Search in sources :

Example 1 with WordPointer

use of org.graalvm.nativeimage.c.type.WordPointer in project graal by oracle.

the class PosixCEntryPointSnippets method createIsolate.

@Uninterruptible(reason = "Thread state not yet set up.")
@SubstrateForeignCallTarget
private static int createIsolate(CEntryPointCreateIsolateParameters parameters, int vmThreadSize) {
    WordPointer isolate = StackValue.get(SizeOf.get(WordPointer.class));
    isolate.write(Word.nullPointer());
    int error = PosixIsolates.create(isolate, parameters);
    if (error != Errors.NO_ERROR) {
        return error;
    }
    if (UseHeapBaseRegister.getValue()) {
        setHeapBase(PosixIsolates.getHeapBase(isolate.read()));
    }
    if (MultiThreaded.getValue()) {
        PosixVMThreads.ensureInitialized();
    }
    return attachThread(isolate.read(), vmThreadSize);
}
Also used : WordPointer(org.graalvm.nativeimage.c.type.WordPointer) Safepoint(com.oracle.svm.core.thread.Safepoint) SubstrateForeignCallTarget(com.oracle.svm.core.snippets.SubstrateForeignCallTarget) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible)

Example 2 with WordPointer

use of org.graalvm.nativeimage.c.type.WordPointer in project graal by oracle.

the class PosixIsolates method create.

@Uninterruptible(reason = "Thread state not yet set up.")
public static int create(WordPointer isolatePointer, @SuppressWarnings("unused") CEntryPointCreateIsolateParameters parameters) {
    if (!SubstrateOptions.SpawnIsolates.getValue()) {
        isolatePointer.write(CEntryPointSetup.SINGLE_ISOLATE_SENTINEL);
        return Errors.NO_ERROR;
    }
    Word begin = IMAGE_HEAP_BEGIN.get();
    Word size = IMAGE_HEAP_END.get().subtract(begin);
    /*
         * Request an anonymous memory mapping for this isolate's clone of the image heap. The start
         * address of that mapping becomes the isolate's heap base address. We want extra heap
         * chunks that we allocate later to be at a higher address than the heap base so that we can
         * safely consider the base-relative offsets to be unsigned. Therefore, we request the
         * lowest non-zero multiple of the page size as this mapping's address. However, that
         * request is only a hint unless we use MAP_FIXED, which makes things much more complex on
         * our end. Observations:
         *
         * - Without a hint to mmap(), anonymous mappings on Linux 4.4 (openSUSE) on x86_64 are
         * created just before the mapped shared objects, and subsequent mappings are assigned
         * decreasing addresses. However, specifying sysconf(_SC_PAGE_SIZE) as a hint for the first
         * mapping reproducingly places it at a very low address, even before the loaded executable.
         * Therefore, it seems that a number of isolates can be reliably created with their image
         * heap clones at low addresses and with allocated heap chunks at higher addresses.
         *
         * - On Darwin 13.4, anonymous mappings are created after the mapped executable (and some
         * malloc regions in between). Subsequent mappings are assigned increasing addresses that
         * are close to each other. Specifying hints does not have a noticeable effect. Unmapping a
         * mapping makes its address space immediately reusable. Due to the increasing addresses, a
         * single isolate's heap can be safely created. However, because of the address space reuse,
         * a heap chunk of an isolate can be allocated at a lower address than its heap base when
         * another isolate unmaps a chunk at that location.
         */
    long pageSize = Unistd.NoTransitions.sysconf(Unistd._SC_PAGE_SIZE());
    Pointer heap = Mman.NoTransitions.mmap(Word.pointer(pageSize), size, PROT_READ() | PROT_WRITE(), MAP_ANON() | MAP_PRIVATE(), -1, 0);
    if (heap.equal(MAP_FAILED())) {
        return Errors.HEAP_CLONE_FAILED;
    }
    LibC.memcpy(heap, begin, size);
    isolatePointer.write(heap);
    return Errors.NO_ERROR;
}
Also used : Word(org.graalvm.compiler.word.Word) WordPointer(org.graalvm.nativeimage.c.type.WordPointer) Pointer(org.graalvm.word.Pointer) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible)

Example 3 with WordPointer

use of org.graalvm.nativeimage.c.type.WordPointer in project graal by oracle.

the class JavavmExportJvm method NET_SetSockOpt.

/* @formatter:on */
/* Do not re-wrap commented-out code.  @formatter:off */
// 1266 /*
// 1267  * Wrapper for setsockopt system routine - performs any
// 1268  * necessary pre/post processing to deal with OS specific
// 1269  * issue :-
// 1270  *
// 1271  * On Solaris need to limit the suggested value for SO_SNDBUF
// 1272  * and SO_RCVBUF to the kernel configured limit
// 1273  *
// 1274  * For IP_TOS socket option need to mask off bits as this
// 1275  * aren't automatically masked by the kernel and results in
// 1276  * an error. In addition IP_TOS is a NOOP with IPv6 as it
// 1277  * should be setup as connection time.
// 1278  */
// 1279 int
// 1280 NET_SetSockOpt(int fd, int level, int  opt, const void *arg,
// 1281                int len)
// 1282 {
static int NET_SetSockOpt(int fd, int level, int opt, WordPointer arg, int len) {
    // 1283
    // 1284 #ifndef IPTOS_TOS_MASK
    // 1285 #define IPTOS_TOS_MASK 0x1e
    final int IPTOS_TOS_MASK = 0x1e;
    // 1286 #endif
    // 1287 #ifndef IPTOS_PREC_MASK
    // 1288 #define IPTOS_PREC_MASK 0xe0
    final int IPTOS_PREC_MASK = 0xe0;
    // 1289 #endif
    // 1290
    // 1291 #if defined(_ALLBSD_SOURCE)
    /* Hoist declarations out of "#if defined" block". */
    CIntPointer mib = null;
    CLongPointer rlen_Pointer = null;
    CIntPointer bufsize = null;
    /* maxsockbuf should be static. */
    /* Declaring maxsockbuf to be a CIntPointer because it is only used inside _ALLBSD_SOURCE. */
    CIntPointer maxsockbuf_Pointer = StackValue.get(SizeOf.get(CIntPointer.class));
    int maxsockbuf_size = SizeOf.get(CIntPointer.class);
    if (IsDefined._ALLBSD_SOURCE()) {
        // 1292 #if defined(KIPC_MAXSOCKBUF)
        if (IsDefined.sysctl_KIPC_MAXSOCKBUF()) {
            // 1293     int mib[3];
            mib = StackValue.get(3, SizeOf.get(CIntPointer.class));
            // 1294     size_t rlen;
            rlen_Pointer = StackValue.get(SizeOf.get(CLongPointer.class));
        }
        // 1295 #endif
        // 1296
        // 1297     int *bufsize;
        bufsize = StackValue.get(SizeOf.get(CIntPointer.class));
        // 1299 #ifdef __APPLE__
        if (IsDefined.__APPLE__()) {
            // 1300     static int maxsockbuf = -1;
            maxsockbuf_Pointer.write(-1);
            maxsockbuf_size = SizeOf.get(CIntPointer.class);
        // 1301 #else
        } else {
            // 1302     static long maxsockbuf = -1;
            VMError.unimplemented();
        }
    // 1303 #endif
    }
    // 1317     if (level == IPPROTO_IP && opt == IP_TOS) {
    if (level == NetinetIn.IPPROTO_IP() && opt == NetinetIn.IP_TOS()) {
        // 1318         int *iptos;
        CIntPointer iptos = StackValue.get(SizeOf.get(CIntPointer.class));
        // 1320 #if defined(AF_INET6) && (defined(__solaris__) || defined(MACOSX))
        if (IsDefined.socket_AF_INET6() && (IsDefined.__solaris__() || IsDefined.MACOSX())) {
            // 1321         if (ipv6_available()) {
            if (JavaNetNetUtil.ipv6_available()) {
                // 1322             return 0;
                return 0;
            }
        // 1324 #endif
        }
        // 1326 #if defined(AF_INET6) && defined(__linux__)
        if (IsDefined.socket_AF_INET6() && IsDefined.__linux__()) {
            VMError.unimplemented();
        // 1327         if (ipv6_available()) {
        // 1328             int optval = 1;
        // 1329             if (setsockopt(fd, IPPROTO_IPV6, IPV6_FLOWINFO_SEND,
        // 1330                            (void *)&optval, sizeof(optval)) < 0) {
        // 1331                 return -1;
        // 1332             }
        // 1332         }
        }
        // 1334 #endif
        // 1335
        // 1336         iptos = (int *)arg;
        iptos = (CIntPointer) arg;
        // 1337         *iptos &= (IPTOS_TOS_MASK | IPTOS_PREC_MASK);
        iptos.write(iptos.read() & (IPTOS_TOS_MASK | IPTOS_PREC_MASK));
    }
    // 1344 #ifdef __solaris__
    if (IsDefined.__solaris__()) {
        VMError.unimplemented();
    // 1345     if (level == SOL_SOCKET) {
    // 1346         if (opt == SO_SNDBUF || opt == SO_RCVBUF) {
    // 1347             int sotype=0, arglen;
    // 1348             int *bufsize, maxbuf;
    // 1349             int ret;
    // 1350
    // 1351             /* Attempt with the original size */
    // 1352             ret = setsockopt(fd, level, opt, arg, len);
    // 1353             if ((ret == 0) || (ret == -1 && errno != ENOBUFS))
    // 1354                 return ret;
    // 1355
    // 1356             /* Exceeded system limit so clamp and retry */
    // 1357
    // 1358             arglen = sizeof(sotype);
    // 1359             if (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void *)&sotype,
    // 1360                            &arglen) < 0) {
    // 1361                 return -1;
    // 1362             }
    // 1363
    // 1364             /*
    // 1365              * We try to get tcp_maxbuf (and udp_max_buf) using
    // 1366              * an ioctl() that isn't available on all versions of Solaris.
    // 1367              * If that fails, we use the search algorithm in findMaxBuf()
    // 1368              */
    // 1369             if (!init_tcp_max_buf && sotype == SOCK_STREAM) {
    // 1370                 tcp_max_buf = net_getParam("/dev/tcp", "tcp_max_buf");
    // 1371                 if (tcp_max_buf == -1) {
    // 1372                     tcp_max_buf = findMaxBuf(fd, opt, SOCK_STREAM);
    // 1373                     if (tcp_max_buf == -1) {
    // 1374                         return -1;
    // 1375                     }
    // 1376                 }
    // 1377                 init_tcp_max_buf = 1;
    // 1378             } else if (!init_udp_max_buf && sotype == SOCK_DGRAM) {
    // 1379                 udp_max_buf = net_getParam("/dev/udp", "udp_max_buf");
    // 1380                 if (udp_max_buf == -1) {
    // 1381                     udp_max_buf = findMaxBuf(fd, opt, SOCK_DGRAM);
    // 1382                     if (udp_max_buf == -1) {
    // 1383                         return -1;
    // 1384                     }
    // 1385                 }
    // 1386                 init_udp_max_buf = 1;
    // 1387             }
    // 1388
    // 1389             maxbuf = (sotype == SOCK_STREAM) ? tcp_max_buf : udp_max_buf;
    // 1390             bufsize = (int *)arg;
    // 1391             if (*bufsize > maxbuf) {
    // 1392                 *bufsize = maxbuf;
    // 1393             }
    // 1394         }
    // 1395     }
    }
    // 1427 #ifdef __linux__
    if (IsDefined.__linux__()) {
        // 1428     if (level == SOL_SOCKET && opt == SO_RCVBUF) {
        if (level == Socket.SOL_SOCKET() && opt == Socket.SO_RCVBUF()) {
            // 1429         int *bufsize = (int *)arg;
            bufsize = (CIntPointer) arg;
            // 1430         if (*bufsize < 1024) {
            if (bufsize.read() < 1024) {
                // 1431             *bufsize = 1024;
                bufsize.write(1024);
            }
        }
    }
    // 1436 #if defined(_ALLBSD_SOURCE)
    if (IsDefined._ALLBSD_SOURCE()) {
        // 1442     if (level == SOL_SOCKET) {
        if (level == Socket.SOL_SOCKET()) {
            // 1443         if (opt == SO_SNDBUF || opt == SO_RCVBUF) {
            if (opt == Socket.SO_SNDBUF() || opt == Socket.SO_RCVBUF()) {
                // 1444 #ifdef KIPC_MAXSOCKBUF
                if (IsDefined.sysctl_KIPC_MAXSOCKBUF()) {
                    // 1445             if (maxsockbuf == -1) {
                    if (maxsockbuf_Pointer.read() == -1) {
                        // 1446                mib[0] = CTL_KERN;
                        mib.write(0, DarwinSysctl.CTL_KERN());
                        // 1447                mib[1] = KERN_IPC;
                        mib.write(1, DarwinSysctl.KERN_IPC());
                        // 1448                mib[2] = KIPC_MAXSOCKBUF;
                        mib.write(2, DarwinSysctl.KIPC_MAXSOCKBUF());
                        // 1449                rlen = sizeof(maxsockbuf);
                        rlen_Pointer.write(maxsockbuf_size);
                        // 1450                if (sysctl(mib, 3, &maxsockbuf, &rlen, NULL, 0) == -1)
                        if (Sysctl.sysctl(mib, 3, maxsockbuf_Pointer, (WordPointer) rlen_Pointer, WordFactory.nullPointer(), 0) == -1) {
                            // 1451                    maxsockbuf = 1024;
                            maxsockbuf_Pointer.write(1024);
                        }
                        // 1453 #if 1
                        if (true) {
                            // 1454                /* XXXBSD: This is a hack to workaround mb_max/mb_max_adj
                            // 1455                   problem.  It should be removed when kern.ipc.maxsockbuf
                            // 1456                   will be real value. */
                            // 1457                maxsockbuf = (maxsockbuf/5)*4;
                            maxsockbuf_Pointer.write((maxsockbuf_Pointer.read() / 5) * 4);
                        }
                    // 1458 #endif
                    }
                // 1460 #elif defined(__OpenBSD__)
                } else if (IsDefined.__OpenBSD__()) {
                    VMError.unimplemented();
                // 1461            maxsockbuf = SB_MAX;
                // 1462 #else
                } else {
                    VMError.unimplemented();
                // 1463            maxsockbuf = 64 * 1024;      /* XXX: NetBSD */
                }
                // 1464 #endif
                // 1465
                // 1466            bufsize = (int *)arg;
                bufsize = (CIntPointer) arg;
                // 1467            if (*bufsize > maxsockbuf) {
                if (bufsize.read() > maxsockbuf_Pointer.read()) {
                    // 1468                *bufsize = maxsockbuf;
                    bufsize.write(maxsockbuf_Pointer.read());
                }
                // 1471            if (opt == SO_RCVBUF && *bufsize < 1024) {
                if (opt == Socket.SO_RCVBUF() && bufsize.read() < 1024) {
                    // 1472                 *bufsize = 1024;
                    bufsize.write(1024);
                }
            // 1474
            }
        }
    }
    // 1479 #if defined(_ALLBSD_SOURCE) || defined(_AIX)
    if (IsDefined._AIX()) {
        VMError.unimplemented();
    // 1480     /*
    // 1481      * On Solaris, SO_REUSEADDR will allow multiple datagram
    // 1482      * sockets to bind to the same port. The network jck tests check
    // 1483      * for this "feature", so we need to emulate it by turning on
    // 1484      * SO_REUSEPORT as well for that combination.
    // 1485      */
    // 1486     if (level == SOL_SOCKET && opt == SO_REUSEADDR) {
    // 1487         int sotype;
    // 1488         socklen_t arglen;
    // 1489
    // 1490         arglen = sizeof(sotype);
    // 1491         if (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void *)&sotype, &arglen) < 0) {
    // 1492             return -1;
    // 1493         }
    // 1494
    // 1495         if (sotype == SOCK_DGRAM) {
    // 1496             setsockopt(fd, level, SO_REUSEPORT, arg, len);
    // 1497         }
    // 1498     }
    }
    // 1501     return setsockopt(fd, level, opt, arg, len);
    return Socket.setsockopt(fd, level, opt, arg, len);
}
Also used : CIntPointer(org.graalvm.nativeimage.c.type.CIntPointer) WordPointer(org.graalvm.nativeimage.c.type.WordPointer) CLongPointer(org.graalvm.nativeimage.c.type.CLongPointer)

Example 4 with WordPointer

use of org.graalvm.nativeimage.c.type.WordPointer in project graal by oracle.

the class JNIFunctions method GetDirectBufferAddress.

@CEntryPoint
@CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, exceptionHandler = JNIExceptionHandlerReturnNullWord.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static WordPointer GetDirectBufferAddress(JNIEnvironment env, JNIObjectHandle handle) {
    WordPointer address = WordFactory.nullPointer();
    Object obj = JNIObjectHandles.getObject(handle);
    if (obj instanceof Target_java_nio_Buffer) {
        Target_java_nio_Buffer buf = (Target_java_nio_Buffer) obj;
        address = Word.pointer(buf.address);
    }
    return address;
}
Also used : WordPointer(org.graalvm.nativeimage.c.type.WordPointer) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Example 5 with WordPointer

use of org.graalvm.nativeimage.c.type.WordPointer in project graal by oracle.

the class Target_com_oracle_truffle_nfi_impl_NFIContext method executeObject.

@Substitute
Object executeObject(long cif, long functionPointer, byte[] primArgs, int patchCount, int[] patchOffsets, Object[] objArgs) {
    try (LocalNativeScope scope = TruffleNFISupport.createLocalScope(patchCount)) {
        NativeTruffleContext ctx = WordFactory.pointer(nativeContext);
        ffi_cif ffiCif = WordFactory.pointer(cif);
        WordPointer retPtr = StackValue.get(8);
        ExecuteHelper.execute(ctx, ffiCif, retPtr, functionPointer, primArgs, patchCount, patchOffsets, objArgs, scope);
        return ImageSingletons.lookup(TruffleNFISupport.class).resolveHandle(retPtr.read());
    }
}
Also used : LibFFI.ffi_cif(com.oracle.svm.truffle.nfi.libffi.LibFFI.ffi_cif) WordPointer(org.graalvm.nativeimage.c.type.WordPointer) NativeTruffleContext(com.oracle.svm.truffle.nfi.NativeAPI.NativeTruffleContext) Substitute(com.oracle.svm.core.annotate.Substitute)

Aggregations

WordPointer (org.graalvm.nativeimage.c.type.WordPointer)8 Substitute (com.oracle.svm.core.annotate.Substitute)2 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)2 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)2 CIntPointer (org.graalvm.nativeimage.c.type.CIntPointer)2 CEntryPointOptions (com.oracle.svm.core.c.function.CEntryPointOptions)1 Socket (com.oracle.svm.core.posix.headers.Socket)1 SubstrateForeignCallTarget (com.oracle.svm.core.snippets.SubstrateForeignCallTarget)1 Safepoint (com.oracle.svm.core.thread.Safepoint)1 ClosureData (com.oracle.svm.truffle.nfi.LibFFI.ClosureData)1 NativeClosureHandle (com.oracle.svm.truffle.nfi.LibFFI.NativeClosureHandle)1 NativeTruffleContext (com.oracle.svm.truffle.nfi.NativeAPI.NativeTruffleContext)1 LibFFI.ffi_cif (com.oracle.svm.truffle.nfi.libffi.LibFFI.ffi_cif)1 ServerSocket (java.net.ServerSocket)1 SocketException (java.net.SocketException)1 Word (org.graalvm.compiler.word.Word)1 PinnedObject (org.graalvm.nativeimage.PinnedObject)1 CCharPointerPointer (org.graalvm.nativeimage.c.type.CCharPointerPointer)1 CLongPointer (org.graalvm.nativeimage.c.type.CLongPointer)1 Pointer (org.graalvm.word.Pointer)1