Merge "Make it easier to add syscalls for another architecture."
This commit is contained in:
commit
7b538021bd
|
@ -2,7 +2,7 @@
|
||||||
#
|
#
|
||||||
# Each non-blank, non-comment line has the following format:
|
# Each non-blank, non-comment line has the following format:
|
||||||
#
|
#
|
||||||
# return_type func_name[:syscall_name[:call_id]]([parameter_list]) arch_list
|
# return_type func_name[:syscall_name[:socketcall_id]]([parameter_list]) arch_list
|
||||||
#
|
#
|
||||||
# where:
|
# where:
|
||||||
# arch_list ::= "all" | "custom" | arch+
|
# arch_list ::= "all" | "custom" | arch+
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# auto-generated by gensyscalls.py, do not touch
|
# Auto-generated by gensyscalls.py. Do not edit.
|
||||||
syscall_src :=
|
syscall_src :=
|
||||||
syscall_src += arch-arm/syscalls/_exit.S
|
syscall_src += arch-arm/syscalls/_exit.S
|
||||||
syscall_src += arch-arm/syscalls/_exit_thread.S
|
syscall_src += arch-arm/syscalls/_exit_thread.S
|
||||||
syscall_src += arch-arm/syscalls/__fork.S
|
syscall_src += arch-arm/syscalls/__fork.S
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# auto-generated by gensyscalls.py, do not touch
|
# Auto-generated by gensyscalls.py. Do not edit.
|
||||||
syscall_src :=
|
syscall_src :=
|
||||||
syscall_src += arch-mips/syscalls/_exit.S
|
syscall_src += arch-mips/syscalls/_exit.S
|
||||||
syscall_src += arch-mips/syscalls/_exit_thread.S
|
syscall_src += arch-mips/syscalls/_exit_thread.S
|
||||||
syscall_src += arch-mips/syscalls/__fork.S
|
syscall_src += arch-mips/syscalls/__fork.S
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# auto-generated by gensyscalls.py, do not touch
|
# Auto-generated by gensyscalls.py. Do not edit.
|
||||||
syscall_src :=
|
syscall_src :=
|
||||||
syscall_src += arch-x86/syscalls/_exit.S
|
syscall_src += arch-x86/syscalls/_exit.S
|
||||||
syscall_src += arch-x86/syscalls/_exit_thread.S
|
syscall_src += arch-x86/syscalls/_exit_thread.S
|
||||||
syscall_src += arch-x86/syscalls/__fork.S
|
syscall_src += arch-x86/syscalls/__fork.S
|
||||||
|
|
|
@ -2,9 +2,7 @@
|
||||||
|
|
||||||
import sys, os, commands, string
|
import sys, os, commands, string
|
||||||
|
|
||||||
# support Bionic architectures, add new ones as appropriate
|
all_arches = [ "arm", "mips", "x86" ]
|
||||||
#
|
|
||||||
bionic_archs = [ "arm", "x86", "mips" ]
|
|
||||||
|
|
||||||
# basic debugging trace support
|
# basic debugging trace support
|
||||||
# call D_setlevel to set the verbosity level
|
# call D_setlevel to set the verbosity level
|
||||||
|
@ -51,7 +49,7 @@ class SysCallsTxtParser:
|
||||||
""" parse a syscall spec line.
|
""" parse a syscall spec line.
|
||||||
|
|
||||||
line processing, format is
|
line processing, format is
|
||||||
return type func_name[:syscall_name[:call_id]] ( [paramlist] ) architecture_list
|
return type func_name[:syscall_name[:socketcall_id]] ( [paramlist] ) architecture_list
|
||||||
"""
|
"""
|
||||||
pos_lparen = line.find('(')
|
pos_lparen = line.find('(')
|
||||||
E = self.E
|
E = self.E
|
||||||
|
@ -71,7 +69,7 @@ class SysCallsTxtParser:
|
||||||
|
|
||||||
syscall_func = return_type[-1]
|
syscall_func = return_type[-1]
|
||||||
return_type = string.join(return_type[:-1],' ')
|
return_type = string.join(return_type[:-1],' ')
|
||||||
call_id = -1
|
socketcall_id = -1
|
||||||
|
|
||||||
pos_colon = syscall_func.find(':')
|
pos_colon = syscall_func.find(':')
|
||||||
if pos_colon < 0:
|
if pos_colon < 0:
|
||||||
|
@ -81,7 +79,7 @@ class SysCallsTxtParser:
|
||||||
E("misplaced colon in '%s'" % line)
|
E("misplaced colon in '%s'" % line)
|
||||||
return
|
return
|
||||||
|
|
||||||
# now find if there is a call_id for a dispatch-type syscall
|
# now find if there is a socketcall_id for a dispatch-type syscall
|
||||||
# after the optional 2nd colon
|
# after the optional 2nd colon
|
||||||
pos_colon2 = syscall_func.find(':', pos_colon + 1)
|
pos_colon2 = syscall_func.find(':', pos_colon + 1)
|
||||||
if pos_colon2 < 0:
|
if pos_colon2 < 0:
|
||||||
|
@ -92,7 +90,7 @@ class SysCallsTxtParser:
|
||||||
E("misplaced colon2 in '%s'" % line)
|
E("misplaced colon2 in '%s'" % line)
|
||||||
return
|
return
|
||||||
syscall_name = syscall_func[(pos_colon+1):pos_colon2]
|
syscall_name = syscall_func[(pos_colon+1):pos_colon2]
|
||||||
call_id = int(syscall_func[pos_colon2+1:])
|
socketcall_id = int(syscall_func[pos_colon2+1:])
|
||||||
syscall_func = syscall_func[:pos_colon]
|
syscall_func = syscall_func[:pos_colon]
|
||||||
|
|
||||||
if pos_rparen > pos_lparen+1:
|
if pos_rparen > pos_lparen+1:
|
||||||
|
@ -102,51 +100,35 @@ class SysCallsTxtParser:
|
||||||
syscall_params = []
|
syscall_params = []
|
||||||
params = "void"
|
params = "void"
|
||||||
|
|
||||||
|
t = {
|
||||||
|
"name" : syscall_name,
|
||||||
|
"func" : syscall_func,
|
||||||
|
"params" : syscall_params,
|
||||||
|
"decl" : "%-15s %s (%s);" % (return_type, syscall_func, params),
|
||||||
|
"socketcall_id" : socketcall_id
|
||||||
|
}
|
||||||
|
|
||||||
# Parse the architecture list.
|
# Parse the architecture list.
|
||||||
syscall_common = -1
|
|
||||||
syscall_arm = -1
|
|
||||||
syscall_x86 = -1
|
|
||||||
syscall_mips = -1
|
|
||||||
arch_list = line[pos_rparen+1:].strip()
|
arch_list = line[pos_rparen+1:].strip()
|
||||||
if arch_list == "custom":
|
if arch_list == "custom":
|
||||||
pass
|
pass
|
||||||
elif arch_list == "all":
|
elif arch_list == "all":
|
||||||
syscall_common = 1
|
for arch in all_arches:
|
||||||
|
t[arch] = True
|
||||||
else:
|
else:
|
||||||
for arch in string.split(arch_list, ','):
|
for arch in string.split(arch_list, ','):
|
||||||
if arch == "arm":
|
if arch in all_arches:
|
||||||
syscall_arm = 1
|
t[arch] = True
|
||||||
elif arch == "x86":
|
|
||||||
syscall_x86 = 1
|
|
||||||
elif arch == "mips":
|
|
||||||
syscall_mips = 1
|
|
||||||
else:
|
else:
|
||||||
E("invalid syscall architecture list in '%s'" % line)
|
E("invalid syscall architecture list in '%s'" % line)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
self.syscalls.append(t)
|
||||||
|
|
||||||
global verbose
|
global verbose
|
||||||
if verbose >= 2:
|
if verbose >= 2:
|
||||||
if call_id == -1:
|
print t
|
||||||
if syscall_common == -1:
|
|
||||||
print "%s: %d,%d,%d" % (syscall_name, syscall_arm, syscall_x86, syscall_mips)
|
|
||||||
else:
|
|
||||||
print "%s: %d" % (syscall_name, syscall_common)
|
|
||||||
else:
|
|
||||||
if syscall_common == -1:
|
|
||||||
print "%s(%d): %d,%d,%d" % (syscall_name, call_id, syscall_arm, syscall_x86, syscall_mips)
|
|
||||||
else:
|
|
||||||
print "%s(%d): %d" % (syscall_name, call_id, syscall_common)
|
|
||||||
|
|
||||||
t = { "armid" : syscall_arm,
|
|
||||||
"x86id" : syscall_x86,
|
|
||||||
"mipsid" : syscall_mips,
|
|
||||||
"common" : syscall_common,
|
|
||||||
"cid" : call_id,
|
|
||||||
"name" : syscall_name,
|
|
||||||
"func" : syscall_func,
|
|
||||||
"params" : syscall_params,
|
|
||||||
"decl" : "%-15s %s (%s);" % (return_type, syscall_func, params) }
|
|
||||||
self.syscalls.append(t)
|
|
||||||
|
|
||||||
def parse_file(self, file_path):
|
def parse_file(self, file_path):
|
||||||
D2("parse_file: %s" % file_path)
|
D2("parse_file: %s" % file_path)
|
||||||
|
|
|
@ -15,9 +15,6 @@ bionic_libc_root = os.environ["ANDROID_BUILD_TOP"] + "/bionic/libc/"
|
||||||
# temp directory where we store all intermediate files
|
# temp directory where we store all intermediate files
|
||||||
bionic_temp = "/tmp/bionic_gensyscalls/"
|
bionic_temp = "/tmp/bionic_gensyscalls/"
|
||||||
|
|
||||||
# all architectures, update as you see fit
|
|
||||||
all_archs = [ "arm", "mips", "x86" ]
|
|
||||||
|
|
||||||
def make_dir( path ):
|
def make_dir( path ):
|
||||||
path = os.path.abspath(path)
|
path = os.path.abspath(path)
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
|
@ -217,10 +214,7 @@ class State:
|
||||||
result += x86_return % t
|
result += x86_return % t
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def x86_genstub_cid(self, fname, numparams, idname, cid):
|
def x86_genstub_socketcall(self, fname, idname, socketcall_id):
|
||||||
# We'll ignore numparams here because in reality, if there is a
|
|
||||||
# dispatch call (like a socketcall syscall) there are actually
|
|
||||||
# only 2 arguments to the syscall and 2 regs we have to save:
|
|
||||||
# %ebx <--- Argument 1 - The call id of the needed vectored
|
# %ebx <--- Argument 1 - The call id of the needed vectored
|
||||||
# syscall (socket, bind, recv, etc)
|
# syscall (socket, bind, recv, etc)
|
||||||
# %ecx <--- Argument 2 - Pointer to the rest of the arguments
|
# %ecx <--- Argument 2 - Pointer to the rest of the arguments
|
||||||
|
@ -238,7 +232,7 @@ class State:
|
||||||
stack_bias += 4
|
stack_bias += 4
|
||||||
|
|
||||||
# set the call id (%ebx)
|
# set the call id (%ebx)
|
||||||
result += " mov $%d, %%ebx" % (cid) + "\n"
|
result += " mov $%d, %%ebx" % (socketcall_id) + "\n"
|
||||||
|
|
||||||
# set the pointer to the rest of the args into %ecx
|
# set the pointer to the rest of the args into %ecx
|
||||||
result += " mov %esp, %ecx" + "\n"
|
result += " mov %esp, %ecx" + "\n"
|
||||||
|
@ -281,23 +275,23 @@ class State:
|
||||||
syscall_func = t["func"]
|
syscall_func = t["func"]
|
||||||
syscall_params = t["params"]
|
syscall_params = t["params"]
|
||||||
syscall_name = t["name"]
|
syscall_name = t["name"]
|
||||||
|
__NR_name = make__NR_name(t["name"])
|
||||||
|
|
||||||
if t["common"] >= 0 or t["armid"] >= 0:
|
if t.has_key("arm"):
|
||||||
num_regs = count_arm_param_registers(syscall_params)
|
num_regs = count_arm_param_registers(syscall_params)
|
||||||
t["asm-arm"] = self.arm_eabi_genstub(syscall_func, num_regs, make__NR_name(syscall_name))
|
t["asm-arm"] = self.arm_eabi_genstub(syscall_func, num_regs, __NR_name)
|
||||||
|
|
||||||
if t["common"] >= 0 or t["x86id"] >= 0:
|
if t.has_key("x86"):
|
||||||
num_regs = count_generic_param_registers(syscall_params)
|
num_regs = count_generic_param_registers(syscall_params)
|
||||||
if t["cid"] >= 0:
|
if t["socketcall_id"] >= 0:
|
||||||
t["asm-x86"] = self.x86_genstub_cid(syscall_func, num_regs, make__NR_name(syscall_name), t["cid"])
|
t["asm-x86"] = self.x86_genstub_socketcall(syscall_func, __NR_name, t["socketcall_id"])
|
||||||
else:
|
else:
|
||||||
t["asm-x86"] = self.x86_genstub(syscall_func, num_regs, make__NR_name(syscall_name))
|
t["asm-x86"] = self.x86_genstub(syscall_func, num_regs, __NR_name)
|
||||||
elif t["cid"] >= 0:
|
elif t["socketcall_id"] >= 0:
|
||||||
E("cid for dispatch syscalls is only supported for x86 in "
|
E("socketcall_id for dispatch syscalls is only supported for x86 in '%s'" % t)
|
||||||
"'%s'" % syscall_name)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if t["common"] >= 0 or t["mipsid"] >= 0:
|
if t.has_key("mips"):
|
||||||
t["asm-mips"] = self.mips_genstub(syscall_func, make__NR_name(syscall_name))
|
t["asm-mips"] = self.mips_genstub(syscall_func, make__NR_name(syscall_name))
|
||||||
|
|
||||||
|
|
||||||
|
@ -336,60 +330,39 @@ class State:
|
||||||
self.other_files.append(glibc_syscalls_h_path)
|
self.other_files.append(glibc_syscalls_h_path)
|
||||||
|
|
||||||
|
|
||||||
# now dump the contents of syscalls.mk
|
# Write the contents of syscalls.mk.
|
||||||
def gen_arch_syscalls_mk(self, arch):
|
def gen_arch_syscalls_mk(self, arch):
|
||||||
path = "arch-%s/syscalls.mk" % arch
|
path = "arch-%s/syscalls.mk" % arch
|
||||||
D( "generating "+path )
|
D("generating " + path)
|
||||||
fp = create_file( path )
|
fp = create_file(path)
|
||||||
fp.write( "# auto-generated by gensyscalls.py, do not touch\n" )
|
fp.write("# Auto-generated by gensyscalls.py. Do not edit.\n")
|
||||||
fp.write( "syscall_src := \n" )
|
fp.write("syscall_src :=\n")
|
||||||
arch_test = {
|
|
||||||
"arm": lambda x: x.has_key("asm-arm"),
|
|
||||||
"x86": lambda x: x.has_key("asm-x86"),
|
|
||||||
"mips": lambda x: x.has_key("asm-mips")
|
|
||||||
}
|
|
||||||
|
|
||||||
for sc in self.syscalls:
|
for sc in self.syscalls:
|
||||||
if arch_test[arch](sc):
|
if sc.has_key("asm-%s" % arch):
|
||||||
fp.write("syscall_src += arch-%s/syscalls/%s.S\n" %
|
fp.write("syscall_src += arch-%s/syscalls/%s.S\n" % (arch, sc["func"]))
|
||||||
(arch, sc["func"]))
|
|
||||||
fp.close()
|
fp.close()
|
||||||
self.other_files.append( path )
|
self.other_files.append(path)
|
||||||
|
|
||||||
|
|
||||||
# now generate each syscall stub
|
# Write each syscall stub.
|
||||||
def gen_syscall_stubs(self):
|
def gen_syscall_stubs(self):
|
||||||
for sc in self.syscalls:
|
for sc in self.syscalls:
|
||||||
if sc.has_key("asm-arm") and 'arm' in all_archs:
|
for arch in all_arches:
|
||||||
fname = "arch-arm/syscalls/%s.S" % sc["func"]
|
if sc.has_key("asm-%s" % arch):
|
||||||
D2( ">>> generating "+fname )
|
filename = "arch-%s/syscalls/%s.S" % (arch, sc["func"])
|
||||||
fp = create_file( fname )
|
D2(">>> generating " + filename)
|
||||||
fp.write(sc["asm-arm"])
|
fp = create_file(filename)
|
||||||
fp.close()
|
fp.write(sc["asm-%s" % arch])
|
||||||
self.new_stubs.append( fname )
|
fp.close()
|
||||||
|
self.new_stubs.append(filename)
|
||||||
|
|
||||||
if sc.has_key("asm-x86") and 'x86' in all_archs:
|
|
||||||
fname = "arch-x86/syscalls/%s.S" % sc["func"]
|
|
||||||
D2( ">>> generating "+fname )
|
|
||||||
fp = create_file( fname )
|
|
||||||
fp.write(sc["asm-x86"])
|
|
||||||
fp.close()
|
|
||||||
self.new_stubs.append( fname )
|
|
||||||
|
|
||||||
if sc.has_key("asm-mips") and 'mips' in all_archs:
|
def regenerate(self):
|
||||||
fname = "arch-mips/syscalls/%s.S" % sc["func"]
|
|
||||||
D2( ">>> generating "+fname )
|
|
||||||
fp = create_file( fname )
|
|
||||||
fp.write(sc["asm-mips"])
|
|
||||||
fp.close()
|
|
||||||
self.new_stubs.append( fname )
|
|
||||||
|
|
||||||
def regenerate(self):
|
|
||||||
D( "scanning for existing architecture-specific stub files" )
|
D( "scanning for existing architecture-specific stub files" )
|
||||||
|
|
||||||
bionic_libc_root_len = len(bionic_libc_root)
|
bionic_libc_root_len = len(bionic_libc_root)
|
||||||
|
|
||||||
for arch in all_archs:
|
for arch in all_arches:
|
||||||
arch_path = bionic_libc_root + "arch-" + arch
|
arch_path = bionic_libc_root + "arch-" + arch
|
||||||
D( "scanning " + arch_path )
|
D( "scanning " + arch_path )
|
||||||
files = glob.glob( arch_path + "/syscalls/*.S" )
|
files = glob.glob( arch_path + "/syscalls/*.S" )
|
||||||
|
@ -405,7 +378,7 @@ class State:
|
||||||
D( "re-generating stubs and support files" )
|
D( "re-generating stubs and support files" )
|
||||||
|
|
||||||
self.gen_glibc_syscalls_h()
|
self.gen_glibc_syscalls_h()
|
||||||
for arch in all_archs:
|
for arch in all_arches:
|
||||||
self.gen_arch_syscalls_mk(arch)
|
self.gen_arch_syscalls_mk(arch)
|
||||||
self.gen_syscall_stubs()
|
self.gen_syscall_stubs()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue