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/04/09 13:08:58 UTC

svn commit: r763600 - in /commons/sandbox/runtime/trunk/src/main/native: ./ include/ include/arch/windows/ os/unix/ os/win32/

Author: mturk
Date: Thu Apr  9 11:08:58 2009
New Revision: 763600

URL: http://svn.apache.org/viewvc?rev=763600&view=rev
Log:
Add initial win32 code

Added:
    commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in   (with props)
    commons/sandbox/runtime/trunk/src/main/native/os/win32/apache.ico   (with props)
    commons/sandbox/runtime/trunk/src/main/native/os/win32/logmessages.bin   (with props)
    commons/sandbox/runtime/trunk/src/main/native/os/win32/logmessages.mc   (with props)
    commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c   (with props)
    commons/sandbox/runtime/trunk/src/main/native/os/win32/main.rc   (with props)
    commons/sandbox/runtime/trunk/src/main/native/os/win32/syslog.c   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/native/Makefile.in
    commons/sandbox/runtime/trunk/src/main/native/configure
    commons/sandbox/runtime/trunk/src/main/native/include/acr.h
    commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/main.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/os.c

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.in?rev=763600&r1=763599&r2=763600&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.in Thu Apr  9 11:08:58 2009
@@ -103,7 +103,7 @@
 
 distclean: clean
 	rm -f $(TOPDIR)/Makefile
-	rm -f $(INCDIR)/cconfig.h
+	rm -f $(INCDIR)/ccconfig.h
 	rm -rf $(BLDDIR)
 
 install: all

Added: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=763600&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (added)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Thu Apr  9 11:08:58 2009
@@ -0,0 +1,98 @@
+# 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.
+#
+# ====================================================================
+#
+# Apache Commons Runtime Windows Makefile
+# 
+#
+# ====================================================================
+#
+
+NAME=@name@
+HOST=@host@
+MACH=@mach@
+BITS=@bits@
+CC=@cc@
+SO=@so@
+OBJ=@obj@
+EXE=@exe@
+AR=@ar@
+RANLIB=@ranlib@
+PREFIX=@prefix@
+LIBDIR=@libdir@
+TOPDIR=@topdir@
+CPP=@cpp@
+CXX=@cxx@
+CFLAGS=@ccflags@ -DACR_DECLARE_EXPORT -DACR_CORE_PRIVATE
+CPPFLAGS=@cppopts@
+CXXFLAGS=@cxxopts@
+LDFLAGS=@ldflags@
+SHFLAGS=@shflags@
+INCLUDES=@includes@
+
+LINK=link.exe
+RC=rc.exe
+MT=mt.exe
+
+DESTDIR=$(PREFIX)
+SONAME=lib$(NAME)$(SO)
+SHAREDLIB=lib$(NAME)$(SO)
+
+SRCDIR=$(TOPDIR)
+INCDIR=$(TOPDIR)/include
+BLDDIR=$(TOPDIR)\.libs
+PWDDIR=$(PWD)
+
+COMMON_OBJS=\
+	$(SRCDIR)/shared/dbb.$(OBJ) \
+	$(SRCDIR)/shared/error.$(OBJ)
+
+WINDOWS_OBJS= \
+	$(SRCDIR)/os/win32/main.$(OBJ) \
+	$(SRCDIR)/os/win32/os.$(OBJ) \
+	$(SRCDIR)/os/win32/syslog.$(OBJ)
+
+all: setup $(SHAREDLIB)
+
+.c.$(OBJ):
+	$(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDES) -c -Fo$@ $<
+
+.cpp.$(OBJ):
+	$(CXX) $(CFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(INCLUDES) -c -Fo$@ $<
+
+$(SHAREDLIB): $(COMMON_OBJS) $(@platform@_OBJS)
+	$(RC) /l 0x409 /d "NDEBUG" /i "$(SRCDIR)\include" /fo $(BLDDIR)\$(NAME).res $(SRCDIR)/os/win32/main.rc 
+	$(LINK) $(SHFLAGS) $(LDFLAGS) /DLL /SUBSYSTEM:WINDOWS $(COMMON_OBJS) $(WINDOWS_OBJS) $(BLDDIR)\$(NAME).res /out:$(BLDDIR)/$@
+	IF EXIST $(BLDDIR)/$(SHAREDLIB).manifest \
+		mt -nologo -manifest  $(BLDDIR)/$(SHAREDLIB).manifest -outputresource:$(BLDDIR)/$(SHAREDLIB);2 
+
+setup:
+	@if not exist "$(BLDDIR)\$(NULL)" mkdir "$(BLDDIR)" 
+
+clean:
+	-@del /Q $(SRCDIR)\*.pdb 2>NUL
+	-@del /Q $(SRCDIR)\shared\*.$(OBJ) 2>NUL
+	-@del /Q $(SRCDIR)\os\win32\*$(OBJ) 2>NUL
+	-@del /Q $(BLDDIR)\*  2>NUL
+
+distclean: clean
+	-@del /Q $(TOPDIR)\Makefile 2>NUL
+	-@del /Q $(SRCDIR)\include\ccconfig.h 2>NUL
+	@if exist "$(BLDDIR)\$(NULL)" rd /s /q $(BLDDIR) 
+
+install: all
+	@if not exist "$(DESTDIR)\include\$(NULL)" mkdir "$(DESTDIR)\include" 
+	@if not exist "$(DESTDIR)\$(LIBDIR)\$(NULL)" mkdir "$(DESTDIR)\$(LIBDIR)" 

Propchange: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/configure
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/configure?rev=763600&r1=763599&r2=763600&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/configure (original)
+++ commons/sandbox/runtime/trunk/src/main/native/configure Thu Apr  9 11:08:58 2009
@@ -60,7 +60,7 @@
 obj="o"
 bits=""
 nmake=""
-java_home="$JAVA_HOME"
+java_home="`echo $JAVA_HOME | tr '\\' '/' 2>/dev/null`"
 java_pinc=""
 has_dso_test=false
 has_jni=false
@@ -295,7 +295,7 @@
         varadds cppopts "-D_WIN32_WINNT=0x0501 -D_WIN32_IE=0x0600"
         varadds cxxopts "/TP"
         varadds ldflags "kernel32.lib advapi32.lib ws2_32.lib mswsock.lib"
-        varadds ldflags "ole32.lib shell32.lib rpcrt4.lib"
+        varadds ldflags "ole32.lib shell32.lib rpcrt4.lib user32.lib"
         varadds shflags "/NOLOGO /OPT:REF"
         so=".dll"
         exe=".exe"

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr.h?rev=763600&r1=763599&r2=763600&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr.h Thu Apr  9 11:08:58 2009
@@ -37,6 +37,11 @@
 #include <winsock2.h>
 #include <mswsock.h>
 #include <ws2tcpip.h>
+#include <psapi.h>
+
+/* Define synonims for some common posix functions */
+#define snprintf        _snprintf
+
 #endif /* HAVE_WINDOWS_H */
 
 #include <stdlib.h>

Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h?rev=763600&r1=763599&r2=763600&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h Thu Apr  9 11:08:58 2009
@@ -43,6 +43,7 @@
 #endif /* PRODUCT_UNDEFINED */
 
 #define ACR_PLATFORM_CLASS_PATH   ACR_CLASS_PATH "platform/windows/"
+#define LOG_MSG_DOMAIN            "ApacheCommonsRuntime"
 
 #define ACR_JNI_PLATFORM_DECLARE(RT, CL, FN)  \
     JNIEXPORT RT JNICALL Java_org_apache_commons_runtime_platform_windows_##CL##_##FN
@@ -216,7 +217,7 @@
         else { SetLastError(ERROR_INVALID_FUNCTION); return def;}           \
     } //
 
-#define ACR_DECLARE_LATE_DLL_VOID(lib, def, calltype,                       \
+#define ACR_DECLARE_LATE_DLL_VOID(lib, calltype,                            \
                                   fn, ord, args, names)                     \
     typedef void (calltype *acr_winapi_fpt_##fn) args;                      \
     static acr_winapi_fpt_##fn acr_winapi_pfn_##fn = NULL;                  \
@@ -335,10 +336,7 @@
 #ifdef WSAPoll
 #undef WSAPoll
 #endif
-ACR_DECLARE_LATE_DLL_FUNC(SYSDLL_IPHLPAPI, DWORD, ERROR_INVALID_FUNCTION,
-                          WINAPI, GetExtendedUdpTable, 0, (
-
-APR_DECLARE_LATE_DLL_FUNC(SYSDLL_WS_2_32, int, -1,
+ACR_DECLARE_LATE_DLL_FUNC(SYSDLL_WS_2_32, int, -1,
                           WSAAPI, WSAPoll, 0, (
     IN OUT LPWSAPOLLFD fdArray,
     IN ULONG fds,
@@ -350,15 +348,15 @@
 #ifdef SetDllDirectoryW
 #undef SetDllDirectoryW
 #endif
-APR_DECLARE_LATE_DLL_FUNC(SYSDLL_KERNEL32, BOOL, FALSE,
+ACR_DECLARE_LATE_DLL_FUNC(SYSDLL_KERNEL32, BOOL, FALSE,
                           WINAPI, SetDllDirectoryW, 0, (
     IN LPCWSTR lpPathName),
     (lpPathName));
 #define SetDllDirectoryW acr_winapi_SetDllDirectoryW
 
-ACR_DECLARE_LATE_DLL_CALL(SYSDLL_JVM, void, JNICALL,
+ACR_DECLARE_LATE_DLL_VOID(SYSDLL_JVM, JNICALL,
                           JVM_DumpAllStacks,
-                         _JVM_DumpAllStacks@8, 0, (
+                         8, (
     JNIEnv *lpEnv,
     jclass jClazz),
     (lpEnv, jClazz));

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/main.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/main.c?rev=763600&r1=763599&r2=763600&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/main.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/main.c Thu Apr  9 11:08:58 2009
@@ -53,7 +53,7 @@
     void   *epp;
 
     UNREFERENCED(reserved);
-    if ((*vm)->GetEnv(vm, (void **)&epp, JNI_VERSION_1_4)) {
+    if ((*vm)->GetEnv(vm, &epp, JNI_VERSION_1_4)) {
         return JNI_ERR;
     }
     acr_pvm = vm;
@@ -79,9 +79,9 @@
         tlsd = (acr_thread_local_t *)malloc(sizeof(acr_thread_local_t));
         if (tlsd == NULL)
             return NULL;
-        if ((*acr_pvm)->GetEnv(acr_pvm, (void **)&epp,
+        if ((*acr_pvm)->GetEnv(acr_pvm, &epp,
                                JNI_VERSION_1_4) == JNI_EDETACHED) {
-            (*acr_pvm)->AttachCurrentThread(acr_pvm, (void **)&epp, NULL);
+            (*acr_pvm)->AttachCurrentThread(acr_pvm, &epp, NULL);
             tlsd->attached = 1;
         }
         else

Added: commons/sandbox/runtime/trunk/src/main/native/os/win32/apache.ico
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/apache.ico?rev=763600&view=auto
==============================================================================
Binary file - no diff available.

Propchange: commons/sandbox/runtime/trunk/src/main/native/os/win32/apache.ico
------------------------------------------------------------------------------
    svn:mime-type = image/x-icon

Added: commons/sandbox/runtime/trunk/src/main/native/os/win32/logmessages.bin
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/logmessages.bin?rev=763600&view=auto
==============================================================================
Binary file - no diff available.

Propchange: commons/sandbox/runtime/trunk/src/main/native/os/win32/logmessages.bin
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: commons/sandbox/runtime/trunk/src/main/native/os/win32/logmessages.mc
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/logmessages.mc?rev=763600&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/logmessages.mc (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/logmessages.mc Thu Apr  9 11:08:58 2009
@@ -0,0 +1,41 @@
+MessageId=0x1
+Severity=Error
+SymbolicName=LOG_MSG_EMERG
+Language=English
+Emerg: %1
+.
+
+MessageId=0x2
+Severity=Error
+SymbolicName=LOG_MSG_ERROR
+Language=English
+Error: %1
+.
+
+MessageId=0x3
+Severity=Warning
+SymbolicName=LOG_MSG_NOTICE
+Language=English
+Notice: %1
+.
+
+MessageId=0x4
+Severity=Warning
+SymbolicName=LOG_MSG_WARN
+Language=English
+Warn: %1
+.
+
+MessageId=0x5
+Severity=Informational
+SymbolicName=LOG_MSG_INFO
+Language=English
+Info: %1
+.
+
+MessageId=0x6
+Severity=Success
+SymbolicName=LOG_MSG_DEBUG
+Language=English
+Debug: %1
+.

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

Added: commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c?rev=763600&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c Thu Apr  9 11:08:58 2009
@@ -0,0 +1,339 @@
+/* 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"
+
+#define ACR_WANT_LATE_DLL
+#include "acr_arch.h"
+
+/**
+ * Posix main
+ *
+ */
+
+static HINSTANCE        dll_instance = NULL;
+static WCHAR            dll_file_name[ACR_HBUFFER_SIZ];
+static DWORD            dll_tls_index = TLS_OUT_OF_INDEXES;
+
+static SYSTEM_INFO      osinf;
+static OSVERSIONINFOEXA osver;
+
+LPSYSTEM_INFO           acr_osinf = &osinf;
+LPOSVERSIONINFOEXA      acr_osver = &osver;
+static JavaVM          *acr_pvm   = NULL;
+
+typedef struct acr_thread_local_t {
+    JNIEnv  *env;
+    int     attached;
+} acr_thread_local_t;
+
+BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
+{
+    acr_thread_local_t *tlsd;
+
+    switch (reason) {
+        /** The DLL is loading due to process
+         *  initialization or a call to LoadLibrary.
+         */
+        case DLL_PROCESS_ATTACH:
+            dll_instance = instance;
+            GetModuleFileNameW(instance, dll_file_name, ACR_HBUFFER_LEN);
+        break;
+        /** The attached process creates a new thread.
+         */
+        case DLL_THREAD_ATTACH:
+        break;
+        /** The thread of the attached process terminates.
+         */
+        case DLL_THREAD_DETACH:
+            if (dll_tls_index != TLS_OUT_OF_INDEXES) {
+                tlsd = (acr_thread_local_t *)TlsGetValue(dll_tls_index);
+                if (tlsd) {
+                    if (acr_pvm && tlsd->attached) {
+                        (*acr_pvm)->DetachCurrentThread(acr_pvm);
+                    }
+                    LocalFree(tlsd);
+                }
+            }
+        break;
+        /** DLL unload due to process termination
+         *  or FreeLibrary.
+         */
+        case DLL_PROCESS_DETACH:
+            if (dll_tls_index != TLS_OUT_OF_INDEXES) {
+                tlsd = (acr_thread_local_t *)TlsGetValue(dll_tls_index);
+                if (tlsd) {
+                    if (acr_pvm && tlsd->attached) {
+                        (*acr_pvm)->DetachCurrentThread(acr_pvm);
+                    }
+                    LocalFree(tlsd);
+                }
+                TlsFree(dll_tls_index);
+            }
+            dll_instance = NULL;
+        break;
+        default:
+        break;
+    }
+
+    return TRUE;
+    UNREFERENCED_PARAMETER(reserved);
+}
+
+/* This is the helper code to resolve late bound entry points
+ * missing from one or more releases of the Win32 API
+ */
+static const char* const late_dll_names[SYSDLL_defined] = {
+    "kernel32.dll",
+    "ntdll.dll",
+    "user32.dll",
+    "iphlpapi.dll",
+    "mswsock.dll",
+    "ws_2_32.dll",
+    "shell32.dll",
+    "advapi32.dll",
+    "jvm.dll"
+};
+
+static HMODULE late_dll_handles[SYSDLL_defined] = { NULL, NULL, NULL,
+                                                    NULL, NULL, NULL,
+                                                    NULL, NULL, NULL };
+
+FARPROC acr_load_dll_func(acr_dlltoken_e fnLib, const char* fnName, int ordinal)
+{
+    if (!late_dll_handles[fnLib]) {
+        /* First see if the .dll is already loaded in the process */
+        late_dll_handles[fnLib] = GetModuleHandleA(late_dll_names[fnLib]);
+        if (!late_dll_handles[fnLib]) {
+            /* Do not display error messages when loading library */
+            UINT em = SetErrorMode(SEM_FAILCRITICALERRORS);
+            late_dll_handles[fnLib] = LoadLibraryA(late_dll_names[fnLib]);
+            SetErrorMode(em);
+        }
+        if (!late_dll_handles[fnLib])
+            return NULL;
+    }
+    if (ordinal)
+        return GetProcAddress(late_dll_handles[fnLib],
+                              V2P(const char *, ordinal));
+    else
+        return GetProcAddress(late_dll_handles[fnLib], fnName);
+}
+
+static DWORD preload_late_dlls()
+{
+    acr_dlltoken_e fnLib = SYSDLL_KERNEL32;
+
+    for (fnLib = SYSDLL_KERNEL32; fnLib < SYSDLL_defined; fnLib++) {
+        if (!late_dll_handles[fnLib]) {
+            DWORD rc = ERROR_SUCCESS;
+            /* First see if the .dll is already loaded in the process */
+            late_dll_handles[fnLib] = GetModuleHandleA(late_dll_names[fnLib]);
+            if (!late_dll_handles[fnLib]) {
+                UINT em;
+                rc = GetLastError();
+                /* Do not display error messages when loading library */
+                em = SetErrorMode(SEM_FAILCRITICALERRORS);
+                late_dll_handles[fnLib] = LoadLibraryA(late_dll_names[fnLib]);
+                rc = GetLastError();
+                SetErrorMode(em);
+            }
+            if (!late_dll_handles[fnLib])
+                return rc;
+        }
+    }
+    return ERROR_SUCCESS;
+}
+
+static DWORD set_current_privilege(LPCWSTR szPrivilege,
+                                   BOOL bEnablePrivilege)
+{
+    DWORD dwError;
+    HANDLE hToken;
+    TOKEN_PRIVILEGES tp;
+    LUID luid;
+    TOKEN_PRIVILEGES tpPrevious;
+    DWORD cbPrevious = sizeof(TOKEN_PRIVILEGES);
+    BOOL bSuccess=FALSE;
+
+    if (!LookupPrivilegeValueW(NULL, szPrivilege, &luid))
+        return ERROR_NO_SUCH_PRIVILEGE;
+
+    if (!OpenProcessToken(GetCurrentProcess(),
+                          TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES,
+                          &hToken))
+        return GetLastError();
+
+    tp.PrivilegeCount           = 1;
+    tp.Privileges[0].Luid       = luid;
+    tp.Privileges[0].Attributes = 0;
+
+    AdjustTokenPrivileges(hToken,
+                          FALSE,
+                          &tp,
+                          sizeof(TOKEN_PRIVILEGES),
+                          &tpPrevious,
+                          &cbPrevious);
+
+    if ((dwError = GetLastError()) == ERROR_SUCCESS) {
+        tpPrevious.PrivilegeCount     = 1;
+        tpPrevious.Privileges[0].Luid = luid;
+
+        if(bEnablePrivilege)
+            tpPrevious.Privileges[0].Attributes |= (SE_PRIVILEGE_ENABLED);
+        else
+            tpPrevious.Privileges[0].Attributes &= ~(SE_PRIVILEGE_ENABLED);
+
+        AdjustTokenPrivileges(hToken,
+                              FALSE,
+                              &tpPrevious,
+                              cbPrevious,
+                              NULL,
+                              NULL);
+
+        dwError = GetLastError();
+    }
+    CloseHandle(hToken);
+    return dwError;
+}
+
+static DWORD enable_privilege(LPCWSTR szPrivilege)
+{
+    DWORD dwError;
+    HANDLE hToken;
+    TOKEN_PRIVILEGES tp;
+    LUID luid;
+
+    if (!LookupPrivilegeValueW(NULL, szPrivilege, &luid))
+        return ERROR_NO_SUCH_PRIVILEGE;
+
+    if (!OpenProcessToken(GetCurrentProcess(),
+                          TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES,
+                          &hToken))
+        return GetLastError();
+
+    tp.PrivilegeCount           = 1;
+    tp.Privileges[0].Luid       = luid;
+    tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
+
+    AdjustTokenPrivileges(hToken,
+                          FALSE,
+                          &tp,
+                          sizeof(TOKEN_PRIVILEGES),
+                          NULL,
+                          NULL);
+
+    dwError = GetLastError();
+    CloseHandle(hToken);
+    return dwError;
+}
+
+char       *acr_log_domain = NULL;
+extern void do_syslog(jint, LPWSTR, DWORD);
+
+void acr_init_log_source(const char *domain)
+{
+    HKEY  key;
+    DWORD ts;
+    char  *event_key = malloc(strlen(domain) + 64);
+
+    lstrcpyA(event_key,
+             "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\");
+    lstrcatA(event_key, domain);
+    if (!RegCreateKeyA(HKEY_LOCAL_MACHINE, event_key, &key)) {
+        RegSetValueExW(key, L"EventMessageFile", 0, REG_SZ,
+                       (LPBYTE)&dll_file_name[0],
+                       lstrlenW(dll_file_name) + 1);
+        ts = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE |
+             EVENTLOG_INFORMATION_TYPE;
+
+        RegSetValueExW(key, L"TypesSupported", 0, REG_DWORD,
+                       (LPBYTE) &ts, sizeof(DWORD));
+        RegCloseKey(key);
+    }
+    free(event_key);
+    if (acr_log_domain)
+        free(acr_log_domain);
+    acr_log_domain = strdup(domain);
+}
+
+/* Called by the JVM when ACR is loaded */
+JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
+{
+    DWORD   rc;
+    JNIEnv *env;
+    void   *epp;
+
+    UNREFERENCED(reserved);
+    if ((*vm)->GetEnv(vm, &epp, JNI_VERSION_1_4)) {
+        return JNI_ERR;
+    }
+    acr_pvm = vm;
+
+    GetSystemInfo(acr_osinf);
+    acr_osver->dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
+    GetVersionExA((LPOSVERSIONINFOA)acr_osver);
+
+    /* Preload Late bound system libraries */
+    if ((rc = preload_late_dlls()) != ERROR_SUCCESS) {
+        /* Should never happen. */
+        acr_init_log_source(LOG_MSG_DOMAIN);
+        do_syslog(ACR_LOG_ERROR,
+                  L"Failed loading system libraries", rc);
+        return JNI_ERR;
+    }
+    /* Allocate a TLS index. */
+    if ((dll_tls_index = TlsAlloc()) == TLS_OUT_OF_INDEXES) {
+        return JNI_ERR;
+    }
+    if ((rc = enable_privilege(L"SeDebugPrivilege")) != ERROR_SUCCESS) {
+        /* Log that we couldn't set privilege */
+        acr_init_log_source(LOG_MSG_DOMAIN);
+        do_syslog(ACR_LOG_ERROR,
+                  L"Failed setting SeDebugPrivilege", rc);
+    }
+
+    env = epp;
+    return  JNI_VERSION_1_4;
+}
+
+ACR_DECLARE(JNIEnv *)ACR_GetJNIEnv()
+{
+    acr_thread_local_t *tlsd;
+    void *epp = NULL;
+
+    if (acr_pvm == NULL) {
+        return NULL;
+    }
+    tlsd = (acr_thread_local_t *)TlsGetValue(dll_tls_index);
+    if (tlsd == NULL) {
+        tlsd = (acr_thread_local_t *)LocalAlloc(LPTR,
+                                                sizeof(acr_thread_local_t));
+        if (tlsd == NULL)
+            return NULL;
+        if ((*acr_pvm)->GetEnv(acr_pvm, &epp,
+                               JNI_VERSION_1_4) == JNI_EDETACHED) {
+            (*acr_pvm)->AttachCurrentThread(acr_pvm, &epp, NULL);
+            tlsd->attached = 1;
+        }
+        else
+            tlsd->attached = 0;
+        tlsd->env = epp;
+        TlsSetValue(dll_tls_index, tlsd);
+    }
+    return tlsd->env;
+}

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

Added: commons/sandbox/runtime/trunk/src/main/native/os/win32/main.rc
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/main.rc?rev=763600&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/main.rc (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/main.rc Thu Apr  9 11:08:58 2009
@@ -0,0 +1,107 @@
+/* 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 <windows.h>
+
+LANGUAGE 0x9,0x1
+1 11 logmessages.bin
+
+#define STR_LICENSE \
+  "Licensed 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\r\n"                                \
+  "\r\n"                                                                       \
+  "http://www.apache.org/licenses/LICENSE-2.0\r\n"                             \
+  "\r\n"                                                                       \
+  "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."
+
+#define STR_COPYRIGHT \
+  "Copyright © 2009 Apache Software Foundation.\r\n"                           \
+  "See the NOTICE file distributed with this work for additional "             \
+  "information regarding copyright ownership."
+
+#define STR_COMPANY         "Apache Software Foundation"
+#define STR_TRADEMARK       "™ Apache Software Foundation"
+#define STR_PRODUCT         "Apache Commons Runtime"
+
+#define STR_VERISON         "1.0.0.0"
+#define CSV_VERISON         1,0,0,0
+
+#define PRIVATE_BUILD       1
+#define PRERELEASE_BUILD    1
+
+#if PRIVATE_BUILD
+#define STR_PRIVATE   "Initial Prerelease"
+#define STR_SPECIAL   "Basic functionality"
+#define STD_FILEFLAGS VS_FF_PRIVATEBUILD | VS_FF_SPECIALBUILD
+#else
+#define STD_FILEFLAGS 0x0L
+#endif
+
+#if RERELEASE_BUILD
+#define PSTD_FILEFLAGS STD_FILEFLAGS | VS_FF_PRERELEASE
+#else
+#define PSTD_FILEFLAGS STD_FILEFLAGS
+#endif
+
+#ifdef _DEBUG
+#define APP_FILEFLAGS STD_FILEFLAGS | VS_FF_DEBUG
+#else
+#define APP_FILEFLAGS STD_FILEFLAGS
+#endif
+
+
+IDI_MAINICON         ICON                   "apache.ico"
+
+1 VERSIONINFO
+ FILEVERSION CSV_VERISON
+ PRODUCTVERSION CSV_VERISON
+ FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
+ FILEFLAGS APP_FILEFLAGS
+ FILEOS VOS_NT
+ FILETYPE VFT_APP
+ FILESUBTYPE 0x0L
+BEGIN
+    BLOCK "StringFileInfo"
+    BEGIN
+        BLOCK "040904b0"
+        BEGIN
+            VALUE "Comments",  STR_LICENSE "\0"
+            VALUE "CompanyName", STR_COMPANY "\0"
+            VALUE "FileDescription", STR_PRODUCT "\0"
+            VALUE "FileVersion", STR_VERISON "\0"
+            VALUE "InternalName", "libacr"
+            VALUE "LegalCopyright", STR_COPYRIGHT "\0"
+            VALUE "LegalTrademarks", STR_TRADEMARK "\0"
+            VALUE "OriginalFilename", "libacr.dll"
+            VALUE "ProductName", STR_PRODUCT "\0"
+            VALUE "ProductVersion", STR_VERISON "\0"
+#if PRIVATE_BUILD
+            VALUE "PrivateBuild", STR_PRIVATE "\0"
+            VALUE "SpecialBuild", STR_SPECIAL "\0"
+#endif
+        END
+    END
+    BLOCK "VarFileInfo"
+    BEGIN
+        VALUE "Translation", 0x409, 1200
+    END
+END

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

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/os.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/os.c?rev=763600&r1=763599&r2=763600&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/os.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/os.c Thu Apr  9 11:08:58 2009
@@ -60,27 +60,57 @@
 {
     char buf[ACR_SBUFFER_SIZ];
 
-    if (ACR_osver->dwMajorVersion == 4) {
-       strcpy(buf, "NT4");
-    }
-    else if (acr_osver->dwMajorVersion == 5) {
-        if (acr_osver->dwMinorVersion == 0) {
-            strcpy(buf, "2000");
-        }
-        else if (acr_osver->dwMinorVersion == 2) {
-            strcpy(buf, "2003");
-        }
-        else {
-            strcpy(buf, "XP");
-        }
-    }
-    else if (acr_osver->dwMajorVersion == 6) {
-        strcpy(buf, "VISTA");
-    }
-    else {
-        sprintf(buf, "%d.%d",
-                acr_osver->dwMajorVersion,
-                acr_osver->dwMinorVersion);
+    switch (acr_osver->dwMajorVersion) {
+        case 4:
+           strcpy(buf, "NT4");
+        break;
+        case 5:
+            switch (acr_osver->dwMinorVersion) {
+                case 0:
+                    strcpy(buf, "2000");
+                break;
+                case 1:
+                    strcpy(buf, "XP");
+                break;
+                case 2 :
+                    if (acr_osver->wProductType == VER_NT_WORKSTATION)
+                        strcpy(buf, "XP");
+                    else {
+                        strcpy(buf, "2003");
+                        if (GetSystemMetrics(SM_SERVERR2))
+                            strcat(buf, "R2");
+                    }
+                break;
+            }
+        break;
+        case 6:
+            switch (acr_osver->dwMinorVersion) {
+                case 0 :
+                    switch (acr_osver->wProductType) {
+                        case VER_NT_WORKSTATION:
+                            strcpy(buf, "Vista");
+                        break;
+                        default:
+                            strcpy(buf, "2008");
+                        break;
+                    }
+                break;
+                case 1 :
+                    switch (acr_osver->wProductType) {
+                        case VER_NT_WORKSTATION:
+                            strcpy(buf, "7");
+                        break;
+                        default:
+                            strcpy(buf, "7");
+                        break;
+                    }
+                break;
+            }
+        break;
+        default:
+            sprintf(buf, "%d.%d", acr_osver->dwMajorVersion,
+                                  acr_osver->dwMinorVersion);
+        break;
     }
     if (acr_osver->szCSDVersion[0]) {
         strcat(buf, " (");
@@ -92,11 +122,31 @@
 
 ACR_JNI_EXPORT_DECLARE(jstring, OS, getRelease)(ACR_JNISTDARGS)
 {
-    char buf[32];
+    const char *prodver = "Generic";
+    char buf[64];
+    BOOL isWoW64 = FALSE;
+
+    switch (acr_osver->wProductType) {
+        case VER_NT_DOMAIN_CONTROLLER:
+        case VER_NT_SERVER:
+            prodver = "Server";
+        break;
+        case VER_NT_WORKSTATION:
+            prodver = "Workstation";
+        break;
+    }
+    sprintf(buf, "%s_%d-%d.%d", prodver,
+            acr_osver->dwBuildNumber,
+            acr_osver->wServicePackMajor,
+            acr_osver->wServicePackMinor);
+#ifdef _WIN64
+    strcat(buf, "_64-bit");
+#else
+    IsWow64Process(GetCurrentProcess(), &isWoW64);
+    if (isWoW64)
+        strcat(buf, "_64-bit");
+#endif
 
-    sprintf(buf, "%d.%d.%d", acr_osver->dwMajorVersion,
-                             acr_osver->dwMinorVersion,
-                             acr_osver->dwBuildNumber);
     return CSTR_TO_JSTRING(buf);
 }
 
@@ -104,23 +154,27 @@
 {
     char buf[32];
 
-    if (acr_osinf->wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
-        strcpy(buf, "x86_64");
-    else if (acr_osinf->wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)
-        strcpy(buf, "ia64");
-    else if (acr_osinf->wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL) {
-        int pl = acr_osinf->wProcessorLevel;
-        if (pl < 8)
-            sprintf(buf, "i%d86", acr_osinf->wProcessorLevel);
-        else {
-            /* TODO: Figure out the proper names for EMT64
-             * and other Intel processors
-             */
-            strcpy(buf, "i786");
-        }
+    switch (acr_osinf->wProcessorArchitecture) {
+        case PROCESSOR_ARCHITECTURE_AMD64:
+            strcpy(buf, "x86_64");
+        break;
+        case PROCESSOR_ARCHITECTURE_IA64:
+            strcpy(buf, "ia64");
+        case PROCESSOR_ARCHITECTURE_INTEL:
+            if (acr_osinf->wProcessorLevel < 8)
+                sprintf(buf, "i%d86", acr_osinf->wProcessorLevel);
+            else {
+                /* TODO: Figure out the proper names for
+                 * other Intel processors
+                 */
+                strcpy(buf, "ia32");
+            }
+        break;
+        default:
+            strcpy(buf, unknown);
+        break;
     }
-    else
-        return CSTR_TO_JSTRING(unknown);
+
     return CSTR_TO_JSTRING(buf);
 }
 
@@ -129,7 +183,7 @@
     char buf[MAX_COMPUTERNAME_LENGTH + 1] = { 0 };
     DWORD len = MAX_COMPUTERNAME_LENGTH;
 
-    if (GetComputerName(buf, &len)) {
+    if (GetComputerNameA(buf, &len)) {
         return CSTR_TO_JSTRING(buf);
     }
     else {
@@ -141,26 +195,54 @@
 {
     char buf[32];
 
-    if (acr_osinf->wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
-        strcpy(buf, "amd64");
-    else if (acr_osinf->wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)
-        strcpy(buf, "ia64");
-    else if (acr_osinf->wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
-#ifdef _WIN64
-        strcpy(buf, "emt64");
-#else
-        strcpy(buf, "ia32");
-#endif
+    switch (acr_osinf->wProcessorArchitecture) {
+        case PROCESSOR_ARCHITECTURE_AMD64:
+            strcpy(buf, "x86_64");
+        break;
+        case PROCESSOR_ARCHITECTURE_IA64:
+            strcpy(buf, "ia64");
+        case PROCESSOR_ARCHITECTURE_INTEL:
+            if (acr_osinf->wProcessorLevel < 8)
+                sprintf(buf, "i%d86", acr_osinf->wProcessorLevel);
+            else {
+                /* TODO: Figure out the proper names for
+                 * other Intel processors
+                 */
+                strcpy(buf, "ia32");
+            }
+        break;
+        default:
+            strcpy(buf, unknown);
+        break;
     }
-    else
-        strcpy(buf, unknown);
+
     return CSTR_TO_JSTRING(buf);
 }
 
 ACR_JNI_EXPORT_DECLARE(jstring, OS, getHardwarePlatform)(ACR_JNISTDARGS)
 {
-    if (acr_osinf->wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
-        return CSTR_TO_JSTRING("amd64");
-    else
-        return CSTR_TO_JSTRING("intel");
+    BOOL isWoW64 = FALSE;
+    char buf[32];
+
+    switch (acr_osver->wProductType) {
+        case VER_NT_DOMAIN_CONTROLLER:
+        case VER_NT_SERVER:
+            strcpy(buf, "Server");
+        break;
+        case VER_NT_WORKSTATION:
+            strcpy(buf, "Workstation");
+        break;
+        default:
+            strcpy(buf, "Generic");
+        break;
+    }
+#ifdef _WIN64
+    strcat(buf, "64");
+#else
+    IsWow64Process(GetCurrentProcess(), &isWoW64);
+    if (isWoW64)
+        strcat(buf, "64");
+#endif
+
+    return CSTR_TO_JSTRING(buf);
 }

Added: commons/sandbox/runtime/trunk/src/main/native/os/win32/syslog.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/syslog.c?rev=763600&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/syslog.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/syslog.c Thu Apr  9 11:08:58 2009
@@ -0,0 +1,119 @@
+/* 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"
+
+#define ACR_WANT_LATE_DLL
+#include "acr_arch.h"
+
+#define LOG_MSG_EMERG           0xC0000001L
+#define LOG_MSG_ERROR           0xC0000002L
+#define LOG_MSG_NOTICE          0x80000003L
+#define LOG_MSG_WARN            0x80000004L
+#define LOG_MSG_INFO            0x40000005L
+#define LOG_MSG_DEBUG           0x00000006L
+
+extern char *acr_log_domain;
+extern void acr_init_log_source(const char *);
+
+void do_syslog(jint level, LPWSTR msg, DWORD err)
+{
+    DWORD id = LOG_MSG_DEBUG;
+    WORD  il = EVENTLOG_SUCCESS;
+    HANDLE source;
+    WCHAR *messages[2];
+    WCHAR  buffer[ACR_MBUFFER_SIZ];
+    WORD   nStrings = 1;
+
+    switch (level) {
+        case ACR_LOG_EMERG:
+            id = LOG_MSG_EMERG;
+            il = EVENTLOG_ERROR_TYPE;
+        break;
+        case ACR_LOG_ERROR:
+            id = LOG_MSG_ERROR;
+            il = EVENTLOG_ERROR_TYPE;
+        break;
+        case ACR_LOG_NOTICE:
+            id = LOG_MSG_NOTICE;
+            il = EVENTLOG_WARNING_TYPE;
+        break;
+        case ACR_LOG_WARN:
+            id = LOG_MSG_WARN;
+            il = EVENTLOG_WARNING_TYPE;
+        break;
+        case ACR_LOG_INFO:
+            id = LOG_MSG_INFO;
+            il = EVENTLOG_INFORMATION_TYPE;
+        break;
+    }
+
+    messages[0] = msg;
+    if (err) {
+        FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+                       FORMAT_MESSAGE_FROM_SYSTEM |
+                       FORMAT_MESSAGE_IGNORE_INSERTS,
+                       NULL,
+                       err,
+                       MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+                       buffer,
+                       ACR_MBUFFER_SIZ, NULL);
+        messages[1] = &buffer[0];
+        nStrings = 2;
+    }
+    source = RegisterEventSourceA(NULL, acr_log_domain);
+
+    if (source != NULL) {
+        ReportEventW(source, il,
+                     0,
+                     id,
+                     NULL,
+                     nStrings, 0,
+                     messages, NULL);
+        DeregisterEventSource(source);
+    }
+}
+
+ACR_JNI_EXPORT_DECLARE(void, Syslog, init0)(ACR_JNISTDARGS)
+{
+    UNREFERENCED_STDARGS;
+
+    acr_init_log_source(LOG_MSG_DOMAIN);
+}
+
+ACR_JNI_EXPORT_DECLARE(void, Syslog, init1)(ACR_JNISTDARGS, jstring domain)
+{
+    CSTR_GETCHAR(domain);
+
+    UNREFERENCED_O;
+
+    acr_init_log_source(J2S(domain));
+
+    CSTR_RELEASE(domain);
+}
+
+ACR_JNI_EXPORT_DECLARE(void, Syslog, log0)(ACR_JNISTDARGS,
+                                           jint level,
+                                           jstring msg)
+{
+    WSTR_GETCHAR(msg);
+
+    UNREFERENCED_O;
+    WSTR_DOALLOC(msg);
+    do_syslog(level, J2W(msg), 0);
+    WSTR_RELEASE(msg);
+}

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