static void do_realloc( struct x86_function *p ) { if (p->store == p->error_overflow) { p->csr = p->store; } else if (p->size == 0) { p->size = 1024; p->store = rtasm_exec_malloc(p->size); p->csr = p->store; } else { uintptr_t used = pointer_to_uintptr( p->csr ) - pointer_to_uintptr( p->store ); unsigned char *tmp = p->store; p->size *= 2; p->store = rtasm_exec_malloc(p->size); if (p->store) { memcpy(p->store, tmp, used); p->csr = p->store + used; } else { p->csr = p->store; } rtasm_exec_free(tmp); } if (p->store == NULL) { p->store = p->csr = p->error_overflow; p->size = sizeof(p->error_overflow); } }
/** * Append instruction to instruction buffer. Grow buffer if out of room. */ static void emit_instruction(struct ppc_function *p, uint32_t inst_bits) { if (!p->store) return; /* out of memory, drop the instruction */ if (p->num_inst == p->max_inst) { /* allocate larger buffer */ uint32_t *newbuf; p->max_inst *= 2; /* 2x larger */ newbuf = rtasm_exec_malloc(p->max_inst * PPC_INST_SIZE); if (newbuf) { memcpy(newbuf, p->store, p->num_inst * PPC_INST_SIZE); } rtasm_exec_free(p->store); p->store = newbuf; if (!p->store) { /* out of memory */ p->num_inst = 0; return; } } p->store[p->num_inst++] = inst_bits; }
void x86_release_func( struct x86_function *p ) { if (p->store && p->store != p->error_overflow) rtasm_exec_free(p->store); p->store = NULL; p->csr = NULL; p->size = 0; }
void ppc_release_func(struct ppc_function *p) { assert(p->num_inst <= p->max_inst); if (p->store != NULL) { rtasm_exec_free(p->store); } p->store = NULL; }