You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ge...@apache.org on 2005/12/01 07:04:00 UTC

svn commit: r350181 [157/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....

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hynlshelpers.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hynlshelpers.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hynlshelpers.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hynlshelpers.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,131 @@
+/* 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 <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <utime.h>
+
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <locale.h>
+
+#include <langinfo.h>
+
+#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
+
+#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)
+{
+
+  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);
+
+}
+
+#undef CDEV_CURRENT_FUNCTION

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hynlshelpers.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hynlshelpers.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hynlshelpers.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hynlshelpers.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,20 @@
+/* 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/linux.IA32/port/hyosdump.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyosdump.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyosdump.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyosdump.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,178 @@
+/* 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 <sys/types.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#if defined(LINUX)
+#include <sys/mman.h>
+#endif
+
+#include "hyport.h"
+
+#include <signal.h>
+
+#define CDEV_CURRENT_FUNCTION _prototypes_private
+
+static void markAllPagesWritable (struct HyPortLibrary *portLibrary);
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION appendCoreName
+
+#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)
+{
+
+  char *lastSep = filename ? strrchr (filename, DIR_SEPARATOR) : NULL;
+  IDATA pid;
+
+  /* dump a core file */
+  if ((pid = fork ()) == 0)
+    {
+
+      /* Move to specified folder before dumping? */
+      if (lastSep != NULL)
+        {
+          lastSep[1] = '\0';
+          chdir (filename);
+        }
+
+      /* Ensure we get default action (core) - reset primary&app handlers */
+      HYJSIG_SIGNAL (SIGABRT, SIG_DFL);
+      signal (SIGABRT, SIG_DFL);
+
+#if defined(LINUX)
+      /* on Linux, shared library pages don't appear in core files by default. Mark 
+       * all pages writable to force these pages to appear 
+       */
+      markAllPagesWritable (portLibrary);
+#endif
+
+      abort ();
+
+    }
+
+  portLibrary->tty_err_printf (portLibrary,
+                               "Note: dump may be truncated if \"ulimit -c\" is set too low\n");
+
+  /* guess typical filename */
+  if (lastSep != NULL)
+    {
+      lastSep[1] = '\0';
+      strcat (filename, "{default OS core name}");
+    }
+  else if (filename != NULL)
+    {
+      strcpy (filename, "{default OS core name}");
+    }
+
+  return 0;
+
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#if defined(LINUX)
+#define CDEV_CURRENT_FUNCTION markAllPagesWritable
+/**
+ * @internal  read /proc/self/maps to determine what pages are mapped for this process.
+ * Modify each page to be writable. This will cause it to be included in core dumps.
+ *
+ * The format of /proc/self/maps is:
+ *   40000000-40013000 r-xp 00000000 03:03 1161002    /lib/ld-2.2.5.so
+ *   40013000-40014000 rw-p 00013000 03:03 1161002    /lib/ld-2.2.5.so
+ *   40014000-40016000 rw-p 00000000 00:00 0
+ * ...
+ *
+ * This implementation expects the format to be strictly conformed to.
+ * If deviations in the format are discovered, we'll have to make this routine 
+ * more robust.
+ */
+static void
+markAllPagesWritable (struct HyPortLibrary *portLibrary)
+{
+  I_32 fd =
+    portLibrary->file_open (portLibrary, "/proc/self/maps", HyOpenRead, 0);
+  if (fd != -1)
+    {
+      /* sizeof(void*) * 2 is the number of hex digits to represent a pointer */
+      char buf[sizeof (void *) * 4 + sizeof ("-")];
+      while (portLibrary->
+             file_read (portLibrary, fd, buf,
+                        sizeof (buf) - 1) == sizeof (buf) - 1)
+        {
+          char *next;
+          U_8 *start, *end;
+          int rc;
+          /* we've now read "40000000-40013000 " into buf */
+          /* NUL terminate buf for extra safety */
+          buf[sizeof (buf) - 1] = '\0';
+          /* use strtoull for correctness on 64-bit platforms and gratuitous extra precision on 32-bit platforms */
+          start = (U_8 *) (UDATA) strtoull (buf, &next, 16);
+          /* skip the '-' */
+          next += 1;
+          end = (U_8 *) (UDATA) strtoull (next, NULL, 16);
+          /* mark the pages as writable (and readable and executable, just in case they already were) */
+          rc =
+            mprotect (start, end - start, PROT_READ | PROT_WRITE | PROT_EXEC);
+          /* skip to the next line */
+          while ((portLibrary->file_read (portLibrary, fd, buf, 1) == 1)
+                 && buf[0] != '\n');
+        }
+      portLibrary->file_close (portLibrary, fd);
+    }
+}
+
+#undef CDEV_CURRENT_FUNCTION
+#endif
+
+#define CDEV_CURRENT_FUNCTION
+
+#undef CDEV_CURRENT_FUNCTION

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyport.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyport.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyport.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyport.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,561 @@
+/* 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 <string.h>
+#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/linux.IA32/port/hyportcontrol.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyportcontrol.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyportcontrol.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyportcontrol.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,71 @@
+/* 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 <string.h>
+#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/linux.IA32/port/hyportpg.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyportpg.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyportpg.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyportpg.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,38 @@
+/* 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
+typedef struct HyPortPlatformGlobals
+{
+#if defined(LINUXPPC) || defined(PPC)
+  int mem_ppcCacheLineSize;
+#endif
+  char *si_osType;
+  char *si_osVersion;
+  UDATA vmem_pageSize[HYPORT_VMEM_PAGESIZE_COUNT];       /** <0 terminated array of supported page sizes */
+} HyPortPlatformGlobals;
+#if defined(LINUXPPC) || defined(PPC)
+#define PPG_mem_ppcCacheLineSize (portLibrary->portGlobals->platformGlobals.mem_ppcCacheLineSize)
+#endif
+#define PPG_si_osType (portLibrary->portGlobals->platformGlobals.si_osType)
+#define PPG_si_osVersion (portLibrary->portGlobals->platformGlobals.si_osVersion)
+#define PPG_vmem_pageSize (portLibrary->portGlobals->platformGlobals.vmem_pageSize)
+#endif /* hyportpg_h */

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyportptb.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyportptb.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyportptb.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyportptb.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,75 @@
+/* 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 defined(IPv6_FUNCTION_SUPPORT)
+      if (NULL != ptBuffer->addr_info_hints.addr_info)
+        {
+          portLibrary->mem_free_memory (portLibrary,
+                                        ptBuffer->addr_info_hints.addr_info);
+        }
+#endif
+
+#if HOSTENT_DATA_R
+      if (NULL != ptBuffer->hostent_data)
+        {
+          portLibrary->mem_free_memory (portLibrary, ptBuffer->hostent_data);
+        }
+#elif GLIBC_R || OTHER_R || NO_R
+      if (NULL != ptBuffer->gethostBuffer)
+        {
+          portLibrary->mem_free_memory (portLibrary, ptBuffer->gethostBuffer);
+        }
+#endif
+
+      portLibrary->mem_free_memory (portLibrary, ptBuffer);
+    }
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyportptb.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyportptb.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyportptb.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyportptb.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,74 @@
+/* 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 
+ * @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 */
+  char ntoa[NTOA_SIZE];
+  hyaddrinfo_struct addr_info_hints;
+#if HOSTENT_DATA_R||GLIBC_R||OTHER_R||NO_R
+  OSHOSTENT hostent;
+#endif
+
+#if HOSTENT_DATA_R
+  OSHOSTENT_DATA *hostent_data;
+#elif GLIBC_R || OTHER_R || NO_R
+  int gethostBufferSize;
+  char *gethostBuffer;
+#endif                          /* HOSTENT_DATA_R */
+
+} PortlibPTBuffers_struct;
+/**
+ * @typedef 
+ * @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/linux.IA32/port/hyprt.exp
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyprt.exp?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyprt.exp (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyprt.exp Wed Nov 30 21:29:27 2005
@@ -0,0 +1,11 @@
+HYPRT_0.1 {
+	global :
+		hyport_allocate_library;
+		hyport_create_library;
+		hyport_getSize;
+		hyport_getVersion;
+		hyport_init_library;
+		hyport_isCompatible;
+		hyport_startup_library;
+	local : *;
+};

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hysharedhelper.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hysharedhelper.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hysharedhelper.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hysharedhelper.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,129 @@
+/* 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 "hysharedhelper.h"
+#include "hyport.h"
+#include "portpriv.h"
+#include "ut_hyprt.h"
+
+#define SUCCESS 0
+#define FAILED -1
+
+#define __errno2() 0
+
+static void changeDirectoryPermission (struct HyPortLibrary *portLibrary,
+                                       const char *pathname);
+static IDATA createDirectory (struct HyPortLibrary *portLibrary,
+                              char *pathname);
+
+/**
+ * @internal
+ * @brief Shared Semaphore and Shared Memory
+ *
+ * This function ensure the directory which used to store shared classes file exists.
+ * 
+ * @param[in] portLibrary The port library
+ * @return 0 for success, -1 for failure.
+ *
+ * @note Currently, we have fixed the base directory to be a macro in portpriv.h (HYSH_BASEDIR) 
+ *	This should be common across both shared semaphore and shared memory modules.
+ */
+
+IDATA VMCALL
+ensureDirectory (struct HyPortLibrary *portLibrary)
+{
+  I_32 rc;
+
+  Trc_PRT_shared_ensureDirectory_Entry (HYSH_BASEDIR);
+
+  rc = portLibrary->file_attr (portLibrary, HYSH_BASEDIR);
+  switch (rc)
+    {
+    case HyIsFile:
+      Trc_PRT_shared_ensureDirectory_Event1 ();
+      break;
+    case HyIsDir:
+      changeDirectoryPermission (portLibrary, HYSH_BASEDIR);
+      return SUCCESS;
+    default:                   /* Directory is not there */
+      if (FAILED != createDirectory (portLibrary, HYSH_BASEDIR))
+        {
+          changeDirectoryPermission (portLibrary, HYSH_BASEDIR);
+          return SUCCESS;
+        }
+    }
+
+  Trc_PRT_shared_ensureDirectory_Event2 (errno);
+  return FAILED;
+}
+static void
+changeDirectoryPermission (struct HyPortLibrary *portLibrary,
+                           const char *pathname)
+{
+  if (-1 == chmod (pathname, HYSH_DIRPERM))
+    {
+      Trc_PRT_shared_changeDirectoryPermission_Event1 (errno);
+    }
+}
+static IDATA
+createDirectory (struct HyPortLibrary *portLibrary, char *pathname)
+{
+
+  char tempPath[HYSH_MAXPATH];
+  char *current;
+
+  if (0 == portLibrary->file_mkdir (portLibrary, pathname))
+    {
+      return SUCCESS;
+    }
+  else if (portLibrary->error_last_error_number (portLibrary) ==
+           HYPORT_ERROR_FILE_EXIST)
+    {
+      return FAILED;
+    }
+
+  portLibrary->str_printf (portLibrary, tempPath, HYSH_MAXPATH, "%s",
+                           pathname);
+
+  current = strchr (tempPath + 1, DIR_SEPARATOR);       /* skip the first '/' */
+
+  while (portLibrary->file_attr (portLibrary, pathname) != HyIsDir)
+    {
+      char *previous;
+
+      *current = '\0';
+
+#if defined(HYSHSEM_DEBUG)
+      portLibrary->tty_printf (portLibrary, "mkdir %s\n", tempPath);
+#endif
+
+      if (-1 == portLibrary->file_mkdir (portLibrary, tempPath))
+        {
+          /* check to see whether the directory has already been created, if it is, it should
+             return file exist error. If not we should return */
+          if (portLibrary->error_last_error_number (portLibrary) !=
+              HYPORT_ERROR_FILE_EXIST)
+            {
+              return FAILED;
+            }
+        }
+
+      previous = current;
+      current = strchr (current + 1, DIR_SEPARATOR);
+      *previous = DIR_SEPARATOR;
+    }
+
+  return SUCCESS;
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hysharedhelper.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hysharedhelper.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hysharedhelper.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hysharedhelper.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,20 @@
+/* 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(hysharedhelper_h)
+#define hysharedhelper_h
+#include "hyport.h"
+IDATA VMCALL ensureDirectory (struct HyPortLibrary *portLibrary);
+#endif /* hysharedhelper_h */

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyshmem.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyshmem.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyshmem.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyshmem.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,1146 @@
+/* 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 Shared Memory Semaphores
+ */
+
+#undef CDEV_CURRENT_FUNCTION
+
+#include "hyport.h"
+#include "ut_hyprt.h"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <errno.h>
+#include <string.h>
+
+#include "portnls.h"
+#include "portpriv.h"
+#include "hysharedhelper.h"
+#define CDEV_CURRENT_FUNCTION include_header
+#include "hyshmem.h"
+#undef CDEV_CURRENT_FUNCTION
+
+#define CREATE_ERROR -10
+#define OPEN_ERROR  -11
+#define WRITE_ERROR -12
+#define READ_ERROR -13
+#define MALLOC_ERROR -14
+
+#define HYSH_NO_DATA -21
+#define HYSH_BAD_DATA -22
+
+#define RETRY_COUNT 10
+#define SUCCESS 0
+#define FAILED -1
+#define RETRY -2
+
+#define SHMFLAGS (IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR)
+#define SHMFLAGS_GROUP (IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP)
+
+#define HYSH_MEMORY_ID "_memory_"
+
+#define __errno2() 0
+
+#define CDEV_CURRENT_FUNCTION _prototypes_private
+static IDATA createFile (HyPortLibrary * portLibrary,
+                         const char *controlFile);
+static I_32 createSharedMemory (HyPortLibrary * portLibrary,
+                                struct hyshmem_handle **handle,
+                                const char *controlFile, I_32 size,
+                                I_32 perm);
+static void getNameFromControlFileName (struct HyPortLibrary *portLibrary,
+                                        char *buffer, UDATA size,
+                                        const char *controlFileName);
+static IDATA readControlFile (HyPortLibrary * portLibrary,
+                              const char *filename,
+                              struct hyshmem_controlFileFormat
+                              **controlfileinfo);
+static I_32 findError_shmget (I_32 errorCode, I_32 errorCode2);
+static I_32 findError_shmctl (I_32 errorCode, I_32 errorCode2);
+static void getControlFilePath (struct HyPortLibrary *portLibrary,
+                                char *buffer, UDATA size, const char *name);
+static I_32 findError_shmat (I_32 errorCode, I_32 errorCode2);
+static struct hyshmem_handle *createshmHandle (HyPortLibrary * portLibrary,
+                                               I_32 shmid,
+                                               const char *controlFile);
+static IDATA writeControlFile (HyPortLibrary * portLibrary,
+                               const char *filename, I_32 proj_id, key_t key,
+                               I_32 size, I_32 shmid);
+static void getControlFileName (struct HyPortLibrary *portLibrary,
+                                char *buffer, UDATA size, const char *name);
+static IDATA openSharedMemory (HyPortLibrary * portLibrary,
+                               struct hyshmem_handle **handle,
+                               const char *controlFile);
+static int isControlFileName (struct HyPortLibrary *portLibrary,
+                              char *buffer);
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyshmem_open
+/**
+ * Creates/open a shared memory region
+ * 
+ * The rootname will uniquely identify the shared memory region, 
+ * and is valid across different JVM instance. 
+ * 
+ * The shared memory region should persist across process, until OS reboots 
+ * or destroy call is being made.
+ * 
+ * @param[in] portLibrary The port Library
+ * @param[out] handle This handle is required for further attach/destroy of the memory region
+ * @param[in] rootname Shared name for the region, which used to identify the region. 
+ * @param[in] size Size of the region in bytes
+ * @param[in] perm permission for the region.
+ * 
+ * @return
+ * \arg HYPORT_ERROR_SHMEM_OPFAILED Failure - Cannot open the shared memory region
+ * \arg HYPORT_INFO_SHMEM_OPENED Success - Existing memory region has been opened
+ * \arg HYPORT_INFO_SHMEM_CREATED Success - A new shared memory region has been created
+ * 
+ */
+IDATA VMCALL
+hyshmem_open (HyPortLibrary * portLibrary, struct hyshmem_handle **handle,
+              const char *rootname, I_32 size, I_32 perm)
+{
+  /*TODO: Do we need the length to be longer? */
+  char controlFile[HYSH_MAXPATH];
+  IDATA retryCount, exist, rc;
+  key_t fkey;
+  void *region;
+  int retry = RETRY_COUNT;
+
+  Trc_PRT_shmem_hyshmem_open_Entry (rootname, size, perm);
+
+  if (ensureDirectory (portLibrary) == FAILED)
+    {
+      portLibrary->error_set_last_error (portLibrary, errno,
+                                         HYPORT_ERROR_SHMEM_DATA_DIRECTORY_FAILED);
+      Trc_PRT_shmem_hyshmem_open_Exit3 ();
+      return HYPORT_ERROR_SHSEM_OPFAILED;
+    }
+
+  getControlFilePath (portLibrary, controlFile, HYSH_MAXPATH, rootname);
+
+  while (retry)
+    {
+      I_32 rc;
+
+      rc = portLibrary->file_attr (portLibrary, controlFile);
+      if (HyIsFile != rc)
+        {
+          Trc_PRT_shmem_hyshmem_open_Event1 (controlFile);
+          rc =
+            createSharedMemory (portLibrary, handle, controlFile, size, perm);
+        }
+      else
+        {
+          Trc_PRT_shmem_hyshmem_open_Event2 (controlFile);
+          rc = openSharedMemory (portLibrary, handle, controlFile);
+        }
+
+      switch (rc)
+        {
+        case RETRY:
+          Trc_PRT_shmem_hyshmem_open_Event3 (retry);
+          retry--;
+          usleep (100);
+          continue;
+        case FAILED:
+          Trc_PRT_shmem_hyshmem_open_Exit1 ();
+          return HYPORT_ERROR_SHMEM_OPFAILED;
+        default:
+          Trc_PRT_shmem_hyshmem_open_Exit (rc, *handle);
+          return rc;
+        }
+    }
+
+  /* max number of retry count reach, return failure */
+  portLibrary->file_unlink (portLibrary, controlFile);
+  Trc_PRT_shmem_hyshmem_open_Exit2 ();
+  return HYPORT_ERROR_SHMEM_OPFAILED;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyshmem_close
+/**
+ * Detach, Close and remove the shared memory handle.
+ * 
+ * @note This method does not remove the shared memory region from the OS
+ *	 use @ref hyshmem_destroy instead. However this will free all the memory
+ * resources used by the handle, and detach the region specified by the handle
+ *
+ * @param[in] portLibrary The port Library
+ * @param[in] handle Pointer to a valid shared memory handle
+ * 
+ */
+void VMCALL
+hyshmem_close (struct HyPortLibrary *portLibrary,
+               struct hyshmem_handle **handle)
+{
+  Trc_PRT_shmem_hyshmem_close_Entry (*handle);
+  portLibrary->shmem_detach (portLibrary, handle);
+  portLibrary->mem_free_memory (portLibrary, (*handle)->baseFileName);
+  portLibrary->mem_free_memory (portLibrary, *handle);
+
+  *handle = NULL;
+  Trc_PRT_shmem_hyshmem_close_Exit ();
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyshmem_attach
+/**
+ * Attaches the shared memory represented by the handle
+ * 
+ * @param[in] portLibrary The port Library
+ * @param[in] handle A valid shared memory handle
+ * 
+ * @return: A pointer to the shared memory region, NULL on failure
+ */
+void *VMCALL
+hyshmem_attach (struct HyPortLibrary *portLibrary,
+                struct hyshmem_handle *handle)
+{
+  void *region;
+  Trc_PRT_shmem_hyshmem_attach_Entry (handle);
+
+  if (NULL == handle)
+    {
+      Trc_PRT_shmem_hyshmem_attach_Exit1 ();
+      return NULL;
+    }
+
+  Trc_PRT_shmem_hyshmem_attach_Debug1 (handle->shmid);
+
+  if (NULL != handle->regionStart)
+    {
+      Trc_PRT_shmem_hyshmem_attach_Exit (handle->regionStart);
+      return handle->regionStart;
+    }
+
+  if (handle->shmid > 0)
+    {
+      region = shmat (handle->shmid, 0, 0);
+      /* Do not do shmctl to release on event of ^C or crash */
+      if ((void *) -1 != region)
+        {
+          handle->regionStart = region;
+          Trc_PRT_shmem_hyshmem_attach_Exit (region);
+          return region;
+        }
+    }
+
+  portLibrary->error_set_last_error (portLibrary, errno,
+                                     findError_shmat (errno, __errno2 ()));
+  Trc_PRT_shmem_hyshmem_attach_Exit2 (errno);
+  return NULL;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyshmem_destroy
+/**
+ * Destroy and removes the shared memory region from OS.
+ * 
+ * The timing of which OS removes the memory is OS dependent. However when 
+ * you make a call you can considered that you can no longer access the region through
+ * the handle. Memory allocated for handle structure is freed as well.
+ * 
+ * @param[in] portLibrary The port Library
+ * @param[in] handle Pointer to a valid shared memory handle
+ * 
+ * @return 0 on success, -1 on failure.
+ */
+IDATA VMCALL
+hyshmem_destroy (struct HyPortLibrary * portLibrary,
+                 struct hyshmem_handle ** handle)
+{
+  IDATA rc;
+
+  Trc_PRT_shmem_hyshmem_destroy_Entry (*handle);
+
+  if (NULL == *handle)
+    {
+      Trc_PRT_shmem_hyshmem_destroy_Exit ();
+      return SUCCESS;
+    }
+
+  portLibrary->shmem_detach (portLibrary, handle);
+
+  rc = portLibrary->file_unlink (portLibrary, (*handle)->baseFileName);
+  Trc_PRT_shmem_hyshmem_destroy_Debug1 ((*handle)->baseFileName, rc, errno);
+
+  if (-1 == shmctl ((*handle)->shmid, IPC_RMID, NULL))
+    {
+      portLibrary->error_set_last_error (portLibrary, errno,
+                                         findError_shmctl (errno,
+                                                           __errno2 ()));
+      Trc_PRT_shmem_hyshmem_destroy_Exit1 ();
+      return FAILED;
+    }
+
+  portLibrary->shmem_close (portLibrary, handle);
+  Trc_PRT_shmem_hyshmem_destroy_Exit ();
+  return SUCCESS;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyshmem_detach
+/**
+ * Detaches the shared memory region from the caller's process address space
+ * Use @ref hyshmem_destroy to actually remove the memory region from the Operating system
+ *
+ * @param[in] portLibrary the Port Library.
+ * @param[in] handle Pointer to the shared memory region.
+ * 
+ * @return 0 on success, -1 on failure.
+ */
+IDATA VMCALL
+hyshmem_detach (struct HyPortLibrary * portLibrary,
+                struct hyshmem_handle ** handle)
+{
+  Trc_PRT_shmem_hyshmem_detach_Entry (*handle);
+  if ((*handle)->regionStart == NULL)
+    {
+      Trc_PRT_shmem_hyshmem_detach_Exit ();
+      return SUCCESS;
+    }
+
+  if (-1 == shmdt ((*handle)->regionStart))
+    {
+      Trc_PRT_shmem_hyshmem_detach_Exit1 ();
+      return FAILED;
+    }
+
+  (*handle)->regionStart = NULL;
+  Trc_PRT_shmem_hyshmem_detach_Exit ();
+  return SUCCESS;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyshmem_findclose
+/**
+ * Close the handle returned from @ref hyshmem_findfirst.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] findhandle  Handle returned from @ref hyshmem_findfirst.
+ */
+void VMCALL
+hyshmem_findclose (struct HyPortLibrary *portLibrary, UDATA findhandle)
+{
+  Trc_PRT_shmem_hyshmem_findclose_Entry (findhandle);
+  portLibrary->file_findclose (portLibrary, findhandle);
+  Trc_PRT_shmem_hyshmem_findclose_Exit ();
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyshmem_findfirst
+/**
+ * Find the name of a shared memory region on the system. Answers a handle
+ * to be used in subsequent calls to @ref hyshmem_findnext and @ref hyshmem_findclose. 
+ *
+ * @param[in] portLibrary The port library
+ * @param[out] resultbuf filename and path matching path.
+ *
+ * @return valid handle on success, -1 on failure.
+ */
+UDATA VMCALL
+hyshmem_findfirst (struct HyPortLibrary *portLibrary, char *resultbuf)
+{
+  UDATA findHandle;
+  char file[HyMaxPath];
+
+  Trc_PRT_shmem_hyshmem_findfirst_Entry ();
+  findHandle = portLibrary->file_findfirst (portLibrary, HYSH_BASEDIR, file);
+
+  if (findHandle == -1)
+    {
+      Trc_PRT_shmem_hyshmem_findfirst_Exit1 ();
+      return -1;
+    }
+
+  while (!isControlFileName (portLibrary, file))
+    {
+      if (-1 == portLibrary->file_findnext (portLibrary, findHandle, file))
+        {
+          portLibrary->file_findclose (portLibrary, findHandle);
+          Trc_PRT_shmem_hyshmem_findfirst_Exit2 ();
+          return -1;
+        }
+    }
+
+  /*TODO: We want to do some verifying here */
+  getNameFromControlFileName (portLibrary, resultbuf, HyMaxPath, file);
+  Trc_PRT_shmem_hyshmem_findfirst_Exit ();
+  return findHandle;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyshmem_findnext
+/**
+ * Find the name of the next shared memory region.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] findhandle handle returned from @ref hyshmem_findfirst.
+ * @param[out] resultbuf next filename and path matching findhandle.
+ *
+ * @return 0 on success, -1 on failure or if no matching entries.
+ */
+I_32 VMCALL
+hyshmem_findnext (struct HyPortLibrary * portLibrary, UDATA findHandle,
+                  char *resultbuf)
+{
+  char file[HyMaxPath];
+  int result;
+
+  Trc_PRT_shmem_hyshmem_findnext_Entry (findHandle);
+
+  if (-1 == portLibrary->file_findnext (portLibrary, findHandle, file))
+    {
+      Trc_PRT_shmem_hyshmem_findnext_Exit1 ();
+      return -1;
+    }
+
+  while (!isControlFileName (portLibrary, file))
+    {
+      if (-1 == portLibrary->file_findnext (portLibrary, findHandle, file))
+        {
+          Trc_PRT_shmem_hyshmem_findnext_Exit2 ();
+          return -1;
+        }
+    }
+
+  /* TODO: needs code to verify whether the file is a valid control file */
+  getNameFromControlFileName (portLibrary, resultbuf, HyMaxPath, file);
+  Trc_PRT_shmem_hyshmem_findnext_Exit ();
+  return 0;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyshmem_stat
+/**
+ * Return the statistic for a shared memory region
+ *
+ * @note notice that the implementation can decided to put -1 in the fields of @ref statbuf
+ * if it does not make sense on this platform, or it is impossible to obtain.
+ * 
+ * @param[in] portLibrary The port library
+ * @param[in] name The name of the shared memory area.
+ * @param[out] statbuf the statistics returns by the operating system
+ *
+ * @return 0 on success, -1 on failure or if there is no matching entries.
+ */
+UDATA VMCALL
+hyshmem_stat (struct HyPortLibrary * portLibrary, const char *name,
+              struct HyPortShmemStatistic * statbuf)
+{
+  I_32 rc;
+  char controlFile[HYSH_MAXPATH];
+  struct hyshmem_controlFileFormat *fileContents;
+  struct shmid_ds shminfo;
+
+  Trc_PRT_shmem_hyshmem_stat_Entry (name);
+  if (statbuf == NULL)
+    {
+      return -1;
+    }
+
+  getControlFilePath (portLibrary, controlFile, HYSH_MAXPATH, name);
+
+  rc = portLibrary->file_attr (portLibrary, controlFile);
+  if (HyIsFile != rc)
+    {
+      Trc_PRT_shmem_hyshmem_stat_Exit1 (controlFile);
+      return -1;
+    }
+
+  if (readControlFile (portLibrary, controlFile, &fileContents) != SUCCESS)
+    {
+      Trc_PRT_shmem_hyshmem_stat_Exit2 (controlFile);
+      return -1;
+    }
+
+  statbuf->shmid = fileContents->shmid;
+  statbuf->file = NULL;         /* We probably don't need it */
+
+  rc = shmctl (statbuf->shmid, IPC_STAT, &shminfo);
+
+  if (-1 == rc)
+    {
+      Trc_PRT_shmem_hyshmem_stat_Exit3 (errno);
+      return -1;
+    }
+
+  statbuf->atime = shminfo.shm_atime;
+  statbuf->dtime = shminfo.shm_dtime;
+  statbuf->chtime = shminfo.shm_ctime;
+  statbuf->nattach = shminfo.shm_nattch;
+  statbuf->perm = 0;            /* Not used yet, but we probably want to convert into portable ones later */
+
+  Trc_PRT_shmem_hyshmem_stat_Exit ();
+  return 0;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyshmem_shutdown
+/**
+ * PortLibrary shutdown.
+ *
+ * This function is called during shutdown of the portLibrary.  Any resources that were created by @ref hyshsem_startup
+ * should be destroyed here.
+ *
+ * @param[in] portLibrary The port library.
+ *
+ * @note Most implementations will be empty.
+ */
+void VMCALL
+hyshmem_shutdown (struct HyPortLibrary *portLibrary)
+{
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyshmem_startup
+/**
+ * PortLibrary startup.
+ *
+ * This function is called during startup of the portLibrary.  Any resources that are required for
+ * the file operations may be created here.  All resources created here should be destroyed
+ * in @ref hyshsem_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_SHMEM
+ *
+ * @note Most implementations will simply return success.
+ */
+I_32 VMCALL
+hyshmem_startup (struct HyPortLibrary *portLibrary)
+{
+  portLibrary->portGlobals->control.shmem_group_perm = 0;
+  return 0;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION openSharedMemory
+static IDATA
+openSharedMemory (HyPortLibrary * portLibrary, struct hyshmem_handle **handle,
+                  const char *controlFile)
+{
+  struct hyshmem_controlFileFormat *info;
+  key_t fkey;
+  void *region;
+  UDATA retryCount = RETRY_COUNT;
+  IDATA rc;
+
+  while (retryCount > 0)
+    {
+      rc = readControlFile (portLibrary, controlFile, &info);
+      switch (rc)
+        {
+        case OPEN_ERROR:
+          return FAILED;
+        case READ_ERROR:
+          return RETRY;
+        case HYSH_NO_DATA:
+          retryCount--;
+          usleep (100);
+          continue;
+        case HYSH_BAD_DATA:
+          return FAILED;
+        default:
+          retryCount = 0;
+          break;
+        }
+    }
+
+  if (NULL == info)
+    {
+      /* Can't get anything from the control file */
+      /* We will just unlink the control file and retry */
+#if defined(HYSHMEM_DEBUG)
+      portLibrary->tty_printf (portLibrary,
+                               "info is not right, back to top\n");
+#endif /* HYSHMEM_DEBUG */
+
+      if (portLibrary->file_unlink (portLibrary, controlFile) < 0)
+        {
+          return FAILED;
+        }
+      else
+        {
+          return RETRY;
+        }
+    }
+
+  /* check that the modlevel and version is okay */
+  if (info->version != HYSH_VERSION || info->modlevel != HYSH_MODLEVEL)
+    {
+      portLibrary->mem_free_memory (portLibrary, info);
+      return FAILED;
+    }
+
+  *handle = createshmHandle (portLibrary, info->shmid, controlFile);
+
+  /* Check that we can actually attach to *a* region */
+  region = hyshmem_attach (portLibrary, *handle);
+  if (NULL == region)
+    {
+      /* controlFile's shmid is bad, or in zOS case we are using the wrong key! */
+
+#if defined(HYSHMEM_DEBUG)
+      portLibrary->tty_printf (portLibrary, "shmid not valid, back to top\n");
+#endif /* HYSHMEM_DEBUG */
+
+      portLibrary->mem_free_memory (portLibrary, info);
+      if (portLibrary->error_last_error_number (portLibrary) ==
+          HYPORT_ERROR_SHMEM_INVALID_INPUT)
+        {
+          if (portLibrary->file_unlink (portLibrary, controlFile) == 0)
+            {
+              return RETRY;
+            }
+        }
+      return FAILED;
+    }
+
+  /* everything rosy, so just detach the region */
+  hyshmem_detach (portLibrary, handle);
+
+  /* now setup the handle */
+
+  (*handle)->timestamp = portLibrary->file_lastmod (portLibrary, controlFile);
+  portLibrary->mem_free_memory (portLibrary, info);
+
+  return HYPORT_INFO_SHMEM_OPENED;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION createSharedMemory
+static I_32
+createSharedMemory (HyPortLibrary * portLibrary,
+                    struct hyshmem_handle **handle, const char *controlFile,
+                    I_32 size, I_32 perm)
+{
+  I_32 projid = 1;
+  key_t fkey;
+  I_32 shmid;
+  IDATA rc;
+
+  int group_perm = portLibrary->portGlobals->control.shmem_group_perm;
+  int shmflags = group_perm ? SHMFLAGS_GROUP : SHMFLAGS;
+
+  Trc_PRT_shmem_createSharedMemory_Entry ();
+
+  /* Control file doesn't exist, so we create it along with shared memory region.
+   * If the control file exists we might be in a creation race, return to the top
+   */
+  rc = createFile (portLibrary, controlFile);
+  if (HYPORT_ERROR_FILE_EXIST == rc)
+    {
+      Trc_PRT_shmem_createSharedMemory_Exit1 ();
+      return RETRY;
+    }
+  else if (CREATE_ERROR == rc)
+    {
+      Trc_PRT_shmem_createSharedMemory_Exit2 ();
+      return FAILED;
+    }
+
+  /*created control file, now create shared memory */
+  while (1)
+    {
+      /* first ftok to get key */
+
+      Trc_PRT_shmem_createSharedMemory_ftok (controlFile, projid);
+      fkey = ftok (controlFile, projid);
+      if (-1 == fkey)
+        {
+          if (errno == ENOENT || errno == ENOTDIR)
+            {
+              /* TODO: Someone removed our directory!
+               * We will need a new return code here and tell user
+               * of this lib to restart at top */
+              Trc_PRT_shmem_createSharedMemory_Exit3 ();
+              return RETRY;
+            }
+          /* any other error code is is bad */
+          Trc_PRT_shmem_createSharedMemory_Exit4 ();
+          return FAILED;
+        }
+
+      /* now we do semget */
+      /* TODO: we need to round up size to nearest M */
+      Trc_PRT_shmem_createSharedMemory_shmget (fkey, size, SHMFLAGS);
+      shmid = shmget (fkey, size, shmflags);
+
+      if (-1 == shmid)
+        {
+          if (EEXIST == errno)
+            {
+              if (projid >= HYSH_MAX_PROJ_ID)
+                {
+                  portLibrary->error_set_last_error (portLibrary, errno,
+                                                     findError_shmget (errno,
+                                                                       __errno2
+                                                                       ()));
+                  Trc_PRT_shmem_createSharedMemory_Exit5 (HYSH_MAX_PROJ_ID);
+                  return FAILED;
+                }
+              else
+                {
+                  Trc_PRT_shmem_createSharedMemory_shmget_Event1 (projid);
+                  projid++;
+                  continue;
+                }
+            }
+
+          /* If we get here it means some OS error stop us getting shm segments */
+          /* Here we would want to capture the zOS errno2 - in order to see whether
+             We are trying to create in different storage key */
+          portLibrary->error_set_last_error (portLibrary, errno,
+                                             findError_shmget (errno,
+                                                               __errno2 ()));
+          portLibrary->file_unlink (portLibrary, controlFile);
+          Trc_PRT_shmem_createSharedMemory_Exit6 (errno, __errno2 ());
+          return FAILED;
+        }
+      else
+        {
+          /* shmid is good, we can stop loop */
+          break;
+        }
+    }
+
+  Trc_PRT_shmem_createSharedMemory_Event1 (shmid);
+
+  if (writeControlFile (portLibrary, controlFile, projid, fkey, size, shmid)
+      == CREATE_ERROR)
+    {
+      Trc_PRT_shmem_createSharedMemory_Exit7 ();
+      portLibrary->file_unlink (portLibrary, controlFile);
+      return FAILED;
+    }
+
+  *handle = createshmHandle (portLibrary, shmid, controlFile);
+  if (NULL == *handle)
+    {
+      Trc_PRT_shmem_createSharedMemory_Exit8 ();
+      return FAILED;
+    }
+
+  (*handle)->timestamp = portLibrary->file_lastmod (portLibrary, controlFile);
+
+  Trc_PRT_shmem_createSharedMemory_Exit ();
+  return HYPORT_INFO_SHMEM_CREATED;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION createFile
+static IDATA
+createFile (HyPortLibrary * portLibrary, const char *controlFile)
+{
+  I_32 fd;
+
+  Trc_PRT_shmem_createFile_Entry ();
+
+  fd =
+    portLibrary->file_open (portLibrary, controlFile,
+                            HyOpenWrite | HyOpenCreateNew, HYSH_BASEFILEPERM);
+  if (-1 == fd)
+    {
+      I_32 errorno = portLibrary->error_last_error_number (portLibrary);
+
+      /*special handling for file exist case */
+      if (HYPORT_ERROR_FILE_EXIST == errorno)
+        {
+          Trc_PRT_shmem_createFile_Exit1 ();
+          return errorno;
+        }
+
+      Trc_PRT_shmem_createFile_Exit2 (portLibrary->
+                                      error_last_error_message (portLibrary));
+      return CREATE_ERROR;
+    }
+
+  Trc_PRT_shmem_createFile_Exit ();
+  portLibrary->file_close (portLibrary, fd);
+  return SUCCESS;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION createshmHandle
+static struct hyshmem_handle *
+createshmHandle (HyPortLibrary * portLibrary, I_32 shmid,
+                 const char *controlFile)
+{
+  struct hyshmem_handle *result;
+  IDATA cfstrLength = strlen (controlFile);
+
+  result =
+    portLibrary->mem_allocate_memory (portLibrary,
+                                      sizeof (struct hyshmem_handle));
+  if (NULL == result)
+    {
+#if defined(HYSHMEM_DEBUG)
+      portLibrary->tty_printf (portLibrary, "Malloc error!");
+#endif /* HYSHMEM_DEBUG */
+
+      return NULL;              /*malloc error! */
+    }
+
+  result->shmid = shmid;
+  result->baseFileName =
+    portLibrary->mem_allocate_memory (portLibrary, cfstrLength + 1);
+  if (NULL == result->baseFileName)
+    {
+      portLibrary->mem_free_memory (portLibrary, result);
+      return NULL;
+    }
+
+  portLibrary->str_printf (portLibrary, result->baseFileName, cfstrLength + 1,
+                           controlFile);
+  result->regionStart = NULL;
+  return result;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION writeControlFile
+static IDATA
+writeControlFile (HyPortLibrary * portLibrary, const char *filename,
+                  I_32 proj_id, key_t key, I_32 size, I_32 shmid)
+{
+  I_32 fd, rc;
+  struct hyshmem_controlFileFormat *info;
+
+  fd =
+    portLibrary->file_open (portLibrary, filename,
+                            HyOpenTruncate | HyOpenWrite, HYSH_BASEFILEPERM);
+  if (-1 == fd)
+    {
+      return CREATE_ERROR;
+    }
+
+  info =
+    portLibrary->mem_allocate_memory (portLibrary,
+                                      sizeof (struct
+                                              hyshmem_controlFileFormat));
+  if (info == NULL)
+    {
+      /*malloc failure! */
+      return CREATE_ERROR;
+    }
+
+  info->version = HYSH_VERSION;
+  info->modlevel = HYSH_MODLEVEL;
+  info->proj_id = proj_id;
+  info->ftok_key = key;
+  info->shmid = shmid;
+  info->size = size;
+  info->uid = getuid ();
+  info->gid = getgid ();
+
+#if defined(HYSHMEM_DEBUG)
+  portLibrary->tty_printf (portLibrary, "writing: shmid = %x\n", shmid);
+#endif /* HYSHMEM_DEBUG */
+
+  rc =
+    portLibrary->file_write (portLibrary, fd, info,
+                             sizeof (struct hyshmem_controlFileFormat));
+  if (rc < 0)
+    {
+      rc = CREATE_ERROR;
+    }
+  else
+    {
+      rc = SUCCESS;
+    }
+
+  portLibrary->file_close (portLibrary, fd);
+  portLibrary->mem_free_memory (portLibrary, info);
+  return rc;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION readControlFile
+static IDATA
+readControlFile (HyPortLibrary * portLibrary, const char *filename,
+                 struct hyshmem_controlFileFormat **controlfileinfo)
+{
+  I_32 fd, rc;
+  struct hyshmem_controlFileFormat *info;
+
+  fd = portLibrary->file_open (portLibrary, filename, HyOpenRead, 0);
+  if (-1 == fd)
+    {
+      return OPEN_ERROR;
+    }
+
+  info =
+    portLibrary->mem_allocate_memory (portLibrary,
+                                      sizeof (struct
+                                              hyshmem_controlFileFormat));
+  if (NULL == info)
+    {
+      /* malloc failure! */
+      return MALLOC_ERROR;
+    }
+
+  rc =
+    portLibrary->file_read (portLibrary, fd, info,
+                            sizeof (struct hyshmem_controlFileFormat));
+  portLibrary->file_close (portLibrary, fd);
+  if (rc < 0)
+    {
+      rc = READ_ERROR;
+    }
+  else if (rc == 0)
+    {
+      rc = HYSH_NO_DATA;
+    }
+  else if (rc < sizeof (struct hyshmem_controlFileFormat))
+    {
+      rc = HYSH_BAD_DATA;
+    }
+  else
+    {
+      rc = SUCCESS;
+    }
+
+  if (SUCCESS != rc)
+    {
+      portLibrary->mem_free_memory (portLibrary, info);
+      (*controlfileinfo) = NULL;
+    }
+  else
+    {
+      (*controlfileinfo) = info;
+    }
+
+  return rc;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION getControlFileName
+/**
+ * @internal
+ * Get the filename for a shared memory area
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] buffer where the base file name will be stored
+ * @param[in] size size of the buffer
+ * @param[in] name of the shared memory area
+ *
+ */
+static void
+getControlFileName (struct HyPortLibrary *portLibrary, char *buffer,
+                    UDATA size, const char *name)
+{
+  char versionStr[256];
+
+  GET_VERSION_STRING (portLibrary, versionStr);
+  portLibrary->str_printf (portLibrary, buffer, size, "%s%s%s", versionStr,
+                           HYSH_MEMORY_ID, name);
+
+#if defined(HYSHMEM_DEBUG)
+  portLibrary->tty_printf (portLibrary, "getControlFileName returns: %s\n",
+                           buffer);
+#endif
+
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION isControlFileName
+static int
+isControlFileName (struct HyPortLibrary *portLibrary, char *buffer)
+{
+  char versionStr[30];
+
+  GET_VERSION_STRING (portLibrary, versionStr);
+
+  if (NULL != strstr (buffer, versionStr))
+    {
+      if (NULL != strstr (buffer, HYSH_MEMORY_ID))
+        {
+          return 1;
+        }
+    }
+
+  return 0;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION getNameFromControlFileName
+static void
+getNameFromControlFileName (struct HyPortLibrary *portLibrary, char *buffer,
+                            UDATA size, const char *controlFileName)
+{
+  char *name = strstr (controlFileName, HYSH_MEMORY_ID);
+
+  if (name == NULL)
+    {
+      return;
+    }
+
+  name = name + strlen (HYSH_MEMORY_ID);
+
+  portLibrary->str_printf (portLibrary, buffer, size, name);
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION getControlFilePath
+/**
+ * @internal
+ * Get the full path for a shared memory area
+ *
+ * @param[in] portLibrary The port library
+ * @param[out] buffer where the path will be stored
+ * @param[in] size size of the buffer
+ * @param[in] name of the shared memory area
+ *
+ */
+static void
+getControlFilePath (struct HyPortLibrary *portLibrary, char *buffer,
+                    UDATA size, const char *name)
+{
+  char versionStr[256];
+
+  GET_VERSION_STRING (portLibrary, versionStr);
+  portLibrary->str_printf (portLibrary, buffer, size, "%s%s%s%s",
+                           HYSH_BASEDIR, versionStr, HYSH_MEMORY_ID, name);
+
+#if defined(HYSHMEM_DEBUG)
+  portLibrary->tty_printf (portLibrary, "getControlFileName returns: %s\n",
+                           buffer);
+#endif
+
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION findError_shmget
+/**
+ * @internal
+ * Determines the proper portable error code to return given a native error code, for shmget calls
+ *
+ * @param[in] errorCode The error code reported by the OS
+ *
+ * @return	the (negative) portable error code
+ */
+static I_32
+findError_shmget (I_32 errorCode, I_32 errorCode2)
+{
+  switch (errorCode)
+    {
+    case EPERM:
+    case EACCES:
+      return HYPORT_ERROR_SHMEM_NOPERMISSION;
+    case EEXIST:
+      return HYPORT_ERROR_SHMEM_ALREADY_EXIST;
+    case EINVAL:
+      return HYPORT_ERROR_SHMEM_TOOBIG;
+    case ENOMEM:
+    case ENOSPC:
+    case EMFILE:
+      return HYPORT_ERROR_SHMEM_NOSPACE;
+    case ENOENT:
+    default:
+      return HYPORT_ERROR_SHMEM_OPFAILED;
+    }
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION findError_shmat
+/**
+ * @internal
+ * Determines the proper portable error code to return given a native error code
+ *
+ * @param[in] errorCode The error code reported by the OS
+ *
+ * @return	the (negative) portable error code
+ */
+static I_32
+findError_shmat (I_32 errorCode, I_32 errorCode2)
+{
+  switch (errorCode)
+    {
+    case EPERM:
+    case EACCES:
+      return HYPORT_ERROR_SHMEM_NOPERMISSION;
+    case EEXIST:
+      return HYPORT_ERROR_SHMEM_ALREADY_EXIST;
+    case ENOMEM:
+    case ENOSPC:
+    case EMFILE:
+      return HYPORT_ERROR_SHMEM_NOSPACE;
+    case EINVAL:
+      return HYPORT_ERROR_SHMEM_INVALID_INPUT;
+    case ENOENT:
+    default:
+      return HYPORT_ERROR_SHMEM_ATTACH_FAILED;
+    }
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION findError_shmctl
+/**
+ * @internal
+ * Determines the proper portable error code to return given a native error code
+ *
+ * @param[in] errorCode The error code reported by the OS
+ *
+ * @return	the (negative) portable error code
+ */
+static I_32
+findError_shmctl (I_32 errorCode, I_32 errorCode2)
+{
+  switch (errorCode)
+    {
+    case EPERM:
+    case EACCES:
+      return HYPORT_ERROR_SHMEM_NOPERMISSION;
+    default:
+      return HYPORT_ERROR_SHMEM_OPFAILED;
+    }
+}
+
+#undef CDEV_CURRENT_FUNCTION

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyshmem.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyshmem.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyshmem.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyshmem.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,38 @@
+/* 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(hyshmem_h)
+#define hyshmem_h
+#include <sys/types.h>
+typedef struct hyshmem_handle
+{
+  I_32 shmid;
+  char *baseFileName;
+  void *regionStart;
+  I_64 timestamp;
+  I_32 baseFilefd;
+} hyshmem_handle;
+typedef struct hyshmem_controlFileFormat
+{
+  I_32 version;
+  I_32 modlevel;
+  key_t ftok_key;
+  I_32 proj_id;
+  I_32 shmid;
+  I_64 size;
+  I_32 uid;
+  I_32 gid;
+} hyshmem_controlFileFormat;
+#endif /* hyshmem_h */