Return-Path: Delivered-To: apmail-incubator-harmony-commits-archive@www.apache.org Received: (qmail 55788 invoked from network); 1 Dec 2005 06:22:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 1 Dec 2005 06:22:09 -0000 Received: (qmail 16492 invoked by uid 500); 1 Dec 2005 06:19:36 -0000 Delivered-To: apmail-incubator-harmony-commits-archive@incubator.apache.org Received: (qmail 16174 invoked by uid 500); 1 Dec 2005 06:19:33 -0000 Mailing-List: contact harmony-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: harmony-dev@incubator.apache.org Delivered-To: mailing list harmony-commits@incubator.apache.org Received: (qmail 14771 invoked by uid 99); 1 Dec 2005 06:19:20 -0000 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 30 Nov 2005 22:18:54 -0800 Received: (qmail 44238 invoked by uid 65534); 1 Dec 2005 06:11:51 -0000 Message-ID: <20051201061151.44237.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r350181 [187/198] - in /incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core: ./ depends/ depends/files/ depends/jars/ depends/libs/ depends/libs/linux.IA32/ depends/libs/win.IA32/ depends/oss/ depends/oss/linux.IA32/ depends/oss/win.... Date: Thu, 01 Dec 2005 06:04:00 -0000 To: harmony-commits@incubator.apache.org From: geirm@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hynls.c URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hynls.c?rev=350181&view=auto ============================================================================== --- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hynls.c (added) +++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hynls.c Wed Nov 30 21:29:27 2005 @@ -0,0 +1,1180 @@ +/* Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * @ingroup Port + * @brief Native language support + */ +#define CDEV_CURRENT_FUNCTION include_header + +#undef CDEV_CURRENT_FUNCTION + +#include "hycomp.h" +#include "hyport.h" +#include "portpriv.h" +#include "hythread.h" +#include "hynlshelpers.h" +#include "portnls.h" + +#include +#include + +#define CDEV_CURRENT_FUNCTION _prototypes_private +static const char *nlsh_lookup (struct HyPortLibrary *portLibrary, + U_32 module_name, U_32 message_num); +static char *build_catalog_name (struct HyPortLibrary *portLibrary, + I_32 usePath, I_32 useDepth); +static void free_catalog (struct HyPortLibrary *portLibrary); +char *read_from_catalog (struct HyPortLibrary *portLibrary, IDATA fd, + char *buf, IDATA bufsize); +static HyNLSHashEntry *nls_allocateHashEntry (struct HyPortLibrary + *portLibrary, U_32 module_name, + U_32 message_num, + const char *message, + U_32 sizeOfMessage); +static const char *parse_catalog (struct HyPortLibrary *portLibrary, + UDATA flags, U_32 module_name, + U_32 message_num, + const char *default_string); +static void nlsh_insert (struct HyPortLibrary *portLibrary, + HyNLSHashEntry * entry); +static void open_catalog (struct HyPortLibrary *portLibrary); +void convertModuleName (U_32 module_name, U_8 * module_str); +static U_32 nlsh_hash (U_32 module_name, U_32 message_num); +#undef CDEV_CURRENT_FUNCTION + +/* a sample key */ +#define HYNLS_EXEMPLAR "XXXX000" + +#define BUF_SIZE 1024 + +#define CDEV_CURRENT_FUNCTION hynls_set_locale +/** + * Set the language, region, and variant of the locale. + * + * @param[in] portLibrary The port library + * @param[in] lang - the language of the locale (e.g., "en"), 2 characters or less + * @param[in] region - the region of the locale (e.g., "US"), 2 characters or less + * @param[in] variant - the variant of the locale (e.g., "boont"), 31 characters or less + */ +void VMCALL +hynls_set_locale (struct HyPortLibrary *portLibrary, const char *lang, + const char *region, const char *variant) +{ + HyNLSDataCache *nls = &portLibrary->portGlobals->nls_data; +#if defined(NLS_DEBUG_TRACE) + portLibrary->tty_printf (portLibrary, "NLS - hynls_set_locale\n"); +#endif + + hythread_monitor_enter (nls->monitor); + + if (lang && strlen (lang) <= 2) + strcpy (nls->language, lang); + if (region && strlen (region) <= 2) + strcpy (nls->region, region); + if (variant && strlen (variant) <= 31) + strcpy (nls->variant, variant); + + hythread_monitor_exit (nls->monitor); +} + +#undef CDEV_CURRENT_FUNCTION + +#define CDEV_CURRENT_FUNCTION hynls_get_language +/** + * Return the string representing the currently set language. + * + * @param[in] portLibrary The port library + * + * @return language string + */ +const char *VMCALL +hynls_get_language (struct HyPortLibrary *portLibrary) +{ +#if defined(NLS_DEBUG_TRACE) + portLibrary->tty_printf (portLibrary, "NLS - hynls_get_language\n"); +#endif + + return portLibrary->portGlobals->nls_data.language; +} + +#undef CDEV_CURRENT_FUNCTION + +#define CDEV_CURRENT_FUNCTION hynls_get_region +/** + * Return the string representing the currently set region. + * + * @param[in] portLibrary The port library + * + * @return region string + */ +const char *VMCALL +hynls_get_region (struct HyPortLibrary *portLibrary) +{ +#if defined(NLS_DEBUG_TRACE) + portLibrary->tty_printf (portLibrary, "NLS - hynls_get_region\n"); +#endif + + return portLibrary->portGlobals->nls_data.region; +} + +#undef CDEV_CURRENT_FUNCTION + +#define CDEV_CURRENT_FUNCTION hynls_get_variant +/** + * Return the string representing the currently set variant. + * + * @param[in] portLibrary The port library + * + * @return variant string + */ +const char *VMCALL +hynls_get_variant (struct HyPortLibrary *portLibrary) +{ +#if defined(NLS_DEBUG_TRACE) + portLibrary->tty_printf (portLibrary, "NLS - hynls_get_variant\n"); +#endif + + return portLibrary->portGlobals->nls_data.variant; +} + +#undef CDEV_CURRENT_FUNCTION + +#define CDEV_CURRENT_FUNCTION hynls_printf +/** + * Print a formatted NLS message. + * + * @param[in] portLibrary The port library + * @param[in] flags - to indicate what type of message (e.g., ERROR) and whether + * a newline is required + * @param[in] module_name - the module identifier of the NLS message + * @param[in] message_num - the NLS message number within the module + * @param[in] ... - arguments used in the NLS message format + */ +void VMCALL +hynls_printf (struct HyPortLibrary *portLibrary, UDATA flags, + U_32 module_name, U_32 message_num, ...) +{ + va_list args; +#if defined(NLS_DEBUG_TRACE) + portLibrary->tty_printf (portLibrary, "NLS - hynls_printf\n"); +#endif + + va_start (args, message_num); + portLibrary->nls_vprintf (portLibrary, flags, module_name, message_num, + args); + va_end (args); +} + +#undef CDEV_CURRENT_FUNCTION + +#define CDEV_CURRENT_FUNCTION hynls_vprintf +/** + * Print a formatted NLS message. + * + * @param[in] portLibrary The port library + * @param[in] flags - to indicate what type of message (e.g., ERROR) and whether + * a newline is required + * @param[in] module_name - the module identifier of the NLS message + * @param[in] message_num - the NLS message number within the module + * @param[in] args - arguments used in the NLS message format + */ +void VMCALL +hynls_vprintf (struct HyPortLibrary *portLibrary, UDATA flags, + U_32 module_name, U_32 message_num, va_list args) +{ + const char *message; + +#if defined(NLS_DEBUG_TRACE) + portLibrary->tty_printf (portLibrary, "NLS - hynls_vprintf\n"); +#endif + + message = + portLibrary->nls_lookup_message (portLibrary, flags, module_name, + message_num, NULL); + +#if defined(NLS_DEBUG) + portLibrary->tty_printf (portLibrary, "NLS - vprintf - message: %s\n", + message); +#endif + + if (flags & HYNLS_STDOUT) + { + portLibrary->file_vprintf (portLibrary, HYPORT_TTY_OUT, message, args); + } + else + { + portLibrary->file_vprintf (portLibrary, HYPORT_TTY_ERR, message, args); + } +} + +#undef CDEV_CURRENT_FUNCTION + +#define CDEV_CURRENT_FUNCTION hynls_lookup_message +/** + * Return the NLS string for the module name and message number. If no string is found, + * or a failure occurs, return the default_string. + * + * @param[in] portLibrary The port library + * @param[in] flags - to indicate what type of message (e.g., ERROR) and whether + * a newline is required + * @param[in] module_name - the module identifier of the NLS message + * @param[in] message_num - the NLS message number within the module + * @param[in] default_string - a default message, in case no NLS message is found + * + * @return NLS String + */ +const char *VMCALL +hynls_lookup_message (struct HyPortLibrary *portLibrary, UDATA flags, + U_32 module_name, U_32 message_num, + const char *default_string) +{ + HyNLSDataCache *nls = &portLibrary->portGlobals->nls_data; + const char *message; +#if defined(NLS_DEBUG_TRACE) + portLibrary->tty_printf (portLibrary, "NLS - hynls_lookup_message\n"); +#endif + + hythread_monitor_enter (nls->monitor); + + if (!nls->catalog) + open_catalog (portLibrary); + + message = nlsh_lookup (portLibrary, module_name, message_num); + if (!message) + { + message = + parse_catalog (portLibrary, flags, module_name, message_num, + default_string); + if (!message) + message = + HYNLS_ERROR_MESSAGE (HYNLS_PORT_NLS_FAILURE, "NLS Failure\n"); + } + + hythread_monitor_exit (nls->monitor); + return message; +} + +#undef CDEV_CURRENT_FUNCTION + +#define CDEV_CURRENT_FUNCTION hynls_release_message + +#undef CDEV_CURRENT_FUNCTION + +#define CDEV_CURRENT_FUNCTION hynls_set_catalog +/** + * Setup the path to the NLS catalog. + * + * @param[in] portLibrary The port library + * @param[in] paths - an array of directory paths where the NLS catalog may be found + * @param[in] nPaths - the number of entries in the paths array + * @param[in] baseName - the lead name of the catalog file name (i.e., the "java" in java_en_US.properties) + * @param[in] extension - the extension of the catalog file name (i.e., the "properties in java_en_US.properties) + */ +void VMCALL +hynls_set_catalog (struct HyPortLibrary *portLibrary, const char **paths, + const int nPaths, const char *baseName, + const char *extension) +{ + int i; + char *p; + + HyNLSDataCache *nls = &portLibrary->portGlobals->nls_data; +#if defined(NLS_DEBUG_TRACE) + portLibrary->tty_printf (portLibrary, "NLS - hynls_set_catalog\n"); +#endif + + hythread_monitor_enter (nls->monitor); + + if (!baseName || !extension) + goto clean_exit; + for (i = 0; i < nPaths; i++) + { + if (nls->baseCatalogPaths[i]) + portLibrary->mem_free_memory (portLibrary, nls->baseCatalogPaths[i]); + nls->baseCatalogPaths[i] = NULL; + } + nls->nPaths = 0; + if (nls->baseCatalogName) + { + portLibrary->mem_free_memory (portLibrary, nls->baseCatalogName); + nls->baseCatalogName = NULL; + } + if (nls->baseCatalogExtension) + { + portLibrary->mem_free_memory (portLibrary, nls->baseCatalogExtension); + nls->baseCatalogExtension = NULL; + } + + for (i = 0; i < nPaths; i++) + { + nls->baseCatalogPaths[i] = + portLibrary->mem_allocate_memory (portLibrary, strlen (paths[i]) + 1); + if (nls->baseCatalogPaths[i]) + { + strcpy (nls->baseCatalogPaths[i], paths[i]); + p = strrchr (nls->baseCatalogPaths[i], DIR_SEPARATOR); + if (p) + p[1] = '\0'; + nls->nPaths++; + } + } + + nls->baseCatalogName = + portLibrary->mem_allocate_memory (portLibrary, strlen (baseName) + 1); + if (nls->baseCatalogName) + strcpy (nls->baseCatalogName, baseName); + + nls->baseCatalogExtension = + portLibrary->mem_allocate_memory (portLibrary, strlen (extension) + 1); + if (nls->baseCatalogExtension) + strcpy (nls->baseCatalogExtension, extension); + + if (nls->language[0] == 0 && nls->region[0] == 0 && nls->variant[0] == 0) + { + nls_determine_locale (portLibrary); + } + +clean_exit: + hythread_monitor_exit (nls->monitor); +} + +#undef CDEV_CURRENT_FUNCTION + +#define CDEV_CURRENT_FUNCTION build_catalog_name +static char * +build_catalog_name (struct HyPortLibrary *portLibrary, I_32 usePath, + I_32 useDepth) +{ + HyNLSDataCache *nls = &portLibrary->portGlobals->nls_data; + I_32 len = 1; + char *catalog = NULL; + char *defaultCatalog = NULL; + char *endPathPtr = NULL; + + hysysinfo_get_executable_name (portLibrary, NULL, &defaultCatalog); + endPathPtr = strrchr (defaultCatalog, DIR_SEPARATOR); + endPathPtr[1] = '\0'; + // defaultCatalog now holds the name of the launcher's home directory + +#if defined(NLS_DEBUG_TRACE) + portLibrary->tty_printf (portLibrary, "NLS - build_catalog_name\n"); +#endif + + if (!nls->nPaths) + { + portLibrary->nls_set_catalog (portLibrary, + (const char **) &defaultCatalog, 1, + "harmony", "properties"); + if (!nls->baseCatalogName) + goto _done; + if (nls->language[0] == 0 && nls->region[0] == 0 + && nls->variant[0] == 0) + { + nls_determine_locale (portLibrary); + } + } + + if (useDepth > 0) + { + if (nls->language[0] == 0) + goto _done; + if (useDepth > 1) + { + if (nls->region[0] == 0) + goto _done; + if (useDepth > 2) + { + if (nls->variant[0] == 0) + goto _done; + } + } + } + + len += strlen (nls->baseCatalogPaths[usePath]); + len += strlen (nls->baseCatalogName); + len += strlen (nls->baseCatalogExtension); + len += 1; /* the . before the extension */ + len += strlen (nls->language) + 1; /* '_en' */ + len += strlen (nls->region) + 1; + len += strlen (nls->variant) + 1; + len += 1; /* null terminator */ + + catalog = portLibrary->mem_allocate_memory (portLibrary, len); + if (!catalog) + goto _done; + strcpy (catalog, nls->baseCatalogPaths[usePath]); + strcat (catalog, nls->baseCatalogName); + if (useDepth > 0) + { + strcat (catalog, "_"); + strcat (catalog, nls->language); + if (useDepth > 1) + { + strcat (catalog, "_"); + strcat (catalog, nls->region); + if (useDepth > 2) + { + strcat (catalog, "_"); + strcat (catalog, nls->variant); + } + } + } + strcat (catalog, "."); + strcat (catalog, nls->baseCatalogExtension); + +_done: + // Free memory for defaultCatalog -- necessary ?? + if (defaultCatalog) + { + portLibrary->mem_free_memory (portLibrary, defaultCatalog); + } + return catalog; +} + +#undef CDEV_CURRENT_FUNCTION + +#define CDEV_CURRENT_FUNCTION open_catalog +static void +open_catalog (struct HyPortLibrary *portLibrary) +{ + HyNLSDataCache *nls = &portLibrary->portGlobals->nls_data; + char *catalog = NULL; + I_32 fd = -1, d, p; + +#if defined(NLS_DEBUG_TRACE) + portLibrary->tty_printf (portLibrary, "NLS - open_catalog\n"); + portLibrary->tty_printf (portLibrary, "nPaths = %d\n", (I_32) nls->nPaths); +#endif + + /* try the following way to look for the catalog: + * The base name will typically be "/harmony.properties". Append as many + * locale descriptors to the file name as possible to find a file. + * e.g. + * harmony_en_GB.properties + * harmony_en.properties + * harmony.properties + */ + for (p = 0; p < (I_32) nls->nPaths; p++) + { + for (d = 3; d >= 0; d--) + { + if (catalog) + portLibrary->mem_free_memory (portLibrary, catalog); + catalog = build_catalog_name (portLibrary, p, d); + if (!catalog) + continue; +#if defined(NLS_DEBUG) + portLibrary->tty_printf (portLibrary, + "NLS - attempting to open: %s\n", catalog); +#endif + + fd = portLibrary->file_open (portLibrary, catalog, HyOpenRead, 0); + if (fd != -1) + break; + } + if (fd != -1) + break; + } + + if (fd == -1) + { +#if defined(NLS_DEBUG) + portLibrary->tty_printf (portLibrary, + "NLS - failed to open the nls catalog\n"); +#endif + return; + } + + portLibrary->portGlobals->nls_data.catalog = catalog; + + portLibrary->file_close (portLibrary, fd); + +#if defined(NLS_DEBUG) + portLibrary->tty_printf (portLibrary, "NLS - succesfully opened %s\n", + catalog); +#endif + + free_catalog (portLibrary); +} + +#undef CDEV_CURRENT_FUNCTION + +#define CDEV_CURRENT_FUNCTION parse_catalog +static const char * +parse_catalog (struct HyPortLibrary *portLibrary, UDATA flags, + U_32 module_name, U_32 message_num, const char *default_string) +{ +#define MSG_NONE 0 +#define MSG_SLASH 1 +#define MSG_UNICODE 2 +#define MSG_CONTINUE 3 +#define MSG_DONE 4 +#define MSG_IGNORE 5 + + U_8 dataBuf[BUF_SIZE]; + U_8 *charPointer = NULL; + U_8 *endPointer = NULL; + int mode = MSG_NONE, count, digit; + U_32 unicode = 0; + char nextChar; + U_32 offset = 0, bufSize = BUF_SIZE, maxOffset = 0; + I_32 keyLength = -1; + char *buf, *newBuf; + BOOLEAN firstChar = TRUE; + IDATA fd = -1; + HyNLSDataCache *nls = &portLibrary->portGlobals->nls_data; + HyNLSHashEntry *entry = NULL; + char *message = NULL; + char convertedModuleEnum[5]; + /* calculate a size which is larger than we could possibly need by putting together all of the prefixes and suffixes */ + char + prefix[sizeof + (HYNLS_ERROR_PREFIX "" HYNLS_INFO_PREFIX "" HYNLS_WARNING_PREFIX "" + HYNLS_COMMON_PREFIX "" HYNLS_EXEMPLAR "" HYNLS_ERROR_SUFFIX "" + HYNLS_INFO_SUFFIX "" HYNLS_WARNING_SUFFIX " \n")]; + char *searchKey; + BOOLEAN newline = !(flags & HYNLS_DO_NOT_APPEND_NEWLINE); + const char *format; + +#if defined(NLS_DEBUG_TRACE) + portLibrary->tty_printf (portLibrary, "NLS - parse_catalog\n"); +#endif + + convertModuleName (module_name, (U_8 *) convertedModuleEnum); + + format = "" HYNLS_COMMON_PREFIX "%s%03u %s"; + + if (0 == (flags & HYNLS_DO_NOT_PRINT_MESSAGE_TAG)) + { + if (flags & HYNLS_ERROR) + { + format = + "" HYNLS_ERROR_PREFIX "" HYNLS_COMMON_PREFIX "%s%03u" + HYNLS_ERROR_SUFFIX " %s"; + } + else if (flags & HYNLS_WARNING) + { + format = + "" HYNLS_WARNING_PREFIX "" HYNLS_COMMON_PREFIX "%s%03u" + HYNLS_WARNING_SUFFIX " %s"; + } + else if (flags & HYNLS_INFO) + { + format = + "" HYNLS_INFO_PREFIX "" HYNLS_COMMON_PREFIX "%s%03u" + HYNLS_INFO_SUFFIX " %s"; + } + } + portLibrary->str_printf (portLibrary, prefix, sizeof (prefix), format, + convertedModuleEnum, message_num, + newline ? "\n" : ""); + + /* make sure the searchKey string starts at HYVM001 instead of (E)HYVM001 */ + searchKey = prefix + (strchr (format, '%') - format); + +#if defined(NLS_DEBUG) + portLibrary->tty_printf (portLibrary, + "NLS - parse_catalog - searchKey: %s\n", + searchKey); +#endif + + /* we do a lazy caching, populate the cache as we look up messages */ + + if (nls->catalog) + { + fd = + portLibrary->file_open (portLibrary, (char *) nls->catalog, + HyOpenRead, 0); + } + if (fd == -1) + { + /* couldn't open the file, store the searchKey instead */ + char *tmpStr = prefix; + if (default_string) + { + tmpStr = (char *) default_string; + } + entry = + nls_allocateHashEntry (portLibrary, module_name, message_num, tmpStr, + strlen (tmpStr)); + if (!entry) + { + return default_string; + } + nlsh_insert (portLibrary, entry); + return entry->message; + } + + if (!(buf = portLibrary->mem_allocate_memory (portLibrary, bufSize))) + { + goto finished; + } + + while (read_from_catalog (portLibrary, fd, (char *) dataBuf, BUF_SIZE) != + NULL) + { + charPointer = dataBuf; + endPointer = charPointer + strlen ((char *) dataBuf); + + while (charPointer < endPointer) + { + nextChar = *charPointer++; + + if (offset + 2 >= bufSize) + { + bufSize <<= 1; + if (! + (newBuf = + portLibrary->mem_allocate_memory (portLibrary, bufSize))) + goto finished; + memcpy (newBuf, buf, offset); + portLibrary->mem_free_memory (portLibrary, buf); + buf = newBuf; + } + + if (mode == MSG_UNICODE) + { + if (nextChar >= '0' && nextChar <= '9') + digit = nextChar - '0'; + else if (nextChar >= 'a' && nextChar <= 'f') + digit = (nextChar - 'a') + 10; + else if (nextChar >= 'A' && nextChar <= 'F') + digit = (nextChar - 'A') + 10; + else + digit = -1; + if (digit >= 0) + { + unicode = (unicode << 4) + digit; + if (++count < 4) + continue; + } + mode = MSG_NONE; + if (unicode >= 0x01 && unicode <= 0x7f) + { + buf[offset++] = unicode; + } + else if (unicode == 0 || (unicode >= 0x80 && unicode <= 0x7ff)) + { + buf[offset++] = ((unicode >> 6) & 0x1f) | 0xc0; + buf[offset++] = (unicode & 0x3f) | 0x80; + } + else if (unicode >= 0x800 && unicode <= 0xffff) + { + buf[offset++] = ((unicode >> 12) & 0x0f) | 0xe0; + buf[offset++] = ((unicode >> 6) & 0x3f) | 0x80; + buf[offset++] = (unicode & 0x3f) | 0x80; + } + if (nextChar != '\n') + continue; + } + + if (mode == MSG_SLASH) + { + mode = MSG_NONE; + switch (nextChar) + { + case '\r': + mode = MSG_CONTINUE; /* Look for a following 'n */ + continue; + case '\n': + mode = MSG_IGNORE; /* Ignore whitespace on the next line */ + continue; + case 'b': + nextChar = '\b'; + break; + case 'f': + nextChar = '\f'; + break; + case 'n': + nextChar = '\n'; + break; + case 'r': + nextChar = '\r'; + break; + case 't': + nextChar = '\t'; + break; + case 'u': + mode = MSG_UNICODE; + unicode = count = 0; + continue; + } + } + else + { + switch (nextChar) + { + case '#': + case '!': + if (firstChar) + { + + while (1) + { + if (charPointer >= endPointer) + { + if (read_from_catalog + (portLibrary, fd, (char *) dataBuf, + BUF_SIZE) != NULL) + { + charPointer = dataBuf; + endPointer = + charPointer + strlen (charPointer); + } + } + if (charPointer >= endPointer) + break; + nextChar = *charPointer++; + if (nextChar == '\r' || nextChar == '\n') + break; + } + continue; + } + break; + case '\n': + if (mode == MSG_CONTINUE) + { /* Part of a \r\n sequence */ + mode = MSG_IGNORE; + continue; + } + /* fall into next case */ + case '\r': + mode = MSG_NONE; + firstChar = TRUE; + makeStrings: + if (keyLength >= 0) + { +#if defined(NLS_DEBUG) + portLibrary->tty_printf (portLibrary, + "NLS - parse_catalog - keyLength: %d -- buf: %20.20s\n", + keyLength, buf); +#endif + + if (strncmp + (searchKey, buf, sizeof (HYNLS_EXEMPLAR) - 1) == 0) + { +#if defined(NLS_DEBUG) + portLibrary->tty_printf (portLibrary, + "NLS - parse_catalog - key match\n"); +#endif + + /* we have the exact message */ + if (flags & HYNLS_DO_NOT_PRINT_MESSAGE_TAG) + { + entry = + nls_allocateHashEntry (portLibrary, + module_name, + message_num, + buf + keyLength, + offset - keyLength + + 1); + if (entry) + { + entry->message[offset - keyLength] = '\0'; + if (newline) + strcat (entry->message, "\n"); + } + } + else + { + entry = + nls_allocateHashEntry (portLibrary, + module_name, + message_num, prefix, + offset - keyLength + + strlen (prefix)); + if (entry) + { + /* null terminate and trim the \n if required */ + entry->message[strlen (prefix) - + (newline ? 1 : 0)] = '\0'; + strncat (entry->message, buf + keyLength, + offset - keyLength); + if (newline) + strcat (entry->message, "\n"); + } + } + goto finished; + } + keyLength = -1; + } + if (charPointer >= endPointer) + { + if (read_from_catalog + (portLibrary, fd, (char *) dataBuf, + BUF_SIZE) != NULL) + { + charPointer = dataBuf; + endPointer = charPointer + strlen (charPointer); + } + } + if (charPointer >= endPointer) + { + finished: + if (buf) + portLibrary->mem_free_memory (portLibrary, buf); +#if defined(NLS_DEBUG) + portLibrary->tty_printf (portLibrary, + "NLS - parse_catalog - inserting message\n"); +#endif + + if (!entry) + { + char *tmpStr = prefix; + if (default_string) + tmpStr = (char *) default_string; + entry = + nls_allocateHashEntry (portLibrary, module_name, + message_num, tmpStr, + strlen (tmpStr)); + if (!entry) + { + portLibrary->file_close (portLibrary, fd); + return default_string; + } + } + nlsh_insert (portLibrary, entry); + portLibrary->file_close (portLibrary, fd); + return entry->message; + } + if (offset > maxOffset) + maxOffset = offset; + offset = 0; + continue; + case '\\': + mode = MSG_SLASH; + continue; + case ':': + case '=': + if (keyLength == -1) + { /* if parsing the key */ + keyLength = offset; + continue; + } + break; + } + if ((nextChar >= 0x1c && nextChar <= ' ') + || (nextChar >= 9 && nextChar <= 0xd)) + { + if (mode == MSG_CONTINUE) + mode = MSG_IGNORE; + /* if key length == 0 or value length == 0 */ + if (offset == 0 || offset == (U_32) keyLength + || mode == MSG_IGNORE) + continue; + if (keyLength == -1) + { /* if parsing the key */ + mode = MSG_DONE; + continue; + } + } + if (mode == MSG_IGNORE || mode == MSG_CONTINUE) + mode = MSG_NONE; + } + firstChar = FALSE; + if (mode == MSG_DONE) + { + keyLength = offset; + mode = MSG_NONE; + } + buf[offset++] = nextChar; + } + } + goto makeStrings; + +#undef MSG_NONE +#undef MSG_SLASH +#undef MSG_UNICODE +#undef MSG_CONTINUE +#undef MSG_DONE +#undef MSG_IGNORE +} + +#undef CDEV_CURRENT_FUNCTION + +#define CDEV_CURRENT_FUNCTION free_catalog +static void +free_catalog (struct HyPortLibrary *portLibrary) +{ + HyNLSDataCache *nls = &portLibrary->portGlobals->nls_data; + HyNLSHashEntry *old_hashEntries = nls->old_hashEntries; + U_32 i; +#if defined(NLS_DEBUG_TRACE) + portLibrary->tty_printf (portLibrary, "NLS - free_catalog\n"); +#endif + + for (i = 0; i < HYNLS_NUM_HASH_BUCKETS; i++) + { + HyNLSHashEntry *entry = nls->hash_buckets[i]; + if (entry) + { + while (entry->next) + { + entry = entry->next; + } + entry->next = nls->old_hashEntries; + nls->old_hashEntries = nls->hash_buckets[i]; + nls->hash_buckets[i] = NULL; + } + } +} + +#undef CDEV_CURRENT_FUNCTION + +#define CDEV_CURRENT_FUNCTION nlsh_hash +static U_32 +nlsh_hash (U_32 module_name, U_32 message_num) +{ + return (module_name ^ message_num); +} + +#undef CDEV_CURRENT_FUNCTION + +#define CDEV_CURRENT_FUNCTION nlsh_lookup +static const char * +nlsh_lookup (struct HyPortLibrary *portLibrary, U_32 module_name, + U_32 message_num) +{ + HyNLSDataCache *nls = &portLibrary->portGlobals->nls_data; + U_32 hashKey = nlsh_hash (module_name, message_num); + U_32 index; + HyNLSHashEntry *entry; + +#if defined(NLS_DEBUG_TRACE) + portLibrary->tty_printf (portLibrary, "NLS - nlsh_lookup\n"); +#endif + + index = hashKey % HYNLS_NUM_HASH_BUCKETS; + entry = nls->hash_buckets[index]; + + while (entry) + { + if (entry->module_name == module_name + && entry->message_num == message_num) + { + return entry->message; + } + entry = entry->next; + } + + return NULL; +} + +#undef CDEV_CURRENT_FUNCTION + +#define CDEV_CURRENT_FUNCTION nlsh_insert +static void +nlsh_insert (struct HyPortLibrary *portLibrary, HyNLSHashEntry * entry) +{ + HyNLSDataCache *nls = &portLibrary->portGlobals->nls_data; + U_32 hashKey = nlsh_hash (entry->module_name, entry->message_num); + U_32 index; + +#if defined(NLS_DEBUG_TRACE) + portLibrary->tty_printf (portLibrary, "NLS - nlsh_insert\n"); +#endif + + index = hashKey % HYNLS_NUM_HASH_BUCKETS; + entry->next = nls->hash_buckets[index]; + nls->hash_buckets[index] = entry; +} + +#undef CDEV_CURRENT_FUNCTION + +#define CDEV_CURRENT_FUNCTION hynls_startup +/** + * PortLibrary startup. + * + * This function is called during startup of the portLibrary. Any resources that are required for + * the NLS library operations may be created here. All resources created here should be destroyed + * in @ref hynls_shutdown. + * + * @param[in] portLibrary The port library + * + * @return 0 on success, negative error code on failure. Error code values returned are + * \arg HYPORT_ERROR_STARTUP_NLS + */ +I_32 VMCALL +hynls_startup (struct HyPortLibrary *portLibrary) +{ + HyNLSDataCache *nls = &portLibrary->portGlobals->nls_data; + + if (0 != + hythread_monitor_init_with_name (&nls->monitor, 0, "NLS hash table")) + { + return (I_32) HYPORT_ERROR_STARTUP_NLS; + } + + nls_determine_locale (portLibrary); + + return (I_32) 0; +} + +#undef CDEV_CURRENT_FUNCTION + +#define CDEV_CURRENT_FUNCTION hynls_shutdown +/** + * PortLibrary shutdown. + * + * This function is called during shutdown of the portLibrary. Any resources that were created by + * @ref hynls_startup should be destroyed here. + * + * @param[in] portLibrary The port library + */ +void VMCALL +hynls_shutdown (struct HyPortLibrary *portLibrary) +{ + HyNLSDataCache *nls = &portLibrary->portGlobals->nls_data; + HyNLSHashEntry *entry; + U_32 i; + + for (i = 0; i < HYNLS_NUM_HASH_BUCKETS; i++) + { + entry = nls->hash_buckets[i]; + while (entry) + { + HyNLSHashEntry *next = entry->next; + portLibrary->mem_free_memory (portLibrary, entry); + entry = next; + } + } + + /* Free the baseCatalogPaths allocated in hynls_set_catalog */ + for (i = 0; i < nls->nPaths; i++) + { + if (nls->baseCatalogPaths[i]) + { + portLibrary->mem_free_memory (portLibrary, + nls->baseCatalogPaths[i]); + nls->baseCatalogPaths[i] = NULL; + } + } + + if (nls->baseCatalogExtension) + { + portLibrary->mem_free_memory (portLibrary, nls->baseCatalogExtension); + nls->baseCatalogExtension = NULL; + } + + /* catalog is never free'd without this flag */ + entry = nls->old_hashEntries; + while (entry) + { + HyNLSHashEntry *next = entry->next; + portLibrary->mem_free_memory (portLibrary, entry); + entry = next; + } + + if (nls->baseCatalogName) + portLibrary->mem_free_memory (portLibrary, nls->baseCatalogName); + if (nls->catalog) + portLibrary->mem_free_memory (portLibrary, nls->catalog); + + hythread_monitor_destroy (nls->monitor); +} + +#undef CDEV_CURRENT_FUNCTION + +#define CDEV_CURRENT_FUNCTION nls_allocateHashEntry +static HyNLSHashEntry * +nls_allocateHashEntry (struct HyPortLibrary *portLibrary, U_32 module_name, + U_32 message_num, const char *message, + U_32 sizeOfMessage) +{ + HyNLSHashEntry *entry = portLibrary->mem_allocate_memory (portLibrary, + sizeof + (HyNLSHashEntry) + + sizeOfMessage + + 1 - + sizeof (entry-> + message)); +#if defined(NLS_DEBUG_TRACE) + portLibrary->tty_printf (portLibrary, "NLS - nls_allocateHashEntry\n"); +#endif + + if (!entry) + return NULL; + entry->module_name = module_name; + entry->message_num = message_num; + entry->next = NULL; + memcpy (entry->message, message, sizeOfMessage); + entry->message[sizeOfMessage] = '\0'; +#if defined(NLS_DEBUG) + portLibrary->tty_printf (portLibrary, + "NLS - nls_allocateHashEntry - message: %s - sizeOfMessage: %d\n", + entry->message, sizeOfMessage); +#endif + + return entry; +} + +#undef CDEV_CURRENT_FUNCTION + +#define CDEV_CURRENT_FUNCTION convertModuleName +void +convertModuleName (U_32 module_name, U_8 * module_str) +{ + module_str[0] = (U_8) ((module_name >> 24) & 0xff); + module_str[1] = (U_8) ((module_name >> 16) & 0xff); + module_str[2] = (U_8) ((module_name >> 8) & 0xff); + module_str[3] = (U_8) ((module_name) & 0xff); + module_str[4] = 0; +} + +#undef CDEV_CURRENT_FUNCTION + +#define CDEV_CURRENT_FUNCTION read_from_catalog +char * +read_from_catalog (struct HyPortLibrary *portLibrary, IDATA fd, char *buf, + IDATA bufsize) +{ + char temp[BUF_SIZE]; + IDATA count, nbytes = bufsize; + char *cursor = buf; + + if (nbytes <= 0) + return 0; + + /* discount 1 for the trailing NUL */ + nbytes -= 1; + + while (nbytes) + { + count = BUF_SIZE > nbytes ? nbytes : BUF_SIZE; + count = portLibrary->file_read (portLibrary, fd, temp, count); + + if (count < 0) + { + + /* if we've made it through a successful read, return the buf. */ + if (nbytes + 1 != bufsize) + return buf; + return NULL; + } + + memcpy (cursor, temp, count); + cursor += count; + nbytes -= count; + + } + + *cursor = '\0'; + + return buf; +} + +#undef CDEV_CURRENT_FUNCTION Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hynlshelpers.c URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hynlshelpers.c?rev=350181&view=auto ============================================================================== --- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hynlshelpers.c (added) +++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hynlshelpers.c Wed Nov 30 21:29:27 2005 @@ -0,0 +1,239 @@ +/* Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define CDEV_CURRENT_FUNCTION _comment_ +/** + * @internal @file + * @ingroup Port + * @brief Native language support helpers + */ +#undef CDEV_CURRENT_FUNCTION + +#include +#include +#include +#include +#include + +#include "hyport.h" +#include "portpriv.h" + +#define CDEV_CURRENT_FUNCTION _prototypes_public +void nls_determine_locale (struct HyPortLibrary *portLibrary); +#undef CDEV_CURRENT_FUNCTION + +#define CDEV_CURRENT_FUNCTION _prototypes_private +/* none * +#undef CDEV_CURRENT_FUNCTION + +#define CDEV_CURRENT_FUNCTION tableMap + +/* tableMap */ + +static const char *const CountryMap[] = { + "LBR", "LR", + "MAC", "MO", + "LBY", "LY", + "BHS", "BS", + "SYC", "SC", + "NIU", "NU", + "AUT", "AT", + "ESH", "EH", + "PCN", "PN", + "UKR", "UA", + "GUY", "GY", + "CAF", "CF", + "GNQ", "GQ", + "EST", "EE", + "MDG", "MG", + "SWZ", "SZ", + "JAM", "JM", + "SUR", "SR", + "MNP", "MP", + "MYT", "YT", + "PNG", "PG", + "TUV", "TV", + "CHN", "CN", + "TKM", "TM", + "AGO", "AO", + "BDI", "BI", + "MDV", "MV", + "BGD", "BD", + "GUF", "GF", + "PYF", "PF", + "CYM", "KY", + "SGS", "GS", + "TUN", "TN", + "IRL", "IE", + "ISR", "IL", + "BLR", "BY", + "FSM", "FM", + "ARM", "AM", + "SEN", "SN", + "BRB", "BB", + "WLF", "WF", + "MOZ", "MZ", + "BEN", "BJ", + "PRK", "KP", + "IRQ", "IQ", + "BLZ", "BZ", + "COG", "CG", + "MLT", "MT", + "COK", "CK", + "TMP", "TP", + "BRN", "BN", + "COM", "KM", + "MEX", "MX", + "ATG", "AG", + "PRT", "PT", + "KOR", "KR", + "SLB", "SB", + "POL", "PL", + "ARE", "AE", + "URY", "UY", + "PLW", "PW", + "FRO", "FO", + "GIN", "GN", + "SLV", "SV", + "ATF", "TF", + "MTQ", "MQ", + "GRL", "GL", + "ATA", "AQ", + "ZAR", "ZR", + "BIH", "BA", + "AND", "AD", + "CPV", "CV", + "SPM", "PM", + "GNB", "GW", + "PRY", "PY", + "GRD", "GD", + "CHL", "CL", + "GLP", "GP", + "KAZ", "KZ", + "PAK", "PK", + "SWE", "SE", + "SVK", "SK", + "SVN", "SI", + "FLK", "FK", + "TUR", "TR", + "DNK", "DK", + "ABW", "AW", + "TCD", "TD" +}; + +#undef CDEV_CURRENT_FUNCTION + +#define CDEV_CURRENT_FUNCTION nls_determine_locale +/** + * @internal + * Set set locale. + * + * @param[in] portLibrary The port library + */ +void +nls_determine_locale (struct HyPortLibrary *portLibrary) +{ + OSVERSIONINFO versionInfo; + LCID threadLocale; + LCTYPE infoType; + int length, i; + char lang[8]; + char country[8]; + HyNLSDataCache *nls = &portLibrary->portGlobals->nls_data; + + PORT_ACCESS_FROM_PORT (portLibrary); + + versionInfo.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); + GetVersionEx (&versionInfo); + + /* Get the language */ + infoType = LOCALE_SABBREVLANGNAME; + if (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) + infoType = LOCALE_SISO639LANGNAME; + + threadLocale = GetThreadLocale (); + + length = GetLocaleInfo (threadLocale, infoType, &lang[0], sizeof (lang)); + if (length < 2) + { + strncpy (nls->language, "en", 2); + } + else + { + +#if defined(UNICODE) + /* convert double byte to single byte */ + for (i = 0; i < length; i++) + { + lang[i] = (char) ((short *) lang)[i]; + } +#endif + + if (infoType == LOCALE_SABBREVLANGNAME) + lang[2] = 0; + + _strlwr (lang); + + // Not required for NT, Win32 gets it wrong + if (!strcmp (lang, "jp")) + strncpy (nls->language, "ja", 2); + /* One platform gives ch instead of zh for Chinese */ + else if (!strcmp (lang, "ch")) + strncpy (nls->language, "zh", 2); + else + strncpy (nls->language, lang, 3); + } + + /* Get the region */ + infoType = LOCALE_SABBREVCTRYNAME; + if (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) + infoType = LOCALE_SISO3166CTRYNAME; + + length = + GetLocaleInfo (threadLocale, infoType, &country[0], sizeof (country)); + if (length < 2) + { + strncpy (nls->region, "US", 2); + } + else + { +#if defined(UNICODE) + // convert double byte to single byte + for (i = 0; i < length; i++) + { + country[i] = (char) ((short *) country)[i]; + } + country[3] = 0; +#endif + + if (versionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT) + { + // If not NT, lookup in the table to find the code + for (i = 0; i < sizeof (CountryMap) >> 2; i += 2) + { + if (strcmp (country, CountryMap[i]) == 0) + { + strcpy (&country[0], CountryMap[i + 1]); + break; + } + } + } + /* Countries which are not in the table use the first two letters. */ + country[2] = 0; + strncpy (nls->region, country, 2); + } +} + +#undef CDEV_CURRENT_FUNCTION Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hynlshelpers.h URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hynlshelpers.h?rev=350181&view=auto ============================================================================== --- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hynlshelpers.h (added) +++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hynlshelpers.h Wed Nov 30 21:29:27 2005 @@ -0,0 +1,21 @@ +/* Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#if !defined(hynlshelpers_h) +#define hynlshelpers_h + +void nls_determine_locale (struct HyPortLibrary *portLibrary); + +#endif /* hynlshelpers_h */ Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyosdump.c URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyosdump.c?rev=350181&view=auto ============================================================================== --- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyosdump.c (added) +++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyosdump.c Wed Nov 30 21:29:27 2005 @@ -0,0 +1,408 @@ +/* Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define CDEV_CURRENT_FUNCTION _comment_ +/** + * @file + * @ingroup Port + * @brief Dump formatting + */ +#undef CDEV_CURRENT_FUNCTION + +#include +#include +#include +#include + +#include +#include + +#include "hyport.h" +#include "hysignal.h" + +typedef BOOL (WINAPI * PMINIDUMPWRITEDUMP) (IN HANDLE hProcess, + IN DWORD ProcessId, + IN HANDLE hFile, + IN MINIDUMP_TYPE DumpType, + IN CONST + PMINIDUMP_EXCEPTION_INFORMATION + ExceptionParam, + OPTIONAL IN CONST + PMINIDUMP_USER_STREAM_INFORMATION + UserStreamParam, + OPTIONAL IN CONST + PMINIDUMP_CALLBACK_INFORMATION + CallbackParam OPTIONAL); + +PMINIDUMPWRITEDUMP dump_fn; + +#define MINIDUMPWRITEDUMP "MiniDumpWriteDump" +#define DBGHELP_DLL "DBGHELP.DLL" + +typedef struct _WriteDumpFileArgs +{ + PMINIDUMPWRITEDUMP dmp_function; + HANDLE hDumpFile; + MINIDUMP_EXCEPTION_INFORMATION *mdei; +} WriteDumpFileArgs, *PWriteDumpFileArgs; + +#define HYUSE_UNIQUE_DUMP_NAMES "HYUNIQUE_DUMPS" +#define DUMP_FNAME_KEY "SOFTWARE\\Microsoft\\DrWatson" +#define DUMP_FNAME_VALUE "CrashDumpFile" + +#define CDEV_CURRENT_FUNCTION _prototypes_private + +static HANDLE openFileInCWD (struct HyPortLibrary *portLibrary, + char *fileNameBuff, U_32 fileNameBuffSize); + +static HANDLE openFileFromEnvVar (struct HyPortLibrary *portLibrary, + char *envVarName, char *fileNameBuff, + U_32 fileNameBuffSize); + +static HANDLE openFileFromReg (const char *keyName, const char *valName, + char *fileNameBuff, U_32 fileNameBuffSize); + +static void writeDumpFile (PWriteDumpFileArgs args); + +static HINSTANCE loadDumpLib (const char *dllName); + +static PMINIDUMPWRITEDUMP linkDumpFn (HINSTANCE dllHandle, + const char *fnName); + +#undef CDEV_CURRENT_FUNCTION + +#define CDEV_CURRENT_FUNCTION hydump_create +/** + * Create a dump file of the OS state. + * + * @param[in] portLibrary The port library. + * @param[in] filename Buffer for filename optionally containing the filename where dump is to be output. + * @param[out] filename filename used for dump file or error message. + * @param[in] dumpType Type of dump to perform. + * @param[in] userData Implementation specific data. + * + * @return 0 on success, non-zero otherwise. + * + * @note filename buffer can not be NULL. + * @note user allocates and frees filename buffer. + * @note filename buffer length is platform dependent, assumed to be HyMaxPath/MAX_PATH + * + * @note if filename buffer is empty, a filename will be generated. + * @note if HYUNIQUE_DUMPS is set, filename will be unique. + */ +UDATA VMCALL +hydump_create (struct HyPortLibrary *portLibrary, char *filename, + char *dumpType, void *userData) +{ + HANDLE hFile; + WriteDumpFileArgs args; + HINSTANCE dllHandle; + HANDLE hThread; + MINIDUMP_EXCEPTION_INFORMATION mdei; + EXCEPTION_POINTERS exceptionPointers; + HyWin32SignalInfo *info = (HyWin32SignalInfo *) userData; + + if (filename == NULL) + { + return 1; + } + + if (*filename == '\0') + { + /* no file name provided, so generate one and open the file */ + + hFile = + openFileFromReg (DUMP_FNAME_KEY, DUMP_FNAME_VALUE, filename, + HyMaxPath); + if (hFile == INVALID_HANDLE_VALUE) + { + hFile = + openFileFromEnvVar (portLibrary, "USERPROFILE", filename, + HyMaxPath); + if (hFile == INVALID_HANDLE_VALUE) + { + hFile = openFileInCWD (portLibrary, filename, HyMaxPath); + if (hFile == INVALID_HANDLE_VALUE) + { + hFile = + openFileFromEnvVar (portLibrary, "TEMP", filename, + HyMaxPath); + if (hFile == INVALID_HANDLE_VALUE) + { + hFile = + openFileFromEnvVar (portLibrary, "TMP", filename, + HyMaxPath); + } + } + } + } + } + else + { + /* use name provided */ + /* 0666 is a guess...0?, 0666??...want to grant write permissions */ + hFile = + (HANDLE) portLibrary->file_open (portLibrary, filename, + HyOpenWrite | HyOpenCreate | + HyOpenRead, 0666); + } + + if (hFile == (HANDLE) - 1) + { + /*make sure useful */ + portLibrary->str_printf (portLibrary, filename, HyMaxPath, + "Dump failed - could not create dump file:\n"); + return 1; + } + + /* Try to load JRE minidump module before the system one */ + dllHandle = loadDumpLib ("..\\bin\\" DBGHELP_DLL); + + dllHandle = loadDumpLib (DBGHELP_DLL); + + dump_fn = linkDumpFn (dllHandle, MINIDUMPWRITEDUMP); + + if (dump_fn == NULL) + { + portLibrary->str_printf (portLibrary, filename, HyMaxPath, + "Dump failed - could not link %s in %s\n", + MINIDUMPWRITEDUMP, DBGHELP_DLL); + return 1; + } + + /* collect exception data */ + if (info) + { + exceptionPointers.ExceptionRecord = info->ExceptionRecord; + exceptionPointers.ContextRecord = info->ContextRecord; + mdei.ThreadId = GetCurrentThreadId (); + mdei.ExceptionPointers = &exceptionPointers; + mdei.ClientPointers = TRUE; + } + + args.dmp_function = dump_fn; + args.hDumpFile = hFile; + args.mdei = info ? &mdei : NULL; + + /* call createCrashDumpFile on a different thread so we can walk the stack back to our code */ + hThread = (HANDLE) _beginthread (writeDumpFile, 0, &args); + + /* exception thread waits while crash dump is printed on other thread */ + if ((HANDLE) - 1 == hThread) + { + portLibrary->str_printf (portLibrary, filename, HyMaxPath, + "Dump failed - could not begin dump thread\n"); + return 1; + } + else + { + WaitForSingleObject (hThread, INFINITE); + } + + if ((portLibrary->file_close (portLibrary, (I_32) hFile)) == -1) + { + /*make sure useful */ + portLibrary->str_printf (portLibrary, filename, HyMaxPath, + "Dump failed - could not close dump file.\n"); + return 1; + } + return 0; +} + +#undef CDEV_CURRENT_FUNCTION + +#define CDEV_CURRENT_FUNCTION linkDumpFn +static PMINIDUMPWRITEDUMP +linkDumpFn (HINSTANCE dllHandle, const char *fnName) +{ + return (PMINIDUMPWRITEDUMP) GetProcAddress (dllHandle, fnName); +} + +#undef CDEV_CURRENT_FUNCTION + +#define CDEV_CURRENT_FUNCTION loadDumpLib +/* will remove private from name once duplicate functionality removed from GPHandler */ +static HINSTANCE +loadDumpLib (const char *dllName) +{ + HINSTANCE dbghelpDll = GetModuleHandle (dllName); + + if (dbghelpDll == NULL) + { + dbghelpDll = LoadLibrary (dllName); + } + + return dbghelpDll; +} + +#undef CDEV_CURRENT_FUNCTION + +#define CDEV_CURRENT_FUNCTION writeDumpFile +static void +writeDumpFile (PWriteDumpFileArgs args) +{ +#define MAX_MINIDUMP_ATTEMPTS 10 + + HANDLE hFile = args->hDumpFile; + int i; + + for (i = 0; i < MAX_MINIDUMP_ATTEMPTS; i++) + { + BOOL ok = args->dmp_function (GetCurrentProcess (), + GetCurrentProcessId (), + hFile, + 2, + args->mdei, + NULL, + NULL); + + if (ok) + { + break; /* dump taken! */ + } + else + { + Sleep (100); + } + } + + _endthread (); +} + +#undef CDEV_CURRENT_FUNCTION + +#define CDEV_CURRENT_FUNCTION openFileFromEnvVar +static HANDLE +openFileFromEnvVar (struct HyPortLibrary *portLibrary, char *envVarName, + char *fileNameBuff, U_32 fileNameBuffSize) +{ + HANDLE hFile; + I_32 retCode; + U_32 i; + char pidStore[25]; /* This is roughly the 3 * sizeof(int)+1 which is more than enough space */ + + if (portLibrary == NULL) + { + return INVALID_HANDLE_VALUE; + } + + retCode = + portLibrary->sysinfo_get_env (portLibrary, envVarName, fileNameBuff, + fileNameBuffSize); + if (retCode != 0) + { + return INVALID_HANDLE_VALUE; + } + + retCode = + portLibrary->sysinfo_get_env (portLibrary, HYUSE_UNIQUE_DUMP_NAMES, NULL, + 0); + if (-1 != retCode) + { + pidStore[0] = '-'; + /* this env var is set to append a unique identifier to the dump file name */ + itoa (GetCurrentProcessId (), &pidStore[1], 10); + } + else + { + /* we aren't using this feature so make this a zero-length string */ + pidStore[0] = 0; + } + + i = strlen (fileNameBuff); + i += strlen (pidStore); + if (i + 8 > fileNameBuffSize) + { + return INVALID_HANDLE_VALUE; + } + strcat (fileNameBuff, "\\hy"); + strcat (fileNameBuff, pidStore); + strcat (fileNameBuff, ".dmp"); + + hFile = CreateFileA (fileNameBuff, + GENERIC_READ | GENERIC_WRITE, + 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + + return hFile; +} + +#undef CDEV_CURRENT_FUNCTION + +#define CDEV_CURRENT_FUNCTION openFileFromReg +static HANDLE +openFileFromReg (const char *keyName, const char *valName, char *fileNameBuff, + U_32 fileNameBuffSize) +{ + HANDLE hFile; + HKEY hKey; + LONG lRet; + U_32 buffUsed = fileNameBuffSize; + + lRet = RegOpenKeyEx (HKEY_LOCAL_MACHINE, + keyName, 0, KEY_QUERY_VALUE, &hKey); + if (lRet != ERROR_SUCCESS) + { + return INVALID_HANDLE_VALUE; + } + + lRet = RegQueryValueEx (hKey, + valName, + NULL, NULL, (LPBYTE) fileNameBuff, &buffUsed); + if (lRet != ERROR_SUCCESS) + { + return INVALID_HANDLE_VALUE; + } + + RegCloseKey (hKey); + + hFile = CreateFileA (fileNameBuff, + GENERIC_READ | GENERIC_WRITE, + 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + + return hFile; +} + +#undef CDEV_CURRENT_FUNCTION + +#define CDEV_CURRENT_FUNCTION openFileInCWD +static HANDLE +openFileInCWD (struct HyPortLibrary *portLibrary, char *fileNameBuff, + U_32 fileNameBuffSize) +{ + HANDLE hFile; + U_32 length; + + if (portLibrary == NULL) + { + return INVALID_HANDLE_VALUE; + } + + length = GetModuleFileName (NULL, fileNameBuff, fileNameBuffSize); + if (length == 0 || length > fileNameBuffSize || length < 3) + { + return INVALID_HANDLE_VALUE; + } + fileNameBuff[length - 1] = 'p'; + fileNameBuff[length - 2] = 'm'; + fileNameBuff[length - 3] = 'd'; + + hFile = CreateFileA (fileNameBuff, + GENERIC_READ | GENERIC_WRITE, + 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + + return hFile; +} + +#undef CDEV_CURRENT_FUNCTION Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyport.c URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyport.c?rev=350181&view=auto ============================================================================== --- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyport.c (added) +++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyport.c Wed Nov 30 21:29:27 2005 @@ -0,0 +1,562 @@ +/* Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * @ingroup Port + * @brief Port Library + */ +#include +#include "hyport.h" +#include "portpriv.h" +#include "hyportpg.h" + +/** + * Initialize the port library. + * + * Given a pointer to a port library and the required version, + * populate the port library table with the appropriate functions + * and then call the startup function for the port library. + * + * @param[in] portLibrary The port library. + * @param[in] version The required version of the port library. + * @param[in] size Size of the port library. + * + * @return 0 on success, negative return value on failure + */ +I_32 VMCALL +hyport_init_library (struct HyPortLibrary * portLibrary, + struct HyPortLibraryVersion * version, UDATA size) +{ + /* return value of 0 is success */ + I_32 rc; + + rc = hyport_create_library (portLibrary, version, size); + + if (rc == 0) + { + rc = hyport_startup_library (portLibrary); + } + + if (rc == 0) + { + // try and initialise the nls data before any nls_* calls + initNLSCatalog(portLibrary); + } + return rc; +} + +/** + * PortLibrary shutdown. + * + * Shutdown the port library, de-allocate resources required by the components of the portlibrary. + * Any resources that werer created by @ref hyport_startup_library should be destroyed here. + * + * @param[in] portLibrary The portlibrary. + * + * @return 0 on success, negative return code on failure + */ +I_32 VMCALL +hyport_shutdown_library (struct HyPortLibrary * portLibrary) +{ + portLibrary->sig_shutdown (portLibrary); + portLibrary->shmem_shutdown (portLibrary); + portLibrary->shsem_shutdown (portLibrary); + + portLibrary->str_shutdown (portLibrary); + portLibrary->sl_shutdown (portLibrary); + portLibrary->sysinfo_shutdown (portLibrary); + portLibrary->exit_shutdown (portLibrary); + portLibrary->gp_shutdown (portLibrary); + portLibrary->time_shutdown (portLibrary); + + /* Shutdown the socket library before the tty, so it can write to the tty if required */ + portLibrary->sock_shutdown (portLibrary); + + portLibrary->nls_shutdown (portLibrary); + portLibrary->ipcmutex_shutdown (portLibrary); + portLibrary->mmap_shutdown (portLibrary); + + portLibrary->tty_shutdown (portLibrary); + portLibrary->file_shutdown (portLibrary); + + portLibrary->vmem_shutdown (portLibrary); + portLibrary->cpu_shutdown (portLibrary); + portLibrary->error_shutdown (portLibrary); + hyport_tls_shutdown (portLibrary); + portLibrary->mem_shutdown (portLibrary); + + hythread_detach (portLibrary->attached_thread); + + /* Last thing to do. If this port library was self allocated free this memory */ + if (NULL != portLibrary->self_handle) + { + hymem_deallocate_portLibrary (portLibrary); + } + + return (I_32) 0; +} + +/** + * Create the port library. + * + * Given a pointer to a port library and the required version, + * populate the port library table with the appropriate functions + * + * @param[in] portLibrary The port library. + * @param[in] version The required version of the port library. + * @param[in] size Size of the port library. + * + * @return 0 on success, negative return value on failure + * @note The portlibrary version must be compatabile with the that which we are compiled against + */ +I_32 VMCALL +hyport_create_library (struct HyPortLibrary * portLibrary, + struct HyPortLibraryVersion * version, UDATA size) +{ + UDATA versionSize = hyport_getSize (version); + + if (HYPORT_MAJOR_VERSION_NUMBER != version->majorVersionNumber) + { + return -1; + } + + if (versionSize > size) + { + return -1; + } + + /* Ensure required functionality is there */ + if ((version->capabilities & HYPORT_CAPABILITY_MASK) != + version->capabilities) + { + return -1; + } + + /* Null and initialize the table passed in */ + memset (portLibrary, 0, size); + memcpy (portLibrary, &MasterPortLibraryTable, versionSize); + + /* Reset capabilities to be what is actually there, not what was requested */ + portLibrary->portVersion.majorVersionNumber = version->majorVersionNumber; + portLibrary->portVersion.minorVersionNumber = version->minorVersionNumber; + portLibrary->portVersion.capabilities = HYPORT_CAPABILITY_MASK; + + return 0; +} + +/** + * PortLibrary startup. + * + * Start the port library, allocate resources required by the components of the portlibrary. + * All resources created here should be destroyed in @ref hyport_shutdown_library. + * + * @param[in] portLibrary The portlibrary. + * + * @return 0 on success, negative error code on failure. Error code values returned are + * \arg HYPORT_ERROR_STARTUP_THREAD + * \arg HYPORT_ERROR_STARTUP_MEM + * \arg HYPORT_ERROR_STARTUP_TLS + * \arg HYPORT_ERROR_STARTUP_TLS_ALLOC + * \arg HYPORT_ERROR_STARTUP_TLS_MUTEX + * \arg HYPORT_ERROR_STARTUP_ERROR + * \arg HYPORT_ERROR_STARTUP_CPU + * \arg HYPORT_ERROR_STARTUP_VMEM + * \arg HYPORT_ERROR_STARTUP_FILE + * \arg HYPORT_ERROR_STARTUP_TTY + * \arg HYPORT_ERROR_STARTUP_TTY_HANDLE + * \arg HYPORT_ERROR_STARTUP_TTY_CONSOLE + * \arg HYPORT_ERROR_STARTUP_MMAP + * \arg HYPORT_ERROR_STARTUP_IPCMUTEX + * \arg HYPORT_ERROR_STARTUP_NLS + * \arg HYPORT_ERROR_STARTUP_SOCK + * \arg HYPORT_ERROR_STARTUP_TIME + * \arg HYPORT_ERROR_STARTUP_GP + * \arg HYPORT_ERROR_STARTUP_EXIT + * \arg HYPORT_ERROR_STARTUP_SYSINFO + * \arg HYPORT_ERROR_STARTUP_SL + * \arg HYPORT_ERROR_STARTUP_STR + * \arg HYPORT_ERROR_STARTUP_SHSEM + * \arg HYPORT_ERROR_STARTUP_SHMEM + * \arg HYPORT_ERROR_STARTUP_SIGNAL + * + * @note The port library memory is deallocated if it was created by @ref hyport_allocate_library + */ +I_32 VMCALL +hyport_startup_library (struct HyPortLibrary * portLibrary) +{ + I_32 rc = 0; + + /* NLS uses the thread library */ + rc = hythread_attach (&portLibrary->attached_thread); + if (0 != rc) + { + /* Reassign return code as hythread_attach only returns -1 on error */ + rc = HYPORT_ERROR_STARTUP_THREAD; + goto cleanup; + } + + /* Must not access anything in portGlobals, as this allocates them */ + rc = + portLibrary->mem_startup (portLibrary, sizeof (HyPortLibraryGlobalData)); + if (0 != rc) + { + goto cleanup; + } + + /* Create the tls buffers as early as possible */ + rc = hyport_tls_startup (portLibrary); + if (0 != rc) + { + goto cleanup; + } + + /* Start error handling as early as possible, require TLS buffers */ + rc = portLibrary->error_startup (portLibrary); + if (0 != rc) + { + goto cleanup; + } + + rc = portLibrary->cpu_startup (portLibrary); + if (0 != rc) + { + goto cleanup; + } + + rc = portLibrary->vmem_startup (portLibrary); + if (0 != rc) + { + goto cleanup; + } + + rc = portLibrary->file_startup (portLibrary); + if (0 != rc) + { + goto cleanup; + } + + rc = portLibrary->tty_startup (portLibrary); + if (0 != rc) + { + goto cleanup; + } + + rc = portLibrary->mmap_startup (portLibrary); + if (0 != rc) + { + goto cleanup; + } + + rc = portLibrary->ipcmutex_startup (portLibrary); + if (0 != rc) + { + goto cleanup; + } + + rc = portLibrary->nls_startup (portLibrary); + if (0 != rc) + { + goto cleanup; + } + + rc = portLibrary->sock_startup (portLibrary); + if (0 != rc) + { + goto cleanup; + } + + rc = portLibrary->time_startup (portLibrary); + if (0 != rc) + { + goto cleanup; + } + + rc = portLibrary->gp_startup (portLibrary); + if (0 != rc) + { + goto cleanup; + } + + rc = portLibrary->exit_startup (portLibrary); + if (0 != rc) + { + goto cleanup; + } + + rc = portLibrary->sysinfo_startup (portLibrary); + if (0 != rc) + { + goto cleanup; + } + + rc = portLibrary->sl_startup (portLibrary); + if (0 != rc) + { + goto cleanup; + } + + rc = portLibrary->str_startup (portLibrary); + if (0 != rc) + { + goto cleanup; + } + + rc = portLibrary->shsem_startup (portLibrary); + if (0 != rc) + { + goto cleanup; + } + + rc = portLibrary->shmem_startup (portLibrary); + if (0 != rc) + { + goto cleanup; + } + + rc = portLibrary->sig_startup (portLibrary); + if (0 != rc) + { + goto cleanup; + } + + return rc; + +cleanup: + /* TODO: should call shutdown, but need to make all shutdown functions + * safe if the corresponding startup was not called. No worse than the existing + * code + */ + + /* If this port library was self allocated free this memory */ + if (NULL != portLibrary->self_handle) + { + hymem_deallocate_portLibrary (portLibrary); + } + + return rc; +} + +/** + * Determine the size of the port library. + * + * Given a port library version, return the size of the structure in bytes + * required to be allocated. + * + * @param[in] version The HyPortLibraryVersion structure. + * + * @return size of port library on success, zero on failure + * + * @note The portlibrary version must be compatabile with the that which we are compiled against + */ +UDATA VMCALL +hyport_getSize (struct HyPortLibraryVersion * version) +{ + /* Can't initialize a structure that is not understood by this version of the port library */ + if (HYPORT_MAJOR_VERSION_NUMBER != version->majorVersionNumber) + { + return 0; + } + + /* The size of the portLibrary table is determined by the majorVersion number + * and the presence/absense of the HYPORT_CAPABILITY_STANDARD capability + */ + if (0 != (version->capabilities & HYPORT_CAPABILITY_STANDARD)) + { + return sizeof (HyPortLibrary); + } + else + { + return offsetof (HyPortLibrary, attached_thread) + sizeof (void *); + } +} + +/** + * Determine the version of the port library. + * + * Given a port library return the version of that instance. + * + * @param[in] portLibrary The port library. + * @param[in,out] version The HyPortLibraryVersion structure to be populated. + * + * @return 0 on success, negative return value on failure + * @note If portLibrary is NULL, version is populated with the version in the linked DLL + */ +I_32 VMCALL +hyport_getVersion (struct HyPortLibrary *portLibrary, + struct HyPortLibraryVersion *version) +{ + if (NULL == version) + { + return -1; + } + + if (portLibrary) + { + version->majorVersionNumber = + portLibrary->portVersion.majorVersionNumber; + version->minorVersionNumber = + portLibrary->portVersion.minorVersionNumber; + version->capabilities = portLibrary->portVersion.capabilities; + } + else + { + version->majorVersionNumber = HYPORT_MAJOR_VERSION_NUMBER; + version->minorVersionNumber = HYPORT_MINOR_VERSION_NUMBER; + version->capabilities = HYPORT_CAPABILITY_MASK; + } + + return 0; +} + +/** + * Determine port library compatibility. + * + * Given the minimum version of the port library that the application requires determine + * if the current port library meets that requirements. + * + * @param[in] expectedVersion The version the application requires as a minimum. + * + * @return 1 if compatible, 0 if not compatible + */ +I_32 VMCALL +hyport_isCompatible (struct HyPortLibraryVersion * expectedVersion) +{ + /* Position of functions, signature of functions. + * Major number incremented when existing functions change positions or signatures + */ + if (HYPORT_MAJOR_VERSION_NUMBER != expectedVersion->majorVersionNumber) + { + return 0; + } + + /* Size of table, it's ok to have more functions at end of table that are not used. + * Minor number incremented when new functions added to the end of the table + */ + if (HYPORT_MINOR_VERSION_NUMBER < expectedVersion->minorVersionNumber) + { + return 0; + } + + /* Functionality supported */ + return (HYPORT_CAPABILITY_MASK & expectedVersion->capabilities) == + expectedVersion->capabilities; +} + +/** + * Query the port library. + * + * Given a pointer to the port library and an offset into the table determine if + * the function at that offset has been overridden from the default value expected. + * + * @param[in] portLibrary The port library. + * @param[in] offset The offset of the function to be queried. + * + * @return 1 if the function is overriden, else 0. + * + * hyport_isFunctionOverridden(portLibrary, offsetof(HyPortLibrary, mem_allocate_memory)); + */ +I_32 VMCALL +hyport_isFunctionOverridden (struct HyPortLibrary * portLibrary, UDATA offset) +{ + UDATA requiredSize; + + requiredSize = hyport_getSize (&(portLibrary->portVersion)); + if (requiredSize < offset) + { + return 0; + } + + return *((UDATA *) & (((U_8 *) portLibrary)[offset])) != + *((UDATA *) & (((U_8 *) & MasterPortLibraryTable)[offset])); +} + +/** + * Allocate a port library. + * + * Given a pointer to the required version of the port library allocate and initialize the structure. + * The startup function is not called (@ref hyport_startup_library) allowing the application to override + * any functions they desire. In the event @ref hyport_startup_library fails when called by the application + * the port library memory will be freed. + * + * @param[in] version The required version of the port library. + * @param[out] portLibrary Pointer to the allocated port library table. + * + * @return 0 on success, negative return value on failure + * + * @note portLibrary will be NULL on failure + * @note The portlibrary version must be compatabile with the that which we are compiled against + * @note @ref hyport_shutdown_library will deallocate this memory as part of regular shutdown + */ +I_32 VMCALL +hyport_allocate_library (struct HyPortLibraryVersion * version, + struct HyPortLibrary ** portLibrary) +{ + UDATA size = hyport_getSize (version); + HyPortLibrary *portLib; + I_32 rc; + + /* Allocate the memory */ + *portLibrary = NULL; + if (0 == size) + { + return -1; + } + else + { + portLib = hymem_allocate_portLibrary (size); + if (NULL == portLib) + { + return -1; + } + } + + /* Initialize with default values */ + rc = hyport_create_library (portLib, version, size); + if (0 == rc) + { + /* Record this was self allocated */ + portLib->self_handle = portLib; + *portLibrary = portLib; + } + else + { + hymem_deallocate_portLibrary (portLib); + } + return rc; +} + +/* Set up the NLS catalog. This must be called prior to attempting + * any nls_printf() calls on the port library. + */ +void +initNLSCatalog (HyPortLibrary * portLib) +{ + char *endPathPtr = NULL; + char *launcherName = NULL; + + hysysinfo_get_executable_name (portLib, NULL, &launcherName); + endPathPtr = strrchr (launcherName, DIR_SEPARATOR); + endPathPtr[1] = '\0'; + // launcherName now holds the name of the launcher's home directory + + portLib->nls_set_catalog (portLib, (const char **) &launcherName, 1, "harmony", "properties"); + + // Free memory for launcherName -- necessary ?? + if (launcherName) + { + portLib->mem_free_memory (portLib, launcherName); + } +} Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyportcontrol.c URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyportcontrol.c?rev=350181&view=auto ============================================================================== --- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyportcontrol.c (added) +++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyportcontrol.c Wed Nov 30 21:29:27 2005 @@ -0,0 +1,72 @@ +/* Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "hyport.h" +#include "portpriv.h" + +#define _UTE_STATIC_ +#include "ut_hyprt.h" + +I_32 VMCALL +hyport_control (struct HyPortLibrary * portLibrary, char *key, UDATA value) +{ + /* return value of 0 is success */ + if (!strcmp (HYPORT_CTLDATA_SIG_FLAGS, key)) + { + portLibrary->portGlobals->control.sig_flags = value; + return 0; + } + + if (!strcmp (HYPORT_CTLDATA_SHMEM_GROUP_PERM, key)) + { + portLibrary->portGlobals->control.shmem_group_perm = value; + return 0; + } + + if (!strcmp (HYPORT_CTLDATA_TRACE_START, key) && value) + { + UtInterface *utIntf = (UtInterface *) value; + utIntf->module->TraceInit (NULL, &UT_MODULE_INFO); + Trc_PRT_PortInitStages_Event1 (); + return 0; + } + + if (!strcmp (HYPORT_CTLDATA_TRACE_STOP, key) && value) + { + UtInterface *utIntf = (UtInterface *) value; + utIntf->module->TraceTerm (NULL, &UT_MODULE_INFO); + return 0; + } + +#if defined(WIN32) + if (!strcmp ("SIG_INTERNAL_HANDLER", key)) + { + /* used by optimized code to implement fast signal handling on Windows */ + extern int structuredExceptionHandler (struct HyPortLibrary + *portLibrary, + hysig_handler_fn handler, + void *handler_arg, U_32 flags, + EXCEPTION_POINTERS * + exceptionInfo); + *(int (**) + (struct HyPortLibrary *, hysig_handler_fn, void *, U_32, + EXCEPTION_POINTERS *)) value = structuredExceptionHandler; + return 0; + } +#endif + + return 1; +} Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyportpg.h URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyportpg.h?rev=350181&view=auto ============================================================================== --- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyportpg.h (added) +++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyportpg.h Wed Nov 30 21:29:27 2005 @@ -0,0 +1,59 @@ +/* Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#if !defined(hyportpg_h) +#define hyportpg_h + + +/** Number of pageSizes supported. There is always 1 for the default size, + * and 1 for the 0 terminator. + * The number of large pages supported determines the remaining size. + * Responsibility of the implementation of hyvmem to initialize this table correctly. + */ +#define HYPORT_VMEM_PAGESIZE_COUNT 3 + +/* from windef.h */ +typedef void *HANDLE; + +typedef struct HyPortPlatformGlobals +{ + HANDLE tty_consoleInputHd; + HANDLE tty_consoleOutputHd; + HANDLE tty_consoleErrorHd; + HANDLE mem_heap; + UDATA vmem_pageSize[HYPORT_VMEM_PAGESIZE_COUNT]; /** <0 terminated array of supported page sizes */ + BOOLEAN sock_IPv6_function_support; + char *si_osType; + char *si_osVersion; + U_64 time_hiresClockFrequency; + char *shmem_directory; + HANDLE shmem_creationMutex; + HANDLE shsem_creationMutex; +} HyPortPlatformGlobals; + +#define PPG_tty_consoleInputHd (portLibrary->portGlobals->platformGlobals.tty_consoleInputHd) +#define PPG_tty_consoleOutputHd (portLibrary->portGlobals->platformGlobals.tty_consoleOutputHd) +#define PPG_tty_consoleErrorHd (portLibrary->portGlobals->platformGlobals.tty_consoleErrorHd) +#define PPG_mem_heap (portLibrary->portGlobals->platformGlobals.mem_heap) +#define PPG_vmem_pageSize (portLibrary->portGlobals->platformGlobals.vmem_pageSize) +#define PPG_sock_IPv6_FUNCTION_SUPPORT (portLibrary->portGlobals->platformGlobals.sock_IPv6_function_support) +#define PPG_si_osType (portLibrary->portGlobals->platformGlobals.si_osType) +#define PPG_si_osVersion (portLibrary->portGlobals->platformGlobals.si_osVersion) +#define PPG_time_hiresClockFrequency (portLibrary->portGlobals->platformGlobals.time_hiresClockFrequency) +#define PPG_shmem_directory (portLibrary->portGlobals->platformGlobals.shmem_directory) +#define PPG_shmem_creationMutex (portLibrary->portGlobals->platformGlobals.shmem_creationMutex) +#define PPG_shsem_creationMutex (portLibrary->portGlobals->platformGlobals.shsem_creationMutex) + +#endif /* hyportpg_h */ Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyportptb.c URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyportptb.c?rev=350181&view=auto ============================================================================== --- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyportptb.c (added) +++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyportptb.c Wed Nov 30 21:29:27 2005 @@ -0,0 +1,61 @@ +/* Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "hyportptb.h" + +void VMCALL hyport_free_ptBuffer (struct HyPortLibrary *portLibrary, + PortlibPTBuffers_t ptBuffer); + +/** + * @internal + * @brief Per Thread Buffer Support + * + * Free all memory associated with a per thread buffer, including any memory it may + * have allocated. + * + * @param[in] portLibrary The port library. + * @param[in] ptBuffers pointer to the PortlibPTBuffers struct that contains the buffers + */ +void VMCALL +hyport_free_ptBuffer (struct HyPortLibrary *portLibrary, + PortlibPTBuffers_t ptBuffer) +{ + if (NULL != ptBuffer) + { + if (NULL != ptBuffer->errorMessageBuffer) + { + portLibrary->mem_free_memory (portLibrary, + ptBuffer->errorMessageBuffer); + ptBuffer->errorMessageBufferSize = 0; + } + if (NULL != ptBuffer->reportedMessageBuffer) + { + portLibrary->mem_free_memory (portLibrary, + ptBuffer->reportedMessageBuffer); + ptBuffer->reportedMessageBufferSize = 0; + } + if (NULL != ptBuffer->fdset) + { + portLibrary->mem_free_memory (portLibrary, ptBuffer->fdset); + } + if (NULL != ptBuffer->addr_info_hints.addr_info) + { + portLibrary->mem_free_memory (portLibrary, + ptBuffer->addr_info_hints.addr_info); + } + + portLibrary->mem_free_memory (portLibrary, ptBuffer); + } +} Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyportptb.h URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyportptb.h?rev=350181&view=auto ============================================================================== --- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyportptb.h (added) +++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyportptb.h Wed Nov 30 21:29:27 2005 @@ -0,0 +1,68 @@ +/* Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#if !defined(hyportptb_h) +#define hyportptb_h + +/** + * @file + * @ingroup Port + * @brief Per Thread Buffers + * + * Per thread buffers are used to store information that is not sharable among the threads. + * For example when an OS system call fails the error code associated with that error is + * relevant to the thread that called the OS function; it has no meaning to any other thread. + * + * This file contains the structure of the per thread buffers. @see hytlshelpers.c for details on accessing + * these buffers.. + */ + +#include "hyport.h" +#include "hysocket.h" +#include "hysock.h" + +#define HYERROR_DEFAULT_BUFFER_SIZE 256 /**< default customized error message size if we need to create one */ + +/** + * @typedef struct PortlibPTBuffers_struct + * @brief The per thread buffer + * Storage for data related to the threads state. + */ +typedef struct PortlibPTBuffers_struct +{ + struct PortlibPTBuffers_struct *next; /**< Next per thread buffer */ + struct PortlibPTBuffers_struct *previous; /**< Previous per thread buffer */ + I_32 platformErrorCode; /**< error code as reported by the OS */ + I_32 portableErrorCode; /**< error code translated to portable format by application */ + char *errorMessageBuffer; /**< last saved error message, either customized or from OS */ + U_32 errorMessageBufferSize; /**< error message buffer size */ + I_32 reportedErrorCode; /**< last reported error code */ + char *reportedMessageBuffer; /**< last reported error message, either customized or from OS */ + U_32 reportedMessageBufferSize; /**< reported message buffer size */ + hyfdset_t fdset; /**< file descriptor set */ + hyaddrinfo_struct addr_info_hints; +} PortlibPTBuffers_struct; + +/** + * @typedef struct PortlibPTBuffers_struct + * @brief The per thread buffer + * Storage for data related to the threads state. + */ +typedef struct PortlibPTBuffers_struct *PortlibPTBuffers_t; + +void VMCALL hyport_free_ptBuffer (struct HyPortLibrary *portLibrary, + PortlibPTBuffers_t ptBuffer); + +#endif /* hyportptb_h */ Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyprt.def URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyprt.def?rev=350181&view=auto ============================================================================== --- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyprt.def (added) +++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyprt.def Wed Nov 30 21:29:27 2005 @@ -0,0 +1,15 @@ +LIBRARY HYPRT + +SECTIONS + .data READ WRITE + .text EXECUTE READ + +EXPORTS + hyport_allocate_library + hyport_create_library + hyport_getSize + hyport_getVersion + hyport_init_library + hyport_isCompatible + hyport_startup_library + Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyprt.rc URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyprt.rc?rev=350181&view=auto ============================================================================== --- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyprt.rc (added) +++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyprt.rc Wed Nov 30 21:29:27 2005 @@ -0,0 +1,47 @@ +; +; Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable +; +; Licensed under the Apache License, Version 2.0 (the "License"); +; you may not use this file except in compliance with the License. +; You may obtain a copy of the License at +; +; http://www.apache.org/licenses/LICENSE-2.0 +; +; Unless required by applicable law or agreed to in writing, software +; distributed under the License is distributed on an "AS IS" BASIS, +; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +; See the License for the specific language governing permissions and +; limitations under the License. +; + +#include +#include + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 0,1,0,0 + PRODUCTVERSION 0,1,0,0 + FILEFLAGSMASK 0x3fL + FILEFLAGS 0x0L + FILEOS VOS_NT_WINDOWS32 + FILETYPE VFT_DLL + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "CompanyName", "The Apache Software Foundation.\0" + VALUE "FileDescription", "Portlib native code\0" + VALUE "FileVersion", "0.1\0" + VALUE "InternalName", "port\0" + VALUE "LegalCopyright", "(c) Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable.\0" + VALUE "OriginalFilename", "hyprt.dll\0" + VALUE "ProductName", "Apache Harmony\0" + VALUE "ProductVersion", "0.1\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0409, 1200 + END +END