forked from hrw/syscalls-table
-
Notifications
You must be signed in to change notification settings - Fork 4
/
parser.py
executable file
·189 lines (153 loc) · 5.62 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/bin/python3
import collections
import csv
import datetime
import os
syscalls = collections.OrderedDict()
archs = []
os.chdir('tables')
for filename in os.listdir(os.getcwd()):
try:
arch=filename.replace('syscalls-', '')
with open(filename, newline='') as csvh:
seccompdata = csv.reader(csvh, delimiter="\t")
archs.append(arch)
for row in seccompdata:
try:
syscalls[row[0]][arch] = row[1]
except KeyError:
syscalls[row[0]] = collections.OrderedDict()
syscalls[row[0]][arch] = row[1]
except IndexError:
pass
except IndexError:
pass
print("""
<html>
<head>
<title>System calls table for several architectures</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css"/>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.2.2/css/buttons.dataTables.min.css"/>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/colreorder/1.3.2/css/colReorder.dataTables.min.css"/>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/fixedheader/3.1.2/css/fixedHeader.dataTables.min.css"/>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/select/1.2.0/css/select.dataTables.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.2.2/js/dataTables.buttons.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.2.2/js/buttons.colVis.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.2.2/js/buttons.print.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/colreorder/1.3.2/js/dataTables.colReorder.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/fixedheader/3.1.2/js/dataTables.fixedHeader.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/select/1.2.0/js/dataTables.select.min.js"></script>
<script type="text/javascript" id="js">
$(document).ready(function() {
$("table").DataTable( {
pageLength : -1,
fixedHeader : true,
dom : 'Bft',
buttons : [
{
extend : 'colvis',
text: 'disable architectures',
columns: ':gt(0)'
}
]
});
});
</script>
<style type="text/css">
table.syscalls {
border: 1px solid #000;
}
table.syscalls th {
text-align: center;
padding: 0.5em;
line-height: 2em;
color: white;
}
table.syscalls thead {
border: 1px solid black;
background-color: grey;
}
table.syscalls td {
padding: 0.5em;
}
table.syscalls tbody tr.odd td {
background-color: lightgrey;
}
.legacy, table.syscalls tbody tr.odd td.legacy {
background-color: lightpink;
}
</style>
</head>
<body>
<h1>Introduction</h1>
<p>
Linux provides many system calls for userspace. But numbers used for them
differ between architectures. This page was created to help developers find
those values.
</p>
<p>
But there is another issue. Some of system calls got dropped during Linux
development, some got replaced by newer ones. Several architectures got
added into kernel later and their maintainers decided to not bother with
supporting obsoleted system calls. They are marked with "-1" value in table
below.
</p>
<h1>How to use</h1>
<p>
There are few features you can use:
<ul>
<li>search field allows to filter table by syscall name or number</li>
<li>system call names link to their man pages</li>
<li>'disable architectures' button allows to disable not needed columns</li>
<li>clicking on header entries sorts table</li>
</ul>
</p>
<h1>How to help</h1>
<p>
Sources used to generate table are available in <a
href="https://github.com/hrw/syscalls-table">git repository at github</a>.
Patches are always welcomed.
</p>
""")
print("""
<table class="syscalls">
<thead>
<tr>
<th>system call</th>
""")
for arch in sorted(archs):
print("<th>%s</th>" % arch)
print("""
</tr>
</thead>
<tbody>
""")
oddeven = 0
for syscall in sorted(syscalls.keys()):
if (oddeven % 2 == 0):
trclass = "even"
else:
trclass = "odd"
oddeven += 1
print("<tr class='%s'><td><a href='http://www.man7.org/linux/man-pages/man2/%s.2.html'>%s</a></td>" % (trclass, syscall,syscall))
for arch in sorted(archs):
try:
syscallnr = syscalls[syscall][arch]
css = ''
except KeyError:
syscallnr = -1
css = ' class="legacy" '
if not syscallnr:
syscallnr = -1
css = ' class="legacy" '
print("<td%s>%s</td>" % (css, syscallnr))
print("</tr>")
print("""
</tbody>
</table>
<p>Table generated on %s</p>
</body>
</html>
""" % datetime.datetime.strftime(datetime.datetime.utcnow(), "%Y.%m.%d %H:%M"))