summaryrefslogtreecommitdiffstats
path: root/src/framework/include/nsfw_ps_api.h
blob: 36a64eea537fa1629135eb1d00e81deaf087f992 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
*
* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef _NSFW_PS_API_H
#define _NSFW_PS_API_H

#include "list.h"
#include "compiling_check.h"
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C"{
/* *INDENT-ON* */
#endif /* __cplusplus */

#define NSFW_PS_MODULE      "nsfw_ps"

#define NSFW_PS_MAX_CALLBACK 16

#define NSFW_MAX_HBT_CHK_COUNT_DEF 60
#define NSFW_MAX_PID 65535
COMPAT_PROTECT_RETURN(NSFW_MAX_PID, 65535);

typedef enum _nsfw_ps_state
{
    NSFW_PS_NULL = 0,
    NSFW_PS_START,
    NSFW_PS_RUNNING,
    NSFW_PS_PARENT_FORK,
    NSFW_PS_CHILD_FORK,
    NSFW_PS_HBT_FAILED,
    NSFW_PS_EXITING,
    NSFW_PS_EXIT,
    NSFW_PS_MAX
} nsfw_ps_state;

/* for state change call back proc*/
typedef int (*nsfw_ps_proc_fun) (void *pps_info, void *argv);
typedef struct _nsfw_ps_callback
{
    u8 state;
    nsfw_ps_proc_fun fun;
    void *argv;
} nsfw_ps_callback;

/* for value in ps_info get/set*/
typedef enum _nsfw_ps_user_value
{
    NSFW_REC_IDX = 1,
    NSFW_REC_TIMER = 2,
    NSFW_PS_UV_MAX = 16
} nsfw_ps_user_value;
#define nsfw_ps_set_uv(_pps_info, _type, _value) (_pps_info)->value[(_type)] = (_value)
#define nsfw_ps_get_uv(_pps_info, _type) ((_pps_info)->value[(_type)])

typedef struct _nsfw_ps_info
{
    struct list_head node;
    u8 alloc_flag;
    u8 state;                   /*nsfw_ps_state */
    u8 proc_type;               /*fw_poc_type */
    u8 rechk_flg;
    u32 host_pid;
    u32 parent_pid;             /* only use for fork */
    u32 cur_child_pid;          /* only use for fork */
    void *exit_timer_ptr;
    void *resend_timer_ptr;
    void *hbt_timer_ptr;
    u32 hbt_failed_count;
    nsfw_ps_callback callback[NSFW_PS_MAX_CALLBACK];
    void *value[NSFW_PS_UV_MAX];
} nsfw_ps_info;

typedef struct _nsfw_thread_dogs
{
    u8 alloc_flag;
    i32 count;
    u32 thread_id;
} nsfw_thread_dogs;

extern nsfw_ps_info *nsfw_ps_info_alloc(u32 pid, u8 proc_type,
                                        u8 realloc_flg);
extern nsfw_ps_info *nsfw_ps_info_get(u32 pid);
extern void nsfw_ps_info_free(nsfw_ps_info * ps_info);

extern u8 nsfw_ps_reg_fun(nsfw_ps_info * pps_info, u8 ps_state,
                          nsfw_ps_proc_fun fun, void *argv);

/* will auto reg after ps_info alloc*/
extern u8 nsfw_ps_reg_global_fun(u8 proc_type, u8 ps_state,
                                 nsfw_ps_proc_fun fun, void *argv);

typedef struct _nsfw_ps_info_msg
{
    u32 host_pid;
    u32 parent_pid;
    u64 reserve;
} nsfw_ps_info_msg;
extern u8 nsfw_ps_exit_end_notify(u32 pid);

/*for heartbeat check*/
extern u8 nsfw_ps_check_dst_init(u8 dst_proc_type);
extern u8 nsfw_thread_chk();
extern nsfw_thread_dogs *nsfw_thread_get_dog();
extern u8 nsfw_thread_chk_unreg();
extern u8 nsfw_ps_hbt_start(nsfw_ps_info * ps_info);
extern u8 nsfw_ps_hbt_stop(nsfw_ps_info * ps_info);

extern u32 nsfw_ps_iterator(nsfw_ps_proc_fun fun, void *argv);

/* print bt */
#define MAX_THREAD 16
extern pthread_t g_all_thread[];
extern u8 nsfw_reg_trace_thread(pthread_t tid);

typedef int (*nsfw_ps_pid_fun) (u32 pid, u8 proc_type, void *argv);
extern int nsfw_ps_rechk_pid_exit(nsfw_ps_pid_fun fun, void *argv);
extern nsfw_ps_info *nsfw_share_ps_info_get(u32 pid);
extern void nsfw_ps_cfg_set_chk_count(u16 count);

extern int nsfw_ps_check_pid_nstack_status(int pid);
extern u64 nsfw_ps_get_starttime_from_file(u32 pid);
extern u64 nsfw_ps_get_starttime_from_info(u32 pid);

#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif /* __cplusplus */

#endif /* _NSFW_PS_API_H  */