99public final class MmapSharedMemory extends AbstractSharedMemory {
1010 private static MemorySession session ;
1111 private static MethodHandle shm_open , ftruncate , mmap , munmap , shm_unlink ;
12+ private static final int O_CREAT = 0x00000200 , O_EXCL = 0x00000800 , O_RDWR = 0x0002 ,
13+ PROT_READ = 0x01 , PROT_WRITE = 0x02 , MAP_SHARED = 0x01 ;
1214 @ SuppressWarnings ("OctalInteger" )
13- private static final int O_CREAT = 0x00000200 , O_RDWR = 0x0002 , S_IRUSR = 0000400 , S_IWUSR = 0000200 ,
14- PROT_READ = 0x01 , PROT_WRITE = 0x02 , MAP_SHARED = 0x01 ;
15+ private static final short S_IRUSR = 00400 , S_IWUSR = 00200 ;
1516
1617 static {
1718 if (CABI .SYSTEM_TYPE == CABI .SystemType .Unix ) {
@@ -21,9 +22,8 @@ public final class MmapSharedMemory extends AbstractSharedMemory {
2122 shm_open = linker .downcallHandle (lookup .lookup ("shm_open" ).orElseThrow (), FunctionDescriptor .of (
2223 ValueLayout .JAVA_INT ,
2324 ValueLayout .ADDRESS ,
24- ValueLayout .JAVA_INT ,
2525 ValueLayout .JAVA_INT
26- ));
26+ ). asVariadic ( ValueLayout . JAVA_SHORT ) );
2727 ftruncate = linker .downcallHandle (lookup .lookup ("ftruncate" ).orElseThrow (), FunctionDescriptor .of (
2828 ValueLayout .JAVA_INT ,
2929 ValueLayout .JAVA_INT ,
@@ -54,8 +54,8 @@ public MmapSharedMemory(String name, int size, boolean isCreate) throws Throwabl
5454 super (name , size , isCreate );
5555 if (CABI .SYSTEM_TYPE != CABI .SystemType .Unix ) throw new UnsupportedOperationException ("Only Unix is supported" );
5656 int mode = O_RDWR ;
57- if (isCreate ) mode |= O_CREAT ;
58- int fd = (int ) shm_open .invokeExact ((Addressable ) session .allocateUtf8String (name ), mode , S_IRUSR | S_IWUSR );
57+ if (isCreate ) mode |= O_CREAT | O_EXCL ;
58+ int fd = (int ) shm_open .invokeExact ((Addressable ) session .allocateUtf8String (name ), mode , ( short ) ( S_IRUSR | S_IWUSR ) );
5959 if (fd == -1 ) throw new IllegalStateException ("shm_open failed." );
6060 try {
6161 if (isCreate && (int ) ftruncate .invokeExact (fd , size ) == -1 ) throw new IllegalStateException ("ftruncate failed." );
0 commit comments