blob: d371b721d5570ad736a9fa35c5923c334d80f3b9 [file] [log] [blame]
Elliott Hughes6b586e72021-04-15 13:39:08 -07001#!/usr/bin/env python3
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 filecmp
9import glob
Elliott Hughes103ccde2013-10-16 14:27:59 -070010import re
11import shutil
12import stat
Elliott Hughesdc1fb702014-08-20 11:16:11 -070013import string
Elliott Hughes103ccde2013-10-16 14:27:59 -070014import sys
Christopher Ferris01bd32e2014-08-05 12:19:27 -070015import tempfile
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070016
Elliott Hughesdc1fb702014-08-20 11:16:11 -070017
Elliott Hughes704772b2022-10-10 17:06:43 +000018SupportedArchitectures = [ "arm", "arm64", "riscv64", "x86", "x86_64" ]
Elliott Hughesdc1fb702014-08-20 11:16:11 -070019
Elliott Hughesd67b0372019-04-15 14:18:26 -070020syscall_stub_header = \
Elliott Hughes103ccde2013-10-16 14:27:59 -070021"""
Elliott Hughes0437f3f2013-10-07 23:53:13 -070022ENTRY(%(func)s)
Pavel Chupinf12a18b2012-12-12 13:11:48 +040023"""
24
Elliott Hughes0437f3f2013-10-07 23:53:13 -070025
Elliott Hughes0437f3f2013-10-07 23:53:13 -070026#
27# ARM assembler templates for each syscall stub
28#
29
Elliott Hughes06b8f9c2025-02-10 15:30:11 -050030# ARM assembler template for a syscall stub needing 4 or fewer registers
Elliott Hughesb53e48f2024-06-26 18:07:30 +000031arm_call_default = syscall_stub_header + """\
Elliott Hughes0437f3f2013-10-07 23:53:13 -070032 mov ip, r7
Christopher Ferrisf5a91232016-04-27 18:31:02 -070033 .cfi_register r7, ip
Elliott Hughes0437f3f2013-10-07 23:53:13 -070034 ldr r7, =%(__NR_name)s
35 swi #0
36 mov r7, ip
Christopher Ferrisf5a91232016-04-27 18:31:02 -070037 .cfi_restore r7
Elliott Hughes0437f3f2013-10-07 23:53:13 -070038 cmn r0, #(MAX_ERRNO + 1)
39 bxls lr
40 neg r0, r0
Elliott Hughes011e1112014-09-08 15:25:01 -070041 b __set_errno_internal
Elliott Hughes0437f3f2013-10-07 23:53:13 -070042END(%(func)s)
43"""
44
Elliott Hughes06b8f9c2025-02-10 15:30:11 -050045# ARM assembler template for a syscall stub needing more than 4 registers
Elliott Hughesb53e48f2024-06-26 18:07:30 +000046arm_call_long = syscall_stub_header + """\
Elliott Hughes0437f3f2013-10-07 23:53:13 -070047 mov ip, sp
Elliott Hughes0437f3f2013-10-07 23:53:13 -070048 stmfd sp!, {r4, r5, r6, r7}
Christopher Ferrised459702013-12-02 17:44:53 -080049 .cfi_def_cfa_offset 16
50 .cfi_rel_offset r4, 0
51 .cfi_rel_offset r5, 4
52 .cfi_rel_offset r6, 8
53 .cfi_rel_offset r7, 12
Elliott Hughes0437f3f2013-10-07 23:53:13 -070054 ldmfd ip, {r4, r5, r6}
55 ldr r7, =%(__NR_name)s
56 swi #0
57 ldmfd sp!, {r4, r5, r6, r7}
Christopher Ferrised459702013-12-02 17:44:53 -080058 .cfi_def_cfa_offset 0
Elliott Hughes0437f3f2013-10-07 23:53:13 -070059 cmn r0, #(MAX_ERRNO + 1)
60 bxls lr
61 neg r0, r0
Elliott Hughes011e1112014-09-08 15:25:01 -070062 b __set_errno_internal
Elliott Hughes0437f3f2013-10-07 23:53:13 -070063END(%(func)s)
64"""
65
66
67#
Elliott Hughesd67b0372019-04-15 14:18:26 -070068# Arm64 assembler template for each syscall stub
Colin Crossd1973ca2014-01-21 19:50:58 -080069#
70
71arm64_call = syscall_stub_header + """\
Colin Crossd1973ca2014-01-21 19:50:58 -080072 mov x8, %(__NR_name)s
73 svc #0
74
Colin Crossd1973ca2014-01-21 19:50:58 -080075 cmn x0, #(MAX_ERRNO + 1)
76 cneg x0, x0, hi
Elliott Hughes011e1112014-09-08 15:25:01 -070077 b.hi __set_errno_internal
Colin Crossd1973ca2014-01-21 19:50:58 -080078
79 ret
80END(%(func)s)
81"""
82
83
84#
Elliott Hughes704772b2022-10-10 17:06:43 +000085# RISC-V64 assembler templates for each syscall stub
86#
87
88riscv64_call = syscall_stub_header + """\
89 li a7, %(__NR_name)s
90 ecall
91
92 li a7, -MAX_ERRNO
Mao Hand4e662e2023-05-11 14:52:40 +080093 bgeu a0, a7, 1f
Elliott Hughes704772b2022-10-10 17:06:43 +000094
95 ret
961:
97 neg a0, a0
caowenchengc42c7412023-03-09 09:16:34 +080098 tail __set_errno_internal
Elliott Hughes704772b2022-10-10 17:06:43 +000099END(%(func)s)
100"""
101
102#
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700103# x86 assembler templates for each syscall stub
104#
105
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800106x86_registers = [ "ebx", "ecx", "edx", "esi", "edi", "ebp" ]
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700107
Mingwei Shibe910522015-11-12 07:02:14 +0000108x86_call_prepare = """\
109
110 call __kernel_syscall
111 pushl %eax
112 .cfi_adjust_cfa_offset 4
113 .cfi_rel_offset eax, 0
114
115"""
116
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700117x86_call = """\
118 movl $%(__NR_name)s, %%eax
Mingwei Shibe910522015-11-12 07:02:14 +0000119 call *(%%esp)
120 addl $4, %%esp
121
Elliott Hughes9aceab52013-03-12 14:57:30 -0700122 cmpl $-MAX_ERRNO, %%eax
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700123 jb 1f
124 negl %%eax
125 pushl %%eax
Elliott Hughes011e1112014-09-08 15:25:01 -0700126 call __set_errno_internal
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700127 addl $4, %%esp
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -07001281:
129"""
130
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700131x86_return = """\
132 ret
133END(%(func)s)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700134"""
135
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700136
Elliott Hughescd6780b2013-02-07 14:07:00 -0800137#
Elliott Hughesd67b0372019-04-15 14:18:26 -0700138# x86_64 assembler template for each syscall stub
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400139#
140
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700141x86_64_call = """\
142 movl $%(__NR_name)s, %%eax
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400143 syscall
144 cmpq $-MAX_ERRNO, %%rax
145 jb 1f
146 negl %%eax
147 movl %%eax, %%edi
Elliott Hughes011e1112014-09-08 15:25:01 -0700148 call __set_errno_internal
Pavel Chupinf12a18b2012-12-12 13:11:48 +04001491:
150 ret
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700151END(%(func)s)
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400152"""
153
Raghu Gandham1fa0d842012-01-27 17:51:42 -0800154
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100155def param_uses_64bits(param):
156 """Returns True iff a syscall parameter description corresponds
157 to a 64-bit type."""
158 param = param.strip()
159 # First, check that the param type begins with one of the known
160 # 64-bit types.
161 if not ( \
162 param.startswith("int64_t") or param.startswith("uint64_t") or \
163 param.startswith("loff_t") or param.startswith("off64_t") or \
164 param.startswith("long long") or param.startswith("unsigned long long") or
165 param.startswith("signed long long") ):
166 return False
167
168 # Second, check that there is no pointer type here
169 if param.find("*") >= 0:
Elliott Hughes06b8f9c2025-02-10 15:30:11 -0500170 return False
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100171
172 # Ok
173 return True
174
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700175
Elliott Hughes06b8f9c2025-02-10 15:30:11 -0500176def count_param_registers_arm32(params):
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100177 """This function is used to count the number of register used
Elliott Hughescd6780b2013-02-07 14:07:00 -0800178 to pass parameters when invoking an ARM system call.
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100179 This is because the ARM EABI mandates that 64-bit quantities
180 must be passed in an even+odd register pair. So, for example,
181 something like:
182
183 foo(int fd, off64_t pos)
184
185 would actually need 4 registers:
186 r0 -> int
187 r1 -> unused
188 r2-r3 -> pos
189 """
190 count = 0
191 for param in params:
192 if param_uses_64bits(param):
193 if (count & 1) != 0:
194 count += 1
195 count += 2
196 else:
197 count += 1
198 return count
199
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700200
Elliott Hughes06b8f9c2025-02-10 15:30:11 -0500201def count_param_registers_x86(params):
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100202 count = 0
203 for param in params:
204 if param_uses_64bits(param):
205 count += 2
206 else:
207 count += 1
208 return count
209
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700210
Elliott Hughescda62092013-03-22 13:50:44 -0700211# This lets us support regular system calls like __NR_write and also weird
212# ones like __ARM_NR_cacheflush, where the NR doesn't come at the start.
213def make__NR_name(name):
Christopher Ferris01bd32e2014-08-05 12:19:27 -0700214 if name.startswith("__ARM_NR_"):
Elliott Hughescda62092013-03-22 13:50:44 -0700215 return name
216 else:
217 return "__NR_%s" % (name)
218
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700219
Elliott Hughesfff6e272013-10-24 17:03:20 -0700220def add_footer(pointer_length, stub, syscall):
221 # Add any aliases for this syscall.
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700222 aliases = syscall["aliases"]
223 for alias in aliases:
Christopher Ferrisfa5faa02015-03-24 16:50:46 -0700224 stub += "\nALIAS_SYMBOL(%s, %s)\n" % (alias, syscall["func"])
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700225 return stub
226
227
Elliott Hughesb53e48f2024-06-26 18:07:30 +0000228def arm_genstub(syscall):
Elliott Hughes06b8f9c2025-02-10 15:30:11 -0500229 num_regs = count_param_registers_arm32(syscall["params"])
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700230 if num_regs > 4:
Elliott Hughesb53e48f2024-06-26 18:07:30 +0000231 return arm_call_long % syscall
232 return arm_call_default % syscall
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700233
234
Colin Crossd1973ca2014-01-21 19:50:58 -0800235def arm64_genstub(syscall):
236 return arm64_call % syscall
237
238
Elliott Hughes704772b2022-10-10 17:06:43 +0000239def riscv64_genstub(syscall):
240 return riscv64_call % syscall
241
242
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700243def x86_genstub(syscall):
244 result = syscall_stub_header % syscall
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700245
Elliott Hughes06b8f9c2025-02-10 15:30:11 -0500246 numparams = count_param_registers_x86(syscall["params"])
Mingwei Shibe910522015-11-12 07:02:14 +0000247 stack_bias = numparams*4 + 8
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800248 offset = 0
249 mov_result = ""
Christopher Ferris15b91e92014-05-29 18:17:09 -0700250 first_push = True
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800251 for register in x86_registers[:numparams]:
252 result += " pushl %%%s\n" % register
Christopher Ferris15b91e92014-05-29 18:17:09 -0700253 if first_push:
254 result += " .cfi_def_cfa_offset 8\n"
255 result += " .cfi_rel_offset %s, 0\n" % register
256 first_push = False
257 else:
258 result += " .cfi_adjust_cfa_offset 4\n"
259 result += " .cfi_rel_offset %s, 0\n" % register
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800260 mov_result += " mov %d(%%esp), %%%s\n" % (stack_bias+offset, register)
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800261 offset += 4
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700262
Mingwei Shibe910522015-11-12 07:02:14 +0000263 result += x86_call_prepare
Christopher Ferris15b91e92014-05-29 18:17:09 -0700264 result += mov_result
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700265 result += x86_call % syscall
266
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800267 for register in reversed(x86_registers[:numparams]):
268 result += " popl %%%s\n" % register
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700269
270 result += x86_return % syscall
271 return result
272
Serban Constantinescufeaa89a2013-10-07 16:49:09 +0100273
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700274def x86_genstub_socketcall(syscall):
275 # %ebx <--- Argument 1 - The call id of the needed vectored
276 # syscall (socket, bind, recv, etc)
277 # %ecx <--- Argument 2 - Pointer to the rest of the arguments
278 # from the original function called (socket())
279
280 result = syscall_stub_header % syscall
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700281
282 # save the regs we need
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800283 result += " pushl %ebx\n"
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800284 result += " .cfi_def_cfa_offset 8\n"
285 result += " .cfi_rel_offset ebx, 0\n"
Christopher Ferris15b91e92014-05-29 18:17:09 -0700286 result += " pushl %ecx\n"
287 result += " .cfi_adjust_cfa_offset 4\n"
288 result += " .cfi_rel_offset ecx, 0\n"
Mingwei Shibe910522015-11-12 07:02:14 +0000289 stack_bias = 16
290
291 result += x86_call_prepare
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700292
293 # set the call id (%ebx)
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800294 result += " mov $%d, %%ebx\n" % syscall["socketcall_id"]
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700295
296 # set the pointer to the rest of the args into %ecx
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800297 result += " mov %esp, %ecx\n"
298 result += " addl $%d, %%ecx\n" % (stack_bias)
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700299
300 # now do the syscall code itself
301 result += x86_call % syscall
302
303 # now restore the saved regs
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800304 result += " popl %ecx\n"
305 result += " popl %ebx\n"
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700306
307 # epilog
308 result += x86_return % syscall
309 return result
310
311
312def x86_64_genstub(syscall):
313 result = syscall_stub_header % syscall
Elliott Hughes06b8f9c2025-02-10 15:30:11 -0500314 num_regs = len(syscall["params"])
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700315 if (num_regs > 3):
316 # rcx is used as 4th argument. Kernel wants it at r10.
317 result += " movq %rcx, %r10\n"
318
319 result += x86_64_call % syscall
320 return result
321
322
Elliott Hughesdc1fb702014-08-20 11:16:11 -0700323class SysCallsTxtParser:
324 def __init__(self):
325 self.syscalls = []
Elliott Hughes1c1dfb82022-11-08 02:57:55 +0000326 self.lineno = 0
327 self.errors = False
Elliott Hughesdc1fb702014-08-20 11:16:11 -0700328
329 def E(self, msg):
Elliott Hughesbc6999f2021-02-03 13:13:57 -0800330 print("%d: %s" % (self.lineno, msg))
Elliott Hughes1c1dfb82022-11-08 02:57:55 +0000331 self.errors = True
Elliott Hughesdc1fb702014-08-20 11:16:11 -0700332
333 def parse_line(self, line):
334 """ parse a syscall spec line.
335
Elliott Hughes6de2a8b2025-02-14 09:07:45 -0800336 format is one syscall per line:
337
338 func_name[|alias_list][:syscall_name[:socketcall_id]] ( [paramlist] ) architecture_list
339
340 with no line breaking/continuation allowed.
Elliott Hughesdc1fb702014-08-20 11:16:11 -0700341 """
342 pos_lparen = line.find('(')
343 E = self.E
344 if pos_lparen < 0:
345 E("missing left parenthesis in '%s'" % line)
346 return
347
348 pos_rparen = line.rfind(')')
349 if pos_rparen < 0 or pos_rparen <= pos_lparen:
350 E("missing or misplaced right parenthesis in '%s'" % line)
351 return
352
Elliott Hughes6de2a8b2025-02-14 09:07:45 -0800353 syscall_func = line[:pos_lparen]
Elliott Hughesdc1fb702014-08-20 11:16:11 -0700354 socketcall_id = -1
355
356 pos_colon = syscall_func.find(':')
357 if pos_colon < 0:
358 syscall_name = syscall_func
359 else:
360 if pos_colon == 0 or pos_colon+1 >= len(syscall_func):
361 E("misplaced colon in '%s'" % line)
362 return
363
364 # now find if there is a socketcall_id for a dispatch-type syscall
365 # after the optional 2nd colon
366 pos_colon2 = syscall_func.find(':', pos_colon + 1)
367 if pos_colon2 < 0:
368 syscall_name = syscall_func[pos_colon+1:]
369 syscall_func = syscall_func[:pos_colon]
370 else:
371 if pos_colon2+1 >= len(syscall_func):
372 E("misplaced colon2 in '%s'" % line)
373 return
374 syscall_name = syscall_func[(pos_colon+1):pos_colon2]
375 socketcall_id = int(syscall_func[pos_colon2+1:])
376 syscall_func = syscall_func[:pos_colon]
377
378 alias_delim = syscall_func.find('|')
379 if alias_delim > 0:
380 alias_list = syscall_func[alias_delim+1:].strip()
381 syscall_func = syscall_func[:alias_delim]
382 alias_delim = syscall_name.find('|')
383 if alias_delim > 0:
384 syscall_name = syscall_name[:alias_delim]
Elliott Hughesbc6999f2021-02-03 13:13:57 -0800385 syscall_aliases = alias_list.split(',')
Elliott Hughesdc1fb702014-08-20 11:16:11 -0700386 else:
387 syscall_aliases = []
388
389 if pos_rparen > pos_lparen+1:
390 syscall_params = line[pos_lparen+1:pos_rparen].split(',')
Elliott Hughesdc1fb702014-08-20 11:16:11 -0700391 else:
392 syscall_params = []
Elliott Hughesdc1fb702014-08-20 11:16:11 -0700393
394 t = {
395 "name" : syscall_name,
396 "func" : syscall_func,
397 "aliases" : syscall_aliases,
398 "params" : syscall_params,
Elliott Hughesdc1fb702014-08-20 11:16:11 -0700399 "socketcall_id" : socketcall_id
400 }
401
402 # Parse the architecture list.
403 arch_list = line[pos_rparen+1:].strip()
404 if arch_list == "all":
Elliott Hughesae03b122019-09-17 16:37:05 -0700405 for arch in SupportedArchitectures:
Elliott Hughesdc1fb702014-08-20 11:16:11 -0700406 t[arch] = True
407 else:
Elliott Hughesbc6999f2021-02-03 13:13:57 -0800408 for arch in arch_list.split(','):
Elliott Hughes2b499042020-02-13 14:21:55 -0800409 if arch == "lp32":
410 for arch in SupportedArchitectures:
411 if "64" not in arch:
412 t[arch] = True
413 elif arch == "lp64":
414 for arch in SupportedArchitectures:
415 if "64" in arch:
416 t[arch] = True
417 elif arch in SupportedArchitectures:
Elliott Hughesdc1fb702014-08-20 11:16:11 -0700418 t[arch] = True
419 else:
420 E("invalid syscall architecture '%s' in '%s'" % (arch, line))
421 return
422
423 self.syscalls.append(t)
424
Paul Lawrence7ea40902017-02-14 13:32:23 -0800425 def parse_open_file(self, fp):
426 for line in fp:
Elliott Hughesdc1fb702014-08-20 11:16:11 -0700427 self.lineno += 1
428 line = line.strip()
429 if not line: continue
430 if line[0] == '#': continue
431 self.parse_line(line)
Elliott Hughes1c1dfb82022-11-08 02:57:55 +0000432 if self.errors:
433 sys.exit(1)
Elliott Hughesdc1fb702014-08-20 11:16:11 -0700434
Paul Lawrence7ea40902017-02-14 13:32:23 -0800435 def parse_file(self, file_path):
Paul Lawrence7ea40902017-02-14 13:32:23 -0800436 with open(file_path) as fp:
Alessio Balsini93d4f8b2017-04-11 18:27:29 +0200437 self.parse_open_file(fp)
Elliott Hughesdc1fb702014-08-20 11:16:11 -0700438
439
John Catere86e5052019-09-26 14:47:03 -0400440def main(arch, syscall_file):
Elliott Hughes782c4852019-04-16 12:31:00 -0700441 parser = SysCallsTxtParser()
John Catere86e5052019-09-26 14:47:03 -0400442 parser.parse_file(syscall_file)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700443
Elliott Hughes782c4852019-04-16 12:31:00 -0700444 for syscall in parser.syscalls:
445 syscall["__NR_name"] = make__NR_name(syscall["name"])
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400446
Rupert Shuttleworthe99df592021-04-15 06:09:04 -0400447 if "arm" in syscall:
Elliott Hughesb53e48f2024-06-26 18:07:30 +0000448 syscall["asm-arm"] = add_footer(32, arm_genstub(syscall), syscall)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700449
Rupert Shuttleworthe99df592021-04-15 06:09:04 -0400450 if "arm64" in syscall:
Elliott Hughes782c4852019-04-16 12:31:00 -0700451 syscall["asm-arm64"] = add_footer(64, arm64_genstub(syscall), syscall)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700452
Elliott Hughes704772b2022-10-10 17:06:43 +0000453 if "riscv64" in syscall:
454 syscall["asm-riscv64"] = add_footer(64, riscv64_genstub(syscall), syscall)
455
Rupert Shuttleworthe99df592021-04-15 06:09:04 -0400456 if "x86" in syscall:
Elliott Hughes782c4852019-04-16 12:31:00 -0700457 if syscall["socketcall_id"] >= 0:
458 syscall["asm-x86"] = add_footer(32, x86_genstub_socketcall(syscall), syscall)
459 else:
460 syscall["asm-x86"] = add_footer(32, x86_genstub(syscall), syscall)
461 elif syscall["socketcall_id"] >= 0:
462 E("socketcall_id for dispatch syscalls is only supported for x86 in '%s'" % t)
463 return
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700464
Rupert Shuttleworthe99df592021-04-15 06:09:04 -0400465 if "x86_64" in syscall:
Elliott Hughes782c4852019-04-16 12:31:00 -0700466 syscall["asm-x86_64"] = add_footer(64, x86_64_genstub(syscall), syscall)
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800467
Elliott Hughes782c4852019-04-16 12:31:00 -0700468 print("/* Generated by gensyscalls.py. Do not edit. */\n")
469 print("#include <private/bionic_asm.h>\n")
470 for syscall in parser.syscalls:
Rupert Shuttleworthe99df592021-04-15 06:09:04 -0400471 if ("asm-%s" % arch) in syscall:
Elliott Hughes782c4852019-04-16 12:31:00 -0700472 print(syscall["asm-%s" % arch])
Chris Dearman50432122014-02-05 16:59:23 -0800473
Tamas Petz19d66e62019-12-03 17:18:43 +0100474 if arch == 'arm64':
475 print('\nNOTE_GNU_PROPERTY()\n')
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700476
Paul Lawrenceeabc3522016-11-11 11:33:42 -0800477if __name__ == "__main__":
John Catere86e5052019-09-26 14:47:03 -0400478 if len(sys.argv) < 2:
Elliott Hughesbc6999f2021-02-03 13:13:57 -0800479 print("Usage: gensyscalls.py ARCH SOURCE_FILE")
John Catere86e5052019-09-26 14:47:03 -0400480 sys.exit(1)
481
482 arch = sys.argv[1]
483 syscall_file = sys.argv[2]
484 main(arch, syscall_file)