-
Notifications
You must be signed in to change notification settings - Fork 38
/
gen_syscalls.py
executable file
·86 lines (80 loc) · 2.63 KB
/
gen_syscalls.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
import ctags, re, simplejson, sys, os
from ctags import CTags, TagEntry
# file generated by ctags --fields=afmikKlnsStz --c-kinds=+pc -R
tags = CTags('tags')
entry = TagEntry()
sct_file = open('arch/x86/kernel/syscall_table_32.S', 'r')
sys_calls = []
i = 0
for line in sct_file:
name = re.search(".long (\w*)", line)
if(name):
name = name.group(1)
is_ptregs = False
if(name == "sys_ni_syscall"):
sys_calls.append([i, "not implemented", "", "%0#4x"%(i), "", "", "", "", "", "", ""])
i += 1
continue
# take care of ptregs
elif(name.find('ptregs_') == 0):
name = name.replace("ptregs_", "sys_")
is_ptregs = True
if tags.find(entry, name, ctags.TAG_FULLMATCH | ctags.TAG_OBSERVECASE):
found_sym = False
while(not found_sym):
if(entry['kind'] == 'prototype'):
found_sym = True
details = [i, name, entry['signature']]
if(entry['signature'] != "(void)"):
sig = entry['signature'].strip('()').split(',')
else:
sig = [];
regs = {};
details.append("%0#4x"%(i));
if(len(sig) < 6):
for param in sig:
par = param.strip()
par_def = None
if(param.find("struct") != -1):
type_match = re.search("struct (\w+)", param)
if(type_match):
par_entry = TagEntry()
if(tags.find(par_entry, type_match.group(1), ctags.TAG_FULLMATCH|ctags.TAG_OBSERVECASE)):
if(par_entry['kind'] == 'struct'):
par_def = {'file': par_entry['file'], 'line': int(par_entry['lineNumber'])}
details.append({'type': par, 'def': par_def})
else:
details.append("param addr*")
remaining = 9 - len(details)
for x in range(0, remaining):
details.append("")
# try to get the line now
if(not is_ptregs):
pattern = "SYSCALL_DEFINE%d(%s"%(len(sig), name.replace("sys_", ""))
search = "SYSCALL_DEFINE%d"%(len(sig))
else:
pattern = name
search = name
if tags.find(entry, search, ctags.TAG_FULLMATCH | ctags.TAG_OBSERVECASE):
found = False
while(found == False):
if(entry['pattern'].find(pattern) == 2):
#details['found'] = entry['pattern']
details.append(entry['file'])
details.append(int(entry['lineNumber']))
found = True
break
if(not tags.findNext(entry)):
details.append("not found")
details.append("")
break
else:
details.append("not found")
details.append("")
sys_calls.append(details)
else:
if(not tags.findNext(entry)):
sys_calls.append([i, "", "", "", "", "", "", "", "", "", ""])
break
i += 1
print simplejson.dumps({'aaData': sys_calls}, indent=" ")