[ros-diffs] [fireball] 34037: Jeffrey Morlan <mrnobo1024 at 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.

fireball at svn.reactos.org fireball at svn.reactos.org
Fri Jun 20 21:00:37 CEST 2008


Author: fireball
Date: Fri Jun 20 14:00:37 2008
New Revision: 34037

URL: http://svn.reactos.org/svn/reactos?rev=34037&view=rev
Log:
Jeffrey Morlan <mrnobo1024 at 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.

Added:
    trunk/reactos/lib/3rdparty/libwine/debug_ros.c   (with props)
Modified:
    trunk/reactos/lib/3rdparty/libwine/libwine.rbuild

Added: trunk/reactos/lib/3rdparty/libwine/debug_ros.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/3rdparty/libwine/debug_ros.c?rev=34037&view=auto
==============================================================================
--- trunk/reactos/lib/3rdparty/libwine/debug_ros.c (added)
+++ trunk/reactos/lib/3rdparty/libwine/debug_ros.c [iso-8859-1] Fri Jun 20 14:00:37 2008
@@ -1,0 +1,32 @@
+/* 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
+
+#include "debug.c"
+
+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);
+}
+
+char *_strdup(const char *str)
+{
+    char *newstr = malloc(strlen(str) + 1);
+    if (newstr) strcpy(newstr, str);
+    return newstr;
+}

Propchange: trunk/reactos/lib/3rdparty/libwine/debug_ros.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: trunk/reactos/lib/3rdparty/libwine/libwine.rbuild
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/3rdparty/libwine/libwine.rbuild?rev=34037&r1=34036&r2=34037&view=diff
==============================================================================
--- trunk/reactos/lib/3rdparty/libwine/libwine.rbuild [iso-8859-1] (original)
+++ trunk/reactos/lib/3rdparty/libwine/libwine.rbuild [iso-8859-1] Fri Jun 20 14:00:37 2008
@@ -3,6 +3,6 @@
 <module name="wine" type="staticlibrary">
 	<define name="_DISABLE_TIDENTS" />
 	<file>config.c</file>
-	<file>debug.c</file>
+	<file>debug_ros.c</file>
 	<file>string.c</file>
 </module>



More information about the Ros-diffs mailing list