commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1094631 - in /commons/sandbox/runtime/trunk/src/main/native: Makefile.unx.in os/unix/execmem.c
Date Mon, 18 Apr 2011 16:02:59 GMT
Author: mturk
Date: Mon Apr 18 16:02:59 2011
New Revision: 1094631

URL: http://svn.apache.org/viewvc?rev=1094631&view=rev
Log:
Add posix executable memory support

Added:
    commons/sandbox/runtime/trunk/src/main/native/os/unix/execmem.c   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in?rev=1094631&r1=1094630&r2=1094631&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in Mon Apr 18 16:02:59 2011
@@ -61,6 +61,7 @@ ASMSOURCES=\
 
 UNIX_SOURCES=\
 	$(TOPDIR)/os/unix/dso.c \
+	$(TOPDIR)/os/unix/execmem.c \
 	$(TOPDIR)/os/unix/init.c \
 	$(TOPDIR)/os/unix/platform.c \
 	$(TOPDIR)/os/unix/posixapi.c \

Added: commons/sandbox/runtime/trunk/src/main/native/os/unix/execmem.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/execmem.c?rev=1094631&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/execmem.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/execmem.c Mon Apr 18 16:02:59 2011
@@ -0,0 +1,75 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "acr/string.h"
+#include "acr/clazz.h"
+#include "acr/jniapi.h"
+#include "acr/port.h"
+#include "arch_opts.h"
+
+#include <sys/mman.h>
+
+J_DECLARE_CLAZZ = {
+    INVALID_FIELD_OFFSET,
+    0,
+    0,
+    0,
+    ACR_UNX_CP "PosixExecutableMemoryImpl"
+};
+
+J_DECLARE_M_ID(0000) = {
+    0,
+    "<init>",
+    "()V"
+};
+
+ACR_JNI_EXPORT(jobject, ExecutableMemoryImpl, init0)(JNI_STDARGS)
+{
+    if (_clazzn.u == 1)
+        return (*env)->NewObject(env, _clazzn.i, J4MID(0000));
+    if (AcrLoadClass(env, &_clazzn, 0) != 0) {
+        ACR_THROW_MSG(ACR_EX_EINSTANCE, "PosixExecutableMemoryImpl not initialized");
+        return 0;
+    }
+    R_LOAD_METHOD(0000, 0);
+    _clazzn.u = 1;
+    return (*env)->NewObject(env, _clazzn.i, J4MID(0000));
+}
+
+ACR_UNX_EXPORT(jlong, PosixExecutableMemory,  alloc0)(JNI_STDARGS, jint size)
+{
+    void *mem;
+
+    mem = mmap(0, size,
+               PROT_READ | PROT_WRITE | PROT_EXEC,
+               MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+    if (mem == MAP_FAILED) {
+        ACR_THROW_BY_ERRNO();
+        mem = 0;
+    }
+    return P2J(mem);
+}
+
+ACR_UNX_EXPORT(jint, PosixExecutableMemory,  free0)(JNI_STDARGS, jlong addr, jint size)
+{
+    void *mem = J2P(addr, void *);
+
+
+    if (munmap(mem, size) == 0)
+        return 0;
+    else
+        return ACR_GET_OS_ERROR();
+}

Propchange: commons/sandbox/runtime/trunk/src/main/native/os/unix/execmem.c
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message