提交 1bad99ef 编写于 作者: F fangting

线程栈命名修改

Signed-off-by: Nfangting <fangting10@huawei.com>
上级 011a9056
...@@ -18,6 +18,24 @@ void log_print(const char* info,...) ...@@ -18,6 +18,24 @@ void log_print(const char* info,...)
va_end(ap); va_end(ap);
} }
void stack_naming(struct pthread *new){
size_t size_len;
unsigned char *start_addr;
char name[ANON_STACK_NAME_SIZE];
if (new->guard_size) {
snprintf(name, ANON_STACK_NAME_SIZE, "guard:%d", new->tid);
prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, new->map_base, new->guard_size, name);
start_addr = new->map_base + new->guard_size;
size_len = new->map_size - new->guard_size;
memset(name, 0, ANON_STACK_NAME_SIZE);
} else {
start_addr = new->map_base;
size_len = new->map_size;
}
snprintf(name, ANON_STACK_NAME_SIZE, "stack:%d", new->tid);
prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, start_addr, size_len, name);
};
#ifdef RESERVE_SIGNAL_STACK #ifdef RESERVE_SIGNAL_STACK
#if defined (__LF64__) #if defined (__LF64__)
#define RESERVE_SIGNAL_STACK_SIZE (32 * 1024) #define RESERVE_SIGNAL_STACK_SIZE (32 * 1024)
...@@ -348,25 +366,15 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att ...@@ -348,25 +366,15 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att
__munmap(map, size); __munmap(map, size);
goto fail; 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 { } else {
map = __mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0); map = __mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0);
if (map == MAP_FAILED) goto fail; if (map == MAP_FAILED) goto fail;
start_addr = map;
size_len = size;
} }
tsd = map + size - __pthread_tsd_size; tsd = map + size - __pthread_tsd_size;
if (!stack) { if (!stack) {
stack = tsd - libc.tls_size; stack = tsd - libc.tls_size;
stack_limit = map + guard; 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); new = __copy_tls(tsd - libc.tls_size);
...@@ -429,6 +437,8 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att ...@@ -429,6 +437,8 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att
} }
if (ret >= 0) { if (ret >= 0) {
stack_naming(new);
new->next = self->next; new->next = self->next;
new->prev = self; new->prev = self;
new->next->prev = new; new->next->prev = new;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册