blob: d0a8f273a084ce8d5a0c3160f73547e0f9c07bb0 [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"""
Elliott Hughesed744842013-11-07 10:31:05 -080044#include <private/bionic_asm.h>
Pavel Chupinf12a18b2012-12-12 13:11:48 +040045
Elliott Hughes0437f3f2013-10-07 23:53:13 -070046ENTRY(%(func)s)
Pavel Chupinf12a18b2012-12-12 13:11:48 +040047"""
48
Elliott Hughes0437f3f2013-10-07 23:53:13 -070049
H.J. Lu6fe4e872013-10-04 10:03:17 -070050function_alias = """
51 .globl _C_LABEL(%(alias)s)
Elliott Hughes0437f3f2013-10-07 23:53:13 -070052 .equ _C_LABEL(%(alias)s), _C_LABEL(%(func)s)
H.J. Lu6fe4e872013-10-04 10:03:17 -070053"""
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070054
Elliott Hughes0437f3f2013-10-07 23:53:13 -070055
56#
Serban Constantinescufeaa89a2013-10-07 16:49:09 +010057# AArch64 assembler templates for each syscall stub
58#
59
60aarch64_call = syscall_stub_header + """\
61 stp x29, x30, [sp, #-16]!
62 mov x29, sp
63 str x8, [sp, #-16]!
64
65 mov x8, %(__NR_name)s
66 svc #0
67
68 ldr x8, [sp], #16
69 ldp x29, x30, [sp], #16
70
71 cmn x0, #(MAX_ERRNO + 1)
72 cneg x0, x0, hi
73 b.hi __set_errno
74
75 ret
76END(%(func)s)
77"""
78
79#
Elliott Hughes0437f3f2013-10-07 23:53:13 -070080# ARM assembler templates for each syscall stub
81#
82
83arm_eabi_call_default = syscall_stub_header + """\
84 mov ip, r7
85 ldr r7, =%(__NR_name)s
86 swi #0
87 mov r7, ip
88 cmn r0, #(MAX_ERRNO + 1)
89 bxls lr
90 neg r0, r0
91 b __set_errno
92END(%(func)s)
93"""
94
95arm_eabi_call_long = syscall_stub_header + """\
96 mov ip, sp
97 .save {r4, r5, r6, r7}
98 stmfd sp!, {r4, r5, r6, r7}
99 ldmfd ip, {r4, r5, r6}
100 ldr r7, =%(__NR_name)s
101 swi #0
102 ldmfd sp!, {r4, r5, r6, r7}
103 cmn r0, #(MAX_ERRNO + 1)
104 bxls lr
105 neg r0, r0
106 b __set_errno
107END(%(func)s)
108"""
109
110
111#
112# MIPS assembler templates for each syscall stub
113#
114
Elliott Hughes103ccde2013-10-16 14:27:59 -0700115mips_call = "/* " + warning + " */\n" + \
116"""
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700117#include <asm/unistd.h>
118 .text
119 .globl %(func)s
120 .align 4
121 .ent %(func)s
122
123%(func)s:
124 .set noreorder
125 .cpload $t9
126 li $v0, %(__NR_name)s
127 syscall
128 bnez $a3, 1f
129 move $a0, $v0
130 j $ra
131 nop
1321:
133 la $t9,__set_errno
134 j $t9
135 nop
136 .set reorder
137 .end %(func)s
138"""
139
140
Elliott Hughescd6780b2013-02-07 14:07:00 -0800141#
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700142# x86 assembler templates for each syscall stub
143#
144
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700145x86_registers = [ "%ebx", "%ecx", "%edx", "%esi", "%edi", "%ebp" ]
146
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700147x86_call = """\
148 movl $%(__NR_name)s, %%eax
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700149 int $0x80
Elliott Hughes9aceab52013-03-12 14:57:30 -0700150 cmpl $-MAX_ERRNO, %%eax
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700151 jb 1f
152 negl %%eax
153 pushl %%eax
154 call __set_errno
155 addl $4, %%esp
156 orl $-1, %%eax
1571:
158"""
159
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700160x86_return = """\
161 ret
162END(%(func)s)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700163"""
164
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700165
Elliott Hughescd6780b2013-02-07 14:07:00 -0800166#
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400167# x86_64 assembler templates for each syscall stub
168#
169
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700170x86_64_call = """\
171 movl $%(__NR_name)s, %%eax
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400172 syscall
173 cmpq $-MAX_ERRNO, %%rax
174 jb 1f
175 negl %%eax
176 movl %%eax, %%edi
177 call __set_errno
178 orq $-1, %%rax
1791:
180 ret
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700181END(%(func)s)
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400182"""
183
Raghu Gandham1fa0d842012-01-27 17:51:42 -0800184
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100185def param_uses_64bits(param):
186 """Returns True iff a syscall parameter description corresponds
187 to a 64-bit type."""
188 param = param.strip()
189 # First, check that the param type begins with one of the known
190 # 64-bit types.
191 if not ( \
192 param.startswith("int64_t") or param.startswith("uint64_t") or \
193 param.startswith("loff_t") or param.startswith("off64_t") or \
194 param.startswith("long long") or param.startswith("unsigned long long") or
195 param.startswith("signed long long") ):
196 return False
197
198 # Second, check that there is no pointer type here
199 if param.find("*") >= 0:
200 return False
201
202 # Ok
203 return True
204
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700205
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100206def count_arm_param_registers(params):
207 """This function is used to count the number of register used
Elliott Hughescd6780b2013-02-07 14:07:00 -0800208 to pass parameters when invoking an ARM system call.
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100209 This is because the ARM EABI mandates that 64-bit quantities
210 must be passed in an even+odd register pair. So, for example,
211 something like:
212
213 foo(int fd, off64_t pos)
214
215 would actually need 4 registers:
216 r0 -> int
217 r1 -> unused
218 r2-r3 -> pos
219 """
220 count = 0
221 for param in params:
222 if param_uses_64bits(param):
223 if (count & 1) != 0:
224 count += 1
225 count += 2
226 else:
227 count += 1
228 return count
229
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700230
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100231def count_generic_param_registers(params):
232 count = 0
233 for param in params:
234 if param_uses_64bits(param):
235 count += 2
236 else:
237 count += 1
238 return count
239
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700240
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400241def count_generic_param_registers64(params):
242 count = 0
243 for param in params:
244 count += 1
245 return count
246
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700247
Elliott Hughescda62092013-03-22 13:50:44 -0700248# This lets us support regular system calls like __NR_write and also weird
249# ones like __ARM_NR_cacheflush, where the NR doesn't come at the start.
250def make__NR_name(name):
251 if name.startswith("__"):
252 return name
253 else:
254 return "__NR_%s" % (name)
255
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700256
Elliott Hughesfff6e272013-10-24 17:03:20 -0700257def add_footer(pointer_length, stub, syscall):
258 # Add any aliases for this syscall.
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700259 aliases = syscall["aliases"]
260 for alias in aliases:
261 stub += function_alias % { "func" : syscall["func"], "alias" : alias }
Elliott Hughesfff6e272013-10-24 17:03:20 -0700262
263 # Use hidden visibility for any functions beginning with underscores.
Elliott Hughesfff6e272013-10-24 17:03:20 -0700264 if pointer_length == 64 and syscall["func"].startswith("__"):
265 stub += '.hidden _C_LABEL(' + syscall["func"] + ')\n'
266
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700267 return stub
268
269
Serban Constantinescufeaa89a2013-10-07 16:49:09 +0100270def aarch64_genstub(syscall):
271 return aarch64_call % syscall
272
273
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700274def arm_eabi_genstub(syscall):
275 num_regs = count_arm_param_registers(syscall["params"])
276 if num_regs > 4:
277 return arm_eabi_call_long % syscall
278 return arm_eabi_call_default % syscall
279
280
281def mips_genstub(syscall):
282 return mips_call % syscall
283
284
285def x86_genstub(syscall):
286 result = syscall_stub_header % syscall
287 stack_bias = 4
288
289 numparams = count_generic_param_registers(syscall["params"])
290 for r in range(numparams):
291 result += " pushl " + x86_registers[r] + "\n"
292 stack_bias += 4
293
294 for r in range(numparams):
295 result += " mov %d(%%esp), %s" % (stack_bias+r*4, x86_registers[r]) + "\n"
296
297 result += x86_call % syscall
298
299 for r in range(numparams):
300 result += " popl " + x86_registers[numparams-r-1] + "\n"
301
302 result += x86_return % syscall
303 return result
304
Serban Constantinescufeaa89a2013-10-07 16:49:09 +0100305
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700306def x86_genstub_socketcall(syscall):
307 # %ebx <--- Argument 1 - The call id of the needed vectored
308 # syscall (socket, bind, recv, etc)
309 # %ecx <--- Argument 2 - Pointer to the rest of the arguments
310 # from the original function called (socket())
311
312 result = syscall_stub_header % syscall
313 stack_bias = 4
314
315 # save the regs we need
316 result += " pushl %ebx" + "\n"
317 stack_bias += 4
318 result += " pushl %ecx" + "\n"
319 stack_bias += 4
320
321 # set the call id (%ebx)
322 result += " mov $%d, %%ebx" % syscall["socketcall_id"] + "\n"
323
324 # set the pointer to the rest of the args into %ecx
325 result += " mov %esp, %ecx" + "\n"
326 result += " addl $%d, %%ecx" % (stack_bias) + "\n"
327
328 # now do the syscall code itself
329 result += x86_call % syscall
330
331 # now restore the saved regs
332 result += " popl %ecx" + "\n"
333 result += " popl %ebx" + "\n"
334
335 # epilog
336 result += x86_return % syscall
337 return result
338
339
340def x86_64_genstub(syscall):
341 result = syscall_stub_header % syscall
342 num_regs = count_generic_param_registers64(syscall["params"])
343 if (num_regs > 3):
344 # rcx is used as 4th argument. Kernel wants it at r10.
345 result += " movq %rcx, %r10\n"
346
347 result += x86_64_call % syscall
348 return result
349
350
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700351class State:
352 def __init__(self):
353 self.old_stubs = []
354 self.new_stubs = []
355 self.other_files = []
356 self.syscalls = []
357
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400358
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700359 def process_file(self, input):
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700360 parser = SysCallsTxtParser()
361 parser.parse_file(input)
362 self.syscalls = parser.syscalls
363 parser = None
364
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700365 for syscall in self.syscalls:
366 syscall["__NR_name"] = make__NR_name(syscall["name"])
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700367
Serban Constantinescufeaa89a2013-10-07 16:49:09 +0100368 if syscall.has_key("aarch64"):
369 syscall["asm-aarch64"] = add_footer(64, aarch64_genstub(syscall), syscall)
370
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700371 if syscall.has_key("arm"):
Elliott Hughesfff6e272013-10-24 17:03:20 -0700372 syscall["asm-arm"] = add_footer(32, arm_eabi_genstub(syscall), syscall)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700373
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700374 if syscall.has_key("x86"):
375 if syscall["socketcall_id"] >= 0:
Elliott Hughesfff6e272013-10-24 17:03:20 -0700376 syscall["asm-x86"] = add_footer(32, x86_genstub_socketcall(syscall), syscall)
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800377 else:
Elliott Hughesfff6e272013-10-24 17:03:20 -0700378 syscall["asm-x86"] = add_footer(32, x86_genstub(syscall), syscall)
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700379 elif syscall["socketcall_id"] >= 0:
Elliott Hughesd6121652013-09-25 22:43:36 -0700380 E("socketcall_id for dispatch syscalls is only supported for x86 in '%s'" % t)
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800381 return
Elliott Hughescd6780b2013-02-07 14:07:00 -0800382
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700383 if syscall.has_key("mips"):
Elliott Hughesfff6e272013-10-24 17:03:20 -0700384 syscall["asm-mips"] = add_footer(32, mips_genstub(syscall), syscall)
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800385
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700386 if syscall.has_key("x86_64"):
Elliott Hughesfff6e272013-10-24 17:03:20 -0700387 syscall["asm-x86_64"] = add_footer(64, x86_64_genstub(syscall), syscall)
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700388
Elliott Hughes1b91c6c2013-03-22 18:56:24 -0700389 # Scan a Linux kernel asm/unistd.h file containing __NR_* constants
390 # and write out equivalent SYS_* constants for glibc source compatibility.
Elliott Hughes5c2772f2013-03-21 22:15:06 -0700391 def scan_linux_unistd_h(self, fp, path):
392 pattern = re.compile(r'^#define __NR_([a-z]\S+) .*')
393 syscalls = set() # MIPS defines everything three times; work around that.
394 for line in open(path):
395 m = re.search(pattern, line)
396 if m:
397 syscalls.add(m.group(1))
398 for syscall in sorted(syscalls):
Elliott Hughescda62092013-03-22 13:50:44 -0700399 fp.write("#define SYS_%s %s\n" % (syscall, make__NR_name(syscall)))
Elliott Hughes8ecf2252013-03-21 18:06:55 -0700400
401
Elliott Hughes1b91c6c2013-03-22 18:56:24 -0700402 def gen_glibc_syscalls_h(self):
Elliott Hughescda62092013-03-22 13:50:44 -0700403 # TODO: generate a separate file for each architecture, like glibc's bits/syscall.h.
Elliott Hughes9724ce32013-03-21 19:43:54 -0700404 glibc_syscalls_h_path = "include/sys/glibc-syscalls.h"
Elliott Hughes1b91c6c2013-03-22 18:56:24 -0700405 D("generating " + glibc_syscalls_h_path)
Elliott Hughes9724ce32013-03-21 19:43:54 -0700406 glibc_fp = create_file(glibc_syscalls_h_path)
Elliott Hughes103ccde2013-10-16 14:27:59 -0700407 glibc_fp.write("/* %s */\n" % warning)
Elliott Hughes9724ce32013-03-21 19:43:54 -0700408 glibc_fp.write("#ifndef _BIONIC_GLIBC_SYSCALLS_H_\n")
409 glibc_fp.write("#define _BIONIC_GLIBC_SYSCALLS_H_\n")
410
Serban Constantinescufeaa89a2013-10-07 16:49:09 +0100411 glibc_fp.write("#if defined(__aarch64__)\n")
412 self.scan_linux_unistd_h(glibc_fp, bionic_libc_root + "/kernel/uapi/asm-generic/unistd.h")
413 glibc_fp.write("#elif defined(__arm__)\n")
Elliott Hughes18bc9752013-06-17 10:26:10 -0700414 self.scan_linux_unistd_h(glibc_fp, bionic_libc_root + "/kernel/arch-arm/asm/unistd.h")
Elliott Hughes5c2772f2013-03-21 22:15:06 -0700415 glibc_fp.write("#elif defined(__mips__)\n")
Elliott Hughes18bc9752013-06-17 10:26:10 -0700416 self.scan_linux_unistd_h(glibc_fp, bionic_libc_root + "/kernel/arch-mips/asm/unistd.h")
Elliott Hughes5c2772f2013-03-21 22:15:06 -0700417 glibc_fp.write("#elif defined(__i386__)\n")
Elliott Hughes18bc9752013-06-17 10:26:10 -0700418 self.scan_linux_unistd_h(glibc_fp, bionic_libc_root + "/kernel/arch-x86/asm/unistd_32.h")
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400419 glibc_fp.write("#elif defined(__x86_64__)\n")
420 self.scan_linux_unistd_h(glibc_fp, bionic_libc_root + "/kernel/arch-x86/asm/unistd_64.h")
Elliott Hughes5c2772f2013-03-21 22:15:06 -0700421 glibc_fp.write("#endif\n")
422
423 glibc_fp.write("#endif /* _BIONIC_GLIBC_SYSCALLS_H_ */\n")
424 glibc_fp.close()
425 self.other_files.append(glibc_syscalls_h_path)
426
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700427
Elliott Hughesd6121652013-09-25 22:43:36 -0700428 # Write the contents of syscalls.mk.
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800429 def gen_arch_syscalls_mk(self, arch):
430 path = "arch-%s/syscalls.mk" % arch
Elliott Hughesd6121652013-09-25 22:43:36 -0700431 D("generating " + path)
432 fp = create_file(path)
Elliott Hughes103ccde2013-10-16 14:27:59 -0700433 fp.write("# %s\n" % warning)
Elliott Hughesd6121652013-09-25 22:43:36 -0700434 fp.write("syscall_src :=\n")
Elliott Hughes103ccde2013-10-16 14:27:59 -0700435 for syscall in sorted(self.syscalls, key=lambda syscall: syscall["func"]):
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700436 if syscall.has_key("asm-%s" % arch):
437 fp.write("syscall_src += arch-%s/syscalls/%s.S\n" % (arch, syscall["func"]))
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700438 fp.close()
Elliott Hughesd6121652013-09-25 22:43:36 -0700439 self.other_files.append(path)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700440
Raghu Gandham1fa0d842012-01-27 17:51:42 -0800441
Elliott Hughesd6121652013-09-25 22:43:36 -0700442 # Write each syscall stub.
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700443 def gen_syscall_stubs(self):
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700444 for syscall in self.syscalls:
Elliott Hughesd6121652013-09-25 22:43:36 -0700445 for arch in all_arches:
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700446 if syscall.has_key("asm-%s" % arch):
447 filename = "arch-%s/syscalls/%s.S" % (arch, syscall["func"])
Elliott Hughesd6121652013-09-25 22:43:36 -0700448 D2(">>> generating " + filename)
449 fp = create_file(filename)
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700450 fp.write(syscall["asm-%s" % arch])
Elliott Hughesd6121652013-09-25 22:43:36 -0700451 fp.close()
452 self.new_stubs.append(filename)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700453
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700454
Elliott Hughesd6121652013-09-25 22:43:36 -0700455 def regenerate(self):
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400456 D("scanning for existing architecture-specific stub files...")
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700457
Elliott Hughes18bc9752013-06-17 10:26:10 -0700458 bionic_libc_root_len = len(bionic_libc_root)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700459
Elliott Hughesd6121652013-09-25 22:43:36 -0700460 for arch in all_arches:
Elliott Hughes18bc9752013-06-17 10:26:10 -0700461 arch_path = bionic_libc_root + "arch-" + arch
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400462 D("scanning " + arch_path)
463 files = glob.glob(arch_path + "/syscalls/*.S")
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700464 for f in files:
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400465 self.old_stubs.append(f[bionic_libc_root_len:])
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700466
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400467 D("found %d stub files" % len(self.old_stubs))
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700468
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400469 if not os.path.exists(bionic_temp):
470 D("creating %s..." % bionic_temp)
471 make_dir(bionic_temp)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700472
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400473 D("re-generating stubs and support files...")
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700474
Elliott Hughes1b91c6c2013-03-22 18:56:24 -0700475 self.gen_glibc_syscalls_h()
Elliott Hughesd6121652013-09-25 22:43:36 -0700476 for arch in all_arches:
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800477 self.gen_arch_syscalls_mk(arch)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700478 self.gen_syscall_stubs()
479
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400480 D("comparing files...")
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700481 adds = []
482 edits = []
483
484 for stub in self.new_stubs + self.other_files:
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400485 if not os.path.exists(bionic_libc_root + stub):
David 'Digit' Turnerfc269312010-10-11 22:11:06 +0200486 # new file, git add it
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400487 D("new file: " + stub)
488 adds.append(bionic_libc_root + stub)
489 shutil.copyfile(bionic_temp + stub, bionic_libc_root + stub)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700490
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400491 elif not filecmp.cmp(bionic_temp + stub, bionic_libc_root + stub):
492 D("changed file: " + stub)
493 edits.append(stub)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700494
495 deletes = []
496 for stub in self.old_stubs:
497 if not stub in self.new_stubs:
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400498 D("deleted file: " + stub)
499 deletes.append(bionic_libc_root + stub)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700500
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400501 if not DRY_RUN:
502 if adds:
503 commands.getoutput("git add " + " ".join(adds))
504 if deletes:
505 commands.getoutput("git rm " + " ".join(deletes))
506 if edits:
507 for file in edits:
508 shutil.copyfile(bionic_temp + file, bionic_libc_root + file)
509 commands.getoutput("git add " + " ".join((bionic_libc_root + file) for file in edits))
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700510
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400511 commands.getoutput("git add %s%s" % (bionic_libc_root,"SYSCALLS.TXT"))
David 'Digit' Turnerfc269312010-10-11 22:11:06 +0200512
513 if (not adds) and (not deletes) and (not edits):
514 D("no changes detected!")
515 else:
516 D("ready to go!!")
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700517
518D_setlevel(1)
519
520state = State()
Elliott Hughes18bc9752013-06-17 10:26:10 -0700521state.process_file(bionic_libc_root+"SYSCALLS.TXT")
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700522state.regenerate()