提交 21ec438b 编写于 作者: F fangting

pthread_create.c中增加线程栈命名的功能

Signed-off-by: Nfangting <fangting10@huawei.com>
上级 a6b5f75a
......@@ -1854,6 +1854,7 @@ musl_src_porting_file = [
"src/exit/atexit.c",
"crt/arm/crti.s",
"crt/aarch64/crti.s",
"src/thread/pthread_create.c",
]
musl_inc_hook_files = [
......
#define _GNU_SOURCE
#define ANON_STACK_NAME_SIZE 50
#include "pthread_impl.h"
#include "stdio_impl.h"
#include "libc.h"
......@@ -7,6 +8,7 @@
#include <string.h>
#include <stddef.h>
#include <stdarg.h>
#include <sys/prctl.h>
void log_print(const char* info,...)
{
......@@ -231,9 +233,9 @@ static void init_file_lock(FILE *f)
int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict attrp, void *(*entry)(void *), void *restrict arg)
{
int ret, c11 = (attrp == __ATTRP_C11_THREAD);
size_t size, guard;
size_t size, guard, size_len;
struct pthread *self, *new;
unsigned char *map = 0, *stack = 0, *tsd = 0, *stack_limit;
unsigned char *map = 0, *stack = 0, *tsd = 0, *stack_limit, *start_addr;
unsigned flags = CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND
| CLONE_THREAD | CLONE_SYSVSEM | CLONE_SETTLS
| CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID | CLONE_DETACHED;
......@@ -293,15 +295,25 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att
__munmap(map, size);
goto fail;
}
char guard_name[ANON_STACK_NAME_SIZE];
snprintf(guard_name, ANON_STACK_NAME_SIZE, "guard:%d", __pthread_self()->tid);
prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, map, guard, guard_name);
start_addr = map + guard;
size_len = size - guard;
} else {
map = __mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0);
if (map == MAP_FAILED) goto fail;
start_addr = map;
size_len = size;
}
tsd = map + size - __pthread_tsd_size;
if (!stack) {
stack = tsd - libc.tls_size;
stack_limit = map + guard;
}
char name[ANON_STACK_NAME_SIZE];
snprintf(name, ANON_STACK_NAME_SIZE, "stack:%d", __pthread_self()->tid);
prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, start_addr, size_len, name);
}
new = __copy_tls(tsd - libc.tls_size);
......@@ -419,4 +431,4 @@ pid_t __pthread_gettid_np(pthread_t t)
__tl_unlock();
return thread ? thread->tid : -1;
}
weak_alias(__pthread_gettid_np, pthread_gettid_np);
\ No newline at end of file
weak_alias(__pthread_gettid_np, pthread_gettid_np);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册