blob: 578605d32bea71f12cdaca56ea61d7dedc02151e [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#
59# ARM assembler templates for each syscall stub
60#
61
62arm_eabi_call_default = syscall_stub_header + """\
63 mov ip, r7
64 ldr r7, =%(__NR_name)s
65 swi #0
66 mov r7, ip
67 cmn r0, #(MAX_ERRNO + 1)
68 bxls lr
69 neg r0, r0
70 b __set_errno
71END(%(func)s)
72"""
73
74arm_eabi_call_long = syscall_stub_header + """\
75 mov ip, sp
76 .save {r4, r5, r6, r7}
77 stmfd sp!, {r4, r5, r6, r7}
78 ldmfd ip, {r4, r5, r6}
79 ldr r7, =%(__NR_name)s
80 swi #0
81 ldmfd sp!, {r4, r5, r6, r7}
82 cmn r0, #(MAX_ERRNO + 1)
83 bxls lr
84 neg r0, r0
85 b __set_errno
86END(%(func)s)
87"""
88
89
90#
91# MIPS assembler templates for each syscall stub
92#
93
Elliott Hughes103ccde2013-10-16 14:27:59 -070094mips_call = "/* " + warning + " */\n" + \
95"""
Elliott Hughes0437f3f2013-10-07 23:53:13 -070096#include <asm/unistd.h>
97 .text
98 .globl %(func)s
99 .align 4
100 .ent %(func)s
101
102%(func)s:
103 .set noreorder
104 .cpload $t9
105 li $v0, %(__NR_name)s
106 syscall
107 bnez $a3, 1f
108 move $a0, $v0
109 j $ra
110 nop
1111:
112 la $t9,__set_errno
113 j $t9
114 nop
115 .set reorder
116 .end %(func)s
117"""
118
119
Elliott Hughescd6780b2013-02-07 14:07:00 -0800120#
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700121# x86 assembler templates for each syscall stub
122#
123
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700124x86_registers = [ "%ebx", "%ecx", "%edx", "%esi", "%edi", "%ebp" ]
125
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700126x86_call = """\
127 movl $%(__NR_name)s, %%eax
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700128 int $0x80
Elliott Hughes9aceab52013-03-12 14:57:30 -0700129 cmpl $-MAX_ERRNO, %%eax
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700130 jb 1f
131 negl %%eax
132 pushl %%eax
133 call __set_errno
134 addl $4, %%esp
135 orl $-1, %%eax
1361:
137"""
138
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700139x86_return = """\
140 ret
141END(%(func)s)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700142"""
143
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700144
Elliott Hughescd6780b2013-02-07 14:07:00 -0800145#
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400146# x86_64 assembler templates for each syscall stub
147#
148
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700149x86_64_call = """\
150 movl $%(__NR_name)s, %%eax
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400151 syscall
152 cmpq $-MAX_ERRNO, %%rax
153 jb 1f
154 negl %%eax
155 movl %%eax, %%edi
156 call __set_errno
157 orq $-1, %%rax
1581:
159 ret
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700160END(%(func)s)
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400161"""
162
Raghu Gandham1fa0d842012-01-27 17:51:42 -0800163
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100164def param_uses_64bits(param):
165 """Returns True iff a syscall parameter description corresponds
166 to a 64-bit type."""
167 param = param.strip()
168 # First, check that the param type begins with one of the known
169 # 64-bit types.
170 if not ( \
171 param.startswith("int64_t") or param.startswith("uint64_t") or \
172 param.startswith("loff_t") or param.startswith("off64_t") or \
173 param.startswith("long long") or param.startswith("unsigned long long") or
174 param.startswith("signed long long") ):
175 return False
176
177 # Second, check that there is no pointer type here
178 if param.find("*") >= 0:
179 return False
180
181 # Ok
182 return True
183
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700184
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100185def count_arm_param_registers(params):
186 """This function is used to count the number of register used
Elliott Hughescd6780b2013-02-07 14:07:00 -0800187 to pass parameters when invoking an ARM system call.
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100188 This is because the ARM EABI mandates that 64-bit quantities
189 must be passed in an even+odd register pair. So, for example,
190 something like:
191
192 foo(int fd, off64_t pos)
193
194 would actually need 4 registers:
195 r0 -> int
196 r1 -> unused
197 r2-r3 -> pos
198 """
199 count = 0
200 for param in params:
201 if param_uses_64bits(param):
202 if (count & 1) != 0:
203 count += 1
204 count += 2
205 else:
206 count += 1
207 return count
208
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700209
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100210def count_generic_param_registers(params):
211 count = 0
212 for param in params:
213 if param_uses_64bits(param):
214 count += 2
215 else:
216 count += 1
217 return count
218
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700219
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400220def count_generic_param_registers64(params):
221 count = 0
222 for param in params:
223 count += 1
224 return count
225
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700226
Elliott Hughescda62092013-03-22 13:50:44 -0700227# This lets us support regular system calls like __NR_write and also weird
228# ones like __ARM_NR_cacheflush, where the NR doesn't come at the start.
229def make__NR_name(name):
230 if name.startswith("__"):
231 return name
232 else:
233 return "__NR_%s" % (name)
234
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700235
Elliott Hughesfff6e272013-10-24 17:03:20 -0700236def add_footer(pointer_length, stub, syscall):
237 # Add any aliases for this syscall.
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700238 aliases = syscall["aliases"]
239 for alias in aliases:
240 stub += function_alias % { "func" : syscall["func"], "alias" : alias }
Elliott Hughesfff6e272013-10-24 17:03:20 -0700241
242 # Use hidden visibility for any functions beginning with underscores.
243 # TODO: clean up single-underscore names too.
244 if pointer_length == 64 and syscall["func"].startswith("__"):
245 stub += '.hidden _C_LABEL(' + syscall["func"] + ')\n'
246
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700247 return stub
248
249
250def arm_eabi_genstub(syscall):
251 num_regs = count_arm_param_registers(syscall["params"])
252 if num_regs > 4:
253 return arm_eabi_call_long % syscall
254 return arm_eabi_call_default % syscall
255
256
257def mips_genstub(syscall):
258 return mips_call % syscall
259
260
261def x86_genstub(syscall):
262 result = syscall_stub_header % syscall
263 stack_bias = 4
264
265 numparams = count_generic_param_registers(syscall["params"])
266 for r in range(numparams):
267 result += " pushl " + x86_registers[r] + "\n"
268 stack_bias += 4
269
270 for r in range(numparams):
271 result += " mov %d(%%esp), %s" % (stack_bias+r*4, x86_registers[r]) + "\n"
272
273 result += x86_call % syscall
274
275 for r in range(numparams):
276 result += " popl " + x86_registers[numparams-r-1] + "\n"
277
278 result += x86_return % syscall
279 return result
280
281def x86_genstub_socketcall(syscall):
282 # %ebx <--- Argument 1 - The call id of the needed vectored
283 # syscall (socket, bind, recv, etc)
284 # %ecx <--- Argument 2 - Pointer to the rest of the arguments
285 # from the original function called (socket())
286
287 result = syscall_stub_header % syscall
288 stack_bias = 4
289
290 # save the regs we need
291 result += " pushl %ebx" + "\n"
292 stack_bias += 4
293 result += " pushl %ecx" + "\n"
294 stack_bias += 4
295
296 # set the call id (%ebx)
297 result += " mov $%d, %%ebx" % syscall["socketcall_id"] + "\n"
298
299 # set the pointer to the rest of the args into %ecx
300 result += " mov %esp, %ecx" + "\n"
301 result += " addl $%d, %%ecx" % (stack_bias) + "\n"
302
303 # now do the syscall code itself
304 result += x86_call % syscall
305
306 # now restore the saved regs
307 result += " popl %ecx" + "\n"
308 result += " popl %ebx" + "\n"
309
310 # epilog
311 result += x86_return % syscall
312 return result
313
314
315def x86_64_genstub(syscall):
316 result = syscall_stub_header % syscall
317 num_regs = count_generic_param_registers64(syscall["params"])
318 if (num_regs > 3):
319 # rcx is used as 4th argument. Kernel wants it at r10.
320 result += " movq %rcx, %r10\n"
321
322 result += x86_64_call % syscall
323 return result
324
325
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700326class State:
327 def __init__(self):
328 self.old_stubs = []
329 self.new_stubs = []
330 self.other_files = []
331 self.syscalls = []
332
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400333
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700334 def process_file(self, input):
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700335 parser = SysCallsTxtParser()
336 parser.parse_file(input)
337 self.syscalls = parser.syscalls
338 parser = None
339
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700340 for syscall in self.syscalls:
341 syscall["__NR_name"] = make__NR_name(syscall["name"])
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700342
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700343 if syscall.has_key("arm"):
Elliott Hughesfff6e272013-10-24 17:03:20 -0700344 syscall["asm-arm"] = add_footer(32, arm_eabi_genstub(syscall), syscall)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700345
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700346 if syscall.has_key("x86"):
347 if syscall["socketcall_id"] >= 0:
Elliott Hughesfff6e272013-10-24 17:03:20 -0700348 syscall["asm-x86"] = add_footer(32, x86_genstub_socketcall(syscall), syscall)
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800349 else:
Elliott Hughesfff6e272013-10-24 17:03:20 -0700350 syscall["asm-x86"] = add_footer(32, x86_genstub(syscall), syscall)
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700351 elif syscall["socketcall_id"] >= 0:
Elliott Hughesd6121652013-09-25 22:43:36 -0700352 E("socketcall_id for dispatch syscalls is only supported for x86 in '%s'" % t)
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800353 return
Elliott Hughescd6780b2013-02-07 14:07:00 -0800354
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700355 if syscall.has_key("mips"):
Elliott Hughesfff6e272013-10-24 17:03:20 -0700356 syscall["asm-mips"] = add_footer(32, mips_genstub(syscall), syscall)
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800357
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700358 if syscall.has_key("x86_64"):
Elliott Hughesfff6e272013-10-24 17:03:20 -0700359 syscall["asm-x86_64"] = add_footer(64, x86_64_genstub(syscall), syscall)
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700360
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700361
Elliott Hughes1b91c6c2013-03-22 18:56:24 -0700362 # Scan a Linux kernel asm/unistd.h file containing __NR_* constants
363 # and write out equivalent SYS_* constants for glibc source compatibility.
Elliott Hughes5c2772f2013-03-21 22:15:06 -0700364 def scan_linux_unistd_h(self, fp, path):
365 pattern = re.compile(r'^#define __NR_([a-z]\S+) .*')
366 syscalls = set() # MIPS defines everything three times; work around that.
367 for line in open(path):
368 m = re.search(pattern, line)
369 if m:
370 syscalls.add(m.group(1))
371 for syscall in sorted(syscalls):
Elliott Hughescda62092013-03-22 13:50:44 -0700372 fp.write("#define SYS_%s %s\n" % (syscall, make__NR_name(syscall)))
Elliott Hughes8ecf2252013-03-21 18:06:55 -0700373
374
Elliott Hughes1b91c6c2013-03-22 18:56:24 -0700375 def gen_glibc_syscalls_h(self):
Elliott Hughescda62092013-03-22 13:50:44 -0700376 # TODO: generate a separate file for each architecture, like glibc's bits/syscall.h.
Elliott Hughes9724ce32013-03-21 19:43:54 -0700377 glibc_syscalls_h_path = "include/sys/glibc-syscalls.h"
Elliott Hughes1b91c6c2013-03-22 18:56:24 -0700378 D("generating " + glibc_syscalls_h_path)
Elliott Hughes9724ce32013-03-21 19:43:54 -0700379 glibc_fp = create_file(glibc_syscalls_h_path)
Elliott Hughes103ccde2013-10-16 14:27:59 -0700380 glibc_fp.write("/* %s */\n" % warning)
Elliott Hughes9724ce32013-03-21 19:43:54 -0700381 glibc_fp.write("#ifndef _BIONIC_GLIBC_SYSCALLS_H_\n")
382 glibc_fp.write("#define _BIONIC_GLIBC_SYSCALLS_H_\n")
383
Elliott Hughes5c2772f2013-03-21 22:15:06 -0700384 glibc_fp.write("#if defined(__arm__)\n")
Elliott Hughes18bc9752013-06-17 10:26:10 -0700385 self.scan_linux_unistd_h(glibc_fp, bionic_libc_root + "/kernel/arch-arm/asm/unistd.h")
Elliott Hughes5c2772f2013-03-21 22:15:06 -0700386 glibc_fp.write("#elif defined(__mips__)\n")
Elliott Hughes18bc9752013-06-17 10:26:10 -0700387 self.scan_linux_unistd_h(glibc_fp, bionic_libc_root + "/kernel/arch-mips/asm/unistd.h")
Elliott Hughes5c2772f2013-03-21 22:15:06 -0700388 glibc_fp.write("#elif defined(__i386__)\n")
Elliott Hughes18bc9752013-06-17 10:26:10 -0700389 self.scan_linux_unistd_h(glibc_fp, bionic_libc_root + "/kernel/arch-x86/asm/unistd_32.h")
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400390 glibc_fp.write("#elif defined(__x86_64__)\n")
391 self.scan_linux_unistd_h(glibc_fp, bionic_libc_root + "/kernel/arch-x86/asm/unistd_64.h")
Elliott Hughes5c2772f2013-03-21 22:15:06 -0700392 glibc_fp.write("#endif\n")
393
394 glibc_fp.write("#endif /* _BIONIC_GLIBC_SYSCALLS_H_ */\n")
395 glibc_fp.close()
396 self.other_files.append(glibc_syscalls_h_path)
397
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700398
Elliott Hughesd6121652013-09-25 22:43:36 -0700399 # Write the contents of syscalls.mk.
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800400 def gen_arch_syscalls_mk(self, arch):
401 path = "arch-%s/syscalls.mk" % arch
Elliott Hughesd6121652013-09-25 22:43:36 -0700402 D("generating " + path)
403 fp = create_file(path)
Elliott Hughes103ccde2013-10-16 14:27:59 -0700404 fp.write("# %s\n" % warning)
Elliott Hughesd6121652013-09-25 22:43:36 -0700405 fp.write("syscall_src :=\n")
Elliott Hughes103ccde2013-10-16 14:27:59 -0700406 for syscall in sorted(self.syscalls, key=lambda syscall: syscall["func"]):
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700407 if syscall.has_key("asm-%s" % arch):
408 fp.write("syscall_src += arch-%s/syscalls/%s.S\n" % (arch, syscall["func"]))
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700409 fp.close()
Elliott Hughesd6121652013-09-25 22:43:36 -0700410 self.other_files.append(path)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700411
Raghu Gandham1fa0d842012-01-27 17:51:42 -0800412
Elliott Hughesd6121652013-09-25 22:43:36 -0700413 # Write each syscall stub.
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700414 def gen_syscall_stubs(self):
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700415 for syscall in self.syscalls:
Elliott Hughesd6121652013-09-25 22:43:36 -0700416 for arch in all_arches:
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700417 if syscall.has_key("asm-%s" % arch):
418 filename = "arch-%s/syscalls/%s.S" % (arch, syscall["func"])
Elliott Hughesd6121652013-09-25 22:43:36 -0700419 D2(">>> generating " + filename)
420 fp = create_file(filename)
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700421 fp.write(syscall["asm-%s" % arch])
Elliott Hughesd6121652013-09-25 22:43:36 -0700422 fp.close()
423 self.new_stubs.append(filename)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700424
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700425
Elliott Hughesd6121652013-09-25 22:43:36 -0700426 def regenerate(self):
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400427 D("scanning for existing architecture-specific stub files...")
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700428
Elliott Hughes18bc9752013-06-17 10:26:10 -0700429 bionic_libc_root_len = len(bionic_libc_root)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700430
Elliott Hughesd6121652013-09-25 22:43:36 -0700431 for arch in all_arches:
Elliott Hughes18bc9752013-06-17 10:26:10 -0700432 arch_path = bionic_libc_root + "arch-" + arch
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400433 D("scanning " + arch_path)
434 files = glob.glob(arch_path + "/syscalls/*.S")
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700435 for f in files:
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400436 self.old_stubs.append(f[bionic_libc_root_len:])
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700437
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400438 D("found %d stub files" % len(self.old_stubs))
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700439
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400440 if not os.path.exists(bionic_temp):
441 D("creating %s..." % bionic_temp)
442 make_dir(bionic_temp)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700443
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400444 D("re-generating stubs and support files...")
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700445
Elliott Hughes1b91c6c2013-03-22 18:56:24 -0700446 self.gen_glibc_syscalls_h()
Elliott Hughesd6121652013-09-25 22:43:36 -0700447 for arch in all_arches:
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800448 self.gen_arch_syscalls_mk(arch)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700449 self.gen_syscall_stubs()
450
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400451 D("comparing files...")
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700452 adds = []
453 edits = []
454
455 for stub in self.new_stubs + self.other_files:
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400456 if not os.path.exists(bionic_libc_root + stub):
David 'Digit' Turnerfc269312010-10-11 22:11:06 +0200457 # new file, git add it
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400458 D("new file: " + stub)
459 adds.append(bionic_libc_root + stub)
460 shutil.copyfile(bionic_temp + stub, bionic_libc_root + stub)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700461
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400462 elif not filecmp.cmp(bionic_temp + stub, bionic_libc_root + stub):
463 D("changed file: " + stub)
464 edits.append(stub)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700465
466 deletes = []
467 for stub in self.old_stubs:
468 if not stub in self.new_stubs:
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400469 D("deleted file: " + stub)
470 deletes.append(bionic_libc_root + stub)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700471
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400472 if not DRY_RUN:
473 if adds:
474 commands.getoutput("git add " + " ".join(adds))
475 if deletes:
476 commands.getoutput("git rm " + " ".join(deletes))
477 if edits:
478 for file in edits:
479 shutil.copyfile(bionic_temp + file, bionic_libc_root + file)
480 commands.getoutput("git add " + " ".join((bionic_libc_root + file) for file in edits))
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700481
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400482 commands.getoutput("git add %s%s" % (bionic_libc_root,"SYSCALLS.TXT"))
David 'Digit' Turnerfc269312010-10-11 22:11:06 +0200483
484 if (not adds) and (not deletes) and (not edits):
485 D("no changes detected!")
486 else:
487 D("ready to go!!")
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700488
489D_setlevel(1)
490
491state = State()
Elliott Hughes18bc9752013-06-17 10:26:10 -0700492state.process_file(bionic_libc_root+"SYSCALLS.TXT")
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700493state.regenerate()