Running valgrind with Wine

Mike McCormack mike at codeweavers.com
Sat Sep 4 22:55:33 CDT 2004


Hi All,

Valgrind stopped working with Wine a while back due to the way Wine 
reserves memory above address 0x80000000.

The following patch allows valgrind to work with wine again. You need to 
start wine-pthread or wine-kthread instead of starting the wine binary 
depending on whether your system uses NPTL or not. eg. my system uses 
kthreads so:

valgrind wine-kthread notepad.exe

I'm not sure if Alexandre wants to commit this or not, but it should be 
of use to those that want to use valgrind again.

Happy debugging.

Mike


ChangeLog:
* allow wine-[pk]threads to work with valgrind
-------------- next part --------------
Index: loader/main.c
===================================================================
RCS file: /cvstrees/crossover/office/wine/loader/main.c,v
retrieving revision 1.1.1.11
diff -u -r1.1.1.11 main.c
--- loader/main.c	16 Jun 2004 02:57:30 -0000	1.1.1.11
+++ loader/main.c	5 Sep 2004 02:22:27 -0000
@@ -32,16 +32,17 @@
 int main( int argc, char *argv[] )
 {
     char error[1024];
-    int i;
+    int i, reserve = 0;
 
     if (wine_main_preload_info)
     {
         for (i = 0; wine_main_preload_info[i].size; i++)
             wine_mmap_add_reserved_area( wine_main_preload_info[i].addr,
                                          wine_main_preload_info[i].size );
+        reserve = 1;
     }
 
-    wine_init( argc, argv, error, sizeof(error) );
+    wine_init( argc, argv, error, sizeof(error), reserve );
     fprintf( stderr, "wine: failed to initialize: %s\n", error );
     exit(1);
 }
Index: libs/wine/mmap.c
===================================================================
RCS file: /cvstrees/crossover/office/wine/libs/wine/mmap.c,v
retrieving revision 1.1.1.3
diff -u -r1.1.1.3 mmap.c
--- libs/wine/mmap.c	31 Jul 2004 00:38:48 -0000	1.1.1.3
+++ libs/wine/mmap.c	5 Sep 2004 02:22:27 -0000
@@ -249,7 +249,7 @@
 /***********************************************************************
  *           mmap_init
  */
-void mmap_init(void)
+void mmap_init(int reserve)
 {
     struct reserved_area *area;
     struct list *ptr;
@@ -258,6 +258,8 @@
     char * const stack_ptr = &stack;
     char *user_space_limit = (char *)0x80000000;
 
+    if( reserve )
+    {
     /* check for a reserved area starting at the user space limit */
     /* to avoid wasting time trying to allocate it again */
     LIST_FOR_EACH( ptr, &reserved_areas )
@@ -285,6 +287,7 @@
     }
     else reserve_area( user_space_limit, 0 );
 #endif /* __i386__ */
+    }
 
     /* reserve the DOS area if not already done */
 
Index: libs/wine/loader.c
===================================================================
RCS file: /cvstrees/crossover/office/wine/libs/wine/loader.c,v
retrieving revision 1.1.1.10
diff -u -r1.1.1.10 loader.c
--- libs/wine/loader.c	16 Jun 2004 02:57:30 -0000	1.1.1.10
+++ libs/wine/loader.c	5 Sep 2004 02:22:27 -0000
@@ -25,6 +25,7 @@
 #include <ctype.h>
 #include <fcntl.h>
 #include <stdarg.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
@@ -78,7 +79,7 @@
 static int nb_dll_paths;
 static int dll_path_maxlen;
 
-extern void mmap_init(void);
+extern void mmap_init(int reserve);
 
 /* build the dll load path from the WINEDLLPATH variable */
 static void build_dll_path(void)
@@ -511,7 +524,7 @@
  *
  * Main Wine initialisation.
  */
-void wine_init( int argc, char *argv[], char *error, int error_size )
+void wine_init( int argc, char *argv[], char *error, int error_size, int reserve )
 {
     char *wine_debug;
     int file_exists;
@@ -523,7 +536,7 @@
     __wine_main_argc = argc;
     __wine_main_argv = argv;
     __wine_main_environ = environ;
-    mmap_init();
+    mmap_init( reserve );
 
     if ((wine_debug = getenv("WINEDEBUG")))
     {


More information about the wine-patches mailing list