From owner-freebsd-hackers@FreeBSD.ORG Mon Jul 24 15:06:21 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E1DCC16A4DD; Mon, 24 Jul 2006 15:06:20 +0000 (UTC) (envelope-from tijl@ulyssis.org) Received: from outmx013.isp.belgacom.be (outmx013.isp.belgacom.be [195.238.5.64]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4F5EC43D49; Mon, 24 Jul 2006 15:06:17 +0000 (GMT) (envelope-from tijl@ulyssis.org) Received: from outmx013.isp.belgacom.be (localhost [127.0.0.1]) by outmx013.isp.belgacom.be (8.12.11.20060308/8.12.11/Skynet-OUT-2.22) with ESMTP id k6OF6EM9027430; Mon, 24 Jul 2006 17:06:15 +0200 (envelope-from ) Received: from kalimero.kotnet.org (88.193-245-81.adsl-dyn.isp.belgacom.be [81.245.193.88]) by outmx013.isp.belgacom.be (8.12.11.20060308/8.12.11/Skynet-OUT-2.22) with ESMTP id k6OF6CZG027402; Mon, 24 Jul 2006 17:06:12 +0200 (envelope-from ) Received: from kalimero.kotnet.org (kalimero.kotnet.org [127.0.0.1]) by kalimero.kotnet.org (8.13.6/8.13.6) with ESMTP id k6OF684T047356; Mon, 24 Jul 2006 17:06:09 +0200 (CEST) (envelope-from tijl@ulyssis.org) From: Tijl Coosemans To: freebsd-hackers@freebsd.org Date: Mon, 24 Jul 2006 17:06:01 +0200 User-Agent: KMail/1.9.3 References: <200607221914.15826.lofi@freebsd.org> In-Reply-To: <200607221914.15826.lofi@freebsd.org> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart5011153.KMGMiH3a1f"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit Message-Id: <200607241706.08396.tijl@ulyssis.org> Cc: freebsd-emulation@freebsd.org, Michael Nottebrock Subject: Re: WINE vs. FreeBSD X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Jul 2006 15:06:21 -0000 --nextPart5011153.KMGMiH3a1f Content-Type: multipart/mixed; boundary="Boundary-01=_aHOxEESzu2uIOd8" Content-Transfer-Encoding: 7bit Content-Disposition: inline --Boundary-01=_aHOxEESzu2uIOd8 Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Saturday 22 July 2006 19:14, Michael Nottebrock wrote: > WINE does have certain requirements regarding memory allocation. In > particular it (or Windows, rather) really wants a few memory ranges > for itself: > > (from wine-0.9.17/loader/preloader.c): > > * 0x00000000 - 0x00110000 the DOS area > * 0x80000000 - 0x81000000 the shared heap > * ??? - ??? the PE binary load address (usually > starting at 0x00400000) > > The first two are particularly important for WINE running in win98 > (or earlier) emulation mode, which is currently completely broken on > FreeBSD, since those two memory ranges tend to be unavailable. The reason for the second range is that wine is located way at the end=20 of the 2G range (0x7bf00000). FreeBSD's mmap preserves heap space after=20 that (for brk(2) style allocations). This is about 512Mb by default so=20 everything in 0x7bf00000-0x9bf00000 is unavailable (unless MAP_FIXED is=20 used of course). The DOS area should be available but can't be allocated by wine because=20 of a FreeBSD specific quirk in its code to work arround another mmap=20 related problem. Both problems can be solved by locating wine at say 0x20000000 instead=20 of 0x7bf00000. That leaves plenty of space for the windows executable=20 and allows us to remove mmap related freebsd quirks from wine's code. I've attached two patches that accomplish this, but this seems to=20 trigger other problems, so use at your own risk. If you want to try=20 them, place them in the port's files/ directory and add a line=20 containing "USE_AUTOTOOLS=3D autoconf:259" to the Makefile. This seems to=20 break wine+libpthread, so I've also changed the port to use libthr=20 instead. =46or the libpthread experts, I haven't investigated that much further=20 yet, but libpthread seems to fail in create_stack() from=20 _pthread_create() from _thr_start_sig_daemon(). > The preloader bit from which this is quoted is WINE's "own shared > object loader that reserves memory that is important to Wine, and > then loads the main binary and its ELF interpreter", and obviously > does not work right on FreeBSD. I'm not sure whether it can be made > to or not, perhaps somebody familiar with both our VM and runtime > linker could take a look. The preloader isn't used on FreeBSD. You either run wine-kthread or=20 wine(-pthread) directly. The reason for the preloader in linux is=20 mainly exec-shield which makes the mapping of DSOs unpredictable. > http://bugs.winehq.org/show_bug.cgi?id=3D5732 Do the above mentioned patches solve your second issue here (PE exec=20 location)? > The other big issue with WINE on FreeBSD seems to be our threading > support. WINE quite reliably manages to confuse libpthread, see > http://www.freebsd.org/cgi/query-pr.cgi?pr=3Dthreads/100701. On SMP > machines, I've even been able to trigger kernel panics with WINE (in > win2k+ emulation mode) by merely hitting the close button on a > windows application (and WINE subsequently shutting down): >=20 http://lists.freebsd.org/pipermail/freebsd-stable/2006-June/026219.html.=20 > > WINE's threads interface can be found in loader/pthread.c and > loader/kthread.c - again, it would be great, if someone to whom that > sort of code means more than just random gibberish could take a look. Wine does some freaky stack manipulations. I think that may interfere=20 with the way our threading libs handle the stack (allocation etc.). But=20 I am just guessing here really. --Boundary-01=_aHOxEESzu2uIOd8 Content-Type: text/plain; charset="iso-8859-15"; name="patch-configure.ac" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="patch-configure.ac" =2D-- configure.ac.orig Mon Jul 10 18:01:07 2006 +++ configure.ac Mon Jul 24 15:42:41 2006 @@ -149,7 +149,7 @@ dnl Check for -lresolv for Mac OS X/Darwin AC_CHECK_LIB(resolv,res_9_init) dnl Check for -lpthread =2DAC_CHECK_LIB(pthread,pthread_create,AC_SUBST(LIBPTHREAD,"-lpthread")) +AC_CHECK_LIB(thr,pthread_create,AC_SUBST(LIBPTHREAD,"-lthr")) =20 AC_SUBST(XLIB,"") AC_SUBST(XFILES,"") @@ -1116,18 +1116,18 @@ ac_cv_ld_rpath=3D"yes",ac_cv_ld_rpath=3D"no")]) if test "$ac_cv_ld_rpath" =3D "yes" then =2D AC_SUBST(LDEXERPATH,["-Wl,--rpath,\\\$\$ORIGIN/\`\$(RELPATH) \= $(bindir) \$(libdir)\`"]) =2D AC_SUBST(LDDLLRPATH,["-Wl,--rpath,\\\$\$ORIGIN/\`\$(RELPATH) \= $(dlldir) \$(libdir)\`"]) + AC_SUBST(LDEXERPATH,["-Wl,--rpath,${libdir}"]) + AC_SUBST(LDDLLRPATH,["-Wl,--rpath,${libdir}"]) fi =20 case $host_cpu in *i[[3456789]]86* | x86_64) =2D AC_CACHE_CHECK([whether we can relocate the executable to 0x= 7bf00000], ac_cv_ld_reloc_exec, =2D [WINE_TRY_CFLAGS([-Wl,--section-start,.interp=3D0x7bf00400= ], + AC_CACHE_CHECK([whether we can relocate the executable to 0x20= 000000], ac_cv_ld_reloc_exec, + [WINE_TRY_CFLAGS([-Wl,--section-start,.interp=3D0x20000400], ac_cv_ld_reloc_exec=3D"yes", ac_cv_ld_reloc= _exec=3D"no")]) if test "$ac_cv_ld_reloc_exec" =3D "yes" then =2D LDEXECFLAGS=3D"$LDEXECFLAGS -Wl,--section-start,.interp=3D= 0x7bf00400" + LDEXECFLAGS=3D"$LDEXECFLAGS -Wl,--section-start,.interp=3D0x= 20000400" fi ;; esac --Boundary-01=_aHOxEESzu2uIOd8 Content-Type: text/plain; charset="iso-8859-15"; name="patch-libs-wine-mmap.c" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="patch-libs-wine-mmap.c" =2D-- libs/wine/mmap.c.orig Mon Jul 24 11:12:42 2006 +++ libs/wine/mmap.c Mon Jul 24 11:13:39 2006 @@ -200,11 +200,6 @@ =20 if (!(flags & MAP_FIXED)) { =2D#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) =2D /* Even FreeBSD 5.3 does not properly support NULL here. */ =2D if( start =3D=3D NULL ) start =3D (void *)0x110000; =2D#endif =2D #ifdef MAP_TRYFIXED /* If available, this will attempt a fixed mapping in-kernel */ flags |=3D MAP_TRYFIXED; @@ -318,7 +313,7 @@ { struct reserved_area *area; struct list *ptr; =2D#if defined(__i386__) && !defined(__FreeBSD__) && !defined(__FreeBSD_ker= nel__) /* commented out until FreeBSD gets fixed */ +#if defined(__i386__) char stack; char * const stack_ptr =3D &stack; char *user_space_limit =3D (char *)0x7ffe0000; --Boundary-01=_aHOxEESzu2uIOd8-- --nextPart5011153.KMGMiH3a1f Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.4 (FreeBSD) iD8DBQBExOHgdMR2xnarec8RAmaXAKCMOnNwdauewwJkZeVFnJGb7C+gcwCgx/7Y zrPmcSy7QfdMB6TliKSi61k= =hLF8 -----END PGP SIGNATURE----- --nextPart5011153.KMGMiH3a1f--