-
Notifications
You must be signed in to change notification settings - Fork 30
/
proc.h
84 lines (67 loc) · 1.84 KB
/
proc.h
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
/*-
* xnumon - monitor macOS for malicious activity
* https://www.roe.ch/xnumon
*
* Copyright (c) 2017-2019, Daniel Roethlisberger <daniel@roe.ch>.
* All rights reserved.
*
* Licensed under the Open Software License version 3.0.
*/
#ifndef PROC_H
#define PROC_H
#include "procmon.h" /* image_exec_t */
#include "tommylist.h"
#include <sys/types.h>
typedef struct {
tommy_node node;
int fd;
int flags;
#define FDFLAG_SOCKET 1
#define FDFLAG_FILE 2
#define FDFLAG_CLOEXEC 4 /* unused */
union {
struct {
int proto;
ipaddr_t addr;
uint16_t port;
} so;
struct {
audit_proc_t subject;
char *path;
} fi;
};
} fd_ctx_t;
typedef struct proc {
/* fork meta-data at time of fork */
pid_t pid;
struct timespec fork_tv;
/* image of last exec */
image_exec_t *image_exec;
/* current working directory, tracked via chdir/fchdir */
char *cwd;
/* hashtable bucket linkage */
struct proc *next;
/*
* Open file descriptors smaller than default RLIMIT_NOFILE stored in
* pointer array in addition to a list to allow O(1) access time but
* still quick iteration on exit with only few descriptors. This
* yields good access complexity except for large network servers with
* thousands of open sockets. FIXME look into alternatives
*/
fd_ctx_t *fdlovect[256];
tommy_list fdlolist;
tommy_list fdhilist;
} proc_t;
extern uint32_t procs;
void proctab_init(void);
void proctab_fini(void);
proc_t * proctab_create(pid_t);
proc_t * proctab_find_or_create(pid_t);
proc_t * proctab_find(pid_t);
void proctab_remove(pid_t, struct timespec *);
fd_ctx_t * proc_getfd(proc_t *, int) NONNULL(1) WUNRES;
fd_ctx_t * proc_closefd(proc_t *, int) NONNULL(1) WUNRES;
void proc_setfd(proc_t *, fd_ctx_t *) NONNULL(1,2);
void proc_triggerfd(fd_ctx_t *ctx, struct timespec *tv) NONNULL(1,2);
void proc_freefd(fd_ctx_t *) NONNULL(1);
#endif