Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #ifndef STACKTRACE_COMMON_H
12 : #define STACKTRACE_COMMON_H
13 :
14 : #include <signal.h>
15 : #include <stdbool.h>
16 : #include <stddef.h>
17 : #include <stdint.h>
18 : #include "trace_system_api.h"
19 :
20 : #define SIG_ATRACE 35
21 : #define STACKTRACE_DUMP_BIN_MODE 0xAABB0003U
22 : #define THREAD_NAME_LEN 16U
23 : #define MAX_BIN_PATH_LEN 1024U
24 : #define MAX_THREAD_NUM 1024U
25 :
26 : #define SCD_MAX_NAME_HEAD_LEN 64U
27 : #define SCD_MAX_FILENAME_LEN 128U
28 : #define SCD_MAX_FULLPATH_LEN (TRACE_MAX_PATH - 1U)
29 : #define SCD_FILE_SUFFIX_MAX_LEN 4U
30 : #define SCD_FILE_RESERVED_LEN (1U + SCD_MAX_FILENAME_LEN + SCD_FILE_SUFFIX_MAX_LEN)
31 : #define SCD_MAX_FILEPATH_LEN ((SCD_MAX_FULLPATH_LEN > SCD_FILE_RESERVED_LEN) ? \
32 : (SCD_MAX_FULLPATH_LEN - SCD_FILE_RESERVED_LEN) : 0U)
33 : #define SCD_MAX_FILEDIR_LEN SCD_MAX_FILEPATH_LEN
34 :
35 : /*
36 : * [parent process] ---fork---> [child process] ---execv---> [new process]
37 : * [parent process] application process which receive signal
38 : * [child process] copy form "parent process", prepare to execute new program
39 : * [new process] created by "child process" via execv, dumper stacktrace in this process
40 : */
41 :
42 : typedef enum ScdDumpType {
43 : SCD_DUMP_THREADS_TXT,
44 : SCD_DUMP_THREADS_BIN,
45 : SCD_DUMP_THREAD_TXT,
46 : SCD_DUMP_THREAD_BIN,
47 : } ScdDumpType;
48 :
49 176 : static inline bool ScdSignalIsBinDump(int32_t signo, const siginfo_t *siginfo)
50 : {
51 209 : return (signo == SIG_ATRACE) && (siginfo != NULL) &&
52 33 : ((uint32_t)siginfo->si_value.sival_int == STACKTRACE_DUMP_BIN_MODE);
53 : }
54 :
55 : // [child process] ---execv---> [new process]
56 : typedef struct ScdProcessArgs {
57 : int32_t pid; // the crashing process
58 : int32_t crashTid; // the crashing thread
59 : int32_t signo;
60 : uint64_t crashTime;
61 : uintptr_t stackBaseAddr;
62 : siginfo_t si;
63 : ucontext_t uc;
64 : char filePath[SCD_MAX_FILEPATH_LEN + 1U];
65 : char fileName[SCD_MAX_FILENAME_LEN + 1U];
66 : ScdDumpType handleType;
67 : } ScdProcessArgs;
68 :
69 : // [parent process] ---fork---> [child process]
70 : typedef struct {
71 : int32_t pid; // the crashing process
72 : int32_t tid; // the crashing thread
73 : int32_t signo;
74 : uint64_t crashTime;
75 : uintptr_t stackBaseAddr;
76 : siginfo_t siginfo;
77 : ucontext_t ucontext;
78 : char filePath[SCD_MAX_FILEPATH_LEN + 1U];
79 : char fileName[SCD_MAX_FILENAME_LEN + 1U];
80 : char exePath[MAX_BIN_PATH_LEN];
81 : } ThreadArgument;
82 :
83 : #endif
|