summaryrefslogtreecommitdiff
path: root/portable
diff options
context:
space:
mode:
Diffstat (limited to 'portable')
-rw-r--r--portable/include/PFile.h4
-rw-r--r--portable/include/pmemory.h49
-rw-r--r--portable/src/ESR_ReturnCode.c150
-rw-r--r--portable/src/PFile.c2
-rw-r--r--portable/src/PFileWrap.c4
-rw-r--r--portable/src/pcrc.c2
-rw-r--r--portable/src/pmemory.c136
7 files changed, 147 insertions, 200 deletions
diff --git a/portable/include/PFile.h b/portable/include/PFile.h
index 1ae8605..5438c68 100644
--- a/portable/include/PFile.h
+++ b/portable/include/PFile.h
@@ -119,7 +119,7 @@ typedef struct PFile_t
* an error occurs.
* @return ESR_INVALID_ARGUMENT if self is null; ESR_WRITE_ERROR if a writing error occurs
*/
- ESR_ReturnCode(*write)(struct PFile_t* self, void* buffer, size_t size, size_t* count);
+ ESR_ReturnCode(*write)(struct PFile_t* self, const void* buffer, size_t size, size_t* count);
/**
* Flushes a PFile.
@@ -464,7 +464,7 @@ PORTABLE_API size_t pfread(void* buffer, size_t size, size_t count, PFile* strea
* @param stream See fwrite()
* @return see fwrite()
*/
-PORTABLE_API size_t pfwrite(void* buffer, size_t size, size_t count, PFile* stream);
+PORTABLE_API size_t pfwrite(const void* buffer, size_t size, size_t count, PFile* stream);
/**
* Backwards compatible fclose().
diff --git a/portable/include/pmemory.h b/portable/include/pmemory.h
index 58716ad..4c09c83 100644
--- a/portable/include/pmemory.h
+++ b/portable/include/pmemory.h
@@ -11,7 +11,7 @@
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an 'AS IS' BASIS, *
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
* *
@@ -22,7 +22,7 @@
-#define PMEM_MAP_TRACE
+/* #define PMEM_MAP_TRACE */
#include "PortPrefix.h"
#include "ptypes.h"
@@ -47,6 +47,40 @@
*/
#define _STR(x) _VAL(x)
+#ifndef offsetof
+#define offsetof(type, member) ((size_t) &(((type *)0)->member))
+#endif
+
+/**
+ * \<static_cast\> implementation for C.
+ */
+#define STATIC_CAST(self, subClass, member) ((subClass*) (((char*) self) - (offsetof(subClass, member))))
+
+
+#define USE_STDLIB_MALLOC
+
+#ifdef USE_STDLIB_MALLOC
+
+#define MALLOC(n, tag) malloc(n)
+#define CALLOC(m, n, tag) calloc(m, n)
+#define CALLOC_CLR(m, n, tag) calloc(m, n)
+#define REALLOC(p, n) realloc(p, n)
+#define FREE(p) free(p)
+#define NEW(type, tag) ((type*)MALLOC(sizeof(type), tag))
+#define NEW_ARRAY(type, n, tag) ((type*)CALLOC(n, sizeof(type), tag))
+
+#define PMemInit() ESR_SUCCESS
+#define PMemShutdown() ESR_SUCCESS
+#define PMemSetLogFile(f) ESR_NOT_SUPPORTED
+#define PMemDumpLogFile() ESR_NOT_SUPPORTED
+#define PMemSetLogEnabled(b) ESR_NOT_SUPPORTED
+#define PMemLogFree(p) (free(p), ESR_SUCCESS)
+#define PMemReport(f) ESR_NOT_SUPPORTED
+#define PMemorySetPoolSize(n) ESR_NOT_SUPPORTED
+#define PMemoryGetPoolSize(p) ESR_NOT_SUPPORTED
+
+#else
+
#ifdef DISABLE_MALLOC
#define malloc #error
#define calloc #error
@@ -54,21 +88,12 @@
#define free #error
#endif
-#ifndef offsetof
-#define offsetof(type, member) ((size_t) &(((type *)0)->member))
-#endif
-
/*
* PMEM_MAP_TRACE is not defined by default.
* It is up to user to define PMEM_MAP_TRACE;
* define in either makefile or here for test purpose.
*/
-/**
- * \<static_cast\> implementation for C.
- */
-#define STATIC_CAST(self, subClass, member) ((subClass*) (((char*) self) - (offsetof(subClass, member))))
-
#ifdef PMEM_MAP_TRACE
/**
* Portable malloc()
@@ -307,3 +332,5 @@ PORTABLE_API ESR_ReturnCode PMemoryGetPoolSize(size_t *size);
*/
#endif
+
+#endif
diff --git a/portable/src/ESR_ReturnCode.c b/portable/src/ESR_ReturnCode.c
index 539ff24..aed93ca 100644
--- a/portable/src/ESR_ReturnCode.c
+++ b/portable/src/ESR_ReturnCode.c
@@ -11,7 +11,7 @@
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an 'AS IS' BASIS, *
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
* *
@@ -21,123 +21,37 @@
#include "ESR_ReturnCode.h"
-#define RETURNCODE_COUNT 28
-static LCHAR* rcStringMapping[RETURNCODE_COUNT+1] =
- {
- L("ESR_SUCCESS"),
- L("ESR_CONTINUE_PROCESSING"),
- L("ESR_FATAL_ERROR"),
- L("ESR_BUFFER_OVERFLOW"),
- L("ESR_OPEN_ERROR"),
- L("ESR_ALREADY_OPEN"),
- L("ESR_CLOSE_ERROR"),
- L("ESR_ALREADY_CLOSED"),
- L("ESR_READ_ERROR"),
- L("ESR_WRITE_ERROR"),
- L("ESR_FLUSH_ERROR"),
- L("ESR_SEEK_ERROR"),
- L("ESR_OUT_OF_MEMORY"),
- L("ESR_ARGUMENT_OUT_OF_BOUNDS"),
- L("ESR_NO_MATCH_ERROR"),
- L("ESR_INVALID_ARGUMENT"),
- L("ESR_NOT_SUPPORTED"),
- L("ESR_INVALID_STATE"),
- L("ESR_THREAD_CREATION_ERROR"),
- L("ESR_IDENTIFIER_COLLISION"),
- L("ESR_TIMED_OUT"),
- L("ESR_INVALID_RESULT_TYPE"),
- L("ESR_NOT_IMPLEMENTED"),
- L("ESR_CONNECTION_RESET_BY_PEER"),
- L("ESR_PROCESS_CREATE_ERROR"),
- L("ESR_TTS_NO_ENGINE"),
- L("ESR_MUTEX_CREATION_ERROR"),
- L("ESR_DEADLOCK"),
- L("invalid return code") /* must remain last element for ESR_rc2str() to function */
- };
-
const LCHAR* ESR_rc2str(const ESR_ReturnCode rc)
{
- if (rc >= RETURNCODE_COUNT)
- return rcStringMapping[RETURNCODE_COUNT];
- return rcStringMapping[rc];
+ switch (rc) {
+ case ESR_SUCCESS: return L("ESR_SUCCESS");
+ case ESR_CONTINUE_PROCESSING: return L("ESR_CONTINUE_PROCESSING");
+ case ESR_FATAL_ERROR: return L("ESR_FATAL_ERROR");
+ case ESR_BUFFER_OVERFLOW: return L("ESR_BUFFER_OVERFLOW");
+ case ESR_OPEN_ERROR: return L("ESR_OPEN_ERROR");
+ case ESR_ALREADY_OPEN: return L("ESR_ALREADY_OPEN");
+ case ESR_CLOSE_ERROR: return L("ESR_CLOSE_ERROR");
+ case ESR_ALREADY_CLOSED: return L("ESR_ALREADY_CLOSED");
+ case ESR_READ_ERROR: return L("ESR_READ_ERROR");
+ case ESR_WRITE_ERROR: return L("ESR_WRITE_ERROR");
+ case ESR_FLUSH_ERROR: return L("ESR_FLUSH_ERROR");
+ case ESR_SEEK_ERROR: return L("ESR_SEEK_ERROR");
+ case ESR_OUT_OF_MEMORY: return L("ESR_OUT_OF_MEMORY");
+ case ESR_ARGUMENT_OUT_OF_BOUNDS: return L("ESR_ARGUMENT_OUT_OF_BOUNDS");
+ case ESR_NO_MATCH_ERROR: return L("ESR_NO_MATCH_ERROR");
+ case ESR_INVALID_ARGUMENT: return L("ESR_INVALID_ARGUMENT");
+ case ESR_NOT_SUPPORTED: return L("ESR_NOT_SUPPORTED");
+ case ESR_INVALID_STATE: return L("ESR_INVALID_STATE");
+ case ESR_THREAD_CREATION_ERROR: return L("ESR_THREAD_CREATION_ERROR");
+ case ESR_IDENTIFIER_COLLISION: return L("ESR_IDENTIFIER_COLLISION");
+ case ESR_TIMED_OUT: return L("ESR_TIMED_OUT");
+ case ESR_INVALID_RESULT_TYPE: return L("ESR_INVALID_RESULT_TYPE");
+ case ESR_NOT_IMPLEMENTED: return L("ESR_NOT_IMPLEMENTED");
+ case ESR_CONNECTION_RESET_BY_PEER: return L("ESR_CONNECTION_RESET_BY_PEER");
+ case ESR_PROCESS_CREATE_ERROR: return L("ESR_PROCESS_CREATE_ERROR");
+ case ESR_TTS_NO_ENGINE: return L("ESR_TTS_NO_ENGINE");
+ case ESR_MUTEX_CREATION_ERROR: return L("ESR_MUTEX_CREATION_ERROR");
+ case ESR_DEADLOCK: return L("ESR_DEADLOCK");
+ };
+ return L("invalid return code");
}
-
-
-#ifdef _WIN32
-__declspec(thread) unsigned long stackEnd = 0;
-__declspec(thread) unsigned long stackBeginMin = LONG_MAX;
-
-#include "plog.h"
-
-#ifdef __cplusplus
-extern "C"
-#endif
-
- void __declspec(naked) _cdecl _penter(void)
-{
- _asm
- {
- pushad
- mov ebp, esp
- }
-
- {
- unsigned long espBuffer;
-
- _asm
- {
- mov espBuffer, esp
- }
- if (espBuffer > stackEnd)
- stackEnd = espBuffer;
- //printf("\nThread=%d,-addressStack-begin=%lu\n", GetCurrentThreadId(), espBuffer);
- }
-
- _asm
- {
- popad
- ret
- }
-}
-
-void __declspec(naked) _cdecl _pexit(void)
-{
- _asm
- {
- pushad
- mov ebp, esp
- }
-
- {
- unsigned long stackBegin;
-
- _asm
- {
- sub esp, 4
- mov stackBegin, esp
- }
-
- if (stackBegin < stackBeginMin)
- {
- stackBeginMin = stackBegin;
- if (stackEnd - stackBegin > 20*1000)
- printf("*****************************\nThread %d, Maximum stack usage=%lu\n*******************************\n", GetCurrentThreadId(), (stackEnd - stackBeginMin));
- }
- /*
- if (stackEnd - stackBegin > 15*1000)
- printf("\nThread=%d,Stack-size=%lu\n", GetCurrentThreadId(), (stackEnd - stackBegin));
- */
-
- _asm
- {
- add esp, 4
- }
- }
-
- _asm
- {
- popad
- ret
- }
-}
-#endif
diff --git a/portable/src/PFile.c b/portable/src/PFile.c
index 06e1317..9320846 100644
--- a/portable/src/PFile.c
+++ b/portable/src/PFile.c
@@ -366,7 +366,7 @@ size_t pfread(void* buffer, size_t size, size_t count, PFile* stream)
return count;
}
-size_t pfwrite(void* buffer, size_t size, size_t count, PFile* stream)
+size_t pfwrite(const void* buffer, size_t size, size_t count, PFile* stream)
{
ESR_ReturnCode rc;
diff --git a/portable/src/PFileWrap.c b/portable/src/PFileWrap.c
index d7dddfe..b2fa53a 100644
--- a/portable/src/PFileWrap.c
+++ b/portable/src/PFileWrap.c
@@ -70,7 +70,7 @@ ESR_ReturnCode PFileRead ( PFile *self, void *buffer, size_t size, size_t *count
-ESR_ReturnCode PFileWrite ( PFile *self, void *buffer, size_t size, size_t *count )
+ESR_ReturnCode PFileWrite ( PFile *self, const void *buffer, size_t size, size_t *count )
{
ESR_ReturnCode write_status;
size_t items_written;
@@ -301,7 +301,7 @@ size_t pfread ( void *buffer, size_t size, size_t count, PFile *stream )
-size_t pfwrite ( void *buffer, size_t size, size_t count, PFile *stream )
+size_t pfwrite ( const void *buffer, size_t size, size_t count, PFile *stream )
{
ESR_ReturnCode rc;
diff --git a/portable/src/pcrc.c b/portable/src/pcrc.c
index a178fd8..6f31f08 100644
--- a/portable/src/pcrc.c
+++ b/portable/src/pcrc.c
@@ -69,7 +69,7 @@ static unsigned int crcTable[] =
0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
};
-#elif (UINT_MAX >= 0xFFFFU)*/
+#elif (UINT_MAX >= 0xFFFFU)
/* use CRC-16 on machine with [16..32[ bits integer. */
#define WIDTH 16
diff --git a/portable/src/pmemory.c b/portable/src/pmemory.c
index f00427d..4718eab 100644
--- a/portable/src/pmemory.c
+++ b/portable/src/pmemory.c
@@ -11,7 +11,7 @@
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an 'AS IS' BASIS, *
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
* *
@@ -29,6 +29,8 @@
#include "pmemory_ext.h"
#include "pmutex.h"
+#ifndef USE_STDLIB_MALLOC
+
#undef malloc
#undef calloc
#undef realloc
@@ -124,14 +126,14 @@ static ESR_ReturnCode getStackTrace(LCHAR* stackTrace, size_t* len)
{
ESR_BOOL isInit;
ESR_ReturnCode rc;
-
+
rc = PStackTraceIsInitialized(&isInit);
if (rc == ESR_SUCCESS && isInit)
{
LCHAR* index;
size_t bufferLen = *len;
size_t i;
-
+
rc = PStackTraceGetValue(stackTrace, &bufferLen);
if (rc == ESR_SUCCESS)
{
@@ -175,7 +177,7 @@ static int getIndex(const LCHAR *key)
unsigned int crc = ~pcrcComputeString(key);
int initialIdx = (int)(crc % MAX_MEM_TAG);
int idx = initialIdx;
-
+
for (;;)
{
if (gMemoryMap[idx].tag == NULL)
@@ -193,14 +195,14 @@ static int getIndex(const LCHAR *key)
#endif
return idx;
}
-
+
if (gMemoryMap[idx].crc == crc &&
LSTRCMP(gMemoryMap[idx].tag, key) == 0)
{
/* found a matching slot, return it */
return idx;
}
-
+
if (++idx == MAX_MEM_TAG)
{
/* Look at next slot and wrap around. */
@@ -218,7 +220,7 @@ ESR_ReturnCode PMemorySetPoolSize(size_t size)
#if defined(PORTABLE_DINKUM_MEM_MGR) || defined(PORTABLE_FIXED_SIZE_MEM_BLOCK_SCHEME)
if (gNbInit > 0)
return ESR_INVALID_STATE;
-
+
gMemPoolSize = size;
return ESR_SUCCESS;
#else
@@ -244,12 +246,12 @@ ESR_ReturnCode PMemoryGetPoolSize(size_t *size)
ESR_ReturnCode PMemInit(void)
{
ESR_ReturnCode init_status;
-
+
if (gNbInit > 0)
return ESR_INVALID_STATE;
-
+
init_status = createMutex(&memMutex, ESR_FALSE);
-
+
if (init_status == ESR_SUCCESS)
{
++gNbInit;
@@ -281,10 +283,12 @@ ESR_ReturnCode PMemInit(void)
deleteMutex(&memMutex);
}
+#ifdef PMEM_MAP_TRACE
// Initialize global static variables
gCurAlloc = 0;
gMaxAlloc = 0;
-
+#endif
+
return (init_status);
}
@@ -298,7 +302,7 @@ ESR_ReturnCode PMemShutdown(void)
#ifdef PMEM_MAP_TRACE
size_t i;
#endif
-
+
if (gNbInit == 0)
return ESR_INVALID_STATE;
if (gNbInit == 1)
@@ -316,7 +320,7 @@ ESR_ReturnCode PMemShutdown(void)
deleteMutex(&memMutex);
}
gNbInit--;
-
+
return ESR_SUCCESS;
}
@@ -324,27 +328,27 @@ ESR_ReturnCode PMemSetLogFile(PFile* file)
{
if (gNbInit == 0)
return ESR_INVALID_STATE;
-
+
lockMutex(&memMutex);
gFile = file;
unlockMutex(&memMutex);
-
+
return ESR_SUCCESS;
}
ESR_ReturnCode PMemDumpLogFile(void)
{
ESR_ReturnCode rc;
-
+
if (gNbInit == 0)
return ESR_INVALID_STATE;
-
+
lockMutex(&memMutex);
if (gFile != NULL)
{
/* Hide gFile from memory report */
/* CHK(rc, gFile->hideMemoryAllocation(gFile));*/
-
+
rc = PMemReport(gFile);
if (rc != ESR_SUCCESS)
{
@@ -375,7 +379,7 @@ ESR_ReturnCode PMemSetLogEnabled(ESR_BOOL value)
lockMutex(&memMutex);
isLogEnabled = value;
unlockMutex(&memMutex);
-
+
return ESR_SUCCESS;
}
@@ -388,12 +392,12 @@ ESR_ReturnCode PMemLogFree(void* ptr)
#if PMEM_STACKTRACE && PMEM_LOG_LOWLEVEL
ESR_ReturnCode rc;
#endif
-
+
if (ptr == NULL || gNbInit == 0)
return ESR_SUCCESS;
-
+
lockMutex(&memMutex);
-
+
data = (MemoryData*)(((unsigned char*) ptr) - sizeof(MemoryData));
#ifdef PMEM_MAP_TRACE
e = gMemoryMap + data->index;
@@ -402,10 +406,10 @@ ESR_ReturnCode PMemLogFree(void* ptr)
{
passert(e->curAlloc >= data->size);
e->curAlloc -= data->size;
-
+
passert(gCurAlloc >= data->size);
gCurAlloc -= data->size;
-
+
data->size = 0;
}
#if PMEM_STACKTRACE
@@ -428,7 +432,7 @@ ESR_ReturnCode PMemLogFree(void* ptr)
#if PMEM_STACKTRACE
LCHAR stackTrace[P_MAX_STACKTRACE];
size_t len = P_MAX_STACKTRACE;
-
+
rc = getStackTrace(stackTrace, &len);
if (rc != ESR_SUCCESS)
{
@@ -442,7 +446,7 @@ ESR_ReturnCode PMemLogFree(void* ptr)
}
#endif /* PMEM_LOG_LOWLEVEL */
#endif /* PMEM_MAP_TRACE */
-
+
unlockMutex(&memMutex);
return ESR_SUCCESS;
#if PMEM_STACKTRACE && PMEM_LOG_LOWLEVEL
@@ -469,7 +473,7 @@ ESR_ReturnCode PMemReport(PFile* file)
#if PMEM_STACKTRACE
MemoryData* data;
#endif
-
+
if (gNbInit == 0)
return ESR_INVALID_STATE;
if (file == NULL)
@@ -478,7 +482,7 @@ ESR_ReturnCode PMemReport(PFile* file)
if (file == NULL)
return ESR_SUCCESS;
}
-
+
lockMutex(&memMutex);
#ifdef PMEM_MAP_TRACE
if (gFile != NULL)
@@ -492,9 +496,9 @@ ESR_ReturnCode PMemReport(PFile* file)
pfprintf(gFile, L("pmem|-|0|corrupt|%d|\n"), i);
}
}
-
+
pfprintf(file, L("%-52s %10s %15s\n"), L("Memory tag"), L("Cur. Alloc"), L("Max. Alloc"));
-
+
for (i = 0, e = gMemoryMap; i < MAX_MEM_TAG; ++i, ++e)
{
if (e->tag == NULL)
@@ -505,7 +509,7 @@ ESR_ReturnCode PMemReport(PFile* file)
else
{
len = LSTRLEN(e->tag);
-
+
if (len > TAG_SIZE - 1)
{
LSTRCPY(truncatedTag, TAG_PREFIX);
@@ -524,7 +528,7 @@ ESR_ReturnCode PMemReport(PFile* file)
{
LCHAR stackTrace[P_MAX_STACKTRACE];
LCHAR* index;
-
+
LSTRCPY(stackTrace, data->stackTrace);
index = stackTrace;
while (index)
@@ -547,7 +551,7 @@ ESR_ReturnCode PMemReport(PFile* file)
/* not support */
#endif /* PMEM_MAP_TRACE */
unlockMutex(&memMutex);
-
+
return ESR_SUCCESS;
}
/*
@@ -579,17 +583,17 @@ void *pmalloc(size_t nbBytes)
ESR_BOOL isInit;
ESR_ReturnCode rc;
#endif
-
+
if (gNbInit == 0)
return NULL;
-
+
lockMutex(&memMutex);
-
+
#ifdef PMEM_MAP_TRACE
if (tag == NULL)
tag = file;
passert(tag != NULL);
-
+
idx = getIndex(tag);
if (idx == -1)
{
@@ -606,7 +610,7 @@ void *pmalloc(size_t nbBytes)
}
#endif
actualSize = sizeof(MemoryData) + nbBytes;
-
+
data = (MemoryData *) malloc(actualSize);
if (data == NULL)
{
@@ -616,7 +620,7 @@ void *pmalloc(size_t nbBytes)
*/
goto CLEANUP;
}
-
+
#ifdef PMEM_MAP_TRACE
data->index = idx;
#if PMEM_STACKTRACE
@@ -643,9 +647,9 @@ void *pmalloc(size_t nbBytes)
else
data->stackTrace = NULL;
#endif
-
+
e = gMemoryMap + idx;
-
+
#if PMEM_STACKTRACE
if (e->last != NULL)
e->last->next = data;
@@ -656,7 +660,7 @@ void *pmalloc(size_t nbBytes)
e->first = data;
#endif
#endif
-
+
if (isLogEnabled)
{
data->size = actualSize;
@@ -664,7 +668,7 @@ void *pmalloc(size_t nbBytes)
e->curAlloc += actualSize;
if (e->maxAlloc < e->curAlloc)
e->maxAlloc = e->curAlloc;
-
+
gCurAlloc += actualSize;
if (gMaxAlloc < gCurAlloc)
gMaxAlloc = gCurAlloc;
@@ -672,12 +676,12 @@ void *pmalloc(size_t nbBytes)
}
else
data->size = 0;
-
+
result = (void*)(data + 1);
-
+
#if PMEM_LOG_LOWLEVEL
if (gFile != NULL && isLogEnabled)
-
+
if (gFile != NULL)
{
#if PMEM_STACKTRACE
@@ -687,7 +691,7 @@ void *pmalloc(size_t nbBytes)
#endif /* PMEM_STACKTRACE */
}
#endif /* PMEM_LOG_LOWLEVEL */
-
+
CLEANUP:
unlockMutex(&memMutex);
return result;
@@ -746,10 +750,10 @@ void *prealloc(void *ptr, size_t newSize)
MemoryData* oldLast;
#endif
ESR_BOOL bMalloc = ESR_FALSE;
-
+
if (gNbInit == 0)
return NULL;
-
+
if (newSize == 0 && ptr != NULL)
{
#ifdef PMEM_MAP_TRACE
@@ -767,9 +771,9 @@ void *prealloc(void *ptr, size_t newSize)
return pmalloc(newSize);
#endif
}
-
+
lockMutex(&memMutex);
-
+
oldData = (MemoryData *)(((unsigned char *) ptr) - sizeof(MemoryData));
oldSize = oldData->size;
passert(oldSize >= 0);
@@ -781,7 +785,7 @@ void *prealloc(void *ptr, size_t newSize)
#ifdef PMEM_MAP_TRACE
e = gMemoryMap + oldData->index;
#endif
-
+
actualSize = newSize + sizeof(MemoryData);
if (oldSize != actualSize)
{
@@ -811,7 +815,7 @@ void *prealloc(void *ptr, size_t newSize)
{
newData = oldData;
}
-
+
#ifdef PMEM_MAP_TRACE
if (newData != NULL && bMalloc)
{
@@ -820,12 +824,12 @@ void *prealloc(void *ptr, size_t newSize)
e->curAlloc += actualSize - oldSize;
if (e->maxAlloc < e->curAlloc)
e->maxAlloc = e->curAlloc;
-
+
gCurAlloc += actualSize - oldSize;
if (gMaxAlloc < gCurAlloc)
gMaxAlloc = gCurAlloc;
}
-
+
#if PMEM_STACKTRACE
newData->stackTrace = oldStackTrace;
newData->next = oldNext;
@@ -841,13 +845,13 @@ void *prealloc(void *ptr, size_t newSize)
#endif
}
#endif
-
+
if (newData != NULL)
{
newData->size = actualSize;
result = (void*)(newData + 1);
}
-
+
#if PMEM_LOG_LOWLEVEL
if (gFile != NULL && isLogEnabled)
{
@@ -855,7 +859,7 @@ void *prealloc(void *ptr, size_t newSize)
LCHAR stackTrace[P_MAX_STACKTRACE];
size_t len = P_MAX_STACKTRACE;
ESR_ReturnCode rc;
-
+
rc = getStackTrace(stackTrace, &len);
if (rc != ESR_SUCCESS)
{
@@ -868,7 +872,7 @@ void *prealloc(void *ptr, size_t newSize)
#endif /* PMEM_STACKTRACE */
}
#endif /* PMEM_LOG_LOWLEVEL */
-
+
unlockMutex(&memMutex);
return result;
#if PMEM_STACKTRACE && PMEM_LOG_LOWLEVEL
@@ -890,9 +894,9 @@ void pfree(void* ptr)
#endif
if (ptr == NULL || gNbInit == 0)
return;
-
+
lockMutex(&memMutex);
-
+
data = (MemoryData*)(((unsigned char*) ptr) - sizeof(MemoryData));
#ifdef PMEM_MAP_TRACE
passert(data->index >= 0 && data->index <= MAX_MEM_TAG);
@@ -901,7 +905,7 @@ void pfree(void* ptr)
{
passert(e->curAlloc >= data->size);
e->curAlloc -= data->size;
-
+
passert(gCurAlloc >= data->size);
gCurAlloc -= data->size;
}
@@ -926,7 +930,7 @@ void pfree(void* ptr)
LCHAR stackTrace[P_MAX_STACKTRACE];
size_t len = P_MAX_STACKTRACE;
ESR_ReturnCode rc;
-
+
rc = getStackTrace(stackTrace, &len);
if (rc != ESR_SUCCESS)
{
@@ -944,7 +948,7 @@ void pfree(void* ptr)
data->stackTrace = NULL;
#endif /* PMEM_STACKTRACE */
#endif
-
+
free(data);
unlockMutex(&memMutex);
#if PMEM_STACKTRACE && PMEM_LOG_LOWLEVEL
@@ -952,5 +956,7 @@ CLEANUP:
unlockMutex(&memMutex);
return;
#endif
-
+
}
+
+#endif