diff options
author | A. Wilcox <awilcox@wilcox-tech.com> | 2019-01-08 01:54:00 +0000 |
---|---|---|
committer | A. Wilcox <awilcox@wilcox-tech.com> | 2019-01-08 01:54:00 +0000 |
commit | 70add83428603fe757098a9531a22e611a759017 (patch) | |
tree | 9a6b8cb275db8d142924eabc82ec9204a55ae5f9 /libgcompat/pthread.c | |
parent | e97935b9c3b3c745d6264f9fad8afd912dbd366d (diff) | |
parent | d186323a2db1f8bf65b24236ce8d2ddff1b4385a (diff) | |
download | gcompat-70add83428603fe757098a9531a22e611a759017.tar.gz gcompat-70add83428603fe757098a9531a22e611a759017.tar.bz2 gcompat-70add83428603fe757098a9531a22e611a759017.tar.xz gcompat-70add83428603fe757098a9531a22e611a759017.zip |
Merge branch 'patch-4' into 'master'
New kernel compatibility; obstack; pthread_getname_np
The gcompat loader compiled as a static binary doesn't work on Linux since [a4ff8e8620d3f4](https://github.com/torvalds/linux/commit/a4ff8e8620d3f4f50ac4b41e8067b7d395056843), failing with an error like:
```
[349055.473655] 13325 (cmake): Uhuuh, elf segment at 0000000000400000 requested but the memory is mapped already
```
This is because the actual binary we want to run is also loaded at 0x400000. While it's actually okay to overlap the binary, since we're going to call `execve` again, the kernel doesn't allow the overlap anymore. Fix that by compiling the loader as static PIE, so it can be put at a different address.
Also add `pthread_getname_np` and the option to link `obstack`.
See merge request !4
Diffstat (limited to 'libgcompat/pthread.c')
-rw-r--r-- | libgcompat/pthread.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/libgcompat/pthread.c b/libgcompat/pthread.c index 4ebbe6b..0456c40 100644 --- a/libgcompat/pthread.c +++ b/libgcompat/pthread.c @@ -1,4 +1,8 @@ -#include <pthread.h> +#define _GNU_SOURCE +#include <errno.h> /* errno */ +#include <fcntl.h> /* O_CLOEXEC, O_RDONLY */ +#include <pthread.h> /* pthread_atfork */ +#include <unistd.h> /* open, read */ #include "alias.h" /* weak_alias */ @@ -27,3 +31,22 @@ int __register_atfork(void (*prepare)(void), void (*parent)(void), return pthread_atfork(prepare, parent, child); } weak_alias(__register_atfork, register_atfork); + +/** + * Get the name of a thread. + */ +int pthread_getname_np(pthread_t thread, char *name, size_t len) +{ + int fd = open("/proc/thread-self/comm", O_RDONLY | O_CLOEXEC); + char dummy; + + if (fd < 0) + return errno; + if (read(fd, name, len) < 0) + return errno; + /* If there's more to read, the buffer was too small. */ + if (read(fd, &dummy, 1) > 0) + return ERANGE; + + return 0; +} |