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