struct Hnetscape_jsdebug_StackFrameInfo *netscape_jsdebug_JSStackFrameInfo_getCaller0(struct Hnetscape_jsdebug_JSStackFrameInfo * self) { JSDStackFrameInfo* jsdframeCur; JSDStackFrameInfo* jsdframeCaller; struct Hnetscape_jsdebug_JSThreadState* threadState; JSDThreadState* jsdthreadstate; if( ! context || ! controller ) return NULL; jsdframeCur = (JSDStackFrameInfo*) unhand(self)->_nativePtr; if( ! jsdframeCur ) return NULL; threadState = (struct Hnetscape_jsdebug_JSThreadState*) unhand(self)->threadState; if( ! threadState ) return NULL; jsdthreadstate = (JSDThreadState*) unhand(threadState)->nativeThreadState; if( ! jsdthreadstate ) return NULL; jsdframeCaller = JSD_GetCallingStackFrame(context, jsdthreadstate, jsdframeCur); if( ! jsdframeCaller ) return NULL; return (struct Hnetscape_jsdebug_StackFrameInfo*) _constructJSStackFrameInfo( 0, jsdframeCaller, threadState ); }
struct Hnetscape_jsdebug_SourceLocation *netscape_jsdebug_JSPC_getSourceLocation(struct Hnetscape_jsdebug_JSPC * self) { JSDScript* jsdscript; struct Hnetscape_jsdebug_Script* script; struct Hnetscape_jsdebug_JSPC* newPCOb; int line; int newpc; int pc; ExecEnv* ee = EE(); if( ! context || ! controller || ! ee ) return NULL; script = unhand(self)->script; if( ! script ) return NULL; jsdscript = (JSDScript*) unhand(script)->_nativePtr; if( ! jsdscript ) return NULL; pc = unhand(self)->pc; line = JSD_GetClosestLine(context, jsdscript, pc); newpc = JSD_GetClosestPC(context, jsdscript, line); newPCOb = _constructJSPC(ee, script, newpc ); if( ! newPCOb ) return NULL; return (struct Hnetscape_jsdebug_SourceLocation *) execute_java_constructor( ee, "netscape/jsdebug/JSSourceLocation", 0, "(Lnetscape/jsdebug/JSPC;I)", newPCOb, line ); }
struct Hjava_lang_String *netscape_jsdebug_DebugController_executeScriptInStackFrame0(struct Hnetscape_jsdebug_DebugController *self,struct Hnetscape_jsdebug_JSStackFrameInfo *frame,struct Hjava_lang_String *src,struct Hjava_lang_String *filename,long lineno) { struct Hnetscape_jsdebug_JSThreadState* threadStateOb; JSDThreadState* jsdthreadstate; JSDStackFrameInfo* jsdframe; char* filenameC; char* srcC; JSString* jsstr; jsval rval; JSBool success; int srclen; threadStateOb = (struct Hnetscape_jsdebug_JSThreadState*)unhand(frame)->threadState; jsdthreadstate = (JSDThreadState*) unhand(threadStateOb)->nativeThreadState; jsdframe = (JSDStackFrameInfo*) unhand(frame)->_nativePtr; if( ! context || ! controller || ! jsdframe ) return NULL; filenameC = allocCString(filename); if( ! filenameC ) return NULL; srcC = allocCString(src); if( ! srcC ) { free(filenameC); return NULL; } srclen = strlen(srcC); success = JSD_EvaluateScriptInStackFrame(context, jsdthreadstate, jsdframe, srcC, srclen, filenameC, lineno, &rval); /* XXX crashing on Windows under Symantec (though I can't see why!)*/ free(filenameC); free(srcC); if( ! success ) return NULL; if( JSVAL_IS_NULL(rval) || JSVAL_IS_VOID(rval) ) return NULL; jsstr = JSD_ValToStringInStackFrame(context,jsdthreadstate,jsdframe,rval); if( ! jsstr ) return NULL; /* XXXbe should use JS_GetStringChars and preserve Unicode. */ return makeJavaString((char*)JS_GetStringBytes(jsstr), JS_GetStringLength(jsstr)); }
void netscape_jsdebug_DebugController_setInstructionHook0(struct Hnetscape_jsdebug_DebugController * self,struct Hnetscape_jsdebug_PC * pcOb) { Hnetscape_jsdebug_Script* script; JSDScript* jsdscript; unsigned pc; ExecEnv* ee = EE(); if( ! context || ! controller || ! ee ) return; script = (Hnetscape_jsdebug_Script*) execute_java_dynamic_method(ee, (JHandle*)pcOb, "getScript","()Lnetscape/jsdebug/Script;"); if( ! script ) return; jsdscript = (JSDScript*) unhand(script)->_nativePtr; if( ! jsdscript ) return; pc = (unsigned) execute_java_dynamic_method(ee, (JHandle*)pcOb, "getPC","()I"); JSD_SetExecutionHook(context, jsdscript, pc, _executionHook, 0); }
/* * Create a classblock to represent a primitive type. * NOTE: We don't add it to the builtin class table, so this should be * called only once per primitive type. * See FindPrimitiveClass(). */ ClassClass * createPrimitiveClass(char *name, char sig, unsigned char typecode, unsigned char slotsize, unsigned char elementsize) { ClassClass *cb = allocClassClass(); Classjava_lang_Class *ucb = unhand(cb); ucb->major_version = JAVA_VERSION; ucb->minor_version = JAVA_MINOR_VERSION; ucb->name = strdup(name); ucb->super_name = JAVAPKG "Object"; ucb->constantpool = NULL; ucb->constantpool_count = 0; ucb->loader = NULL; ucb->access = ACC_FINAL | ACC_ABSTRACT | ACC_PUBLIC; CCSet(cb, Primitive); cbTypeSig(cb) = sig; cbTypeCode(cb) = typecode; cbSlotSize(cb) = slotsize; cbElementSize(cb) = elementsize; MakeClassSticky(cb); return cb; }
void netscape_jsdebug_DebugController__setController(struct Hnetscape_jsdebug_DebugController * self,/*boolean*/ long on) { if(on) { context = JSD_DebuggerOn(); if( ! context ) return; _simContext = context; /* XXX HACK */ unhand(self)->_nativeContext = (long) context; controller = self; JSD_SetScriptHook(context, _scriptHook, (void*)1 ); JSD_SetErrorReporter(context, _errorReporter, (void*)1 ); JSD_SetDebugBreakHook(context, _executionHook, (void*)1 ); } else { /* XXX stop somehow... */ /* kill context */ JSD_SetDebugBreakHook(context, NULL, NULL ); JSD_SetErrorReporter(context, NULL, NULL); JSD_SetScriptHook(context, NULL, NULL); context = 0; controller = 0; } }
static Hnetscape_jsdebug_Script* _scriptObFromJSDScriptPtr( ExecEnv* ee, JSDScript* jsdscript ) { JHandle* tbl = (JHandle*) unhand(controller)->scriptTable; JHandle* key = _constructInteger(ee,(long)jsdscript); return (Hnetscape_jsdebug_Script*) _getHash( ee, tbl, key ); }
/** * Decodes the given byte array into the <tt>ImageData</tt>. * <p> * Java declaration: * <pre> * loadJPG(Ljavax/microedition/lcdui/ImageData;[BII)V * </pre> * * @param imageData the ImageData to load to * @param imageBytes A byte array containing the encoded JPEG image data * @param imageOffset The start of the image data within the byte array * @param imageLength The length of the image data in the byte array */ KNIEXPORT KNI_RETURNTYPE_VOID KNIDECL(javax_microedition_lcdui_ImageDataFactory_loadJPEG) { int length = KNI_GetParameterAsInt(4); int offset = KNI_GetParameterAsInt(3); unsigned char* srcBuffer = NULL; gxj_screen_buffer image; java_imagedata * midpImageData = NULL; /* variable to hold error codes */ gxutl_native_image_error_codes creationError = GXUTL_NATIVE_IMAGE_NO_ERROR; KNI_StartHandles(3); /* KNI_DeclareHandle(alphaData); */ KNI_DeclareHandle(pixelData); KNI_DeclareHandle(jpegData); KNI_DeclareHandle(imageData); KNI_GetParameterAsObject(2, jpegData); KNI_GetParameterAsObject(1, imageData); midpImageData = GXAPI_GET_IMAGEDATA_PTR(imageData); /* assert * (KNI_IsNullHandle(jpegData)) */ srcBuffer = (unsigned char *)JavaByteArray(jpegData); /* * JAVA_TRACE("loadJPEG jpegData length=%d %x\n", * JavaByteArray(jpegData)->length, srcBuffer); */ image.width = midpImageData->width; image.height = midpImageData->height; unhand(jbyte_array, pixelData) = midpImageData->pixelData; if (!KNI_IsNullHandle(pixelData)) { image.pixelData = (gxj_pixel_type *)JavaByteArray(pixelData); /* * JAVA_TRACE("loadJPEG pixelData length=%d\n", * JavaByteArray(pixelData)->length); */ } /* assert * (imagedata.pixelData != NULL) */ decode_jpeg((srcBuffer + offset), length, &image, &creationError); if (GXUTL_NATIVE_IMAGE_NO_ERROR != creationError) { KNI_ThrowNew(midpIllegalArgumentException, NULL); } KNI_EndHandles(); KNI_ReturnVoid(); }
struct Hnetscape_jsdebug_PC *netscape_jsdebug_JSStackFrameInfo_getPC(struct Hnetscape_jsdebug_JSStackFrameInfo * self) { JSDScript* jsdscript; JSDStackFrameInfo* jsdframe; struct Hnetscape_jsdebug_Script* script; struct Hnetscape_jsdebug_JSThreadState* threadState; JSDThreadState* jsdthreadstate; int pc; ExecEnv* ee = EE(); if( ! context || ! controller || ! ee ) return NULL; jsdframe = (JSDStackFrameInfo*) unhand(self)->_nativePtr; if( ! jsdframe ) return NULL; threadState = (struct Hnetscape_jsdebug_JSThreadState*) unhand(self)->threadState; if( ! threadState ) return NULL; jsdthreadstate = (JSDThreadState*) unhand(threadState)->nativeThreadState; if( ! jsdthreadstate ) return NULL; jsdscript = JSD_GetScriptForStackFrame(context, jsdthreadstate, jsdframe ); if( ! jsdscript ) return NULL; script = _scriptObFromJSDScriptPtr(ee, jsdscript); if( ! script ) return NULL; pc = JSD_GetPCForStackFrame(context, jsdthreadstate, jsdframe); if( ! pc ) return NULL; return (struct Hnetscape_jsdebug_PC*) _constructJSPC(ee, script, pc); }
long netscape_jsdebug_JSThreadState_countStackFrames(struct Hnetscape_jsdebug_JSThreadState * self) { JSDThreadState* jsdstate; if( ! context || ! controller ) return 0; jsdstate = (JSDThreadState*) unhand(self)->nativeThreadState; if( ! jsdstate ) return 0; return (long) JSD_GetCountOfStackFrames(context, jsdstate); }
static void ThreadName( Classjava_lang_Thread* trd, char *buff, int len ) /***********************************************************************/ { char *p; unicode *src; src = unhand(trd->name)->body; len = obj_length(trd->name); p = buff; while( *src ) { if( --len < 0 ) break; *p++ = *src++; } *p = '\0'; }
ClassClass * createFakeArrayClass(char *name, /* name */ int base_type, /* base_type */ int depth, /* array dimension */ ClassClass *inner_cb, /* base type if T_CLASS */ struct Hjava_lang_ClassLoader *loader) { ClassClass *cb = allocClassClass(); Classjava_lang_Class *ucb = unhand(cb); cp_item_type *constant_pool = sysCalloc(CONSTANT_POOL_ARRAY_LENGTH, (sizeof(cp_item_type) + sizeof(unsigned char))); unsigned char *type_table = (unsigned char *) (constant_pool + CONSTANT_POOL_ARRAY_LENGTH); sysAssert(name[0] == SIGNATURE_ARRAY); ucb->major_version = JAVA_VERSION; ucb->minor_version = JAVA_MINOR_VERSION; ucb->name = strdup(name); ucb->super_name = JAVAPKG "Object"; ucb->constantpool = constant_pool; ucb->constantpool_count = CONSTANT_POOL_ARRAY_LENGTH; ucb->loader = loader; constant_pool[CONSTANT_POOL_TYPE_TABLE_INDEX].type = type_table; constant_pool[CONSTANT_POOL_ARRAY_DEPTH_INDEX].i = depth; constant_pool[CONSTANT_POOL_ARRAY_TYPE_INDEX].i = base_type; type_table[CONSTANT_POOL_ARRAY_DEPTH_INDEX] = CONSTANT_Integer | CONSTANT_POOL_ENTRY_RESOLVED; type_table[CONSTANT_POOL_ARRAY_TYPE_INDEX] = CONSTANT_Integer | CONSTANT_POOL_ENTRY_RESOLVED; if (base_type == T_CLASS) { /* Initialize the appropriate fields of the constant pool */ constant_pool[CONSTANT_POOL_ARRAY_CLASS_INDEX].clazz = inner_cb; type_table[CONSTANT_POOL_ARRAY_CLASS_INDEX] = CONSTANT_Class | CONSTANT_POOL_ENTRY_RESOLVED; /* The class is public iff its base class is public */ ucb->access = ACC_FINAL | ACC_ABSTRACT | (cbAccess(inner_cb) & ACC_PUBLIC); } else { /* Set the class field to something innocuous */ type_table[CONSTANT_POOL_ARRAY_CLASS_INDEX] = CONSTANT_Integer | CONSTANT_POOL_ENTRY_RESOLVED; ucb->access = ACC_FINAL | ACC_ABSTRACT | ACC_PUBLIC; } AddBinClass(cb); return cb; }
struct Hnetscape_jsdebug_JSStackFrameInfo* _constructJSStackFrameInfo( ExecEnv* ee, JSDStackFrameInfo* jsdframe, struct Hnetscape_jsdebug_JSThreadState* threadState ) { struct Hnetscape_jsdebug_JSStackFrameInfo* frame; frame = (struct Hnetscape_jsdebug_JSStackFrameInfo*) execute_java_constructor( ee, "netscape/jsdebug/JSStackFrameInfo", 0, "(Lnetscape/jsdebug/JSThreadState;)", threadState ); if( ! frame ) return NULL; /* XXX fill in additional fields */ unhand(frame)->_nativePtr = (long) jsdframe; return frame; }
struct Hnetscape_jsdebug_JSPC *netscape_jsdebug_Script_getClosestPC(struct Hnetscape_jsdebug_Script * self,long line) { unsigned pc; JSDScript* jsdscript; if( ! context || ! controller ) return 0; jsdscript = (JSDScript*) unhand(self)->_nativePtr; if( ! jsdscript ) return 0; pc = JSD_GetClosestPC(context, jsdscript, line); if( -1 == pc ) return 0; return _constructJSPC( 0, self, pc); }
unsigned _errorReporter( JSDContext* jsdc, JSContext* cx, const char* message, JSErrorReport* report, void* callerdata ) { JHandle* reporter; JHandle* msg = NULL; JHandle* filename = NULL; int lineno = 0; JHandle* linebuf = NULL; int tokenOffset = 0; ExecEnv* ee = EE(); if( ! context || ! controller || ! ee ) return JSD_ERROR_REPORTER_PASS_ALONG; reporter = (JHandle*) unhand(controller)->errorReporter; if( ! reporter ) return JSD_ERROR_REPORTER_PASS_ALONG; if( message ) msg = (JHandle*) makeJavaString((char*)message, strlen(message)); if( report && report->filename ) filename = (JHandle*) makeJavaString((char*)report->filename, strlen(report->filename)); if( report && report->linebuf ) linebuf = (JHandle*) makeJavaString((char*)report->linebuf, strlen(report->linebuf)); if( report ) lineno = report->lineno; if( report && report->linebuf && report->tokenptr ) tokenOffset = report->tokenptr - report->linebuf; return (int) execute_java_dynamic_method( ee, reporter, "reportError", "(Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;I)I", msg, filename, lineno, linebuf, tokenOffset ); }
struct Hnetscape_jsdebug_StackFrameInfo *netscape_jsdebug_JSThreadState_getCurrentFrame(struct Hnetscape_jsdebug_JSThreadState * self) { JSDThreadState* jsdstate; JSDStackFrameInfo* jsdframe; if( ! context || ! controller ) return NULL; jsdstate = (JSDThreadState*) unhand(self)->nativeThreadState; if( ! jsdstate ) return NULL; jsdframe = JSD_GetStackFrame(context, jsdstate); if( ! jsdframe ) return NULL; return (struct Hnetscape_jsdebug_StackFrameInfo*) _constructJSStackFrameInfo( 0, jsdframe, self ); }
void _scriptHook( JSDContext* jsdc, JSDScript* jsdscript, JSBool creating, void* callerdata ) { Hnetscape_jsdebug_Script* script; ExecEnv* ee = EE(); if( ! context || ! controller || ! ee ) return; if( creating ) { char* url = (char*)JSD_GetScriptFilename (jsdc, jsdscript); JSString* function = JSD_GetScriptFunctionId (jsdc, jsdscript); int base = JSD_GetScriptBaseLineNumber (jsdc, jsdscript); int extent = JSD_GetScriptLineExtent (jsdc, jsdscript); if( ! url ) { return; /* url = ""; */ } /* create Java Object for Script */ script = (Hnetscape_jsdebug_Script*) execute_java_constructor(ee, "netscape/jsdebug/Script", 0, "()"); if( ! script ) return; /* set the members */ unhand(script)->_url = makeJavaString(url,strlen(url)); unhand(script)->_function = function ? makeJavaString(function,strlen(function)) : 0; unhand(script)->_baseLineNumber = base; unhand(script)->_lineExtent = extent; unhand(script)->_nativePtr = (long)jsdscript; /* add it to the hash table */ _putHash( ee, (JHandle*) unhand(controller)->scriptTable, _constructInteger(ee, (long)jsdscript), (JHandle*)script ); /* call the hook */ if( unhand(controller)->scriptHook ) { execute_java_dynamic_method( ee,(JHandle*)unhand(controller)->scriptHook, "justLoadedScript", "(Lnetscape/jsdebug/Script;)V", script ); } } else { JHandle* tbl = (JHandle*) unhand(controller)->scriptTable; JHandle* key = _constructInteger(ee,(long)jsdscript); /* find Java Object for Script */ script = (Hnetscape_jsdebug_Script*) _getHash( ee, tbl, key ); if( ! script ) return; /* remove it from the hash table */ _removeHash( ee, tbl, key ); /* call the hook */ if( unhand(controller)->scriptHook ) { execute_java_dynamic_method( ee,(JHandle*)unhand(controller)->scriptHook, "aboutToUnloadScript", "(Lnetscape/jsdebug/Script;)V", script ); } /* set the Script as invalid */ execute_java_dynamic_method( ee,(JHandle*)script, "_setInvalid", "()V" ); } }
* */ long demo_InputFile_open(struct Hdemo_InputFile *this) { int fd; char buf[MAXPATHLEN]; /* * we need to convert JAVA path string into a C string and * then change it to a system dependent path string. * note that "unhand" gets the data portion of the handle to * the C representation of the JAVA class InputFile. * */ javaString2CString(unhand(this)->path, buf, sizeof(buf)); convertPath(buf); /* * now we actually call the system dependent routines to implement * the method. note that we could throw an exception via * SignalError() instead of returning a boolean. * */ fd = open(buf, O_RDONLY); if (fd < 0) return(FALSE); /* * on success we store the system fd into the class variable for * future calls to this library.
bool_t createInternalClass1(unsigned char *ptr, unsigned char *end_ptr, ClassClass *cb, struct Hjava_lang_ClassLoader *loader, char *name, char **detail) { struct CICcontext context_block; struct CICcontext *context = &context_block; struct Classjava_lang_Class *ucb = unhand(cb); /* Set up the context */ context->ptr = ptr; context->end_ptr = end_ptr; context->cb = cb; context->detail = detail; if (setjmp(context->jump_buffer)) { /* We've gotten an error of some sort */ /* See comments below about zeroing these two fields before * freeing the temporary buffer. */ cbConstantPool(cb) = NULL; cbFields(cb) = NULL; /* Zero out the method out so that freeClass will not try to free the clinit method */ cbMethodsCount(cb) = 0; freeBuffers(context); return FALSE; } context->in_clinit = 0; context->pass1.mallocs = 0; context->malloc_size = 0; context->clinit_size = 0; /* The first pass allows us to uncover any class format errors and find out the size of the buffer needed. */ context->pass = 1; createInternalClass0(context, cb, loader, name); /* We must set the following two fields to zero before we free * the temporary buffers, because markClassClass may scan a * partially constructed class block in the second pass. * If these two fields are set to zero, markClassClass will * not scan the constant pool and field blocks, which may * point to freed memory. */ cbConstantPool(cb) = NULL; cbFields(cb) = NULL; /* Zero out the method out so that freeClass will not try to free the clinit method */ cbMethodsCount(cb) = 0; freeBuffers(context); context->ptr = ptr; /* rewind the raw class data */ context->pass2.malloc_buffer = sysCalloc(1, context->malloc_size); if (context->pass2.malloc_buffer == 0) JAVA_ERROR(context, "out of memory"); if (context->clinit_size) { context->pass2.clinit_buffer = sysCalloc(1, context->clinit_size); if (context->pass2.clinit_buffer == 0) { sysFree(context->pass2.malloc_buffer); JAVA_ERROR(context, "out of memory"); } } context->pass2.malloc_ptr = context->pass2.malloc_buffer; context->pass2.clinit_ptr = context->pass2.clinit_buffer; /* The second pass accomplishes the real task. */ context->pass = 2; createInternalClass0(context, cb, loader, name); /* Valid class - let's put it in the class table. */ AddBinClass(cb); return TRUE; }
static void createInternalClass0(CICcontext *context, ClassClass *cb, struct Hjava_lang_ClassLoader *loader, char *name) { int i, j; union cp_item_type *constant_pool; unsigned char *type_table; int attribute_count; unsigned fields_count; struct methodblock *mb; struct fieldblock *fb; struct Classjava_lang_Class *ucb = unhand(cb); if (get4bytes(context) != JAVA_CLASSFILE_MAGIC) JAVA_ERROR(context, "Bad magic number"); ucb->minor_version = get2bytes(context); ucb->major_version = get2bytes(context); ucb->loader = loader; if (ucb->major_version != JAVA_VERSION) JAVA_ERROR(context, "Bad major version number"); LoadConstantPool(context); constant_pool = ucb->constantpool; type_table = constant_pool[CONSTANT_POOL_TYPE_TABLE_INDEX].type; ucb->access = get2bytes(context) & ACC_WRITTEN_FLAGS; /* Work around javac bug */ if (ucb->access & ACC_INTERFACE) { ucb->access |= ACC_ABSTRACT; } /* Get the name of the class */ i = get2bytes(context); /* index in constant pool of class */ ucb->name = getAscizFromClass(context, i); if (name != NULL && strcmp(ucb->name, name) != 0) JAVA_ERROR(context, "Wrong name"); constant_pool[i].clazz = cb; CONSTANT_POOL_TYPE_TABLE_SET_RESOLVED(type_table, i); if (loader) { /* We don't trust a classloader to do the right thing. . . */ ClassClass **pcb, **end_pcb; char *name = ucb->name; if (name == NULL || !IsLegalClassname(name, FALSE)) { JAVA_ERROR(context, "Bad name"); } BINCLASS_LOCK(); for (pcb = binclasses, end_pcb = pcb + nbinclasses; pcb < end_pcb; pcb++) { ClassClass *cb = *pcb; if ((cbLoader(cb) == loader) && (strcmp(name, cbName(cb)) == 0)) break; } BINCLASS_UNLOCK(); if (pcb < end_pcb) /* There's already a class with the same name and loader */ JAVA_ERROR(context, "Duplicate name"); } /* Get the super class name. */ i = get2bytes(context); /* index in constant pool of class */ if (i > 0) { ucb->super_name = getAscizFromClass(context, i); if (!IsLegalClassname(ucb->super_name, FALSE)) { JAVA_ERROR(context, "Bad superclass name"); } } i = ucb->implements_count = get2bytes(context); if (i > 0) { int j; ucb->implements = allocNBytes(context, i * sizeof(short)); for (j = 0; j < i; j++) { ucb->implements[j] = get2bytes(context); } } fields_count = ucb->fields_count = get2bytes(context); if (fields_count > 0) ucb->fields = (struct fieldblock *) allocNBytes(context, ucb->fields_count * sizeof(struct fieldblock)); for (i = fields_count, fb = ucb->fields; --i >= 0; fb++) { fieldclass(fb) = cb; fb->access = get2bytes(context) & ACC_WRITTEN_FLAGS; fb->name = getAsciz(context); fb->signature = getAsciz(context); attribute_count = get2bytes(context); for (j = 0; j < (int)attribute_count; j++) { char *name = getAsciz(context); int length = get4bytes(context); if ((fb->access & ACC_STATIC) && strcmp(name, "ConstantValue") == 0) { if (length != 2) JAVA_ERROR(context, "Wrong size for VALUE attribute"); fb->access |= ACC_VALKNOWN; /* we'll change this below */ fb->u.offset = get2bytes(context); } else { getNbytes(context, length, NULL); } } /* if (fb->access & ACC_STATIC) { InitializeStaticVar(fb, context); } */ } if ((ucb->methods_count = get2bytes(context)) > 0) ucb->methods = (struct methodblock *) allocNBytes(context, ucb->methods_count * sizeof(struct methodblock)); for (i = cbMethodsCount(cb), mb = cbMethods(cb); --i >= 0; mb++) { fieldclass(&mb->fb) = cb; mb->fb.access = get2bytes(context) & ACC_WRITTEN_FLAGS; mb->fb.name = getAsciz(context); mb->fb.signature = getAsciz(context); if (strcmp(mb->fb.name, "<clinit>") == 0 && strcmp(mb->fb.signature, "()V") == 0) context->in_clinit = TRUE; mb->args_size = Signature2ArgsSize(mb->fb.signature) + ((mb->fb.access & ACC_STATIC) ? 0 : 1); if (mb->args_size > 255) JAVA_ERROR(context, "Too many arguments"); attribute_count = get2bytes(context); for (j = 0; j < attribute_count; j++) { char *attr_name = getAsciz(context); if ((strcmp(attr_name, "Code") == 0) && ((mb->fb.access & (ACC_NATIVE | ACC_ABSTRACT))==0)) { ReadInCode(context, mb); } else if (strcmp(attr_name, "Exceptions") == 0) { ReadExceptions(context, mb); } else { int length = get4bytes(context); getNbytes(context, length, NULL); } } context->in_clinit = FALSE; } /* See if there are class attributes */ attribute_count = get2bytes(context); for (j = 0; j < attribute_count; j++) { char *name = getAsciz(context); int length = get4bytes(context); if (strcmp(name, "SourceFile") == 0) { if (length != 2) { JAVA_ERROR(context, "Wrong size for VALUE attribute"); } ucb->source_name = getAsciz(context); #ifdef JCOV } else if (strcmp(name, "AbsoluteSourcePath") == 0) { if (length == 2) { ucb->absolute_source_name = getAsciz(context); } else getNbytes(context, length, NULL); } else if (strcmp(name, "TimeStamp") == 0) { unsigned high; unsigned low; int64_t value; Java8 t1; if (length == 8) { high = get4bytes(context); low = get4bytes(context); value = ll_add(ll_shl(uint2ll(high), 32), uint2ll(low)); SET_INT64(t1, &ucb->timestamp, value); } else getNbytes(context, length, NULL); #endif } else { getNbytes(context, length, NULL); } } }
Description : Translate an array of bytes into a class Maintainer : Byung-Sun Yang <*****@*****.**> Pre-condition: Post-condition: Notes: I'm not sure this implementation fully satisfies JVM specification. The loading is too complex..... */ struct Hjava_lang_Class* java_lang_ClassLoader_defineClass0(struct Hjava_lang_ClassLoader* this, struct Hjava_lang_String* name, HArrayOfByte* data, jint offset, jint length) { Hjava_lang_Class* clazz; classFile hand; hand.base = &unhand(data)->body[offset]; hand.buf = hand.base; hand.size = length; clazz = (Hjava_lang_Class*)newObject(ClassClass); clazz = readClass(clazz, &hand, this); processClass(clazz, CSTATE_PREPARED); return clazz; } /* * Resolve classes reference by this class. */ void
#include "java.io.stubs/File.h" #include "runtime/support.h" #include "runtime/errors.h" #include "runtime/exception.h" /* * Is named item a file? */ jbool java_io_File_isFile0(struct Hjava_io_File* this) { struct stat buf; char str[MAXPATHLEN]; int r; javaString2CString(unhand(this)->path, str, sizeof(str)); r = stat(str, &buf); if (r == 0 && S_ISREG(buf.st_mode)) { return (1); } else { return (0); } } /* * Is named item a directory? */ jbool java_io_File_isDirectory0(struct Hjava_io_File* this)
#define GET_STREAM(THIS) (*(z_stream**)&unhand(this)->strm) void java_util_zip_Inflater_setDictionary(struct Hjava_util_zip_Inflater* this, HArrayOfByte* buf, jint from, jint len) { int r; z_stream* dstream; // // This function must be synchronized. // _lockMutex( (Hjava_lang_Object*)this ); dstream = GET_STREAM(this); r = inflateSetDictionary (dstream, &unhand(buf)->body[from], len); if (r < 0) { SignalError(0, "java.lang.Error", dstream->msg ? dstream->msg : "unknown error"); } _unlockMutex( (Hjava_lang_Object*)this ); } jint java_util_zip_Inflater_inflate(struct Hjava_util_zip_Inflater* this, HArrayOfByte* buf, jint off, jint len) { int r; int ilen; z_stream* dstream; jint ret_val;
void netscape_jsdebug_JSSourceTextProvider_refreshSourceTextVector(struct Hnetscape_jsdebug_JSSourceTextProvider * self) { JHandle* vec; JHandle* itemOb; JSDSourceText* iterp = 0; JSDSourceText* item; const char* url; struct Hjava_lang_String* urlOb; ExecEnv* ee = EE(); if( ! context || ! controller || ! ee ) return; /* create new vector */ vec = (JHandle*) execute_java_constructor(ee, "netscape/util/Vector", 0, "()"); if( ! vec ) return; /* lock the native subsystem */ JSD_LockSourceTextSubsystem(context); /* iterate through the native items */ while( 0 != (item = JSD_IterateSources(context, &iterp)) ) { int urlStrLen; int status = JSD_GetSourceStatus(context,item); /* try to find Java object */ url = JSD_GetSourceURL(context, item); if( ! url || 0 == (urlStrLen = strlen(url)) ) /* ignoring those with no url */ continue; urlOb = makeJavaString((char*)url,urlStrLen); if( ! urlOb ) continue; itemOb = (JHandle*) execute_java_dynamic_method( ee, (JHandle*)self, "findSourceTextItem0", "(Ljava/lang/String;)Lnetscape/jsdebug/SourceTextItem;", urlOb ); if( ! itemOb ) { /* if not found then generate new item */ struct Hjava_lang_String* textOb; const char* str; int length; if( ! JSD_GetSourceText(context, item, &str, &length ) ) { str = ""; length = 0; } textOb = makeJavaString((char*)str, length); itemOb = (JHandle*) execute_java_constructor(ee, "netscape/jsdebug/SourceTextItem",0, "(Ljava/lang/String;Ljava/lang/String;I)", urlOb, textOb, status ); } else if( JSD_IsSourceDirty(context, item) && JSD_SOURCE_CLEARED != status ) { /* if found and dirty then update */ struct Hjava_lang_String* textOb; const char* str; int length; if( ! JSD_GetSourceText(context, item, &str, &length ) ) { str = ""; length = 0; } textOb = makeJavaString((char*)str, length); execute_java_dynamic_method(ee, itemOb, "setText", "(Ljava/lang/String;)V", textOb); execute_java_dynamic_method(ee, itemOb, "setStatus", "(I)V", status ); execute_java_dynamic_method(ee, itemOb, "setDirty", "(Z)V", 1 ); } /* we have our copy; clear the native cached text */ if( JSD_SOURCE_INITED != status && JSD_SOURCE_PARTIAL != status && JSD_SOURCE_CLEARED != status ) { JSD_ClearSourceText(context, item); } /* set the item clean */ JSD_SetSourceDirty(context, item, FALSE ); /* add the item to the vector */ if( itemOb ) execute_java_dynamic_method(ee, vec, "addElement", "(Ljava/lang/Object;)V", itemOb ); } /* unlock the native subsystem */ JSD_UnlockSourceTextSubsystem(context); /* set main vector to our new vector */ unhand(self)->_sourceTextVector = (struct Hnetscape_util_Vector*) vec; }
/** * Performs data transfer to the device. This method must be called within * <tt>synchronize</tt> block with the Slot object. * <p>Java declaration: * <pre> * public native static int exchangeAPDU0(Handle h, Slot slot, byte[] request, byte[] response) throws IOException; * </pre> * @param h Connection handle. Can be null for internal purposes * @param slot Slot object. Unused when <tt>h</tt> is not null. * Must be provided if <tt>h</tt> is null. * @param request Buffer with request data * @param response Buffer for response data * @return Length of response data * @exception NullPointerException if any parameter is null * @exception IllegalArgumentException if request does not contain proper APDU * @exception InterruptedIOException if the connection handle is suddenly closed * in the middle of exchange or the card was removed and inserted again * @exception IOException if any I/O troubles occured */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_midp_io_j2me_apdu_APDUManager_exchangeAPDU0() { jint retcode = -1; MidpReentryData* info; void *context = NULL; JSR177_STATUSCODE status_code; JSR177_CARD_MOVEMENT movements; jsize tx_length, rx_length, rx_length_max; jbyte *tx_buffer, *rx_buffer; jbyte *cur; jbyte case_2[5]; int Lc, Le; int cla, channel; ConnectionHandle *h; CardSlot *card_slot; char *err_msg; jbyte getResponseAPDU[5]; KNI_StartHandles(4); KNI_DeclareHandle(connection_handle); KNI_DeclareHandle(slot_handle); KNI_DeclareHandle(request_handle); KNI_DeclareHandle(response_handle); info = (MidpReentryData*)SNI_GetReentryData(NULL); // If the Handle object is provided we get a Slot object from it KNI_GetParameterAsObject(1, connection_handle); if (!KNI_IsNullHandle(connection_handle)) { h = unhand(ConnectionHandle,(connection_handle)); card_slot = h->cardSlot; if (card_slot == NULL) { KNI_ThrowNew(midpNullPointerException, "Slot object is null"); goto end; } } else { h = NULL; KNI_GetParameterAsObject(2, slot_handle); if (KNI_IsNullHandle(slot_handle)) { KNI_ThrowNew(midpNullPointerException, "Handle and slot are null"); goto end; } card_slot = unhand(CardSlot,(slot_handle)); } KNI_GetParameterAsObject(3, request_handle); if (KNI_IsNullHandle(request_handle)) { KNI_ThrowNew(midpNullPointerException, "Request APDU is null"); goto end; } tx_length = KNI_GetArrayLength(request_handle); tx_buffer = SNI_GetRawArrayPointer(request_handle); KNI_GetParameterAsObject(4, response_handle); if (KNI_IsNullHandle(response_handle)) { KNI_ThrowNew(midpNullPointerException, "Response buffer is null"); goto end; } rx_length_max = KNI_GetArrayLength(response_handle); rx_buffer = SNI_GetRawArrayPointer(response_handle); if (h != NULL && (!h->opened || h->cardSessionId != card_slot->cardSessionId)) { char *msg = "Connection closed"; if (!card_slot->locked) { KNI_ThrowNew(midpIOException, msg); goto end; } else { KNI_ThrowNew(midpInterruptedIOException, msg); goto unlock_end; } } if (!card_slot->powered) { char *msg = "Card not powered up"; if (!card_slot->locked) { KNI_ThrowNew(midpIOException, msg); goto end; } else { KNI_ThrowNew(midpInterruptedIOException, msg); goto unlock_end; } } if (tx_length < 4) { // invalid APDU: too short invalid_apdu: KNI_ThrowNew(midpIllegalArgumentException, "Invalid APDU"); goto end; } // trying to guess the case if (tx_length == 4) { // case 1 Lc = Le = 0; } else { Lc = (tx_buffer[4]&0xFF); if (tx_length == 5) { // case 2 Le = Lc; Lc = 0; if (Le == 0) { Le = 256; } } else if (tx_length == 5 + Lc) { // case 3 Le = 0; } else { // case 4 if (5 + Lc >= tx_length) { // invalid APDU: bad Lc field goto invalid_apdu; } Le = tx_buffer[5 + Lc] & 0xFF; if (Le == 0) { Le = 256; } } } // if APDU of case 4 has Lc=0 then we transform it to case 2 if (tx_length > 5 && Lc == 0) { memcpy(case_2, tx_buffer, 4); case_2[4] = tx_buffer[5]; tx_buffer = case_2; tx_length = 5; } // trimming APDU if (tx_length > 5 + Lc + 1) { tx_length = 5 + Lc + 1; } cla = tx_buffer[0] & 0xf8; // mask channel and secure bit channel = cla != 0 && (cla < 0x80 || cla > 0xA0) ? 0 : tx_buffer[0] & 3; // locked slot means that we are in the middle of an exchange, // otherwise we should start a data transfer if (!card_slot->locked) { card_slot->received = 0; cur = rx_buffer; } else { cur = rx_buffer + card_slot->received; } do { // infinite loop int sw1, sw2; rx_length = rx_length_max - (jint)(cur - rx_buffer); if (rx_length < Le + 2) { err_msg = "Too long response"; goto err_mess; } if (info == NULL || info->status == SIGNAL_LOCK) { if (!card_slot->locked) { status_code = jsr177_lock(); if (status_code == JSR177_STATUSCODE_WOULD_BLOCK) { midp_thread_wait(CARD_READER_DATA_SIGNAL, SIGNAL_LOCK, NULL); goto end; } if (status_code != JSR177_STATUSCODE_OK) { goto err; } card_slot->locked = KNI_TRUE; // Since this line slot is locked status_code = jsr177_select_slot(card_slot->slot); if (status_code != JSR177_STATUSCODE_OK) { goto err; } } status_code = jsr177_xfer_data_start(tx_buffer, tx_length, cur, &rx_length, &context); } else { context = info->pResult; status_code = jsr177_xfer_data_finish(tx_buffer, tx_length, cur, &rx_length, context); } if (jsr177_card_movement_events(&movements) == JSR177_STATUSCODE_OK) { if ((movements & JSR177_CARD_MOVEMENT_MASK) != 0) { err_msg = "Card changed"; jsr177_set_error(err_msg); if (jsr177_get_error((jbyte*)gKNIBuffer, KNI_BUFFER_SIZE)) { err_msg = gKNIBuffer; } card_slot->powered = KNI_FALSE; goto interrupted; } } if (status_code == JSR177_STATUSCODE_WOULD_BLOCK) { midp_thread_wait(CARD_READER_DATA_SIGNAL, SIGNAL_XFER, context); card_slot->received = (jint)(cur - rx_buffer); goto end; } if (status_code != JSR177_STATUSCODE_OK) { err: if (jsr177_get_error((jbyte*)gKNIBuffer, KNI_BUFFER_SIZE)) { err_msg = gKNIBuffer; } else { err_msg = "exchangeAPDU0()"; } err_mess: KNI_ThrowNew(midpIOException, err_msg); if (card_slot->locked) { status_code = jsr177_unlock(); // ignore status_code card_slot->locked = KNI_FALSE; midp_thread_signal(CARD_READER_DATA_SIGNAL, SIGNAL_LOCK, SIGNAL_LOCK); } goto end; } if (rx_length < 2) { err_msg = "Response error"; goto err_mess; } if (h != NULL && (!h->opened || h->cardSessionId != card_slot->cardSessionId)) { err_msg = "Handle invalid or closed"; interrupted: KNI_ThrowNew(midpInterruptedIOException, err_msg); goto unlock_end; } sw1 = cur[rx_length - 2] & 0xFF; sw2 = cur[rx_length - 1] & 0xFF; if (sw1 == 0x6C && sw2 != 0x00 && Le != 0) { tx_buffer[tx_length - 1] = sw2; Le = sw2; info = NULL; continue; } cur += rx_length; if (Le == 0 || (sw1 != 0x61 && (channel != 0 || !card_slot->SIMPresent || (sw1 != 0x62 && sw1 != 0x63 && sw1 != 0x9E && sw1 != 0x9F)))) { break; } cur -= 2; // delete last SW1/SW2 from buffer Le = sw1 == 0x62 || sw1 == 0x63 ? 0 : sw2; memset(getResponseAPDU, 0, sizeof getResponseAPDU); tx_buffer = getResponseAPDU; tx_buffer[0] = channel; tx_buffer[1] = 0xC0; tx_buffer[4] = Le; if (Le == 0) { Le = 256; } tx_length = 5; info = NULL; } while(1); retcode = (jint)(cur - rx_buffer); unlock_end: card_slot->locked = KNI_FALSE; midp_thread_signal(CARD_READER_DATA_SIGNAL, SIGNAL_LOCK, SIGNAL_LOCK); status_code = jsr177_unlock(); if (status_code != JSR177_STATUSCODE_OK) { goto err; } end: KNI_EndHandles(); KNI_ReturnInt(retcode); }
unsigned _executionHook( JSDContext* jsdc, JSDThreadState* jsdstate, unsigned type, void* callerdata ) { Hnetscape_jsdebug_JSThreadState* threadState; Hnetscape_jsdebug_Script* script; JHandle* pcOb; JSDStackFrameInfo* jsdframe; JSDScript* jsdscript; int pc; JHandle* tblScript; JHandle* keyScript; ExecEnv* ee = EE(); if( ! context || ! controller || ! ee ) return JSD_HOOK_RETURN_HOOK_ERROR; /* get the JSDStackFrameInfo */ jsdframe = JSD_GetStackFrame(jsdc, jsdstate); if( ! jsdframe ) return JSD_HOOK_RETURN_HOOK_ERROR; /* get the JSDScript */ jsdscript = JSD_GetScriptForStackFrame(jsdc, jsdstate, jsdframe); if( ! jsdscript ) return JSD_HOOK_RETURN_HOOK_ERROR; /* find Java Object for Script */ tblScript = (JHandle*) unhand(controller)->scriptTable; keyScript = _constructInteger(ee, (long)jsdscript); script = (Hnetscape_jsdebug_Script*) _getHash( ee, tblScript, keyScript ); if( ! script ) return JSD_HOOK_RETURN_HOOK_ERROR; /* generate a JSPC */ pc = JSD_GetPCForStackFrame(jsdc, jsdstate, jsdframe); pcOb = (JHandle*) _constructJSPC(ee, script, pc); if( ! pcOb ) return JSD_HOOK_RETURN_HOOK_ERROR; /* build a JSThreadState */ threadState = (struct Hnetscape_jsdebug_JSThreadState*) execute_java_constructor( ee, "netscape/jsdebug/JSThreadState",0,"()"); if( ! threadState ) return JSD_HOOK_RETURN_HOOK_ERROR; /* populate the ThreadState */ /* XXX FILL IN THE REST... */ unhand(threadState)->valid = 1; /* correct value for true? */ unhand(threadState)->currentFramePtr = (long) jsdframe; unhand(threadState)->nativeThreadState = (long) jsdstate; unhand(threadState)->continueState = netscape_jsdebug_JSThreadState_DEBUG_STATE_RUN; /* XXX FILL IN THE REST... */ /* find and call the appropriate Hook */ if( JSD_HOOK_INTERRUPTED == type ) { JHandle* hook; /* clear the JSD level hook (must reset on next sendInterrupt0()*/ JSD_ClearInterruptHook(context); hook = (JHandle*) unhand(controller)->interruptHook; if( ! hook ) return JSD_HOOK_RETURN_HOOK_ERROR; /* call the hook */ execute_java_dynamic_method( ee, hook, "aboutToExecute", "(Lnetscape/jsdebug/ThreadStateBase;Lnetscape/jsdebug/PC;)V", threadState, pcOb ); } else if( JSD_HOOK_DEBUG_REQUESTED == type ) { JHandle* hook; hook = (JHandle*) unhand(controller)->debugBreakHook; if( ! hook ) return JSD_HOOK_RETURN_HOOK_ERROR; /* call the hook */ execute_java_dynamic_method( ee, hook, "aboutToExecute", "(Lnetscape/jsdebug/ThreadStateBase;Lnetscape/jsdebug/PC;)V", threadState, pcOb ); } else if( JSD_HOOK_BREAKPOINT == type ) { JHandle* hook; hook = (JHandle*) execute_java_dynamic_method( ee,(JHandle*)controller, "getInstructionHook0", "(Lnetscape/jsdebug/PC;)Lnetscape/jsdebug/InstructionHook;", pcOb ); if( ! hook ) return JSD_HOOK_RETURN_HOOK_ERROR; /* call the hook */ execute_java_dynamic_method( ee, hook, "aboutToExecute", "(Lnetscape/jsdebug/ThreadStateBase;)V", threadState ); } if( netscape_jsdebug_JSThreadState_DEBUG_STATE_THROW == unhand(threadState)->continueState ) return JSD_HOOK_RETURN_ABORT; return JSD_HOOK_RETURN_CONTINUE; }
/** * Performs reset of the card in the slot. This method must be called within * <tt>synchronize</tt> block with the Slot object. * <p>Java declaration: * <pre> * public native static byte[] reset0(Slot cardSlot) throws IOException; * </pre> * @param cardSlot Slot object * @return byte array with ATR * @exception NullPointerException if parameter is null * @exception IOException if any i/o troubles occured */ KNIEXPORT KNI_RETURNTYPE_OBJECT Java_com_sun_midp_io_j2me_apdu_APDUManager_reset0() { MidpReentryData* info; void *context = NULL; JSR177_STATUSCODE status_code; CardSlot *card_slot; jsize atr_length; char *err_msg; // IMPL_NOTE: I assumed that maximum length of ATR is 256 bytes jbyte atr_buffer[256]; KNI_StartHandles(2); KNI_DeclareHandle(slot_handle); KNI_DeclareHandle(atr_handle); info = (MidpReentryData*)SNI_GetReentryData(NULL); KNI_GetParameterAsObject(1, slot_handle); if (!KNI_IsNullHandle(slot_handle)) { card_slot = unhand(CardSlot,(slot_handle)); } else { KNI_ThrowNew(midpNullPointerException, "Slot object is null"); goto end; } atr_length = sizeof atr_buffer; if (info == NULL || info->status == SIGNAL_LOCK) { if (!card_slot->locked) { status_code = jsr177_lock(); if (status_code == JSR177_STATUSCODE_WOULD_BLOCK) { midp_thread_wait(CARD_READER_DATA_SIGNAL, SIGNAL_LOCK, NULL); goto end; } if (status_code != JSR177_STATUSCODE_OK) { goto err; } card_slot->locked = KNI_TRUE; // Since this line slot is locked status_code = jsr177_select_slot(card_slot->slot); if (status_code != JSR177_STATUSCODE_OK) { goto err; } } status_code = jsr177_reset_start(atr_buffer, &atr_length, &context); } else { context = info->pResult; status_code = jsr177_reset_finish(atr_buffer, &atr_length, context); } if (status_code == JSR177_STATUSCODE_WOULD_BLOCK) { midp_thread_wait(CARD_READER_DATA_SIGNAL, SIGNAL_RESET, context); goto end; } if (status_code != JSR177_STATUSCODE_OK) { err: if (jsr177_get_error((jbyte*)gKNIBuffer, KNI_BUFFER_SIZE)) { err_msg = gKNIBuffer; } else { err_msg = "reset0()"; } KNI_ThrowNew(midpIOException, err_msg); if (card_slot->locked) { status_code = jsr177_unlock(); // ignore status_code card_slot->locked = KNI_FALSE; midp_thread_signal(CARD_READER_DATA_SIGNAL, SIGNAL_LOCK, SIGNAL_LOCK); } goto end; } status_code = jsr177_is_sat(card_slot->slot, &card_slot->SIMPresent); if (status_code != JSR177_STATUSCODE_OK) { goto err; } card_slot->cardSessionId++; card_slot->powered = KNI_TRUE; card_slot->locked = KNI_FALSE; midp_thread_signal(CARD_READER_DATA_SIGNAL, SIGNAL_LOCK, SIGNAL_LOCK); status_code = jsr177_unlock(); if (status_code != JSR177_STATUSCODE_OK) { goto err; } SNI_NewArray(SNI_BYTE_ARRAY, atr_length, atr_handle); memcpy(JavaByteArray(atr_handle), atr_buffer, atr_length); end: KNI_EndHandlesAndReturnObject(atr_handle); }