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; }
/* * Initialize global data structure for non-blocking * close semantics for Solaris 2.6 and ealier. */ int InitializeIO(rlim_t limit) { int i; fd_limit = (int) limit; fd_table = (file_t *) sysCalloc(fd_limit, sizeof(file_t)); if (fd_table == 0) { return SYS_ERR; } for (i = 0; i < fd_limit; i++) { mutexInit(&(fd_table[i].lock)); } return SYS_OK; }
static void *allocNBytes(CICcontext *context, int size) { void *result; if (context->pass == 1) { /* The first pass * A more sophisticated scheme could reduce the number of mallocs. */ CICmallocs *mallocs = (CICmallocs *)sysCalloc(1, sizeof(CICmallocs) + size); if (mallocs == 0) JAVA_ERROR(context, "out of memory"); result = (void *)(mallocs + 1); mallocs->next = context->pass1.mallocs; ROUNDUP_SIZE(size); if (context->in_clinit) context->clinit_size += size; else context->malloc_size += size; context->pass1.mallocs = mallocs; } else { /* The second pass */ #define ALLOC_BLOCK(ptr,buf,sizelimit) \ result = (ptr); \ ROUNDUP_SIZE(size); \ (ptr) += (size); \ sysAssert((ptr) <= (buf) + (sizelimit)) if (context->in_clinit) { ALLOC_BLOCK(context->pass2.clinit_ptr, context->pass2.clinit_buffer, context->clinit_size); } else { ALLOC_BLOCK(context->pass2.malloc_ptr, context->pass2.malloc_buffer, context->malloc_size); } } return result; }
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; }