2008-10-21 16:00:00 +02:00
|
|
|
#!/usr/bin/python
|
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
|
|
|
|
2013-10-16 23:27:59 +02:00
|
|
|
import commands
|
|
|
|
import filecmp
|
|
|
|
import glob
|
|
|
|
import os.path
|
|
|
|
import re
|
|
|
|
import shutil
|
|
|
|
import stat
|
|
|
|
import sys
|
2008-10-21 16:00:00 +02:00
|
|
|
|
|
|
|
from bionic_utils import *
|
|
|
|
|
2013-06-17 19:26:10 +02:00
|
|
|
bionic_libc_root = os.environ["ANDROID_BUILD_TOP"] + "/bionic/libc/"
|
2008-10-21 16:00:00 +02:00
|
|
|
|
|
|
|
# temp directory where we store all intermediate files
|
|
|
|
bionic_temp = "/tmp/bionic_gensyscalls/"
|
|
|
|
|
2013-10-16 23:27:59 +02:00
|
|
|
warning = "Generated by gensyscalls.py. Do not edit."
|
|
|
|
|
2012-12-12 10:11:48 +01:00
|
|
|
DRY_RUN = False
|
|
|
|
|
|
|
|
def make_dir(path):
|
2012-01-28 02:51:42 +01:00
|
|
|
path = os.path.abspath(path)
|
2008-10-21 16:00:00 +02:00
|
|
|
if not os.path.exists(path):
|
|
|
|
parent = os.path.dirname(path)
|
|
|
|
if parent:
|
|
|
|
make_dir(parent)
|
|
|
|
os.mkdir(path)
|
|
|
|
|
2013-10-08 08:53:13 +02:00
|
|
|
|
2012-12-12 10:11:48 +01:00
|
|
|
def create_file(relpath):
|
|
|
|
dir = os.path.dirname(bionic_temp + relpath)
|
2008-10-21 16:00:00 +02:00
|
|
|
make_dir(dir)
|
2012-12-12 10:11:48 +01:00
|
|
|
return open(bionic_temp + relpath, "w")
|
2008-10-21 16:00:00 +02:00
|
|
|
|
|
|
|
|
2013-10-16 23:27:59 +02:00
|
|
|
syscall_stub_header = "/* " + warning + " */\n" + \
|
|
|
|
"""
|
2013-11-07 19:31:05 +01:00
|
|
|
#include <private/bionic_asm.h>
|
2008-10-21 16:00:00 +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
|
|
|
|
2013-10-04 19:03:17 +02:00
|
|
|
function_alias = """
|
2014-02-19 01:42:36 +01:00
|
|
|
.globl %(alias)s
|
|
|
|
.equ %(alias)s, %(func)s
|
2008-10-21 16:00:00 +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
|
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
|
2013-03-12 22:57:30 +01:00
|
|
|
cmn r0, #(MAX_ERRNO + 1)
|
|
|
|
bxls lr
|
|
|
|
neg r0, r0
|
|
|
|
b __set_errno
|
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
|
|
|
|
b __set_errno
|
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
|
|
|
#
|
|
|
|
# Arm64 assembler templates for each syscall stub
|
|
|
|
#
|
|
|
|
|
|
|
|
arm64_call = syscall_stub_header + """\
|
|
|
|
stp x29, x30, [sp, #-16]!
|
2014-05-22 01:00:13 +02:00
|
|
|
.cfi_def_cfa_offset 16
|
|
|
|
.cfi_rel_offset x29, 0
|
|
|
|
.cfi_rel_offset x30, 8
|
2014-01-22 04:50:58 +01:00
|
|
|
mov x29, sp
|
|
|
|
|
|
|
|
mov x8, %(__NR_name)s
|
|
|
|
svc #0
|
|
|
|
|
|
|
|
ldp x29, x30, [sp], #16
|
2014-05-22 01:00:13 +02:00
|
|
|
.cfi_def_cfa_offset 0
|
|
|
|
.cfi_restore x29
|
|
|
|
.cfi_restore x30
|
2014-01-22 04:50:58 +01:00
|
|
|
|
|
|
|
cmn x0, #(MAX_ERRNO + 1)
|
|
|
|
cneg x0, x0, hi
|
|
|
|
b.hi __set_errno
|
|
|
|
|
|
|
|
ret
|
|
|
|
END(%(func)s)
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2013-02-07 23:07:00 +01:00
|
|
|
#
|
2013-10-08 08:53:13 +02:00
|
|
|
# MIPS assembler templates for each syscall stub
|
2012-01-28 02:51:42 +01:00
|
|
|
#
|
2013-02-07 23:07:00 +01:00
|
|
|
|
2014-02-19 23:54:31 +01:00
|
|
|
mips_call = syscall_stub_header + """\
|
2012-01-28 02:51:42 +01:00
|
|
|
.set noreorder
|
2014-02-19 21:20:00 +01:00
|
|
|
.cpload t9
|
|
|
|
li v0, %(__NR_name)s
|
2012-01-28 02:51:42 +01:00
|
|
|
syscall
|
2014-02-19 21:20:00 +01:00
|
|
|
bnez a3, 1f
|
|
|
|
move a0, v0
|
|
|
|
j ra
|
2012-01-28 02:51:42 +01:00
|
|
|
nop
|
|
|
|
1:
|
2014-02-19 21:20:00 +01:00
|
|
|
la t9,__set_errno
|
|
|
|
j t9
|
2012-01-28 02:51:42 +01:00
|
|
|
nop
|
|
|
|
.set reorder
|
2014-02-19 23:54:31 +01:00
|
|
|
END(%(func)s)
|
2013-10-08 08:53:13 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
2014-02-06 01:59:23 +01:00
|
|
|
#
|
|
|
|
# MIPS64 assembler templates for each syscall stub
|
|
|
|
#
|
|
|
|
|
2014-02-19 23:54:31 +01:00
|
|
|
mips64_call = syscall_stub_header + """\
|
2014-02-06 01:59:23 +01:00
|
|
|
.set push
|
|
|
|
.set noreorder
|
|
|
|
li v0, %(__NR_name)s
|
|
|
|
syscall
|
|
|
|
bnez a3, 1f
|
|
|
|
move a0, v0
|
|
|
|
j ra
|
|
|
|
nop
|
|
|
|
1:
|
|
|
|
move t0, ra
|
|
|
|
bal 2f
|
|
|
|
nop
|
|
|
|
2:
|
|
|
|
.cpsetup ra, t1, 2b
|
|
|
|
LA t9,__set_errno
|
|
|
|
.cpreturn
|
|
|
|
j t9
|
|
|
|
move ra, t0
|
|
|
|
.set pop
|
2014-02-19 23:54:31 +01:00
|
|
|
END(%(func)s)
|
2014-02-06 01:59:23 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
x86_call = """\
|
|
|
|
movl $%(__NR_name)s, %%eax
|
|
|
|
int $0x80
|
|
|
|
cmpl $-MAX_ERRNO, %%eax
|
|
|
|
jb 1f
|
|
|
|
negl %%eax
|
|
|
|
pushl %%eax
|
|
|
|
call __set_errno
|
|
|
|
addl $4, %%esp
|
|
|
|
1:
|
|
|
|
"""
|
|
|
|
|
|
|
|
x86_return = """\
|
|
|
|
ret
|
|
|
|
END(%(func)s)
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# x86_64 assembler templates for each syscall stub
|
|
|
|
#
|
|
|
|
|
|
|
|
x86_64_call = """\
|
|
|
|
movl $%(__NR_name)s, %%eax
|
|
|
|
syscall
|
|
|
|
cmpq $-MAX_ERRNO, %%rax
|
|
|
|
jb 1f
|
|
|
|
negl %%eax
|
|
|
|
movl %%eax, %%edi
|
|
|
|
call __set_errno
|
|
|
|
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):
|
|
|
|
if name.startswith("__"):
|
|
|
|
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:
|
|
|
|
stub += function_alias % { "func" : syscall["func"], "alias" : alias }
|
2013-10-25 02:03:20 +02:00
|
|
|
|
|
|
|
# Use hidden visibility for any functions beginning with underscores.
|
|
|
|
if pointer_length == 64 and syscall["func"].startswith("__"):
|
2014-02-20 03:59:19 +01:00
|
|
|
stub += '.hidden ' + syscall["func"] + '\n'
|
2013-10-25 02:03:20 +02:00
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2013-10-08 08:53:13 +02:00
|
|
|
def mips_genstub(syscall):
|
|
|
|
return mips_call % syscall
|
2008-10-21 16:00:00 +02:00
|
|
|
|
|
|
|
|
2014-02-06 01:59:23 +01:00
|
|
|
def mips64_genstub(syscall):
|
|
|
|
return mips64_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"])
|
2014-01-07 01:39:10 +01:00
|
|
|
stack_bias = numparams*4 + 4
|
|
|
|
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
|
|
|
|
|
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"
|
2014-01-07 01:39:10 +01:00
|
|
|
stack_bias = 12
|
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
|
|
|
|
|
|
|
class State:
|
|
|
|
def __init__(self):
|
|
|
|
self.old_stubs = []
|
|
|
|
self.new_stubs = []
|
|
|
|
self.other_files = []
|
|
|
|
self.syscalls = []
|
|
|
|
|
|
|
|
|
|
|
|
def process_file(self, input):
|
2008-10-21 16:00:00 +02:00
|
|
|
parser = SysCallsTxtParser()
|
|
|
|
parser.parse_file(input)
|
|
|
|
self.syscalls = parser.syscalls
|
|
|
|
parser = None
|
|
|
|
|
2013-10-08 08:53:13 +02:00
|
|
|
for syscall in self.syscalls:
|
|
|
|
syscall["__NR_name"] = make__NR_name(syscall["name"])
|
|
|
|
|
|
|
|
if syscall.has_key("arm"):
|
2013-10-25 02:03:20 +02:00
|
|
|
syscall["asm-arm"] = add_footer(32, arm_eabi_genstub(syscall), syscall)
|
2014-01-22 04:50:58 +01:00
|
|
|
|
|
|
|
if syscall.has_key("arm64"):
|
|
|
|
syscall["asm-arm64"] = add_footer(64, arm64_genstub(syscall), syscall)
|
2013-10-08 08:53:13 +02:00
|
|
|
|
|
|
|
if syscall.has_key("x86"):
|
|
|
|
if syscall["socketcall_id"] >= 0:
|
2013-10-25 02:03:20 +02:00
|
|
|
syscall["asm-x86"] = add_footer(32, x86_genstub_socketcall(syscall), syscall)
|
2008-12-18 03:03:48 +01:00
|
|
|
else:
|
2013-10-25 02:03:20 +02:00
|
|
|
syscall["asm-x86"] = add_footer(32, x86_genstub(syscall), syscall)
|
2013-10-08 08:53:13 +02:00
|
|
|
elif syscall["socketcall_id"] >= 0:
|
2013-09-26 07:43:36 +02:00
|
|
|
E("socketcall_id for dispatch syscalls is only supported for x86 in '%s'" % t)
|
2008-12-18 03:03:48 +01:00
|
|
|
return
|
2013-02-07 23:07:00 +01:00
|
|
|
|
2013-10-08 08:53:13 +02:00
|
|
|
if syscall.has_key("mips"):
|
2013-10-25 02:03:20 +02:00
|
|
|
syscall["asm-mips"] = add_footer(32, mips_genstub(syscall), syscall)
|
2013-10-08 08:53:13 +02:00
|
|
|
|
2014-02-06 01:59:23 +01:00
|
|
|
if syscall.has_key("mips64"):
|
|
|
|
syscall["asm-mips64"] = add_footer(64, mips64_genstub(syscall), syscall)
|
|
|
|
|
2013-10-08 08:53:13 +02:00
|
|
|
if syscall.has_key("x86_64"):
|
2013-10-25 02:03:20 +02:00
|
|
|
syscall["asm-x86_64"] = add_footer(64, x86_64_genstub(syscall), syscall)
|
2008-12-18 03:03:48 +01:00
|
|
|
|
2013-03-23 02:56:24 +01:00
|
|
|
# Scan a Linux kernel asm/unistd.h file containing __NR_* constants
|
|
|
|
# and write out equivalent SYS_* constants for glibc source compatibility.
|
2013-03-22 06:15:06 +01:00
|
|
|
def scan_linux_unistd_h(self, fp, path):
|
|
|
|
pattern = re.compile(r'^#define __NR_([a-z]\S+) .*')
|
|
|
|
syscalls = set() # MIPS defines everything three times; work around that.
|
|
|
|
for line in open(path):
|
|
|
|
m = re.search(pattern, line)
|
|
|
|
if m:
|
|
|
|
syscalls.add(m.group(1))
|
|
|
|
for syscall in sorted(syscalls):
|
2013-03-22 21:50:44 +01:00
|
|
|
fp.write("#define SYS_%s %s\n" % (syscall, make__NR_name(syscall)))
|
2013-03-22 02:06:55 +01:00
|
|
|
|
|
|
|
|
2013-03-23 02:56:24 +01:00
|
|
|
def gen_glibc_syscalls_h(self):
|
2013-03-22 21:50:44 +01:00
|
|
|
# TODO: generate a separate file for each architecture, like glibc's bits/syscall.h.
|
2013-03-22 02:06:55 +01:00
|
|
|
glibc_syscalls_h_path = "include/sys/glibc-syscalls.h"
|
2013-03-23 02:56:24 +01:00
|
|
|
D("generating " + glibc_syscalls_h_path)
|
2013-03-22 03:43:54 +01:00
|
|
|
glibc_fp = create_file(glibc_syscalls_h_path)
|
2013-10-16 23:27:59 +02:00
|
|
|
glibc_fp.write("/* %s */\n" % warning)
|
2013-03-22 03:43:54 +01:00
|
|
|
glibc_fp.write("#ifndef _BIONIC_GLIBC_SYSCALLS_H_\n")
|
|
|
|
glibc_fp.write("#define _BIONIC_GLIBC_SYSCALLS_H_\n")
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2013-10-07 17:49:09 +02:00
|
|
|
glibc_fp.write("#if defined(__aarch64__)\n")
|
|
|
|
self.scan_linux_unistd_h(glibc_fp, bionic_libc_root + "/kernel/uapi/asm-generic/unistd.h")
|
|
|
|
glibc_fp.write("#elif defined(__arm__)\n")
|
2014-01-02 21:05:50 +01:00
|
|
|
self.scan_linux_unistd_h(glibc_fp, bionic_libc_root + "/kernel/uapi/asm-arm/asm/unistd.h")
|
2013-03-22 06:15:06 +01:00
|
|
|
glibc_fp.write("#elif defined(__mips__)\n")
|
2013-12-03 02:44:53 +01:00
|
|
|
self.scan_linux_unistd_h(glibc_fp, bionic_libc_root + "/kernel/uapi/asm-mips/asm/unistd.h")
|
2013-03-22 06:15:06 +01:00
|
|
|
glibc_fp.write("#elif defined(__i386__)\n")
|
2013-12-03 02:44:53 +01:00
|
|
|
self.scan_linux_unistd_h(glibc_fp, bionic_libc_root + "/kernel/uapi/asm-x86/asm/unistd_32.h")
|
2012-12-12 10:11:48 +01:00
|
|
|
glibc_fp.write("#elif defined(__x86_64__)\n")
|
2013-12-03 02:44:53 +01:00
|
|
|
self.scan_linux_unistd_h(glibc_fp, bionic_libc_root + "/kernel/uapi/asm-x86/asm/unistd_64.h")
|
2013-03-22 06:15:06 +01:00
|
|
|
glibc_fp.write("#endif\n")
|
|
|
|
|
|
|
|
glibc_fp.write("#endif /* _BIONIC_GLIBC_SYSCALLS_H_ */\n")
|
|
|
|
glibc_fp.close()
|
|
|
|
self.other_files.append(glibc_syscalls_h_path)
|
|
|
|
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2013-09-26 07:43:36 +02:00
|
|
|
# Write each syscall stub.
|
2008-10-21 16:00:00 +02:00
|
|
|
def gen_syscall_stubs(self):
|
2013-10-08 08:53:13 +02:00
|
|
|
for syscall in self.syscalls:
|
2013-09-26 07:43:36 +02:00
|
|
|
for arch in all_arches:
|
2013-10-08 08:53:13 +02:00
|
|
|
if syscall.has_key("asm-%s" % arch):
|
|
|
|
filename = "arch-%s/syscalls/%s.S" % (arch, syscall["func"])
|
2013-09-26 07:43:36 +02:00
|
|
|
D2(">>> generating " + filename)
|
|
|
|
fp = create_file(filename)
|
2013-10-08 08:53:13 +02:00
|
|
|
fp.write(syscall["asm-%s" % arch])
|
2013-09-26 07:43:36 +02:00
|
|
|
fp.close()
|
|
|
|
self.new_stubs.append(filename)
|
|
|
|
|
|
|
|
|
|
|
|
def regenerate(self):
|
2012-12-12 10:11:48 +01:00
|
|
|
D("scanning for existing architecture-specific stub files...")
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2013-06-17 19:26:10 +02:00
|
|
|
bionic_libc_root_len = len(bionic_libc_root)
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2013-09-26 07:43:36 +02:00
|
|
|
for arch in all_arches:
|
2013-06-17 19:26:10 +02:00
|
|
|
arch_path = bionic_libc_root + "arch-" + arch
|
2012-12-12 10:11:48 +01:00
|
|
|
D("scanning " + arch_path)
|
|
|
|
files = glob.glob(arch_path + "/syscalls/*.S")
|
2008-10-21 16:00:00 +02:00
|
|
|
for f in files:
|
2012-12-12 10:11:48 +01:00
|
|
|
self.old_stubs.append(f[bionic_libc_root_len:])
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2012-12-12 10:11:48 +01:00
|
|
|
D("found %d stub files" % len(self.old_stubs))
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2012-12-12 10:11:48 +01:00
|
|
|
if not os.path.exists(bionic_temp):
|
|
|
|
D("creating %s..." % bionic_temp)
|
|
|
|
make_dir(bionic_temp)
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2012-12-12 10:11:48 +01:00
|
|
|
D("re-generating stubs and support files...")
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2013-03-23 02:56:24 +01:00
|
|
|
self.gen_glibc_syscalls_h()
|
2008-10-21 16:00:00 +02:00
|
|
|
self.gen_syscall_stubs()
|
|
|
|
|
2012-12-12 10:11:48 +01:00
|
|
|
D("comparing files...")
|
2008-10-21 16:00:00 +02:00
|
|
|
adds = []
|
|
|
|
edits = []
|
|
|
|
|
|
|
|
for stub in self.new_stubs + self.other_files:
|
2012-12-12 10:11:48 +01:00
|
|
|
if not os.path.exists(bionic_libc_root + stub):
|
2010-10-11 22:11:06 +02:00
|
|
|
# new file, git add it
|
2012-12-12 10:11:48 +01:00
|
|
|
D("new file: " + stub)
|
|
|
|
adds.append(bionic_libc_root + stub)
|
|
|
|
shutil.copyfile(bionic_temp + stub, bionic_libc_root + stub)
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2012-12-12 10:11:48 +01:00
|
|
|
elif not filecmp.cmp(bionic_temp + stub, bionic_libc_root + stub):
|
|
|
|
D("changed file: " + stub)
|
|
|
|
edits.append(stub)
|
2008-10-21 16:00:00 +02:00
|
|
|
|
|
|
|
deletes = []
|
|
|
|
for stub in self.old_stubs:
|
|
|
|
if not stub in self.new_stubs:
|
2012-12-12 10:11:48 +01:00
|
|
|
D("deleted file: " + stub)
|
|
|
|
deletes.append(bionic_libc_root + stub)
|
|
|
|
|
|
|
|
if not DRY_RUN:
|
|
|
|
if adds:
|
|
|
|
commands.getoutput("git add " + " ".join(adds))
|
|
|
|
if deletes:
|
|
|
|
commands.getoutput("git rm " + " ".join(deletes))
|
|
|
|
if edits:
|
|
|
|
for file in edits:
|
|
|
|
shutil.copyfile(bionic_temp + file, bionic_libc_root + file)
|
|
|
|
commands.getoutput("git add " + " ".join((bionic_libc_root + file) for file in edits))
|
|
|
|
|
|
|
|
commands.getoutput("git add %s%s" % (bionic_libc_root,"SYSCALLS.TXT"))
|
2010-10-11 22:11:06 +02:00
|
|
|
|
|
|
|
if (not adds) and (not deletes) and (not edits):
|
|
|
|
D("no changes detected!")
|
|
|
|
else:
|
|
|
|
D("ready to go!!")
|
2008-10-21 16:00:00 +02:00
|
|
|
|
|
|
|
D_setlevel(1)
|
|
|
|
|
|
|
|
state = State()
|
2013-06-17 19:26:10 +02:00
|
|
|
state.process_file(bionic_libc_root+"SYSCALLS.TXT")
|
2008-10-21 16:00:00 +02:00
|
|
|
state.regenerate()
|