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>
* <argument_0>\n<argument_1>\n...<argument_n>\n
* <env_key_value_1>\n<env_key_value_2>\n...<env_key_value_n>\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());
}
Aggregations