eb74a97b1f11a187afb15c0a24b870679e00b47c
2 * System call table mapper
4 * (C) 2016 Arnaldo Carvalho de Melo <acme@redhat.com>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 #include "syscalltbl.h"
19 #ifdef HAVE_SYSCALL_TABLE
20 #include <linux/compiler.h>
29 static int syscallcmpname(const void *vkey
, const void *ventry
)
31 const char *key
= vkey
;
32 const struct syscall
*entry
= ventry
;
34 return strcmp(key
, entry
->name
);
37 static int syscallcmp(const void *va
, const void *vb
)
39 const struct syscall
*a
= va
, *b
= vb
;
41 return strcmp(a
->name
, b
->name
);
44 static int syscalltbl__init_native(struct syscalltbl
*tbl
)
46 int nr_entries
= 0, i
, j
;
47 struct syscall
*entries
;
49 for (i
= 0; i
<= syscalltbl_native_max_id
; ++i
)
50 if (syscalltbl_native
[i
])
53 entries
= tbl
->syscalls
.entries
= malloc(sizeof(struct syscall
) * nr_entries
);
54 if (tbl
->syscalls
.entries
== NULL
)
57 for (i
= 0, j
= 0; i
<= syscalltbl_native_max_id
; ++i
) {
58 if (syscalltbl_native
[i
]) {
59 entries
[j
].name
= syscalltbl_native
[i
];
65 qsort(tbl
->syscalls
.entries
, nr_entries
, sizeof(struct syscall
), syscallcmp
);
66 tbl
->syscalls
.nr_entries
= nr_entries
;
70 struct syscalltbl
*syscalltbl__new(void)
72 struct syscalltbl
*tbl
= malloc(sizeof(*tbl
));
74 if (syscalltbl__init_native(tbl
)) {
82 void syscalltbl__delete(struct syscalltbl
*tbl
)
84 zfree(&tbl
->syscalls
.entries
);
88 const char *syscalltbl__name(const struct syscalltbl
*tbl __maybe_unused
, int id
)
90 return id
<= syscalltbl_native_max_id
? syscalltbl_native
[id
]: NULL
;
93 int syscalltbl__id(struct syscalltbl
*tbl
, const char *name
)
95 struct syscall
*sc
= bsearch(name
, tbl
->syscalls
.entries
,
96 tbl
->syscalls
.nr_entries
, sizeof(*sc
),
99 return sc
? sc
->id
: -1;
102 #else /* HAVE_SYSCALL_TABLE */
104 #include <libaudit.h>
106 struct syscalltbl
*syscalltbl__new(void)
108 struct syscalltbl
*tbl
= malloc(sizeof(*tbl
));
110 tbl
->audit_machine
= audit_detect_machine();
114 void syscalltbl__delete(struct syscalltbl
*tbl
)
119 const char *syscalltbl__name(const struct syscalltbl
*tbl
, int id
)
121 return audit_syscall_to_name(id
, tbl
->audit_machine
);
124 int syscalltbl__id(struct syscalltbl
*tbl
, const char *name
)
126 return audit_name_to_syscall(name
, tbl
->audit_machine
);
128 #endif /* HAVE_SYSCALL_TABLE */
This page took 0.041481 seconds and 4 git commands to generate.