This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
zhangyang-variable-monitor/source/ucli/ucli.h
2023-12-05 22:29:41 -05:00

142 lines
3.7 KiB
C++

#ifndef UAPI_H
#define UAPI_H
#include <asm/ptrace.h> // struct pt_regs
#include <sys/types.h>
#include <cstddef> // size_t
#include <stdlib.h>
#include <string>
// ioctl
#define IOCTL_WATCH_VARIABLE 0
#define IOCTL_DUMP_LOG 1
// dump type
#define VARIABLE_MONITOR_RECORD_TYPE 0x0
#define VARIABLE_MONITOR_TASK_TYPE 0x1
#define DEVICE "/dev/variable_monitor"
#define DEVICE_BAK "/host/dev/variable_monitor"
#define CGROUP_NAME_LEN 32 // max length of cgroup name
#define TASK_COMM_LEN 16 // max length of task name
#define BACKTRACE_DEPTH 30 // max depth of backtrace
#define PROCESS_CHAINS_COUNT 10 // max count of process chains
#define PROCESS_ARGV_LEN 128 // max length of process argv
#define MAX_NAME_LEN (127) // max name length
#define TIMER_MAX_WATCH_NUM (32) // A timer max watch number at once time
#define DIAG_USER_STACK_SIZE (16 * 1024)
typedef struct {
pid_t task_id; // current process id
char name[MAX_NAME_LEN + 1]; // name
void *ptr; // virtual address
long long threshold; // threshold value
// long long true_value; // target true value
} threshold;
typedef struct {
int et_type;
unsigned long id;
unsigned long long tv;
int threshold_num;
threshold threshold_record[TIMER_MAX_WATCH_NUM];
} variable_monitor_record;
typedef struct {
char cgroup_buf[CGROUP_NAME_LEN];
char cgroup_cpuset[CGROUP_NAME_LEN];
int pid;
int tgid;
int container_pid;
int container_tgid;
long state;
int task_type;
unsigned long syscallno;
/**
* 0->user 1->sys 2->idle
*/
unsigned long sys_task;
/**
* 1->user mode 0->sys mode -1->unknown
*/
unsigned long user_mode;
char comm[TASK_COMM_LEN];
} task_detail;
typedef struct {
unsigned long stack[BACKTRACE_DEPTH];
} kern_stack_detail;
// typedef struct {
// struct pt_regs regs;
// unsigned long ip;
// unsigned long bp;
// unsigned long sp;
// unsigned long stack[BACKTRACE_DEPTH];
// } user_stack_detail;
typedef struct {
struct pt_regs regs;
unsigned long ip;
unsigned long bp;
unsigned long sp;
unsigned long stack_size;
unsigned long stack[DIAG_USER_STACK_SIZE / sizeof(unsigned long)];
} raw_stack_detail;
typedef struct {
unsigned int full_argv[PROCESS_CHAINS_COUNT]; //
char chains[PROCESS_CHAINS_COUNT][PROCESS_ARGV_LEN]; // process chains argv
unsigned int tgid[PROCESS_CHAINS_COUNT]; // process chains tgid
} proc_chains_detail;
// most important struct
typedef struct {
int et_type;
unsigned long id;
unsigned long long tv;
task_detail task; // brief
// user_stack_detail user_stack; // user stack
kern_stack_detail kern_stack; // kernel stack
proc_chains_detail proc_chains; // process chains argv
raw_stack_detail raw_stack;
} variable_monitor_task;
#define DIAG_VARIANT_BUFFER_HEAD_MAGIC_SEALED 197612031122
#define DIAG_VARIANT_BUFFER_HEAD_MAGIC_UNSEALED 197612031234
struct diag_variant_buffer_head {
unsigned long magic;
unsigned long len;
};
struct diag_ioctl_dump_param {
int *user_ptr_len;
size_t user_buf_len;
void *user_buf;
};
long diag_call_ioctl(unsigned long request, unsigned long arg);
void extract_variant_buffer(char *buf, unsigned int len,
int (*func)(void *, unsigned int, void *),
void *arg);
extern unsigned long run_in_host;
int check_in_host(void);
// all print fun
void printk_task_brief(task_detail *detail);
void diag_printf_raw_stack(int pid, int ns_pid, const char *comm,
raw_stack_detail *raw_stack);
void diag_printf_kern_stack(kern_stack_detail *kern_stack);
void diag_printf_proc_chains(proc_chains_detail *proc_chains);
std::string state_str(int __state);
#endif /* UAPI_H */