char *findArchiveDirEntry(char *pathname, ZipFile *zip) { char *found; /* Do not add if absent, no scavenge, not locked */ findHashEntry((*zip->dir_hash), pathname, found, FALSE, FALSE, FALSE); return found; }
CodeBlockHeader *findCodeBlock(CodeBlockHeader *block) { CodeBlockHeader *hashed_block; /* Search hash table. Add if absent, scavenge and locked */ findHashEntry(code_hash_table, block, hashed_block, TRUE, TRUE, TRUE); return hashed_block; }
char *findHashedUtf8(char *string, int add_if_absent) { char *interned; /* Add if absent, no scavenge, locked */ findHashEntry(hash_table, string, interned, add_if_absent, FALSE, TRUE); return interned; }
char *findHashedNativeMethodUtf8(char *string, int add_if_absent) { char *interned = NULL; findHashEntry(native_hash_table, string, interned, add_if_absent, FALSE, TRUE, native_name, TRUE); if(is_persistent){ OPC *ph_values = get_opc_ptr(); ph_values->utf8_native_hash_count = get_utf8_native_HC(); msync_nvm(); } return interned; }
Monitor *findMonitor(Object *obj) { uintptr_t lockword = LOCKWORD_READ(&obj->lock); if(lockword & SHAPE_BIT) return (Monitor*) (lockword & ~SHAPE_BIT); else { Monitor *mon; /* Add if absent, scavenge, locked */ findHashEntry(mon_cache, obj, mon, TRUE, TRUE, TRUE); return mon; } }
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; }