int32_t execute_common_handle(struct data_buffer* dbuf,int socket_fd,MEM_POOL* mem_pool) { struct data_buffer rbuf; //发数据包 if(socket_write(socket_fd,dbuf->data,dbuf->data_len) <= 0) return -1; //接受命名 memset(&rbuf,0,sizeof(struct data_buffer)); rbuf.data_len = sizeof(uint32_t); rbuf.data = (uint8_t *)mem_pool_malloc(mem_pool,sizeof(uint32_t)); rbuf.size = rbuf.data_len; if(socket_read(socket_fd,rbuf.data,sizeof(uint32_t)) <= 0) return -1; rbuf.data_len = read_int32(&rbuf); rbuf.data = (uint8_t *)mem_pool_malloc(mem_pool,rbuf.data_len); rbuf.rpos = 0; rbuf.size = rbuf.data_len; if(socket_read(socket_fd,rbuf.data,rbuf.data_len) <= 0) return -1; rbuf.rpos += MESSAGE_HEAD_LEN; uint16_t type = message_type(&rbuf); if (type != MT_DC_EXE_RS) return -1; return read_int32(&rbuf); }
int SCOPE replay_rt_sigaction(const struct syscall_regs * regs) { int32_t eax = read_int32(); if (eax == 0) { int sigsetsize = read_int32(); ASSERT(sigsetsize == regs->esi, regs, ""); ASSERT(sigsetsize == sizeof(k_sigset_t), regs, "!@@#1\n"); uintptr_t oact = read_uint32(); ASSERT(oact == regs->edx, regs, "oact inconsistent: 0x%x != 0x%x\n", regs->edx, oact); uintptr_t act = read_uint32(); ASSERT(act == regs->ecx, regs, "act inconsistent: 0x%x != 0x%x\n", regs->ecx, act); if (oact != 0) read_mem(oact, sizeof(struct k_sigaction)); /* we need trace sighandler even in replay */ if (act != 0) __dup_mem(&state_vector.sigactions[regs->ebx], act, sizeof(struct k_sigaction)); } return eax; }
struct object_class_audioclip* object_class_audioclip_load(unsigned char* data, size_t start, size_t size) { size_t offset = start; struct object_class_audioclip* object_class = (struct object_class_audioclip*)calloc(1, sizeof(*object_class)); offset += read_int32(data, offset, &object_class->name_len, true); if (object_class->name_len < 0 || object_class->name_len >(int)size) { free(object_class); return NULL; } offset += read_buffer(data, offset, &object_class->name, object_class->name_len); offset = (offset + 3) / 4 * 4; offset += read_int32(data, offset, &object_class->format, true); offset += read_int32(data, offset, &object_class->type, true); offset += read_byte(data, offset, &object_class->is_3d); offset += read_byte(data, offset, &object_class->use_hardware); offset = (offset + 3) / 4 * 4; offset += read_int32(data, offset, &object_class->stream, true); offset += read_int32(data, offset, &object_class->data_size, true); offset += read_buffer(data, offset, &object_class->data, object_class->data_size); return object_class; }
static void process(ErlDrvData handle, ErlIOVec *ev) { spidermonkey_drv_t *dd = (spidermonkey_drv_t *) handle; char *data = ev->binv[1]->orig_bytes; char *command = read_command(&data); if (strncmp(command, "ij", 2) == 0) { char *call_id = read_string(&data); int thread_stack = read_int32(&data); if (thread_stack < 8) { thread_stack = 8; } thread_stack = thread_stack * (1024 * 1024); int heap_size = read_int32(&data) * (1024 * 1024); dd->vm = sm_initialize(thread_stack, heap_size); send_ok_response(dd, call_id); driver_free(call_id); } else { js_call *call_data = (js_call *) driver_alloc(sizeof(js_call)); call_data->driver_data = dd; call_data->args = ev->binv[1]; driver_binary_inc_refc(call_data->args); ErlDrvPort port = dd->port; unsigned long thread_key = (unsigned long) port; driver_async(dd->port, (unsigned int *) &thread_key, (asyncfun) run_js, (void *) call_data, NULL); } driver_free(command); }
int SCOPE replay_time(const struct syscall_regs * regs) { int32_t eax = read_int32(); int32_t ebx = read_int32(); ASSERT(ebx == regs->ebx, regs, ""); if (ebx != 0) read_mem(ebx, sizeof(time_t)); return eax; }
static void read_binary(parse_info *info, numbuf_t *buf, int wide) { if (wide <= 4) read_int32(info, &buf->i32, wide); else { uint32_t lo, hi; /* in big endian */ read_int32(info, &hi, 4); read_int32(info, &lo, wide - 4); buf->i64 = info->endian == BIG_ENDIAN ? ((uint64_t)hi << ((wide-4)<<3)) | lo : ((uint64_t)lo << 32) | hi; } }
static bool checkEquality(char *jqBase, int32 jqPos, int32 type, JsonbValue *jb) { int len; if (type == jqiAny) return true; if (jb->type == jbvBinary) return false; if (jb->type != type /* see enums */) return false; switch(type) { case jqiNull: return true; case jqiString: read_int32(len, jqBase, jqPos); return (len == jb->val.string.len && memcmp(jb->val.string.val, jqBase + jqPos, len) == 0); case jqiBool: read_byte(len, jqBase, jqPos); return (jb->val.boolean == (bool)len); case jqiNumeric: return (compareNumeric((Numeric)(jqBase + jqPos), jb->val.numeric) == 0); default: elog(ERROR,"Wrong state"); } }
void test_decompress(FILE* outFp, FILE* inpFp) { static char decBuf[DECODE_RING_BUFFER]; int decOffset = 0; LZ4_streamDecode_t lz4StreamDecode_body = { 0 }; LZ4_streamDecode_t* lz4StreamDecode = &lz4StreamDecode_body; for(;;) { int cmpBytes = 0; char cmpBuf[LZ4_COMPRESSBOUND(MESSAGE_MAX_BYTES)]; { const size_t r0 = read_int32(inpFp, &cmpBytes); if(r0 != 1 || cmpBytes <= 0) break; const size_t r1 = read_bin(inpFp, cmpBuf, cmpBytes); if(r1 != (size_t) cmpBytes) break; } { char* const decPtr = &decBuf[decOffset]; const int decBytes = LZ4_decompress_safe_continue( lz4StreamDecode, cmpBuf, decPtr, cmpBytes, MESSAGE_MAX_BYTES); if(decBytes <= 0) break; decOffset += decBytes; write_bin(outFp, decPtr, decBytes); // Wraparound the ringbuffer offset if(decOffset >= DECODE_RING_BUFFER - MESSAGE_MAX_BYTES) decOffset = 0; } } }
int SCOPE replay__newselect(const struct syscall_regs * regs) { int32_t eax = read_int32(); int n; uint32_t inp; uint32_t outp; uint32_t exp; read_obj(n); read_obj(inp); read_obj(outp); read_obj(exp); ASSERT(n == regs->ebx, regs, ""); ASSERT(inp == regs->ecx, regs, ""); ASSERT(outp == regs->edx, regs, ""); ASSERT(exp == regs->esi, regs, ""); int fd_bytes = FDS_BYTES(n); if (inp != 0) read_mem(inp, fd_bytes); if (outp != 0) read_mem(outp, fd_bytes); if (exp != 0) read_mem(exp, fd_bytes); return eax; }
int SCOPE replay_rt_sigprocmask(const struct syscall_regs * regs) { int32_t ret = read_int32(); if (ret == 0) { int sigsetsize = read_int32(); ASSERT(sigsetsize == regs->esi, regs, ""); if (sigsetsize == sizeof(k_sigset_t)) { int oset = read_int32(); ASSERT(oset == regs->edx, regs, ""); if (oset) read_mem(oset, sigsetsize); } } return ret; }
static int32_t SPICE_GNUC_UNUSED consume_int32(uint8_t **ptr) { int32_t val; val = read_int32(*ptr); *ptr += 4; return val; }
struct slave_sync_res *parse_master_response(struct mile_packet *packet) { struct data_buffer* rbuf = packet->rbuf; struct mile_message_header header; if (NULL == rbuf) { log_error( "read buffer is empty"); return NULL; } header.version_major = read_int8(rbuf); header.version_minor = read_int8(rbuf); header.message_type = read_int16(rbuf); header.message_id = read_int32(rbuf); log_debug( "数据包包头信息 -- 主版本号: %d, 小版本号: %d, 消息类型: 0x%x, 消息id: %d", header.version_major, header.version_minor, header.message_type, header.message_id); if (MT_DM_RS != header.message_type) { log_error( "unknown message type: %hu", header.message_type); return NULL; } // read body struct slave_sync_res *res = (struct slave_sync_res *) (rbuf->data + rbuf->rpos); rbuf->rpos += res->len + sizeof(struct slave_sync_res); if (rbuf->rpos > rbuf->data_len) { log_error( "wrong packet lenght."); return NULL; } return res; }
SCOPE int replay_tty_ioctl(int fd, uint32_t cmd, uint32_t arg, const struct syscall_regs * regs) { /* write eax is done in ioctl.c */ int32_t eax = read_int32(); switch (cmd) { case TCGETS: if (arg != 0) read_mem(arg, sizeof(struct termios)); return eax; case TIOCGWINSZ: if (arg != 0) read_mem(arg, sizeof(struct winsize)); return eax; case FIONREAD: if (arg != 0) read_mem(arg, sizeof(int)); return eax; case FIONBIO: return eax; case TCGETA: if (arg != 0) read_mem(arg, sizeof(struct termio)); return eax; case TCSETA: return eax; default: INJ_WARNING("doesn't know such tty ioctl: 0x%x\n", cmd); __exit(-1); } return eax; }
const char* read_string_val(bson_iter_t* it) { int32_t sz = read_int32(it); const char* p = (const char*)it->ptr; it->ptr += sz; it->size += sz; return p; }
int32_t execute_segment_stat_handle(struct data_buffer* dbuf,int socket_fd,MEM_POOL* mem_pool) { struct data_buffer rbuf; //发数据包 if(socket_write(socket_fd,dbuf->data,dbuf->data_len) <= 0) return -1; //接受命名 memset(&rbuf,0,sizeof(struct data_buffer)); rbuf.data_len = sizeof(uint32_t); rbuf.size = rbuf.data_len; rbuf.data = (uint8_t *)mem_pool_malloc(mem_pool,sizeof(uint32_t)); if(socket_read(socket_fd,rbuf.data,rbuf.data_len) <= 0) return -1; rbuf.data_len = read_int32(&rbuf); rbuf.data = (uint8_t *)mem_pool_malloc(mem_pool,rbuf.data_len); rbuf.rpos = 0; rbuf.size = rbuf.data_len; if(socket_read(socket_fd,rbuf.data,rbuf.data_len) <= 0) return -1; rbuf.rpos += MESSAGE_HEAD_LEN; uint16_t type = message_type(&rbuf); if (type != MT_DC_STAT_RS) return -1; uint16_t segment_count = read_int16(&rbuf); uint16_t i; fprintf(stderr,"%-20s%-20s%-20s%-20s%-20s%-20s%-20s\n","SEGMENT_ID","CREATE_TIME","MODIFY_TIME","CHECKPOINT_TIME","FLAG","ROW_COUNT","DEL_COUNT"); for(i=0; i<segment_count; i++) { fprintf(stderr,"%-20u",read_int16(&rbuf)); fprintf(stderr,"%-20llu",read_int64(&rbuf)); fprintf(stderr,"%-20llu",read_int64(&rbuf)); fprintf(stderr,"%-20llu",read_int64(&rbuf)); fprintf(stderr,"%-20u",read_int8(&rbuf)); fprintf(stderr,"%-20u",read_int32(&rbuf)); fprintf(stderr,"%-20u\n",read_int32(&rbuf)); } return 0; }
int SCOPE replay_pread64(const struct syscall_regs * regs) { int32_t eax = read_int32(); if (eax > 0) read_mem(regs->ecx, eax); return eax; }
static inline void init_w32 (uint32_t * W, const uint32_t * block) { int t; for (t = 0; t < 16; t++) W [t] = read_int32 ((char *) (block + t)); for (t = 16; t < 80; t++) W [t] = rotl32 (1, W [t - 3] ^ W [t - 8] ^ W [t - 14] ^ W [t - 16]); }
int SCOPE replay_lstat64(const struct syscall_regs * regs) { int32_t eax = read_int32(); if (eax >= 0) { read_mem(regs->ecx, sizeof(struct stat64)); } return eax; }
char* objectinfo_getname(unsigned char* data, size_t start, size_t size) { int name_len; size_t offset = start; offset += read_int32(data, offset, &name_len, true); if (name_len >= 0 && name_len <= (int)size) return strndup((char*)data + offset, name_len); return strdup(""); }
/* Reads a string index, looks up the string and returns it. Bounds * checks the string heap index too. */ static MVMString * get_heap_string(MVMThreadContext *tc, MVMCompUnit *cu, ReaderState *rs, MVMuint8 *buffer, size_t offset) { MVMuint32 heap_index = read_int32(buffer, offset); if (heap_index >= cu->body.num_strings) { if (rs) cleanup_all(tc, rs); MVM_exception_throw_adhoc(tc, "String heap index beyond end of string heap"); } return MVM_cu_string(tc, cu, heap_index); }
static jl_fptr_t jl_deserialize_fptr(ios_t *s) { int fptr = read_int32(s); if (fptr == 0) return NULL; void **pbp = ptrhash_bp(&id_to_fptr, (void*)(ptrint_t)fptr); if (*pbp == HT_NOTFOUND) jl_error("unknown function pointer ID"); return *(jl_fptr_t*)pbp; }
void load_exceptions() { dbFILE *f; int i; uint16 n; uint16 tmp16; uint32 tmp32; if (! (f = open_db(s_OperServ, ExceptionDBName, "r", EXCEPTION_VERSION))) return; switch (i = get_file_version(f)) { case 9: case 8: case 7: SAFE(read_int16(&n, f)); nexceptions = n; exceptions = scalloc(sizeof(Exception) * nexceptions, 1); if (!nexceptions) { close_db(f); return; } for (i = 0; i < nexceptions; i++) { SAFE(read_string(&exceptions[i].mask, f)); SAFE(read_int16(&tmp16, f)); exceptions[i].limit = tmp16; SAFE(read_buffer(exceptions[i].who, f)); SAFE(read_string(&exceptions[i].reason, f)); SAFE(read_int32(&tmp32, f)); exceptions[i].time = tmp32; SAFE(read_int32(&tmp32, f)); exceptions[i].expires = tmp32; } break; default: fatal("Unsupported version (%d) on %s", i, ExceptionDBName); } /* switch (ver) */ close_db(f); }
int32_t execute_index_stat_handle(struct data_buffer* dbuf,int socket_fd,MEM_POOL* mem_pool) { struct data_buffer rbuf; //发一个数据包长度 if(socket_write(socket_fd,dbuf->data,dbuf->data_len) <= 0) return -1; //接受命名 memset(&rbuf,0,sizeof(struct data_buffer)); rbuf.data_len = sizeof(uint32_t); rbuf.size = rbuf.data_len; rbuf.data = (uint8_t *)mem_pool_malloc(mem_pool,sizeof(uint32_t)); if(socket_read(socket_fd,rbuf.data,rbuf.data_len) <= 0) return -1; rbuf.data_len = read_int32(&rbuf); rbuf.data = (uint8_t *)mem_pool_malloc(mem_pool,rbuf.data_len); rbuf.rpos = 0; rbuf.size = rbuf.data_len; if(socket_read(socket_fd,rbuf.data,rbuf.data_len) <= 0) return -1; rbuf.rpos += MESSAGE_HEAD_LEN; uint16_t type = message_type(&rbuf); if (type != MT_DC_STAT_RS) return -1; uint16_t field_count = read_int16(&rbuf); uint16_t i; char* field_name = NULL; fprintf(stderr,"%-20s%-20s%-20s%-20s\n","FIELD_NAME","INDEX_TYPE","DATA_TYPE","FLAG"); uint8_t j; uint8_t index_num; for(i=0; i<field_count; i++) { field_name = read_cstring(&rbuf,mem_pool); index_num = read_int8(&rbuf); for(j=0;j < index_num; j++) { fprintf(stderr,"%-20s",field_name); fprintf(stderr,"%-20u",read_int8(&rbuf)); fprintf(stderr,"%-20u",read_int8(&rbuf)); fprintf(stderr,"%-20u\n",read_int8(&rbuf)); } } return 0; }
int SCOPE replay_close(const struct syscall_regs * regs) { /* open is real, the close must be real... */ int32_t eax = read_int32(); /* don't check retval of close, * the desire fd may be a socket or pipe that not opened in 'open' * */ #ifdef IN_INJECTOR INTERNAL_SYSCALL(close, 1, regs->ebx); #endif return eax; }
static int32 ckd_read_int32(FILE *fp) { if (feof(fp)) { fflush(stdout); fprintf(stderr, "%s(%d): ERROR premature EOF\n", __FILE__, __LINE__); fflush(stderr); exit(1); } return read_int32(fp); }
/* Loads the SC dependencies list. */ static void deserialize_sc_deps(MVMThreadContext *tc, MVMCompUnit *cu, ReaderState *rs) { MVMCompUnitBody *cu_body = &cu->body; MVMuint32 i, sh_idx; MVMuint8 *pos; /* Allocate SC lists in compilation unit. */ cu_body->scs = MVM_malloc(rs->expected_scs * sizeof(MVMSerializationContext *)); cu_body->scs_to_resolve = MVM_malloc(rs->expected_scs * sizeof(MVMSerializationContextBody *)); cu_body->sc_handle_idxs = MVM_malloc(rs->expected_scs * sizeof(MVMint32)); cu_body->num_scs = rs->expected_scs; /* Resolve all the things. */ pos = rs->sc_seg; for (i = 0; i < rs->expected_scs; i++) { MVMSerializationContextBody *scb; MVMString *handle; /* Grab string heap index. */ ensure_can_read(tc, cu, rs, pos, 4); sh_idx = read_int32(pos, 0); pos += 4; /* Resolve to string. */ if (sh_idx >= cu_body->num_strings) { cleanup_all(tc, rs); MVM_exception_throw_adhoc(tc, "String heap index beyond end of string heap"); } cu_body->sc_handle_idxs[i] = sh_idx; handle = MVM_cu_string(tc, cu, sh_idx); /* See if we can resolve it. */ uv_mutex_lock(&tc->instance->mutex_sc_weakhash); MVM_string_flatten(tc, handle); MVM_HASH_GET(tc, tc->instance->sc_weakhash, handle, scb); if (scb && scb->sc) { cu_body->scs_to_resolve[i] = NULL; MVM_ASSIGN_REF(tc, &(cu->common.header), cu_body->scs[i], scb->sc); } else { if (!scb) { scb = MVM_calloc(1, sizeof(MVMSerializationContextBody)); scb->handle = handle; MVM_HASH_BIND(tc, tc->instance->sc_weakhash, handle, scb); MVM_sc_add_all_scs_entry(tc, scb); } cu_body->scs_to_resolve[i] = scb; cu_body->scs[i] = NULL; } uv_mutex_unlock(&tc->instance->mutex_sc_weakhash); } }
int SCOPE replay_wait4(const struct syscall_regs * regs) { int32_t eax = read_int32(); uintptr_t stat_addr = read_uint32(); ASSERT(stat_addr == regs->ecx, regs, "stat_addr inconsistent\n"); if (stat_addr != 0) read_mem(stat_addr, sizeof(int)); uintptr_t ru = read_uint32(); ASSERT(ru == regs->esi, regs, "ru inconsistent\n"); if (ru != 0) read_mem(ru, sizeof(struct rusage)); return eax; }
static bool executeArrayOp(char *jqBase, int32 jqPos, int32 type, int32 op, JsonbValue *jb) { int32 i, nelems, *arrayPos; int32 r; JsonbIterator *it; JsonbValue v; int32 nres = 0, nval = 0; if (jb->type != jbvBinary) return false; if (type != jqiArray) return false; read_int32(nelems, jqBase, jqPos); arrayPos = (int32*)(jqBase + jqPos); it = JsonbIteratorInit(jb->val.binary.data); while((r = JsonbIteratorNext(&it, &v, true)) != WJB_DONE) { if (r == WJB_BEGIN_ARRAY) nval = v.val.array.nElems; if (r == WJB_ELEM) { bool res = false; for(i=0; i<nelems; i++) { if (executeExpr(jqBase, arrayPos[i], jqiEqual, &v)) { if (op == jqiOverlap) return true; nres++; res = true; break; } } } } if (op == jqiContains) return (nres == nelems && nelems > 0); if (op == jqiContained) return (nres == nval && nval > 0); return false; }
void transport_fds(int rfd, int wfd) { payload_size_t _; int n; char *buf; n = read_int32(rfd, &_); assert(0 <= n); buf = (char *)alloca(sizeof(char) * n); read_or_die(rfd, buf, n); write_int32(wfd, n); write_or_die(wfd, buf, n); }
// Any string read using this function must be freed // using driver_free later char *read_string(char **data) { int length = read_int32(data); char *buf = NULL; if (length > 0) { buf = (char *) driver_alloc(length + 1); memset(buf, 0, length + 1); memcpy(buf, (const char *) *data, length); (*data) += length; } else { buf = (char *) driver_alloc(1); memset(buf, 0, 1); } return buf; }