harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r350181 [155/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 GMT
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/hynio.exp
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/hynio.exp?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/hynio.exp (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/hynio.exp Wed Nov 30 21:29:27 2005
@@ -0,0 +1,35 @@
+HYNIO_0.1 {
+	global :
+		Java_com_ibm_platform_OSFileSystem_readDirectImpl;
+		Java_com_ibm_platform_OSFileSystem_writeDirectImpl;
+		Java_com_ibm_platform_OSFileSystem_readImpl;
+		Java_com_ibm_platform_OSFileSystem_seekImpl;
+		Java_com_ibm_platform_OSFileSystem_fflushImpl;
+		Java_com_ibm_platform_OSFileSystem_closeImpl;
+		Java_com_ibm_platform_OSFileSystem_mmapImpl;
+		Java_com_ibm_platform_OSFileSystem_lockImpl;
+		Java_com_ibm_platform_OSFileSystem_unlockImpl;
+		Java_com_ibm_platform_OSMemory_isLittleEndianImpl;
+		Java_com_ibm_platform_OSMemory_getPointerSizeImpl;
+		Java_com_ibm_platform_OSMemory_getAddress;
+		Java_com_ibm_platform_OSMemory_setAddress;
+		Java_com_ibm_platform_OSMemory_malloc;
+		Java_com_ibm_platform_OSMemory_free;
+		Java_com_ibm_platform_OSMemory_memmove;
+		Java_com_ibm_platform_OSMemory_memset;
+		Java_com_ibm_platform_OSMemory_getByteArray;
+		Java_com_ibm_platform_OSMemory_setByteArray;
+		Java_com_ibm_platform_OSMemory_getByte;
+		Java_com_ibm_platform_OSMemory_setByte;
+		Java_com_ibm_platform_OSMemory_getShort;
+		Java_com_ibm_platform_OSMemory_setShort;
+		Java_com_ibm_platform_OSMemory_getInt;
+		Java_com_ibm_platform_OSMemory_setInt;
+		Java_com_ibm_platform_OSMemory_getLong;
+		Java_com_ibm_platform_OSMemory_setLong;
+		Java_com_ibm_platform_OSMemory_getFloat;
+		Java_com_ibm_platform_OSMemory_setFloat;
+		Java_com_ibm_platform_OSMemory_getDouble;
+		Java_com_ibm_platform_OSMemory_setDouble;
+	local : *;
+};

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/jcl.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/jcl.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/jcl.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/jcl.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,20 @@
+/* Copyright 2004, 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(jcl_h)
+#define jcl_h
+#define USING_VMI
+#include "vmi.h"
+#endif /* jcl_h */

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/makefile
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/makefile?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/makefile (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/makefile Wed Nov 30 21:29:27 2005
@@ -0,0 +1,70 @@
+# 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.
+
+#
+# Makefile for module 'nio'
+#
+
+include ../makefile.include
+
+DLLFILENAME=libhynio.so# declaration
+
+DLLNAME=../libhynio.so# declaration
+
+LIBNAME=hynio# declaration
+
+LIBPATH=../lib/# declaration
+
+CFLAGS=-fpic -O1 -march=pentium3 -DLINUX -D_REENTRANT -DIPv6_FUNCTION_SUPPORT -DHYX86  -I../include -I../zlib -I../zip -I../fdlibm -I../nio $(VMDEBUG)
+
+.SUFFIXES:.cpp
+.cpp.o:
+	$(CXX) -fpic -O1 -march=pentium3 -fno-exceptions -fno-rtti -DLINUX -D_REENTRANT -DIPv6_FUNCTION_SUPPORT -DHYX86  -I../include -I../zlib -I../zip -I../fdlibm -I../nio $(VMDEBUG) -c $<
+
+ASFLAGS= -o $@
+
+.SUFFIXES:.asm
+.asm.o:
+	perl ../masm2gas/masm2gas.pl -I../include -I../zlib -I../zip -I../fdlibm -I../nio $*.asm
+	$(AS) $(ASFLAGS) -o $*.o $*.s
+	-rm $*.s
+
+BUILDFILES1 = nio_copyright.o 
+BUILDFILES2 = OSFileSystem.o OSFileSystemLinux32.o OSMemory.o OSMemoryLinux32.o
+
+MDLLIBFILES1 = ../libhysig.so ../lib/libhyzip.a ../libhyzlib.so ../lib/libhycommon.a ../lib/libhypool.a
+MDLLIBFILES2 = ../lib/libhyfdlibm.a ../libhythr.so ../libvmi.so
+
+all: \
+	 $(DLLNAME)
+
+BUILDLIB: $(DLLNAME)
+
+$(DLLNAME):\
+	$(BUILDFILES1) $(BUILDFILES2) \
+	$(MDLLIBFILES1) $(MDLLIBFILES2) 
+	$(DLL_LD) -shared -Wl,--version-script,$(LIBNAME).exp -Wl,-soname=$(DLLFILENAME) $(VMLINK) -L.  -L../lib -L.. -o $(DLLNAME) \
+	$(BUILDFILES1) $(BUILDFILES2) -Xlinker --start-group \
+	-lhysig \
+	-lhyzip \
+	-lhyzlib \
+	-lhycommon \
+	-lhypool \
+	-lhyfdlibm \
+	-lhythr \
+	-lvmi -Xlinker --end-group  -lc -lm -ldl
+
+clean:
+	-rm -f *.o
+	-rm -f ../libhynio.so

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/nio_copyright.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/nio_copyright.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/nio_copyright.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/nio_copyright.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,19 @@
+/* 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.
+ */
+
+/* A copyright string included in each DLL and executable */
+
+const char hyCopyright[] =
+  "(c) Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable.";

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/pool/DoxygenSupport.txt
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/pool/DoxygenSupport.txt?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/pool/DoxygenSupport.txt (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/pool/DoxygenSupport.txt Wed Nov 30 21:29:27 2005
@@ -0,0 +1,25 @@
+# Copyright 2004 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.
+
+/*
+ * This file provides the group definitions required to create the Doxygen generated
+ * output for compounds.  There is one group per directory (port, pool, thread, etc.).
+ */
+ 
+/**
+ * @defgroup Pool Pool
+ * @brief Provides primitives  for creation, iteration, and deletion of pools of (arbitrary) elements.
+ */
+
+

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/pool/makefile
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/pool/makefile?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/pool/makefile (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/pool/makefile Wed Nov 30 21:29:27 2005
@@ -0,0 +1,53 @@
+# 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.
+
+#
+# Makefile for module 'pool'
+#
+
+include ../makefile.include
+
+LIBNAME=libhypool.a# declaration
+
+LIBPATH=../lib/# declaration
+
+BUILDFILES1 = pool.o pool_cap.o
+
+CFLAGS= -DLINUX -D_REENTRANT -O1 -march=pentium3 -DIPv6_FUNCTION_SUPPORT  -DHYX86 -I../include  $(VMDEBUG)
+
+.SUFFIXES:.cpp
+.cpp.o:
+	$(CXX)  -DLINUX -D_REENTRANT -O1 -march=pentium3 -fno-exceptions -fno-rtti -DIPv6_FUNCTION_SUPPORT  -DHYX86 -I../include  $(VMDEBUG) -c $<
+
+ASFLAGS= -o $@
+
+.SUFFIXES:.asm
+.asm.o:
+	perl ../masm2gas/masm2gas.pl   -I../include $*.asm
+	$(AS) $(ASFLAGS) -o $*.o $*.s
+	-rm $*.s
+
+all: $(LIBPATH)$(LIBNAME)
+
+$(LIBPATH)$(LIBNAME):\
+	$(BUILDFILES1) 
+	$(AR) rcv $(LIBPATH)$(LIBNAME) \
+	$(BUILDFILES1) 
+
+quick:
+	$(MAKE)
+
+clean:
+	-rm -f *.o
+	-rm -f ../lib/libhypool.a

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/pool/pool.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/pool/pool.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/pool/pool.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/pool/pool.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,580 @@
+/* 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 Pool
+ * @brief Pool primitives (creation, iteration, deletion, etc.)
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "hypool.h"
+
+#define ROUND_TO(granularity, number) ( (((number) % (granularity)) ? ((number) + (granularity) - ((number) % (granularity))) : (number)))
+
+#define MIN_GRANULARITY		sizeof(UDATA)
+
+#define MALLOC_ALIGNMENT sizeof(UDATA)
+
+/* read this if a port library call becomes available that gives out the OS page size */
+#if 0
+#define OS_PAGE_SIZE		(EsGetAddressSpacePageSize())
+#else
+
+#define OS_PAGE_SIZE		4096
+#endif
+
+/**
+ *	Returns a handle to a variable sized pool of structures.
+ *	This handle should be passed into all other pool functions.
+ *
+ * @param[in] structSize Size of the pool-elements
+ * @param[in] minNumberElelements If zero, will default to 1
+ * @param[in] elementAlignment If zero will default to MIN_GRANULARITY
+ * @param[in] poolFlags
+ * @param[in] memAlloc Allocate function pointer
+ * @param[in] memFree	Free function pointer
+ * @param[in] userData
+ *
+ * @return pointer to a new pool
+ *
+*/
+HyPool *VMCALL
+pool_new (U_32 structSize, U_32 minNumberElements, U_32 elementAlignment,
+          UDATA poolFlags, void *(VMCALL * memAlloc) (void *, U_32),
+          void (VMCALL * memFree) (void *, void *), void *userData)
+{
+  U_64 roundedStructSize, tempAllocSize, finalAllocSize;
+  U_32 finalNumberOfElements, tempNumElems;
+  UDATA freeLocation, *oldFreeLocation;
+  HyPool *newHandle;
+
+  if (minNumberElements == 0)
+    {
+      minNumberElements = 1;
+    }
+
+  if (elementAlignment == 0)
+    {
+      elementAlignment = MIN_GRANULARITY;
+    }
+
+  roundedStructSize = ROUND_TO (elementAlignment, structSize);
+
+  tempAllocSize = roundedStructSize * minNumberElements
+    + ROUND_TO (elementAlignment, sizeof (HyPool))
+    + (elementAlignment - MALLOC_ALIGNMENT);
+  finalAllocSize = ROUND_TO (OS_PAGE_SIZE, tempAllocSize);
+  finalNumberOfElements = minNumberElements;
+  finalNumberOfElements +=
+    (finalAllocSize - tempAllocSize) / roundedStructSize;
+
+  /* 
+   * finalAllocSize is a U_64 so that we can detect pool sizes which overflow 32-bits. 
+   */
+  if (finalAllocSize > (U_64) 0xFFFFFFFF)
+    {
+      return NULL;
+    }
+
+  newHandle = memAlloc (userData, (UDATA) finalAllocSize);
+
+  if (newHandle)
+    {
+      memset ((void *) newHandle, 0, (size_t) finalAllocSize);
+      newHandle->elementSize = roundedStructSize;
+      newHandle->alignment = (U_16) elementAlignment;   /* we assume no alignment is > 64k */
+      newHandle->flags = poolFlags | POOL_SORTED;       /* list starts sorted */
+      newHandle->numberOfElements = finalNumberOfElements;
+      newHandle->usedElements = 0;
+      newHandle->firstElementAddress = (void *) ROUND_TO (elementAlignment,
+                                                          ((UDATA) newHandle)
+                                                          + sizeof (HyPool));
+      newHandle->firstFreeSlot = (UDATA *) newHandle->firstElementAddress;
+      newHandle->activePuddle = newHandle;
+      newHandle->nextPool = NULL;
+      newHandle->memAlloc = memAlloc;
+      newHandle->memFree = memFree;
+      newHandle->userData = userData;
+
+      /* now stuff the free list pointers in */
+      freeLocation = (UDATA) newHandle->firstElementAddress;
+      tempNumElems = newHandle->numberOfElements;
+      while (tempNumElems--)
+        {
+          oldFreeLocation = (UDATA *) freeLocation;
+          freeLocation += roundedStructSize;
+          *oldFreeLocation = freeLocation;
+        }
+      *oldFreeLocation = 0;     /* end of list */
+    }
+  return newHandle;
+}
+
+/**
+ *	Deallocates all memory associated with a pool.
+ *
+ * @param[in] aPool Pool to be deallocated
+ *
+ * @return none
+ *
+*/
+void VMCALL
+pool_kill (HyPool * aPool)
+{
+  HyPool *tmpPool;
+
+  while (aPool)
+    {
+      tmpPool = aPool;
+      aPool = aPool->nextPool;
+      tmpPool->memFree (tmpPool->userData, tmpPool);
+    }
+}
+
+/**
+ *	Asks for the address of a new pool element.
+ *	If it succeeds, the address returned will have space for
+ *	one element of the correct structure size.
+ *	The contents of the element are undefined.
+ *	If the current pool is full, a new one will be grafted onto the
+ *	end of the pool chain and memory from there will be used.
+ *
+ * @param[in] aPool
+ *
+ * @return NULL on error
+ * @return pointer to a new element otherwise
+ *
+*/
+void *VMCALL
+pool_newElement (HyPool * aPool)
+{
+  void *newElement = NULL;
+  BOOLEAN searchedActive = FALSE;
+  HyPool *head = aPool;
+
+  aPool = head->activePuddle;   /* peek at current active puddle */
+  while (aPool)
+    {
+      if (aPool->firstFreeSlot != NULL)
+        {
+          newElement = aPool->firstFreeSlot;
+          aPool->firstFreeSlot = (UDATA *) * ((UDATA *) newElement);
+          aPool->usedElements += 1;
+          /* if we were sorted before getting the new element, the free list is still in order afterwards.  If not,
+             it's unlikely to have become sorted.  Thus, the POOL_SORTED bit should only be flipped in
+             pool_removeElement. */
+          head->activePuddle = aPool;   /* sets to most recently active puddle */
+          break;
+        }
+      else if (!searchedActive)
+        {                       /* allocate a new pool to flow into */
+          searchedActive = TRUE;
+          aPool = head;         /* no space in active puddle - walk the chain from the head */
+        }
+      else
+        {
+          if (aPool->nextPool)
+            {
+              aPool = aPool->nextPool;
+            }
+          else
+            {
+              aPool->nextPool =
+                pool_new (aPool->elementSize, aPool->numberOfElements,
+                          aPool->alignment, aPool->flags, aPool->memAlloc,
+                          aPool->memFree, aPool->userData);
+              if (!(aPool->nextPool))
+                return NULL;
+              aPool = aPool->nextPool;  /* let the next iteration do the address calc. */
+            }
+        }
+    }
+  return newElement;
+}
+
+/**
+ *	Deallocates an element from a pool
+ *
+ * It is safe to call pool_removeElement() while looping over
+ * the pool with @ref pool_startDo / @ref pool_nextDo on the element 
+ * returned by those calls.  This is because the free element
+ * is always inserted at either the head of the free list or 
+ * before the nextFree element in the pool_state.
+ *
+ * @param[in] aPool
+ * @param[in] anElement Pointer to the element to be removed
+ *
+ * @return none
+ *
+*/
+void VMCALL
+pool_removeElement (HyPool * aPool, void *anElement)
+{
+  UDATA tempHead, tmp2;
+  BOOLEAN foundPool = FALSE;
+  BOOLEAN searchedActive = FALSE;
+  HyPool *oldPool = aPool;
+  HyPool *head = aPool;
+
+  if (!aPool)
+    return;
+
+  /* Peek at active puddle first. If not suitable, walk whole chain. */
+  aPool = head->activePuddle;
+  do
+    {
+      tmp2 =
+        (UDATA) aPool->firstElementAddress +
+        aPool->elementSize * aPool->numberOfElements;
+      if (((UDATA) anElement < tmp2) && ((UDATA) anElement > (UDATA) aPool))
+        {
+
+          /* If we've already walked the chain, FOUND. If we're peeking at the active puddle
+             and there's only one element left, walk the chain from the start. */
+          if (searchedActive
+              || (!searchedActive
+                  && (aPool == head || aPool->usedElements > 1)))
+            {
+              foundPool = TRUE;
+              break;            /* this is the right pool */
+            }
+        }
+      if (!searchedActive)
+        {
+          searchedActive = TRUE;
+          aPool = head;         /* start from the beginning */
+        }
+      else
+        {
+          oldPool = aPool;
+          aPool = aPool->nextPool;
+        }
+    }
+  while (aPool);
+
+  if (!foundPool)
+    return;                     /* this is an error...  we were passed an invalid data pointer. */
+
+  head->activePuddle = aPool;   /* set this pool to the active pool */
+
+  /* we delete from the list differently, depending on if we want to preserve sort order */
+  if (aPool->flags & POOL_ALWAYS_KEEP_SORTED)
+    {
+      /*      in this case, we walk the free list, looking for where to insert the newly freed item. */
+      UDATA *lastElem = (UDATA *) & (aPool->firstFreeSlot);
+      UDATA *current = (UDATA *) aPool->firstFreeSlot;
+      while (current && (UDATA) current < (UDATA) anElement)
+        {
+          lastElem = current;
+          current = (UDATA *) * current;
+        }
+      *((UDATA *) anElement) = (UDATA) current;
+      *lastElem = (UDATA) anElement;
+      aPool->usedElements -= 1;
+    }
+  else
+    {
+      tempHead = (UDATA) aPool->firstFreeSlot;
+      aPool->firstFreeSlot = (UDATA *) anElement;
+      *((UDATA *) anElement) = tempHead;
+      aPool->usedElements -= 1;
+      aPool->flags &= ~POOL_SORTED;     /* reset sorted flag */
+    }
+
+  if ((oldPool != aPool) && (aPool->usedElements == 0)
+      && !(aPool->flags & POOL_NEVER_FREE_PUDDLES))
+    {
+      oldPool->nextPool = aPool->nextPool;
+      head->activePuddle = oldPool;
+      aPool->memFree (aPool->userData, aPool);
+    }
+}
+
+/**	
+ *	Calls a user provided function for each element in the list.
+ *
+ * @param[in] aPool The pool to "do" things to
+ * @param[in] aFunction Pointer to function which will "do" things to the elements of aPool
+ * @param[in] userData Pointer to data to be passed to "do" function, along with each pool-element
+ *
+ * @return none
+ *
+ * @see pool_startDo, pool_nextDo
+ *
+ */
+void VMCALL
+pool_do (HyPool * aPool, void (*aFunction) (void *anElement, void *userData),
+         void *userData)
+{
+  void *anElement;
+  pool_state aState;
+  anElement = pool_startDo (aPool, &aState);
+
+  while (anElement)
+    {
+      (aFunction) (anElement, userData);
+      anElement = pool_nextDo (&aState);
+    }
+}
+
+/**
+ *	Returns the number of elements in a given pool.
+ *
+ * @param[in] aPool
+ *
+ * @return 0 on error
+ * @return the number of elements in the pool otherwise
+ *
+*/
+UDATA VMCALL
+pool_numElements (HyPool * aPool)
+{
+  UDATA numElements = 0;
+
+  while (aPool)
+    {
+      numElements += aPool->usedElements;
+      aPool = aPool->nextPool;
+    }
+  return numElements;
+}
+
+/**
+ *	Start of an iteration set that will return when code is to be executed.
+ *	This is based strongly on pool_sortFreeAndIterateUsed.
+ *	Pass in a pointer to an empty pool_state and it will be filled in.
+ *
+ * @param[in] aPool The pool to "do" things to
+ * @param[in] lastHandle 
+ *
+ * @return NULL
+ * @return pointer to element otherwise
+ *
+ * @see pool_do, pool_nextDo
+ *
+ */
+void *VMCALL
+pool_startDo (HyPool * aPool, pool_state * lastHandle)
+{
+  UDATA tmpInc;
+  UDATA *currAddr, **nextFreeAddr;
+
+  if (!aPool)
+    return NULL;
+
+  if (!(aPool->flags & POOL_SORTED))
+    {                           /* sort if not pure */
+      pool_sortFree (aPool);
+    }
+
+  if (0 == aPool->usedElements)
+    {                           /* this pool is empty */
+      if (aPool->nextPool)
+        {
+          return pool_startDo (aPool->nextPool, lastHandle);
+        }
+      else
+        {
+          return NULL;          /* totally empty */
+        }
+    }
+
+  /* walk, iterating. */
+  tmpInc = aPool->elementSize;
+  currAddr = (UDATA *) aPool->firstElementAddress;
+  nextFreeAddr = (UDATA **) aPool->firstFreeSlot;
+
+  while (currAddr == (UDATA *) nextFreeAddr)
+    {
+      nextFreeAddr = (UDATA **) * nextFreeAddr;
+      currAddr = (UDATA *) ((U_8 *) currAddr + tmpInc);
+    }
+
+  lastHandle->currPool = aPool;
+  lastHandle->nextFree = nextFreeAddr;
+  lastHandle->lastAddr = (UDATA *) ((U_8 *) currAddr + tmpInc); /* set up for next time in. */
+  lastHandle->leftToDo = aPool->usedElements - 1;
+  return (void *) currAddr;
+}
+
+/**
+ *	Continue an iteration based on state passed in by lastHandle.
+ *	It is safe to stop an iteration midway through.
+ *
+ * @param[in] lastHandle pointer for current iteration state
+ *
+ * @return NULL nothing more to be done
+ * @return pointer to next element to be processed otherwise
+ *
+ * @see pool_do, pool_startDo
+ *
+ */
+void *VMCALL
+pool_nextDo (pool_state * lastHandle)
+{
+  UDATA tmpInc;
+  UDATA *currAddr, **nextFreeAddr;
+
+  if (lastHandle->leftToDo == 0)
+    {                           /* no more used elements, stop this pool. */
+      if (lastHandle->currPool->nextPool)       /* check the next one. */
+        return pool_startDo (lastHandle->currPool->nextPool, lastHandle);
+      else
+        return NULL;
+    }
+
+  /* there's at least one more used element */
+
+  currAddr = lastHandle->lastAddr;
+  nextFreeAddr = lastHandle->nextFree;
+  tmpInc = lastHandle->currPool->elementSize;
+
+  /* walk, iterating. */
+  while (currAddr == (UDATA *) nextFreeAddr)
+    {
+      nextFreeAddr = (UDATA **) * nextFreeAddr;
+      currAddr = (UDATA *) ((U_8 *) currAddr + tmpInc);
+    }
+
+  lastHandle->nextFree = nextFreeAddr;
+  lastHandle->lastAddr = (UDATA *) ((U_8 *) currAddr + tmpInc); /* set up for next time in. */
+  lastHandle->leftToDo -= 1;
+
+  return (void *) currAddr;
+}
+
+/**
+ *	Sorts the free list of the current pool.
+ *	(ie: does not follow nextPool pointers...)
+ *	This is a O(n) most of the time.
+ *
+ * @param[in] aPool The pool to be sorted
+ *
+ * @return none
+ *
+ */
+void VMCALL
+pool_sortFree (HyPool * aPool)
+{
+  BOOLEAN done = FALSE, conflict;
+  UDATA *currAddr, *tmpAddr, **nextFreeAddr;
+  UDATA tmpInc, x, numElements;
+  U_32 flagVal = 0xDEADBEEE;
+
+  tmpInc = aPool->elementSize;
+  numElements = aPool->numberOfElements;
+
+  currAddr = (UDATA *) aPool->firstElementAddress;
+  while (!done)
+    {
+      conflict = FALSE;
+      for (x = 0; x < numElements; x++)
+        {
+          if (*currAddr == flagVal)
+            {
+              conflict = TRUE;
+              flagVal -= 1;
+              break;
+            }
+          currAddr = (UDATA *) ((U_8 *) currAddr + tmpInc);
+        }
+      if (!conflict)
+        {
+          done = TRUE;
+        }
+    }
+  /* now walk, slamming pointers as I go */
+  currAddr = aPool->firstFreeSlot;
+  while (currAddr)
+    {
+      tmpAddr = (UDATA *) * currAddr;
+      *currAddr = flagVal;
+      currAddr = tmpAddr;
+    }
+  /* walk, fixing pointers and iterating. */
+  currAddr = (UDATA *) aPool->firstElementAddress;
+  nextFreeAddr = (UDATA **) & (aPool->firstFreeSlot);
+
+  for (x = 0; x < numElements; x++)
+    {
+      if (*currAddr == flagVal)
+        {                       /* add to free list being built */
+          *nextFreeAddr = currAddr;
+          nextFreeAddr = (UDATA **) currAddr;
+        }
+      currAddr = (UDATA *) ((U_8 *) currAddr + tmpInc);
+    }
+  *nextFreeAddr = NULL;         /* end the free list cleanly */
+  aPool->flags |= POOL_SORTED;  /* set sorted flag */
+}
+
+/**
+ *	Shortcut for @ref pool_new, using the default malloc/free from the portLibrary
+ *
+ * @param[in] structSize size of pool-element
+ * @param[in] portLibrary
+ *
+ * @return pointer to a Pool
+ *
+ * @see pool_new
+ *
+*/
+HyPool *VMCALL
+pool_forPortLib (U_32 structSize, HyPortLibrary * portLibrary)
+{
+  return pool_new (structSize, 0, 0, 0, POOL_FOR_PORT (portLibrary));
+}
+
+/**
+ * Clear the contents of a pool but not delete it
+ *
+ * @note Make no assumptions about the contents of the pool after invoking this method (it currently does not zero the memory)
+ *
+ * @param[in] aPool The pool to clear
+ *
+ * @return none
+ *
+*/
+
+void VMCALL
+pool_clear (HyPool * aPool)
+{
+  while (aPool)
+    {
+      UDATA freeLocation, *oldFreeLocation;
+      U_32 tempNumElems;
+
+      aPool->usedElements = 0;
+      aPool->firstElementAddress =
+        (void *) ROUND_TO (aPool->alignment,
+                           ((UDATA) aPool) + sizeof (HyPool));
+      aPool->firstFreeSlot = (UDATA *) aPool->firstElementAddress;
+      freeLocation = (UDATA) aPool->firstElementAddress;
+      tempNumElems = aPool->numberOfElements;
+      while (tempNumElems--)
+        {
+          oldFreeLocation = (UDATA *) freeLocation;
+          freeLocation += aPool->elementSize;
+          *oldFreeLocation = freeLocation;
+        }
+      *oldFreeLocation = 0;     /* end of list */
+      aPool->flags |= POOL_SORTED;      /* an empty list is sorted */
+      aPool = aPool->nextPool;
+    }
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/pool/pool_cap.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/pool/pool_cap.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/pool/pool_cap.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/pool/pool_cap.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,107 @@
+/* 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 Pool
+ * @brief Pool-capacity functions
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "hypool.h"
+
+#define ROUND_TO(granularity, number) ( (((number) % (granularity)) ? ((number) + (granularity) - ((number) % (granularity))) : (number)))
+
+#define MIN_GRANULARITY		sizeof(UDATA)
+
+#define MALLOC_ALIGNMENT sizeof(UDATA)
+
+/* read this if a port library call becomes available that gives out the OS page size */
+#if 0
+#define OS_PAGE_SIZE		(EsGetAddressSpacePageSize())
+#else
+
+#define OS_PAGE_SIZE		4096
+#endif
+
+/**
+ * Ensures that the pool is large enough for newCapacity elements.
+ * This has the side effect of setting the POOL_NEVER_FREE_PUDDLES flag.
+ * Without this, the pool could shrink back down to its original size.
+ * Note that this does not take into account the number of elements already
+ * used in the pool.
+ *
+ * @param[in] aPool The pool
+ * @param[in] newCapacity The desired new-size of the pool
+ *
+ * @return 0 on success
+ * @return -1 on failure
+ * 
+ */
+UDATA VMCALL
+pool_ensureCapacity (HyPool * aPool, UDATA newCapacity)
+{
+  UDATA numElements = pool_capacity (aPool);
+
+  /* find the last pool and mark each pool as POOL_NEVER_FREE_PUDDLES */
+  for (;;)
+    {
+      aPool->flags |= POOL_NEVER_FREE_PUDDLES;
+      if (aPool->nextPool == NULL)
+        break;
+      aPool = aPool->nextPool;
+    }
+
+  if (newCapacity > numElements)
+    {
+      UDATA newSize = newCapacity - numElements;
+      if (newSize < aPool->numberOfElements)
+        {
+          newSize = aPool->numberOfElements;
+        }
+
+      aPool->nextPool =
+        pool_new (aPool->elementSize, newSize, aPool->alignment, aPool->flags,
+                  aPool->memAlloc, aPool->memFree, aPool->userData);
+      if (aPool->nextPool == NULL)
+        return -1;
+    }
+
+  return 0;
+}
+
+/**
+ * Returns the total capacity of a pool
+ *
+ * @param[in] aPool The pool
+ *
+ * @return 0 on error
+ * @return numElements in aPool otherwise
+ *
+ */
+UDATA VMCALL
+pool_capacity (HyPool * aPool)
+{
+  UDATA numElements = 0;
+  while (aPool)
+    {
+      numElements += aPool->numberOfElements;
+      aPool = aPool->nextPool;
+    }
+  return numElements;
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/DoxygenSupport.txt
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/DoxygenSupport.txt?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/DoxygenSupport.txt (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/DoxygenSupport.txt Wed Nov 30 21:29:27 2005
@@ -0,0 +1,163 @@
+/* Copyright 2004 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.
+ */
+
+/*
+ * This file provides the group definitions required to create the Doxygen generated
+ * output for compounds.  There is one group per directory (port, pool, thread, etc.).
+ */
+ 
+/**
+ * @defgroup Port Port
+ *
+@section Part1 Introduction
+
+The port library interacts with the native operating system to provide the Java virtual machine a platform independent 
+interface to operating system functionality.  Functionality such as file, socket and memory operations are incorporated 
+in the port library.  By utilizing the port library the Java virtual machine isolates all platform specific knowledge to one area, 
+thus allowing for rapid development of new platforms while promoting a large common code base between these platforms.
+
+The port library is implemented as a table of function pointers.  One advantage of a function pointer based table is the ability 
+to replace any functionality without recompiling the entire Java virtual machine.  For example if an application is experiencing
+a memory leak, the memory management functions of the port library can be replaced to help determine the root cause of this
+leak. Alternatively applications wishing to control all memory allocation can provide their own routines to override the platform
+specific allocation and deallocation of memory.
+
+Various implementations of the port library may choose not to implement all functionality contained in the port library table. 
+If a platform does not support sockets, and thus the Java virtual machine does not utilize sockets, the port library does not need
+to provide a valid socket behavior.  The port library contains @ref PortVersionControl "version control information" that enables applications 
+to determine if required functionality is supported.  In addition the version control information allows applications to determine if the 
+port library provided is compatible with the one which they were compiled against.
+
+
+@section CreatePortLib Creating a port library
+
+The port library is either allocated on the stack or allocated in a memory space via platform specific operations such as malloc.
+Since the size of the area allocated is dependent on the size of the structure compiled against, the port library provides 
+@ref PortVersionControl "version control information"  that applications use to request the 
+specific version they compiled against.  Backward compatibility between versions of the port library is maintained where possible,
+but the application must ensure they check this compatibility prior to invoking any port library functionality.  Failure to do so could
+result in catastrophic failure as application code accesses random port library functionality.
+
+Applications may use the port library with no modifications as follows.  In this example a port library is declared on the stack.
+Of course, the stack allocated data must remain valid for the duration of the port library usage. All utility functions and data
+structures related to the port library are defined in the header file @ref hyport.h "hyport.h".
+
+@code
+{
+    int rc;
+    HyPortLibrary hyportLibrary;
+    HyPortLibraryVersion portLibraryVersion;
+
+    // Use portlibrary version which we compiled against, and have allocated space
+    // for on the stack.  This version may be different from the one in the linked DLL.
+    HYPORT_SET_VERSION(&portLibraryVersion, HYPORT_CAPABILITY_MASK);
+
+    // Initialize and start the port library 
+    rc = hyport_init_library(&hyportLibrary, &portLibraryVersion, sizeof(HyPortLibrary));
+    if (0 != rc) {
+        // handle error condition
+    }
+
+    ...
+}
+@endcode
+
+Applications wishing to override port library functionality can do so by first allocating the port library table, then initializing it with
+the default values. They can then override specific function pointers as required and then finally start the port library.
+
+@code
+{
+    int rc;
+    HyPortLibrary hyportLibrary;
+    HyPortLibraryVersion portLibraryVersion;
+
+    // Use portlibrary version which we compiled against, and have allocated space
+    // for on the stack.  This version may be different from the one in the linked DLL.
+    HYPORT_SET_VERSION(&portLibraryVersion, HYPORT_CAPABILITY_MASK);
+
+    // Initializes the port library with the default functions for the specified version 
+    rc = hyport_create_library(hyportLibrary, &portLibraryVersion, sizeof(HyPortLibrary));
+    if (0 != rc) {
+        // handle error condition
+    }
+
+    // override the file_write operation, store the old one so we can restore it later 
+    old_write = hyportLibrary->file_write;
+    hyportLibrary->file_write = dbg_write;
+
+    // Now start the port library 
+    rc = hyport_startup_library(hyportLibrary);
+    if (0 != rc) {
+        // handle error condition
+    }
+}
+@endcode
+
+If the application wishes to dynamically allocate memory for the port library they need to first determine the size required.
+@code
+{
+    int rc;
+    int hyportLibrarySize;
+    HyPortLibrary* hyportLibrary;
+    HyPortLibraryVersion portLibraryVersion;
+
+    // Use portlibrary version which we compiled against, and have allocated space
+    // for on the stack.  This version may be different from the one in the linked DLL.
+    HYPORT_SET_VERSION(&portLibraryVersion, HYPORT_CAPABILITY_MASK);
+
+    // Allocate space for the port library 
+    hyportLibrarySize = (int) hyport_getsize(&portLibraryVersion);
+    if (0 == hyportLibrarySize) {
+        // handle error condition
+    }
+
+    hyportLibrary = (HyPortLibrary*)malloc(hyportLibrarySize);
+    if (NULL == hyportLibrary) {
+        // handle error condition
+    }
+
+    // Initialize and start the port library 
+    rc = hyport_init_library(hyportLibrary, &portLibraryVersion, hyportLibrarySize);
+    if (0 != rc) {
+        // handle error condition
+    }
+
+    ...
+}
+@endcode
+Functions are also provided to determine @ref PortVersionControl "compatibility" with a running port library, as well as determine 
+the version of a running port library.
+
+
+@section UsePortLib Using the port library
+
+Access to the port library can either be by directly reaching into the port library table, or by using macros to access 
+port library functionality.
+
+@code
+void *internalAllocateMemory(JNIEnv *jniEnv)
+{
+    PORT_ACCESS_FROM_ENV(jniEnv);
+    return hymem_allocate_memory(1024);
+}
+
+void *internalAllocateMemory(HyPortLibrary *portLibrary)
+{
+    return portLibrary->mem_allocate_memory(portLibrary, 1024);
+}
+@endcode
+ */
+
+

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hycpu.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hycpu.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hycpu.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hycpu.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,187 @@
+/* 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 CPU Control.
+ *
+ * Functions setting CPU attributes.
+ */
+
+#undef CDEV_CURRENT_FUNCTION
+
+#include <stdlib.h>
+#if defined(LINUXPPC) || defined(PPC)
+#include <string.h>
+#endif
+
+
+#include "hyport.h"
+#if defined(LINUXPPC) || defined(PPC)
+#include "portpriv.h"
+#include "hyportpg.h"
+#endif
+
+
+#if (__IBMC__||__IBMCPP__)
+void dcbf (unsigned char *);
+void icbi (unsigned char *);
+void sync (void);
+void isync (void);
+void dcbz (void *);
+#pragma mc_func dcbf  {"7c0018ac"}
+#pragma mc_func icbi  {"7c001fac"}
+#pragma mc_func sync  {"7c0004ac"}
+#pragma mc_func isync {"4c00012c"}
+#pragma mc_func dcbz {"7c001fec"}
+#pragma reg_killed_by dcbf
+#pragma reg_killed_by dcbz
+#pragma reg_killed_by icbi
+#pragma reg_killed_by sync
+#pragma reg_killed_by isync
+#endif
+
+
+#define CDEV_CURRENT_FUNCTION hycpu_startup
+/**
+ * PortLibrary startup.
+ *
+ * This function is called during startup of the portLibrary.  Any resources that are required for
+ * the exit operations may be created here.  All resources created here should be destroyed
+ * in @ref hycpu_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_CPU
+ *
+ * @note Most implementations will simply return success.
+ */
+I_32 VMCALL
+hycpu_startup (struct HyPortLibrary *portLibrary)
+{
+  /* initialize the ppc level 1 cache line size */
+#if defined(LINUXPPC) || defined(PPC)
+  int ppcCacheLineSize;
+  int i;
+  int input1 = 20;
+  char buf[1024];
+  memset (buf, 255, 1024);
+#if (__IBMC__||__IBMCPP__)
+  dcbz ((void *) &buf[512]);
+#elif defined(LINUX)
+__asm__ ("dcbz 0, %0":         /* no outputs */
+:"r" ((void *) &buf[512]));
+#endif
+for (i = 0, ppcCacheLineSize = 0; i < 1024; i++)
+    {
+      if (buf[i] == 0)
+        {
+          ppcCacheLineSize++;
+        }
+    }
+  PPG_mem_ppcCacheLineSize = ppcCacheLineSize;
+#endif
+
+
+  return 0;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hycpu_shutdown
+/**
+ * PortLibrary shutdown.
+ *
+ * This function is called during shutdown of the portLibrary.  Any resources that were created by @ref hycpu_startup
+ * should be destroyed here.
+ *
+ * @param[in] portLibrary The port library
+ *
+ * @note Most implementations will be empty.
+ */
+void VMCALL
+hycpu_shutdown (struct HyPortLibrary *portLibrary)
+{
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hycpu_flush_icache
+/**
+ * @brief CPU Control operations.
+ *
+ * Flush the instruction cache to memory.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] memoryPointer The base address of memory to flush.
+ * @param[in] byteAmount Number of bytes to flush.
+ */
+void VMCALL
+hycpu_flush_icache (struct HyPortLibrary *portLibrary, void *memoryPointer,
+                    UDATA byteAmount)
+{
+	
+#if defined(LINUX) && defined(ARMGNU)
+  privateFlushICache (memoryPointer, byteAmount);
+
+#elif defined (LINUXPPC) || defined (PPC)
+  int cacheLineSize = PPG_mem_ppcCacheLineSize;
+  unsigned char *addr;
+  unsigned char *limit;
+  limit =
+    (unsigned char
+     *) (((unsigned long) memoryPointer + (unsigned int) byteAmount +
+          (cacheLineSize - 1)) / cacheLineSize * cacheLineSize);
+  /* for each cache line, do a data cache block flush */
+  for (addr = (unsigned char *) memoryPointer; addr < limit;
+       addr += cacheLineSize)
+    {
+#if (__IBMC__||__IBMCPP__)
+      dcbf (addr);
+#elif defined(LINUX)
+    __asm__ ("dcbf 0,%0":      /* no outputs */
+    :"r" (addr));
+#endif
+}
+#if (__IBMC__||__IBMCPP__)
+  sync ();
+#elif defined(LINUX)
+  __asm__ ("sync");
+#endif
+/* for each cache line  do an icache block invalidate */
+  for (addr = (unsigned char *) memoryPointer; addr < limit;
+       addr += cacheLineSize)
+    {
+#if (__IBMC__||__IBMCPP__)
+      icbi (addr);
+#elif defined(LINUX)
+    __asm__ ("icbi 0,%0":      /* no outputs */
+    :"r" (addr));
+#endif
+}
+#if (__IBMC__||__IBMCPP__)
+  isync ();
+#elif defined(LINUX)
+  __asm__ ("isync");
+#endif
+#endif
+
+
+}
+
+#undef CDEV_CURRENT_FUNCTION

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyerror.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyerror.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyerror.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyerror.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,324 @@
+/* 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 Error Handling
+ *
+ * If an OS system call fails the error code reported by the OS needs to be saved for future reference.
+ * The OS error code as well as the corresponding portable error code are stored in the per thread
+ * buffers @ref hyportptb.h via a call the @ref hyerror_set_last_error or @ref hyerror_set_last_error_with_message.
+ * These functions are meant for private use by the port library, to set the error related to a system call failure.
+ * They are in the port library table as people overriding port library functions may need to set the error
+ * message accordingly.
+ *
+ * The majority of applications are not interested in the human readable error message corresponding to
+ * the error.  As a result the error message is not stored at time of the reported error, but can be looked
+ * up at a later time.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include "portpriv.h"
+#include "portnls.h"
+#include "hyportptb.h"
+
+static const char *
+swapMessageBuffer (PortlibPTBuffers_t ptBuffers, const char *message)
+{
+  char *tempBuffer = ptBuffers->reportedMessageBuffer;
+  U_32 tempBufferSize = ptBuffers->reportedMessageBufferSize;
+
+  if (message == NULL)
+    {
+      return "";
+    }
+
+  /* Can't swap unknown message buffer */
+  if (message != ptBuffers->errorMessageBuffer)
+    {
+      return message;
+    }
+
+  /* Save reported information */
+  ptBuffers->reportedErrorCode = ptBuffers->portableErrorCode;
+  ptBuffers->reportedMessageBuffer = ptBuffers->errorMessageBuffer;
+  ptBuffers->reportedMessageBufferSize = ptBuffers->errorMessageBufferSize;
+
+  if (tempBufferSize > 0)
+    {
+      tempBuffer[0] = '\0';
+    }
+
+  /* Clear pending fields ready for next error */
+  ptBuffers->portableErrorCode = 0;
+  ptBuffers->errorMessageBuffer = tempBuffer;
+  ptBuffers->errorMessageBufferSize = tempBufferSize;
+
+  return ptBuffers->reportedMessageBuffer;
+}
+
+/**
+ * PortLibrary startup.
+ *
+ * This function is called during startup of the portLibrary.  Any resources that are required for
+ * the error handling operations may be created here.  All resources created here should be destroyed
+ * in @ref hyerror_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_ERROR
+ *
+ * @note Most implementations will simply return success.
+ */
+I_32 VMCALL
+hyerror_startup (struct HyPortLibrary * portLibrary)
+{
+  return 0;
+}
+
+/**
+ * PortLibrary shutdown.
+ *
+ * This function is called during shutdown of the portLibrary.  Any resources that were created by @ref hyerror_startup
+ * should be destroyed here.
+ *
+ * @param[in] portLibrary The port library
+ *
+ * @note Most implementations will be empty.
+ */
+void VMCALL
+hyerror_shutdown (struct HyPortLibrary *portLibrary)
+{
+}
+
+/**
+ *  @brief Error Handling
+ *
+ * Return the error message as reported by the OS for the last saved error.
+ * If no error has been saved then an empty message is returned.
+ *
+ * @param[in] portLibrary The port library
+ *
+ * @return The error message for the last OS failure, empty message on failure.
+ */
+const char *VMCALL
+hyerror_last_error_message (struct HyPortLibrary *portLibrary)
+{
+  PortlibPTBuffers_t ptBuffers;
+
+  /* Was an error saved ? */
+  ptBuffers = hyport_tls_peek (portLibrary);
+  if (NULL == ptBuffers)
+    {
+      return "";
+    }
+
+  /* New error ? */
+  if (ptBuffers->portableErrorCode != 0)
+    {
+      const char *message = NULL;
+
+      /* Customized message stored ? */
+      if (ptBuffers->errorMessageBufferSize > 0)
+        {
+          if ('\0' != ptBuffers->errorMessageBuffer[0])
+            {
+              message = ptBuffers->errorMessageBuffer;
+            }
+        }
+
+      /* Call a helper to get the last message from the OS.  */
+      if (message == NULL)
+        {
+          message = errorMessage (portLibrary, ptBuffers->platformErrorCode);
+        }
+
+      /* Avoid overwrite by internal portlib errors */
+      return swapMessageBuffer (ptBuffers, message);
+    }
+
+  /* Previous message stored ? */
+  if (ptBuffers->reportedMessageBufferSize > 0)
+    {
+      if ('\0' != ptBuffers->reportedMessageBuffer[0])
+        {
+          return ptBuffers->reportedMessageBuffer;
+        }
+    }
+
+  /* No error.  */
+  return "";
+}
+
+/**
+ * @brief Error Handling
+ *
+ * Look up the reason for the last stored failure.  If no error code has been
+ * stored then failure is returned.
+ *
+ * @param[in] portLibrary The port library
+ *
+ * @return The negative portable error code on success, 0 on failure.
+ *
+ * @note Does not clear the reason for the last failure.
+ */
+I_32 VMCALL
+hyerror_last_error_number (struct HyPortLibrary * portLibrary)
+{
+  PortlibPTBuffers_t ptBuffers;
+
+  /* get the buffers, return failure if not present */
+  ptBuffers = hyport_tls_peek (portLibrary);
+  if (NULL == ptBuffers)
+    {
+      return 0;
+    }
+
+  /* New error ? */
+  if (ptBuffers->portableErrorCode != 0)
+    {
+      return ptBuffers->portableErrorCode;
+    }
+  else
+    {
+      return ptBuffers->reportedErrorCode;
+    }
+}
+
+/**
+ * @brief Error Handling
+ *
+ * Save the platform specific error code and the portable error code for future reference.  Once stored an 
+ * application may obtain the error message describing the last stored error by calling hyerror_last_error_message.  
+ * Likewise the last portable error code can be obtained by calling hyerror_last_error_number. 
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] platformCode The error code reported by the OS
+ * @param[in] portableCode The corresponding portable error code as determined by the caller
+ *
+ * @return portable error code
+ *
+ * @note There is no way to access the last platform specific error code.
+ *
+ * @note If per thread buffers @see hyportptb.h are not available the error code is not stored.
+ * This event would only occur if the per thread buffers could not be allocated, which is highly unlikely.  In this 
+ * case an application will receive a generic message/errorCode when querying for the last stored values.
+ */
+I_32 VMCALL
+hyerror_set_last_error (struct HyPortLibrary * portLibrary, I_32 platformCode,
+                        I_32 portableCode)
+{
+  PortlibPTBuffers_t ptBuffers;
+
+  /* get the buffers, allocate if necessary.
+   * Silently return if not present, what else would the caller do anyway? 
+   */
+  ptBuffers = hyport_tls_get (portLibrary);
+  if (NULL == ptBuffers)
+    {
+      return portableCode;
+    }
+
+  /* Save the last error */
+  ptBuffers->platformErrorCode = platformCode;
+  ptBuffers->portableErrorCode = portableCode;
+
+  /* Overwrite any customized messages stored */
+  if (ptBuffers->errorMessageBufferSize > 0)
+    {
+      ptBuffers->errorMessageBuffer[0] = '\0';
+    }
+
+  return portableCode;
+}
+
+/**
+ * @brief Error Handling
+ *
+ * Save the platform specific error code and the portable error code for future reference.  Once stored an 
+ * application may obtain the error message describing the last stored error by calling hyerror_last_error_message.  
+ * Likewise the last portable error code can be obtained by calling hyerror_last_error_number. 
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] portableCode The corresponding portable error code as determined by the caller
+ * @param[in] errorMessage The customized error message to be stored
+ *
+ * @return portable error code
+ *
+ * @note There is no way to access the last platform specific error code.
+ *
+ * @note If per thread buffers @see hyportptb.h are not available the error code is not stored.
+ * This event would only occur if the per thread buffers could not be allocated, which is highly unlikely.  In this 
+ * case an application will receive a generic message/errorCode when querying for the last stored values.
+ */
+I_32 VMCALL
+hyerror_set_last_error_with_message (struct HyPortLibrary * portLibrary,
+                                     I_32 portableCode,
+                                     const char *errorMessage)
+{
+  PortlibPTBuffers_t ptBuffers;
+  U_32 requiredSize;
+
+  /* get the buffers, allocate if necessary.
+   * Silently return if not present, what else would the caller do anyway? 
+   */
+  ptBuffers = hyport_tls_get (portLibrary);
+  if (NULL == ptBuffers)
+    {
+      return portableCode;
+    }
+
+  /* Save the last error */
+  ptBuffers->platformErrorCode = -1;
+  ptBuffers->portableErrorCode = portableCode;
+
+  /* Store the message, allocate a bigger buffer if required.  Keep the old buffer around
+   * just in case memory can not be allocated
+   */
+  requiredSize = strlen (errorMessage) + 1;
+  requiredSize =
+    requiredSize <
+    HYERROR_DEFAULT_BUFFER_SIZE ? HYERROR_DEFAULT_BUFFER_SIZE : requiredSize;
+  if (requiredSize > ptBuffers->errorMessageBufferSize)
+    {
+      char *newBuffer =
+        portLibrary->mem_allocate_memory (portLibrary, requiredSize);
+      if (NULL != newBuffer)
+        {
+          if (ptBuffers->errorMessageBuffer != NULL)
+            {
+              portLibrary->mem_free_memory (portLibrary,
+                                            ptBuffers->errorMessageBuffer);
+            }
+          ptBuffers->errorMessageBuffer = newBuffer;
+          ptBuffers->errorMessageBufferSize = requiredSize;
+        }
+    }
+
+  /* Save the message */
+  if (ptBuffers->errorMessageBufferSize > 0)
+    {
+      portLibrary->str_printf (portLibrary, ptBuffers->errorMessageBuffer,
+                               ptBuffers->errorMessageBufferSize,
+                               errorMessage);
+      ptBuffers->errorMessageBuffer[ptBuffers->errorMessageBufferSize - 1] =
+        '\0';
+    }
+
+  return portableCode;
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyerrorhelpers.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyerrorhelpers.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyerrorhelpers.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyerrorhelpers.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,78 @@
+/* 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 Error Handling
+ *
+ * Helper utilities for @ref hyerror.c.  This file reduces the amount of code duplication as formatting of messages
+ * from the OS is the only part of error handling that can not be handled in a generic manner.
+ *
+ * These functions are not accessible via the port library function table.
+ */
+
+#undef CDEV_CURRENT_FUNCTION
+
+#include <string.h>
+#include <errno.h>
+#include "portpriv.h"
+#include "hyportptb.h"
+
+#define CDEV_CURRENT_FUNCTION errorMessage
+/**
+ * @internal
+ * @brief Error Handling
+ *
+ * Given an error code save the OS error message to the ptBuffers and return
+ * a reference to the saved message.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] errorCode The platform specific error code to look up.
+ *
+ * @note By the time this function is called it is known that ptBuffers are not NULL.  It is possible, however, that the
+ * buffer to hold the error message has not yet been allocated..
+ *
+ * @note Buffer is managed by the port library, do not free
+ */
+const char *VMCALL
+errorMessage (struct HyPortLibrary *portLibrary, I_32 errorCode)
+{
+  PortlibPTBuffers_t ptBuffers;
+
+  ptBuffers = hyport_tls_peek (portLibrary);
+  if (0 == ptBuffers->errorMessageBufferSize)
+    {
+      ptBuffers->errorMessageBuffer =
+        portLibrary->mem_allocate_memory (portLibrary,
+                                          HYERROR_DEFAULT_BUFFER_SIZE);
+      if (NULL == ptBuffers->errorMessageBuffer)
+        {
+          return "";
+        }
+      ptBuffers->errorMessageBufferSize = HYERROR_DEFAULT_BUFFER_SIZE;
+    }
+
+  /* Copy from OS to ptBuffers */
+  portLibrary->str_printf (portLibrary, ptBuffers->errorMessageBuffer,
+                           ptBuffers->errorMessageBufferSize,
+                           strerror (errorCode));
+  ptBuffers->errorMessageBuffer[ptBuffers->errorMessageBufferSize - 1] = '\0';
+  return ptBuffers->errorMessageBuffer;
+}
+
+#undef CDEV_CURRENT_FUNCTION

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyexit.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyexit.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyexit.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyexit.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,96 @@
+/* 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 Process shutdown.
+ */
+#include <stdlib.h>
+
+#include "hyport.h"
+
+extern void VMCALL hysig_chain_at_shutdown_and_exit (struct HyPortLibrary
+                                                     *portLibrary);
+
+/**
+ * Block until the portlibary has been exited and return the error code.
+ *
+ * @param[in] portLibrary The port library
+ *
+ * @return exit code.
+ * @note Most implementations will be empty.
+ */
+I_32 VMCALL
+hyexit_get_exit_code (struct HyPortLibrary *portLibrary)
+{
+  return 0;
+}
+
+/**
+ * Terminate a process.
+ *
+ * Perform any shutdown which is absolutely necessary before terminating the process,
+ * and terminate the process.  Unblock any callers to @ref hyexit_get_exit_code
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] exitCode The exit code to be used to terminate the process.
+ */
+void VMCALL
+hyexit_shutdown_and_exit (struct HyPortLibrary *portLibrary, I_32 exitCode)
+{
+
+#if !defined(WIN32)
+  hysig_chain_at_shutdown_and_exit (portLibrary);
+#endif
+
+
+  exit ((int) exitCode);
+}
+
+/**
+ * PortLibrary shutdown.
+ *
+ * This function is called during shutdown of the portLibrary.  Any resources that were created by @ref hyexit_startup
+ * should be destroyed here.
+ *
+ * @param[in] portLibrary The port library
+ *
+ * @note Most implementations will be empty.
+ */
+void VMCALL
+hyexit_shutdown (struct HyPortLibrary *portLibrary)
+{
+}
+
+/**
+ * PortLibrary startup.
+ *
+ * This function is called during startup of the portLibrary.  Any resources that are required for
+ * the exit operations may be created here.  All resources created here should be destroyed
+ * in @ref hyexit_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_EXIT
+ *
+ * @note Most implementations will simply return success.
+ */
+I_32 VMCALL
+hyexit_startup (struct HyPortLibrary *portLibrary)
+{
+  return 0;
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyfile.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyfile.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyfile.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/port/hyfile.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,826 @@
+/* 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 file
+ */
+
+#undef CDEV_CURRENT_FUNCTION
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <time.h>
+
+#include "hyport.h"
+#include "portsock.h"
+#include "hystdarg.h"
+#include "portnls.h"
+#include "ut_hyprt.h"
+
+#define CDEV_CURRENT_FUNCTION _prototypes_private
+static I_32 EsTranslateOpenFlags (I_32 flags);
+static I_32 findError (I_32 errorCode);
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION EsTranslateOpenFlags
+static I_32
+EsTranslateOpenFlags (I_32 flags)
+{
+  I_32 realFlags = 0;
+
+  if (flags & HyOpenAppend)
+    {
+      realFlags |= O_APPEND;
+    }
+  if (flags & HyOpenTruncate)
+    {
+      realFlags |= O_TRUNC;
+    }
+  if (flags & HyOpenCreate)
+    {
+      realFlags |= O_CREAT;
+    }
+  if (flags & HyOpenCreateNew)
+    {
+      realFlags |= O_EXCL | O_CREAT;
+    }
+  if (flags & HyOpenRead)
+    {
+      if (flags & HyOpenWrite)
+        {
+          return (O_RDWR | realFlags);
+        }
+      return (O_RDONLY | realFlags);
+    }
+  if (flags & HyOpenWrite)
+    {
+      return (O_WRONLY | realFlags);
+    }
+  return -1;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION findError
+/**
+ * @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 (I_32 errorCode)
+{
+  switch (errorCode)
+    {
+    case EACCES:
+    case EPERM:
+      return HYPORT_ERROR_FILE_NOPERMISSION;
+    case ENAMETOOLONG:
+      return HYPORT_ERROR_FILE_NAMETOOLONG;
+    case ENOENT:
+      return HYPORT_ERROR_FILE_NOENT;
+    case ENOTDIR:
+      return HYPORT_ERROR_FILE_NOTDIR;
+    case ELOOP:
+      return HYPORT_ERROR_FILE_LOOP;
+
+    case EBADF:
+      return HYPORT_ERROR_FILE_BADF;
+    case EEXIST:
+      return HYPORT_ERROR_FILE_EXIST;
+    case ENOSPC:
+    case EFBIG:
+      return HYPORT_ERROR_FILE_DISKFULL;
+    default:
+      return HYPORT_ERROR_FILE_OPFAILED;
+    }
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_close
+/**
+ * Closes a file descriptor.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] fd The file descriptor.
+ *
+ * @return 0 on success, -1 on failure.
+ * @internal @todo return negative portable return code on failure.
+ */
+I_32 VMCALL
+hyfile_close (struct HyPortLibrary * portLibrary, IDATA fd)
+{
+  return close ((int) fd);
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_open
+/**
+ * Convert a pathname into a file descriptor.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] path Name of the file to be opened.
+ * @param[in] flags Portable file read/write attributes.
+ * @param[in] mode Platform file permissions.
+ *
+ * @return The file descriptor of the newly opened file, -1 on failure.
+ */
+IDATA VMCALL
+hyfile_open (struct HyPortLibrary *portLibrary, const char *path, I_32 flags,
+             I_32 mode)
+{
+  struct stat buffer;
+  I_32 fd;
+  I_32 realFlags = EsTranslateOpenFlags (flags);
+  I_32 fdflags;
+
+  Trc_PRT_file_open_Entry (path, flags, mode);
+
+  if (realFlags == -1)
+    {
+      Trc_PRT_file_open_Exit1 (flags);
+      portLibrary->error_set_last_error (portLibrary, EINVAL,
+                                         findError (EINVAL));
+      return -1;
+    }
+
+  /* Neutrino does not handle NULL for stat */
+
+  if (!stat (path, &buffer))
+    {
+      if (S_ISDIR (buffer.st_mode))
+        {
+          Trc_PRT_file_open_Exit4 ();
+          return -1;
+        }
+    }
+
+  fd = open (path, realFlags, mode);
+
+  if (-1 == fd)
+    {
+      Trc_PRT_file_open_Exit2 (errno, findError (errno));
+      portLibrary->error_set_last_error (portLibrary, errno,
+                                         findError (errno));
+      return -1;
+    }
+
+  /* Tag this descriptor as being non-inheritable */
+  fdflags = fcntl (fd, F_GETFD, 0);
+  fcntl (fd, F_SETFD, fdflags | FD_CLOEXEC);
+
+  Trc_PRT_file_open_Exit (fd);
+  return (IDATA) fd;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_unlink
+/**
+ * Remove a file from the file system.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] path file/path name to remove.
+ *
+ * @return 0 on success, -1 on failure.
+ * @internal @todo return negative portable return code on failure.
+ */
+I_32 VMCALL
+hyfile_unlink (struct HyPortLibrary * portLibrary, const char *path)
+{
+  return unlink (path);
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_write
+/**
+ * Write to a file.
+ *
+ * Writes up to nbytes from the provided buffer  to the file referenced by the file descriptor.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] fd File descriptor to write.
+ * @param[in] buf Buffer to be written.
+ * @param[in] nbytes Size of buffer.
+ *
+ * @return Number of bytes written on success,  -1 on failure.
+ * @internal @todo return negative portable return code on failure.
+ */
+IDATA VMCALL
+hyfile_write (struct HyPortLibrary * portLibrary, IDATA fd, const void *buf,
+              IDATA nbytes)
+{
+  IDATA rc = 0;
+
+  /* write will just do the right thing for HYPORT_TTY_OUT and HYPORT_TTY_ERR */
+  rc = write ((int) fd, buf, nbytes);
+
+  if (rc == -1)
+    {
+      return portLibrary->error_set_last_error (portLibrary, errno,
+                                                findError (errno));
+    }
+  return rc;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_read
+/**
+ * Read bytes from a file descriptor into a user provided buffer.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] fd The file descriptor.
+ * @param[in,out] buf Buffer to read into.
+ * @param[in] nbytes Size of buffer.
+ *
+ * @return The number of bytes read, or -1 on failure.
+ */
+IDATA VMCALL
+hyfile_read (struct HyPortLibrary * portLibrary, IDATA fd, void *buf,
+             IDATA nbytes)
+{
+  IDATA result;
+  if (nbytes == 0)
+    {
+      return 0;
+    }
+
+  result = read ((int) fd, buf, nbytes);
+  if (result == 0)
+    {
+      return -1;
+    }
+  else
+    {
+      return result;
+    }
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_seek
+/**
+ * Repositions the offset of the file descriptor to a given offset as per directive whence.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] fd The file descriptor.
+ * @param[in] offset The offset in the file to position to.
+ * @param[in] whence Portable constant describing how to apply the offset.
+ *
+ * @return The resulting offset on success, -1 on failure.
+ * @note whence is one of HySeekSet (seek from beginning of file), 
+ * HySeekCur (seek from current file pointer) or HySeekEnd (seek backwards from
+ * end of file).
+ * @internal @note seek operations return -1 on failure.  Negative offsets
+ * can be returned when seeking beyond end of file.
+ */
+I_64 VMCALL
+hyfile_seek (struct HyPortLibrary * portLibrary, IDATA fd, I_64 offset,
+             I_32 whence)
+{
+  off_t localOffset = (off_t) offset;
+
+  if ((whence < HySeekSet) || (whence > HySeekEnd))
+    {
+      return -1;
+    }
+
+  /* If file offsets are 32 bit, truncate the seek to that range */
+  if (sizeof (off_t) < sizeof (I_64))
+    {
+      if (offset > 0x7FFFFFFF)
+        {
+          localOffset = 0x7FFFFFFF;
+        }
+      else if (offset < -0x7FFFFFFF)
+        {
+          localOffset = -0x7FFFFFFF;
+        }
+    }
+
+  return (I_64) lseek ((int) fd, localOffset, whence);
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_attr
+/**
+ * Determine whether path is a file or directory.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] path file/path name being queried.
+ *
+ * @return EslsFile if a file, EslsDir if a directory, negative portable error code on failure.
+ */
+I_32 VMCALL
+hyfile_attr (struct HyPortLibrary *portLibrary, const char *path)
+{
+  struct stat buffer;
+
+  /* Neutrino does not handle NULL for stat */
+
+  if (stat (path, &buffer))
+    {
+      return portLibrary->error_set_last_error (portLibrary, errno,
+                                                findError (errno));
+    }
+  if (S_ISDIR (buffer.st_mode))
+    {
+      return HyIsDir;
+    }
+  return HyIsFile;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_findclose
+/**
+ * Close the handle returned from @ref hyfile_findfirst.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] findhandle  Handle returned from @ref hyfile_findfirst.
+ */
+void VMCALL
+hyfile_findclose (struct HyPortLibrary *portLibrary, UDATA findhandle)
+{
+#if defined(_AIX)
+  closedir64 ((DIR64 *) findhandle);
+#else
+  closedir ((DIR *) findhandle);
+#endif
+
+
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_findfirst
+/**
+ * Find the first occurrence of a file identified by path.  Answers a handle
+ * to be used in subsequent calls to @ref hyfile_findnext and @ref hyfile_findclose. 
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] path file/path name being queried.
+ * @param[out] resultbuf filename and path matching path.
+ *
+ * @return valid handle on success, -1 on failure.
+ */
+UDATA VMCALL
+hyfile_findfirst (struct HyPortLibrary *portLibrary, const char *path,
+                  char *resultbuf)
+{
+#if defined(_AIX)
+  DIR64 *dirp = NULL;
+  struct dirent64 *entry;
+#else
+  DIR *dirp = NULL;
+  struct dirent *entry;
+#endif
+
+
+#if defined(_AIX)
+  dirp = opendir64 (path);
+#else
+  dirp = opendir (path);
+#endif
+
+
+  if (dirp == NULL)
+    {
+      return (UDATA) - 1;
+    }
+#if defined(_AIX)
+  entry = readdir64 (dirp);
+#else
+  entry = readdir (dirp);
+#endif
+
+
+  if (entry == NULL)
+    {
+#if defined(_AIX)
+      closedir64 (dirp);
+#else
+      closedir (dirp);
+#endif
+
+
+      return (UDATA) - 1;
+    }
+  strcpy (resultbuf, entry->d_name);
+  return (UDATA) dirp;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_findnext
+/**
+ * Find the next filename and path matching a given handle.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] findhandle handle returned from @ref hyfile_findfirst.
+ * @param[out] resultbuf next filename and path matching findhandle.
+ *
+ * @return 0 on success, -1 on failure or if no matching entries.
+ * @internal @todo return negative portable return code on failure.
+ */
+I_32 VMCALL
+hyfile_findnext (struct HyPortLibrary * portLibrary, UDATA findhandle,
+                 char *resultbuf)
+{
+#if defined(_AIX)
+  struct dirent64 *entry;
+#else
+  struct dirent *entry;
+#endif
+
+
+#if defined(_AIX)
+  entry = readdir64 ((DIR64 *) findhandle);
+#else
+  entry = readdir ((DIR *) findhandle);
+#endif
+
+
+  if (entry == NULL)
+    {
+      return -1;
+    }
+  strcpy (resultbuf, entry->d_name);
+  return 0;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_lastmod
+/**
+ *  Return the last modification time of the file path in seconds.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] path file/path name being queried.
+ *
+ * @return last modification time on success, -1 on failure.
+ */
+I_64 VMCALL
+hyfile_lastmod (struct HyPortLibrary * portLibrary, const char *path)
+{
+  struct stat st;
+  tzset ();
+
+  /* Neutrino does not handle NULL for stat */
+
+  if (stat (path, &st))
+    {
+      return -1;
+    }
+  return st.st_mtime;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_length
+/**
+ * Answer the length in bytes of the file.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] path file/path name being queried.
+ *
+ * @return Length in bytes of the file on success, negative portable error code on failure
+ */
+I_64 VMCALL
+hyfile_length (struct HyPortLibrary * portLibrary, const char *path)
+{
+  struct stat st;
+
+  /* Neutrino does not handle NULL for stat */
+
+  if (stat (path, &st))
+    {
+      return portLibrary->error_set_last_error (portLibrary, errno,
+                                                findError (errno));
+    }
+  return (I_64) st.st_size;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_mkdir
+/**
+ * Create a directory.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] path Directory to be created.
+ *
+ * @return 0 on success, -1 on failure.
+ * @note Assumes all components of path up to the last directory already exist. 
+ * @internal @todo return negative portable return code on failure.
+ */
+I_32 VMCALL
+hyfile_mkdir (struct HyPortLibrary * portLibrary, const char *path)
+{
+  if (-1 == mkdir (path, S_IRWXU | S_IRWXG | S_IRWXO))
+    {
+      portLibrary->error_set_last_error (portLibrary, errno,
+                                         findError (errno));
+      return -1;
+    }
+
+  return 0;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_move
+/**
+ * Move the file pathExist to a new name pathNew.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] pathExist The existing file name.
+ * @param[in] pathNew The new file name.
+ *
+ * @return 0 on success, -1 on failure.
+ * @internal @todo return negative portable return code on failure.
+ */
+I_32 VMCALL
+hyfile_move (struct HyPortLibrary * portLibrary, const char *pathExist,
+             const char *pathNew)
+{
+  return rename (pathExist, pathNew);
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_unlinkdir
+/**
+ * Remove the trailing directory of the path. If the path is a symbolic link to a directory, remove
+ * the symbolic link.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] path directory name being removed.
+ *
+ * @return 0 on success, -1 on failure.
+ * @internal @todo return negative portable return code on failure..
+ */
+I_32 VMCALL
+hyfile_unlinkdir (struct HyPortLibrary * portLibrary, const char *path)
+{
+  /* Call remove() so symbolic links to directories are removed */
+
+  /* QNX has modified the API for remove and rmdir. */
+  /* Remove does not call rmdir automagically like every other Unix. */
+
+  return remove (path);
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_sync
+/**
+ * Synchronize a file's state with the state on disk.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] fd The file descriptor.
+ *
+ * @return 0 on success, -1 on failure.
+ * @internal @todo return negative portable return code on failure.
+ */
+I_32 VMCALL
+hyfile_sync (struct HyPortLibrary * portLibrary, IDATA fd)
+{
+  return fsync ((int) fd);
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_error_message
+/**
+ * Return an error message describing the last OS error that occurred.  The last
+ * error returned is not thread safe, it may not be related to the operation that
+ * failed for this thread.
+ *
+ * @param[in] portLibrary The port library
+ *
+ * @return	error message describing the last OS error, may return NULL.
+ *
+ * @internal
+ * @note  This function gets the last error code from the OS and then returns
+ * the corresponding string.  It is here as a helper function for JCL.  Once hyerror
+ * is integrated into the port library this function should probably disappear.
+ */
+const char *VMCALL
+hyfile_error_message (struct HyPortLibrary *portLibrary)
+{
+  I_32 errorCode;
+
+  errorCode =
+    portLibrary->error_set_last_error (portLibrary, errno, findError (errno));
+  return portLibrary->error_last_error_message (portLibrary);
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_shutdown
+/**
+ * PortLibrary shutdown.
+ *
+ * This function is called during shutdown of the portLibrary.  Any resources that were created by @ref hyfile_startup
+ * should be destroyed here.
+ *
+ * @param[in] portLibrary The port library
+ *
+ * @note Most implementations will be empty.
+ */
+void VMCALL
+hyfile_shutdown (struct HyPortLibrary *portLibrary)
+{
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_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 hyfile_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_FILE
+ *
+ * @note Most implementations will simply return success.
+ */
+I_32 VMCALL
+hyfile_startup (struct HyPortLibrary *portLibrary)
+{
+  return 0;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_vprintf
+/**
+ * Write to a file.
+ *
+ * Writes formatted output  to the file referenced by the file descriptor.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] fd File descriptor to write.
+ * @param[in] format The format String.
+ * @param[in] args Variable argument list.
+ *
+ */
+void VMCALL
+hyfile_vprintf (struct HyPortLibrary *portLibrary, IDATA fd,
+                const char *format, va_list args)
+{
+
+  char outputBuffer[256];
+
+  char *allocatedBuffer;
+  U_32 numberWritten;
+  va_list copyOfArgs;
+
+  /* Attempt to write output to stack buffer */
+  COPY_VA_LIST (copyOfArgs, args);
+  numberWritten =
+    portLibrary->str_vprintf (portLibrary, outputBuffer,
+                              sizeof (outputBuffer), format, copyOfArgs);
+
+  /* str_vprintf always null terminates, returns number characters written excluding the null terminator */
+  if (sizeof (outputBuffer) > (numberWritten + 1))
+    {
+      /* write out the buffer */
+      portLibrary->file_write_text (portLibrary, fd, outputBuffer,
+                                    numberWritten);
+      return;
+    }
+
+  /* Either the buffer was too small, or it was the exact size.  Unfortunately can't tell the difference,
+   * need to determine the size of the buffer (another call to str_vprintf) then print to the buffer,
+   * a third call to str_vprintf
+   */
+  COPY_VA_LIST (copyOfArgs, args);
+
+  /* What is size of buffer required ? Does not include the \0 */
+  numberWritten =
+    portLibrary->str_vprintf (portLibrary, NULL, (U_32) (-1), format,
+                              copyOfArgs);
+  numberWritten += 1;
+
+  allocatedBuffer =
+    portLibrary->mem_allocate_memory (portLibrary, numberWritten);
+  if (NULL == allocatedBuffer)
+    {
+      portLibrary->nls_printf (portLibrary, HYNLS_ERROR,
+                               HYNLS_PORT_FILE_MEMORY_ALLOCATE_FAILURE);
+      return;
+    }
+
+  numberWritten =
+    portLibrary->str_vprintf (portLibrary, allocatedBuffer, numberWritten,
+                              format, args);
+  portLibrary->file_write_text (portLibrary, fd, allocatedBuffer,
+                                numberWritten);
+  portLibrary->mem_free_memory (portLibrary, allocatedBuffer);
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_printf
+/** 
+ * Write to a file.
+ *
+ * Writes formatted output  to the file referenced by the file descriptor.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] fd File descriptor to write to
+ * @param[in] format The format string to be output.
+ * @param[in] ... arguments for format.
+ *
+ */
+void VMCALL
+hyfile_printf (struct HyPortLibrary *portLibrary, IDATA fd,
+               const char *format, ...)
+{
+  va_list args;
+
+  va_start (args, format);
+  portLibrary->file_vprintf (portLibrary, fd, format, args);
+  va_end (args);
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_set_length
+/**
+ * Set the length of a file to a specified value.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] fd The file descriptor.
+ * @param[in] newLength Length to be set
+ *
+ * @return 0 on success, negative portable error code on failure
+ */
+I_32 VMCALL
+hyfile_set_length (struct HyPortLibrary *portLibrary, IDATA fd,
+                   I_64 newLength)
+{
+
+  I_32 rc;
+  off_t length = (off_t) newLength;
+
+  /* If file offsets are 32 bit, truncate the newLength to that range */
+  if (sizeof (off_t) < sizeof (I_64))
+    {
+      if (newLength > 0x7FFFFFFF)
+        {
+          length = 0x7FFFFFFF;
+        }
+      else if (newLength < -0x7FFFFFFF)
+        {
+          length = -0x7FFFFFFF;
+        }
+    }
+
+  rc = ftruncate (fd, length);
+  if (0 != rc)
+    {
+      rc =
+        portLibrary->error_set_last_error (portLibrary, errno,
+                                           findError (errno));
+    }
+  return rc;
+
+}
+
+#undef CDEV_CURRENT_FUNCTION



Mime
View raw message