Hello, everyone.
Experimentally, it was found out that when creating threads, when the calling process and the child process are in the same address space (the CLONE_VM flag), the clone and clone3 system calls cannot be called from a high-level language (C) using the wrapper function syscall(2). In this case, syscall(2) starts the child process without a stack frame and a return address, so it will not be able to return. The description on the man pages for clone(2), which suggests creating a thread (the CLONE_VM flag) using, for example,
long syscall(SYS_clone3, struct clone_args *cl_args, size_t size);
is a documentation error.The solution to this problem is described in detail in the article Practical libc-free threading on Linux. I am also very grateful to the author of this article for individual comments.