From owner-freebsd-java@FreeBSD.ORG Thu Feb 16 21:38:52 2006 Return-Path: X-Original-To: freebsd-java@freebsd.org Delivered-To: freebsd-java@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E887D16A420 for ; Thu, 16 Feb 2006 21:38:51 +0000 (GMT) (envelope-from Arne.Juul@europe.yahoo-inc.com) Received: from mrout2.corp.ukl.yahoo.com (mrout2.corp.ukl.yahoo.com [217.12.1.88]) by mx1.FreeBSD.org (Postfix) with ESMTP id B87E043D46 for ; Thu, 16 Feb 2006 21:38:50 +0000 (GMT) (envelope-from Arne.Juul@europe.yahoo-inc.com) Received: from [172.24.94.128] (pat-gw.trondheim.corp.yahoo.com [217.144.236.4]) by mrout2.corp.ukl.yahoo.com (8.13.4/8.13.4/y.out) with ESMTP id k1GLcelp049634 for ; Thu, 16 Feb 2006 21:38:40 GMT DomainKey-Signature: a=rsa-sha1; s=serpent; d=yahoo-inc.com; c=nofws; q=dns; h=message-id:date:from:user-agent:x-accept-language: mime-version:to:subject:content-type; b=SbuFEs3J8sh8/S9QPadXiz7J1PzbDKsdj+v/o+twdRqzyPmzHsdgl4zor7qV4mB5 Message-ID: <43F4F112.8010202@europe.yahoo-inc.com> Date: Thu, 16 Feb 2006 22:39:30 +0100 From: Arne Juul User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923) X-Accept-Language: en-us, en MIME-Version: 1.0 To: freebsd-java@freebsd.org Content-Type: multipart/mixed; boundary="------------070902020207040407010707" Subject: executing data needs mprotect with PROT_EXEC X-BeenThere: freebsd-java@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Feb 2006 21:38:52 -0000 This is a multi-part message in MIME format. --------------070902020207040407010707 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 +#include 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. --------------070902020207040407010707 Content-Type: text/plain; name="patch-os_bsd_i486.cpp" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="patch-os_bsd_i486.cpp" --- ../../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(); --------------070902020207040407010707 Content-Type: text/plain; name="patch-vm_version_i486.cpp" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="patch-vm_version_i486.cpp" --- ../../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 +#include 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()); --------------070902020207040407010707--