blob: 386a8db92c05ead5b4b53ae14f12ce13d329673e [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
The Android Open Source Project4e468ed2008-12-17 18:03:48 -08007import sys, os.path, glob, re, commands, filecmp, shutil
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -07008
9from bionic_utils import *
10
Elliott Hughes18bc9752013-06-17 10:26:10 -070011bionic_libc_root = os.environ["ANDROID_BUILD_TOP"] + "/bionic/libc/"
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070012
13# temp directory where we store all intermediate files
14bionic_temp = "/tmp/bionic_gensyscalls/"
15
Pavel Chupinf12a18b2012-12-12 13:11:48 +040016DRY_RUN = False
17
18def make_dir(path):
Raghu Gandham1fa0d842012-01-27 17:51:42 -080019 path = os.path.abspath(path)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070020 if not os.path.exists(path):
21 parent = os.path.dirname(path)
22 if parent:
23 make_dir(parent)
24 os.mkdir(path)
25
Pavel Chupinf12a18b2012-12-12 13:11:48 +040026def create_file(relpath):
27 dir = os.path.dirname(bionic_temp + relpath)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070028 make_dir(dir)
Pavel Chupinf12a18b2012-12-12 13:11:48 +040029 return open(bionic_temp + relpath, "w")
30
31
32syscall_stub_header = """/* autogenerated by gensyscalls.py */
33#include <asm/unistd.h>
34#include <linux/err.h>
35#include <machine/asm.h>
36
37ENTRY(%(fname)s)
38"""
39
H.J. Lu6fe4e872013-10-04 10:03:17 -070040function_alias = """
41 .globl _C_LABEL(%(alias)s)
42 .equ _C_LABEL(%(alias)s), _C_LABEL(%(fname)s)
43"""
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070044
Elliott Hughescd6780b2013-02-07 14:07:00 -080045#
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070046# x86 assembler templates for each syscall stub
47#
48
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070049x86_registers = [ "%ebx", "%ecx", "%edx", "%esi", "%edi", "%ebp" ]
50
51x86_call = """ movl $%(idname)s, %%eax
52 int $0x80
Elliott Hughes9aceab52013-03-12 14:57:30 -070053 cmpl $-MAX_ERRNO, %%eax
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070054 jb 1f
55 negl %%eax
56 pushl %%eax
57 call __set_errno
58 addl $4, %%esp
59 orl $-1, %%eax
601:
61"""
62
63x86_return = """ ret
Elliott Hughes7582a9c2013-02-06 17:08:15 -080064END(%(fname)s)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070065"""
66
Elliott Hughescd6780b2013-02-07 14:07:00 -080067#
Pavel Chupinf12a18b2012-12-12 13:11:48 +040068# x86_64 assembler templates for each syscall stub
69#
70
71x86_64_call = """ movl $%(idname)s, %%eax
72 syscall
73 cmpq $-MAX_ERRNO, %%rax
74 jb 1f
75 negl %%eax
76 movl %%eax, %%edi
77 call __set_errno
78 orq $-1, %%rax
791:
80 ret
81END(%(fname)s)
82"""
83
84#
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070085# ARM assembler templates for each syscall stub
86#
Elliott Hughescd6780b2013-02-07 14:07:00 -080087
Pavel Chupinf12a18b2012-12-12 13:11:48 +040088arm_eabi_call_default = syscall_stub_header + """\
Matthieu Castetfaa0fdb2013-01-16 14:02:50 +010089 mov ip, r7
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070090 ldr r7, =%(idname)s
91 swi #0
Matthieu Castetfaa0fdb2013-01-16 14:02:50 +010092 mov r7, ip
Elliott Hughes9aceab52013-03-12 14:57:30 -070093 cmn r0, #(MAX_ERRNO + 1)
94 bxls lr
95 neg r0, r0
96 b __set_errno
Elliott Hughescd6780b2013-02-07 14:07:00 -080097END(%(fname)s)
98"""
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070099
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400100arm_eabi_call_long = syscall_stub_header + """\
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700101 mov ip, sp
102 .save {r4, r5, r6, r7}
103 stmfd sp!, {r4, r5, r6, r7}
104 ldmfd ip, {r4, r5, r6}
105 ldr r7, =%(idname)s
106 swi #0
107 ldmfd sp!, {r4, r5, r6, r7}
Elliott Hughes9aceab52013-03-12 14:57:30 -0700108 cmn r0, #(MAX_ERRNO + 1)
109 bxls lr
110 neg r0, r0
111 b __set_errno
Elliott Hughescd6780b2013-02-07 14:07:00 -0800112END(%(fname)s)
113"""
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700114
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700115#
Raghu Gandham1fa0d842012-01-27 17:51:42 -0800116# mips assembler templates for each syscall stub
117#
Elliott Hughescd6780b2013-02-07 14:07:00 -0800118
Raghu Gandham1fa0d842012-01-27 17:51:42 -0800119mips_call = """/* autogenerated by gensyscalls.py */
Elliott Hughes5c2772f2013-03-21 22:15:06 -0700120#include <asm/unistd.h>
Raghu Gandham1fa0d842012-01-27 17:51:42 -0800121 .text
122 .globl %(fname)s
123 .align 4
124 .ent %(fname)s
125
126%(fname)s:
127 .set noreorder
128 .cpload $t9
129 li $v0, %(idname)s
130 syscall
131 bnez $a3, 1f
132 move $a0, $v0
133 j $ra
134 nop
1351:
136 la $t9,__set_errno
137 j $t9
138 nop
139 .set reorder
140 .end %(fname)s
141"""
142
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100143def param_uses_64bits(param):
144 """Returns True iff a syscall parameter description corresponds
145 to a 64-bit type."""
146 param = param.strip()
147 # First, check that the param type begins with one of the known
148 # 64-bit types.
149 if not ( \
150 param.startswith("int64_t") or param.startswith("uint64_t") or \
151 param.startswith("loff_t") or param.startswith("off64_t") or \
152 param.startswith("long long") or param.startswith("unsigned long long") or
153 param.startswith("signed long long") ):
154 return False
155
156 # Second, check that there is no pointer type here
157 if param.find("*") >= 0:
158 return False
159
160 # Ok
161 return True
162
163def count_arm_param_registers(params):
164 """This function is used to count the number of register used
Elliott Hughescd6780b2013-02-07 14:07:00 -0800165 to pass parameters when invoking an ARM system call.
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100166 This is because the ARM EABI mandates that 64-bit quantities
167 must be passed in an even+odd register pair. So, for example,
168 something like:
169
170 foo(int fd, off64_t pos)
171
172 would actually need 4 registers:
173 r0 -> int
174 r1 -> unused
175 r2-r3 -> pos
176 """
177 count = 0
178 for param in params:
179 if param_uses_64bits(param):
180 if (count & 1) != 0:
181 count += 1
182 count += 2
183 else:
184 count += 1
185 return count
186
187def count_generic_param_registers(params):
188 count = 0
189 for param in params:
190 if param_uses_64bits(param):
191 count += 2
192 else:
193 count += 1
194 return count
195
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400196def count_generic_param_registers64(params):
197 count = 0
198 for param in params:
199 count += 1
200 return count
201
Elliott Hughescda62092013-03-22 13:50:44 -0700202# This lets us support regular system calls like __NR_write and also weird
203# ones like __ARM_NR_cacheflush, where the NR doesn't come at the start.
204def make__NR_name(name):
205 if name.startswith("__"):
206 return name
207 else:
208 return "__NR_%s" % (name)
209
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700210class State:
211 def __init__(self):
212 self.old_stubs = []
213 self.new_stubs = []
214 self.other_files = []
215 self.syscalls = []
216
H.J. Lu6fe4e872013-10-04 10:03:17 -0700217 def x86_64_genstub(self, fname, numparams, idname, aliases):
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400218 t = { "fname" : fname, "idname" : idname }
219
220 result = syscall_stub_header % t
221 # rcx is used as 4th argument. Kernel wants it at r10.
222 if (numparams > 3):
223 result += " movq %rcx, %r10\n"
224
225 result += x86_64_call % t
H.J. Lu6fe4e872013-10-04 10:03:17 -0700226 for alias in aliases:
227 t = { "fname" : fname, "alias" : alias }
228 result += function_alias % t
229
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400230 return result
231
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800232 def x86_genstub(self, fname, numparams, idname):
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700233 t = { "fname" : fname,
234 "idname" : idname }
235
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400236 result = syscall_stub_header % t
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700237 stack_bias = 4
238 for r in range(numparams):
239 result += " pushl " + x86_registers[r] + "\n"
240 stack_bias += 4
241
242 for r in range(numparams):
243 result += " mov %d(%%esp), %s" % (stack_bias+r*4, x86_registers[r]) + "\n"
244
245 result += x86_call % t
246
247 for r in range(numparams):
248 result += " popl " + x86_registers[numparams-r-1] + "\n"
249
Elliott Hughes7582a9c2013-02-06 17:08:15 -0800250 result += x86_return % t
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700251 return result
252
Elliott Hughesd6121652013-09-25 22:43:36 -0700253 def x86_genstub_socketcall(self, fname, idname, socketcall_id):
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800254 # %ebx <--- Argument 1 - The call id of the needed vectored
255 # syscall (socket, bind, recv, etc)
256 # %ecx <--- Argument 2 - Pointer to the rest of the arguments
257 # from the original function called (socket())
258 t = { "fname" : fname,
259 "idname" : idname }
260
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400261 result = syscall_stub_header % t
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800262 stack_bias = 4
263
264 # save the regs we need
265 result += " pushl %ebx" + "\n"
266 stack_bias += 4
267 result += " pushl %ecx" + "\n"
268 stack_bias += 4
269
270 # set the call id (%ebx)
Elliott Hughesd6121652013-09-25 22:43:36 -0700271 result += " mov $%d, %%ebx" % (socketcall_id) + "\n"
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800272
273 # set the pointer to the rest of the args into %ecx
274 result += " mov %esp, %ecx" + "\n"
275 result += " addl $%d, %%ecx" % (stack_bias) + "\n"
276
277 # now do the syscall code itself
278 result += x86_call % t
279
280 # now restore the saved regs
281 result += " popl %ecx" + "\n"
282 result += " popl %ebx" + "\n"
283
284 # epilog
Elliott Hughes7582a9c2013-02-06 17:08:15 -0800285 result += x86_return % t
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800286 return result
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700287
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700288
289 def arm_eabi_genstub(self,fname, flags, idname):
290 t = { "fname" : fname,
291 "idname" : idname }
292 if flags:
293 numargs = int(flags)
294 if numargs > 4:
295 return arm_eabi_call_long % t
296 return arm_eabi_call_default % t
297
298
Raghu Gandham1fa0d842012-01-27 17:51:42 -0800299 def mips_genstub(self,fname, idname):
300 t = { "fname" : fname,
301 "idname" : idname }
302 return mips_call % t
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700303
304 def process_file(self,input):
305 parser = SysCallsTxtParser()
306 parser.parse_file(input)
307 self.syscalls = parser.syscalls
308 parser = None
309
310 for t in self.syscalls:
311 syscall_func = t["func"]
H.J. Lu6fe4e872013-10-04 10:03:17 -0700312 syscall_aliases = t["aliases"]
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700313 syscall_params = t["params"]
314 syscall_name = t["name"]
Elliott Hughesd6121652013-09-25 22:43:36 -0700315 __NR_name = make__NR_name(t["name"])
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700316
Elliott Hughesd6121652013-09-25 22:43:36 -0700317 if t.has_key("arm"):
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100318 num_regs = count_arm_param_registers(syscall_params)
Elliott Hughesd6121652013-09-25 22:43:36 -0700319 t["asm-arm"] = self.arm_eabi_genstub(syscall_func, num_regs, __NR_name)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700320
Elliott Hughesd6121652013-09-25 22:43:36 -0700321 if t.has_key("x86"):
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100322 num_regs = count_generic_param_registers(syscall_params)
Elliott Hughesd6121652013-09-25 22:43:36 -0700323 if t["socketcall_id"] >= 0:
324 t["asm-x86"] = self.x86_genstub_socketcall(syscall_func, __NR_name, t["socketcall_id"])
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800325 else:
Elliott Hughesd6121652013-09-25 22:43:36 -0700326 t["asm-x86"] = self.x86_genstub(syscall_func, num_regs, __NR_name)
327 elif t["socketcall_id"] >= 0:
328 E("socketcall_id for dispatch syscalls is only supported for x86 in '%s'" % t)
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800329 return
Elliott Hughescd6780b2013-02-07 14:07:00 -0800330
Elliott Hughesd6121652013-09-25 22:43:36 -0700331 if t.has_key("mips"):
Elliott Hughescda62092013-03-22 13:50:44 -0700332 t["asm-mips"] = self.mips_genstub(syscall_func, make__NR_name(syscall_name))
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800333
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400334 if t.has_key("x86_64"):
335 num_regs = count_generic_param_registers64(syscall_params)
H.J. Lu6fe4e872013-10-04 10:03:17 -0700336 t["asm-x86_64"] = self.x86_64_genstub(syscall_func, num_regs, __NR_name, syscall_aliases)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700337
Elliott Hughes1b91c6c2013-03-22 18:56:24 -0700338 # Scan a Linux kernel asm/unistd.h file containing __NR_* constants
339 # and write out equivalent SYS_* constants for glibc source compatibility.
Elliott Hughes5c2772f2013-03-21 22:15:06 -0700340 def scan_linux_unistd_h(self, fp, path):
341 pattern = re.compile(r'^#define __NR_([a-z]\S+) .*')
342 syscalls = set() # MIPS defines everything three times; work around that.
343 for line in open(path):
344 m = re.search(pattern, line)
345 if m:
346 syscalls.add(m.group(1))
347 for syscall in sorted(syscalls):
Elliott Hughescda62092013-03-22 13:50:44 -0700348 fp.write("#define SYS_%s %s\n" % (syscall, make__NR_name(syscall)))
Elliott Hughes8ecf2252013-03-21 18:06:55 -0700349
350
Elliott Hughes1b91c6c2013-03-22 18:56:24 -0700351 def gen_glibc_syscalls_h(self):
Elliott Hughescda62092013-03-22 13:50:44 -0700352 # TODO: generate a separate file for each architecture, like glibc's bits/syscall.h.
Elliott Hughes9724ce32013-03-21 19:43:54 -0700353 glibc_syscalls_h_path = "include/sys/glibc-syscalls.h"
Elliott Hughes1b91c6c2013-03-22 18:56:24 -0700354 D("generating " + glibc_syscalls_h_path)
Elliott Hughes9724ce32013-03-21 19:43:54 -0700355 glibc_fp = create_file(glibc_syscalls_h_path)
356 glibc_fp.write("/* Auto-generated by gensyscalls.py; do not edit. */\n")
357 glibc_fp.write("#ifndef _BIONIC_GLIBC_SYSCALLS_H_\n")
358 glibc_fp.write("#define _BIONIC_GLIBC_SYSCALLS_H_\n")
359
Elliott Hughes5c2772f2013-03-21 22:15:06 -0700360 glibc_fp.write("#if defined(__arm__)\n")
Elliott Hughes18bc9752013-06-17 10:26:10 -0700361 self.scan_linux_unistd_h(glibc_fp, bionic_libc_root + "/kernel/arch-arm/asm/unistd.h")
Elliott Hughes5c2772f2013-03-21 22:15:06 -0700362 glibc_fp.write("#elif defined(__mips__)\n")
Elliott Hughes18bc9752013-06-17 10:26:10 -0700363 self.scan_linux_unistd_h(glibc_fp, bionic_libc_root + "/kernel/arch-mips/asm/unistd.h")
Elliott Hughes5c2772f2013-03-21 22:15:06 -0700364 glibc_fp.write("#elif defined(__i386__)\n")
Elliott Hughes18bc9752013-06-17 10:26:10 -0700365 self.scan_linux_unistd_h(glibc_fp, bionic_libc_root + "/kernel/arch-x86/asm/unistd_32.h")
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400366 glibc_fp.write("#elif defined(__x86_64__)\n")
367 self.scan_linux_unistd_h(glibc_fp, bionic_libc_root + "/kernel/arch-x86/asm/unistd_64.h")
Elliott Hughes5c2772f2013-03-21 22:15:06 -0700368 glibc_fp.write("#endif\n")
369
370 glibc_fp.write("#endif /* _BIONIC_GLIBC_SYSCALLS_H_ */\n")
371 glibc_fp.close()
372 self.other_files.append(glibc_syscalls_h_path)
373
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700374
Elliott Hughesd6121652013-09-25 22:43:36 -0700375 # Write the contents of syscalls.mk.
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800376 def gen_arch_syscalls_mk(self, arch):
377 path = "arch-%s/syscalls.mk" % arch
Elliott Hughesd6121652013-09-25 22:43:36 -0700378 D("generating " + path)
379 fp = create_file(path)
380 fp.write("# Auto-generated by gensyscalls.py. Do not edit.\n")
381 fp.write("syscall_src :=\n")
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700382 for sc in self.syscalls:
Elliott Hughesd6121652013-09-25 22:43:36 -0700383 if sc.has_key("asm-%s" % arch):
384 fp.write("syscall_src += arch-%s/syscalls/%s.S\n" % (arch, sc["func"]))
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700385 fp.close()
Elliott Hughesd6121652013-09-25 22:43:36 -0700386 self.other_files.append(path)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700387
Raghu Gandham1fa0d842012-01-27 17:51:42 -0800388
Elliott Hughesd6121652013-09-25 22:43:36 -0700389 # Write each syscall stub.
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700390 def gen_syscall_stubs(self):
391 for sc in self.syscalls:
Elliott Hughesd6121652013-09-25 22:43:36 -0700392 for arch in all_arches:
393 if sc.has_key("asm-%s" % arch):
394 filename = "arch-%s/syscalls/%s.S" % (arch, sc["func"])
395 D2(">>> generating " + filename)
396 fp = create_file(filename)
397 fp.write(sc["asm-%s" % arch])
398 fp.close()
399 self.new_stubs.append(filename)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700400
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700401
Elliott Hughesd6121652013-09-25 22:43:36 -0700402 def regenerate(self):
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400403 D("scanning for existing architecture-specific stub files...")
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700404
Elliott Hughes18bc9752013-06-17 10:26:10 -0700405 bionic_libc_root_len = len(bionic_libc_root)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700406
Elliott Hughesd6121652013-09-25 22:43:36 -0700407 for arch in all_arches:
Elliott Hughes18bc9752013-06-17 10:26:10 -0700408 arch_path = bionic_libc_root + "arch-" + arch
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400409 D("scanning " + arch_path)
410 files = glob.glob(arch_path + "/syscalls/*.S")
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700411 for f in files:
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400412 self.old_stubs.append(f[bionic_libc_root_len:])
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700413
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400414 D("found %d stub files" % len(self.old_stubs))
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700415
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400416 if not os.path.exists(bionic_temp):
417 D("creating %s..." % bionic_temp)
418 make_dir(bionic_temp)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700419
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400420 D("re-generating stubs and support files...")
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700421
Elliott Hughes1b91c6c2013-03-22 18:56:24 -0700422 self.gen_glibc_syscalls_h()
Elliott Hughesd6121652013-09-25 22:43:36 -0700423 for arch in all_arches:
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800424 self.gen_arch_syscalls_mk(arch)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700425 self.gen_syscall_stubs()
426
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400427 D("comparing files...")
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700428 adds = []
429 edits = []
430
431 for stub in self.new_stubs + self.other_files:
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400432 if not os.path.exists(bionic_libc_root + stub):
David 'Digit' Turnerfc269312010-10-11 22:11:06 +0200433 # new file, git add it
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400434 D("new file: " + stub)
435 adds.append(bionic_libc_root + stub)
436 shutil.copyfile(bionic_temp + stub, bionic_libc_root + stub)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700437
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400438 elif not filecmp.cmp(bionic_temp + stub, bionic_libc_root + stub):
439 D("changed file: " + stub)
440 edits.append(stub)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700441
442 deletes = []
443 for stub in self.old_stubs:
444 if not stub in self.new_stubs:
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400445 D("deleted file: " + stub)
446 deletes.append(bionic_libc_root + stub)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700447
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400448 if not DRY_RUN:
449 if adds:
450 commands.getoutput("git add " + " ".join(adds))
451 if deletes:
452 commands.getoutput("git rm " + " ".join(deletes))
453 if edits:
454 for file in edits:
455 shutil.copyfile(bionic_temp + file, bionic_libc_root + file)
456 commands.getoutput("git add " + " ".join((bionic_libc_root + file) for file in edits))
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700457
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400458 commands.getoutput("git add %s%s" % (bionic_libc_root,"SYSCALLS.TXT"))
David 'Digit' Turnerfc269312010-10-11 22:11:06 +0200459
460 if (not adds) and (not deletes) and (not edits):
461 D("no changes detected!")
462 else:
463 D("ready to go!!")
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700464
465D_setlevel(1)
466
467state = State()
Elliott Hughes18bc9752013-06-17 10:26:10 -0700468state.process_file(bionic_libc_root+"SYSCALLS.TXT")
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700469state.regenerate()