Skip to content

Commit

Permalink
Darwin i386 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nelhage committed Mar 12, 2015
1 parent d52384c commit a9068be
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
24 changes: 22 additions & 2 deletions arch.h
Expand Up @@ -105,16 +105,36 @@ static uint8_t *arch_get_bp(ucontext_t *uctx) {
static uint8_t *arch_get_ax(ucontext_t *uctx) {
return (uint8_t*)uctx->uc_mcontext->__ss.__rax;
}
extern "C" void bt_continue(void);

extern "C" void bt_continue(void);
static uint8_t *arch_alloc_code_buffer(size_t size) {
void *hint = (void*)((uintptr_t)bt_continue - (1ul<<32));
uint8_t *alloc = (uint8_t*)mmap(hint, size,
PROT_READ|PROT_WRITE|PROT_EXEC,
MAP_PRIVATE|MAP_ANON, -1, 0);
if (alloc == (uint8_t*)MAP_FAILED)
return NULL;
if (((uintptr_t)alloc - (uintptr_t)bt_continue) > (uintptr_t)(uint32_t)-1)
if (((uintptr_t)alloc - (uintptr_t)bt_continue) > (uintptr_t)(uint32_t)-1)
return NULL;
return alloc;
}

#else
static uint8_t *arch_get_ip(ucontext_t *uctx) {
return (uint8_t*)uctx->uc_mcontext->__ss.__eip;
}
static uint8_t *arch_get_bp(ucontext_t *uctx) {
return (uint8_t*)uctx->uc_mcontext->__ss.__ebp;
}
static uint8_t *arch_get_ax(ucontext_t *uctx) {
return (uint8_t*)uctx->uc_mcontext->__ss.__eax;
}

static uint8_t *arch_alloc_code_buffer(size_t size) {
uint8_t *alloc = (uint8_t*)mmap(NULL, size,
PROT_READ|PROT_WRITE|PROT_EXEC,
MAP_PRIVATE|MAP_ANON, -1, 0);
if (alloc == (uint8_t*)MAP_FAILED)
return NULL;
return alloc;
}
Expand Down
2 changes: 1 addition & 1 deletion bt_helper_32.S
Expand Up @@ -67,7 +67,7 @@ _(bt_continue):
jne miss
movl 8(%ecx), %ecx

cmp $0, 132(%ebp) /* Check CPU.halt */
cmpl $0, 132(%ebp) /* Check CPU.halt */
jnz miss

jmp *%ecx
Expand Down

0 comments on commit a9068be

Please sign in to comment.