wxneeded for dosbox

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

wxneeded for dosbox

Benjamin Baier
Patch to add wxneeded to dosbox. I got a application that otherwise
crashes with the following dosbox error message.

>Setting excute permission on the code cache has failed
>Exit to error: DRC64:Unhandled memory reference

Sat Mar 25 14:59:35 CET 2017
/usr/ports/emulators/dosbox
Index: Makefile
===================================================================
RCS file: /cvs/ports/emulators/dosbox/Makefile,v
retrieving revision 1.31
diff -u -p -r1.31 Makefile
--- Makefile 24 Dec 2015 13:08:12 -0000 1.31
+++ Makefile 25 Mar 2017 13:59:32 -0000
@@ -1,11 +1,12 @@
 # $OpenBSD: Makefile,v 1.31 2015/12/24 13:08:12 bentley Exp $
 
 ONLY_FOR_ARCHS= ${GCC4_ARCHS}
+USE_WXNEEDED= Yes
 
 COMMENT= x86 with DOS emulator targeted at playing games
 
 DISTNAME= dosbox-0.74
-REVISION= 6
+REVISION= 7
 CATEGORIES= games x11 emulators
 MASTER_SITES= ${MASTER_SITE_SOURCEFORGE:=dosbox/}
 

Reply | Threaded
Open this post in threaded view
|

Re: wxneeded for dosbox

Giannis Tsaraias
On Sat, Mar 25, 2017 at 03:24:26PM +0100, Benjamin Baier wrote:
> Patch to add wxneeded to dosbox. I got a application that otherwise
> crashes with the following dosbox error message.
>
> >Setting excute permission on the code cache has failed
> >Exit to error: DRC64:Unhandled memory reference
>

I saw the W^X violation too and had to do this, but forgot to send the diff.
FWIW, OK tsg@ if someone wants to commit.

Reply | Threaded
Open this post in threaded view
|

Re: wxneeded for dosbox

Hiltjo Posthuma
On Sat, Mar 25, 2017 at 05:43:27PM +0200, Giannis Tsaraias wrote:

> On Sat, Mar 25, 2017 at 03:24:26PM +0100, Benjamin Baier wrote:
> > Patch to add wxneeded to dosbox. I got a application that otherwise
> > crashes with the following dosbox error message.
> >
> > >Setting excute permission on the code cache has failed
> > >Exit to error: DRC64:Unhandled memory reference
> >
>
> I saw the W^X violation too and had to do this, but forgot to send the diff.
> FWIW, OK tsg@ if someone wants to commit.
>

Hey,

I noticed it too while playing Mortal Kombat 1 :)

Some other games (skiordi, stunts) don't crash.

--
Kind regards,
Hiltjo

Reply | Threaded
Open this post in threaded view
|

Re: wxneeded for dosbox

Jonathan Gray-11
On Sat, Mar 25, 2017 at 06:51:32PM +0100, Hiltjo Posthuma wrote:

> On Sat, Mar 25, 2017 at 05:43:27PM +0200, Giannis Tsaraias wrote:
> > On Sat, Mar 25, 2017 at 03:24:26PM +0100, Benjamin Baier wrote:
> > > Patch to add wxneeded to dosbox. I got a application that otherwise
> > > crashes with the following dosbox error message.
> > >
> > > >Setting excute permission on the code cache has failed
> > > >Exit to error: DRC64:Unhandled memory reference
> > >
> >
> > I saw the W^X violation too and had to do this, but forgot to send the diff.
> > FWIW, OK tsg@ if someone wants to commit.
> >
>
> Hey,
>
> I noticed it too while playing Mortal Kombat 1 :)
>
> Some other games (skiordi, stunts) don't crash.

Instead of blindly setting USE_WXNEEDED, I'd prefer if someone who has
a case that triggers this can try disabling the various cpu core options
in configure.

Reply | Threaded
Open this post in threaded view
|

Re: wxneeded for dosbox

Theo de Raadt-2
> On Sat, Mar 25, 2017 at 06:51:32PM +0100, Hiltjo Posthuma wrote:
> > On Sat, Mar 25, 2017 at 05:43:27PM +0200, Giannis Tsaraias wrote:
> > > On Sat, Mar 25, 2017 at 03:24:26PM +0100, Benjamin Baier wrote:
> > > > Patch to add wxneeded to dosbox. I got a application that otherwise
> > > > crashes with the following dosbox error message.
> > > >
> > > > >Setting excute permission on the code cache has failed
> > > > >Exit to error: DRC64:Unhandled memory reference
> > > >
> > >
> > > I saw the W^X violation too and had to do this, but forgot to send the diff.
> > > FWIW, OK tsg@ if someone wants to commit.
> > >
> >
> > Hey,
> >
> > I noticed it too while playing Mortal Kombat 1 :)
> >
> > Some other games (skiordi, stunts) don't crash.
>
> Instead of blindly setting USE_WXNEEDED, I'd prefer if someone who has
> a case that triggers this can try disabling the various cpu core options
> in configure.

so true

wxneeded was added as tooling, so that hopefully the greater community
would try to fix programs

instead, people are just marking the programs with it

pretty sad, but I guess that's the way the world works

Reply | Threaded
Open this post in threaded view
|

Re: wxneeded for dosbox

Hiltjo Posthuma
In reply to this post by Jonathan Gray-11
On Sun, Mar 26, 2017 at 11:37:21AM +1100, Jonathan Gray wrote:

> On Sat, Mar 25, 2017 at 06:51:32PM +0100, Hiltjo Posthuma wrote:
> > On Sat, Mar 25, 2017 at 05:43:27PM +0200, Giannis Tsaraias wrote:
> > > On Sat, Mar 25, 2017 at 03:24:26PM +0100, Benjamin Baier wrote:
> > > > Patch to add wxneeded to dosbox. I got a application that otherwise
> > > > crashes with the following dosbox error message.
> > > >
> > > > >Setting excute permission on the code cache has failed
> > > > >Exit to error: DRC64:Unhandled memory reference
> > > >
> > >
> > > I saw the W^X violation too and had to do this, but forgot to send the diff.
> > > FWIW, OK tsg@ if someone wants to commit.
> > >
> >
> > Hey,
> >
> > I noticed it too while playing Mortal Kombat 1 :)
> >
> > Some other games (skiordi, stunts) don't crash.
>
> Instead of blindly setting USE_WXNEEDED, I'd prefer if someone who has
> a case that triggers this can try disabling the various cpu core options
> in configure.

Hey,

I think the issue is with the CPU core=dynamic. It uses a cache and sets
PROT_WRITE|PROT_EXEC on a region.

The log message is found in the files:

./src/cpu/core_dynrec/cache.h:
        LOG_MSG("Setting excute permission on the code cache has failed");
./src/cpu/core_dyn_x86/cache.h:
        LOG_MSG("Setting excute permission on the code cache has failed!");

        and the code:

        if(mprotect(cache_code_link_blocks,CACHE_TOTAL+CACHE_MAXSIZE+PAGESIZE_TEMP,PROT_WRITE|PROT_READ|PROT_EXEC))
                Log_MSG("Setting excute permission on the code cache has failed!");


To workaround this, but without requiring WXNEEDED:
Change in the dosbox config:

        [cpu]
        core=dynamic
        cycles=auto

to:

        [cpu]
        core=normal
        cycles=10000

I don't have the knowledge to patch core=dynamic, but hopefully this
information helps in some way.

--
Kind regards,
Hiltjo

Reply | Threaded
Open this post in threaded view
|

Re: wxneeded for dosbox

Giannis Tsaraias
In reply to this post by Jonathan Gray-11
On Sun, Mar 26, 2017 at 11:37:21AM +1100, Jonathan Gray wrote:

> On Sat, Mar 25, 2017 at 06:51:32PM +0100, Hiltjo Posthuma wrote:
> > On Sat, Mar 25, 2017 at 05:43:27PM +0200, Giannis Tsaraias wrote:
> > > On Sat, Mar 25, 2017 at 03:24:26PM +0100, Benjamin Baier wrote:
> > > > Patch to add wxneeded to dosbox. I got a application that otherwise
> > > > crashes with the following dosbox error message.
> > > >
> > > > >Setting excute permission on the code cache has failed
> > > > >Exit to error: DRC64:Unhandled memory reference
> > > >
> > >
> > > I saw the W^X violation too and had to do this, but forgot to send the diff.
> > > FWIW, OK tsg@ if someone wants to commit.
> > >
> >
> > Hey,
> >
> > I noticed it too while playing Mortal Kombat 1 :)
> >
> > Some other games (skiordi, stunts) don't crash.
>
> Instead of blindly setting USE_WXNEEDED, I'd prefer if someone who has
> a case that triggers this can try disabling the various cpu core options
> in configure.

As Hiltjo mentioned, there are calls to mprotect asking for both write and
execute in ./src/cpu/core_dynrec/cache.h and ./src/cpu/core_dyn_x86/cache.h.

Compiling with '--disable-dynamic-core', I tested a few executables on i386
and amd64 without managing to trigger a violation. Didn't notice any performance
loss either. No need for wxneeded this way.

'--disable-dynrec' is not enough, as I got a violation on i386 using it.

Reply | Threaded
Open this post in threaded view
|

Re: wxneeded for dosbox

Stuart Henderson
On 2017/03/26 16:50, Giannis Tsaraias wrote:

> On Sun, Mar 26, 2017 at 11:37:21AM +1100, Jonathan Gray wrote:
> > On Sat, Mar 25, 2017 at 06:51:32PM +0100, Hiltjo Posthuma wrote:
> > > On Sat, Mar 25, 2017 at 05:43:27PM +0200, Giannis Tsaraias wrote:
> > > > On Sat, Mar 25, 2017 at 03:24:26PM +0100, Benjamin Baier wrote:
> > > > > Patch to add wxneeded to dosbox. I got a application that otherwise
> > > > > crashes with the following dosbox error message.
> > > > >
> > > > > >Setting excute permission on the code cache has failed
> > > > > >Exit to error: DRC64:Unhandled memory reference
> > > > >
> > > >
> > > > I saw the W^X violation too and had to do this, but forgot to send the diff.
> > > > FWIW, OK tsg@ if someone wants to commit.
> > > >
> > >
> > > Hey,
> > >
> > > I noticed it too while playing Mortal Kombat 1 :)
> > >
> > > Some other games (skiordi, stunts) don't crash.
> >
> > Instead of blindly setting USE_WXNEEDED, I'd prefer if someone who has
> > a case that triggers this can try disabling the various cpu core options
> > in configure.
>
> As Hiltjo mentioned, there are calls to mprotect asking for both write and
> execute in ./src/cpu/core_dynrec/cache.h and ./src/cpu/core_dyn_x86/cache.h.
>
> Compiling with '--disable-dynamic-core', I tested a few executables on i386
> and amd64 without managing to trigger a violation. Didn't notice any performance
> loss either. No need for wxneeded this way.
>
> '--disable-dynrec' is not enough, as I got a violation on i386 using it.
>

So..

Index: Makefile
===================================================================
RCS file: /cvs/ports/emulators/dosbox/Makefile,v
retrieving revision 1.32
diff -u -p -r1.32 Makefile
--- Makefile 25 Mar 2017 15:53:56 -0000 1.32
+++ Makefile 28 Mar 2017 10:41:21 -0000
@@ -1,12 +1,11 @@
 # $OpenBSD: Makefile,v 1.32 2017/03/25 15:53:56 landry Exp $
 
 ONLY_FOR_ARCHS= ${GCC4_ARCHS}
-USE_WXNEEDED= Yes
 
 COMMENT= x86 with DOS emulator targeted at playing games
 
 DISTNAME= dosbox-0.74
-REVISION= 7
+REVISION= 8
 CATEGORIES= games x11 emulators
 MASTER_SITES= ${MASTER_SITE_SOURCEFORGE:=dosbox/}
 
@@ -34,6 +33,9 @@ CONFIGURE_STYLE= gnu
 CONFIGURE_ENV=CPPFLAGS="-I${LOCALBASE}/include -I${X11BASE}/include"
 CONFIGURE_ENV+=LDFLAGS="-L${LOCALBASE}/lib -L${X11BASE}/lib"
 CONFIGURE_ARGS+= --disable-alsatest
+
+# needs W+X memory
+CONFIGURE_ARGS+= --disable-dynamic-core
 
 pre-configure:
  cp ${FILESDIR}/midi_sndio.h ${WRKSRC}/src/gui

Reply | Threaded
Open this post in threaded view
|

Re: wxneeded for dosbox

Benjamin Baier
On Tue, 28 Mar 2017 11:42:00 +0100
Stuart Henderson <[hidden email]> wrote:

> On 2017/03/26 16:50, Giannis Tsaraias wrote:
> > On Sun, Mar 26, 2017 at 11:37:21AM +1100, Jonathan Gray wrote:  
> > > On Sat, Mar 25, 2017 at 06:51:32PM +0100, Hiltjo Posthuma wrote:  
> > > > On Sat, Mar 25, 2017 at 05:43:27PM +0200, Giannis Tsaraias wrote:  
> > > > > On Sat, Mar 25, 2017 at 03:24:26PM +0100, Benjamin Baier wrote:  
> > > > > > Patch to add wxneeded to dosbox. I got a application that otherwise
> > > > > > crashes with the following dosbox error message.
> > > > > >  
> > > > > > >Setting excute permission on the code cache has failed
> > > > > > >Exit to error: DRC64:Unhandled memory reference  
> > > > > >  
> > > > >
> > > > > I saw the W^X violation too and had to do this, but forgot to send the diff.
> > > > > FWIW, OK tsg@ if someone wants to commit.
> > > > >  
> > > >
> > > > Hey,
> > > >
> > > > I noticed it too while playing Mortal Kombat 1 :)
> > > >
> > > > Some other games (skiordi, stunts) don't crash.  
> > >
> > > Instead of blindly setting USE_WXNEEDED, I'd prefer if someone who has
> > > a case that triggers this can try disabling the various cpu core options
> > > in configure.  
> >
> > As Hiltjo mentioned, there are calls to mprotect asking for both write and
> > execute in ./src/cpu/core_dynrec/cache.h and ./src/cpu/core_dyn_x86/cache.h.
> >
> > Compiling with '--disable-dynamic-core', I tested a few executables on i386
> > and amd64 without managing to trigger a violation. Didn't notice any performance
> > loss either. No need for wxneeded this way.
> >
> > '--disable-dynrec' is not enough, as I got a violation on i386 using it.
> >  
>
> So..
>
> Index: Makefile
> ===================================================================
> RCS file: /cvs/ports/emulators/dosbox/Makefile,v
> retrieving revision 1.32
> diff -u -p -r1.32 Makefile
> --- Makefile 25 Mar 2017 15:53:56 -0000 1.32
> +++ Makefile 28 Mar 2017 10:41:21 -0000
> @@ -1,12 +1,11 @@
>  # $OpenBSD: Makefile,v 1.32 2017/03/25 15:53:56 landry Exp $
>  
>  ONLY_FOR_ARCHS= ${GCC4_ARCHS}
> -USE_WXNEEDED= Yes
>  
>  COMMENT= x86 with DOS emulator targeted at playing games
>  
>  DISTNAME= dosbox-0.74
> -REVISION= 7
> +REVISION= 8
>  CATEGORIES= games x11 emulators
>  MASTER_SITES= ${MASTER_SITE_SOURCEFORGE:=dosbox/}
>  
> @@ -34,6 +33,9 @@ CONFIGURE_STYLE= gnu
>  CONFIGURE_ENV=CPPFLAGS="-I${LOCALBASE}/include -I${X11BASE}/include"
>  CONFIGURE_ENV+=LDFLAGS="-L${LOCALBASE}/lib -L${X11BASE}/lib"
>  CONFIGURE_ARGS+= --disable-alsatest
> +
> +# needs W+X memory
> +CONFIGURE_ARGS+= --disable-dynamic-core
>  
>  pre-configure:
>   cp ${FILESDIR}/midi_sndio.h ${WRKSRC}/src/gui
>

I have the same in my tree for 2 days. Works for me so far.
No objections.