1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#ifndef _SHARED_EME_DUMP_H
6#define _SHARED_EME_DUMP_H
7#include <inttypes.h>
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
13#define SHARED_FILE_NAME "/tmp/emd-syscallbuf-%d-%d"
14#define SHARED_SOCKET_NAME "/tmp/st2sock-%d.bin"
15
16#if !defined(__mips__)
17#define __NR_Linux (0)
18#else
19#include <asm/unistd.h>
20#endif
21
22#define SYS_init_buffers (__NR_Linux + 1000 - 7) // least magic
23#define SYS_flush_buffers (__NR_Linux + 1000 - 6)
24#define SYS_share_name (__NR_Linux + 1000 - 5)
25#define SYS_enable_dump (__NR_Linux + 1000 - 4)
26#define SYS_update_maps (__NR_Linux + 1000 - 3)
27#define SYS_dump_x11 (__NR_Linux + 1000 - 2)
28#define SYS_dump_dbus (__NR_Linux + 1000 - 1)
29#define SHARED_BUFFER_SIZE (1024 * 1024)
30#define SYSCALL_PAGE_ADDR (0x70000000)
31
32typedef unsigned int number_slot_t;
33#define BITS_PER_SLOT (sizeof(number_slot_t) * 8)
34
35struct number_set {
36 number_slot_t *vec;
37 unsigned int nslots;
38 unsigned char not_flag;
39};
40
41typedef struct tagMemoryDumper {
42 int fd;
43 int pid; /* store current pid to avoid fork affect */
44 int mutex; /* at least 4bytes as futex, or EINVAL */
45 int syscall_count;
46 int size;
47 int current;
48 int page_size;
49 int max_stack_size;
50 uintptr_t stack_begin;
51 uintptr_t stack_end;
52 int max_param_size;
53 struct number_set syscall;
54}MemoryDumper;
55
56#define BUFFER_HEAD(d) (char *)(d + 1)
57
58
59unsigned char is_number_in_set(const unsigned number);
60int send_cmd(int cmd, uintptr_t arg);
61void lock_buffers(MemoryDumper *dumper);
62void unlock_buffers(MemoryDumper *dumper);
63MemoryDumper *create_memory_dumper(void);
64MemoryDumper *get_memory_dumper(void);
65void record_event_simple(MemoryDumper *dumper,
66 int event_type, const char *msg, int msg_len);
67void record_syscall(MemoryDumper *dumper,
68 int nr, long *args, long result, void *cpu);
69
70#ifdef __cplusplus
71}
72#endif
73
74#endif /* end #ifndef _SHARED_EME_DUMP_H */
75