Exemplo n.º 1
0
/*
 * Map a range of virtual memory.  Note that the size asked for here
 * is literally what the upper level has asked for.  We need to do
 * any rounding, etc. here.  If mapping fails return 0, otherwise
 * return the address of the base of the mapped memory.
 */
void *
sysMapMem(size_t requestedSize, size_t *mappedSize)
{
    void *mappedAddr;

    *mappedSize = roundUpToGrain(requestedSize);
#ifdef USE_MALLOC
    mappedAddr = (void *) sysMalloc(*mappedSize); /* Returns 0 on failure */
#ifdef __linux__
     if (mappedAddr) {
       memset(mappedAddr, 0, *mappedSize);
       mappedAddr = (void *) roundUpToGrain(mappedAddr);
     }
#endif
#else
    mappedAddr = mapChunk(*mappedSize);           /* Returns 0 on failure */
#endif /* USE_MALLOC */
    if (mappedAddr) {
        Log3(2, "sysMapMem: 0x%x bytes at 0x%x (request: 0x%x bytes)\n",
             *mappedSize, mappedAddr, requestedSize);
    } else {
        Log1(2, "sysMapMem failed: (request: 0x%x bytes)\n", requestedSize);
    }
    return mappedAddr;
}
Exemplo n.º 2
0
Object *createConstructorObject(MethodBlock *mb) {
    Object *reflect_ob, *vm_reflect_ob, *classes;
    char *signature, *sig;

    if((reflect_ob = allocObject(cons_reflect_class)) == NULL)
        return NULL;

    if((vm_reflect_ob = allocObject(vmcons_reflect_class)) == NULL)
        return NULL;

    signature = sig = sysMalloc(strlen(mb->type) + 1);
    strcpy(sig, mb->type);

    classes = convertSig2ClassArray(&sig, mb->class);
    sysFree(signature);

    if(classes == NULL)
        return NULL;

    INST_DATA(vm_reflect_ob, Class*, vm_cons_class_offset) = mb->class;
    INST_DATA(vm_reflect_ob, Object*, vm_cons_param_offset) = classes;
    INST_DATA(vm_reflect_ob, int, vm_cons_slot_offset) =
                                     mb - CLASS_CB(mb->class)->methods;

    /* Link the Java-level and VM-level objects together */
    INST_DATA(vm_reflect_ob, Object*, vm_cons_cons_offset) = reflect_ob;
    INST_DATA(reflect_ob, Object*, cons_cons_offset) = vm_reflect_ob;

    return reflect_ob;
}
Exemplo n.º 3
0
char *String2Utf8(Object *string) {
    int len = getStringLen(string);
    unsigned short *unicode = getStringChars(string);
    char *utf8 = (char*)sysMalloc(utf8CharLen(unicode, len) + 1);

    return unicode2Utf8(unicode, len, utf8);
}
/*
 * Bootstrap the Java thread system by making the current thread the
 * "primordial" thread.
 */
int threadBootstrapMD(sys_thread_t **tidP, sys_mon_t **lockP, int nb)
{
    OSVERSIONINFO windowsVersion;
    HANDLE hnd = GetCurrentProcess();

    nReservedBytes = (nb + 7) & (~7);
    /*
     * Allocate TLS index for thread-specific data.
     */
    tls_index = TlsAlloc();
    if (tls_index == TLS_INVALID_INDEX) {
        VM_CALL(jio_fprintf)(stderr, "TlsAlloc failed (errcode = %x)\n",
                    GetLastError());
        return SYS_NOMEM;
    }

    /* OS properties */
    windowsVersion.dwOSVersionInfoSize = sizeof(windowsVersion);
    GetVersionEx(&windowsVersion);
    windowsNT = windowsVersion.dwPlatformId == VER_PLATFORM_WIN32_NT;

   /* Initialize the queue lock monitor */
    _sys_queue_lock = (sys_mon_t *)sysMalloc(sysMonitorSizeof());
    if (_sys_queue_lock == NULL) {
        return SYS_ERR;
    }
    VM_CALL(monitorRegister)(_sys_queue_lock, "Thread queue lock");
    *lockP = _sys_queue_lock;

    return sysThreadAlloc(tidP);
}
Exemplo n.º 5
0
/**
 * Creates copy of va_list that can be updated and worked upon
 */
EXTERNAL va_list* sysVaCopy(va_list ap)
{
  TRACE_PRINTF("%s: sysVaCopy\n", Me);
  va_list *ap_ = (va_list*)sysMalloc(sizeof(va_list));
  va_copy (*ap_, ap);
  return ap_;
}
Exemplo n.º 6
0
HashTable *classlibCreateLoaderTable(Object *class_loader) {
    HashTable *table = sysMalloc(sizeof(HashTable));

    initHashTable((*table), CLASS_INITSZE, TRUE);
    INST_DATA(class_loader, HashTable*, ldr_classes_offset) = table;

    return table;
}
Exemplo n.º 7
0
char *String2Cstr(Object *string) {
    int len = INST_DATA(string)[count_offset];
    //char *buff = (char *)sysMalloc(len + 1);
    // duyanning HACK
    char *buff = (char *)sysMalloc(len + 10);

    return String2Buff0(string, buff, len);
}
Exemplo n.º 8
0
Arquivo: utf8.c Projeto: webos21/xi
char *copyUtf8(char *string) {
    char *buff = xi_strcpy(sysMalloc(xi_strlen(string) + 1), string);
    char *found = findHashedUtf8(buff, TRUE);

    if(found != buff)
        sysFree(buff);

    return found;
}
Exemplo n.º 9
0
/******************* Initialization ********************************/
GCFUNC void blkInit(unsigned nMB)
{
  unsigned      sz;
   
  /* Zero out all vars */
  memset( &blkvar, 0, sizeof(blkvar) );

  /* Allocate the heap */
  mokAssert( nMB < (1<<BLOCKBITS) && nMB>0);
  blkvar.heapSz = nMB << 20;
  blkvar.heapStart = (byte*)mokMemReserve( NULL, blkvar.heapSz );
  blkvar.heapTop = blkvar.heapStart + blkvar.heapSz;
  mokMemCommit( blkvar.heapStart, blkvar.heapSz, false );

#ifdef RCVERBOSE
  jio_printf(
         "heap[%x<-->%x]\n", 
         (unsigned)blkvar.heapStart, 
         blkvar.heapSz + (unsigned)blkvar.heapStart);
  fflush( stdout );
#endif 

  /* Allocate block headers table */
  blkvar.nWildernessBlocks = blkvar.nBlocks = blkvar.heapSz >> BLOCKBITS;
  sz = sizeof( BlkAllocHdr ) * (blkvar.nBlocks + 3);
  blkvar.allocatedBlockHeaders  = (BlkAllocHdr*)mokMemReserve( NULL, sz );
  mokMemCommit( blkvar.allocatedBlockHeaders, sz, true );

  blkvar.allocatedBlockHeaders ++;
	
  blkvar.pRegionLists = 
    (BlkListHdr*)blkvar.allocatedBlockHeaders + blkvar.nBlocks + 1;


  bhSet_status( (blkvar.allocatedBlockHeaders-1) , DUMMYBLK );
  bhSet_status( (blkvar.allocatedBlockHeaders+blkvar.nBlocks) , DUMMYBLK );

  blkvar.blockHeaders = 
    blkvar.allocatedBlockHeaders - ((unsigned)blkvar.heapStart>>BLOCKBITS);
	
  blkvar.heapTopRegion = (BlkRegionHdr*)OBJBLOCKHDR( blkvar.heapTop );
  blkvar.wildernessRegion = (BlkRegionHdr*)OBJBLOCKHDR( blkvar.heapStart );
	
  /* Allocate mutex */
  blkvar.blkMgrMon = sysMalloc(sysMonitorSizeof());
  sysMonitorInit( blkvar.blkMgrMon );

#ifdef RCDEBUG
  jio_printf("headers1[%x<-->%x]\n", 
	 (unsigned)blkvar.allocatedBlockHeaders, 
	 sz + (unsigned)blkvar.allocatedBlockHeaders);
  jio_printf("headers2[%x<-->%x]\n",
	 OBJBLOCKHDR(blkvar.heapStart), 
	 OBJBLOCKHDR( (((byte*)blkvar.heapStart)+(nMB<<20)) ) );
#endif 
}
Exemplo n.º 10
0
void 
AddBinClass(ClassClass * cb)
{
    register int left, right, middle, result, i;
    char *name = cbName(cb);
    struct Hjava_lang_ClassLoader *loader = cbLoader(cb);
    
    BINCLASS_LOCK();
    left = 0;
    right = nbinclasses - 1;
    result = 1;
    while (left <= right) {
        ClassClass *cb1;
	middle = (left+right)/2;
	cb1 = binclasses[middle];
	result = strcmp(name, cbName(cb1));
	if (result == 0) {
	    if (loader < cbLoader(cb1)) {
	        result = -1;
	    } else if (loader > cbLoader(cb1)) {
	        result = 1;
	    } else {
	        result = 0;
	    }
	}
	if (result < 0) {
	    right = middle-1;
	} else if (result > 0) {
	    left = middle+1;
	} else {
	    break;
	}
    }
    if (result != 0) {
        if (nbinclasses >= sizebinclasses) {
	    if (binclasses == 0)
		binclasses = (ClassClass **)
		    sysMalloc(sizeof(ClassClass *) * (sizebinclasses = 50));
	    else
		binclasses = (ClassClass **)
		    sysRealloc(binclasses, sizeof(ClassClass *)
			    * (sizebinclasses = nbinclasses * 2));
	}
	if (binclasses == 0)
	    goto unlock;
	right++;
	for (i = nbinclasses; i > right; i--) {
	    binclasses[i] = binclasses[i-1];
	}
	binclasses[right] = cb;
	nbinclasses++;
    }

unlock:
    BINCLASS_UNLOCK();
}	
Exemplo n.º 11
0
char *slash2DotsDup(char *utf8) {
    int len = strlen(utf8);
    char *buff = sysMalloc(len + 1);
    int i;

    for(i = 0; i <= len; i++) {
        char c = utf8[i];
        buff[i] = c == '/' ? '.' : c;
    }

    return buff;
}
Exemplo n.º 12
0
Arquivo: dll.c Projeto: OPSF/uClinux
char *mangleClassAndMethodName(MethodBlock *mb) {
    char *classname = CLASS_CB(mb->class)->name;
    char *methodname = mb->name;
    char *nonMangled = (char*) sysMalloc(strlen(classname) + strlen(methodname) + 7);
    char *mangled;

    sprintf(nonMangled, "Java/%s/%s", classname, methodname);

    mangled = mangleString(nonMangled);
    sysFree(nonMangled);
    return mangled;
}
Exemplo n.º 13
0
char *slash2dots(char *utf8) {
    int len = strlen(utf8);
    char *conv = sysMalloc(len+1);
    int i;

    for(i = 0; i <= len; i++)
        if(utf8[i] == '/')
            conv[i] = '.';
        else
            conv[i] = utf8[i];

    return conv;
}
Exemplo n.º 14
0
void inlineSequence(MethodBlock *mb, CodeBlock *info, int start, int len) {
    int code_len = goto_len + sizeof(CodeBlockHeader);
    Instruction *instructions = &info->start[start];
    OpcodeInfo *opcodes = &info->opcodes[start];
    CodeBlockHeader *hashed_block, *block;
    int aligned_len, i;
    char *pntr;

    /* Calculate sequence length */
    for(i = 0; i < len; i++)
        code_len += handler_sizes[opcodes[i].cache_depth][opcodes[i].opcode];

    aligned_len = ALIGN(code_len);

    /* We malloc memory for the block rather than allocating code memory.
       This reduces fragmentation of the code memory in the case where we
       use an existing block and must free the new sequence */
    block = sysMalloc(aligned_len);

    /* Store length at beginning of sequence */
    block->len = aligned_len;
    pntr = (char *)(block + 1);

    /* Concatenate the handler bodies together */
    for(i = 0; i < len; i++) {
        int size = handler_sizes[opcodes[i].cache_depth][opcodes[i].opcode];

        memcpy(pntr, instructions[i].handler, size);
        pntr += size;
    }

    /* Add the dispatch onto the end of the super-instruction */
    memcpy(pntr, goto_start, goto_len);

    /* Pad with zeros up to block length */
    for(pntr += goto_len; code_len < aligned_len; code_len++)
        *pntr++ = 0;

    /* Look up new block in inlined block cache */
    hashed_block = findCodeBlock(block);
    sysFree(block);

    if(hashed_block != NULL) {
        /* Replace first handler with new inlined block */
        instructions[0].handler = hashed_block + 1;
        MBARRIER();

        TRACE("InlineSequence %s start %p (%d) instruction len %d code len %d sequence %p\n",
              mb->name, instructions, start, len, code_len, instructions[0].handler);
    }
}
Exemplo n.º 15
0
Arquivo: os.c Projeto: vilie/javify
char *nativeJVMPath() {
    Dl_info info;
    char *path;

    if(dladdr(nativeJVMPath, &info) == 0) {
        printf("Error: dladdr failed.  Aborting VM\n");
        exitVM(1);
    }

    path = sysMalloc(strlen(info.dli_fname) + 1);
    strcpy(path, info.dli_fname);

    return path;
}
Exemplo n.º 16
0
/**
 *
 * @return new char
 */
char *Jstring2Char(O string)
{
    O array = (O) (INST_DATA(string)[value_offset - 1]);
    int len = INST_DATA(string)[count_offset - 1];
    int offset = INST_DATA(string)[offset_offset - 1];
    char *cstr = (char *) sysMalloc(len + 1), *spntr;
    short *str = ((short *) INST_DATA(array)) + offset;

    for (spntr = cstr; len > 0; len--)
        *spntr++ = *str++;

    *spntr = '\0';

    return cstr;
}
Exemplo n.º 17
0
Monitor* allocMonitor(Object *obj) {
    Monitor *mon;

    if(mon_free_list != NULL) {
        mon = mon_free_list;
        mon_free_list = mon->next;      
    } else {
        mon = sysMalloc(sizeof(Monitor));
        monitorInit(mon);
    }
    mon->obj = obj;
    /* No need to wrap in LOCKWORD_WRITE as no thread should
     * be modifying it when it's on the free list */
    mon->entering = 0;
    return mon;
}
Exemplo n.º 18
0
Arquivo: dll.c Projeto: OPSF/uClinux
char *mangleSignature(MethodBlock *mb) {
    char *type = mb->type;
    char *nonMangled;
    char *mangled;
    int i;

    /* find ending ) */
    for(i = strlen(type) - 1; type[i] != ')'; i--);

    nonMangled = (char *) sysMalloc(i);
    strncpy(nonMangled, type + 1, i - 1);
    nonMangled[i - 1] = '\0';
    
    mangled = mangleString(nonMangled);
    sysFree(nonMangled);
    return mangled;
}
Exemplo n.º 19
0
/* Load a .class file normally from the local disk */
static ClassClass *
LoadClassFromFile(char *fn, char *dir, char *class_name)
{
    extern int OpenCode(char *, char *, char *, struct stat*);
    struct stat st;
    ClassClass *cb = 0;
    int codefd = -1;
    int	retryCount = 0;
    unsigned char *external_class;
    char *detail;

    codefd = OpenCode(fn, NULL, dir, &st);

    if (codefd < 0)		/* open failed */
	return 0;

    /* Snarf the file into memory. */
    external_class = (unsigned char *)sysMalloc(st.st_size);
    if (external_class == 0)
        goto failed;
    if (sysRead(codefd, external_class, st.st_size) != st.st_size)
        goto failed;
    sysClose(codefd);
    codefd = -1;

    /* Create the internal class */
    cb = allocClassClass();
    if (cb == NULL || 
	!createInternalClass(external_class, external_class + st.st_size, 
			     cb, NULL, class_name, &detail)) {
	sysFree(external_class);
	goto failed;
    }
    sysFree(external_class);

    if (verbose)
	jio_fprintf(stderr, "[Loaded %s]\n", fn);
    return cb;
failed:
    if (codefd >= 0)
	sysClose(codefd);
    if (cb != 0)
        FreeClass(cb);
    return 0;
}
Exemplo n.º 20
0
void createVMThread(const char *name, void (*start)(Thread*)) {
    Thread *thread = new Thread;
    void **args = (void**)sysMalloc(3 * sizeof(void*));
    pthread_t tid;

    args[0] = const_cast<char*>(name);
    args[1] = (void*)start;
    args[2] = thread;

    pthread_create(&tid, &attributes, shell, args);

    /* Wait for thread to start */

    pthread_mutex_lock(&lock);
    while(thread->state == 0)
        pthread_cond_wait(&cv, &lock);
    pthread_mutex_unlock(&lock);
}
Exemplo n.º 21
0
Arquivo: dll.c Projeto: OPSF/uClinux
char *mangleString(char *utf8) {
    int len = utf8Len(utf8);
    unsigned short *unicode = (unsigned short*) sysMalloc(len * 2);
    char *mangled, *mngldPtr;
    int i, mangledLen = 0;

    convertUtf8(utf8, unicode);

    /* Work out the length of the mangled string */

    for(i = 0; i < len; i++) {
        unsigned short c = unicode[i];
        switch(c) {
            case '_':
            case ';':
            case '[':
                mangledLen += 2;
                break;

           default:
                mangledLen += isalnum(c) ? 1 : 6;
                break;
        }
    }

    mangled = mngldPtr = (char*) sysMalloc(mangledLen + 1);

    /* Construct the mangled string */

    for(i = 0; i < len; i++) {
        unsigned short c = unicode[i];
        switch(c) {
            case '_':
                *mngldPtr++ = '_';
                *mngldPtr++ = '1';
                break;
            case ';':
                *mngldPtr++ = '_';
                *mngldPtr++ = '2';
                break;
            case '[':
                *mngldPtr++ = '_';
                *mngldPtr++ = '3';
                break;

            case '/':
                *mngldPtr++ = '_';
                break;

            default:
                if(isalnum(c))
                    *mngldPtr++ = c;
                else
                    mngldPtr += sprintf(mngldPtr, "_0%04x", c);
                break;
        }
    }

    *mngldPtr = '\0';

    sysFree(unicode);
    return mangled;
}
Exemplo n.º 22
0
native_netscape_javascript_JSObject_call(
    JRIEnv* env,
    struct netscape_javascript_JSObject* self,
    struct java_lang_String *method,
    jobjectArray args)
{
#ifndef JAVA
	return NULL;
#else
    JSContext *cx;
    JSObject *jso;
    JSSavedState saved;
    const char *cstr;
    struct java_lang_Object *ret;
    int total_argc, argc, i;
    jsval *argv;
    jsval rval;
    int cost = 0;

    if (!enterJS(env, self, &cx, &jso, &saved))
        return NULL;

    if (! method ||
        ! (cstr = JRI_GetStringPlatformChars(env, method,
					     (const jbyte *) cx->charSetName,
					     (jint) cx->charSetNameLength))) {
        /* FIXME this should be an error of some sort */
        js_throwJSException(env, "illegal member name");
        ret = NULL;
	goto do_exit;
    }

    if (args) {
        total_argc = JRI_GetObjectArrayLength(env, args);
        argv = sysMalloc(total_argc * sizeof(jsval));
    } else {
        total_argc = 0;
        argv = 0;
    }

    for (argc = 0; argc < total_argc; argc++) {
        jref arg = JRI_GetObjectArrayElement(env, args, argc);

        if (!js_convertJObjectToJSValue(cx, argv+argc, (HObject*)arg))
            goto cleanup_argv;
        JS_AddRoot(cx, argv+argc);
    }

    if (! JS_CallFunctionName(cx, jso, cstr, argc, argv, &rval) ||
        ! js_convertJSValueToJObject((HObject **) &ret, cx, rval,
                                     0, 0, JS_FALSE, &cost)) {
        ret = NULL;
    }

  cleanup_argv:
    for (i = 0; i < argc; i++)
        JS_RemoveRoot(cx, argv+i);
    sysFree(argv);

  do_exit:
    if (!exitJS(env, self, cx, jso, &saved))
        return NULL;

    return ret;
#endif
}
Exemplo n.º 23
0
Arquivo: os.c Projeto: vilie/javify
char *nativeLibMapName(char *name) {
   char *buff = sysMalloc(strlen(name) + sizeof("lib.so") + 1);

   sprintf(buff, "lib%s.so", name);
   return buff;
}
Exemplo n.º 24
0
 * The object's isArray is FALSE, so that the length is 0.
 *
 * NOTE: obj->class refer to the java/lang/Class Object whitch
 *      in the methodArea. When a obj.getClass() it's return the
 *      relevent java/lang/Class Object.
 * @qcliu 2015/03/23
 */
O allocObject(C class)
{
    ClassBlock_t *cb;
    O obj;
    int obj_size;

    cb = CLASS_CB(class);
    obj_size = cb->obj_size;
    obj = (O) sysMalloc(OBJ_HEADER_SIZE + sizeof(int) * obj_size);
    //---------------------------------
    obj->type = OBJECT_OBJECT;
    obj->length = obj_size;
    obj->atype = 0;
    //--------------------------
    obj->class = class;
    obj->binding = NULL;
    obj->data = (unsigned int *) (obj + 1);
    memset(obj + 1, 0, sizeof(int) * obj_size);
    obj->cb = cb;
    obj->el_size = sizeof(int);
    //obj->copy_size = OBJ_HEADER_SIZE+ sizeof(int)*obj_size;
    return obj;

}
Exemplo n.º 25
0
int parseCommonOpts(char *string, InitArgs *args, int is_jni) {
    int status = OPT_OK;

    if(strcmp(string, "-Xasyncgc") == 0)
        args->asyncgc = TRUE;

    else if(strncmp(string, "-Xms", 4) == 0 ||
            (!is_jni && strncmp(string, "-ms", 3) == 0)) {

        char *value = string + (string[1] == 'm' ? 3 : 4);
        args->min_heap = parseMemValue(value);

        if(args->min_heap < MIN_HEAP) {
            optError(args, "Invalid minimum heap size: %s (min %dK)\n",
                     string, MIN_HEAP/KB);
            status = OPT_ERROR;
        }

    } else if(strncmp(string, "-Xmx", 4) == 0 ||
              (!is_jni && strncmp(string, "-mx", 3) == 0)) {

        char *value = string + (string[1] == 'm' ? 3 : 4);
        args->max_heap = parseMemValue(value);

        if(args->max_heap < MIN_HEAP) {
            optError(args, "Invalid maximum heap size: %s (min is %dK)\n",
                     string, MIN_HEAP/KB);
            status = OPT_ERROR;
        }

    } else if(strncmp(string, "-Xss", 4) == 0 ||
              (!is_jni && strncmp(string, "-ss", 3) == 0)) {

        char *value = string + (string[1] == 'm' ? 3 : 4);
        args->java_stack = parseMemValue(value);

        if(args->java_stack < MIN_STACK) {
            optError(args, "Invalid Java stack size: %s (min is %dK)\n",
                     string, MIN_STACK/KB);
            status = OPT_ERROR;
        }

    } else if(strncmp(string, "-D", 2) == 0) {
        char *key = strcpy(sysMalloc(strlen(string + 2) + 1), string + 2);
        char *pntr;

        for(pntr = key; *pntr && (*pntr != '='); pntr++);
        if(*pntr)
            *pntr++ = '\0';
        args->commandline_props[args->props_count].key = key;
        args->commandline_props[args->props_count++].value = pntr;

    } else if(strncmp(string, "-Xbootclasspath:", 16) == 0) {
        args->bootpath = string + 16;
        args->bootpath_p = args->bootpath_a = NULL;

    } else if(strncmp(string, "-Xbootclasspath/a:", 18) == 0) {
        args->bootpath_a = string + 18;

    } else if(strncmp(string, "-Xbootclasspath/p:", 18) == 0) {
        args->bootpath_p = string + 18;

    } else if(strcmp(string, "-Xnocompact") == 0) {
        args->compact_specified = TRUE;
        args->do_compact = FALSE;

    } else if(strcmp(string, "-Xcompactalways") == 0) {
        args->compact_specified = args->do_compact = TRUE;

    } else if(strcmp(string, "-Xtracejnisigs") == 0) {
        args->trace_jni_sigs = TRUE;
#ifdef INLINING
    } else if(strcmp(string, "-Xnoinlining") == 0) {
        /* Turning inlining off is equivalent to setting
           code memory to zero */
        args->codemem = 0;

    } else if(strcmp(string, "-Xnoprofiling") == 0) {
        args->profiling = FALSE;

    } else if(strcmp(string, "-Xnopatching") == 0) {
        args->branch_patching = FALSE;

    } else if(strcmp(string, "-Xnopatchingdup") == 0) {
        args->branch_patching_dup = FALSE;

    } else if(strcmp(string, "-Xnojoinblocks") == 0) {
        args->join_blocks = FALSE;

    } else if(strcmp(string, "-Xcodestats") == 0) {
        args->print_codestats = TRUE;

    } else if(strncmp(string, "-Xprofiling:", 12) == 0) {
        args->profile_threshold = strtol(string + 12, NULL, 0);

    } else if(strncmp(string, "-Xreplication:", 14) == 0) {
        char *pntr = string + 14;

        if(strcmp(pntr, "none") == 0)
            args->replication_threshold = INT_MAX;
        else
            if(strcmp(pntr, "always") == 0)
                args->replication_threshold = 0;
            else
                args->replication_threshold = strtol(pntr, NULL, 0);

    } else if(strncmp(string, "-Xcodemem:", 10) == 0) {
        char *pntr = string + 10;

        args->codemem = strncmp(pntr, "unlimited", 10) == 0 ?
            INT_MAX : parseMemValue(pntr);

    } else if(strcmp(string, "-Xshowreloc") == 0) {
        showRelocatability();
#endif

#ifdef HAVE_PROFILE_STUBS
    } else if(strcmp(string, "-Xdumpstubsprofiles") == 0) {
        args->dump_stubs_profiles = TRUE;
#endif
    /* Compatibility options */
    } else {
        int i;

        for(i = 0; compat[i].option != NULL; i++) {
            int len = strlen(compat[i].option);

            if(strncmp(string, compat[i].option, len) == 0 &&
               (((compat[i].flags & OPT_ARG) && string[len] == ':') ||
                ((compat[i].flags & OPT_NOARG) && string[len] == '\0')))
                break;
        }

        if(compat[i].option == NULL)
            status = OPT_UNREC;
    }
       
    return status;
}
Exemplo n.º 26
0
Arquivo: zip.c Projeto: Liam1206/jamvm
ZipFile *processArchive(char *path) {
    unsigned char magic[SIG_LEN];
    unsigned char *data, *pntr;
    int entries, fd, len;

    HashTable *hash_table;
    ZipFile *zip;

    if((fd = open(path, O_RDONLY)) == -1)
        return NULL;

    /* First 4 bytes must be the signature for the first local file header */
    if(read(fd, &magic[0], SIG_LEN) != SIG_LEN ||
                    READ_LE_INT(magic) != LOC_FILE_HEADER_SIG)
        goto error;

    /* Get the length */
    len = lseek(fd, 0, SEEK_END);

    /* Mmap the file into memory */
    if((data = (unsigned char*)mmap(0, len, PROT_READ, MAP_FILE |
                                            MAP_PRIVATE, fd, 0)) == MAP_FAILED)
        goto error;

    /* Locate the end of central directory record by searching backwards for
       the record signature. */

    if(len < END_CEN_LEN)
        goto error2;
        
    for(pntr = data + len - END_CEN_LEN; pntr >= data; )
        if(*pntr == (END_CEN_SIG & 0xff))
            if(READ_LE_INT(pntr) == END_CEN_SIG)
                break;
            else
                pntr -= SIG_LEN;
        else
            pntr--;

    /* Check that we found it */
    if(pntr < data)
        goto error2;

    /* Get the number of entries in the central directory */
    entries = READ_LE_SHORT(pntr + END_CEN_ENTRIES_OFFSET);

    /* Create and initialise hash table to hold the directory.
       Do not create lock -- we're single threaded (bootstrapping)
       and once entries are added, table is read-only */

    hash_table = sysMalloc(sizeof(HashTable));
    initHashTable((*hash_table), HASHTABSZE, FALSE);

    /* Get the offset from the start of the file of the first directory entry */
    pntr = data + READ_LE_INT(pntr + END_CEN_DIR_START_OFFSET);

    /* Scan the directory list and add the entries to the hash table */

    while(entries--) {
        char *found, *pathname;
        int path_len, comment_len, extra_len;

        /* Make sure we're not reading outside the file */
        if((pntr + CEN_FILE_HEADER_LEN) > (data + len))
            goto error2;

        /* Check directory entry signature is present */
        if(READ_LE_INT(pntr) != CEN_FILE_HEADER_SIG)
            goto error2;

        /* Get the length of the pathname */
        path_len = READ_LE_SHORT(pntr + CEN_FILE_PATHLEN_OFFSET);

        /* Not interested in these fields but need length to skip */
        extra_len = READ_LE_SHORT(pntr + CEN_FILE_EXTRALEN_OFFSET);
        comment_len = READ_LE_SHORT(pntr + CEN_FILE_COMMENTLEN_OFFSET);

        /* The pathname starts after the fixed part of the dir entry */
        pathname = (char*)(pntr += CEN_FILE_HEADER_LEN);

        /* Skip variable fields, to point to next sig */
        pntr += path_len + extra_len + comment_len;

        /* Add if absent, no scavenge, not locked */
        findHashEntry((*hash_table), pathname, found, TRUE, FALSE, FALSE);
    }

    zip = sysMalloc(sizeof(ZipFile));

    zip->data = data;
    zip->length = len;
    zip->dir_hash = hash_table;

    return zip;

error2:
    munmap(data, len);

error:
    close(fd);
    return NULL;
}
Exemplo n.º 27
0
Arquivo: jam.c Projeto: OPSF/uClinux
int parseCommandLine(int argc, char *argv[], InitArgs *args) {
    int is_jar = FALSE;
    int status = 1;
    int i;

    Property props[argc-1];
    int props_count = 0;

    for(i = 1; i < argc; i++) {
        if(*argv[i] != '-') {
            if(args->min_heap > args->max_heap) {
                printf("Minimum heap size greater than max!\n");
                goto exit;
            }

            if((args->props_count = props_count)) {
                args->commandline_props = (Property*)sysMalloc(props_count * sizeof(Property));
                memcpy(args->commandline_props, &props[0], props_count * sizeof(Property));
            }

            if(is_jar) {
                args->classpath = argv[i];
                argv[i] = "jamvm/java/lang/JarLauncher";
            }

            return i;
        }

        if(strcmp(argv[i], "-help") == 0) {
            status = 0;
            break;

        } else if(strcmp(argv[i], "-X") == 0) {
            showNonStandardOptions();
            status = 0;
            goto exit;

        } else if(strcmp(argv[i], "-version") == 0) {
            showVersionAndCopyright();
            status = 0;
            goto exit;

        } else if(strcmp(argv[i], "-showversion") == 0) {
            showVersionAndCopyright();

        } else if(strcmp(argv[i], "-fullversion") == 0) {
            showFullVersion();
            status = 0;
            goto exit;

        } else if(strncmp(argv[i], "-verbose", 8) == 0) {
            char *type = &argv[i][8];

            if(*type == '\0' || strcmp(type, ":class") == 0)
                args->verboseclass = TRUE;

            else if(strcmp(type, ":gc") == 0 || strcmp(type, "gc") == 0)
                args->verbosegc = TRUE;

            else if(strcmp(type, ":jni") == 0)
                args->verbosedll = TRUE;

        } else if(strcmp(argv[i], "-Xnoasyncgc") == 0)
            args->noasyncgc = TRUE;

        else if(strncmp(argv[i], "-ms", 3) == 0 || strncmp(argv[i], "-Xms", 4) == 0) {
            args->min_heap = parseMemValue(argv[i] + (argv[i][1] == 'm' ? 3 : 4));
            if(args->min_heap < MIN_HEAP) {
                printf("Invalid minimum heap size: %s (min %dK)\n", argv[i], MIN_HEAP/KB);
                goto exit;
            }

        } else if(strncmp(argv[i], "-mx", 3) == 0 || strncmp(argv[i], "-Xmx", 4) == 0) {
            args->max_heap = parseMemValue(argv[i] + (argv[i][1] == 'm' ? 3 : 4));
            if(args->max_heap < MIN_HEAP) {
                printf("Invalid maximum heap size: %s (min is %dK)\n", argv[i], MIN_HEAP/KB);
                goto exit;
            }

        } else if(strncmp(argv[i], "-ss", 3) == 0 || strncmp(argv[i], "-Xss", 4) == 0) {
            args->java_stack = parseMemValue(argv[i] + (argv[i][1] == 's' ? 3 : 4));
            if(args->java_stack < MIN_STACK) {
                printf("Invalid Java stack size: %s (min is %dK)\n", argv[i], MIN_STACK/KB);
                goto exit;
            }

        } else if(strncmp(argv[i], "-D", 2) == 0) {
            char *pntr, *key = strcpy(sysMalloc(strlen(argv[i]+2) + 1), argv[i]+2);
            for(pntr = key; *pntr && (*pntr != '='); pntr++);
            if(*pntr)
                *pntr++ = '\0';
            props[props_count].key = key;
            props[props_count++].value = pntr;

        } else if(strcmp(argv[i], "-classpath") == 0 || strcmp(argv[i], "-cp") == 0) {

            if(i == (argc-1)) {
                printf("%s : missing path list\n", argv[i]);
                goto exit;
            }
            args->classpath = argv[++i];

        } else if(strncmp(argv[i], "-Xbootclasspath:", 16) == 0) {

            args->bootpathopt = '\0';
            args->bootpath = argv[i] + 16;

        } else if(strncmp(argv[i], "-Xbootclasspath/a:", 18) == 0 ||
                  strncmp(argv[i], "-Xbootclasspath/p:", 18) == 0 ||
                  strncmp(argv[i], "-Xbootclasspath/c:", 18) == 0 ||
                  strncmp(argv[i], "-Xbootclasspath/v:", 18) == 0) {

            args->bootpathopt = argv[i][16];
            args->bootpath = argv[i] + 18;

        } else if(strcmp(argv[i], "-jar") == 0) {
            is_jar = TRUE;

        } else if(strcmp(argv[i], "-Xnocompact") == 0) {
            args->compact_specified = TRUE;
            args->do_compact = FALSE;

        } else if(strcmp(argv[i], "-Xcompactalways") == 0) {
            args->compact_specified = args->do_compact = TRUE;
#ifdef INLINING
        } else if(strcmp(argv[i], "-Xnoinlining") == 0) {
            /* Turning inlining off is equivalent to setting
               code memory to zero */
            args->codemem = 0;

        } else if(strncmp(argv[i], "-Xreplication:", 14) == 0) {
            char *pntr = argv[i] + 14;

            if(strcmp(pntr, "none") == 0)
                args->replication = INT_MAX;
            else
                if(strcmp(pntr, "always") == 0)
                    args->replication = 0;
                else
                    args->replication = strtol(pntr, NULL, 0);

        } else if(strncmp(argv[i], "-Xcodemem:", 10) == 0) {
            char *pntr = argv[i] + 10;

            args->codemem = strncmp(pntr, "unlimited", 10) == 0 ?
                INT_MAX : parseMemValue(pntr);

        } else if(strcmp(argv[i], "-Xshowreloc") == 0) {
            showRelocatability();
            status = 0;
            goto exit;
#endif
        } else {
            printf("Unrecognised command line option: %s\n", argv[i]);
            break;
        }
    }

    showUsage(argv[0]);

exit:
    exit(status);
}
Exemplo n.º 28
0
Arquivo: zip.c Projeto: Liam1206/jamvm
char *findArchiveEntry(char *pathname, ZipFile *zip, int *uncomp_len) {
    int offset, path_len, comp_len, extra_len, comp_method;
    unsigned char *decomp_buff, *comp_data;
    unsigned char *dir_entry;

    dir_entry = (unsigned char *)findArchiveDirEntry(pathname, zip);
    if(dir_entry == NULL)
        return NULL;

    /* Found the file -- the pathname points directly into the
       directory entry.  Read the values relative to it */

    /* Offset of the file entry relative to the start of the file */
    offset = READ_LE_INT(dir_entry + (CEN_FILE_LOCALHDR_OFFSET -
                                      CEN_FILE_HEADER_LEN));

    if((offset + LOC_FILE_HEADER_LEN) > zip->length)
        return NULL;

    /* Get the variable length part of the local file header */
    extra_len = READ_LE_SHORT(zip->data + offset + LOC_FILE_EXTRA_OFFSET);

    /* Get the path_len again */
    path_len = READ_LE_SHORT(dir_entry + (CEN_FILE_PATHLEN_OFFSET -
                                          CEN_FILE_HEADER_LEN));

    /* The file's length when uncompressed -- this is passed out */
    *uncomp_len = READ_LE_INT(dir_entry + (CEN_FILE_UNCOMPLEN_OFFSET -
                                           CEN_FILE_HEADER_LEN));

    /* The compressed file's length, i.e. the data size in the file */
    comp_len = READ_LE_INT(dir_entry + (CEN_FILE_COMPLEN_OFFSET -
                                        CEN_FILE_HEADER_LEN));

    /* How the file is compressed */
    comp_method = READ_LE_SHORT(dir_entry + (CEN_FILE_COMPMETH_OFFSET -
                                             CEN_FILE_HEADER_LEN));

    /* Calculate the data start */
    offset += LOC_FILE_HEADER_LEN + path_len + extra_len;

    /* Make sure we're not reading outside the file */
    if((offset + comp_len) > zip->length)
        return NULL;

    comp_data = zip->data + offset;
    decomp_buff = sysMalloc(*uncomp_len);

    switch(comp_method) {
        case COMP_STORED:
            /* Data isn't compressed, so just return it "as is" */
            memcpy(decomp_buff, comp_data, comp_len);
            return (char*)decomp_buff;

        case COMP_DEFLATED: {
            z_stream stream;
            int err;

            stream.next_in = comp_data;
            stream.avail_in = comp_len;
            stream.next_out = decomp_buff;
            stream.avail_out = *uncomp_len;

            stream.zalloc = Z_NULL;
            stream.zfree = Z_NULL;

            /* Use a negative windowBits value to stop the inflator looking
               for a header */
            if(inflateInit2(&stream, -MAX_WINDOW_BITS) != Z_OK)
                goto error;

            err = inflate(&stream, Z_SYNC_FLUSH);
            inflateEnd(&stream);

            if(err == Z_STREAM_END || (err == Z_OK && stream.avail_in == 0))
                return (char*)decomp_buff;
            break;
        }

        default:
            break;
    }

error:
    sysFree(decomp_buff);
    return NULL;
}
Exemplo n.º 29
0
Arquivo: jam.c Projeto: cfriedt/jamvm
int parseCommandLine(int argc, char *argv[], InitArgs *args) {
    Property props[argc-1];
    int is_jar = FALSE;
    int status = 0;
    int i;

    args->commandline_props = &props[0];

    for(i = 1; i < argc; i++) {
        if(*argv[i] != '-') {
            if(args->min_heap > args->max_heap) {
                printf("Minimum heap size greater than max!\n");
                status = 1;
                goto exit;
            }

            if(args->props_count) {
                args->commandline_props = sysMalloc(args->props_count *
                                                    sizeof(Property));
                memcpy(args->commandline_props, &props[0], args->props_count *
                                                           sizeof(Property));
            }

            if(is_jar) {
                args->classpath = argv[i];
                argv[i] = "jamvm/java/lang/JarLauncher";
            }

            return i;
        }

        switch(parseCommonOpts(argv[i], args, FALSE)) {
            case OPT_OK:
                break;
        	
            case OPT_ERROR:
        	status = 1;
        	goto exit;
        	
            case OPT_UNREC:
            default:
                if(strcmp(argv[i], "-?") == 0 ||
                   strcmp(argv[i], "-help") == 0) {
                    goto usage;

                } else if(strcmp(argv[i], "-X") == 0) {
                    showNonStandardOptions();
                    goto exit;

                } else if(strcmp(argv[i], "-version") == 0) {
                    showVersionAndCopyright();
                    goto exit;

                } else if(strcmp(argv[i], "-showversion") == 0) {
                    showVersionAndCopyright();
        
                } else if(strcmp(argv[i], "-fullversion") == 0) {
                    showFullVersion();
                    goto exit;

                } else if(strncmp(argv[i], "-verbose", 8) == 0) {
                    char *type = &argv[i][8];

                    if(*type == '\0' || strcmp(type, ":class") == 0)
                        args->verboseclass = TRUE;

                    else if(strcmp(type, ":gc") == 0 || strcmp(type, "gc") == 0)
                        args->verbosegc = TRUE;

                    else if(strcmp(type, ":jni") == 0)
                        args->verbosedll = TRUE;

                } else if(strcmp(argv[i], "-jar") == 0) {
                    is_jar = TRUE;

                } else if(strcmp(argv[i], "-classpath") == 0 ||
                          strcmp(argv[i], "-cp") == 0) {

                    if(i == argc - 1) {
                        printf("%s : missing path list\n", argv[i]);
                        goto exit;
                    }
                    args->classpath = argv[++i];

                } else if(strncmp(argv[i], "-Xbootclasspath/c:", 18) == 0) {
                    args->bootpath_c = argv[i] + 18;

                } else if(strncmp(argv[i], "-Xbootclasspath/v:", 18) == 0) {
                    args->bootpath_v = argv[i] + 18;

                /* Compatibility options */
                } else if(strcmp(argv[i], "-client") == 0 ||
                          strcmp(argv[i], "-server") == 0) {
                    /* Ignore */
                } else {
                    printf("Unrecognised command line option: %s\n", argv[i]);
                    status = 1;
                    goto usage;
                }
        }
    }

usage:
    showUsage(argv[0]);

exit:
    exit(status);
}