executing data needs mprotect with PROT_EXEC
Arne Juul
Arne.Juul at europe.yahoo-inc.com
Thu Feb 16 13:38:52 PST 2006
I've been trying to run some FreeBSD4 packages
inside a jail on a FreeBSD6 / amd64 box; and I've
hit a problem with ports/jdk.
A couple of places the VM uses an array of
integers, puts code in it, and executes it.
This doesn't work on machines where the CPU
honors the PROT_EXEC settings; this can be
different on different machines (depending on
BIOS settings probably).
The right fix is to call mprotect() from jdk to allow
execution of the memory in question, something like this:
--- ../../hotspot/src/os_cpu/bsd_i486/vm/os_bsd_i486.cpp Tue Feb
14 21:12:46 2006
+++ ../../hotspot/src/os_cpu/bsd_i486/vm/os_bsd_i486.cpp Wed Feb
15 16:30:49 2006
@@ -561,6 +562,9 @@
}
#else
static void (*fixcw)(void) = CAST_TO_FN_PTR(void (*)(void),
code_template);
+
+ ::mprotect((void *)code_template, sizeof(code_template),
+ PROT_EXEC | PROT_READ | PROT_WRITE);
#endif
fixcw();
--- ../../hotspot/src/cpu/i486/vm/vm_version_i486.cpp Thu Sep 11
03:40:14 2003
+++ ../../hotspot/src/cpu/i486/vm/vm_version_i486.cpp Tue Feb 14
23:34:40 2006
@@ -9,6 +9,8 @@
# include "incls/_precompiled.incl"
# include "incls/_vm_version_i486.cpp.incl"
+#include <sys/types.h>
+#include <sys/mman.h>
int VM_Version::_cpu;
int VM_Version::_cpuFeatures;
@@ -145,6 +147,10 @@
ResourceMark rm;
// Making this stub must be FIRST use of assembler
CodeBuffer* c = new CodeBuffer(address(stubCode), sizeof(stubCode));
+
+ ::mprotect((void *)stubCode, sizeof(stubCode),
+ PROT_EXEC | PROT_READ | PROT_WRITE);
+
VM_Version_StubGenerator g(c);
getPsrInfo_stub = CAST_TO_FN_PTR(_getPsrInfo_stub_t,
g.generate_getPsrInfo());
patches also attached in case the mail client mangles them :-)
- Arne H. J.
-------------- next part --------------
--- ../../hotspot/src/os_cpu/bsd_i486/vm/os_bsd_i486.cpp Tue Feb 14 21:12:46 2006
+++ ../../hotspot/src/os_cpu/bsd_i486/vm/os_bsd_i486.cpp Wed Feb 15 16:30:49 2006
@@ -561,6 +562,9 @@
}
#else
static void (*fixcw)(void) = CAST_TO_FN_PTR(void (*)(void), code_template);
+
+ ::mprotect((void *)code_template, sizeof(code_template),
+ PROT_EXEC | PROT_READ | PROT_WRITE);
#endif
fixcw();
-------------- next part --------------
--- ../../hotspot/src/cpu/i486/vm/vm_version_i486.cpp Thu Sep 11 03:40:14 2003
+++ ../../hotspot/src/cpu/i486/vm/vm_version_i486.cpp Tue Feb 14 23:34:40 2006
@@ -9,6 +9,8 @@
# include "incls/_precompiled.incl"
# include "incls/_vm_version_i486.cpp.incl"
+#include <sys/types.h>
+#include <sys/mman.h>
int VM_Version::_cpu;
int VM_Version::_cpuFeatures;
@@ -145,6 +147,10 @@
ResourceMark rm;
// Making this stub must be FIRST use of assembler
CodeBuffer* c = new CodeBuffer(address(stubCode), sizeof(stubCode));
+
+ ::mprotect((void *)stubCode, sizeof(stubCode),
+ PROT_EXEC | PROT_READ | PROT_WRITE);
+
VM_Version_StubGenerator g(c);
getPsrInfo_stub = CAST_TO_FN_PTR(_getPsrInfo_stub_t, g.generate_getPsrInfo());
More information about the freebsd-java
mailing list