Generate assembler system call stubs via genrule.

There's no need to check in generated code.

Test: builds & boots
Change-Id: Ife368bca4349d4adeb0666db590356196b4fbd63
This commit is contained in:
Elliott Hughes 2019-04-16 12:31:00 -07:00
parent b9a7c651f1
commit 782c485880
14 changed files with 79 additions and 22897 deletions

View file

@ -1,3 +1,2 @@
[Hook Scripts]
notice = tools/update_notice.sh
syscalls = tools/update_syscalls.sh

View file

@ -162,17 +162,16 @@ Adding a system call usually involves:
1. Add entries to SYSCALLS.TXT.
See SYSCALLS.TXT itself for documentation on the format.
2. Run the gensyscalls.py script.
3. Add constants (and perhaps types) to the appropriate header file.
2. Add constants (and perhaps types) to the appropriate header file.
Note that you should check to see whether the constants are already in
kernel uapi header files, in which case you just need to make sure that
the appropriate POSIX header file in libc/include/ includes the
relevant file or files.
4. Add function declarations to the appropriate header file. Don't forget
3. Add function declarations to the appropriate header file. Don't forget
to include the appropriate `__INTRODUCED_IN()`.
5. Add the function name to the correct section in libc/libc.map.txt and
4. Add the function name to the correct section in libc/libc.map.txt and
run `./libc/tools/genversion-scripts.py`.
6. Add at least basic tests. Even a test that deliberately supplies
5. Add at least basic tests. Even a test that deliberately supplies
an invalid argument helps check that we're generating the right symbol
and have the right declaration in the header file, and that you correctly
updated the maps in step 5. (You can use strace(1) to confirm that the

View file

@ -1241,27 +1241,53 @@ cc_library_static {
// libc_syscalls.a
// ========================================================
genrule {
name: "syscalls-arm.S",
out: ["syscalls-arm.S"],
srcs: ["SYSCALLS.TXT"],
tool_files: [":bionic-gensyscalls"],
cmd: "$(location :bionic-gensyscalls) arm $(in) > $(out)",
}
genrule {
name: "syscalls-arm64.S",
out: ["syscalls-arm64.S"],
srcs: ["SYSCALLS.TXT"],
tool_files: [":bionic-gensyscalls"],
cmd: "$(location :bionic-gensyscalls) arm64 $(in) > $(out)",
}
genrule {
name: "syscalls-x86.S",
out: ["syscalls-x86.S"],
srcs: ["SYSCALLS.TXT"],
tool_files: [":bionic-gensyscalls"],
cmd: "$(location :bionic-gensyscalls) x86 $(in) > $(out)",
}
genrule {
name: "syscalls-x86_64.S",
out: ["syscalls-x86_64.S"],
srcs: ["SYSCALLS.TXT"],
tool_files: [":bionic-gensyscalls"],
cmd: "$(location :bionic-gensyscalls) x86_64 $(in) > $(out)",
}
cc_library_static {
defaults: ["libc_defaults"],
srcs: ["bionic/__set_errno.cpp"],
arch: {
arm: {
srcs: ["arch-arm/syscalls.S"],
srcs: [":syscalls-arm.S"],
},
arm64: {
srcs: ["arch-arm64/syscalls.S"],
},
mips: {
srcs: ["arch-mips/syscalls.S"],
},
mips64: {
srcs: ["arch-mips64/syscalls.S"],
srcs: [":syscalls-arm64.S"],
},
x86: {
srcs: ["arch-x86/syscalls.S"],
srcs: [":syscalls-x86.S"],
},
x86_64: {
srcs: ["arch-x86_64/syscalls.S"],
srcs: [":syscalls-x86_64.S"],
},
},
name: "libc_syscalls",
@ -2455,19 +2481,19 @@ cc_library_shared {
arch: {
arm: {
srcs: ["arch-arm/syscalls.S"],
srcs: [":syscalls-arm.S"],
},
arm64: {
srcs: ["arch-arm64/syscalls.S"],
srcs: [":syscalls-arm64.S"],
},
x86: {
srcs: [
"arch-x86/bionic/__libc_init_sysinfo.cpp",
"arch-x86/syscalls.S",
":syscalls-x86.S",
],
},
x86_64: {
srcs: ["arch-x86_64/syscalls.S"],
srcs: [":syscalls-x86_64.S"],
},
},

View file

@ -22,7 +22,8 @@
#
# - Each parameter type is assumed to be stored in 32 bits.
#
# This file is processed by a python script named gensyscalls.py.
# This file is processed by a python script named gensyscalls.py, run via
# genrules in Android.bp.
int execve(const char*, char* const*, char* const*) all

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -81,10 +81,5 @@ Next, run this command to copy the parsed files to bionic/libc/kernel/uapi:
bionic/libc/kernel/tools/update_all.py
```
Finally, run this command to regenerate the syscalls list:
```
bionic/libc/tools/gensyscalls.py
```
After this, you will need to build/test the tree to make sure that these
changes do not introduce any errors.

4
libc/tools/Android.bp Normal file
View file

@ -0,0 +1,4 @@
filegroup {
name: "bionic-gensyscalls",
srcs: ["gensyscalls.py"]
}

View file

@ -8,7 +8,6 @@ import atexit
import commands
import filecmp
import glob
import logging
import os.path
import re
import shutil
@ -478,8 +477,6 @@ class SysCallsTxtParser:
self.syscalls.append(t)
logging.debug(t)
def parse_open_file(self, fp):
for line in fp:
self.lineno += 1
@ -489,64 +486,47 @@ class SysCallsTxtParser:
self.parse_line(line)
def parse_file(self, file_path):
logging.debug("parse_file: %s" % file_path)
with open(file_path) as fp:
self.parse_open_file(fp)
class State:
def __init__(self):
self.syscalls = []
def main(arch):
parser = SysCallsTxtParser()
parser.parse_file(os.path.join(bionic_libc, "SYSCALLS.TXT"))
for syscall in parser.syscalls:
syscall["__NR_name"] = make__NR_name(syscall["name"])
def process_file(self, input):
parser = SysCallsTxtParser()
parser.parse_file(input)
self.syscalls = parser.syscalls
parser = None
if syscall.has_key("arm"):
syscall["asm-arm"] = add_footer(32, arm_eabi_genstub(syscall), syscall)
for syscall in self.syscalls:
syscall["__NR_name"] = make__NR_name(syscall["name"])
if syscall.has_key("arm64"):
syscall["asm-arm64"] = add_footer(64, arm64_genstub(syscall), syscall)
if syscall.has_key("arm"):
syscall["asm-arm"] = add_footer(32, arm_eabi_genstub(syscall), syscall)
if syscall.has_key("x86"):
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
if syscall.has_key("arm64"):
syscall["asm-arm64"] = add_footer(64, arm64_genstub(syscall), syscall)
if syscall.has_key("mips"):
syscall["asm-mips"] = add_footer(32, mips_genstub(syscall), syscall)
if syscall.has_key("x86"):
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
if syscall.has_key("mips64"):
syscall["asm-mips64"] = add_footer(64, mips64_genstub(syscall), syscall)
if syscall.has_key("mips"):
syscall["asm-mips"] = add_footer(32, mips_genstub(syscall), syscall)
if syscall.has_key("x86_64"):
syscall["asm-x86_64"] = add_footer(64, x86_64_genstub(syscall), syscall)
if syscall.has_key("mips64"):
syscall["asm-mips64"] = add_footer(64, mips64_genstub(syscall), syscall)
print("/* Generated by gensyscalls.py. Do not edit. */\n")
print("#include <private/bionic_asm.h>\n")
for syscall in parser.syscalls:
if syscall.has_key("asm-%s" % arch):
print(syscall["asm-%s" % arch])
if syscall.has_key("x86_64"):
syscall["asm-x86_64"] = add_footer(64, x86_64_genstub(syscall), syscall)
def regenerate(self):
for arch in all_arches:
filename = '%s/arch-%s/syscalls.S' % (bionic_libc, arch)
fp = open(filename, 'w')
fp.write("/* Generated by gensyscalls.py. Do not edit. */\n")
fp.write("#include <private/bionic_asm.h>\n")
for syscall in self.syscalls:
if syscall.has_key("asm-%s" % arch):
fp.write(syscall["asm-%s" % arch])
fp.close()
logging.basicConfig(level=logging.INFO)
if __name__ == "__main__":
state = State()
state.process_file(os.path.join(bionic_libc, "SYSCALLS.TXT"))
state.regenerate()
main(sys.argv[1])

View file

@ -1,7 +0,0 @@
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $DIR/..
./libc/tools/gensyscalls.py
git diff --exit-code HEAD libc/arch-*/syscalls/
exit $?