I'm on OS X 10.10 64 bit (x86_64) and created a chunk of memory called code with
vm_allocate. I allocate a chunk of memory for a stack. I load a library to memory and determine an entry point to the library. I write the library to my code buffer using
vm_write, no problems there.
I setup the registers and call
thread_create_running and run remote thread into another process.
Over in the other process the thread starts. I'm using lldb and have it setup so when my thread starts it breaks on that entry point I see my code. I step through the code.
However it crashes when it tries to do the
_pthread_set_self. If I step into
pthread_set_self, it crashes in
_pthread_mutex_lock at the following instruction:
movq %gs:0x0, %rax
0x00000000 prior to the instruction where the crash occurs)
It's my understanding this instruction is an operation to retrieve the first segment of
gs from a thread segment structure and move it into the
My question is what do I need to do to prevent the crash that ensues upon execution of this instruction? Upon execution of this instruction I see
I tried putting in the code to
pthread_mutex_init, followed by
pthread_set_self. However when it hits the first
pthread_mutex_lock, i get the same issue. It dies at the same spot.
My target app to which i don't have source code, is multi-threaded.