提交 d7deb3fb 编写于 作者: Z zhushengle

fix: 进程退出静态问题

问题描述:
    进程在退出过程中,拿到了init_fini_lock锁后被信号打断,
收到退出信号,再次调用exit函数进入进程退出流程,造成死锁

解决方案:
    在libc中添加exit字段,在进程退出时将该字段表示进程已经在退出,
若再次进入退出流程,则直接退出,由第一个执行退出流程的线程继续执行
退出流程。并且在退出时屏蔽信号,避免退出流程被频繁打断。
Close #I43V23
Signed-off-by: Nzhushengle <zhushengle@huawei.com>

Change-Id: I57b60391267d50c8eb89fc115a26229461bb4ed4
上级 9c138536
#include <stdlib.h>
#include <stdint.h>
#include <signal.h>
#include <atomic.h>
#include "libc.h"
static void dummy()
{
}
/* atexit.c and __stdio_exit.c override these. the latter is linked
* as a consequence of linking either __toread.c or __towrite.c. */
weak_alias(dummy, __funcs_on_exit);
weak_alias(dummy, __stdio_exit);
weak_alias(dummy, _fini);
extern weak hidden void (*const __fini_array_start)(void), (*const __fini_array_end)(void);
static void libc_exit_fini(void)
{
uintptr_t a = (uintptr_t)&__fini_array_end;
for (; a>(uintptr_t)&__fini_array_start; a-=sizeof(void(*)()))
(*(void (**)())(a-sizeof(void(*)())))();
_fini();
}
weak_alias(libc_exit_fini, __libc_exit_fini);
_Noreturn void exit(int code)
{
sigset_t set;
if (a_cas(&libc.exit, 0, 1) != 0) {
return;
}
__block_app_sigs(&set);
__funcs_on_exit();
__libc_exit_fini();
__stdio_exit();
_Exit(code);
}
......@@ -27,6 +27,7 @@ struct __libc {
size_t tls_size, tls_align, tls_cnt;
size_t page_size;
struct __locale_struct global_locale;
int exit;
};
#ifndef PAGE_SIZE
......
......@@ -30,6 +30,7 @@ pid_t fork(void)
self->next = self->prev = self;
__thread_list_lock = 0;
libc.threads_minus_1 = 0;
libc.exit = 0;
signal(SIGSYS, arm_do_signal);
}
__restore_sigs(&set);
......
......@@ -2,6 +2,8 @@
#include <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <signal.h>
#include <atomic.h>
#include "libc.h"
extern bool g_enable_check;
......@@ -32,6 +34,11 @@ weak_alias(libc_exit_fini, __libc_exit_fini);
_Noreturn void exit(int code)
{
sigset_t set;
if (a_cas(&libc.exit, 0, 1) != 0) {
return;
}
__block_app_sigs(&set);
if (g_enable_check) {
check_leak();
check_heap_integrity();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册