/* ZLib interface to hymem_free_memory. */ void zfree (void *opaque, void *address) { PORT_ACCESS_FROM_PORT ((HyPortLibrary *) opaque); hymem_free_memory (address); }
/* * Takes the command line (1 string) and breaks it into an * argc, argv[] style list. * Understands LFNs and strips quotes off the exe name. * also converts the string to ASCII. */ void freeArgvCmdLine(J9PortLibrary *portLibrary, char **argv) { PORT_ACCESS_FROM_PORT(portLibrary); j9mem_free_memory(argv[0]); j9mem_free_memory(argv); }
/* ZLib interface to hymem_allocate_memory. */ void * zalloc (void *opaque, U_32 items, U_32 size) { PORT_ACCESS_FROM_PORT (((HyPortLibrary *) opaque)); return hymem_allocate_memory (items * size); }
/** * Concatenates a variable number of null-terminated strings into a single string * using the specified port library to allocate memory. The variable number of * strings arguments must be terminated by a single NULL value. * * @param portLibrary - The port library used to allocate memory. * @return The concatenated string or NULL if no memory can be allocated. */ char * str_concat (HyPortLibrary * portLibrary, ...) { PORT_ACCESS_FROM_PORT (portLibrary); va_list argp; char *concatenated; UDATA concatenatedSize = 0; /* Walk the variable arguments once to compute the final size */ va_start (argp, portLibrary); while (1) { char *chunk = va_arg (argp, char *); if (chunk) { concatenatedSize += (UDATA)strlen (chunk); } else { break; } } va_end (argp); /* Allocate concatenated space */ concatenated = hymem_allocate_memory (concatenatedSize + 1 /* for null terminator */ ); if (!concatenated) { return NULL; } concatenated[0] = '\0'; /* Walk again concatenating the pieces */ va_start (argp, portLibrary); while (1) { char *chunk = va_arg (argp, char *); if (chunk) { strcat (concatenated, chunk); } else { break; } } va_end (argp); return concatenated; }
/* This function converts a unicode string into a char array */ LPSTR makeUnicodeToASCII(J9PortLibrary *portLibrary, LPWSTR path) { PORT_ACCESS_FROM_PORT(portLibrary); char* cmdline; int length; length = WideCharToMultiByte(OS_ENCODING_CODE_PAGE, OS_ENCODING_WC_FLAGS, path, -1, NULL, 0, NULL, NULL); cmdline = j9mem_allocate_memory(length + 1); if(NULL == cmdline) { return NULL; } WideCharToMultiByte(OS_ENCODING_CODE_PAGE, OS_ENCODING_WC_FLAGS, path, -1, cmdline, length, NULL, NULL); return cmdline; }
/** * Frees data of all elements and the array itself. * @param portLibrary - The port library used to interact with the platform. * @param properties - The array instance no longer in use. */ void properties_free(HyPortLibrary * portLibrary, key_value_pair * properties) { PORT_ACCESS_FROM_PORT (portLibrary); if (properties) { unsigned i = 0; while (properties[i].key) { hymem_free_memory(properties[i].key); if (properties[i].value) hymem_free_memory(properties[i].value); ++i; } hymem_free_memory(properties); } }
static int handleNeutrinoJxeSpaceArg(J9PortLibrary * portLib, int jxeSpaceArg, char **argv) { PORT_ACCESS_FROM_PORT(portLib); char *tmpargv = &argv[jxeSpaceArg][10]; char *partitionStr = NULL; char *virtStr = NULL; int correctParms = 0; U_32 physicalAddr = 0; U_32 jxeSpaceSize = 0; void *logicalAddr = NULL; void *mappedAddr = NULL; /* parse out the jxespace options, all parameters are expected to be hex */ physicalAddr = parseStringToLong(tmpargv); partitionStr = strchr(tmpargv, ','); if (partitionStr) { jxeSpaceSize = parseStringToLong(partitionStr + 1); correctParms = 1; virtStr = strchr(partitionStr + 1, ','); if (virtStr) { logicalAddr = (void *) parseStringToLong(virtStr + 1); } } /* Don't continue if parsing failed or requested size is 0 */ if (!correctParms || !jxeSpaceSize) { j9nls_printf(PORTLIB, J9NLS_ERROR, J9NLS_EXE_INVALID_JXESPACE ); /* \nInvalid jxespace parameters.\n */ return 8; } /* Get the logical mapped addr. */ mappedAddr = mmap_device_memory(logicalAddr, jxeSpaceSize, PROT_READ | PROT_NOCACHE, 0, physicalAddr); if (mappedAddr == MAP_FAILED) { j9nls_printf( PORTLIB, J9NLS_ERROR, J9NLS_EXE_ERROR_MAPPING_JXE_IN_FLASH ); /* \nError mapping jxe in flash\n */ return 7; } return 0; }
static int prop_alloc(HyPortLibrary * portLibrary, key_value_pair* property, char* start, char* delim, char* end) { PORT_ACCESS_FROM_PORT (portLibrary); /* missing delimiter means the whole line is the key and value is empty */ size_t keyLength = (delim ? delim : end) - start; size_t valueLength = delim ? end - delim - 1 : 0; property->key = hymem_allocate_memory ((UDATA)(keyLength + 1)); property->value = hymem_allocate_memory ((UDATA)(valueLength + 1)); if (!property->key || !property->value) { return 0; } memcpy (property->key, start, keyLength); property->key[keyLength] = '\0'; if (delim) { memcpy (property->value, delim + 1, valueLength); } property->value[valueLength] = '\0'; return 1; }
static void dumpHelpText( J9PortLibrary *portLib, int argc, char **argv, int *copyrightWritten) { PORT_ACCESS_FROM_PORT(portLib); if( *copyrightWritten == 0 ) { dumpCopyrights(portLib); *copyrightWritten = 1; } #ifdef J9VM_OPT_DYNAMIC_LOAD_SUPPORT j9file_printf(PORTLIB, J9PORT_TTY_OUT, portLib->nls_lookup_message( PORTLIB, J9NLS_DO_NOT_PRINT_MESSAGE_TAG, J9NLS_EXE_HELPTEXT_1, "Usage:\t%s [options] classname [args...]\n" ), argv[0] ); #endif #ifdef J9VM_OPT_JXE_LOAD_SUPPORT j9file_printf(PORTLIB, J9PORT_TTY_OUT, portLib->nls_lookup_message( PORTLIB, J9NLS_DO_NOT_PRINT_MESSAGE_TAG, J9NLS_EXE_HELPTEXT_2, "Usage:\t%s [options] -jxe:<jxeFile> [args...]\n" ), argv[0] ); j9file_printf(PORTLIB, J9PORT_TTY_OUT, portLib->nls_lookup_message( PORTLIB, J9NLS_DO_NOT_PRINT_MESSAGE_TAG, J9NLS_EXE_HELPTEXT_2_1, "Usage:\t%s [-jxe] [options] <jxeFile> [args...]\n" ), argv[0] ); #endif j9file_printf(PORTLIB, J9PORT_TTY_OUT, portLib->nls_lookup_message( PORTLIB, J9NLS_DO_NOT_PRINT_MESSAGE_TAG, J9NLS_EXE_HELPTEXT_3, "\n[options]\n" " -classpath <path>\n" " -cp <path> set classpath to <path>.\n" ) ); #ifdef J9VM_OPT_JXE_LOAD_SUPPORT j9file_printf(PORTLIB, J9PORT_TTY_OUT, portLib->nls_lookup_message( PORTLIB, J9NLS_DO_NOT_PRINT_MESSAGE_TAG, J9NLS_EXE_HELPTEXT_4, " -jxe:<jxeFile> run the named jxe file.\n" ) ); j9file_printf(PORTLIB, J9PORT_TTY_OUT, portLib->nls_lookup_message( PORTLIB, J9NLS_DO_NOT_PRINT_MESSAGE_TAG, J9NLS_EXE_HELPTEXT_4_1, " -jxe <jxeFile> places jxeFile on the classpath and executes the startup\n" " class found in jxeFile.\n" ) ); #ifdef NEUTRINO j9file_printf(PORTLIB, J9PORT_TTY_OUT, portLib->nls_lookup_message( PORTLIB, J9NLS_DO_NOT_PRINT_MESSAGE_TAG, J9NLS_EXE_HELPTEXT_5, " -jxespace:<physicalAddr>,<size>,<logicalAddr>\n" " map memory region for jxes, (values are in hex).\n" " -jxeaddr:<logicalAddr>\n" " run a jxe directly from memory, (address is in hex).\n" ) ); #endif /* NEUTRINO */ #endif /* J9VM_OPT_JXE_LOAD_SUPPORT */ j9file_printf(PORTLIB, J9PORT_TTY_OUT, portLib->nls_lookup_message( PORTLIB, J9NLS_DO_NOT_PRINT_MESSAGE_TAG, J9NLS_EXE_HELPTEXT_6, " -D<prop>=<val> set the value of a system property.\n" ) ); /* PGG */ #if defined(J9VM_INTERP_DEBUG_SUPPORT) j9file_printf(PORTLIB, J9PORT_TTY_OUT, portLib->nls_lookup_message( PORTLIB, J9NLS_DO_NOT_PRINT_MESSAGE_TAG, J9NLS_EXE_HELPTEXT_7, " -debug:<options> enable debug, JDWP standard <options>.\n" ) ); #endif #if !defined(J9VM_OPT_LINKED_CLASSES_ZIP) j9file_printf(PORTLIB, J9PORT_TTY_OUT, portLib->nls_lookup_message( PORTLIB, J9NLS_DO_NOT_PRINT_MESSAGE_TAG, J9NLS_EXE_HELPTEXT_8, " -jcl:<config>[:options]\n" " specify which JCL DLL to use (e.g. cdc, cldc, ...).\n" ) ); #endif #if defined(J9VM_INTERP_VERBOSE) j9file_printf(PORTLIB, J9PORT_TTY_OUT, portLib->nls_lookup_message( PORTLIB, J9NLS_DO_NOT_PRINT_MESSAGE_TAG, J9NLS_EXE_HELPTEXT_9, " -verbose[:class,gc,stack,sizes]\n" " enable verbose output (default=class).\n" ) ); #endif j9file_printf(PORTLIB, J9PORT_TTY_OUT, portLib->nls_lookup_message( PORTLIB, J9NLS_DO_NOT_PRINT_MESSAGE_TAG, J9NLS_EXE_HELPTEXT_10, " -verify enable class file verification.\n" " -X print help on non-standard options.\n" ) ); return; }
/* This function converts a unicode string into a char array */ void freeUnicodeToASCII(J9PortLibrary *portLibrary, LPSTR path) { PORT_ACCESS_FROM_PORT(portLibrary); j9mem_free_memory(path); }
/** * Read the properties file specified by <tt>filename</tt> * into the array of <tt>properties</tt>, * using the specified port library to allocate memory. * The array is terminated with null-keyed element, * though one can obtain number of elements directly * via last argument. * * @param[in] portLibrary - The port library used to interact with the platform. * @param[in] filename - The file from which to read data using hyfile* functions. * @param[out] properties - An array that will contain property file entries. * @param[out] number - Optional parameter, number of elements in the returned array. * * @return JNI_OK on success, or a JNI error code on failure. */ jint properties_load(HyPortLibrary * portLibrary, const char *filename, key_value_pair** properties, U_32 *number) { PORT_ACCESS_FROM_PORT (portLibrary); void *handle; I_64 seekResult; IDATA fileSize; char *scanCursor, *scanLimit; char *start, *delim, *end; key_value_pair *props; unsigned arraySize; unsigned count = 0; jint status = JNI_OK; /* Determine the file size, fail if > 2G */ seekResult = hyfile_length (filename); if ((seekResult <= 0) || (seekResult > 0x7FFFFFFF)) { return JNI_ERR; } scanCursor = hymmap_map_file(filename, &handle); if (!scanCursor) { return JNI_ERR; } #ifdef ZOS /* Convert the scan buffer into ASCII */ scanCursor = e2a(scanCursor, seekResult); #endif fileSize = (IDATA) seekResult; arraySize = fileSize/50 + 1; props = hymem_allocate_memory(sizeof(key_value_pair)*(arraySize + 1)); if (!props) { status = JNI_ENOMEM; goto finish; } start = end = scanCursor; delim = NULL; scanLimit = scanCursor + fileSize; do { while (scanCursor < scanLimit) { switch(*scanCursor) { case '\r': case '\n': end = scanCursor; goto read_line; case '=': /* remember only first occurrence which is not key itself */ if (delim == NULL && scanCursor > start) { delim = scanCursor; } default: ++scanCursor; continue; } } read_line: if (scanCursor > start && start != delim && *start != '#' && *start != '!') /* line is not empty, well formed and not commented out */ { if (end == start) { /* the last line ends with EOF */ end = scanLimit; } if (count == arraySize) { void* re_props; arraySize += arraySize/2 + 1; re_props = hymem_reallocate_memory(props, sizeof(key_value_pair)*(arraySize + 1)); if (!re_props) { status = JNI_ENOMEM; goto finish; } props = re_props; } if (!prop_alloc(portLibrary, props + count, start, delim, end)) { status = JNI_ENOMEM; goto finish; } ++count; } start = end = ++scanCursor; delim = NULL; } while (scanCursor < scanLimit); /*set terminating NULL*/ props[count].key = NULL; finish: hymmap_unmap_file(handle); if (status != JNI_OK) { properties_free(portLibrary, props); } else { *properties = props; if (number){ *number = count; } } return status; }
/** * @internal * Set set locale. * * @param[in] portLibrary The port library */ void nls_determine_locale (struct HyPortLibrary *portLibrary) { HyNLSDataCache *nls = &portLibrary->portGlobals->nls_data; char languageProp[4] = "en\0"; char countryProp[3] = "US"; char *lang = NULL; int langlen = 0; #if defined(LINUX) IDATA result; char langProp[24]; #endif IDATA countryStart = 2; PORT_ACCESS_FROM_PORT (portLibrary); /* Get the language */ /* Set locale, returns NULL in case locale data cannot be initialized. This may indicate * that the locale is not installed OR not selected & generated (see /etc/locale.gen) */ setlocale (LC_ALL, ""); #if defined(LINUX) lang = setlocale (LC_CTYPE, NULL); /* set lang for later usage, we cannot use the return of setlocale(LC_ALL, "") as its not * the correct interface to retrieve it (lang/region) */ /* Use LANG environment variable when locale cannot be obtained */ if (!lang || !strcmp (lang, "C") || !strcmp (lang, "POSIX")) { result = hysysinfo_get_env (portLibrary, "LANG", langProp, sizeof (langProp)); if (!result && !strcmp (langProp, "ja")) { strcat (langProp, "_JP"); lang = langProp; } } #else /* Query locale data */ lang = setlocale (LC_CTYPE, NULL); #endif /* LINUX */ if (lang != NULL && strcmp (lang, "POSIX") && strcmp (lang, "C")) if (lang != NULL && (langlen = strlen (lang)) >= 2) { /* copy the language, stopping at '_' */ languageProp[0] = lang[0]; languageProp[1] = lang[1]; if (lang[2] != '_') { languageProp[2] = lang[2]; countryStart++; } } if (!strcmp (languageProp, "jp")) languageProp[1] = 'a'; strncpy (nls->language, languageProp, 3); /* Get the region */ if (langlen >= (3 + countryStart) && lang[countryStart] == '_') { countryProp[0] = lang[countryStart + 1]; countryProp[1] = lang[countryStart + 2]; } strncpy (nls->region, countryProp, 2); }