-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathctest.lua
123 lines (106 loc) · 2.59 KB
/
ctest.lua
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
-- generate C test file to check type sizes etc
local S = require "syscall"
local ffi = require "ffi"
local s, t = S.s, S.t
-- TODO fix these, various naming issues
S.ctypes["struct linux_dirent64"] = nil
S.ctypes["struct statfs64"] = nil
S.ctypes["struct flock64"] = nil
S.ctypes["struct stat64"] = nil
S.ctypes["struct fdb_entry"] = nil
S.ctypes["struct seccomp_data"] = nil
S.ctypes["sighandler_t"] = nil
S.ctypes["struct rlimit64"] = nil
S.ctypes["struct mq_attr"] = nil
-- fixes for constants
S.__WALL = S.WALL; S.WALL = nil
S.__WCLONE = S.WCLONE; S.WCLONE = nil
-- remove seccomp for now as no support on the ARM box
for k, _ in pairs(S) do
if k:sub(1, 8) == 'SECCOMP_' then S[k] = nil end
end
-- fake constants
S.MS_RO = nil
S.MS_RW = nil
S.IFF_ALL = nil
S.IFF_NONE = nil
-- TODO find the headers/flags for these if exist, or remove
S.SA_RESTORER = nil
S.AF_DECNET = nil
S.SIG_HOLD = nil
S.NOTHREAD = nil
S.RTF_PREFIX_RT = nil
S.RTF_EXPIRES = nil
S.RTF_ROUTEINFO = nil
S.RTF_ANYCAST = nil
-- include kitchen sink, garbage can etc
print [[
#include "assert.h"
#define _GNU_SOURCE
#define __USE_GNU
#define _FILE_OFFSET_BITS 64
#define _LARGE_FILES 1
#define __USE_FILE_OFFSET64
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/epoll.h>
#include <signal.h>
#include <sys/utsname.h>
#include <time.h>
#include <linux/aio_abi.h>
#include <sys/resource.h>
#include <sys/sysinfo.h>
#include <sys/time.h>
#include <sys/un.h>
#include <netinet/ip.h>
#include <poll.h>
#include <sys/signalfd.h>
#include <linux/rtnetlink.h>
#include <sys/vfs.h>
#include <sys/timex.h>
#include <linux/posix_types.h>
#include <linux/if.h>
#include <linux/if_bridge.h>
#include <sys/mman.h>
#include <sched.h>
#include <sys/xattr.h>
#include <linux/if_arp.h>
#include <sys/capability.h>
#include <linux/sched.h>
#include <termios.h>
#include <unistd.h>
#include <sys/prctl.h>
#include <sys/mount.h>
#include <sys/uio.h>
#include <net/route.h>
#include <sys/inotify.h>
#include <sys/wait.h>
#include <linux/mman.h>
#include <linux/veth.h>
#include <linux/sockios.h>
#include <dirent.h>
#include <linux/reboot.h>
#include <sys/timerfd.h>
#include <linux/falloc.h>
#include <sys/eventfd.h>
int main(int argc, char **argv) {
]]
-- iterate over S.ctypes
for k, v in pairs(S.ctypes) do
print("assert(sizeof(" .. k .. ") == " .. ffi.sizeof(v) .. ");")
end
-- test all the constants
for k, v in pairs(S) do
if type(S[k]) == "number" then
print("assert(" .. k .. " == " .. v .. ");")
end
end
-- TODO test error codes
print [[
}
]]