2007-11-29 14:18:54 +00:00
|
|
|
/* -*- mode: C; c-basic-offset: 4 -*- */
|
2008-01-24 15:10:32 +00:00
|
|
|
#ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved."
|
2007-11-29 14:18:54 +00:00
|
|
|
|
2013-04-16 23:57:53 -04:00
|
|
|
#include <toku_portability.h>
|
2013-04-16 23:57:34 -04:00
|
|
|
#include <stdlib.h>
|
2013-04-16 23:57:22 -04:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <errno.h>
|
2007-07-13 19:37:47 +00:00
|
|
|
|
2013-04-16 23:57:32 -04:00
|
|
|
static inline size_t resize(size_t n) {
|
2013-04-16 23:57:34 -04:00
|
|
|
if (n >= 1*1024*1024)
|
|
|
|
n = (n+7) & ~7; // round up to make windbg !heap happy
|
|
|
|
#define DO_PAD_64K 0
|
|
|
|
#if DO_PAD_64K
|
|
|
|
else if (64*1024 <= n && n < 1*1024*1024)
|
|
|
|
n = 1*1024*1024; // map anything >= 64K to 1M
|
2013-04-16 23:57:32 -04:00
|
|
|
#endif
|
2013-04-16 23:57:34 -04:00
|
|
|
#define DO_ROUND_POW2 1
|
|
|
|
#if DO_ROUND_POW2
|
|
|
|
else {
|
|
|
|
// make all buffers a power of 2 in size including the windows overhead
|
|
|
|
size_t r = 0;
|
|
|
|
size_t newn = 1<<r;
|
|
|
|
size_t overhead = 0x24;
|
|
|
|
n += overhead;
|
|
|
|
while (n > newn) {
|
|
|
|
r++;
|
|
|
|
newn = 1<<r;
|
|
|
|
}
|
|
|
|
n = newn - overhead;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return n;
|
2013-04-16 23:57:32 -04:00
|
|
|
}
|
|
|
|
|
2013-04-16 23:57:34 -04:00
|
|
|
void *
|
|
|
|
os_malloc(size_t size)
|
|
|
|
{
|
2013-04-16 23:57:32 -04:00
|
|
|
return malloc(resize(size));
|
2007-07-13 19:37:47 +00:00
|
|
|
}
|
2008-07-17 20:58:57 +00:00
|
|
|
|
2013-04-16 23:57:34 -04:00
|
|
|
void *
|
|
|
|
os_realloc(void *p, size_t size)
|
|
|
|
{
|
2013-04-16 23:57:32 -04:00
|
|
|
return realloc(p, resize(size));
|
2007-07-13 19:37:47 +00:00
|
|
|
}
|
|
|
|
|
2013-04-16 23:57:34 -04:00
|
|
|
void
|
|
|
|
os_free(void* p)
|
|
|
|
{
|
2008-07-17 20:58:57 +00:00
|
|
|
free(p);
|
2007-07-13 19:37:47 +00:00
|
|
|
}
|