-
Notifications
You must be signed in to change notification settings - Fork 1
/
machine_darwin.c
81 lines (63 loc) · 1.58 KB
/
machine_darwin.c
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
/* extend freebsd */
#include <sys/types.h>
#define ki_uid kp_eproc.e_pcred.p_ruid
#define ki_rgid kp_eproc.e_pcred.p_rgid
#define ki_pid kp_proc.p_pid
#define ki_stat kp_proc.p_stat
#define ki_flag kp_proc.p_flag
/* kvm interface */
typedef struct kvm_t kvm_t;
kvm_t *kvm_open(void *, const char *path /* /dev/null */, void *, int flags, void *);
int kvm_close(kvm_t *);
struct kinfo_proc *kvm_getprocs(kvm_t *, int what, int flag, int *n);
char **kvm_getargv( kvm_t *, struct kinfo_proc *, int flag);
typedef unsigned long u_long;
typedef unsigned int u_int;
typedef unsigned short u_short;
typedef unsigned char u_char;
#define KERN_PROC_PROC KERN_PROC_PID
/* implementation */
#include "machine_freebsd.c"
kvm_t *kvm_open(void *unused1, const char *path, void *unused2, int flags, void *unused3)
{
(void)unused1;
(void)unused2;
(void)unused3;
(void)path;
(void)flags;
return (void *)0x1; // hack? hack.
}
int kvm_close(kvm_t *kvm)
{
(void)kvm;
return 0;
}
struct kinfo_proc *kvm_getprocs(kvm_t *kvm, int what, int flag, int *n)
{
int eno;
struct kinfo_proc *kp;
int mib[4] = {
CTL_KERN,
KERN_PROC,
what,
flag
};
size_t sz = sizeof *kp;
/*
* what = KERN_PROC_RGID KERN_PROC_PGRP KERN_PROC_PID KERN_PROC_RUID
* KERN_PROC_SESSION KERN_PROC_TTY KERN_PROC_RUID KERN_PROC_UID
* flag = pid
*/
kp = malloc(sizeof *kp);
eno = sysctl(mib, 4, kp, &sz, NULL, 0);
if(eno){
free(kp);
return NULL;
}
return kp;
}
char **kvm_getargv(kvm_t *kvm, struct kinfo_proc *kp, int flag)
{
static char *dummy[] = { "TODO_argv", NULL };
return dummy;
}