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 2011/04/20 09:04:57 UTC
svn commit: r1095302 - in /commons/sandbox/runtime/trunk/src/main:
java/org/apache/commons/runtime/platform/windows/Win32.java
native/os/win32/winapi.c
Author: mturk
Date: Wed Apr 20 07:04:57 2011
New Revision: 1095302
URL: http://svn.apache.org/viewvc?rev=1095302&view=rev
Log:
Add Win32 file mapping API wrappers
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Win32.java
commons/sandbox/runtime/trunk/src/main/native/os/win32/winapi.c
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Win32.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Win32.java?rev=1095302&r1=1095301&r2=1095302&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Win32.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Win32.java Wed Apr 20 07:04:57 2011
@@ -87,7 +87,7 @@ final class Win32
public static final int GENERIC_WRITE = 0x40000000;
public static final int GENERIC_EXECUTE = 0x20000000;
public static final int GENERIC_ALL = 0x10000000;
-
+
/* Generic cumulative rights */
public static final int GENERIC_RWX = 0xe0000000;
public static final int GENERIC_RWR = 0xc0000000;
@@ -112,7 +112,7 @@ final class Win32
SECTION_MAP_READ |
SECTION_MAP_EXECUTE |
SECTION_EXTEND_SIZE;
- /* Some of the file access rights */
+ /* Some of the file access rights */
public static final int FILE_EXECUTE = 0x00000020;
public static final int FILE_READ_DATA = 0x00000001;
public static final int FILE_WRITE_DATA = 0x00000002;
@@ -121,7 +121,7 @@ final class Win32
public static final int FILE_READ_ATTRIBUTES = 0x00000080;
public static final int FILE_WRITE_ATTRIBUTES = 0x00000100;
-
+
public static final int FILE_MAP_COPY = SECTION_QUERY;
public static final int FILE_MAP_WRITE = SECTION_MAP_WRITE;
public static final int FILE_MAP_READ = SECTION_MAP_READ;
@@ -155,6 +155,10 @@ final class Win32
public static native int WaitForSingleObject(long handle, int timeout);
public static native long CreateMutex(long sa, boolean initialOwner, String name);
public static native long OpenMutex(int access, boolean inheritHandle, String name);
+ public static native long CreateFileMapping(long file, long sa, int protect, long size, String name);
+ public static native long OpenFileMapping(int acc, boolean inherit, String name);
+ public static native long MapViewOfFile(long handle, int acc, long offset, long size);
+ public static native int UnmapViewOfFile(long address);
public static native long VirtualAlloc(long base, long size, int type, int protect);
public static native int VirtualProtect(long addr, long size, int protect);
public static native int VirtualFree(long addr, long size, int type);
@@ -163,6 +167,6 @@ final class Win32
public static final int HEAP_PTR = 1;
public static final int SLICE_PTR = 2;
public static final int CONST_PTR = 3;
- public static native Pointer pointer(long addr, long length, int type);
-
+ public static native Pointer pointer(long addr, long len, int type);
+
}
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/winapi.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/winapi.c?rev=1095302&r1=1095301&r2=1095302&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/winapi.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/winapi.c Wed Apr 20 07:04:57 2011
@@ -55,6 +55,69 @@ ACR_WIN_EXPORT(jint, Win32, WaitForSingl
return ACR_GET_OS_ERROR();
}
+ACR_WIN_EXPORT(jlong, Win32, CreateFileMapping)(JNI_STDARGS, jlong file, jlong sa,
+ jint protect, jlong size, jstring name)
+{
+ HANDLE h = 0;
+ DWORD sizelo, sizehi;
+
+ sizelo = (DWORD)(size);
+ sizehi = (DWORD)(size >> 32);
+
+ WITH_WSTR(name) {
+ h = CreateFileMappingW(J2P(file, HANDLE), J2P(sa, LPSECURITY_ATTRIBUTES),
+ protect, sizehi, sizelo, J2S(name));
+ if (h == 0) {
+ ACR_SAVE_OS_ERROR();
+ }
+ else if (GetLastError() == ERROR_ALREADY_EXISTS) {
+ CloseHandle(h);
+ h = 0;
+ ACR_SAVE_ERROR(ACR_EEXIST);
+ }
+ } DONE_WITH_STR(name);
+
+ return P2J(h);
+}
+
+ACR_WIN_EXPORT(jlong, Win32, OpenFileMapping)(JNI_STDARGS, jint acc, jboolean inherit,
+ jstring name)
+{
+ HANDLE h = 0;
+
+ WITH_WSTR(name) {
+ h = OpenFileMappingW(acc, inherit, J2S(name));
+ if (h == 0)
+ ACR_SAVE_OS_ERROR();
+ } DONE_WITH_STR(name);
+
+ return P2J(h);
+}
+
+ACR_WIN_EXPORT(jlong, Win32, MapViewOfFile)(JNI_STDARGS, jlong map, jint acc,
+ jlong offset, jlong size)
+{
+ LPVOID m;
+ DWORD offlo, offhi;
+
+ offlo = (DWORD)(offset);
+ offhi = (DWORD)(offset >> 32);
+
+ m = MapViewOfFile(J2P(map, HANDLE), acc, offhi, offlo, (SIZE_T)size);
+ if (m == 0)
+ ACR_SAVE_OS_ERROR();
+
+ return P2J(m);
+}
+
+ACR_WIN_EXPORT(jint, Win32, UnmapViewOfFile)(JNI_STDARGS, jlong addr)
+{
+ if (UnmapViewOfFile(J2P(addr, LPVOID)))
+ return 0;
+ else
+ return ACR_GET_OS_ERROR();
+}
+
ACR_WIN_EXPORT(jlong, Win32, CreateMutex)(JNI_STDARGS, jlong sa, jboolean owner, jstring name)
{
HANDLE h = 0;
@@ -84,7 +147,7 @@ ACR_WIN_EXPORT(jlong, Win32, OpenMutex)(
ACR_WIN_EXPORT(jlong, Win32, VirtualAlloc)(JNI_STDARGS, jlong base, jlong size, jint type, jint protect)
{
- void *mem = 0;
+ LPVOID mem = 0;
mem = VirtualAlloc(J2P(base, LPVOID), (SIZE_T)size, type, protect);
if (mem == 0)