2021-04-15 22:39:08 +02:00
|
|
|
#!/usr/bin/env python3
|
2012-12-12 10:11:48 +01:00
|
|
|
|
|
|
|
# This tool is used to generate the assembler system call stubs,
|
|
|
|
# the header files listing all available system calls, and the
|
|
|
|
# makefiles used to build all the stubs.
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2014-08-05 21:19:27 +02:00
|
|
|
import atexit
|
2013-10-16 23:27:59 +02:00
|
|
|
import filecmp
|
|
|
|
import glob
|
|
|
|
import re
|
|
|
|
import shutil
|
|
|
|
import stat
|
2014-08-20 20:16:11 +02:00
|
|
|
import string
|
2013-10-16 23:27:59 +02:00
|
|
|
import sys
|
2014-08-05 21:19:27 +02:00
|
|
|
import tempfile
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2014-08-20 20:16:11 +02:00
|
|
|
|
2022-10-10 19:06:43 +02:00
|
|
|
SupportedArchitectures = [ "arm", "arm64", "riscv64", "x86", "x86_64" ]
|
2014-08-20 20:16:11 +02:00
|
|
|
|
2019-04-15 23:18:26 +02:00
|
|
|
syscall_stub_header = \
|
2013-10-16 23:27:59 +02:00
|
|
|
"""
|
2013-10-08 08:53:13 +02:00
|
|
|
ENTRY(%(func)s)
|
2008-10-21 16:00:00 +02:00
|
|
|
"""
|
|
|
|
|
2013-10-08 08:53:13 +02:00
|
|
|
|
2012-12-12 10:11:48 +01:00
|
|
|
#
|
|
|
|
# ARM assembler templates for each syscall stub
|
|
|
|
#
|
|
|
|
|
|
|
|
arm_eabi_call_default = syscall_stub_header + """\
|
2013-01-16 14:02:50 +01:00
|
|
|
mov ip, r7
|
2016-04-28 03:31:02 +02:00
|
|
|
.cfi_register r7, ip
|
2013-10-08 08:53:13 +02:00
|
|
|
ldr r7, =%(__NR_name)s
|
2008-10-21 16:00:00 +02:00
|
|
|
swi #0
|
2013-01-16 14:02:50 +01:00
|
|
|
mov r7, ip
|
2016-04-28 03:31:02 +02:00
|
|
|
.cfi_restore r7
|
2013-03-12 22:57:30 +01:00
|
|
|
cmn r0, #(MAX_ERRNO + 1)
|
|
|
|
bxls lr
|
|
|
|
neg r0, r0
|
2014-09-09 00:25:01 +02:00
|
|
|
b __set_errno_internal
|
2013-10-08 08:53:13 +02:00
|
|
|
END(%(func)s)
|
2013-02-07 23:07:00 +01:00
|
|
|
"""
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2012-12-12 10:11:48 +01:00
|
|
|
arm_eabi_call_long = syscall_stub_header + """\
|
2008-10-21 16:00:00 +02:00
|
|
|
mov ip, sp
|
|
|
|
stmfd sp!, {r4, r5, r6, r7}
|
2013-12-03 02:44:53 +01:00
|
|
|
.cfi_def_cfa_offset 16
|
|
|
|
.cfi_rel_offset r4, 0
|
|
|
|
.cfi_rel_offset r5, 4
|
|
|
|
.cfi_rel_offset r6, 8
|
|
|
|
.cfi_rel_offset r7, 12
|
2008-10-21 16:00:00 +02:00
|
|
|
ldmfd ip, {r4, r5, r6}
|
2013-10-08 08:53:13 +02:00
|
|
|
ldr r7, =%(__NR_name)s
|
2008-10-21 16:00:00 +02:00
|
|
|
swi #0
|
|
|
|
ldmfd sp!, {r4, r5, r6, r7}
|
2013-12-03 02:44:53 +01:00
|
|
|
.cfi_def_cfa_offset 0
|
2013-03-12 22:57:30 +01:00
|
|
|
cmn r0, #(MAX_ERRNO + 1)
|
|
|
|
bxls lr
|
|
|
|
neg r0, r0
|
2014-09-09 00:25:01 +02:00
|
|
|
b __set_errno_internal
|
2013-10-08 08:53:13 +02:00
|
|
|
END(%(func)s)
|
2008-10-21 16:00:00 +02:00
|
|
|
"""
|
|
|
|
|
2013-10-08 08:53:13 +02:00
|
|
|
|
2014-01-22 04:50:58 +01:00
|
|
|
#
|
2019-04-15 23:18:26 +02:00
|
|
|
# Arm64 assembler template for each syscall stub
|
2014-01-22 04:50:58 +01:00
|
|
|
#
|
|
|
|
|
|
|
|
arm64_call = syscall_stub_header + """\
|
|
|
|
mov x8, %(__NR_name)s
|
|
|
|
svc #0
|
|
|
|
|
|
|
|
cmn x0, #(MAX_ERRNO + 1)
|
|
|
|
cneg x0, x0, hi
|
2014-09-09 00:25:01 +02:00
|
|
|
b.hi __set_errno_internal
|
2014-01-22 04:50:58 +01:00
|
|
|
|
|
|
|
ret
|
|
|
|
END(%(func)s)
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2022-10-10 19:06:43 +02:00
|
|
|
#
|
|
|
|
# RISC-V64 assembler templates for each syscall stub
|
|
|
|
#
|
|
|
|
|
|
|
|
riscv64_call = syscall_stub_header + """\
|
|
|
|
li a7, %(__NR_name)s
|
|
|
|
ecall
|
|
|
|
|
|
|
|
li a7, -MAX_ERRNO
|
2023-05-11 08:52:40 +02:00
|
|
|
bgeu a0, a7, 1f
|
2022-10-10 19:06:43 +02:00
|
|
|
|
|
|
|
ret
|
|
|
|
1:
|
|
|
|
neg a0, a0
|
2023-03-09 02:16:34 +01:00
|
|
|
tail __set_errno_internal
|
2022-10-10 19:06:43 +02:00
|
|
|
END(%(func)s)
|
|
|
|
"""
|
|
|
|
|
2013-10-08 08:53:13 +02:00
|
|
|
#
|
|
|
|
# x86 assembler templates for each syscall stub
|
|
|
|
#
|
|
|
|
|
2014-01-07 01:39:10 +01:00
|
|
|
x86_registers = [ "ebx", "ecx", "edx", "esi", "edi", "ebp" ]
|
2013-10-08 08:53:13 +02:00
|
|
|
|
2015-11-12 08:02:14 +01:00
|
|
|
x86_call_prepare = """\
|
|
|
|
|
|
|
|
call __kernel_syscall
|
|
|
|
pushl %eax
|
|
|
|
.cfi_adjust_cfa_offset 4
|
|
|
|
.cfi_rel_offset eax, 0
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2013-10-08 08:53:13 +02:00
|
|
|
x86_call = """\
|
|
|
|
movl $%(__NR_name)s, %%eax
|
2015-11-12 08:02:14 +01:00
|
|
|
call *(%%esp)
|
|
|
|
addl $4, %%esp
|
|
|
|
|
2013-10-08 08:53:13 +02:00
|
|
|
cmpl $-MAX_ERRNO, %%eax
|
|
|
|
jb 1f
|
|
|
|
negl %%eax
|
|
|
|
pushl %%eax
|
2014-09-09 00:25:01 +02:00
|
|
|
call __set_errno_internal
|
2013-10-08 08:53:13 +02:00
|
|
|
addl $4, %%esp
|
|
|
|
1:
|
|
|
|
"""
|
|
|
|
|
|
|
|
x86_return = """\
|
|
|
|
ret
|
|
|
|
END(%(func)s)
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
#
|
2019-04-15 23:18:26 +02:00
|
|
|
# x86_64 assembler template for each syscall stub
|
2013-10-08 08:53:13 +02:00
|
|
|
#
|
|
|
|
|
|
|
|
x86_64_call = """\
|
|
|
|
movl $%(__NR_name)s, %%eax
|
|
|
|
syscall
|
|
|
|
cmpq $-MAX_ERRNO, %%rax
|
|
|
|
jb 1f
|
|
|
|
negl %%eax
|
|
|
|
movl %%eax, %%edi
|
2014-09-09 00:25:01 +02:00
|
|
|
call __set_errno_internal
|
2013-10-08 08:53:13 +02:00
|
|
|
1:
|
|
|
|
ret
|
|
|
|
END(%(func)s)
|
2012-01-28 02:51:42 +01:00
|
|
|
"""
|
|
|
|
|
2013-10-08 08:53:13 +02:00
|
|
|
|
2010-12-16 16:47:14 +01:00
|
|
|
def param_uses_64bits(param):
|
|
|
|
"""Returns True iff a syscall parameter description corresponds
|
|
|
|
to a 64-bit type."""
|
|
|
|
param = param.strip()
|
|
|
|
# First, check that the param type begins with one of the known
|
|
|
|
# 64-bit types.
|
|
|
|
if not ( \
|
|
|
|
param.startswith("int64_t") or param.startswith("uint64_t") or \
|
|
|
|
param.startswith("loff_t") or param.startswith("off64_t") or \
|
|
|
|
param.startswith("long long") or param.startswith("unsigned long long") or
|
|
|
|
param.startswith("signed long long") ):
|
|
|
|
return False
|
|
|
|
|
|
|
|
# Second, check that there is no pointer type here
|
|
|
|
if param.find("*") >= 0:
|
|
|
|
return False
|
|
|
|
|
|
|
|
# Ok
|
|
|
|
return True
|
|
|
|
|
2013-10-08 08:53:13 +02:00
|
|
|
|
2010-12-16 16:47:14 +01:00
|
|
|
def count_arm_param_registers(params):
|
|
|
|
"""This function is used to count the number of register used
|
2013-02-07 23:07:00 +01:00
|
|
|
to pass parameters when invoking an ARM system call.
|
2010-12-16 16:47:14 +01:00
|
|
|
This is because the ARM EABI mandates that 64-bit quantities
|
|
|
|
must be passed in an even+odd register pair. So, for example,
|
|
|
|
something like:
|
|
|
|
|
|
|
|
foo(int fd, off64_t pos)
|
|
|
|
|
|
|
|
would actually need 4 registers:
|
|
|
|
r0 -> int
|
|
|
|
r1 -> unused
|
|
|
|
r2-r3 -> pos
|
|
|
|
"""
|
|
|
|
count = 0
|
|
|
|
for param in params:
|
|
|
|
if param_uses_64bits(param):
|
|
|
|
if (count & 1) != 0:
|
|
|
|
count += 1
|
|
|
|
count += 2
|
|
|
|
else:
|
|
|
|
count += 1
|
|
|
|
return count
|
|
|
|
|
2013-10-08 08:53:13 +02:00
|
|
|
|
2010-12-16 16:47:14 +01:00
|
|
|
def count_generic_param_registers(params):
|
|
|
|
count = 0
|
|
|
|
for param in params:
|
|
|
|
if param_uses_64bits(param):
|
|
|
|
count += 2
|
|
|
|
else:
|
|
|
|
count += 1
|
|
|
|
return count
|
|
|
|
|
2013-10-08 08:53:13 +02:00
|
|
|
|
2012-12-12 10:11:48 +01:00
|
|
|
def count_generic_param_registers64(params):
|
|
|
|
count = 0
|
|
|
|
for param in params:
|
|
|
|
count += 1
|
|
|
|
return count
|
|
|
|
|
2013-10-08 08:53:13 +02:00
|
|
|
|
2013-03-22 21:50:44 +01:00
|
|
|
# This lets us support regular system calls like __NR_write and also weird
|
|
|
|
# ones like __ARM_NR_cacheflush, where the NR doesn't come at the start.
|
|
|
|
def make__NR_name(name):
|
2014-08-05 21:19:27 +02:00
|
|
|
if name.startswith("__ARM_NR_"):
|
2013-03-22 21:50:44 +01:00
|
|
|
return name
|
|
|
|
else:
|
|
|
|
return "__NR_%s" % (name)
|
|
|
|
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2013-10-25 02:03:20 +02:00
|
|
|
def add_footer(pointer_length, stub, syscall):
|
|
|
|
# Add any aliases for this syscall.
|
2013-10-08 08:53:13 +02:00
|
|
|
aliases = syscall["aliases"]
|
|
|
|
for alias in aliases:
|
2015-03-25 00:50:46 +01:00
|
|
|
stub += "\nALIAS_SYMBOL(%s, %s)\n" % (alias, syscall["func"])
|
2013-10-08 08:53:13 +02:00
|
|
|
return stub
|
2012-12-12 10:11:48 +01:00
|
|
|
|
|
|
|
|
2013-10-08 08:53:13 +02:00
|
|
|
def arm_eabi_genstub(syscall):
|
|
|
|
num_regs = count_arm_param_registers(syscall["params"])
|
|
|
|
if num_regs > 4:
|
|
|
|
return arm_eabi_call_long % syscall
|
|
|
|
return arm_eabi_call_default % syscall
|
2013-10-04 19:03:17 +02:00
|
|
|
|
2012-12-12 10:11:48 +01:00
|
|
|
|
2014-01-22 04:50:58 +01:00
|
|
|
def arm64_genstub(syscall):
|
|
|
|
return arm64_call % syscall
|
|
|
|
|
|
|
|
|
2022-10-10 19:06:43 +02:00
|
|
|
def riscv64_genstub(syscall):
|
|
|
|
return riscv64_call % syscall
|
|
|
|
|
|
|
|
|
2013-10-08 08:53:13 +02:00
|
|
|
def x86_genstub(syscall):
|
|
|
|
result = syscall_stub_header % syscall
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2013-10-08 08:53:13 +02:00
|
|
|
numparams = count_generic_param_registers(syscall["params"])
|
2015-11-12 08:02:14 +01:00
|
|
|
stack_bias = numparams*4 + 8
|
2014-01-07 01:39:10 +01:00
|
|
|
offset = 0
|
|
|
|
mov_result = ""
|
2014-05-30 03:17:09 +02:00
|
|
|
first_push = True
|
2014-01-07 01:39:10 +01:00
|
|
|
for register in x86_registers[:numparams]:
|
|
|
|
result += " pushl %%%s\n" % register
|
2014-05-30 03:17:09 +02:00
|
|
|
if first_push:
|
|
|
|
result += " .cfi_def_cfa_offset 8\n"
|
|
|
|
result += " .cfi_rel_offset %s, 0\n" % register
|
|
|
|
first_push = False
|
|
|
|
else:
|
|
|
|
result += " .cfi_adjust_cfa_offset 4\n"
|
|
|
|
result += " .cfi_rel_offset %s, 0\n" % register
|
2014-01-07 01:39:10 +01:00
|
|
|
mov_result += " mov %d(%%esp), %%%s\n" % (stack_bias+offset, register)
|
|
|
|
offset += 4
|
|
|
|
|
2015-11-12 08:02:14 +01:00
|
|
|
result += x86_call_prepare
|
2014-05-30 03:17:09 +02:00
|
|
|
result += mov_result
|
2013-10-08 08:53:13 +02:00
|
|
|
result += x86_call % syscall
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2014-01-07 01:39:10 +01:00
|
|
|
for register in reversed(x86_registers[:numparams]):
|
|
|
|
result += " popl %%%s\n" % register
|
2008-12-18 03:03:48 +01:00
|
|
|
|
2013-10-08 08:53:13 +02:00
|
|
|
result += x86_return % syscall
|
|
|
|
return result
|
2008-12-18 03:03:48 +01:00
|
|
|
|
2013-10-07 17:49:09 +02:00
|
|
|
|
2013-10-08 08:53:13 +02:00
|
|
|
def x86_genstub_socketcall(syscall):
|
|
|
|
# %ebx <--- Argument 1 - The call id of the needed vectored
|
|
|
|
# syscall (socket, bind, recv, etc)
|
|
|
|
# %ecx <--- Argument 2 - Pointer to the rest of the arguments
|
|
|
|
# from the original function called (socket())
|
|
|
|
|
|
|
|
result = syscall_stub_header % syscall
|
2008-12-18 03:03:48 +01:00
|
|
|
|
2013-10-08 08:53:13 +02:00
|
|
|
# save the regs we need
|
2014-01-07 01:39:10 +01:00
|
|
|
result += " pushl %ebx\n"
|
|
|
|
result += " .cfi_def_cfa_offset 8\n"
|
|
|
|
result += " .cfi_rel_offset ebx, 0\n"
|
2014-05-30 03:17:09 +02:00
|
|
|
result += " pushl %ecx\n"
|
|
|
|
result += " .cfi_adjust_cfa_offset 4\n"
|
|
|
|
result += " .cfi_rel_offset ecx, 0\n"
|
2015-11-12 08:02:14 +01:00
|
|
|
stack_bias = 16
|
|
|
|
|
|
|
|
result += x86_call_prepare
|
2008-12-18 03:03:48 +01:00
|
|
|
|
2013-10-08 08:53:13 +02:00
|
|
|
# set the call id (%ebx)
|
2014-01-07 01:39:10 +01:00
|
|
|
result += " mov $%d, %%ebx\n" % syscall["socketcall_id"]
|
2008-12-18 03:03:48 +01:00
|
|
|
|
2013-10-08 08:53:13 +02:00
|
|
|
# set the pointer to the rest of the args into %ecx
|
2014-01-07 01:39:10 +01:00
|
|
|
result += " mov %esp, %ecx\n"
|
|
|
|
result += " addl $%d, %%ecx\n" % (stack_bias)
|
2008-12-18 03:03:48 +01:00
|
|
|
|
2013-10-08 08:53:13 +02:00
|
|
|
# now do the syscall code itself
|
|
|
|
result += x86_call % syscall
|
2008-12-18 03:03:48 +01:00
|
|
|
|
2013-10-08 08:53:13 +02:00
|
|
|
# now restore the saved regs
|
2014-01-07 01:39:10 +01:00
|
|
|
result += " popl %ecx\n"
|
|
|
|
result += " popl %ebx\n"
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2013-10-08 08:53:13 +02:00
|
|
|
# epilog
|
|
|
|
result += x86_return % syscall
|
|
|
|
return result
|
2008-10-21 16:00:00 +02:00
|
|
|
|
|
|
|
|
2013-10-08 08:53:13 +02:00
|
|
|
def x86_64_genstub(syscall):
|
|
|
|
result = syscall_stub_header % syscall
|
|
|
|
num_regs = count_generic_param_registers64(syscall["params"])
|
|
|
|
if (num_regs > 3):
|
|
|
|
# rcx is used as 4th argument. Kernel wants it at r10.
|
|
|
|
result += " movq %rcx, %r10\n"
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2013-10-08 08:53:13 +02:00
|
|
|
result += x86_64_call % syscall
|
|
|
|
return result
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2013-10-08 08:53:13 +02:00
|
|
|
|
2014-08-20 20:16:11 +02:00
|
|
|
class SysCallsTxtParser:
|
|
|
|
def __init__(self):
|
|
|
|
self.syscalls = []
|
2022-11-08 03:57:55 +01:00
|
|
|
self.lineno = 0
|
|
|
|
self.errors = False
|
2014-08-20 20:16:11 +02:00
|
|
|
|
|
|
|
def E(self, msg):
|
2021-02-03 22:13:57 +01:00
|
|
|
print("%d: %s" % (self.lineno, msg))
|
2022-11-08 03:57:55 +01:00
|
|
|
self.errors = True
|
2014-08-20 20:16:11 +02:00
|
|
|
|
|
|
|
def parse_line(self, line):
|
|
|
|
""" parse a syscall spec line.
|
|
|
|
|
|
|
|
line processing, format is
|
|
|
|
return type func_name[|alias_list][:syscall_name[:socketcall_id]] ( [paramlist] ) architecture_list
|
|
|
|
"""
|
|
|
|
pos_lparen = line.find('(')
|
|
|
|
E = self.E
|
|
|
|
if pos_lparen < 0:
|
|
|
|
E("missing left parenthesis in '%s'" % line)
|
|
|
|
return
|
|
|
|
|
|
|
|
pos_rparen = line.rfind(')')
|
|
|
|
if pos_rparen < 0 or pos_rparen <= pos_lparen:
|
|
|
|
E("missing or misplaced right parenthesis in '%s'" % line)
|
|
|
|
return
|
|
|
|
|
|
|
|
return_type = line[:pos_lparen].strip().split()
|
|
|
|
if len(return_type) < 2:
|
|
|
|
E("missing return type in '%s'" % line)
|
|
|
|
return
|
|
|
|
|
|
|
|
syscall_func = return_type[-1]
|
2021-02-03 22:13:57 +01:00
|
|
|
return_type = ' '.join(return_type[:-1])
|
2014-08-20 20:16:11 +02:00
|
|
|
socketcall_id = -1
|
|
|
|
|
|
|
|
pos_colon = syscall_func.find(':')
|
|
|
|
if pos_colon < 0:
|
|
|
|
syscall_name = syscall_func
|
|
|
|
else:
|
|
|
|
if pos_colon == 0 or pos_colon+1 >= len(syscall_func):
|
|
|
|
E("misplaced colon in '%s'" % line)
|
|
|
|
return
|
|
|
|
|
|
|
|
# now find if there is a socketcall_id for a dispatch-type syscall
|
|
|
|
# after the optional 2nd colon
|
|
|
|
pos_colon2 = syscall_func.find(':', pos_colon + 1)
|
|
|
|
if pos_colon2 < 0:
|
|
|
|
syscall_name = syscall_func[pos_colon+1:]
|
|
|
|
syscall_func = syscall_func[:pos_colon]
|
|
|
|
else:
|
|
|
|
if pos_colon2+1 >= len(syscall_func):
|
|
|
|
E("misplaced colon2 in '%s'" % line)
|
|
|
|
return
|
|
|
|
syscall_name = syscall_func[(pos_colon+1):pos_colon2]
|
|
|
|
socketcall_id = int(syscall_func[pos_colon2+1:])
|
|
|
|
syscall_func = syscall_func[:pos_colon]
|
|
|
|
|
|
|
|
alias_delim = syscall_func.find('|')
|
|
|
|
if alias_delim > 0:
|
|
|
|
alias_list = syscall_func[alias_delim+1:].strip()
|
|
|
|
syscall_func = syscall_func[:alias_delim]
|
|
|
|
alias_delim = syscall_name.find('|')
|
|
|
|
if alias_delim > 0:
|
|
|
|
syscall_name = syscall_name[:alias_delim]
|
2021-02-03 22:13:57 +01:00
|
|
|
syscall_aliases = alias_list.split(',')
|
2014-08-20 20:16:11 +02:00
|
|
|
else:
|
|
|
|
syscall_aliases = []
|
|
|
|
|
|
|
|
if pos_rparen > pos_lparen+1:
|
|
|
|
syscall_params = line[pos_lparen+1:pos_rparen].split(',')
|
2021-02-03 22:13:57 +01:00
|
|
|
params = ','.join(syscall_params)
|
2014-08-20 20:16:11 +02:00
|
|
|
else:
|
|
|
|
syscall_params = []
|
|
|
|
params = "void"
|
|
|
|
|
|
|
|
t = {
|
|
|
|
"name" : syscall_name,
|
|
|
|
"func" : syscall_func,
|
|
|
|
"aliases" : syscall_aliases,
|
|
|
|
"params" : syscall_params,
|
|
|
|
"decl" : "%-15s %s (%s);" % (return_type, syscall_func, params),
|
|
|
|
"socketcall_id" : socketcall_id
|
|
|
|
}
|
|
|
|
|
|
|
|
# Parse the architecture list.
|
|
|
|
arch_list = line[pos_rparen+1:].strip()
|
|
|
|
if arch_list == "all":
|
2019-09-18 01:37:05 +02:00
|
|
|
for arch in SupportedArchitectures:
|
2014-08-20 20:16:11 +02:00
|
|
|
t[arch] = True
|
|
|
|
else:
|
2021-02-03 22:13:57 +01:00
|
|
|
for arch in arch_list.split(','):
|
2020-02-13 23:21:55 +01:00
|
|
|
if arch == "lp32":
|
|
|
|
for arch in SupportedArchitectures:
|
|
|
|
if "64" not in arch:
|
|
|
|
t[arch] = True
|
|
|
|
elif arch == "lp64":
|
|
|
|
for arch in SupportedArchitectures:
|
|
|
|
if "64" in arch:
|
|
|
|
t[arch] = True
|
|
|
|
elif arch in SupportedArchitectures:
|
2014-08-20 20:16:11 +02:00
|
|
|
t[arch] = True
|
|
|
|
else:
|
|
|
|
E("invalid syscall architecture '%s' in '%s'" % (arch, line))
|
|
|
|
return
|
|
|
|
|
|
|
|
self.syscalls.append(t)
|
|
|
|
|
2017-02-14 22:32:23 +01:00
|
|
|
def parse_open_file(self, fp):
|
|
|
|
for line in fp:
|
2014-08-20 20:16:11 +02:00
|
|
|
self.lineno += 1
|
|
|
|
line = line.strip()
|
|
|
|
if not line: continue
|
|
|
|
if line[0] == '#': continue
|
|
|
|
self.parse_line(line)
|
2022-11-08 03:57:55 +01:00
|
|
|
if self.errors:
|
|
|
|
sys.exit(1)
|
2014-08-20 20:16:11 +02:00
|
|
|
|
2017-02-14 22:32:23 +01:00
|
|
|
def parse_file(self, file_path):
|
|
|
|
with open(file_path) as fp:
|
2017-04-11 18:27:29 +02:00
|
|
|
self.parse_open_file(fp)
|
2014-08-20 20:16:11 +02:00
|
|
|
|
|
|
|
|
2019-09-26 20:47:03 +02:00
|
|
|
def main(arch, syscall_file):
|
2019-04-16 21:31:00 +02:00
|
|
|
parser = SysCallsTxtParser()
|
2019-09-26 20:47:03 +02:00
|
|
|
parser.parse_file(syscall_file)
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2019-04-16 21:31:00 +02:00
|
|
|
for syscall in parser.syscalls:
|
|
|
|
syscall["__NR_name"] = make__NR_name(syscall["name"])
|
2013-10-08 08:53:13 +02:00
|
|
|
|
2021-04-15 12:09:04 +02:00
|
|
|
if "arm" in syscall:
|
2019-04-16 21:31:00 +02:00
|
|
|
syscall["asm-arm"] = add_footer(32, arm_eabi_genstub(syscall), syscall)
|
2014-01-22 04:50:58 +01:00
|
|
|
|
2021-04-15 12:09:04 +02:00
|
|
|
if "arm64" in syscall:
|
2019-04-16 21:31:00 +02:00
|
|
|
syscall["asm-arm64"] = add_footer(64, arm64_genstub(syscall), syscall)
|
2013-10-08 08:53:13 +02:00
|
|
|
|
2022-10-10 19:06:43 +02:00
|
|
|
if "riscv64" in syscall:
|
|
|
|
syscall["asm-riscv64"] = add_footer(64, riscv64_genstub(syscall), syscall)
|
|
|
|
|
2021-04-15 12:09:04 +02:00
|
|
|
if "x86" in syscall:
|
2019-04-16 21:31:00 +02:00
|
|
|
if syscall["socketcall_id"] >= 0:
|
|
|
|
syscall["asm-x86"] = add_footer(32, x86_genstub_socketcall(syscall), syscall)
|
|
|
|
else:
|
|
|
|
syscall["asm-x86"] = add_footer(32, x86_genstub(syscall), syscall)
|
|
|
|
elif syscall["socketcall_id"] >= 0:
|
|
|
|
E("socketcall_id for dispatch syscalls is only supported for x86 in '%s'" % t)
|
|
|
|
return
|
2013-10-08 08:53:13 +02:00
|
|
|
|
2021-04-15 12:09:04 +02:00
|
|
|
if "x86_64" in syscall:
|
2019-04-16 21:31:00 +02:00
|
|
|
syscall["asm-x86_64"] = add_footer(64, x86_64_genstub(syscall), syscall)
|
2013-03-22 02:06:55 +01:00
|
|
|
|
2019-04-16 21:31:00 +02:00
|
|
|
print("/* Generated by gensyscalls.py. Do not edit. */\n")
|
|
|
|
print("#include <private/bionic_asm.h>\n")
|
|
|
|
for syscall in parser.syscalls:
|
2021-04-15 12:09:04 +02:00
|
|
|
if ("asm-%s" % arch) in syscall:
|
2019-04-16 21:31:00 +02:00
|
|
|
print(syscall["asm-%s" % arch])
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2019-12-03 17:18:43 +01:00
|
|
|
if arch == 'arm64':
|
|
|
|
print('\nNOTE_GNU_PROPERTY()\n')
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2016-11-11 20:33:42 +01:00
|
|
|
if __name__ == "__main__":
|
2019-09-26 20:47:03 +02:00
|
|
|
if len(sys.argv) < 2:
|
2021-02-03 22:13:57 +01:00
|
|
|
print("Usage: gensyscalls.py ARCH SOURCE_FILE")
|
2019-09-26 20:47:03 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
arch = sys.argv[1]
|
|
|
|
syscall_file = sys.argv[2]
|
|
|
|
main(arch, syscall_file)
|