[MPlayer-dev-eng] amd64 -sws 0 fix (iow: playing with NX bit)

Trent Piepho xyzzy at speakeasy.org
Fri Jan 21 00:05:06 CET 2005


On Thu, 20 Jan 2005, Aurelien Jacobs wrote:
> new feature introduced by amd64, which is called NX bit....
> Yes, you've got it. The CPU simply prevent the execution of
> this code which is in a data segment, causing a segfault.
> 
> Now the question is how to solve this, cleanly ?
> I can see few options :
> (5) Probably other solutions, maybe better...

Maybe it is possible to load the generated code via dlopen() or something like
it? 

The following script works for me on ia32, does it work with NX?

cat > dl.s <<EOF
.text
        .align 4
.globl foo
        .type    foo, at function
foo:
.byte 184, 42, 0, 0, 0, 195
        .size    foo,6
EOF
as -o dl.o dl.s
ld -Bshareable -o dl.so dl.o
mv dl.so /tmp  # need to know absolute path
cat > dl_test.c <<EOF
#include <dlfcn.h>
main() {
    void *dl = dlopen("/tmp/dl.so", RTLD_LAZY);      
    int (*foo)(void) = dlsym(dl, "foo"); 
    printf("%d should be 42\n", foo()); }   
EOF
gcc dl_test.c -ldl
a.out




More information about the MPlayer-dev-eng mailing list