ZarfileVFS::ZarfileVFS(MallocFactory *mf, SyncFactory* sf, XaxVFSHandleIfc *zarfile_hdl, ZLCEmit *ze) { ptable = NULL; strtable = NULL; chdr = NULL; chdr_mutex = NULL; this->mf = mf; this->zarfile_hdl = zarfile_hdl; this->ze = ze; lost_mmap_opportunities_misaligned = 0; exploited_mmap_opportunities = 0; XfsErr err; zarfile_hdl->read(&err, &zhdr, sizeof(zhdr), 0); if (err != XFS_NO_ERROR) { goto fail; } if (zhdr.z_magic != Z_MAGIC) { goto fail; } if (zhdr.z_version != Z_VERSION) { goto fail; } if (zhdr.z_path_entsz != sizeof(ZF_Phdr)) { goto fail; } uint32_t ptable_size; ptable_size = sizeof(ZF_Phdr)*zhdr.z_path_num; ptable = (ZF_Phdr*) mf_malloc(mf, ptable_size); zarfile_hdl->read(&err, ptable, ptable_size, zhdr.z_path_off); if (err != XFS_NO_ERROR) { goto fail; } strtable = (char*) mf_malloc(mf, zhdr.z_strtab_len); zarfile_hdl->read(&err, strtable, zhdr.z_strtab_len, zhdr.z_strtab_off); if (err != XFS_NO_ERROR) { goto fail; } if (strtable[zhdr.z_strtab_len-1]!='\0') { goto fail; } // Read in an in-memory copy of all the chdrs. We update it when we // give away chunks via fast_mmap, so we need to make sure all // accesses of this zarfile use the in-memory (updated) chdrs. int chdr_len; chdr_len = sizeof(ZF_Chdr)*zhdr.z_chunktab_count; this->chdr = (ZF_Chdr*) mf_malloc(mf, chdr_len); chdr_mutex = sf->new_mutex(false); err = XFS_DIDNT_SET_ERROR; zarfile_hdl->read(&err, this->chdr, chdr_len, zhdr.z_chunktab_off); if (err != XFS_NO_ERROR) { goto fail; } return; fail: if (ptable!=NULL) { mf_free(mf, ptable); ptable=NULL; } if (strtable!=NULL) { mf_free(mf, strtable); strtable=NULL; } zhdr.z_path_num = 0; // cause lookups to fail. }
bool KeyValClient::insert(KeyVal* kv) { int req_size = sizeof(KVRequest) + kv->val.len; KVRequest* req = (KVRequest*)mf_malloc(this->mf, req_size); req->type = TYPE_INSERT; req->kv = *kv; uint32_t hash131 = hash_buf(kv->val.bytes, kv->val.len); #define READBACK_CHECK 1 #if READBACK_CHECK ZLC_TERSE(ze, "Insert val len %d hash 0x%x\n",, kv->val.len, hash131); #endif // READBACK_CHECK lite_memcpy(req->kv.val.bytes, kv->val.bytes, kv->val.len); bool rc = this->sock->sendto(this->server, req, req_size); if (!rc) { return false; } ZeroCopyBuf* reply = this->sock->recvfrom(this->server); lite_assert(reply!=NULL); lite_assert(reply->len()==sizeof(uint32_t)); lite_assert(((uint32_t*)reply->data())[0] == hash131); delete reply; mf_free(this->mf, req); return true; }
void corefile_add_segment(CoreFile *c, uint32_t vaddr, void *bytes, int size) { CoreSegment *seg = (CoreSegment *) mf_malloc(c->mf, sizeof(CoreSegment)); seg->vaddr = vaddr; seg->bytes = bytes; seg->size = size; linked_list_insert_tail(&c->segments, seg); }
XUDSMessage::XUDSMessage(MallocFactory *mf, const void *content, uint32_t count) { lite_assert(count>0); this->content = (uint8_t*) mf_malloc(mf, count); this->count = count; this->offset = 0; this->mf = mf; memcpy(this->content, content, count); }
ValidatedZCB::ValidatedZCB(ZCache* cache, ZeroCopyBuf* buffer, AbstractSocket* socket) { this->socket = socket; this->buffer = buffer; this->cache = cache; uint32_t num_hashes = buffer->len() / ZFTP_BLOCK_SIZE-1 + 1; // +1 for possible partial block this->hashes = // new hash_t[num_hashes]; (hash_t*) mf_malloc(cache->mf, sizeof(hash_t) * num_hashes); memset(this->hashes, 0, sizeof(hash_t) * num_hashes); }
int map_construct(map_t **map_ptr) { int err; if(unlikely((err = mf_malloc(sizeof(map_t), (void**)map_ptr)))) { return err; } map_t *map = *map_ptr; for(int i = 0; i < HASHTABLE_SIZE; i++ ) { map->cache[i].valid = false; } return skiplist_construct(24, &map->skiplist); }
Value* KeyValClient::lookup(Key* key) { KVRequest req; req.type = TYPE_LOOKUP; req.kv.key = *key; bool rc = this->sock->sendto(this->server, &req, sizeof(KVRequest)); if (!rc) { return NULL; } ZeroCopyBuf* buf = this->sock->recvfrom(this->server); if (buf == NULL) { ZLC_TERSE(ze, "WARNING: timeout contacting KeyVal server\n"); return NULL; } Value* val = (Value*) buf->data(); #if READBACK_CHECK { uint32_t bytes131hash = hash_buf(val->bytes, val->len); ZLC_TERSE(ze, "lookup val len %d hash 0x%x\n",, val->len, bytes131hash); } #endif // READBACK_CHECK Value* new_val = (Value*) mf_malloc(this->mf, sizeof(Value)+val->len); lite_memcpy(new_val, val, sizeof(Value)+val->len); delete buf; #if READBACK_CHECK { uint32_t bytes131hash = hash_buf(new_val->bytes, new_val->len); ZLC_TERSE(ze, "lookup new_val len %d hash 0x%x\n",, new_val->len, bytes131hash); } #endif // READBACK_CHECK return new_val; }
void corefile_add_thread(CoreFile *c, Core_x86_registers *regs, int thread_id) { CoreNote_Regs *note_regs = mf_malloc(c->mf, sizeof(CoreNote_Regs)); lite_memset(note_regs, 0, sizeof(*note_regs)); note_regs->note.nhdr.n_namesz = 5; note_regs->note.nhdr.n_descsz = sizeof(CoreNote_Regs) - sizeof(NoteHeader); note_regs->note.nhdr.n_type = NT_PRSTATUS; //strcpy(note_regs.name, "CORE"); // Avoid VS warning that strcpy is unsafe note_regs->note.name[0] = 'C'; note_regs->note.name[1] = 'O'; note_regs->note.name[2] = 'R'; note_regs->note.name[3] = 'E'; note_regs->note.name[4] = '\0'; lite_memcpy(¬e_regs->desc.regs, regs, sizeof(Core_x86_registers)); note_regs->desc.pid = thread_id; note_regs->desc.ppid = 0x101; note_regs->desc.pgrp = 0x102; note_regs->desc.sid = 0x103; linked_list_insert_tail(&c->threads, note_regs); }