Make threads with sys_clone
I am trying to make a threads using sys_clone.
Unfortunately there is no information about some details:
1. How I have to allocate memory for the thread stack? It is clear that sys_mmap have to be used, but what flags have to be set in order to provide auto growing of the memory block?
2. How the allocated memory have to be free and when - in both threads - the thread that creates new thread and the new thread itself.
3. What flags have to be set in sys_clone call in order to make "real thread", i.e. process that exists in the same space with the main program and have access to all resources of the parent process.
I tried with following settings, but it seems I have some mistakes (maybe not in the bellow settings) because the so created threads can't work stable with XLib probably because of synchronization issues.
MAP_ANONYMOUS + MAP_PRIVATE + MAP_GROWSDOWN + MAP_STACK
PROT_READ + PROT_WRITE + PROT_EXEC
CLONE_SIGHAND + CLONE_THREAD + CLONE_FILES + CLONE_FS + CLONE_VM + CLONE_PTRACE + CLONE_PARENT + CLONE_IO