3

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

(Note: gs is 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 rax register.

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 EXC_BAD_ACCESS in pthread_mutex_lock.

I tried putting in the code to pthread_mutex_init, followed by pthread_mutex_lock then pthread_set_self. However when it hits the first pthread_mutex_lock, i get the same issue. It dies at the same spot.

Any ideas?

My target app to which i don't have source code, is multi-threaded.

  • Did you ever figure this out? I'm having the exact same problem. – Lupe Nov 5 '16 at 22:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.