This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push: new 82ff4624a8 Panama API cleanup 82ff4624a8 is described below commit 82ff4624a8c9d14986500dac7d2d0d4128a4538a Author: remm <r...@apache.org> AuthorDate: Thu Feb 16 21:48:51 2023 +0100 Panama API cleanup --- .../tomcat/util/net/openssl/panama/OpenSSLContext.java | 14 +++++++------- .../tomcat/util/net/openssl/panama/OpenSSLEngine.java | 16 ++++++++-------- .../org/apache/tomcat/util/openssl/RuntimeHelper.java | 6 +++--- .../openssl/SSL_CTX_set_cert_verify_callback$cb.java | 4 ++-- .../util/openssl/SSL_CTX_set_tmp_dh_callback$dh.java | 4 ++-- .../tomcat/util/openssl/SSL_set_info_callback$cb.java | 4 ++-- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/net/openssl/panama/OpenSSLContext.java b/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/net/openssl/panama/OpenSSLContext.java index c958c09f8a..d851c9731e 100644 --- a/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/net/openssl/panama/OpenSSLContext.java +++ b/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/net/openssl/panama/OpenSSLContext.java @@ -794,7 +794,7 @@ public class OpenSSLContext implements org.apache.tomcat.util.net.SSLContext { return SSL_TLSEXT_ERR_NOACK(); } try (var localArena = Arena.ofConfined()) { - MemorySegment inSeg = MemorySegment.ofAddress(in.address(), inlen, localArena); + MemorySegment inSeg = in.reinterpret(inlen, localArena.scope(), null); byte[] advertisedBytes = inSeg.toArray(ValueLayout.JAVA_BYTE); for (byte[] negotiableProtocolBytes : state.negotiableProtocols) { for (int i = 0; i <= advertisedBytes.length - negotiableProtocolBytes.length; i++) { @@ -803,9 +803,9 @@ public class OpenSSLContext implements org.apache.tomcat.util.net.SSLContext { if (advertisedBytes[i + j] == negotiableProtocolBytes[j]) { if (j == negotiableProtocolBytes.length - 1) { // Match - MemorySegment outSeg = MemorySegment.ofAddress(out.address(), ValueLayout.ADDRESS.byteSize(), localArena); + MemorySegment outSeg = out.reinterpret(ValueLayout.ADDRESS.byteSize(), localArena.scope(), null); outSeg.set(ValueLayout.ADDRESS, 0, inSeg.asSlice(i)); - MemorySegment outlenSeg = MemorySegment.ofAddress(outlen.address(), ValueLayout.JAVA_BYTE.byteSize(), localArena); + MemorySegment outlenSeg = outlen.reinterpret(ValueLayout.JAVA_BYTE.byteSize(), localArena.scope(), null); outlenSeg.set(ValueLayout.JAVA_BYTE, 0, (byte) negotiableProtocolBytes.length); return SSL_TLSEXT_ERR_OK(); } @@ -851,7 +851,7 @@ public class OpenSSLContext implements org.apache.tomcat.util.net.SSLContext { continue; } MemorySegment buf = bufPointer.get(ValueLayout.ADDRESS, 0); - certificateChain[i] = MemorySegment.ofAddress(buf.address(), length, localArena).toArray(ValueLayout.JAVA_BYTE); + certificateChain[i] = buf.reinterpret(length, localArena.scope(), null).toArray(ValueLayout.JAVA_BYTE); CRYPTO_free(buf, MemorySegment.NULL, 0); // OPENSSL_free macro } MemorySegment cipher = SSL_get_current_cipher(ssl); @@ -965,7 +965,7 @@ public class OpenSSLContext implements org.apache.tomcat.util.net.SSLContext { // The password is too long log.error(sm.getString("openssl.passwordTooLong")); } else { - MemorySegment bufSegment = MemorySegment.ofAddress(buf.address(), bufsiz, localArena); + MemorySegment bufSegment = buf.reinterpret(bufsiz, localArena.scope(), null); bufSegment.copyFrom(callbackPasswordNative); return (int) callbackPasswordNative.byteSize(); } @@ -1383,9 +1383,9 @@ public class OpenSSLContext implements org.apache.tomcat.util.net.SSLContext { this.negotiableProtocols = negotiableProtocols; // Use another arena to avoid keeping a reference through segments // This also allows making further accesses to the main pointers safer - this.sslCtx = MemorySegment.ofAddress(sslCtx.address(), ValueLayout.ADDRESS.byteSize(), stateArena); + this.sslCtx = sslCtx.reinterpret(ValueLayout.ADDRESS.byteSize(), stateArena.scope(), null); if (!MemorySegment.NULL.equals(confCtx)) { - this.confCtx = MemorySegment.ofAddress(confCtx.address(), ValueLayout.ADDRESS.byteSize(), stateArena); + this.confCtx = confCtx.reinterpret(ValueLayout.ADDRESS.byteSize(), stateArena.scope(), null); } else { this.confCtx = null; } diff --git a/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/net/openssl/panama/OpenSSLEngine.java b/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/net/openssl/panama/OpenSSLEngine.java index bff4228faf..dbfee4dced 100644 --- a/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/net/openssl/panama/OpenSSLEngine.java +++ b/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/net/openssl/panama/OpenSSLEngine.java @@ -914,7 +914,7 @@ public final class OpenSSLEngine extends SSLEngine implements SSLUtil.ProtocolIn return null; } MemorySegment buf = bufPointer.get(ValueLayout.ADDRESS, 0); - byte[] certificate = MemorySegment.ofAddress(buf.address(), length, localArena).toArray(ValueLayout.JAVA_BYTE); + byte[] certificate = buf.reinterpret(length, localArena.scope(), null).toArray(ValueLayout.JAVA_BYTE); X509_free(x509); CRYPTO_free(buf, MemorySegment.NULL, 0); // OPENSSL_free macro return certificate; @@ -938,7 +938,7 @@ public final class OpenSSLEngine extends SSLEngine implements SSLUtil.ProtocolIn continue; } MemorySegment buf = bufPointer.get(ValueLayout.ADDRESS, 0); - byte[] certificate = MemorySegment.ofAddress(buf.address(), length, localArena).toArray(ValueLayout.JAVA_BYTE); + byte[] certificate = buf.reinterpret(length, localArena.scope(), null).toArray(ValueLayout.JAVA_BYTE); certificateChain[i] = certificate; CRYPTO_free(buf, MemorySegment.NULL, 0); // OPENSSL_free macro } @@ -959,7 +959,7 @@ public final class OpenSSLEngine extends SSLEngine implements SSLUtil.ProtocolIn return null; } MemorySegment protocolAddress = protocolPointer.get(ValueLayout.ADDRESS, 0); - byte[] name = MemorySegment.ofAddress(protocolAddress.address(), length, localArena).toArray(ValueLayout.JAVA_BYTE); + byte[] name = protocolAddress.reinterpret(length, localArena.scope(), null).toArray(ValueLayout.JAVA_BYTE); if (log.isDebugEnabled()) { log.debug("Protocol negotiated [" + new String(name) + "]"); } @@ -1329,7 +1329,7 @@ public final class OpenSSLEngine extends SSLEngine implements SSLUtil.ProtocolIn int length = ASN1_STRING_length(os); MemorySegment data = ASN1_STRING_get0_data(os); // ocsp_urls = decode_OCSP_url(os); - byte[] asn1String = MemorySegment.ofAddress(data.address(), length, localArenal).toArray(ValueLayout.JAVA_BYTE); + byte[] asn1String = data.reinterpret(length, localArenal.scope(), null).toArray(ValueLayout.JAVA_BYTE); Asn1Parser parser = new Asn1Parser(asn1String); // Parse the byte sequence ArrayList<String> urls = new ArrayList<>(); @@ -1425,7 +1425,7 @@ public final class OpenSSLEngine extends SSLEngine implements SSLUtil.ProtocolIn // Host: urlHost:urlPort // Content-Type: application/ocsp-request // Content-Length: ocspRequestData.length - byte[] ocspRequestData = MemorySegment.ofAddress(buf.address(), requestLength, localArena).toArray(ValueLayout.JAVA_BYTE); + byte[] ocspRequestData = buf.reinterpret(requestLength, localArena.scope(), null).toArray(ValueLayout.JAVA_BYTE); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setDoInput(true); @@ -1515,7 +1515,7 @@ public final class OpenSSLEngine extends SSLEngine implements SSLUtil.ProtocolIn MemorySegment sessionId = SSL_SESSION_get_id(session, lenPointer); int len = lenPointer.get(ValueLayout.JAVA_INT, 0); id = (len == 0) ? new byte[0] - : MemorySegment.ofAddress(sessionId.address(), len, localArena).toArray(ValueLayout.JAVA_BYTE); + : sessionId.reinterpret(len, localArena.scope(), null).toArray(ValueLayout.JAVA_BYTE); } } } @@ -1814,8 +1814,8 @@ public final class OpenSSLEngine extends SSLEngine implements SSLUtil.ProtocolIn this.noOcspCheck = noOcspCheck; // Use another arena to avoid keeping a reference through segments // This also allows making further accesses to the main pointers safer - this.ssl = MemorySegment.ofAddress(ssl.address(), ValueLayout.ADDRESS.byteSize(), stateArena); - this.networkBIO = MemorySegment.ofAddress(networkBIO.address(), ValueLayout.ADDRESS.byteSize(), stateArena); + this.ssl = ssl.reinterpret(ValueLayout.ADDRESS.byteSize(), stateArena.scope(), null); + this.networkBIO = networkBIO.reinterpret(ValueLayout.ADDRESS.byteSize(), stateArena.scope(), null); } @Override diff --git a/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/openssl/RuntimeHelper.java b/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/openssl/RuntimeHelper.java index 8196a9a3dd..ad46c35012 100644 --- a/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/openssl/RuntimeHelper.java +++ b/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/openssl/RuntimeHelper.java @@ -69,7 +69,7 @@ final class RuntimeHelper { static MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) { return SYMBOL_LOOKUP.find(name) - .map(s -> s.asUnbounded().asSlice(0, layout)) + .map(s -> s.reinterpret(layout.byteSize())) .orElse(null); } @@ -99,8 +99,8 @@ final class RuntimeHelper { } } - static MemorySegment asArray(MemorySegment addr, MemoryLayout layout, int numElements, Arena scope) { - return MemorySegment.ofAddress(addr.address(), numElements * layout.byteSize(), scope); + static MemorySegment asArray(MemorySegment addr, MemoryLayout layout, int numElements, Arena arena) { + return addr.reinterpret(numElements * layout.byteSize(), arena.scope(), null); } // Internals only below this point diff --git a/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/openssl/SSL_CTX_set_cert_verify_callback$cb.java b/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/openssl/SSL_CTX_set_cert_verify_callback$cb.java index 45b39d6a77..3f88ab4832 100644 --- a/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/openssl/SSL_CTX_set_cert_verify_callback$cb.java +++ b/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/openssl/SSL_CTX_set_cert_verify_callback$cb.java @@ -35,8 +35,8 @@ public interface SSL_CTX_set_cert_verify_callback$cb { static MemorySegment allocate(SSL_CTX_set_cert_verify_callback$cb fi, Arena scope) { return RuntimeHelper.upcallStub(SSL_CTX_set_cert_verify_callback$cb.class, fi, constants$15.SSL_CTX_set_cert_verify_callback$cb$FUNC, scope); } - static SSL_CTX_set_cert_verify_callback$cb ofAddress(MemorySegment addr, Arena scope) { - MemorySegment symbol = MemorySegment.ofAddress(addr.address(), 0, scope); + static SSL_CTX_set_cert_verify_callback$cb ofAddress(MemorySegment addr, Arena arena) { + MemorySegment symbol = addr.reinterpret(arena.scope(), null); return (java.lang.foreign.MemorySegment __x0, java.lang.foreign.MemorySegment __x1) -> { try { return (int)constants$15.SSL_CTX_set_cert_verify_callback$cb$MH.invokeExact(symbol, __x0, __x1); diff --git a/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/openssl/SSL_CTX_set_tmp_dh_callback$dh.java b/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/openssl/SSL_CTX_set_tmp_dh_callback$dh.java index 2ec933e3a5..88229dc469 100644 --- a/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/openssl/SSL_CTX_set_tmp_dh_callback$dh.java +++ b/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/openssl/SSL_CTX_set_tmp_dh_callback$dh.java @@ -35,8 +35,8 @@ public interface SSL_CTX_set_tmp_dh_callback$dh { static MemorySegment allocate(SSL_CTX_set_tmp_dh_callback$dh fi, Arena scope) { return RuntimeHelper.upcallStub(SSL_CTX_set_tmp_dh_callback$dh.class, fi, constants$21.SSL_CTX_set_tmp_dh_callback$dh$FUNC, scope); } - static SSL_CTX_set_tmp_dh_callback$dh ofAddress(MemorySegment addr, Arena scope) { - MemorySegment symbol = MemorySegment.ofAddress(addr.address(), 0, scope); + static SSL_CTX_set_tmp_dh_callback$dh ofAddress(MemorySegment addr, Arena arena) { + MemorySegment symbol = addr.reinterpret(arena.scope(), null); return (java.lang.foreign.MemorySegment __x0, int __x1, int __x2) -> { try { return (java.lang.foreign.MemorySegment)constants$22.SSL_CTX_set_tmp_dh_callback$dh$MH.invokeExact(symbol, __x0, __x1, __x2); diff --git a/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/openssl/SSL_set_info_callback$cb.java b/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/openssl/SSL_set_info_callback$cb.java index 2f8267cc81..8b5748f4eb 100644 --- a/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/openssl/SSL_set_info_callback$cb.java +++ b/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/openssl/SSL_set_info_callback$cb.java @@ -35,8 +35,8 @@ public interface SSL_set_info_callback$cb { static MemorySegment allocate(SSL_set_info_callback$cb fi, Arena scope) { return RuntimeHelper.upcallStub(SSL_set_info_callback$cb.class, fi, constants$21.SSL_set_info_callback$cb$FUNC, scope); } - static SSL_set_info_callback$cb ofAddress(MemorySegment addr, Arena scope) { - MemorySegment symbol = MemorySegment.ofAddress(addr.address(), 0, scope); + static SSL_set_info_callback$cb ofAddress(MemorySegment addr, Arena arena) { + MemorySegment symbol = addr.reinterpret(arena.scope(), null); return (java.lang.foreign.MemorySegment __x0, int __x1, int __x2) -> { try { constants$21.SSL_set_info_callback$cb$MH.invokeExact(symbol, __x0, __x1, __x2); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org