You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/08/20 09:53:37 UTC
svn commit: r806076 -
/commons/sandbox/runtime/trunk/src/main/native/shared/shm.c
Author: mturk
Date: Thu Aug 20 07:53:37 2009
New Revision: 806076
URL: http://svn.apache.org/viewvc?rev=806076&view=rev
Log:
Add common shm code
Added:
commons/sandbox/runtime/trunk/src/main/native/shared/shm.c (with props)
Added: commons/sandbox/runtime/trunk/src/main/native/shared/shm.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/shm.c?rev=806076&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/shm.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/shm.c Thu Aug 20 07:53:37 2009
@@ -0,0 +1,141 @@
+/* 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.h"
+#include "acr_private.h"
+#include "acr_arch.h"
+#include "acr_clazz.h"
+#include "acr_error.h"
+#include "acr_memory.h"
+#include "acr_string.h"
+#include "acr_descriptor.h"
+#include "acr_pointer.h"
+#include "acr_shm.h"
+
+ACR_JNI_EXPORT_DECLARE(jobject, SharedMemory, create0)(ACR_JNISTDARGS,
+ jlong size)
+{
+
+ jobject shm = NULL;
+ UNREFERENCED_O;
+
+ shm = ACR_SharedMemoryObjectCreate(_E, NULL, size);
+
+ return shm;
+}
+
+ACR_JNI_EXPORT_DECLARE(jint, SharedMemory, close0)(ACR_JNISTDARGS,
+ jobject shmd)
+{
+ int rc = ACR_EBADF;
+ int sd;
+ UNREFERENCED_O;
+
+ sd = ACR_DescriptorGetInt(_E, shmd);
+ if (sd > 0) {
+ ACR_DescriptorClear(_E, shmd);
+ rc = ACR_ShmClose(_E, sd);
+ }
+ return rc;
+}
+
+ACR_JNI_EXPORT_DECLARE(jint, SharedMemory, detach0)(ACR_JNISTDARGS,
+ jobject shmd)
+{
+ int rc = ACR_EBADF;
+ int sd;
+ UNREFERENCED_O;
+
+ sd = ACR_DescriptorGetInt(_E, shmd);
+ if (sd > 0) {
+ ACR_DescriptorSetInt(_E, shmd, -1);
+ rc = ACR_ShmDetach(_E, sd);
+ }
+ return rc;
+}
+
+ACR_JNI_EXPORT_DECLARE(jobject, SharedMemory, map0)(ACR_JNISTDARGS,
+ jobject shmd)
+{
+ jobject mp = NULL;
+ int sd;
+
+ UNREFERENCED_O;
+
+ sd = ACR_DescriptorGetInt(_E, shmd);
+ if (sd > 0) {
+ char *mem = (char *)ACR_ShmGetBaseAddr(sd);
+ size_t len;
+ if (!mem) {
+ int rc = ACR_GET_OS_ERROR();
+ if (ACR_STATUS_IS_EACCES(rc))
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
+ else
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, rc);
+ return NULL;
+ }
+ len = ACR_ShmGetSize(sd);
+ mp = ACR_NewPointer(_E, mem, len, NULL);
+ }
+ return mp;
+}
+
+ACR_JNI_EXPORT_DECLARE(jobject, SharedMemory, map1)(ACR_JNISTDARGS,
+ jobject shmd,
+ jlong off, jlong siz)
+{
+ jobject mp = NULL;
+ int sd;
+
+ UNREFERENCED_O;
+
+ sd = ACR_DescriptorGetInt(_E, shmd);
+ if (sd > 0) {
+ char *mem = (char *)ACR_ShmGetBaseAddr(sd);
+ size_t len;
+ if (!mem) {
+ int rc = ACR_GET_OS_ERROR();
+ if (ACR_STATUS_IS_EACCES(rc))
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
+ else
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, rc);
+ return NULL;
+ }
+ len = ACR_ShmGetSize(sd);
+ if (len < (size_t)(off + siz)) {
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
+ return NULL;
+ }
+ mp = ACR_NewPointer(_E, mem + off, (size_t)siz, NULL);
+ }
+ return mp;
+}
+
+ACR_JNI_EXPORT_DECLARE(jlong, SharedMemory, size0)(ACR_JNISTDARGS,
+ jobject shmd)
+{
+ jlong rv = 0;
+ int sd;
+
+ UNREFERENCED_O;
+
+ sd = ACR_DescriptorGetInt(_E, shmd);
+ if (sd > 0) {
+ rv = (jlong)ACR_ShmGetSize(sd);
+ }
+ return rv;
+}
+
Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/shm.c
------------------------------------------------------------------------------
svn:eol-style = native