Index: modules/archive/src/main/native/archive/shared/archiveglob.c =================================================================== --- modules/archive/src/main/native/archive/shared/archiveglob.c (revision 525282) +++ modules/archive/src/main/native/archive/shared/archiveglob.c (working copy) @@ -99,6 +99,8 @@ JCLZipFile *jclZipFile; PORT_ACCESS_FROM_ENV (env); + VMI_ACCESS_FROM_ENV(env); + HyZipFunctionTable *zipFuncs = (*VMI)->GetZipFunctions(VMI); /* Detach from the common library */ ClearLibDetach (env); @@ -111,7 +113,7 @@ while (jclZipFile != NULL) { JCLZipFile *next = jclZipFile->next; - zip_closeZipFile (PORTLIB, &jclZipFile->hyZipFile); + zipFuncs->zip_closeZipFile (VMI, &jclZipFile->hyZipFile); jclmem_free_memory (env, jclZipFile); jclZipFile = next; } Index: modules/archive/src/main/native/archive/shared/jarfile.c =================================================================== --- modules/archive/src/main/native/archive/shared/jarfile.c (revision 525282) +++ modules/archive/src/main/native/archive/shared/jarfile.c (working copy) @@ -20,8 +20,7 @@ #include "exceptions.h" #include "jclglob.h" #include "jclprots.h" - -#include "zipsup.h" +#include "hyzip.h" /* Build a new ZipEntry from the C struct */ jobject @@ -28,9 +27,11 @@ createZipEntry (JNIEnv * env, HyZipFile * zipFile, HyZipEntry * zipEntry) { PORT_ACCESS_FROM_ENV (env); + VMI_ACCESS_FROM_ENV(env); jclass javaClass; jobject java_ZipEntry, extra, entryName; jmethodID mid; + HyZipFunctionTable *zipFuncs = (*VMI)->GetZipFunctions(VMI); /* Build a new ZipEntry from the C struct */ entryName = ((*env)->NewStringUTF (env, zipEntry->filename)); @@ -40,7 +41,7 @@ extra = NULL; if (zipEntry->extraFieldLength > 0) { - zip_getZipEntryExtraField (PORTLIB, zipFile, zipEntry, NULL, + zipFuncs->zip_getZipEntryExtraField (VMI, zipFile, zipEntry, NULL, zipEntry->extraFieldLength); if (zipEntry->extraField == NULL) return NULL; @@ -81,6 +82,7 @@ #define RESULT_BUF_SIZE 256 PORT_ACCESS_FROM_ENV (env); + VMI_ACCESS_FROM_ENV(env); JCLZipFile *jclZipFile; HyZipFile *zipFile; @@ -97,6 +99,7 @@ char startNameBuf[MAX_PATH]; UDATA nameBufSize = MAX_PATH; IDATA rc; + HyZipFunctionTable *zipFuncs = (*VMI)->GetZipFunctions(VMI); nameBuf = (char *) &startNameBuf; @@ -113,11 +116,11 @@ if (zipFile->cache) { - if (zipCache_enumNew (zipFile->cache, "META-INF/", &scanPtr)) + if (zipFuncs->zipCache_enumNew (zipFile->cache, "META-INF/", &scanPtr)) return NULL; if (0 != - zipCache_enumGetDirName (scanPtr, (char *) &metaInfName, + zipFuncs->zipCache_enumGetDirName (scanPtr, (char *) &metaInfName, sizeof (metaInfName))) return NULL; @@ -123,7 +126,7 @@ for (;;) { - rc = zipCache_enumElement (scanPtr, nameBuf, nameBufSize, &offset); + rc = zipFuncs->zipCache_enumElement (scanPtr, nameBuf, nameBufSize, &offset); if (rc < 0) { break; /* we're done, leave the loop */ @@ -144,11 +147,11 @@ continue; /* go to the top of the loop again */ } - zip_initZipEntry (PORTLIB, &zipEntry); - if (zip_getZipEntryFromOffset (PORTLIB, zipFile, &zipEntry, offset)) + zipFuncs->zip_initZipEntry (VMI, &zipEntry); + if (zipFuncs->zip_getZipEntryFromOffset (VMI, zipFile, &zipEntry, offset)) goto cleanup; current = createZipEntry (env, zipFile, &zipEntry); - zip_freeZipEntry (PORTLIB, &zipEntry); + zipFuncs->zip_freeZipEntry (VMI, &zipEntry); if (resultCount == RESULT_BUF_SIZE) goto cleanup; /* fail - should fix. */ if (current) @@ -173,7 +176,7 @@ (*env)->SetObjectArrayElement (env, result, i, resultArray[i]); } cleanup: - zipCache_enumKill (scanPtr); + zipFuncs->zipCache_enumKill (scanPtr); if (oldNameBuf) jclmem_free_memory (env, oldNameBuf); /* free old before checking result so we clean up on fail */ return result; Index: modules/archive/src/main/native/archive/shared/zip.c =================================================================== --- modules/archive/src/main/native/archive/shared/zip.c (revision 525282) +++ modules/archive/src/main/native/archive/shared/zip.c (working copy) @@ -54,7 +54,7 @@ JCLZipFileLink *zipfileHandles; jsize length; char pathCopy[HyMaxPath]; - HyZipCachePool *zipCachePool; + HyZipFunctionTable *zipFuncs; jclZipFile = jclmem_allocate_memory (env, sizeof (*jclZipFile)); if (!jclZipFile) @@ -66,11 +66,9 @@ pathCopy[length++] = '\0'; ioh_convertToPlatform (pathCopy); - /* Open the zip file (caching will be managed automatically by zipsup) */ - zipCachePool = (*VMI)->GetZipCachePool (VMI); - retval = - zip_openZipFile (privatePortLibrary, pathCopy, &(jclZipFile->hyZipFile), - zipCachePool); + /* Open the zip file (caching will be managed automatically) */ + zipFuncs = (*VMI)->GetZipFunctions(VMI); + retval = zipFuncs->zip_openZipFile(VMI, pathCopy, &(jclZipFile->hyZipFile)); if (retval) { @@ -103,6 +101,7 @@ Java_java_util_zip_ZipFile_getEntryImpl (JNIEnv * env, jobject recv, jlong zipPointer, jstring entryName) { + VMI_ACCESS_FROM_ENV(env); PORT_ACCESS_FROM_ENV (env); I_32 retval; @@ -113,6 +112,7 @@ jmethodID mid; const char *entryCopy; JCLZipFile *jclZipFile = (JCLZipFile *) (IDATA) zipPointer; + HyZipFunctionTable *zipFuncs = (*VMI)->GetZipFunctions(VMI); if (jclZipFile == (void *) -1) { @@ -124,12 +124,12 @@ if (entryCopy == NULL) return (jobject) NULL; - zip_initZipEntry (PORTLIB, &zipEntry); - retval = zip_getZipEntry (PORTLIB, zipFile, &zipEntry, entryCopy, TRUE); + zipFuncs->zip_initZipEntry (VMI, &zipEntry); + retval = zipFuncs->zip_getZipEntry (VMI, zipFile, &zipEntry, entryCopy, TRUE); (*env)->ReleaseStringUTFChars (env, entryName, entryCopy); if (retval) { - zip_freeZipEntry (PORTLIB, &zipEntry); + zipFuncs->zip_freeZipEntry (VMI, &zipEntry); return (jobject) NULL; } @@ -136,11 +136,11 @@ extra = NULL; if (zipEntry.extraFieldLength > 0) { - zip_getZipEntryExtraField (PORTLIB, zipFile, &zipEntry, NULL, - zipEntry.extraFieldLength); + zipFuncs->zip_getZipEntryExtraField (VMI, zipFile, &zipEntry, NULL, + zipEntry.extraFieldLength); if (zipEntry.extraField == NULL) { - zip_freeZipEntry (PORTLIB, &zipEntry); + zipFuncs->zip_freeZipEntry (VMI, &zipEntry); return (jobject) NULL; } extra = ((*env)->NewByteArray (env, zipEntry.extraFieldLength)); @@ -146,7 +146,7 @@ extra = ((*env)->NewByteArray (env, zipEntry.extraFieldLength)); if (((*env)->ExceptionCheck (env))) { - zip_freeZipEntry (PORTLIB, &zipEntry); + zipFuncs->zip_freeZipEntry (VMI, &zipEntry); return (jobject) NULL; } ((*env)-> @@ -157,7 +157,7 @@ entryClass = JCL_CACHE_GET (env, CLS_java_util_zip_ZipEntry); entryClass = (*env)->NewLocalRef(env, entryClass); if (entryClass == NULL) { - zip_freeZipEntry (PORTLIB, &zipEntry); + zipFuncs->zip_freeZipEntry (VMI, &zipEntry); return (jobject) NULL; } mid = JCL_CACHE_GET (env, MID_java_util_zip_ZipEntry_init); @@ -171,7 +171,7 @@ zipEntry.compressionMethod, (jlong) zipEntry.lastModDate, (jlong) zipEntry.dataPointer)); - zip_freeZipEntry (PORTLIB, &zipEntry); + zipFuncs->zip_freeZipEntry (VMI, &zipEntry); return java_ZipEntry; } @@ -179,6 +179,7 @@ Java_java_util_zip_ZipFile_closeZipImpl (JNIEnv * env, jobject recv) { PORT_ACCESS_FROM_ENV (env); + VMI_ACCESS_FROM_ENV(env); I_32 retval = 0; JCLZipFile *jclZipFile; @@ -184,6 +185,7 @@ JCLZipFile *jclZipFile; jfieldID descriptorFID = JCL_CACHE_GET (env, FID_java_util_zip_ZipFile_descriptor); + HyZipFunctionTable *zipFuncs = (*VMI)->GetZipFunctions(VMI); jclZipFile = (JCLZipFile *) (IDATA) (*env)->GetLongField (env, recv, descriptorFID); if (jclZipFile != (void *) -1) @@ -189,7 +191,7 @@ if (jclZipFile != (void *) -1) { retval = - zip_closeZipFile (privatePortLibrary, &(jclZipFile->hyZipFile)); + zipFuncs->zip_closeZipFile (VMI, &(jclZipFile->hyZipFile)); (*env)->SetLongField (env, recv, descriptorFID, -1); /* Free the zip struct */ @@ -276,9 +278,11 @@ jlong descriptor) { PORT_ACCESS_FROM_ENV (env); + VMI_ACCESS_FROM_ENV(env); IDATA nextEntryPointer; JCLZipFile *jclZipFile = (JCLZipFile *) (IDATA) descriptor; + HyZipFunctionTable *zipFuncs = (*VMI)->GetZipFunctions(VMI); if (jclZipFile == (void *) -1) { @@ -285,7 +289,7 @@ throwNewIllegalStateException (env, ""); return 0; } - zip_resetZipFile (privatePortLibrary, + zipFuncs->zip_resetZipFile (VMI, &(jclZipFile->hyZipFile), &nextEntryPointer); return nextEntryPointer; @@ -298,6 +302,7 @@ jlong nextEntry) { PORT_ACCESS_FROM_ENV (env); + VMI_ACCESS_FROM_ENV(env); I_32 retval; HyZipFile *zipFile; @@ -308,6 +313,7 @@ jstring entryName = NULL; IDATA nextEntryPointer; JCLZipFile *jclZipFile = (JCLZipFile *) (IDATA) descriptor; + HyZipFunctionTable *zipFuncs = (*VMI)->GetZipFunctions(VMI); if (jclZipFile == (void *) -1) { @@ -315,11 +321,11 @@ return NULL; } zipFile = &(jclZipFile->hyZipFile); - zip_initZipEntry (PORTLIB, &zipEntry); + zipFuncs->zip_initZipEntry (VMI, &zipEntry); nextEntryPointer = (IDATA) nextEntry; retval = - zip_getNextZipEntry (PORTLIB, zipFile, &zipEntry, &nextEntryPointer); + zipFuncs->zip_getNextZipEntry (VMI, zipFile, &zipEntry, &nextEntryPointer); if (retval) { if (retval != ZIP_ERR_NO_MORE_ENTRIES) @@ -340,7 +346,7 @@ extra = NULL; if (zipEntry.extraFieldLength > 0) { - zip_getZipEntryExtraField (PORTLIB, zipFile, &zipEntry, NULL, + zipFuncs->zip_getZipEntryExtraField (VMI, zipFile, &zipEntry, NULL, zipEntry.extraFieldLength); extra = ((*env)->NewByteArray (env, zipEntry.extraFieldLength)); if (((*env)->ExceptionCheck (env))) @@ -346,7 +352,7 @@ if (((*env)->ExceptionCheck (env))) { /* free the extraField entry */ - zip_freeZipEntry (PORTLIB, &zipEntry); + zipFuncs->zip_freeZipEntry (VMI, &zipEntry); return NULL; } ((*env)-> @@ -371,7 +377,7 @@ zipEntry.compressionMethod, (jlong) zipEntry.lastModDate, (jlong) zipEntry.dataPointer)); - zip_freeZipEntry (PORTLIB, &zipEntry); + zipFuncs->zip_freeZipEntry (VMI, &zipEntry); (*env)->SetLongField (env, recv, JCL_CACHE_GET (env, FID_java_util_zip_ZipFile_nextEntryPointer), @@ -385,6 +391,7 @@ jstring entryName) { PORT_ACCESS_FROM_ENV (env); + VMI_ACCESS_FROM_ENV(env); I_32 retval; HyZipFile *zipFile; @@ -392,6 +399,7 @@ const char *entryCopy; jbyteArray buf; JCLZipFile *jclZipFile = (JCLZipFile *) (IDATA) descriptor; + HyZipFunctionTable *zipFuncs = (*VMI)->GetZipFunctions(VMI); /* Build the zipFile */ if (jclZipFile == (void *) -1) @@ -404,13 +412,13 @@ if (entryCopy == NULL) return NULL; - zip_initZipEntry (privatePortLibrary, &zipEntry); + zipFuncs->zip_initZipEntry (VMI, &zipEntry); retval = - zip_getZipEntry (privatePortLibrary, zipFile, &zipEntry, entryCopy, TRUE); + zipFuncs->zip_getZipEntry (VMI, zipFile, &zipEntry, entryCopy, TRUE); (*env)->ReleaseStringUTFChars (env, entryName, entryCopy); if (retval) { - zip_freeZipEntry (privatePortLibrary, &zipEntry); + zipFuncs->zip_freeZipEntry (VMI, &zipEntry); if (retval == ZIP_ERR_OUT_OF_MEMORY) throwNewOutOfMemoryError (env, ""); return NULL; @@ -424,7 +432,7 @@ } retval = - zip_getZipEntryData (privatePortLibrary, zipFile, &zipEntry, NULL, + zipFuncs->zip_getZipEntryData (VMI, zipFile, &zipEntry, NULL, zipEntry.uncompressedSize); if (retval == 0) (*env)->SetByteArrayRegion (env, buf, 0, zipEntry.uncompressedSize, @@ -429,7 +437,7 @@ if (retval == 0) (*env)->SetByteArrayRegion (env, buf, 0, zipEntry.uncompressedSize, zipEntry.data); - zip_freeZipEntry (privatePortLibrary, &zipEntry); + zipFuncs->zip_freeZipEntry (VMI, &zipEntry); if (!retval) return buf; Index: modules/archive/src/main/native/archive/shared/zip.h =================================================================== --- modules/archive/src/main/native/archive/shared/zip.h (revision 525282) +++ modules/archive/src/main/native/archive/shared/zip.h (working copy) @@ -18,7 +18,7 @@ #if !defined(zip_h) #define zip_h -#include "zipsup.h" +#include "hyzip.h" typedef struct JCLZipFile { Index: modules/archive/src/main/native/include/shared/zipsup.h =================================================================== --- modules/archive/src/main/native/include/shared/zipsup.h (revision 525282) +++ modules/archive/src/main/native/include/shared/zipsup.h (working copy) @@ -26,6 +26,8 @@ { #endif #include "hyport.h" +#include "hyzip.h" + typedef struct HyZipCachePool HyZipCachePool; #define HY_ZIP_DLL_NAME "hyzlib" @@ -30,34 +32,6 @@ #define HY_ZIP_DLL_NAME "hyzlib" -#define ZIP_INTERNAL_MAX 80 -#define ZIP_CM_Reduced1 2 -#define ZIP_Unknown 0 -#define ZIP_GZIP 2 -#define ZIP_ERR_OUT_OF_MEMORY -3 -#define ZIP_ERR_FILE_CORRUPT -6 -#define ZIP_ERR_INTERNAL_ERROR -11 -#define ZIP_CM_Imploded 6 -#define ZIP_CM_Reduced4 5 -#define ZIP_CM_Shrunk 1 -#define ZIP_CM_Reduced2 3 -#define ZIP_ERR_FILE_READ_ERROR -1 -#define ZIP_CentralHeader 0x2014B50 -#define ZIP_ERR_FILE_CLOSE_ERROR -10 -#define ZIP_ERR_BUFFER_TOO_SMALL -7 -#define ZIP_CM_Reduced3 4 -#define ZIP_CM_Deflated 8 -#define ZIP_LocalHeader 0x4034B50 -#define ZIP_CM_Tokenized 7 -#define ZIP_PKZIP 1 -#define ZIP_CM_Stored 0 -#define ZIP_ERR_UNSUPPORTED_FILE_TYPE -5 -#define ZIP_ERR_NO_MORE_ENTRIES -2 -#define ZIP_CentralEnd 0x6054B50 -#define ZIP_ERR_FILE_OPEN_ERROR -9 -#define ZIP_ERR_UNKNOWN_FILE_TYPE -4 -#define ZIP_ERR_ENTRY_NOT_FOUND -8 -#define ZIP_DataDescriptor 0x8074B50 typedef struct HyZipCache { @@ -93,45 +67,6 @@ } HyZipDataDescriptor; - typedef struct HyZipEntry - { - U_8 *data; - U_8 *filename; - U_8 *extraField; - U_8 *fileComment; - I_32 dataPointer; - I_32 filenamePointer; - I_32 extraFieldPointer; - I_32 fileCommentPointer; - U_32 compressedSize; - U_32 uncompressedSize; - U_32 crc32; - U_16 filenameLength; - U_16 extraFieldLength; - U_16 fileCommentLength; - U_16 internalAttributes; - U_16 versionCreated; - U_16 versionNeeded; - U_16 flags; - U_16 compressionMethod; - U_16 lastModTime; - U_16 lastModDate; - U_8 internalFilename[80]; - } HyZipEntry; - - - typedef struct HyZipFile - { - U_8 *filename; - struct HyZipCache *cache; - void *cachePool; - I_32 fd; - I_32 pointer; - U_8 internalFilename[80]; - U_8 type; - char _hypadding0065[3]; /* 3 bytes of automatic padding */ - } HyZipFile; - /* HySourceZipSupport*/ extern HY_CFUNC I_32 zip_getZipEntryData PROTOTYPE ((HyPortLibrary * portLib, HyZipFile * zipFile, Index: modules/archive/src/main/native/zip/shared/zipsup.c =================================================================== --- modules/archive/src/main/native/zip/shared/zipsup.c (revision 525282) +++ modules/archive/src/main/native/zip/shared/zipsup.c (working copy) @@ -572,7 +572,7 @@ return result; unreadSize = endEntry.dirSize + 4 /* slop */ ; - zipFile->cache->startCentralDir = startCentralDir = + ((HyZipCache *)(zipFile->cache))->startCentralDir = startCentralDir = (IDATA) ((UDATA) endEntry.dirOffset); if (zipFile->pointer != startCentralDir) @@ -839,7 +839,7 @@ readBuffer = NULL; /* Guess how many bytes we'll need to read. If we guess correctly we will do fewer I/O operations */ headerSize = 30; /* local zip header size */ - if (zipFile->cache && (zipFile->pointer >= zipFile->cache->startCentralDir)) + if (zipFile->cache && (zipFile->pointer >= ((HyZipCache *)(zipFile->cache))->startCentralDir)) { headerSize = 46; /* central zip header size */ } @@ -1186,7 +1186,7 @@ { /* Whack cache timestamp to keep other people from starting to use it (we will create a new one for them to start to use instead). Once all the current users of the cache have stopped using it, it will go away */ - zipFile->cache->zipTimeStamp = -2; + ((HyZipCache *)(zipFile->cache))->zipTimeStamp = -2; zipCachePool_release (zipFile->cachePool, zipFile->cache); } zipFile->cache = NULL; @@ -1218,8 +1218,8 @@ if (!zipFile->cache) return ZIP_ERR_OUT_OF_MEMORY; - zipFile->cache->zipFileSize = fileSize; - zipFile->cache->zipTimeStamp = timeStamp; + ((HyZipCache *)(zipFile->cache))->zipFileSize = fileSize; + ((HyZipCache *)(zipFile->cache))->zipTimeStamp = timeStamp; result = zip_populateCache (portLib, zipFile); if (result != 0) @@ -1387,7 +1387,7 @@ FALSE); if (result != entryStart) { - if (result >= zipFile->cache->startCentralDir) + if (result >= ((HyZipCache *)(zipFile->cache))->startCentralDir) { /* ! Cache contents are not valid. Invalidate it and make a new one */ if (!retryAllowed) @@ -2128,7 +2128,7 @@ if (zipFile) { if (zipFile->cache) - *nextEntryPointer = zipFile->cache->startCentralDir; + *nextEntryPointer = ((HyZipCache *)(zipFile->cache))->startCentralDir; else { I_32 result; Index: modules/instrument/src/main/native/instrument/shared/inst_agt.c =================================================================== --- modules/instrument/src/main/native/instrument/shared/inst_agt.c (revision 525282) +++ modules/instrument/src/main/native/instrument/shared/inst_agt.c (working copy) @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include @@ -159,9 +159,11 @@ /* Reach for the VM interface */ VMI_ACCESS_FROM_JAVAVM(vm); PORT_ACCESS_FROM_JAVAVM(vm); + + HyZipFunctionTable *zipFuncs = (*VMI)->GetZipFunctions(VMI); /* open zip file */ - retval = zip_openZipFile(privatePortLibrary, (char *)jar_name, &zipFile, NULL); + retval = zipFuncs->zip_openZipFile(VMI, (char *)jar_name, &zipFile); if(retval){ sprintf(errorMessage,"failed to open file:%s, %d\n", jar_name, retval); (*env)->FatalError(env, errorMessage); @@ -169,10 +171,10 @@ } /* get manifest entry */ - zip_initZipEntry(privatePortLibrary, &zipEntry); - retval = zip_getZipEntry(privatePortLibrary, &zipFile, &zipEntry, "META-INF/MANIFEST.MF", TRUE); + zipFuncs->zip_initZipEntry(VMI, &zipEntry); + retval = zipFuncs->zip_getZipEntry(VMI, &zipFile, &zipEntry, "META-INF/MANIFEST.MF", TRUE); if (retval) { - zip_freeZipEntry(PORTLIB, &zipEntry); + zipFuncs->zip_freeZipEntry(VMI, &zipEntry); sprintf(errorMessage,"failed to get entry: %d\n", retval); (*env)->FatalError(env, errorMessage); return NULL; @@ -181,9 +183,9 @@ /* read bytes */ size = zipEntry.uncompressedSize; result = (char *)hymem_allocate_memory(size*sizeof(char)); - retval = zip_getZipEntryData(privatePortLibrary, &zipFile, &zipEntry, result, size); + retval = zipFuncs->zip_getZipEntryData(VMI, &zipFile, &zipEntry, result, size); if(retval){ - zip_freeZipEntry(PORTLIB, &zipEntry); + zipFuncs->zip_freeZipEntry(VMI, &zipEntry); sprintf(errorMessage,"failed to get bytes from zip entry, %d\n", zipEntry.extraFieldLength); (*env)->FatalError(env, errorMessage); return NULL; @@ -190,8 +192,8 @@ } /* free resource */ - zip_freeZipEntry(privatePortLibrary, &zipEntry); - retval = zip_closeZipFile(privatePortLibrary, &zipFile); + zipFuncs->zip_freeZipEntry(VMI, &zipEntry); + retval = zipFuncs->zip_closeZipFile(VMI, &zipFile); if (retval) { sprintf(errorMessage,"failed to close zip file: %s, %d\n", jar_name, retval); (*env)->FatalError(env, errorMessage); Index: modules/luni/build.xml =================================================================== --- modules/luni/build.xml (revision 525282) +++ modules/luni/build.xml (working copy) @@ -54,10 +54,11 @@ - + + @@ -129,6 +130,9 @@ + + + Index: modules/luni/src/main/native/include/shared/vmi.h =================================================================== --- modules/luni/src/main/native/include/shared/vmi.h (revision 525282) +++ modules/luni/src/main/native/include/shared/vmi.h (working copy) @@ -31,8 +31,6 @@ #include "jni.h" #include "hyport.h" #include "hyvmls.h" - -#include "zipsup.h" /** * @enum vmiError * Enumeration of all possible return codes from VM interface functions @@ -58,6 +56,7 @@ { VMI_VERSION_UNKNOWN = 0x00000000, /**< Unknown VMInterface version */ VMI_VERSION_1_0 = 0x00010000, /**< VMInterface version 1.0 */ + VMI_VERSION_2_0 = 0x00020000, /**< VMInterface version 2.0 */ vmiVersionEnsureWideEnum = 0x1000000 /* ensure 4-byte enum */ } vmiVersion; @@ -70,6 +69,7 @@ typedef void (JNICALL * vmiSystemPropertyIterator) (char *key, char *value, void *userData); + struct HyZipFunctionTable; struct VMInterface_; struct VMInterfaceFunctions_; @@ -96,8 +96,7 @@ JavaVM *(JNICALL * GetJavaVM) (VMInterface * vmi); HyPortLibrary *(JNICALL * GetPortLibrary) (VMInterface * vmi); HyVMLSFunctionTable *(JNICALL * GetVMLSFunctions) (VMInterface * vmi); - - HyZipCachePool *(JNICALL * GetZipCachePool) (VMInterface * vmi); + struct HyZipFunctionTable *(JNICALL * GetZipFunctions) (VMInterface * vmi); JavaVMInitArgs *(JNICALL * GetInitArgs) (VMInterface * vmi); vmiError (JNICALL * GetSystemProperty) (VMInterface * vmi, char *key, char **valuePtr); @@ -187,18 +186,18 @@ */ HyVMLSFunctionTable *JNICALL GetVMLSFunctions (VMInterface * vmi); -/** - * @fn VMInterfaceFunctions_::GetZipCachePool(VMInterface * vmi) - * Return a pointer to the HyZipCachePool structure used by the VM. It is the - * responsibility of the vm to allocate the pool using zipCachePool_new(). - * - * @code HyZipCachePool* JNICALL GetZipCachePool(VMInterface* vmi); @endcode - * - * @param[in] vmi The VM interface pointer - * - * @return a HyZipCachePool pointer - */ - HyZipCachePool *JNICALL GetZipCachePool (VMInterface * vmi); + /** + * @fn VMInterfaceFunctions_::GetZipFunctions + * Return a pointer to a HyZipFunctionTable. This is a table of functions for managing zip files. + * + * @code HyZipFunctionTable* JNICALL GetZipFunctions(VMInterface* vmi); @endcode + * + * @param[in] vmi The VM interface pointer + * + * @return a HyZipFunctionTable pointer + */ + struct HyZipFunctionTable* JNICALL + GetZipFunctions(VMInterface* vmi); /** * @fn VMInterfaceFunctions_::GetInitArgs(VMInterface * vmi) Index: modules/luni/src/main/native/include/shared/hyzip.h =================================================================== --- modules/luni/src/main/native/include/shared/hyzip.h +++ modules/luni/src/main/native/include/shared/hyzip.h @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +#ifndef hyzip_h +#define hyzip_h + +#include "hycomp.h" +#include "vmi.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define ZIP_INTERNAL_MAX 80 +#define ZIP_CM_Reduced1 2 +#define ZIP_Unknown 0 +#define ZIP_GZIP 2 +#define ZIP_ERR_OUT_OF_MEMORY -3 +#define ZIP_ERR_FILE_CORRUPT -6 +#define ZIP_ERR_INTERNAL_ERROR -11 +#define ZIP_CM_Imploded 6 +#define ZIP_CM_Reduced4 5 +#define ZIP_CM_Shrunk 1 +#define ZIP_CM_Reduced2 3 +#define ZIP_ERR_FILE_READ_ERROR -1 +#define ZIP_CentralHeader 0x2014B50 +#define ZIP_ERR_FILE_CLOSE_ERROR -10 +#define ZIP_ERR_BUFFER_TOO_SMALL -7 +#define ZIP_CM_Reduced3 4 +#define ZIP_CM_Deflated 8 +#define ZIP_LocalHeader 0x4034B50 +#define ZIP_CM_Tokenized 7 +#define ZIP_PKZIP 1 +#define ZIP_CM_Stored 0 +#define ZIP_ERR_UNSUPPORTED_FILE_TYPE -5 +#define ZIP_ERR_NO_MORE_ENTRIES -2 +#define ZIP_CentralEnd 0x6054B50 +#define ZIP_ERR_FILE_OPEN_ERROR -9 +#define ZIP_ERR_UNKNOWN_FILE_TYPE -4 +#define ZIP_ERR_ENTRY_NOT_FOUND -8 +#define ZIP_DataDescriptor 0x8074B50 + +typedef struct HyZipEntry +{ + U_8 *data; + U_8 *filename; + U_8 *extraField; + U_8 *fileComment; + I_32 dataPointer; + I_32 filenamePointer; + I_32 extraFieldPointer; + I_32 fileCommentPointer; + U_32 compressedSize; + U_32 uncompressedSize; + U_32 crc32; + U_16 filenameLength; + U_16 extraFieldLength; + U_16 fileCommentLength; + U_16 internalAttributes; + U_16 versionCreated; + U_16 versionNeeded; + U_16 flags; + U_16 compressionMethod; + U_16 lastModTime; + U_16 lastModDate; + U_8 internalFilename[80]; +} HyZipEntry; + +typedef struct HyZipFile +{ + U_8 *filename; + void *cache; + void *cachePool; + I_32 fd; + I_32 pointer; + U_8 internalFilename[80]; + U_8 type; + char _hypadding0065[3]; /* 3 bytes of automatic padding */ +} HyZipFile; + +typedef struct HyZipFunctionTable { + I_32 (PVMCALL zip_getZipEntryData) (VMInterface * vmi, HyZipFile * zipFile, HyZipEntry * entry, U_8 * buffer, U_32 bufferSize) ; + I_32 (PVMCALL zip_getZipEntryFromOffset) (VMInterface * vmi, HyZipFile * zipFile, HyZipEntry * entry, IDATA offset) ; + I_32 (PVMCALL zip_establishCache) (VMInterface * vmi, HyZipFile * zipFile) ; + void (PVMCALL zip_resetZipFile) (VMInterface * vmi, HyZipFile * zipFile, IDATA * nextEntryPointer) ; + I_32 (PVMCALL zip_getNextZipEntry) (VMInterface * vmi, HyZipFile * zipFile, HyZipEntry * zipEntry, IDATA * nextEntryPointer) ; + I_32 (PVMCALL zip_getZipEntry) (VMInterface * vmi, HyZipFile * zipFile, HyZipEntry * entry, const char *filename, BOOLEAN findDirectory) ; + I_32 (PVMCALL zip_getZipEntryExtraField) (VMInterface * vmi, HyZipFile * zipFile, HyZipEntry * entry, U_8 * buffer, U_32 bufferSize) ; + void (PVMCALL zip_initZipEntry) (VMInterface * vmi, HyZipEntry * entry) ; + I_32 (PVMCALL zip_openZipFile) (VMInterface * vmi, char *filename, HyZipFile * zipFile) ; + void (PVMCALL zip_freeZipEntry) (VMInterface * vmi, HyZipEntry * entry) ; + I_32 (PVMCALL zip_closeZipFile) (VMInterface * vmi, HyZipFile * zipFile) ; + I_32 (PVMCALL zip_getZipEntryComment) (VMInterface * vmi, HyZipFile * zipFile, HyZipEntry * entry, U_8 * buffer, U_32 bufferSize) ; + + UDATA (PVMCALL zipCache_findElement) (void * zipCache, const char *elementName, BOOLEAN searchDirList) ; + void (PVMCALL zipCache_kill) (void * zipCache) ; + IDATA (PVMCALL zipCache_enumGetDirName) (void *handle, char *nameBuf, UDATA nameBufSize) ; + struct HyZipCache *(PVMCALL zipCache_new) (VMInterface * vmi, char *zipName, IDATA zipNameLength) ; + IDATA (PVMCALL zipCache_enumNew) (void * zipCache, char *directoryName, void **handle) ; + IDATA (PVMCALL zipCache_enumElement) (void *handle, char *nameBuf, UDATA nameBufSize, UDATA * offset) ; + void (PVMCALL zipCache_enumKill) (void *handle) ; + BOOLEAN (PVMCALL zipCache_addElement) (void * zipCache, char *elementName, UDATA elementOffset) ; + void *reserved; +} HyZipFunctionTable; + +#ifdef __cplusplus +} +#endif + +#endif /* hyzip_h */ Index: modules/luni/src/main/native/hyzip/shared/hyzip.c =================================================================== --- modules/luni/src/main/native/hyzip/shared/hyzip.c +++ modules/luni/src/main/native/hyzip/shared/hyzip.c @@ -0,0 +1,185 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 "zipsup.h" +#include "hyzip.h" +#include "vmi.h" + +I_32 VMCALL +hyzip_getZipEntryData(VMInterface * vmi, struct HyZipFile * zipFile, struct HyZipEntry * entry, U_8 * buffer, U_32 bufferSize) +{ + PORT_ACCESS_FROM_VMI(vmi); + return zip_getZipEntryData(PORTLIB, zipFile, entry, buffer, bufferSize); +} + +I_32 VMCALL +hyzip_getZipEntryFromOffset(VMInterface * vmi, struct HyZipFile * zipFile, struct HyZipEntry * entry, IDATA offset) +{ + PORT_ACCESS_FROM_VMI(vmi); + return zip_getZipEntryFromOffset(PORTLIB, zipFile, entry, offset); +} + +I_32 VMCALL +hyzip_establishCache(VMInterface * vmi, struct HyZipFile * zipFile) +{ + PORT_ACCESS_FROM_VMI(vmi); + return zip_establishCache(PORTLIB, zipFile); +} + +void VMCALL +hyzip_resetZipFile(VMInterface * vmi, struct HyZipFile * zipFile, IDATA * nextEntryPointer) +{ + PORT_ACCESS_FROM_VMI(vmi); + zip_resetZipFile(PORTLIB, zipFile, nextEntryPointer); +} + +I_32 VMCALL +hyzip_getNextZipEntry(VMInterface * vmi, struct HyZipFile * zipFile, struct HyZipEntry * zipEntry, IDATA * nextEntryPointer) +{ + PORT_ACCESS_FROM_VMI(vmi); + return zip_getNextZipEntry(PORTLIB, zipFile, zipEntry, nextEntryPointer); +} + +I_32 VMCALL +hyzip_getZipEntry(VMInterface * vmi, struct HyZipFile * zipFile, struct HyZipEntry * entry, const char *filename, BOOLEAN findDirectory) +{ + PORT_ACCESS_FROM_VMI(vmi); + return zip_getZipEntry(PORTLIB, zipFile,entry, filename, findDirectory); +} + +I_32 VMCALL +hyzip_getZipEntryExtraField(VMInterface * vmi, struct HyZipFile * zipFile, struct HyZipEntry * entry, U_8 * buffer, U_32 bufferSize) +{ + PORT_ACCESS_FROM_VMI(vmi); + return zip_getZipEntryExtraField(PORTLIB, zipFile, entry, buffer, bufferSize); +} + +void VMCALL +hyzip_initZipEntry(VMInterface * vmi, struct HyZipEntry * entry) +{ + PORT_ACCESS_FROM_VMI(vmi); + zip_initZipEntry(PORTLIB, entry); +} + +I_32 VMCALL +hyzip_openZipFile(VMInterface * vmi, char *filename, struct HyZipFile * zipFile) +{ + PORT_ACCESS_FROM_VMI(vmi); + + HyZipFunctionTable *zipFuncs = (*vmi)->GetZipFunctions(vmi); + /* This is a synchonization hole, should probably add a mutex to control setting this variable. */ + if ( zipFuncs->reserved == NULL ) { + zipFuncs->reserved = zipCachePool_new(PORTLIB); + } + + return zip_openZipFile(PORTLIB, filename, zipFile, (HyZipCachePool *)zipFuncs->reserved); +} + +void VMCALL +hyzip_freeZipEntry(VMInterface * vmi, struct HyZipEntry * entry) +{ + PORT_ACCESS_FROM_VMI(vmi); + zip_freeZipEntry(PORTLIB, entry); +} + +I_32 VMCALL +hyzip_closeZipFile(VMInterface * vmi, struct HyZipFile * zipFile) +{ + PORT_ACCESS_FROM_VMI(vmi); + return zip_closeZipFile(PORTLIB, zipFile); +} + +I_32 VMCALL +hyzip_getZipEntryComment(VMInterface * vmi, struct HyZipFile * zipFile, struct HyZipEntry * entry, U_8 * buffer, U_32 bufferSize) +{ + PORT_ACCESS_FROM_VMI(vmi); + return zip_getZipEntryComment(PORTLIB, zipFile, entry, buffer, bufferSize); +} + +UDATA VMCALL +hyzipCache_findElement(struct HyZipCache * zipCache, const char *elementName, BOOLEAN searchDirList) +{ + return zipCache_findElement(zipCache, elementName, searchDirList); +} + +void VMCALL +hyzipCache_kill(struct HyZipCache * zipCache) +{ + zipCache_kill(zipCache); +} + +IDATA VMCALL +hyzipCache_enumGetDirName(void *handle, char *nameBuf, UDATA nameBufSize) +{ + return zipCache_enumGetDirName(handle, nameBuf, nameBufSize); +} + +struct HyZipCache *VMCALL +hyzipCache_new(VMInterface * vmi, char *zipName, IDATA zipNameLength) +{ + PORT_ACCESS_FROM_VMI(vmi); + return (struct HyZipCache *)zipCache_new(PORTLIB, zipName, zipNameLength); +} + +IDATA VMCALL +hyzipCache_enumNew(struct HyZipCache * zipCache, char *directoryName, void **handle) +{ + return zipCache_enumNew(zipCache, directoryName, handle); +} + +IDATA VMCALL +hyzipCache_enumElement(void *handle, char *nameBuf, UDATA nameBufSize, UDATA * offset) +{ + return zipCache_enumElement(handle, nameBuf, nameBufSize, offset); +} + +void VMCALL +hyzipCache_enumKill(void *handle) +{ + zipCache_enumKill(handle); +} + +BOOLEAN VMCALL +hyzipCache_addElement(struct HyZipCache * zipCache, char *elementName, UDATA elementOffset) +{ + return zipCache_addElement(zipCache, elementName, elementOffset); +} + + +HyZipFunctionTable HyZipLibraryTable = { + hyzip_getZipEntryData, + hyzip_getZipEntryFromOffset, + hyzip_establishCache, + hyzip_resetZipFile, + hyzip_getNextZipEntry, + hyzip_getZipEntry, + hyzip_getZipEntryExtraField, + hyzip_initZipEntry, + hyzip_openZipFile, + hyzip_freeZipEntry, + hyzip_closeZipFile, + hyzip_getZipEntryComment, + hyzipCache_findElement, + hyzipCache_kill, + hyzipCache_enumGetDirName, + hyzipCache_new, + hyzipCache_enumNew, + hyzipCache_enumElement, + hyzipCache_enumKill, + hyzipCache_addElement, + NULL +}; Index: modules/luni/src/main/native/hyzip/unix/makefile =================================================================== --- modules/luni/src/main/native/hyzip/unix/makefile +++ modules/luni/src/main/native/hyzip/unix/makefile @@ -0,0 +1,26 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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 'hyzip' +# + +include $(HY_HDK)/build/make/defines.mk + +INCLUDES += -I../../include/shared +BUILDFILES = $(SHAREDSUB)hyzip.o +LIBNAME = $(LIBPATH)libhyzip.a + +include $(HY_HDK)/build/make/rules.mk Index: modules/luni/src/main/native/hyzip/windows/makefile =================================================================== --- modules/luni/src/main/native/hyzip/windows/makefile +++ modules/luni/src/main/native/hyzip/windows/makefile @@ -0,0 +1,29 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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 'hyzip' +# + +!include <$(HY_HDK)\build\make\defines.mak> + +LIBNAME=$(LIBPATH)hyzip.lib + +BUILDFILES = \ + $(SHAREDSUB)hyzip.obj + +HYCFLAGS = $(HYCFLAGS) /I$(SHAREDSUB) /I..\..\include\shared /I..\..\include\windows + +!include <$(HY_HDK)\build\make\rules.mak>