From amistry@united-ware.com  Sun Oct 24 20:01:06 2004
Return-Path: <amistry@united-ware.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 9A89C16A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 24 Oct 2004 20:01:06 +0000 (GMT)
Received: from smtp1.fuse.net (mail-out1.fuse.net [216.68.8.174])
	by mx1.FreeBSD.org (Postfix) with ESMTP id BE1E043D3F
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 24 Oct 2004 20:01:05 +0000 (GMT)
	(envelope-from amistry@united-ware.com)
Received: from gx6.fuse.net ([216.196.156.33]) by smtp1.fuse.net
          (InterMail vM.6.01.03.04 201-2131-111-106-20040729) with ESMTP
          id <20041024200054.FXXK15104.smtp1.fuse.net@gx6.fuse.net>
          for <FreeBSD-gnats-submit@freebsd.org>;
          Sun, 24 Oct 2004 16:00:54 -0400
Received: from www.united-ware.com ([216.196.156.33]) by gx6.fuse.net
          (InterMail vG.1.00.00.00 201-2136-104-20040331) with ESMTP
          id <20041024200048.CYQL6532.gx6.fuse.net@www.united-ware.com>
          for <FreeBSD-gnats-submit@freebsd.org>;
          Sun, 24 Oct 2004 16:00:48 -0400
Received: from www.united-ware.com (localhost [127.0.0.1])
	by www.united-ware.com (8.12.9p2/8.12.9) with ESMTP id i9OJmRjA058927
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT)
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 24 Oct 2004 15:48:27 -0400 (EDT)
	(envelope-from amistry@www.united-ware.com)
Received: (from amistry@localhost)
	by www.united-ware.com (8.12.9p2/8.12.9/Submit) id i9OJmQDb058926;
	Sun, 24 Oct 2004 15:48:26 -0400 (EDT)
	(envelope-from amistry)
Message-Id: <200410241948.i9OJmQDb058926@www.united-ware.com>
Date: Sun, 24 Oct 2004 15:48:26 -0400 (EDT)
From: Anish Mistry <amistry@am-productions.biz>
Reply-To: Anish Mistry <amistry@am-productions.biz>
To: FreeBSD-gnats-submit@freebsd.org
Cc: gerald@pfeifer.com
Subject: Unbreak WINE for 5.x and 6
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         73092
>Category:       kern
>Synopsis:       [patch] Unbreak WINE for 5.x and 6 [patches for both kern and port]
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Oct 24 20:10:10 GMT 2004
>Closed-Date:    Mon Dec 13 12:31:06 GMT 2004
>Last-Modified:  Sat Jul 22 16:30:19 GMT 2006
>Originator:     Anish Mistry
>Release:        FreeBSD 5.3-BETA7 i386
>Organization:
AM Productions
>Environment:
System: FreeBSD bigguy.am-productions.biz 5.3-BETA7 FreeBSD 5.3-BETA7 #5: Fri Oct 22 18:29:32 EDT 2004     amistry@bigguy.am-productions.biz:/usr/obj/usr/src/sys/BIGGUY  i386


	
>Description:
	Versions of WINE after May 2004 no longer work with FreeBSD.  This is 
due to WINE being unable to mmap part of the process address space to load in 
the Windows executables.  The reason this happens is because FreeBSD only allows
anonymously mmaping the upper part of the process address space after the
reserved data sections.
	
>How-To-Repeat:
	Build a version of WINE after May 2004 and try to run a program.
	
>Fix:
	The attached patch for vm_mmap.c will allow the mmap() syscall to be
able to anonymously mmap free areas of the process address space below the
reserved area.  The wine mmap.c patch removes the reserving of the DOS area
thus allowing the correct executable load location to be used.
	

--- wine-mmap.patch begins here ---
--- libs/wine/mmap.c.orig	Mon Sep  6 01:23:40 2004
+++ libs/wine/mmap.c	Mon Sep  6 01:23:46 2004
@@ -294,7 +294,7 @@
         area = LIST_ENTRY( ptr, struct reserved_area, entry );
         if (!area->base) return;  
     }
-    reserve_dos_area();
+    /*reserve_dos_area();*/
 }
 
 #else /* HAVE_MMAP */
--- wine-mmap.patch ends here ---

--- vm_mmap-wine-6-current.patch begins here ---
--- vm_mmap.c.orig	Thu Aug  5 03:04:33 2004
+++ vm_mmap.c	Wed Aug 18 21:31:13 2004
@@ -208,6 +208,8 @@
 	vm_offset_t addr;
 	vm_size_t size, pageoff;
 	vm_prot_t prot, maxprot;
+	vm_map_t map;
+
 	void *handle;
 	int flags, error;
 	off_t pos;
@@ -276,9 +278,26 @@
 		if (addr == 0 ||
 		    (addr >= round_page((vm_offset_t)vms->vm_taddr) &&
 		    addr < round_page((vm_offset_t)vms->vm_daddr +
-		    lim_max(td->td_proc, RLIMIT_DATA))))
+		    lim_max(td->td_proc, RLIMIT_DATA)))) {
+			/*
+			 * XXX So much dirtyness someone who knows what they are doing
+			 * will want to fix this monstrosity.
+			 */
+			map = &td->td_proc->p_vmspace->vm_map;
+			vm_map_lock(map);
 			addr = round_page((vm_offset_t)vms->vm_daddr +
-			    lim_max(td->td_proc, RLIMIT_DATA));
+				lim_max(td->td_proc, RLIMIT_DATA));
+			if(vm_map_findspace(map, addr, size, &addr) != 0) {
+			/*
+			 * since we can't grab the upper process address space bruteforce it.
+			 */
+				for(addr = 0;addr <= round_page((vm_offset_t)vms->vm_taddr) &&
+					vm_map_findspace(map, addr, size, &addr) != 0
+					;addr += PAGE_SIZE,addr = round_page(addr));
+			}
+			vm_map_unlock(map);
+		}
+
 		PROC_UNLOCK(td->td_proc);
 	}
 	if (flags & MAP_ANON) {
--- vm_mmap-wine-6-current.patch ends here ---


>Release-Note:
>Audit-Trail:

From: Anish Mistry <amistry@am-productions.biz>
To: FreeBSD-gnats-submit@freebsd.org
Cc:  
Subject: Re: kern/73092: Unbreak WINE for 5.x and 6
Date: Mon, 15 Nov 2004 20:20:34 -0500

 --nextPart3419735.YXvzd6Ojig
 Content-Type: text/plain;
   charset="iso-8859-1"
 Content-Transfer-Encoding: quoted-printable
 Content-Disposition: inline
 
 The wine-mmap.patch is no longer needed since that code has been #ifdef'd=20
 out in the wine CVS.
 =2D-=20
 Anish Mistry
 amistry@am-productions.biz
 AM Productions http://am-productions.biz/
 
 --nextPart3419735.YXvzd6Ojig
 Content-Type: application/pgp-signature
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.2.6 (FreeBSD)
 
 iD8DBQBBmVXrxqA5ziudZT0RAjMgAKDDpuBhOBKCLDc0dbx96F/4ivFoggCeI9u3
 F4BjeVGg1IzCQaFXIb2yVyw=
 =TPPE
 -----END PGP SIGNATURE-----
 
 --nextPart3419735.YXvzd6Ojig--

From: Simon 'corecode' Schubert <corecode@fs.ei.tum.de>
To: freebsd-gnats-submit@FreeBSD.org, amistry@am-productions.biz
Cc:  
Subject: Re: kern/73092: [patch] Unbreak WINE for 5.x and 6 [patches for both kern and port]
Date: Thu, 18 Nov 2004 05:51:49 +0100

 --Apple-Mail-8-39742086
 Content-Transfer-Encoding: 7bit
 Content-Type: text/plain; charset=US-ASCII; format=flowed
 
 I was looking at getting a current wine running on DragonFly and found 
 your patch. In my opinion, this patch fixes the "problem" at the wrong 
 place:
 
 wine doesn't want arbitary addresses (mmap(NULL...)), but wants 
 addresses below user_space_limit. Although mmap(2) doesn't provide such 
 a rich set of features to be able to specify an "desired/allowed 
 range", this can be easily done in wine itself:
 
 diff -ru work/wine-20041019/dlls/ntdll/virtual.c 
 work.old/wine-20041019/dlls/ntdll/virtual.c
 --- work/wine-20041019/dlls/ntdll/virtual.c	2004-10-11 
 22:59:06.000000000 +0200
 +++ work.old/wine-20041019/dlls/ntdll/virtual.c	2004-11-18 
 04:33:04.000000000 +0100
 @@ -119,6 +119,7 @@
   /* Note: these are Windows limits, you cannot change them. */
   # define ADDRESS_SPACE_LIMIT  ((void *)0xc0000000)  /* top of the 
 total available address space */
   # define USER_SPACE_LIMIT     ((void *)0x80000000)  /* top of the user 
 address space */
 +# define LOW_SPACE_LIMIT      ((void *)0x110000)    /* lower address 
 space limit */
   #else
   static UINT page_shift;
   static UINT page_mask;
 @@ -600,7 +601,7 @@
 
           for (;;)
           {
 -            if ((ptr = wine_anon_mmap( NULL, view_size, 
 VIRTUAL_GetUnixProt(vprot), 0 )) == (void *)-1)
 +            if ((ptr = wine_anon_mmap( LOW_SPACE_LIMIT, view_size, 
 VIRTUAL_GetUnixProt(vprot), 0 )) == (void *)-1)
               {
                   if (errno == ENOMEM) return STATUS_NO_MEMORY;
                   return STATUS_INVALID_PARAMETER;
 
 Just ask mmap to start allocating at a low address. It's not tested a 
 lot, but applications run again.
 
 cheers
    simon
 
 -- 
 /"\
 \ /
   \     ASCII Ribbon Campaign
 / \  Against HTML Mail and News
 
 --Apple-Mail-8-39742086
 content-type: application/pgp-signature; x-mac-type=70674453;
 	name=PGP.sig
 content-description: This is a digitally signed message part
 content-disposition: inline; filename=PGP.sig
 content-transfer-encoding: 7bit
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.2.4 (Darwin)
 
 iD8DBQFBnCpmr5S+dk6z85oRAqysAKDCTQaaZY8EYBdxaEsbrI+Pyt7mMwCgxs1v
 wvmNGslGYV98zf8nnU2HlBk=
 =2JTS
 -----END PGP SIGNATURE-----
 
 --Apple-Mail-8-39742086--
 
State-Changed-From-To: open->feedback 
State-Changed-By: gerald 
State-Changed-When: Sun Dec 12 19:24:42 GMT 2004 
State-Changed-Why:  
I have integrated Simon's patch into the emulators/wine port.  Is there 
still something we may want to address in general, in the FreeBSD kernel 
or libc, or shall we close this PR? 

(If it's the former, would you mind suggesting an appropriate subject for 
the PR to catch the attention of the relevant folks?) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=73092 
State-Changed-From-To: feedback->closed 
State-Changed-By: gerald 
State-Changed-When: Mon Dec 13 12:30:36 GMT 2004 
State-Changed-Why:  
Okay, so it seems we can close this. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=73092 

From: Michael Nottebrock <lofi@freebsd.org>
To: bug-followup@freebsd.org, amistry@am-productions.biz
Cc:  
Subject: Re: kern/73092: [patch] Unbreak WINE for 5.x and 6 [patches for both kern and port]
Date: Sat, 22 Jul 2006 01:32:28 +0200

 IMHO this issue still isn't fixed completely. A good deal of applications=20
 still fail to run in wine on FreeBSD while they do work on Linux, due to=20
 memory allocation issues, the most prominent being Internet Explorer:
 
 [lofi@kiste]:0:~ >winedbg "/home/lofi/.ies4linux/ie6/drive_c/Program Files/Internet Explorer/IEXPLORE.EXE"
 err:heap:HEAP_CreateSystemHeap system heap base address 0x80000000 not available
 WineDbg starting on pid 0xa
 fixme:dbghelp:SymLoadModule Should have successfully loaded debug information
 for image c:\windows\system32\iexplore.exe
 fixme:dbghelp:SymLoadModule Should have successfully loaded debug information
 for image c:\windows\system32\iexplore.exe
 err:heap:HEAP_CreateSystemHeap system heap base address 0x80000000 not available
 fixme:dbghelp:SymLoadModule Should have successfully loaded debug information
 for image c:\windows\system32\winex11.drv
 fixme:dbghelp:SymLoadModule Should have successfully loaded debug information
 for image c:\windows\system32\imm32.dll
 fixme:actctx:CreateActCtxW 0x35fb40 00000008
 fixme:actctx:ActivateActCtx 0xf00baa 0x35f908
 fixme:dbghelp:SymLoadModule Should have successfully loaded debug information
 for image c:\windows\system32\uxtheme.dll
 fixme:actctx:DeactivateActCtx 00000000 00f00bad
 file_set_error: Bad address
 file_set_error: Bad address
 0x9c23eddd: subl        $12,%esp
 
 What's worse - this bug, if reported in wine's bugtracker, either gets misidentified as a duplicate of=20
 http://www.freebsd.org/cgi/query-pr.cgi?pr=3Dports/76459 or ignored as a
 FreeBSD-specific issue that requires attention of people with expertise with
 FreeBSD's memory management (which is probably true).
 

From: Michael Nottebrock <lofi@freebsd.org>
To: bug-followup@freebsd.org, amistry@am-productions.biz
Cc:  
Subject: Re: kern/73092: [patch] Unbreak WINE for 5.x and 6 [patches for both kern and port]
Date: Sat, 22 Jul 2006 18:28:53 +0200

 Also ref.: http://bugs.winehq.org/show_bug.cgi?id=5732
>Unformatted:
