? foo
? xine-lib-fix-w32-recent-versions-linux.patch
Index: wine/ext.c
===================================================================
RCS file: /cvsroot/xine/xine-lib/src/libw32dll/wine/ext.c,v
retrieving revision 1.8
diff -u -r1.8 ext.c
--- wine/ext.c	24 Dec 2003 16:55:36 -0000	1.8
+++ wine/ext.c	21 Sep 2004 19:32:46 -0000
@@ -456,13 +456,30 @@
 LPVOID WINAPI VirtualAlloc(LPVOID address, DWORD size, DWORD type,  DWORD protection)
 {
     void* answer;
-    int fd=open("/dev/zero", O_RDWR);
+    int fd;
+    long pgsz;
+
+    if ((type&(MEM_RESERVE|MEM_COMMIT)) == 0) return NULL;
+
+    fd=open("/dev/zero", O_RDWR);
     if(fd<0){
         perror( "Cannot open /dev/zero for READ+WRITE. Check permissions! error: " );
 	return NULL;
     }
-    size=(size+0xffff)&(~0xffff);
-    //printf("VirtualAlloc(0x%08X, %d)\n", address, size);
+
+    if (type&MEM_RESERVE && (unsigned)address&0xffff) {
+       size += (unsigned)address&0xffff;
+       (unsigned)address &= ~0xffff;
+    }
+    pgsz = sysconf(_SC_PAGESIZE);
+    if (type&MEM_COMMIT && (unsigned)address%pgsz) {
+       size += (unsigned)address%pgsz;
+       address -= (unsigned)address%pgsz;
+    }
+
+    if (type&MEM_RESERVE && size<0x10000) size = 0x10000;
+    if (size%pgsz) size += pgsz - size%pgsz;
+
     if(address!=0)
     {
     //check whether we can allow to allocate this
@@ -474,7 +491,7 @@
 		str=str->prev;
 		continue;
 	    }
-	    if((unsigned)address+size<(unsigned)str->address)
+	    if((unsigned)address+size<=(unsigned)str->address)
 	    {
 		str=str->prev;
 		continue;
@@ -482,29 +499,34 @@
 	    if(str->state==0)
 	    {
 #warning FIXME
-		if(((unsigned)address+size<(unsigned)str->address+str->mapping_size) && (type & MEM_COMMIT))
+               if(   ((unsigned)address >= (unsigned)str->address)
+                  && ((unsigned)address+size<=(unsigned)str->address+str->mapping_size)
+		   && (type & MEM_COMMIT))
 		{
 		    close(fd);
 		    return address; //returning previously reserved memory
 		}
-		return NULL;
 	    }
 	    close(fd);
 	    return NULL;
 	}
-	answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC,
-		    MAP_FIXED | MAP_PRIVATE, fd, 0);
     }
-    else
-	answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC,
-		    MAP_PRIVATE, fd, 0);
+
+    answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC,
+		MAP_PRIVATE, fd, 0);
 //    answer=FILE_dommap(-1, address, 0, size, 0, 0,
 //	PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE);
     close(fd);
+    if (answer != (void *)-1 && address && answer != address) {
+       /* It is dangerous to try mmap() with MAP_FIXED since it does not
+	  always detect conflicts or non-allocation and chaos ensues after
+	  a successful call but an overlapping or non-allocated region.  */
+       munmap(answer, size);
+       answer = (void *) -1;
+       errno = EINVAL;
+    }
     if(answer==(void*)-1)
     {
-	printf("Error no %d\n", errno);
-	printf("VirtualAlloc(0x%p, %ld) failed\n", address, size);
 	return NULL;
     }
     else
Index: wine/ldt_keeper.c
===================================================================
RCS file: /cvsroot/xine/xine-lib/src/libw32dll/wine/ldt_keeper.c,v
retrieving revision 1.12
diff -u -r1.12 ldt_keeper.c
--- wine/ldt_keeper.c	12 Jun 2004 23:19:56 -0000	1.12
+++ wine/ldt_keeper.c	21 Sep 2004 19:32:47 -0000
@@ -258,7 +258,8 @@
     {
         unsigned char *ldt = malloc((TEB_SEL_IDX+1)*8);
         unsigned int limit;
-        
+
+        memset (ldt, 0, (TEB_SEL_IDX+1)*8);
         modify_ldt(0, ldt, (TEB_SEL_IDX+1)*8);
 /*        
         printf("ldt_keeper: old LDT entry = [%x] [%x]\n",
@@ -305,6 +306,7 @@
 	    return NULL;
         }
         *(void**)((char*)ldt_fs->fs_seg+0x18) = ldt_fs->fs_seg;
+        memset (&array, 0, sizeof (array));
         array.base_addr=(int)ldt_fs->fs_seg;
         array.entry_number=TEB_SEL_IDX;
         array.limit=getpagesize()-1;
Index: wine/module.c
===================================================================
RCS file: /cvsroot/xine/xine-lib/src/libw32dll/wine/module.c,v
retrieving revision 1.13
diff -u -r1.13 module.c
--- wine/module.c	8 Aug 2004 16:34:32 -0000	1.13
+++ wine/module.c	21 Sep 2004 19:32:47 -0000
@@ -374,6 +374,8 @@
 
 	while (wm == 0 && listpath[++i])
 	{
+	    memset (&path, 0, sizeof (path));
+
 	    if (i < 2)
 	    {
 		if (i == 0)
