Re: wxneeded for dosbox

2017-03-28 Thread Benjamin Baier
On Tue, 28 Mar 2017 11:42:00 +0100
Stuart Henderson <s...@spacehopper.org> 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 -  1.32
> +++ Makefile  28 Mar 2017 10:41:21 -
> @@ -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.



Re: wxneeded for dosbox

2017-03-28 Thread 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
--- Makefile25 Mar 2017 15:53:56 -  1.32
+++ Makefile28 Mar 2017 10:41:21 -
@@ -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



Re: wxneeded for dosbox

2017-03-26 Thread Giannis Tsaraias
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.



Re: wxneeded for dosbox

2017-03-26 Thread Hiltjo Posthuma
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=1

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

-- 
Kind regards,
Hiltjo



Re: wxneeded for dosbox

2017-03-25 Thread Theo de Raadt
> 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



Re: wxneeded for dosbox

2017-03-25 Thread Jonathan Gray
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.



Re: wxneeded for dosbox

2017-03-25 Thread 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



Re: wxneeded for dosbox

2017-03-25 Thread 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.



wxneeded for dosbox

2017-03-25 Thread 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
--- Makefile24 Dec 2015 13:08:12 -  1.31
+++ Makefile25 Mar 2017 13:59:32 -
@@ -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/}