📄 midpservices.c
字号:
fprintf(stderr, KVM_MSG_USES_64M_MAXIMUM_MEMORY "\n"); heapSize = 64 * 1024 * 1024; } /* Make sure the heap size is divisible by four */ heapSize -= heapSize%CELL; currentArg++; RequestedHeapSize = heapSize; } return (jint)(currentArg - startArg);}/*========================================================================= * FUNCTION: midp_printVmUsage * OVERVIEW: Print VM usage text. * INTERFACE: * parameters: none * returns: none *=======================================================================*/voidmidp_printVmUsage(void) { fprintf(stdout, VmUsageText);}/*========================================================================= * FUNCTION: midp_getCurrentTime * OVERVIEW: Gets the current system time in milliseconds. * INTERFACE: * parameters: none * returns: jlong returns the current system time in milliseconds *=======================================================================*/jlongmidp_getCurrentTime(void) { return (jlong)CurrentTime_md();}/*========================================================================= * Empty stub functions *=======================================================================*//*========================================================================= * These are native methods required by the VM classloader. *=======================================================================*/void Java_java_lang_Class_invoke_1clinit(void) { }void Java_java_lang_Class_invoke_1verifier(void) { }void Java_java_lang_Class_getSuperclass(void) { }/*========================================================================= * Resource helper functions *=======================================================================*//*========================================================================= * FUNCTION: midp_openResourceFile * OVERVIEW: Open a resource file * INTERFACE: * parameters: resourceName: The name of the resource to open * size: (out) The size of the resource * returns: int A handle associated with this resource *=======================================================================*/intmidp_openResourceFile(char* resourceName, int* size) { int fd = -1; FILEPOINTER fp; START_TEMPORARY_ROOTS /* * setFilePointer() may cause a GC, so, we need to protect the * FILEPOINTER Java Object */ IS_TEMPORARY_ROOT(fp, openResourcefile(resourceName)); if (fp != NULL) { /* Translate a FILEPOINTER to a file descriptor */ fd = setFilePointer(&fp); (*size) = getBytesAvailable(&fp); } END_TEMPORARY_ROOTS return fd;}/*========================================================================= * FUNCTION: midp_closeResourceFile * OVERVIEW: Close a resource file * INTERFACE: * parameters: fd: The handle of the resource * returns: none *=======================================================================*/voidmidp_closeResourceFile(int fd) { FILEPOINTER fp; START_TEMPORARY_ROOTS /* Translate a file descriptor to a FILEPOINTER */ IS_TEMPORARY_ROOT(fp, getFilePointer(fd)); if (fp != NULL) { closeClassfile(&fp); clearFilePointer(fd); } END_TEMPORARY_ROOTS}/*========================================================================= * FUNCTION: midp_readResourceFile * OVERVIEW: Read a byte from a resource file * INTERFACE: * parameters: fd: The handle of the resource * returns: int The next byte in the specified resource file *=======================================================================*/intmidp_readResourceFile(int fd) { FILEPOINTER fp; int result = -2; START_TEMPORARY_ROOTS /* Translate a file descriptor to a FILEPOINTER */ IS_TEMPORARY_ROOT(fp, getFilePointer(fd)); if (fp != NULL) { result = loadByteNoEOFCheck(&fp); } END_TEMPORARY_ROOTS return result;}/*========================================================================= * FUNCTION: midp_readallResourceFile * OVERVIEW: Read several bytes from a resource file * INTERFACE: * parameters: fd: The handle of the resource * offset: The starting position in the resource * size: The number of bytes to read * outArray: (in|out) A byte array Object to read into. * It must be created with the appropriate size * prior to calling this method. * pos; The starting position in the array * returns: int The number of bytes actually read *=======================================================================*/intmidp_readallResourceFile(int fd, int offset, int size, jobject* outArray, int pos) { FILEPOINTER fp; int result = -2; START_TEMPORARY_ROOTS /* Translate a file descriptor to a FILEPOINTER */ IS_TEMPORARY_ROOT(fp, getFilePointer(fd)); if (fp != NULL) { /* Unhandle the jobject into kVM's native datatype */ BYTEARRAY barray = (BYTEARRAY)*((jobject)(*outArray)); result = loadBytesNoEOFCheck(&fp, (char*)(&barray->bdata[pos]), offset, size); } END_TEMPORARY_ROOTS return result;}/*========================================================================= * Compression helper functions *=======================================================================*//*========================================================================= * FUNCTION: midp_pngInflate * OVERVIEW: Decompress a PNG image data stream * INTERFACE: * parameters: data: The raw data stream * compLen: The compressed length of the stream * outFileH: (in|out) A buffer to store decompressed data. * It must be created with the appropriate size * prior to calling this method. * decompLen: The decompressed length * returns: jboolean: TRUE if decompression occured without error * FALSE otherwise *=======================================================================*/extern unsigned int PNGdecodeImage_getBytes(unsigned char *buffer, int count, void *p);jbooleanmidp_pngInflate(void *data, int compLen, unsigned char** outFileH, int decompLen) { return inflateData(data, PNGdecodeImage_getBytes, compLen, outFileH, decompLen);}/*========================================================================= * JAR helper functions *=======================================================================*//*========================================================================= * FUNCTION: midp_readJarEntry * OVERVIEW: Read an entry from a JAR file * INTERFACE: * parameters: jarName: The JAR file to read * entryName: The name of the entry * entry: (out) An Object representing the entry, * must be set to null on input, will set to * java byte array if the entry was read * returns: jboolean: TRUE if the entry was read or not found; * FALSE otherwise (such as JAR not found) *=======================================================================*/jbooleanmidp_readJarEntry(char* jarName, char* entryName, jobject* entry) { struct jarInfoStruct jarInfo; long entryLength; int error = 0; /* WARNING: loadJARFileEntry() may cause an allocation. A couple levels * down the call-stack, we potentially call CLDC's implementation * of inflateHuffman() which is where an allocation can happen. We * need to protect any Java-heap allocations with temporary roots. */ START_TEMPORARY_ROOTS DECLARE_TEMPORARY_ROOT(unsigned char*, buf, NULL); /* openJARFile returns TRUE on success */ if (openJARFile(jarName, 0, &jarInfo)) { buf = (unsigned char*) loadJARFileEntry(&jarInfo, entryName, &entryLength, 0); closeJARFile(&jarInfo); } else { error = 1; } if (buf != NULL) { DECLARE_TEMPORARY_ROOT(BYTEARRAY, dataObj, (BYTEARRAY)instantiateArray(PrimitiveArrayClasses[T_BYTE], entryLength)); if (dataObj != NULL) { jobject handle = (jobject)(*entry); memcpy(dataObj->bdata, buf, (int)entryLength); /* Unhandle the jobject and store our newly created Java object */ *((cell*)handle) = (cell)dataObj; } else { error = 1; } } END_TEMPORARY_ROOTS return ((error == 0) ? KNI_TRUE : KNI_FALSE);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -