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/arm/tools/syscall.tbl') 48 syscalls['armeabi'] = parse_tlb(response.read()) 49 50 response = urllib2.urlopen(KSRC + 'arch/arm64/include/asm/unistd32.h') 51 syscalls['aarch32'] = parse_def(response.read()) 52 53 # From: 54 # arch/arm64/include/asm/unistd.h 55 # -> arch/arm64/include/uapi/asm/unistd.h 56 # -> include/uapi/asm-generic/unistd.h 57 response = urllib2.urlopen(KSRC + 'include/uapi/asm-generic/unistd.h') 58 syscalls['aarch64'] = parse_def(response.read()) 59 60 print_table('x86_64') 61 print_table('aarch64') 62 print_table('armeabi') 63 print_table('aarch32') 64 65 66if __name__ == '__main__': 67 sys.exit(Main()) 68