blob: bf44b7031d0289608dd0f3742546fcb5c04d3f2f [file] [log] [blame]
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -07001#!/usr/bin/python
Pavel Chupinf12a18b2012-12-12 13:11:48 +04002
3# This tool is used to generate the assembler system call stubs,
4# the header files listing all available system calls, and the
5# makefiles used to build all the stubs.
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -07006
Elliott Hughes103ccde2013-10-16 14:27:59 -07007import commands
8import filecmp
9import glob
10import os.path
11import re
12import shutil
13import stat
14import sys
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070015
16from bionic_utils import *
17
Elliott Hughes18bc9752013-06-17 10:26:10 -070018bionic_libc_root = os.environ["ANDROID_BUILD_TOP"] + "/bionic/libc/"
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070019
20# temp directory where we store all intermediate files
21bionic_temp = "/tmp/bionic_gensyscalls/"
22
Elliott Hughes103ccde2013-10-16 14:27:59 -070023warning = "Generated by gensyscalls.py. Do not edit."
24
Pavel Chupinf12a18b2012-12-12 13:11:48 +040025DRY_RUN = False
26
27def make_dir(path):
Raghu Gandham1fa0d842012-01-27 17:51:42 -080028 path = os.path.abspath(path)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070029 if not os.path.exists(path):
30 parent = os.path.dirname(path)
31 if parent:
32 make_dir(parent)
33 os.mkdir(path)
34
Elliott Hughes0437f3f2013-10-07 23:53:13 -070035
Pavel Chupinf12a18b2012-12-12 13:11:48 +040036def create_file(relpath):
37 dir = os.path.dirname(bionic_temp + relpath)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070038 make_dir(dir)
Pavel Chupinf12a18b2012-12-12 13:11:48 +040039 return open(bionic_temp + relpath, "w")
40
41
Elliott Hughes103ccde2013-10-16 14:27:59 -070042syscall_stub_header = "/* " + warning + " */\n" + \
43"""
Pavel Chupinf12a18b2012-12-12 13:11:48 +040044#include <asm/unistd.h>
45#include <linux/err.h>
46#include <machine/asm.h>
47
Elliott Hughes0437f3f2013-10-07 23:53:13 -070048ENTRY(%(func)s)
Pavel Chupinf12a18b2012-12-12 13:11:48 +040049"""
50
Elliott Hughes0437f3f2013-10-07 23:53:13 -070051
H.J. Lu6fe4e872013-10-04 10:03:17 -070052function_alias = """
53 .globl _C_LABEL(%(alias)s)
Elliott Hughes0437f3f2013-10-07 23:53:13 -070054 .equ _C_LABEL(%(alias)s), _C_LABEL(%(func)s)
H.J. Lu6fe4e872013-10-04 10:03:17 -070055"""
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070056
Elliott Hughes0437f3f2013-10-07 23:53:13 -070057
58#
Serban Constantinescufeaa89a2013-10-07 16:49:09 +010059# AArch64 assembler templates for each syscall stub
60#
61
62aarch64_call = syscall_stub_header + """\
63 stp x29, x30, [sp, #-16]!
64 mov x29, sp
65 str x8, [sp, #-16]!
66
67 mov x8, %(__NR_name)s
68 svc #0
69
70 ldr x8, [sp], #16
71 ldp x29, x30, [sp], #16
72
73 cmn x0, #(MAX_ERRNO + 1)
74 cneg x0, x0, hi
75 b.hi __set_errno
76
77 ret
78END(%(func)s)
79"""
80
81#
Elliott Hughes0437f3f2013-10-07 23:53:13 -070082# ARM assembler templates for each syscall stub
83#
84
85arm_eabi_call_default = syscall_stub_header + """\
86 mov ip, r7
87 ldr r7, =%(__NR_name)s
88 swi #0
89 mov r7, ip
90 cmn r0, #(MAX_ERRNO + 1)
91 bxls lr
92 neg r0, r0
93 b __set_errno
94END(%(func)s)
95"""
96
97arm_eabi_call_long = syscall_stub_header + """\
98 mov ip, sp
99 .save {r4, r5, r6, r7}
100 stmfd sp!, {r4, r5, r6, r7}
101 ldmfd ip, {r4, r5, r6}
102 ldr r7, =%(__NR_name)s
103 swi #0
104 ldmfd sp!, {r4, r5, r6, r7}
105 cmn r0, #(MAX_ERRNO + 1)
106 bxls lr
107 neg r0, r0
108 b __set_errno
109END(%(func)s)
110"""
111
112
113#
114# MIPS assembler templates for each syscall stub
115#
116
Elliott Hughes103ccde2013-10-16 14:27:59 -0700117mips_call = "/* " + warning + " */\n" + \
118"""
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700119#include <asm/unistd.h>
120 .text
121 .globl %(func)s
122 .align 4
123 .ent %(func)s
124
125%(func)s:
126 .set noreorder
127 .cpload $t9
128 li $v0, %(__NR_name)s
129 syscall
130 bnez $a3, 1f
131 move $a0, $v0
132 j $ra
133 nop
1341:
135 la $t9,__set_errno
136 j $t9
137 nop
138 .set reorder
139 .end %(func)s
140"""
141
142
Elliott Hughescd6780b2013-02-07 14:07:00 -0800143#
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700144# x86 assembler templates for each syscall stub
145#
146
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700147x86_registers = [ "%ebx", "%ecx", "%edx", "%esi", "%edi", "%ebp" ]
148
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700149x86_call = """\
150 movl $%(__NR_name)s, %%eax
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700151 int $0x80
Elliott Hughes9aceab52013-03-12 14:57:30 -0700152 cmpl $-MAX_ERRNO, %%eax
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700153 jb 1f
154 negl %%eax
155 pushl %%eax
156 call __set_errno
157 addl $4, %%esp
158 orl $-1, %%eax
1591:
160"""
161
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700162x86_return = """\
163 ret
164END(%(func)s)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700165"""
166
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700167
Elliott Hughescd6780b2013-02-07 14:07:00 -0800168#
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400169# x86_64 assembler templates for each syscall stub
170#
171
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700172x86_64_call = """\
173 movl $%(__NR_name)s, %%eax
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400174 syscall
175 cmpq $-MAX_ERRNO, %%rax
176 jb 1f
177 negl %%eax
178 movl %%eax, %%edi
179 call __set_errno
180 orq $-1, %%rax
1811:
182 ret
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700183END(%(func)s)
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400184"""
185
Raghu Gandham1fa0d842012-01-27 17:51:42 -0800186
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100187def param_uses_64bits(param):
188 """Returns True iff a syscall parameter description corresponds
189 to a 64-bit type."""
190 param = param.strip()
191 # First, check that the param type begins with one of the known
192 # 64-bit types.
193 if not ( \
194 param.startswith("int64_t") or param.startswith("uint64_t") or \
195 param.startswith("loff_t") or param.startswith("off64_t") or \
196 param.startswith("long long") or param.startswith("unsigned long long") or
197 param.startswith("signed long long") ):
198 return False
199
200 # Second, check that there is no pointer type here
201 if param.find("*") >= 0:
202 return False
203
204 # Ok
205 return True
206
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700207
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100208def count_arm_param_registers(params):
209 """This function is used to count the number of register used
Elliott Hughescd6780b2013-02-07 14:07:00 -0800210 to pass parameters when invoking an ARM system call.
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100211 This is because the ARM EABI mandates that 64-bit quantities
212 must be passed in an even+odd register pair. So, for example,
213 something like:
214
215 foo(int fd, off64_t pos)
216
217 would actually need 4 registers:
218 r0 -> int
219 r1 -> unused
220 r2-r3 -> pos
221 """
222 count = 0
223 for param in params:
224 if param_uses_64bits(param):
225 if (count & 1) != 0:
226 count += 1
227 count += 2
228 else:
229 count += 1
230 return count
231
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700232
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100233def count_generic_param_registers(params):
234 count = 0
235 for param in params:
236 if param_uses_64bits(param):
237 count += 2
238 else:
239 count += 1
240 return count
241
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700242
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400243def count_generic_param_registers64(params):
244 count = 0
245 for param in params:
246 count += 1
247 return count
248
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700249
Elliott Hughescda62092013-03-22 13:50:44 -0700250# This lets us support regular system calls like __NR_write and also weird
251# ones like __ARM_NR_cacheflush, where the NR doesn't come at the start.
252def make__NR_name(name):
253 if name.startswith("__"):
254 return name
255 else:
256 return "__NR_%s" % (name)
257
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700258
Elliott Hughesfff6e272013-10-24 17:03:20 -0700259def add_footer(pointer_length, stub, syscall):
260 # Add any aliases for this syscall.
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700261 aliases = syscall["aliases"]
262 for alias in aliases:
263 stub += function_alias % { "func" : syscall["func"], "alias" : alias }
Elliott Hughesfff6e272013-10-24 17:03:20 -0700264
265 # Use hidden visibility for any functions beginning with underscores.
Elliott Hughesfff6e272013-10-24 17:03:20 -0700266 if pointer_length == 64 and syscall["func"].startswith("__"):
267 stub += '.hidden _C_LABEL(' + syscall["func"] + ')\n'
268
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700269 return stub
270
271
Serban Constantinescufeaa89a2013-10-07 16:49:09 +0100272def aarch64_genstub(syscall):
273 return aarch64_call % syscall
274
275
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700276def arm_eabi_genstub(syscall):
277 num_regs = count_arm_param_registers(syscall["params"])
278 if num_regs > 4:
279 return arm_eabi_call_long % syscall
280 return arm_eabi_call_default % syscall
281
282
283def mips_genstub(syscall):
284 return mips_call % syscall
285
286
287def x86_genstub(syscall):
288 result = syscall_stub_header % syscall
289 stack_bias = 4
290
291 numparams = count_generic_param_registers(syscall["params"])
292 for r in range(numparams):
293 result += " pushl " + x86_registers[r] + "\n"
294 stack_bias += 4
295
296 for r in range(numparams):
297 result += " mov %d(%%esp), %s" % (stack_bias+r*4, x86_registers[r]) + "\n"
298
299 result += x86_call % syscall
300
301 for r in range(numparams):
302 result += " popl " + x86_registers[numparams-r-1] + "\n"
303
304 result += x86_return % syscall
305 return result
306
Serban Constantinescufeaa89a2013-10-07 16:49:09 +0100307
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700308def x86_genstub_socketcall(syscall):
309 # %ebx <--- Argument 1 - The call id of the needed vectored
310 # syscall (socket, bind, recv, etc)
311 # %ecx <--- Argument 2 - Pointer to the rest of the arguments
312 # from the original function called (socket())
313
314 result = syscall_stub_header % syscall
315 stack_bias = 4
316
317 # save the regs we need
318 result += " pushl %ebx" + "\n"
319 stack_bias += 4
320 result += " pushl %ecx" + "\n"
321 stack_bias += 4
322
323 # set the call id (%ebx)
324 result += " mov $%d, %%ebx" % syscall["socketcall_id"] + "\n"
325
326 # set the pointer to the rest of the args into %ecx
327 result += " mov %esp, %ecx" + "\n"
328 result += " addl $%d, %%ecx" % (stack_bias) + "\n"
329
330 # now do the syscall code itself
331 result += x86_call % syscall
332
333 # now restore the saved regs
334 result += " popl %ecx" + "\n"
335 result += " popl %ebx" + "\n"
336
337 # epilog
338 result += x86_return % syscall
339 return result
340
341
342def x86_64_genstub(syscall):
343 result = syscall_stub_header % syscall
344 num_regs = count_generic_param_registers64(syscall["params"])
345 if (num_regs > 3):
346 # rcx is used as 4th argument. Kernel wants it at r10.
347 result += " movq %rcx, %r10\n"
348
349 result += x86_64_call % syscall
350 return result
351
352
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700353class State:
354 def __init__(self):
355 self.old_stubs = []
356 self.new_stubs = []
357 self.other_files = []
358 self.syscalls = []
359
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400360
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700361 def process_file(self, input):
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700362 parser = SysCallsTxtParser()
363 parser.parse_file(input)
364 self.syscalls = parser.syscalls
365 parser = None
366
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700367 for syscall in self.syscalls:
368 syscall["__NR_name"] = make__NR_name(syscall["name"])
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700369
Serban Constantinescufeaa89a2013-10-07 16:49:09 +0100370 if syscall.has_key("aarch64"):
371 syscall["asm-aarch64"] = add_footer(64, aarch64_genstub(syscall), syscall)
372
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700373 if syscall.has_key("arm"):
Elliott Hughesfff6e272013-10-24 17:03:20 -0700374 syscall["asm-arm"] = add_footer(32, arm_eabi_genstub(syscall), syscall)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700375
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700376 if syscall.has_key("x86"):
377 if syscall["socketcall_id"] >= 0:
Elliott Hughesfff6e272013-10-24 17:03:20 -0700378 syscall["asm-x86"] = add_footer(32, x86_genstub_socketcall(syscall), syscall)
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800379 else:
Elliott Hughesfff6e272013-10-24 17:03:20 -0700380 syscall["asm-x86"] = add_footer(32, x86_genstub(syscall), syscall)
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700381 elif syscall["socketcall_id"] >= 0:
Elliott Hughesd6121652013-09-25 22:43:36 -0700382 E("socketcall_id for dispatch syscalls is only supported for x86 in '%s'" % t)
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800383 return
Elliott Hughescd6780b2013-02-07 14:07:00 -0800384
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700385 if syscall.has_key("mips"):
Elliott Hughesfff6e272013-10-24 17:03:20 -0700386 syscall["asm-mips"] = add_footer(32, mips_genstub(syscall), syscall)
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800387
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700388 if syscall.has_key("x86_64"):
Elliott Hughesfff6e272013-10-24 17:03:20 -0700389 syscall["asm-x86_64"] = add_footer(64, x86_64_genstub(syscall), syscall)
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700390
Elliott Hughes1b91c6c2013-03-22 18:56:24 -0700391 # Scan a Linux kernel asm/unistd.h file containing __NR_* constants
392 # and write out equivalent SYS_* constants for glibc source compatibility.
Elliott Hughes5c2772f2013-03-21 22:15:06 -0700393 def scan_linux_unistd_h(self, fp, path):
394 pattern = re.compile(r'^#define __NR_([a-z]\S+) .*')
395 syscalls = set() # MIPS defines everything three times; work around that.
396 for line in open(path):
397 m = re.search(pattern, line)
398 if m:
399 syscalls.add(m.group(1))
400 for syscall in sorted(syscalls):
Elliott Hughescda62092013-03-22 13:50:44 -0700401 fp.write("#define SYS_%s %s\n" % (syscall, make__NR_name(syscall)))
Elliott Hughes8ecf2252013-03-21 18:06:55 -0700402
403
Elliott Hughes1b91c6c2013-03-22 18:56:24 -0700404 def gen_glibc_syscalls_h(self):
Elliott Hughescda62092013-03-22 13:50:44 -0700405 # TODO: generate a separate file for each architecture, like glibc's bits/syscall.h.
Elliott Hughes9724ce32013-03-21 19:43:54 -0700406 glibc_syscalls_h_path = "include/sys/glibc-syscalls.h"
Elliott Hughes1b91c6c2013-03-22 18:56:24 -0700407 D("generating " + glibc_syscalls_h_path)
Elliott Hughes9724ce32013-03-21 19:43:54 -0700408 glibc_fp = create_file(glibc_syscalls_h_path)
Elliott Hughes103ccde2013-10-16 14:27:59 -0700409 glibc_fp.write("/* %s */\n" % warning)
Elliott Hughes9724ce32013-03-21 19:43:54 -0700410 glibc_fp.write("#ifndef _BIONIC_GLIBC_SYSCALLS_H_\n")
411 glibc_fp.write("#define _BIONIC_GLIBC_SYSCALLS_H_\n")
412
Serban Constantinescufeaa89a2013-10-07 16:49:09 +0100413 glibc_fp.write("#if defined(__aarch64__)\n")
414 self.scan_linux_unistd_h(glibc_fp, bionic_libc_root + "/kernel/uapi/asm-generic/unistd.h")
415 glibc_fp.write("#elif defined(__arm__)\n")
Elliott Hughes18bc9752013-06-17 10:26:10 -0700416 self.scan_linux_unistd_h(glibc_fp, bionic_libc_root + "/kernel/arch-arm/asm/unistd.h")
Elliott Hughes5c2772f2013-03-21 22:15:06 -0700417 glibc_fp.write("#elif defined(__mips__)\n")
Elliott Hughes18bc9752013-06-17 10:26:10 -0700418 self.scan_linux_unistd_h(glibc_fp, bionic_libc_root + "/kernel/arch-mips/asm/unistd.h")
Elliott Hughes5c2772f2013-03-21 22:15:06 -0700419 glibc_fp.write("#elif defined(__i386__)\n")
Elliott Hughes18bc9752013-06-17 10:26:10 -0700420 self.scan_linux_unistd_h(glibc_fp, bionic_libc_root + "/kernel/arch-x86/asm/unistd_32.h")
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400421 glibc_fp.write("#elif defined(__x86_64__)\n")
422 self.scan_linux_unistd_h(glibc_fp, bionic_libc_root + "/kernel/arch-x86/asm/unistd_64.h")
Elliott Hughes5c2772f2013-03-21 22:15:06 -0700423 glibc_fp.write("#endif\n")
424
425 glibc_fp.write("#endif /* _BIONIC_GLIBC_SYSCALLS_H_ */\n")
426 glibc_fp.close()
427 self.other_files.append(glibc_syscalls_h_path)
428
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700429
Elliott Hughesd6121652013-09-25 22:43:36 -0700430 # Write the contents of syscalls.mk.
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800431 def gen_arch_syscalls_mk(self, arch):
432 path = "arch-%s/syscalls.mk" % arch
Elliott Hughesd6121652013-09-25 22:43:36 -0700433 D("generating " + path)
434 fp = create_file(path)
Elliott Hughes103ccde2013-10-16 14:27:59 -0700435 fp.write("# %s\n" % warning)
Elliott Hughesd6121652013-09-25 22:43:36 -0700436 fp.write("syscall_src :=\n")
Elliott Hughes103ccde2013-10-16 14:27:59 -0700437 for syscall in sorted(self.syscalls, key=lambda syscall: syscall["func"]):
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700438 if syscall.has_key("asm-%s" % arch):
439 fp.write("syscall_src += arch-%s/syscalls/%s.S\n" % (arch, syscall["func"]))
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700440 fp.close()
Elliott Hughesd6121652013-09-25 22:43:36 -0700441 self.other_files.append(path)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700442
Raghu Gandham1fa0d842012-01-27 17:51:42 -0800443
Elliott Hughesd6121652013-09-25 22:43:36 -0700444 # Write each syscall stub.
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700445 def gen_syscall_stubs(self):
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700446 for syscall in self.syscalls:
Elliott Hughesd6121652013-09-25 22:43:36 -0700447 for arch in all_arches:
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700448 if syscall.has_key("asm-%s" % arch):
449 filename = "arch-%s/syscalls/%s.S" % (arch, syscall["func"])
Elliott Hughesd6121652013-09-25 22:43:36 -0700450 D2(">>> generating " + filename)
451 fp = create_file(filename)
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700452 fp.write(syscall["asm-%s" % arch])
Elliott Hughesd6121652013-09-25 22:43:36 -0700453 fp.close()
454 self.new_stubs.append(filename)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700455
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700456
Elliott Hughesd6121652013-09-25 22:43:36 -0700457 def regenerate(self):
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400458 D("scanning for existing architecture-specific stub files...")
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700459
Elliott Hughes18bc9752013-06-17 10:26:10 -0700460 bionic_libc_root_len = len(bionic_libc_root)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700461
Elliott Hughesd6121652013-09-25 22:43:36 -0700462 for arch in all_arches:
Elliott Hughes18bc9752013-06-17 10:26:10 -0700463 arch_path = bionic_libc_root + "arch-" + arch
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400464 D("scanning " + arch_path)
465 files = glob.glob(arch_path + "/syscalls/*.S")
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700466 for f in files:
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400467 self.old_stubs.append(f[bionic_libc_root_len:])
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700468
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400469 D("found %d stub files" % len(self.old_stubs))
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700470
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400471 if not os.path.exists(bionic_temp):
472 D("creating %s..." % bionic_temp)
473 make_dir(bionic_temp)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700474
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400475 D("re-generating stubs and support files...")
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700476
Elliott Hughes1b91c6c2013-03-22 18:56:24 -0700477 self.gen_glibc_syscalls_h()
Elliott Hughesd6121652013-09-25 22:43:36 -0700478 for arch in all_arches:
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800479 self.gen_arch_syscalls_mk(arch)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700480 self.gen_syscall_stubs()
481
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400482 D("comparing files...")
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700483 adds = []
484 edits = []
485
486 for stub in self.new_stubs + self.other_files:
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400487 if not os.path.exists(bionic_libc_root + stub):
David 'Digit' Turnerfc269312010-10-11 22:11:06 +0200488 # new file, git add it
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400489 D("new file: " + stub)
490 adds.append(bionic_libc_root + stub)
491 shutil.copyfile(bionic_temp + stub, bionic_libc_root + stub)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700492
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400493 elif not filecmp.cmp(bionic_temp + stub, bionic_libc_root + stub):
494 D("changed file: " + stub)
495 edits.append(stub)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700496
497 deletes = []
498 for stub in self.old_stubs:
499 if not stub in self.new_stubs:
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400500 D("deleted file: " + stub)
501 deletes.append(bionic_libc_root + stub)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700502
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400503 if not DRY_RUN:
504 if adds:
505 commands.getoutput("git add " + " ".join(adds))
506 if deletes:
507 commands.getoutput("git rm " + " ".join(deletes))
508 if edits:
509 for file in edits:
510 shutil.copyfile(bionic_temp + file, bionic_libc_root + file)
511 commands.getoutput("git add " + " ".join((bionic_libc_root + file) for file in edits))
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700512
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400513 commands.getoutput("git add %s%s" % (bionic_libc_root,"SYSCALLS.TXT"))
David 'Digit' Turnerfc269312010-10-11 22:11:06 +0200514
515 if (not adds) and (not deletes) and (not edits):
516 D("no changes detected!")
517 else:
518 D("ready to go!!")
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700519
520D_setlevel(1)
521
522state = State()
Elliott Hughes18bc9752013-06-17 10:26:10 -0700523state.process_file(bionic_libc_root+"SYSCALLS.TXT")
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700524state.regenerate()