Get libffi closures to cope with SELinux execmem/execmod

Alexandre Oliva aoliva@redhat.com
Wed Mar 7 07:53:00 GMT 2007


On Mar  5, 2007, Tom Tromey <tromey@redhat.com> wrote:

>>>>>> "Alexandre" == Alexandre Oliva <aoliva@redhat.com> writes:
Alexandre> On Feb 15, 2007, Tom Tromey <tromey@redhat.com> wrote:
>>> It is ok to have the libjava code directly call ffi_closure_alloc and
>>> ffi_closure_free.  We're already making direct calls to the various
>>> ffi functions, so this extra layer isn't needed.

Alexandre> Done in the revised patch below.  Retested on
Alexandre> x86_64-linux-gnu.  Ok to install?

> If there are no other remaining objections or concerns, then yes.
> (I forgot the state of the thread while traveling :-)

Thanks, I had to tweak the changes to natVMProxy.cc to account for the
removal of one of the arguments from ncode.  Here's the revised patch
for that file.  The rest of the patch went in exactly as posted
before.

Index: libjava/java/lang/reflect/natVMProxy.cc
===================================================================
--- libjava/java/lang/reflect/natVMProxy.cc.orig	2007-03-07 04:20:58.000000000 -0300
+++ libjava/java/lang/reflect/natVMProxy.cc	2007-03-07 04:24:29.000000000 -0300
@@ -1,6 +1,6 @@
 // natVMProxy.cc -- Implementation of VMProxy methods.
 
-/* Copyright (C) 2006
+/* Copyright (C) 2006, 2007
    Free Software Foundation
 
    This file is part of libgcj.
@@ -66,7 +66,7 @@ using namespace java::lang::reflect;
 using namespace java::lang;
 
 typedef void (*closure_fun) (ffi_cif*, void*, void**, void*);
-static void *ncode (_Jv_Method *self, closure_fun fun);
+static void *ncode (jclass klass, _Jv_Method *self, closure_fun fun);
 static void run_proxy (ffi_cif*, void*, void**, void*);
 
 typedef jobject invoke_t (jobject, Proxy *, Method *, JArray< jobject > *);
@@ -165,7 +165,7 @@ java::lang::reflect::VMProxy::generatePr
       // the interfaces of which it is a proxy will also be reachable,
       // so this is safe.
       method = imethod;
-      method.ncode = ncode (&method, run_proxy);
+      method.ncode = ncode (klass, &method, run_proxy);
       method.accflags &= ~Modifier::ABSTRACT;
     }
 
@@ -289,6 +289,7 @@ unbox (jobject o, jclass klass, void *rv
 
 typedef struct {
   ffi_closure  closure;
+  _Jv_ClosureList list;
   ffi_cif   cif;
   _Jv_Method *self;
   ffi_type *arg_types[0];
@@ -366,16 +367,19 @@ run_proxy (ffi_cif *cif,
 // the address of its closure.
 
 static void *
-ncode (_Jv_Method *self, closure_fun fun)
+ncode (jclass klass, _Jv_Method *self, closure_fun fun)
 {
   using namespace java::lang::reflect;
 
   jboolean staticp = (self->accflags & Modifier::STATIC) != 0;
   int arg_count = _Jv_count_arguments (self->signature, staticp);
 
+  void *code;
   ncode_closure *closure =
-    (ncode_closure*)_Jv_AllocBytes (sizeof (ncode_closure)
-				    + arg_count * sizeof (ffi_type*));
+    (ncode_closure*)ffi_closure_alloc (sizeof (ncode_closure)
+				       + arg_count * sizeof (ffi_type*),
+				       &code);
+  closure->list.registerClosure (klass, closure);
 
   _Jv_init_cif (self->signature,
 		arg_count,
@@ -387,11 +391,12 @@ ncode (_Jv_Method *self, closure_fun fun
 
   JvAssert ((self->accflags & Modifier::NATIVE) == 0);
 
-  ffi_prep_closure (&closure->closure,
-		    &closure->cif, 
-		    fun,
-		    (void*)closure);
+  ffi_prep_closure_loc (&closure->closure,
+			&closure->cif,
+			fun,
+			code,
+			code);
 
-  self->ncode = (void*)closure;
+  self->ncode = code;
   return self->ncode;
 }

-- 
Alexandre Oliva         http://www.lsd.ic.unicamp.br/~oliva/
FSF Latin America Board Member         http://www.fsfla.org/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}



More information about the Gcc-patches mailing list