forked from hrw/syscalls-table
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.py
executable file
·117 lines (87 loc) · 2.77 KB
/
parser.py
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
#!/usr/bin/python3
from csv import reader
from datetime import datetime
from jinja2 import Environment, FileSystemLoader
from os import listdir
from sys import argv
def load_syscall_data():
syscalls = {}
present_archs = []
# use current system call names - tables/* can contain archive data
with open("syscall-names.text", newline="") as csvh:
syscalldata = reader(csvh, delimiter="\t")
for row in syscalldata:
syscalls[row[0]] = {}
for filename in listdir("tables"):
try:
arch = filename.replace("syscalls-", "")
with open(f"tables/{filename}", newline="") as csvh:
syscalldata = reader(csvh, delimiter="\t")
present_archs.append(arch)
for row in syscalldata:
try:
syscalls[row[0]][arch] = row[1]
except KeyError:
# old kernel table data - we ignore this syscall
pass
except IndexError:
pass
except IndexError:
pass
return [syscalls, present_archs]
def create_arch_list(present_archs):
archs = [
"arm64",
"arm",
"armoabi",
"x86_64",
"x32",
"i386",
"powerpc64",
"powerpc",
"s390x",
"s390",
]
removed_archs = [
"avr32",
"blackfin",
"c6x",
"cris",
"frv",
"m32r",
"metag",
"mn10300",
"nds32",
"score",
"sh64",
"tile",
"tile64",
"unicore32",
]
for arch in sorted(present_archs):
if arch not in removed_archs and arch not in archs:
archs.append(arch)
# loongarch64 is not in mainline so goes after all supported ones
archs.append("loongarch64")
for arch in removed_archs:
archs.append(arch)
return archs
def generate_html_file():
file_loader = FileSystemLoader('templates')
env = Environment(loader=file_loader, trim_blocks=True, lstrip_blocks=True)
template = env.get_template('syscalls.html.j2')
output = template.render(generate_time=datetime.strftime(
datetime.utcnow(), "%d %B %Y %H:%M"),
archs=archs,
kernel_version=kernel_version,
syscall_names=sorted(syscalls.keys()),
syscall_data=syscalls,
minify=True)
print(output)
if __name__ == "__main__":
kernel_version = ""
if len(argv) > 1:
kernel_version = argv[1]
[syscalls, present_archs] = load_syscall_data()
archs = create_arch_list(present_archs)
generate_html_file()