commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r806804 - /commons/sandbox/runtime/trunk/src/main/native/os/win32/dso.c
Date Sat, 22 Aug 2009 07:55:56 GMT
Author: mturk
Date: Sat Aug 22 07:55:55 2009
New Revision: 806804

URL: http://svn.apache.org/viewvc?rev=806804&view=rev
Log:
Implement win32 dso

Added:
    commons/sandbox/runtime/trunk/src/main/native/os/win32/dso.c   (with props)

Added: commons/sandbox/runtime/trunk/src/main/native/os/win32/dso.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/dso.c?rev=806804&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/dso.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/dso.c Sat Aug 22 07:55:55 2009
@@ -0,0 +1,108 @@
+/* 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_error.h"
+#include "acr_memory.h"
+#include "acr_string.h"
+#include "acr_descriptor.h"
+#include "acr_dso.h"
+
+static int dso_cleanup(void *dso, int type, unsigned int flags)
+{
+    if (type != ACR_DT_DSO) {
+        if (!FreeLibrary(dso) != 0)
+            return ACR_GET_OS_ERROR();
+        else
+            return ACR_SUCCESS;
+    }
+    return ACR_EINVAL;
+}
+
+ACR_DECLARE(int) ACR_DsoLoad(JNIEnv *_E, const acr_pchar_t *path)
+{
+    HINSTANCE handle;
+    UINT      em;
+    int       rc = 0;
+
+    /* Do not display message box */ 
+    em = SetErrorMode(SEM_FAILCRITICALERRORS);
+
+    handle = LoadLibraryExW(path, NULL, 0);
+    if (!handle)
+        handle = LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
+    if (!handle) {
+        wchar_t *ignored;
+        wchar_t fpath[ACR_HBUFF_SIZ];
+        rv = ACR_GET_OS_ERROR();
+        if (GetFullPathNameW(path, ACR_HBUFF_LEN, fpath, &ignored)) {
+            if (SetDllDirectoryW(fpath)) {
+                handle = LoadLibraryExW(path, NULL, 0);
+                if (!handle)
+                    handle = LoadLibraryExW(path, NULL,
+                                            LOAD_WITH_ALTERED_SEARCH_PATH);
+                if (handle)
+                    rc = 0;
+                }
+        }
+    }
+    /* Restore original error mode */ 
+    SetErrorMode(em);
+    if (rc) {
+        ACR_THROW_IO_IF_ERR(rc);
+        return -1;
+    }
+    rc = acr_ioh_open(handle, ACR_DT_DSO, 0, dso_cleanup);
+    return rc;
+}
+
+ACR_DECLARE(int) ACR_DsoUnload(JNIEnv *_E, int dso)
+{
+    int rc;
+
+    if (ACR_IOH_TYPE(dso) != ACR_DT_DSO) {
+        ACR_THROW_EX_IF_ERR(ACR_EX_EINVAL, ACR_EFTYPE);
+        return ACR_EINVAL;
+    }
+    rc = acr_ioh_close(dso);
+    ACR_THROW_IO_IF_ERR(rc);
+    return rc;
+}
+
+ACR_DECLARE(void *) ACR_DsoSym(JNIEnv *_E, int dso, const char *symname)
+{
+    int rc;
+    void *handle = ACR_IOH(dso);
+
+    if (IS_INVALID_HANDLE(handle) || ACR_IOH_TYPE(dso) != ACR_DT_DSO) {
+        ACR_THROW_EX_IF_ERR(ACR_EX_EINVAL, ACR_EINVAL);
+        return NULL;
+    }
+    else {
+        void *retval = GetProcAddress(handle, symname);
+        if (retval == NULL) {
+            rc = ACR_GET_OS_ERROR();
+            if (IS_VALID_HANDLE(_E)) {
+                ACR_ThrowExceptionA(_E, THROW_NMARK, ACR_EX_ULINK, dlerror());
+            }
+            ACR_SET_OS_ERROR(rc);
+        }
+        return retval;
+    }
+}
+

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



Mime
View raw message