8333849: (dc) DatagramChannel send/receive fails with UOE if buffer backed by memory segment allocated from shared arena

Reviewed-by: dfuchs
This commit is contained in:
Alan Bateman 2024-06-10 12:47:09 +00:00
parent ec1664e8c9
commit e7dc76b577
2 changed files with 509 additions and 3 deletions

View file

@ -806,14 +806,19 @@ class DatagramChannelImpl
}
}
/**
* Receives a datagram into a direct buffer.
*/
private int receiveIntoNativeBuffer(ByteBuffer bb, int rem, int pos,
boolean connected)
throws IOException
{
NIO_ACCESS.acquireSession(bb);
try {
long bufAddress = NIO_ACCESS.getBufferAddress(bb);
int n = receive0(fd,
((DirectBuffer)bb).address() + pos, rem,
bufAddress + pos,
rem,
sourceSockAddr.address(),
connected);
if (n > 0)
@ -991,6 +996,9 @@ class DatagramChannelImpl
}
}
/**
* Send a datagram contained in a direct buffer.
*/
private int sendFromNativeBuffer(FileDescriptor fd, ByteBuffer bb,
InetSocketAddress target)
throws IOException
@ -1003,9 +1011,13 @@ class DatagramChannelImpl
int written;
NIO_ACCESS.acquireSession(bb);
try {
long bufAddress = NIO_ACCESS.getBufferAddress(bb);
int addressLen = targetSocketAddress(target);
written = send0(fd, ((DirectBuffer)bb).address() + pos, rem,
targetSockAddr.address(), addressLen);
written = send0(fd,
bufAddress + pos,
rem,
targetSockAddr.address(),
addressLen);
} catch (PortUnreachableException pue) {
if (isConnected())
throw pue;