< prev index next >

src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/MappedMemorySegmentImpl.java

Print this page
M MappedMemorySegmentImpl.java

@@ -102,12 +102,16 @@
     public static MappedMemorySegment makeMappedSegment(Path path, long bytesSize, FileChannel.MapMode mapMode) throws IOException {
         if (bytesSize <= 0) throw new IllegalArgumentException("Requested bytes size must be > 0.");
         try (FileChannelImpl channelImpl = (FileChannelImpl)FileChannel.open(path, openOptions(mapMode))) {
             UnmapperProxy unmapperProxy = channelImpl.mapInternal(mapMode, 0L, bytesSize);
             MemoryScope scope = new MemoryScope(null, unmapperProxy::unmap);
+            int modes = defaultAccessModes(bytesSize);
+            if (mapMode == FileChannel.MapMode.READ_ONLY) {
+                modes &= ~WRITE;
+            }
             return new MappedMemorySegmentImpl(unmapperProxy.address(), unmapperProxy, bytesSize,
-                    defaultAccessModes(bytesSize), Thread.currentThread(), scope);
+                    modes, Thread.currentThread(), scope);
         }
     }
 
     private static OpenOption[] openOptions(FileChannel.MapMode mapMode) {
         if (mapMode == FileChannel.MapMode.READ_ONLY) {
< prev index next >