Search in sources :

Example 1 with CEntryPointCreateIsolateParameters

use of com.oracle.svm.core.c.function.CEntryPointCreateIsolateParameters in project graal by oracle.

the class JavaMainWrapper method getCRuntimeArgumentBlockLength.

/**
 * Argv is an array of C strings (i.e. array of pointers to characters). Each entry points to a
 * different C string corresponding to a program argument. The program argument strings
 * themselves are located in a contiguous block of memory followed by the environment variables
 * key-value strings:
 *
 * <pre>
 * &lt;argument_0&gt;\n&lt;argument_1&gt;\n...&lt;argument_n&gt;\n
 * &lt;env_key_value_1&gt;\n&lt;env_key_value_2&gt;\n...&lt;env_key_value_n&gt;\n
 * </pre>
 *
 * @return maximum length of C chars that can be stored in the program argument part of the
 *         contiguous memory block without writing into the environment variables part.
 */
public static int getCRuntimeArgumentBlockLength() {
    if (!isArgumentBlockSupported()) {
        return -1;
    }
    CEntryPointCreateIsolateParameters args = MAIN_ISOLATE_PARAMETERS.get();
    CCharPointer firstArgPos = args.getArgv().read(0);
    if (argvLength.equal(WordFactory.zero())) {
        // Get char* to last program argument
        CCharPointer lastArgPos = args.getArgv().read(args.getArgc() - 1);
        // Determine the length of the last program argument
        UnsignedWord lastArgLength = SubstrateUtil.strlen(lastArgPos);
        // Determine maximum C string length that can be stored in the program argument part
        argvLength = WordFactory.unsigned(lastArgPos.rawValue()).add(lastArgLength).subtract(WordFactory.unsigned(firstArgPos.rawValue()));
    }
    return Math.toIntExact(argvLength.rawValue());
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) CEntryPointCreateIsolateParameters(com.oracle.svm.core.c.function.CEntryPointCreateIsolateParameters) CCharPointer(org.graalvm.nativeimage.c.type.CCharPointer)

Aggregations

CEntryPointCreateIsolateParameters (com.oracle.svm.core.c.function.CEntryPointCreateIsolateParameters)1 CCharPointer (org.graalvm.nativeimage.c.type.CCharPointer)1 UnsignedWord (org.graalvm.word.UnsignedWord)1