use of org.graalvm.nativeimage.c.type.WordPointer in project graal by oracle.
the class Util_jni method socketSetOption.
/* Do not re-format commented-out code: @formatter:off */
// 886 /*
// 887 * Class: java_net_PlainSocketImpl
// 888 * Method: socketSetOption
// 889 * Signature: (IZLjava/lang/Object;)V
// 890 */
// 891 JNIEXPORT void JNICALL
// 892 Java_java_net_PlainSocketImpl_socketSetOption(JNIEnv *env, jobject this,
// 893 jint cmd, jboolean on,
// 894 jobject value) {
@Substitute
void socketSetOption(int cmd, boolean on, Object value) throws SocketException {
// 895 int fd;
int fd;
// 896 int level, optname, optlen;
CIntPointer level_Pointer = StackValue.get(SizeOf.get(CIntPointer.class));
CIntPointer optname_Pointer = StackValue.get(SizeOf.get(CIntPointer.class));
int optlen;
/* Translated as a WordPointer to the larger of the arms. */
// 897 union {
// 898 int i;
// 899 struct linger ling;
// 900 } optval;
/* Guess which arm of the union is larger. Trust, but verify. */
final int sizeof_optval = SizeOf.get(Socket.linger.class);
VMError.guarantee(SizeOf.get(CIntPointer.class) <= sizeof_optval, "sizeof(int) <= sizeof(union optval)");
VMError.guarantee(SizeOf.get(Socket.linger.class) <= sizeof_optval, "sizeof(struct linger) <= sizeof(union optval)");
WordPointer optval_Pointer = StackValue.get(sizeof_optval);
// 901
// 902 /*
// 903 * Check that socket hasn't been closed
// 904 */
// 905 fd = getFD(env, this);
fd = Util_java_io_FileDescriptor.getFD(Util_java_net_PlainSocketImpl.as_Target_java_net_SocketImpl(this).fd);
// 906 if (fd < 0) {
if (fd < 0) {
// 909 return;
throw new SocketException("Socket closed");
}
// 915 if (cmd == java_net_SocketOptions_SO_TIMEOUT) {
if (cmd == SocketOptions.SO_TIMEOUT) {
// 916 return;
return;
}
// 923 if (NET_MapSocketOption(cmd, &level, &optname)) {
if (CTypeConversion.toBoolean(JavaNetNetUtilMD.NET_MapSocketOption(cmd, level_Pointer, optname_Pointer))) {
// 925 return;
throw new SocketException("Invalid option");
}
// 928 switch (cmd) {
switch(cmd) {
// 932 case java_net_SocketOptions_IP_TOS :
case SocketOptions.SO_SNDBUF:
case SocketOptions.SO_RCVBUF:
case SocketOptions.SO_LINGER:
case SocketOptions.IP_TOS:
{
/* Accessing values of java.lang.Integer the easy way. */
Integer valueInteger = (Integer) value;
// 942 if (cmd == java_net_SocketOptions_SO_LINGER) {
if (cmd == SocketOptions.SO_LINGER) {
// 943 if (on) {
if (on) {
// 944 optval.ling.l_onoff = 1;
((Socket.linger) optval_Pointer).set_l_onoff(1);
// 945 optval.ling.l_linger = (*env)->GetIntField(env, value, fid);
((Socket.linger) optval_Pointer).set_l_linger(valueInteger.intValue());
} else {
// 947 optval.ling.l_onoff = 0;
((Socket.linger) optval_Pointer).set_l_onoff(0);
// 948 optval.ling.l_linger = 0;
((Socket.linger) optval_Pointer).set_l_linger(0);
}
// 950 optlen = sizeof(optval.ling);
optlen = SizeOf.get(Socket.linger.class);
/* Copy to optval. */
LibC.memcpy(optval_Pointer, optval_Pointer, WordFactory.unsigned(optlen));
} else {
// 952 optval.i = (*env)->GetIntField(env, value, fid);
((CIntPointer) optval_Pointer).write(valueInteger.intValue());
// 953 optlen = sizeof(optval.i);
optlen = SizeOf.get(CIntPointer.class);
/* Copy to optval. */
LibC.memcpy(optval_Pointer, optval_Pointer, WordFactory.unsigned(optlen));
}
// 956 break;
break;
}
// 960 default :
default:
// 961 optval.i = (on ? 1 : 0);
((CIntPointer) optval_Pointer).write(on ? 1 : 0);
// 962 optlen = sizeof(optval.i);
optlen = SizeOf.get(CIntPointer.class);
/* Copy to optval. */
LibC.memcpy(optval_Pointer, optval_Pointer, WordFactory.unsigned(optlen));
}
// 966 if (NET_SetSockOpt(fd, level, optname, (const void *)&optval, optlen) < 0) {
if (JavaNetNetUtilMD.NET_SetSockOpt(fd, level_Pointer.read(), optname_Pointer.read(), optval_Pointer, optlen) < 0) {
// 968 if (errno == EINVAL) {
if (Errno.errno() == Errno.EINVAL()) {
// 974 return;
throw new SocketException("Invalid option or socket reset by remote peer");
}
// 978 "Error setting socket option");
throw new SocketException("Error setting socket option");
}
}
use of org.graalvm.nativeimage.c.type.WordPointer in project graal by oracle.
the class NativeClosure method call.
private Object call(WordPointer argPointers, ByteBuffer retBuffer) {
Target_com_oracle_truffle_nfi_impl_LibFFIType[] argTypes = signature.getArgTypes();
int length = argTypes.length - skippedArgCount;
if (retBuffer != null) {
length++;
}
int argIdx = 0;
Object[] args = new Object[length];
for (int i = 0; i < argTypes.length; i++) {
Object type = argTypes[i];
if (Target_com_oracle_truffle_nfi_impl_LibFFIType_StringType.class.isInstance(type)) {
CCharPointerPointer argPtr = argPointers.read(i);
args[argIdx++] = TruffleNFISupport.utf8ToJavaString(argPtr.read());
} else if (Target_com_oracle_truffle_nfi_impl_LibFFIType_ObjectType.class.isInstance(type)) {
WordPointer argPtr = argPointers.read(i);
args[argIdx++] = ImageSingletons.lookup(TruffleNFISupport.class).resolveHandle(argPtr.read());
} else if (Target_com_oracle_truffle_nfi_impl_LibFFIType_EnvType.class.isInstance(type)) {
// skip
} else {
WordPointer argPtr = argPointers.read(i);
args[argIdx++] = SubstrateUtil.wrapAsByteBuffer(argPtr, argTypes[i].size);
}
}
if (retBuffer != null) {
args[argIdx] = retBuffer;
}
return callTarget.call(args);
}
use of org.graalvm.nativeimage.c.type.WordPointer in project graal by oracle.
the class NativeClosure method prepareClosure.
static Target_com_oracle_truffle_nfi_impl_ClosureNativePointer prepareClosure(Target_com_oracle_truffle_nfi_impl_NFIContext ctx, Target_com_oracle_truffle_nfi_impl_LibFFISignature signature, CallTarget callTarget, ffi_closure_callback callback) {
NativeClosure closure = new NativeClosure(callTarget, signature);
NativeClosureHandle handle = ImageSingletons.lookup(TruffleNFISupport.class).createClosureHandle(closure);
WordPointer codePtr = StackValue.get(SizeOf.get(WordPointer.class));
ClosureData data = ffi_closure_alloc(SizeOf.unsigned(ClosureData.class), codePtr);
data.setNativeClosureHandle(handle);
data.setIsolate(CEntryPointContext.getCurrentIsolate());
PointerBase code = codePtr.read();
LibFFI.ffi_prep_closure_loc(data.ffiClosure(), WordFactory.pointer(signature.cif), callback, data, code);
return ctx.createClosureNativePointer(data.rawValue(), code.rawValue(), callTarget, signature);
}
Aggregations