mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8296024: Usage of DirectBuffer::address should be guarded
Reviewed-by: mcimadamore, alanb, psandoz, bpb
This commit is contained in:
parent
a9e6c62ba7
commit
84b927a05b
24 changed files with 635 additions and 430 deletions
|
@ -25,11 +25,13 @@
|
|||
|
||||
package sun.nio.fs;
|
||||
|
||||
import java.lang.ref.Reference;
|
||||
import java.nio.file.*;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import jdk.internal.access.JavaNioAccess;
|
||||
import jdk.internal.access.SharedSecrets;
|
||||
import jdk.internal.misc.Unsafe;
|
||||
|
||||
import static sun.nio.fs.UnixConstants.*;
|
||||
|
@ -43,6 +45,8 @@ abstract class UnixUserDefinedFileAttributeView
|
|||
{
|
||||
private static final Unsafe unsafe = Unsafe.getUnsafe();
|
||||
|
||||
private static final JavaNioAccess NIO_ACCESS = SharedSecrets.getJavaNioAccess();
|
||||
|
||||
// namespace for extended user attributes
|
||||
private static final String USER_NAMESPACE = "user.";
|
||||
|
||||
|
@ -174,14 +178,15 @@ abstract class UnixUserDefinedFileAttributeView
|
|||
assert (pos <= lim);
|
||||
int rem = (pos <= lim ? lim - pos : 0);
|
||||
|
||||
if (dst instanceof sun.nio.ch.DirectBuffer buf) {
|
||||
if (dst instanceof sun.nio.ch.DirectBuffer ddst) {
|
||||
NIO_ACCESS.acquireSession(dst);
|
||||
try {
|
||||
long address = buf.address() + pos;
|
||||
long address = ddst.address() + pos;
|
||||
int n = read(name, address, rem);
|
||||
dst.position(pos + n);
|
||||
return n;
|
||||
} finally {
|
||||
Reference.reachabilityFence(buf);
|
||||
NIO_ACCESS.releaseSession(dst);
|
||||
}
|
||||
} else {
|
||||
try (NativeBuffer nb = NativeBuffers.getNativeBuffer(rem)) {
|
||||
|
@ -237,13 +242,14 @@ abstract class UnixUserDefinedFileAttributeView
|
|||
int rem = (pos <= lim ? lim - pos : 0);
|
||||
|
||||
if (src instanceof sun.nio.ch.DirectBuffer buf) {
|
||||
NIO_ACCESS.acquireSession(src);
|
||||
try {
|
||||
long address = buf.address() + pos;
|
||||
write(name, address, rem);
|
||||
src.position(pos + rem);
|
||||
return rem;
|
||||
} finally {
|
||||
Reference.reachabilityFence(buf);
|
||||
NIO_ACCESS.releaseSession(src);
|
||||
}
|
||||
} else {
|
||||
try (NativeBuffer nb = NativeBuffers.getNativeBuffer(rem)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue