• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2
3import re
4import sys
5import urllib2
6
7syscalls = {}
8
9
10def print_table(name):
11  tab = syscalls[name]
12  print '\n\n----------------- BEGIN OF %s -----------------' % name
13  for i in xrange(max(tab.keys()) + 1):
14    print '"%s",  // %d' % (tab.get(i, ''), i)
15  print '----------------- END OF %s -----------------' % name
16
17
18# Parses a .tbl file (new format).
19def parse_tlb(data):
20  table = {}
21  for line in data.splitlines():
22    line = line.strip()
23    if line.startswith('#') or not (line):
24      continue
25    parts = line.split()
26    table[int(parts[0])] = 'sys_' + parts[2]
27  return table
28
29
30# Parses a #define __NR_xx 1234 old-style unistd.h header.
31def parse_def(data):
32  table = {}
33  for line in data.splitlines():
34    m = re.match(r'^#define\s+__NR\d*?_(\w+)\s+(\d+)\s*$', line.strip())
35    if not m or m.group(1) == 'syscalls':  # __NR_syscalls is just a sentinel.
36      continue
37    table[int(m.group(2))] = 'sys_' + m.group(1)
38  return table
39
40
41def Main():
42  KSRC = 'https://raw.githubusercontent.com/torvalds/linux/v4.20/'
43
44  response = urllib2.urlopen(KSRC + 'arch/x86/entry/syscalls/syscall_64.tbl')
45  syscalls['x86_64'] = parse_tlb(response.read())
46
47  response = urllib2.urlopen(KSRC + 'arch/x86/entry/syscalls/syscall_32.tbl')
48  syscalls['x86'] = parse_tlb(response.read())
49
50  response = urllib2.urlopen(KSRC + 'arch/arm/tools/syscall.tbl')
51  syscalls['armeabi'] = parse_tlb(response.read())
52
53  response = urllib2.urlopen(KSRC + 'arch/arm64/include/asm/unistd32.h')
54  syscalls['aarch32'] = parse_def(response.read())
55
56  # From:
57  # arch/arm64/include/asm/unistd.h
58  #   -> arch/arm64/include/uapi/asm/unistd.h
59  #     -> include/uapi/asm-generic/unistd.h
60  response = urllib2.urlopen(KSRC + 'include/uapi/asm-generic/unistd.h')
61  syscalls['aarch64'] = parse_def(response.read())
62
63  print_table('x86_64')
64  print_table('x86')
65  print_table('aarch64')
66  print_table('armeabi')
67  print_table('aarch32')
68
69
70if __name__ == '__main__':
71  sys.exit(Main())
72