blob: 9b6dc81227db92ed4732bb19e8bf3dc0da780ae0 [file] [log] [blame]
Stephen Crane77bb5642017-08-31 15:08:26 -07001#!/usr/bin/env 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
Christopher Ferris01bd32e2014-08-05 12:19:27 -07007import atexit
Elliott Hughes103ccde2013-10-16 14:27:59 -07008import commands
9import filecmp
10import glob
Elliott Hughesdc1fb702014-08-20 11:16:11 -070011import logging
Elliott Hughes103ccde2013-10-16 14:27:59 -070012import os.path
13import re
14import shutil
15import stat
Elliott Hughesdc1fb702014-08-20 11:16:11 -070016import string
Elliott Hughes103ccde2013-10-16 14:27:59 -070017import sys
Christopher Ferris01bd32e2014-08-05 12:19:27 -070018import tempfile
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070019
Elliott Hughesdc1fb702014-08-20 11:16:11 -070020
21all_arches = [ "arm", "arm64", "mips", "mips64", "x86", "x86_64" ]
22
Elliott Hughesd67b0372019-04-15 14:18:26 -070023bionic_libc = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070024
Elliott Hughesd67b0372019-04-15 14:18:26 -070025syscall_stub_header = \
Elliott Hughes103ccde2013-10-16 14:27:59 -070026"""
Elliott Hughes0437f3f2013-10-07 23:53:13 -070027ENTRY(%(func)s)
Pavel Chupinf12a18b2012-12-12 13:11:48 +040028"""
29
Elliott Hughes0437f3f2013-10-07 23:53:13 -070030
Elliott Hughes0437f3f2013-10-07 23:53:13 -070031#
32# ARM assembler templates for each syscall stub
33#
34
35arm_eabi_call_default = syscall_stub_header + """\
36 mov ip, r7
Christopher Ferrisf5a91232016-04-27 18:31:02 -070037 .cfi_register r7, ip
Elliott Hughes0437f3f2013-10-07 23:53:13 -070038 ldr r7, =%(__NR_name)s
39 swi #0
40 mov r7, ip
Christopher Ferrisf5a91232016-04-27 18:31:02 -070041 .cfi_restore r7
Elliott Hughes0437f3f2013-10-07 23:53:13 -070042 cmn r0, #(MAX_ERRNO + 1)
43 bxls lr
44 neg r0, r0
Elliott Hughes011e1112014-09-08 15:25:01 -070045 b __set_errno_internal
Elliott Hughes0437f3f2013-10-07 23:53:13 -070046END(%(func)s)
47"""
48
49arm_eabi_call_long = syscall_stub_header + """\
50 mov ip, sp
Elliott Hughes0437f3f2013-10-07 23:53:13 -070051 stmfd sp!, {r4, r5, r6, r7}
Christopher Ferrised459702013-12-02 17:44:53 -080052 .cfi_def_cfa_offset 16
53 .cfi_rel_offset r4, 0
54 .cfi_rel_offset r5, 4
55 .cfi_rel_offset r6, 8
56 .cfi_rel_offset r7, 12
Elliott Hughes0437f3f2013-10-07 23:53:13 -070057 ldmfd ip, {r4, r5, r6}
58 ldr r7, =%(__NR_name)s
59 swi #0
60 ldmfd sp!, {r4, r5, r6, r7}
Christopher Ferrised459702013-12-02 17:44:53 -080061 .cfi_def_cfa_offset 0
Elliott Hughes0437f3f2013-10-07 23:53:13 -070062 cmn r0, #(MAX_ERRNO + 1)
63 bxls lr
64 neg r0, r0
Elliott Hughes011e1112014-09-08 15:25:01 -070065 b __set_errno_internal
Elliott Hughes0437f3f2013-10-07 23:53:13 -070066END(%(func)s)
67"""
68
69
70#
Elliott Hughesd67b0372019-04-15 14:18:26 -070071# Arm64 assembler template for each syscall stub
Colin Crossd1973ca2014-01-21 19:50:58 -080072#
73
74arm64_call = syscall_stub_header + """\
Colin Crossd1973ca2014-01-21 19:50:58 -080075 mov x8, %(__NR_name)s
76 svc #0
77
Colin Crossd1973ca2014-01-21 19:50:58 -080078 cmn x0, #(MAX_ERRNO + 1)
79 cneg x0, x0, hi
Elliott Hughes011e1112014-09-08 15:25:01 -070080 b.hi __set_errno_internal
Colin Crossd1973ca2014-01-21 19:50:58 -080081
82 ret
83END(%(func)s)
84"""
85
86
87#
Elliott Hughesd67b0372019-04-15 14:18:26 -070088# MIPS assembler template for each syscall stub
Elliott Hughes0437f3f2013-10-07 23:53:13 -070089#
90
Elliott Hughes9abbbdc2014-02-19 14:54:31 -080091mips_call = syscall_stub_header + """\
Elliott Hughes0437f3f2013-10-07 23:53:13 -070092 .set noreorder
Elliott Hughesd4ca2312017-10-11 22:27:45 -070093 .cpload $t9
94 li $v0, %(__NR_name)s
Elliott Hughes0437f3f2013-10-07 23:53:13 -070095 syscall
Elliott Hughesd4ca2312017-10-11 22:27:45 -070096 bnez $a3, 1f
97 move $a0, $v0
98 j $ra
Elliott Hughes0437f3f2013-10-07 23:53:13 -070099 nop
1001:
Elliott Hughesd4ca2312017-10-11 22:27:45 -0700101 la $t9,__set_errno_internal
102 j $t9
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700103 nop
104 .set reorder
Elliott Hughes9abbbdc2014-02-19 14:54:31 -0800105END(%(func)s)
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700106"""
107
108
Elliott Hughescd6780b2013-02-07 14:07:00 -0800109#
Elliott Hughesd67b0372019-04-15 14:18:26 -0700110# MIPS64 assembler template for each syscall stub
Chris Dearman50432122014-02-05 16:59:23 -0800111#
112
Elliott Hughes9abbbdc2014-02-19 14:54:31 -0800113mips64_call = syscall_stub_header + """\
Chris Dearman50432122014-02-05 16:59:23 -0800114 .set push
115 .set noreorder
Elliott Hughesab413c52017-10-13 13:22:24 -0700116 li $v0, %(__NR_name)s
Chris Dearman50432122014-02-05 16:59:23 -0800117 syscall
Elliott Hughesab413c52017-10-13 13:22:24 -0700118 bnez $a3, 1f
119 move $a0, $v0
120 j $ra
Chris Dearman50432122014-02-05 16:59:23 -0800121 nop
1221:
Elliott Hughesab413c52017-10-13 13:22:24 -0700123 move $t0, $ra
124 bal 2f
Chris Dearman50432122014-02-05 16:59:23 -0800125 nop
1262:
Elliott Hughesab413c52017-10-13 13:22:24 -0700127 .cpsetup $ra, $t1, 2b
128 LA $t9, __set_errno_internal
Chris Dearman50432122014-02-05 16:59:23 -0800129 .cpreturn
Elliott Hughesab413c52017-10-13 13:22:24 -0700130 j $t9
131 move $ra, $t0
Chris Dearman50432122014-02-05 16:59:23 -0800132 .set pop
Elliott Hughes9abbbdc2014-02-19 14:54:31 -0800133END(%(func)s)
Chris Dearman50432122014-02-05 16:59:23 -0800134"""
135
136
137#
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700138# x86 assembler templates for each syscall stub
139#
140
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800141x86_registers = [ "ebx", "ecx", "edx", "esi", "edi", "ebp" ]
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700142
Mingwei Shibe910522015-11-12 07:02:14 +0000143x86_call_prepare = """\
144
145 call __kernel_syscall
146 pushl %eax
147 .cfi_adjust_cfa_offset 4
148 .cfi_rel_offset eax, 0
149
150"""
151
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700152x86_call = """\
153 movl $%(__NR_name)s, %%eax
Mingwei Shibe910522015-11-12 07:02:14 +0000154 call *(%%esp)
155 addl $4, %%esp
156
Elliott Hughes9aceab52013-03-12 14:57:30 -0700157 cmpl $-MAX_ERRNO, %%eax
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700158 jb 1f
159 negl %%eax
160 pushl %%eax
Elliott Hughes011e1112014-09-08 15:25:01 -0700161 call __set_errno_internal
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700162 addl $4, %%esp
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -07001631:
164"""
165
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700166x86_return = """\
167 ret
168END(%(func)s)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700169"""
170
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700171
Elliott Hughescd6780b2013-02-07 14:07:00 -0800172#
Elliott Hughesd67b0372019-04-15 14:18:26 -0700173# x86_64 assembler template for each syscall stub
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400174#
175
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700176x86_64_call = """\
177 movl $%(__NR_name)s, %%eax
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400178 syscall
179 cmpq $-MAX_ERRNO, %%rax
180 jb 1f
181 negl %%eax
182 movl %%eax, %%edi
Elliott Hughes011e1112014-09-08 15:25:01 -0700183 call __set_errno_internal
Pavel Chupinf12a18b2012-12-12 13:11:48 +04001841:
185 ret
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700186END(%(func)s)
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400187"""
188
Raghu Gandham1fa0d842012-01-27 17:51:42 -0800189
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100190def param_uses_64bits(param):
191 """Returns True iff a syscall parameter description corresponds
192 to a 64-bit type."""
193 param = param.strip()
194 # First, check that the param type begins with one of the known
195 # 64-bit types.
196 if not ( \
197 param.startswith("int64_t") or param.startswith("uint64_t") or \
198 param.startswith("loff_t") or param.startswith("off64_t") or \
199 param.startswith("long long") or param.startswith("unsigned long long") or
200 param.startswith("signed long long") ):
201 return False
202
203 # Second, check that there is no pointer type here
204 if param.find("*") >= 0:
205 return False
206
207 # Ok
208 return True
209
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700210
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100211def count_arm_param_registers(params):
212 """This function is used to count the number of register used
Elliott Hughescd6780b2013-02-07 14:07:00 -0800213 to pass parameters when invoking an ARM system call.
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100214 This is because the ARM EABI mandates that 64-bit quantities
215 must be passed in an even+odd register pair. So, for example,
216 something like:
217
218 foo(int fd, off64_t pos)
219
220 would actually need 4 registers:
221 r0 -> int
222 r1 -> unused
223 r2-r3 -> pos
224 """
225 count = 0
226 for param in params:
227 if param_uses_64bits(param):
228 if (count & 1) != 0:
229 count += 1
230 count += 2
231 else:
232 count += 1
233 return count
234
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700235
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100236def count_generic_param_registers(params):
237 count = 0
238 for param in params:
239 if param_uses_64bits(param):
240 count += 2
241 else:
242 count += 1
243 return count
244
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700245
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400246def count_generic_param_registers64(params):
247 count = 0
248 for param in params:
249 count += 1
250 return count
251
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700252
Elliott Hughescda62092013-03-22 13:50:44 -0700253# This lets us support regular system calls like __NR_write and also weird
254# ones like __ARM_NR_cacheflush, where the NR doesn't come at the start.
255def make__NR_name(name):
Christopher Ferris01bd32e2014-08-05 12:19:27 -0700256 if name.startswith("__ARM_NR_"):
Elliott Hughescda62092013-03-22 13:50:44 -0700257 return name
258 else:
259 return "__NR_%s" % (name)
260
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700261
Elliott Hughesfff6e272013-10-24 17:03:20 -0700262def add_footer(pointer_length, stub, syscall):
263 # Add any aliases for this syscall.
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700264 aliases = syscall["aliases"]
265 for alias in aliases:
Christopher Ferrisfa5faa02015-03-24 16:50:46 -0700266 stub += "\nALIAS_SYMBOL(%s, %s)\n" % (alias, syscall["func"])
Elliott Hughesfff6e272013-10-24 17:03:20 -0700267
Nick Kralevich00490ae2015-02-03 11:27:25 -0800268 # Use hidden visibility on LP64 for any functions beginning with underscores.
269 # Force hidden visibility for any functions which begin with 3 underscores
270 if (pointer_length == 64 and syscall["func"].startswith("__")) or syscall["func"].startswith("___"):
Elliott Hughesd465eb42014-02-19 18:59:19 -0800271 stub += '.hidden ' + syscall["func"] + '\n'
Elliott Hughesfff6e272013-10-24 17:03:20 -0700272
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700273 return stub
274
275
276def 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
Colin Crossd1973ca2014-01-21 19:50:58 -0800283def arm64_genstub(syscall):
284 return arm64_call % syscall
285
286
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700287def mips_genstub(syscall):
288 return mips_call % syscall
289
290
Chris Dearman50432122014-02-05 16:59:23 -0800291def mips64_genstub(syscall):
292 return mips64_call % syscall
293
294
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700295def x86_genstub(syscall):
296 result = syscall_stub_header % syscall
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700297
298 numparams = count_generic_param_registers(syscall["params"])
Mingwei Shibe910522015-11-12 07:02:14 +0000299 stack_bias = numparams*4 + 8
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800300 offset = 0
301 mov_result = ""
Christopher Ferris15b91e92014-05-29 18:17:09 -0700302 first_push = True
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800303 for register in x86_registers[:numparams]:
304 result += " pushl %%%s\n" % register
Christopher Ferris15b91e92014-05-29 18:17:09 -0700305 if first_push:
306 result += " .cfi_def_cfa_offset 8\n"
307 result += " .cfi_rel_offset %s, 0\n" % register
308 first_push = False
309 else:
310 result += " .cfi_adjust_cfa_offset 4\n"
311 result += " .cfi_rel_offset %s, 0\n" % register
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800312 mov_result += " mov %d(%%esp), %%%s\n" % (stack_bias+offset, register)
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800313 offset += 4
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700314
Mingwei Shibe910522015-11-12 07:02:14 +0000315 result += x86_call_prepare
Christopher Ferris15b91e92014-05-29 18:17:09 -0700316 result += mov_result
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700317 result += x86_call % syscall
318
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800319 for register in reversed(x86_registers[:numparams]):
320 result += " popl %%%s\n" % register
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700321
322 result += x86_return % syscall
323 return result
324
Serban Constantinescufeaa89a2013-10-07 16:49:09 +0100325
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700326def x86_genstub_socketcall(syscall):
327 # %ebx <--- Argument 1 - The call id of the needed vectored
328 # syscall (socket, bind, recv, etc)
329 # %ecx <--- Argument 2 - Pointer to the rest of the arguments
330 # from the original function called (socket())
331
332 result = syscall_stub_header % syscall
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700333
334 # save the regs we need
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800335 result += " pushl %ebx\n"
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800336 result += " .cfi_def_cfa_offset 8\n"
337 result += " .cfi_rel_offset ebx, 0\n"
Christopher Ferris15b91e92014-05-29 18:17:09 -0700338 result += " pushl %ecx\n"
339 result += " .cfi_adjust_cfa_offset 4\n"
340 result += " .cfi_rel_offset ecx, 0\n"
Mingwei Shibe910522015-11-12 07:02:14 +0000341 stack_bias = 16
342
343 result += x86_call_prepare
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700344
345 # set the call id (%ebx)
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800346 result += " mov $%d, %%ebx\n" % syscall["socketcall_id"]
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700347
348 # set the pointer to the rest of the args into %ecx
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800349 result += " mov %esp, %ecx\n"
350 result += " addl $%d, %%ecx\n" % (stack_bias)
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700351
352 # now do the syscall code itself
353 result += x86_call % syscall
354
355 # now restore the saved regs
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800356 result += " popl %ecx\n"
357 result += " popl %ebx\n"
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700358
359 # epilog
360 result += x86_return % syscall
361 return result
362
363
364def x86_64_genstub(syscall):
365 result = syscall_stub_header % syscall
366 num_regs = count_generic_param_registers64(syscall["params"])
367 if (num_regs > 3):
368 # rcx is used as 4th argument. Kernel wants it at r10.
369 result += " movq %rcx, %r10\n"
370
371 result += x86_64_call % syscall
372 return result
373
374
Elliott Hughesdc1fb702014-08-20 11:16:11 -0700375class SysCallsTxtParser:
376 def __init__(self):
377 self.syscalls = []
378 self.lineno = 0
379
380 def E(self, msg):
381 print "%d: %s" % (self.lineno, msg)
382
383 def parse_line(self, line):
384 """ parse a syscall spec line.
385
386 line processing, format is
387 return type func_name[|alias_list][:syscall_name[:socketcall_id]] ( [paramlist] ) architecture_list
388 """
389 pos_lparen = line.find('(')
390 E = self.E
391 if pos_lparen < 0:
392 E("missing left parenthesis in '%s'" % line)
393 return
394
395 pos_rparen = line.rfind(')')
396 if pos_rparen < 0 or pos_rparen <= pos_lparen:
397 E("missing or misplaced right parenthesis in '%s'" % line)
398 return
399
400 return_type = line[:pos_lparen].strip().split()
401 if len(return_type) < 2:
402 E("missing return type in '%s'" % line)
403 return
404
405 syscall_func = return_type[-1]
406 return_type = string.join(return_type[:-1],' ')
407 socketcall_id = -1
408
409 pos_colon = syscall_func.find(':')
410 if pos_colon < 0:
411 syscall_name = syscall_func
412 else:
413 if pos_colon == 0 or pos_colon+1 >= len(syscall_func):
414 E("misplaced colon in '%s'" % line)
415 return
416
417 # now find if there is a socketcall_id for a dispatch-type syscall
418 # after the optional 2nd colon
419 pos_colon2 = syscall_func.find(':', pos_colon + 1)
420 if pos_colon2 < 0:
421 syscall_name = syscall_func[pos_colon+1:]
422 syscall_func = syscall_func[:pos_colon]
423 else:
424 if pos_colon2+1 >= len(syscall_func):
425 E("misplaced colon2 in '%s'" % line)
426 return
427 syscall_name = syscall_func[(pos_colon+1):pos_colon2]
428 socketcall_id = int(syscall_func[pos_colon2+1:])
429 syscall_func = syscall_func[:pos_colon]
430
431 alias_delim = syscall_func.find('|')
432 if alias_delim > 0:
433 alias_list = syscall_func[alias_delim+1:].strip()
434 syscall_func = syscall_func[:alias_delim]
435 alias_delim = syscall_name.find('|')
436 if alias_delim > 0:
437 syscall_name = syscall_name[:alias_delim]
438 syscall_aliases = string.split(alias_list, ',')
439 else:
440 syscall_aliases = []
441
442 if pos_rparen > pos_lparen+1:
443 syscall_params = line[pos_lparen+1:pos_rparen].split(',')
444 params = string.join(syscall_params,',')
445 else:
446 syscall_params = []
447 params = "void"
448
449 t = {
450 "name" : syscall_name,
451 "func" : syscall_func,
452 "aliases" : syscall_aliases,
453 "params" : syscall_params,
454 "decl" : "%-15s %s (%s);" % (return_type, syscall_func, params),
455 "socketcall_id" : socketcall_id
456 }
457
458 # Parse the architecture list.
459 arch_list = line[pos_rparen+1:].strip()
460 if arch_list == "all":
461 for arch in all_arches:
462 t[arch] = True
Elliott Hughes8251d442018-11-09 13:55:21 -0800463 elif arch_list == "lp32":
464 for arch in all_arches:
465 if "64" not in arch:
466 t[arch] = True
467 elif arch_list == "lp64":
468 for arch in all_arches:
469 if "64" in arch:
470 t[arch] = True
Elliott Hughesdc1fb702014-08-20 11:16:11 -0700471 else:
472 for arch in string.split(arch_list, ','):
473 if arch in all_arches:
474 t[arch] = True
475 else:
476 E("invalid syscall architecture '%s' in '%s'" % (arch, line))
477 return
478
479 self.syscalls.append(t)
480
481 logging.debug(t)
482
Paul Lawrence7ea40902017-02-14 13:32:23 -0800483 def parse_open_file(self, fp):
484 for line in fp:
Elliott Hughesdc1fb702014-08-20 11:16:11 -0700485 self.lineno += 1
486 line = line.strip()
487 if not line: continue
488 if line[0] == '#': continue
489 self.parse_line(line)
490
Paul Lawrence7ea40902017-02-14 13:32:23 -0800491 def parse_file(self, file_path):
492 logging.debug("parse_file: %s" % file_path)
493 with open(file_path) as fp:
Alessio Balsini93d4f8b2017-04-11 18:27:29 +0200494 self.parse_open_file(fp)
Elliott Hughesdc1fb702014-08-20 11:16:11 -0700495
496
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700497class State:
498 def __init__(self):
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700499 self.syscalls = []
500
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400501
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700502 def process_file(self, input):
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700503 parser = SysCallsTxtParser()
504 parser.parse_file(input)
505 self.syscalls = parser.syscalls
506 parser = None
507
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700508 for syscall in self.syscalls:
509 syscall["__NR_name"] = make__NR_name(syscall["name"])
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700510
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700511 if syscall.has_key("arm"):
Elliott Hughesfff6e272013-10-24 17:03:20 -0700512 syscall["asm-arm"] = add_footer(32, arm_eabi_genstub(syscall), syscall)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700513
Colin Crossd1973ca2014-01-21 19:50:58 -0800514 if syscall.has_key("arm64"):
515 syscall["asm-arm64"] = add_footer(64, arm64_genstub(syscall), syscall)
516
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700517 if syscall.has_key("x86"):
518 if syscall["socketcall_id"] >= 0:
Elliott Hughesfff6e272013-10-24 17:03:20 -0700519 syscall["asm-x86"] = add_footer(32, x86_genstub_socketcall(syscall), syscall)
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800520 else:
Elliott Hughesfff6e272013-10-24 17:03:20 -0700521 syscall["asm-x86"] = add_footer(32, x86_genstub(syscall), syscall)
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700522 elif syscall["socketcall_id"] >= 0:
Elliott Hughesd6121652013-09-25 22:43:36 -0700523 E("socketcall_id for dispatch syscalls is only supported for x86 in '%s'" % t)
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800524 return
Elliott Hughescd6780b2013-02-07 14:07:00 -0800525
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700526 if syscall.has_key("mips"):
Elliott Hughesfff6e272013-10-24 17:03:20 -0700527 syscall["asm-mips"] = add_footer(32, mips_genstub(syscall), syscall)
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800528
Chris Dearman50432122014-02-05 16:59:23 -0800529 if syscall.has_key("mips64"):
530 syscall["asm-mips64"] = add_footer(64, mips64_genstub(syscall), syscall)
531
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700532 if syscall.has_key("x86_64"):
Elliott Hughesfff6e272013-10-24 17:03:20 -0700533 syscall["asm-x86_64"] = add_footer(64, x86_64_genstub(syscall), syscall)
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700534
Elliott Hughesd2f725e2016-07-15 15:47:47 -0700535
Elliott Hughesd6121652013-09-25 22:43:36 -0700536 def regenerate(self):
Elliott Hughesd6121652013-09-25 22:43:36 -0700537 for arch in all_arches:
Elliott Hughesd67b0372019-04-15 14:18:26 -0700538 filename = '%s/arch-%s/syscalls.S' % (bionic_libc, arch)
539 fp = open(filename, 'w')
540 fp.write("/* Generated by gensyscalls.py. Do not edit. */\n")
541 fp.write("#include <private/bionic_asm.h>\n")
542 for syscall in self.syscalls:
543 if syscall.has_key("asm-%s" % arch):
544 fp.write(syscall["asm-%s" % arch])
545 fp.close()
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700546
Elliott Hughesdc1fb702014-08-20 11:16:11 -0700547logging.basicConfig(level=logging.INFO)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700548
Paul Lawrenceeabc3522016-11-11 11:33:42 -0800549if __name__ == "__main__":
550 state = State()
Elliott Hughesd67b0372019-04-15 14:18:26 -0700551 state.process_file(os.path.join(bionic_libc, "SYSCALLS.TXT"))
Paul Lawrenceeabc3522016-11-11 11:33:42 -0800552 state.regenerate()