Jeffrey Morlan <mrnobo1024@yahoo.com>
- Wrap libwine's memory allocations, avoiding msvcrt imports in kernel32
- The cause is that libwine/debug.c uses functions (malloc, free, realloc, _strdup) which are only present in a complete CRT, creating imports from msvcrt.dll in any module that uses it, including kernel32.dll. Since kernel32 is currently importing from msvcrt, kernel32 gets DLL_PROCESS_DETACHed first, creating a problem for msvcrt's DLL_PROCESS_DETACH which, as a result of a recent bugfix, now uses kernel32 functions that depend on the resources that were freed.
- Fix this by implementing those 4 functions as wrappers around the Local* APIs, in order to avoid the problematic imports.
See issue #3373 for more details.
svn path=/trunk/; revision=34037
2008-06-20 19:00:37 +00:00
|
|
|
/* The use of these four functions was creating unwanted imports
|
|
|
|
* from msvcrt.dll in kernel32.dll. */
|
|
|
|
|
|
|
|
#define malloc libwine_malloc
|
|
|
|
#define free libwine_free
|
|
|
|
#define realloc libwine_realloc
|
|
|
|
#define _strdup libwine__strdup
|
2010-03-30 19:59:29 +00:00
|
|
|
#define interlocked_xchg_add InterlockedExchangeAdd
|
Jeffrey Morlan <mrnobo1024@yahoo.com>
- Wrap libwine's memory allocations, avoiding msvcrt imports in kernel32
- The cause is that libwine/debug.c uses functions (malloc, free, realloc, _strdup) which are only present in a complete CRT, creating imports from msvcrt.dll in any module that uses it, including kernel32.dll. Since kernel32 is currently importing from msvcrt, kernel32 gets DLL_PROCESS_DETACHed first, creating a problem for msvcrt's DLL_PROCESS_DETACH which, as a result of a recent bugfix, now uses kernel32 functions that depend on the resources that were freed.
- Fix this by implementing those 4 functions as wrappers around the Local* APIs, in order to avoid the problematic imports.
See issue #3373 for more details.
svn path=/trunk/; revision=34037
2008-06-20 19:00:37 +00:00
|
|
|
|
|
|
|
#include "debug.c"
|
|
|
|
|
2008-11-26 14:28:19 +00:00
|
|
|
__MINGW_ATTRIB_MALLOC
|
Jeffrey Morlan <mrnobo1024@yahoo.com>
- Wrap libwine's memory allocations, avoiding msvcrt imports in kernel32
- The cause is that libwine/debug.c uses functions (malloc, free, realloc, _strdup) which are only present in a complete CRT, creating imports from msvcrt.dll in any module that uses it, including kernel32.dll. Since kernel32 is currently importing from msvcrt, kernel32 gets DLL_PROCESS_DETACHed first, creating a problem for msvcrt's DLL_PROCESS_DETACH which, as a result of a recent bugfix, now uses kernel32 functions that depend on the resources that were freed.
- Fix this by implementing those 4 functions as wrappers around the Local* APIs, in order to avoid the problematic imports.
See issue #3373 for more details.
svn path=/trunk/; revision=34037
2008-06-20 19:00:37 +00:00
|
|
|
void *malloc(size_t size)
|
|
|
|
{
|
|
|
|
return LocalAlloc(0, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void free(void *ptr)
|
|
|
|
{
|
|
|
|
LocalFree(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *realloc(void *ptr, size_t size)
|
|
|
|
{
|
|
|
|
if (ptr == NULL) return malloc(size);
|
|
|
|
return LocalReAlloc(ptr, size, LMEM_MOVEABLE);
|
|
|
|
}
|
|
|
|
|
2008-11-26 14:28:19 +00:00
|
|
|
__MINGW_ATTRIB_MALLOC
|
Jeffrey Morlan <mrnobo1024@yahoo.com>
- Wrap libwine's memory allocations, avoiding msvcrt imports in kernel32
- The cause is that libwine/debug.c uses functions (malloc, free, realloc, _strdup) which are only present in a complete CRT, creating imports from msvcrt.dll in any module that uses it, including kernel32.dll. Since kernel32 is currently importing from msvcrt, kernel32 gets DLL_PROCESS_DETACHed first, creating a problem for msvcrt's DLL_PROCESS_DETACH which, as a result of a recent bugfix, now uses kernel32 functions that depend on the resources that were freed.
- Fix this by implementing those 4 functions as wrappers around the Local* APIs, in order to avoid the problematic imports.
See issue #3373 for more details.
svn path=/trunk/; revision=34037
2008-06-20 19:00:37 +00:00
|
|
|
char *_strdup(const char *str)
|
|
|
|
{
|
|
|
|
char *newstr = malloc(strlen(str) + 1);
|
|
|
|
if (newstr) strcpy(newstr, str);
|
|
|
|
return newstr;
|
|
|
|
}
|