static load_return_t load_unixthread( struct thread_command *tcp, thread_t thread, int64_t slide, load_result_t *result ) { load_return_t ret; int customstack =0; if (tcp->cmdsize < sizeof(*tcp)) return (LOAD_BADMACHO); if (result->thread_count != 0) { printf("load_unixthread: already have a thread!"); return (LOAD_FAILURE); } if (thread == THREAD_NULL) return (LOAD_SUCCESS); ret = load_threadstack(thread, (uint32_t *)(((vm_offset_t)tcp) + sizeof(struct thread_command)), tcp->cmdsize - sizeof(struct thread_command), &result->user_stack, &customstack); if (ret != LOAD_SUCCESS) return(ret); if (customstack) result->customstack = 1; else result->customstack = 0; result->user_stack += slide; ret = load_threadentry(thread, (uint32_t *)(((vm_offset_t)tcp) + sizeof(struct thread_command)), tcp->cmdsize - sizeof(struct thread_command), &result->entry_point); if (ret != LOAD_SUCCESS) return(ret); result->entry_point += slide; ret = load_threadstate(thread, (uint32_t *)(((vm_offset_t)tcp) + sizeof(struct thread_command)), tcp->cmdsize - sizeof(struct thread_command)); if (ret != LOAD_SUCCESS) return (ret); result->unixproc = TRUE; result->thread_count++; return(LOAD_SUCCESS); }
static load_return_t load_unixthread( struct thread_command *tcp, thread_t thread, load_result_t *result ) { load_return_t ret; int customstack =0; if (result->thread_count != 0) { printf("load_unixthread: already have a thread!"); return (LOAD_FAILURE); } ret = load_threadstack(thread, (unsigned long *)(((vm_offset_t)tcp) + sizeof(struct thread_command)), tcp->cmdsize - sizeof(struct thread_command), &result->user_stack, &customstack); if (ret != LOAD_SUCCESS) return(ret); if (customstack) result->customstack = 1; else result->customstack = 0; ret = load_threadentry(thread, (unsigned long *)(((vm_offset_t)tcp) + sizeof(struct thread_command)), tcp->cmdsize - sizeof(struct thread_command), &result->entry_point); if (ret != LOAD_SUCCESS) return(ret); ret = load_threadstate(thread, (unsigned long *)(((vm_offset_t)tcp) + sizeof(struct thread_command)), tcp->cmdsize - sizeof(struct thread_command)); if (ret != LOAD_SUCCESS) return (ret); result->unixproc = TRUE; result->thread_count++; return(LOAD_SUCCESS); }
static load_return_t load_unixthread( struct thread_command *tcp, thread_t thread, int64_t slide, load_result_t *result ) { load_return_t ret; int customstack =0; mach_vm_offset_t addr; if (tcp->cmdsize < sizeof(*tcp)) return (LOAD_BADMACHO); if (result->thread_count != 0) { printf("load_unixthread: already have a thread!"); return (LOAD_FAILURE); } if (thread == THREAD_NULL) return (LOAD_SUCCESS); ret = load_threadstack(thread, (uint32_t *)(((vm_offset_t)tcp) + sizeof(struct thread_command)), tcp->cmdsize - sizeof(struct thread_command), &addr, &customstack); if (ret != LOAD_SUCCESS) return(ret); /* LC_UNIXTHREAD optionally specifies stack size and location */ if (customstack) { result->prog_stack_size = 0; /* unknown */ result->prog_allocated_stack = 1; } else { result->prog_allocated_stack = 0; result->prog_stack_size = 0; result->user_stack_size = MAXSSIZ; } /* The stack slides down from the default location */ result->user_stack = addr; result->user_stack -= slide; ret = load_threadentry(thread, (uint32_t *)(((vm_offset_t)tcp) + sizeof(struct thread_command)), tcp->cmdsize - sizeof(struct thread_command), &addr); if (ret != LOAD_SUCCESS) return(ret); result->entry_point = addr; result->entry_point += slide; ret = load_threadstate(thread, (uint32_t *)(((vm_offset_t)tcp) + sizeof(struct thread_command)), tcp->cmdsize - sizeof(struct thread_command)); if (ret != LOAD_SUCCESS) return (ret); result->unixproc = TRUE; result->thread_count++; return(LOAD_SUCCESS); }
static load_return_t load_thread( struct thread_command *tcp, thread_t thread, load_result_t *result ) { kern_return_t kret; load_return_t lret; task_t task; int customstack=0; task = get_threadtask(thread); /* if count is 0; same as thread */ if (result->thread_count != 0) { kret = thread_create(task, &thread); if (kret != KERN_SUCCESS) return(LOAD_RESOURCE); thread_deallocate(thread); } lret = load_threadstate(thread, (unsigned long *)(((vm_offset_t)tcp) + sizeof(struct thread_command)), tcp->cmdsize - sizeof(struct thread_command)); if (lret != LOAD_SUCCESS) return (lret); if (result->thread_count == 0) { lret = load_threadstack(thread, (unsigned long *)(((vm_offset_t)tcp) + sizeof(struct thread_command)), tcp->cmdsize - sizeof(struct thread_command), &result->user_stack, &customstack); if (customstack) result->customstack = 1; else result->customstack = 0; if (lret != LOAD_SUCCESS) return(lret); lret = load_threadentry(thread, (unsigned long *)(((vm_offset_t)tcp) + sizeof(struct thread_command)), tcp->cmdsize - sizeof(struct thread_command), &result->entry_point); if (lret != LOAD_SUCCESS) return(lret); } /* * Resume thread now, note that this means that the thread * commands should appear after all the load commands to * be sure they don't reference anything not yet mapped. */ else thread_resume(thread); result->thread_count++; return(LOAD_SUCCESS); }