Skip to content

Commit e287ded

Browse files
committed
native, common: Improve memory-mapping
1 parent 15b0d7e commit e287ded

4 files changed

Lines changed: 239 additions & 39 deletions

File tree

junixsocket-common/src/main/java/org/newsclub/net/unix/MemoryImplUtilInternal.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,12 @@ public final class MemoryImplUtilInternal {
5252

5353
public static final int MMODE_READ = NativeUnixSocket.MMODE_READ;
5454
public static final int MMODE_WRITE = NativeUnixSocket.MMODE_WRITE;
55+
public static final int MMODE_READ_WRITE = NativeUnixSocket.MMODE_READ
56+
| NativeUnixSocket.MMODE_WRITE;
5557
public static final int MMODE_COPY_ON_WRITE = NativeUnixSocket.MMODE_COPY_ON_WRITE;
5658
public static final int MMODE_SYNC = NativeUnixSocket.MMODE_SYNC;
59+
public static final int MMODE_FIXED = NativeUnixSocket.MMODE_FIXED;
60+
public static final int MMODE_ANONYMOUS = NativeUnixSocket.MMODE_ANONYMOUS;
5761

5862
public static final int MADV_NORMAL = NativeUnixSocket.MADV_NORMAL;
5963
public static final int MADV_FREE = NativeUnixSocket.MADV_FREE;
@@ -86,7 +90,7 @@ public long getSharedMemoryAllocationSize() {
8690
return SHM_ALLOC_SIZE;
8791
}
8892

89-
public ByteBuffer mmap(Object arenaSegment, FileDescriptor fd, long offset, long length,
93+
public ByteBuffer mmapShm(Object arenaSegment, FileDescriptor fd, long offset, long length,
9094
int mmode, int duplicates) throws IOException {
9195
if (offset < 0) {
9296
throw new IllegalArgumentException("offset");
@@ -101,6 +105,16 @@ public ByteBuffer mmap(Object arenaSegment, FileDescriptor fd, long offset, long
101105
return NativeUnixSocket.mmapShm(arenaSegment, fd, offset, length, mmode, duplicates);
102106
}
103107

108+
public ByteBuffer mappedBuffer(long address, long length, FileDescriptor fdRef, int mmode,
109+
Object arenaSegment) throws IOException {
110+
return NativeUnixSocket.mappedBuffer(address, length, fdRef, mmode, arenaSegment);
111+
}
112+
113+
public long mmap(long address, FileDescriptor fdObj, long offset, long length, int mmode)
114+
throws IOException {
115+
return NativeUnixSocket.mmap(address, fdObj, offset, length, mmode);
116+
}
117+
104118
public void unmap(long address, long byteSize, int duplicates, boolean ignoreError)
105119
throws IOException {
106120
NativeUnixSocket.unmap(address, byteSize, duplicates, ignoreError);

junixsocket-common/src/main/java/org/newsclub/net/unix/NativeUnixSocket.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ final class NativeUnixSocket {
103103
static final int MMODE_WRITE = 1 << 1;
104104
static final int MMODE_COPY_ON_WRITE = 1 << 2;
105105
static final int MMODE_SYNC = 1 << 3;
106+
static final int MMODE_FIXED = 1 << 4;
107+
static final int MMODE_ANONYMOUS = 1 << 5;
106108

107109
static final int MADV_NORMAL = 1 << 0;
108110
static final int MADV_FREE = 1 << 1;
@@ -400,6 +402,12 @@ static native ByteBuffer mmapShm(Object arenaSegment, FileDescriptor fd, long of
400402
static native void unmap(long address, long byteSize, int duplicates, boolean ignoreError)
401403
throws IOException;
402404

405+
static native long mmap(long address, FileDescriptor fdObj, long offset, long length, int mmode)
406+
throws IOException;
407+
408+
static native ByteBuffer mappedBuffer(long address, long length, FileDescriptor fdRef, int mmode,
409+
Object arenaSegment) throws IOException;
410+
403411
static native void madvise(long address, long byteSize, int madv, boolean ignoreError)
404412
throws IOException;
405413

junixsocket-native/src/main/c/org_newsclub_net_unix_NativeUnixSocket.h

Lines changed: 22 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)