The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | #!/usr/bin/python |
Pavel Chupin | f12a18b | 2012-12-12 13:11:48 +0400 | [diff] [blame] | 2 | |
| 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 Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 6 | |
Christopher Ferris | 01bd32e | 2014-08-05 12:19:27 -0700 | [diff] [blame] | 7 | import atexit |
Elliott Hughes | 103ccde | 2013-10-16 14:27:59 -0700 | [diff] [blame] | 8 | import commands |
| 9 | import filecmp |
| 10 | import glob |
Elliott Hughes | dc1fb70 | 2014-08-20 11:16:11 -0700 | [diff] [blame] | 11 | import logging |
Elliott Hughes | 103ccde | 2013-10-16 14:27:59 -0700 | [diff] [blame] | 12 | import os.path |
| 13 | import re |
| 14 | import shutil |
| 15 | import stat |
Elliott Hughes | dc1fb70 | 2014-08-20 11:16:11 -0700 | [diff] [blame] | 16 | import string |
Elliott Hughes | 103ccde | 2013-10-16 14:27:59 -0700 | [diff] [blame] | 17 | import sys |
Christopher Ferris | 01bd32e | 2014-08-05 12:19:27 -0700 | [diff] [blame] | 18 | import tempfile |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 19 | |
Elliott Hughes | dc1fb70 | 2014-08-20 11:16:11 -0700 | [diff] [blame] | 20 | |
| 21 | all_arches = [ "arm", "arm64", "mips", "mips64", "x86", "x86_64" ] |
| 22 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 23 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 24 | # temp directory where we store all intermediate files |
Christopher Ferris | 01bd32e | 2014-08-05 12:19:27 -0700 | [diff] [blame] | 25 | bionic_temp = tempfile.mkdtemp(prefix="bionic_gensyscalls"); |
| 26 | # Make sure the directory is deleted when the script exits. |
| 27 | atexit.register(shutil.rmtree, bionic_temp) |
| 28 | |
| 29 | bionic_libc_root = os.path.join(os.environ["ANDROID_BUILD_TOP"], "bionic/libc") |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 30 | |
Elliott Hughes | 103ccde | 2013-10-16 14:27:59 -0700 | [diff] [blame] | 31 | warning = "Generated by gensyscalls.py. Do not edit." |
| 32 | |
Pavel Chupin | f12a18b | 2012-12-12 13:11:48 +0400 | [diff] [blame] | 33 | DRY_RUN = False |
| 34 | |
| 35 | def make_dir(path): |
Raghu Gandham | 1fa0d84 | 2012-01-27 17:51:42 -0800 | [diff] [blame] | 36 | path = os.path.abspath(path) |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 37 | if not os.path.exists(path): |
| 38 | parent = os.path.dirname(path) |
| 39 | if parent: |
| 40 | make_dir(parent) |
| 41 | os.mkdir(path) |
| 42 | |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 43 | |
Pavel Chupin | f12a18b | 2012-12-12 13:11:48 +0400 | [diff] [blame] | 44 | def create_file(relpath): |
Christopher Ferris | 01bd32e | 2014-08-05 12:19:27 -0700 | [diff] [blame] | 45 | full_path = os.path.join(bionic_temp, relpath) |
| 46 | dir = os.path.dirname(full_path) |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 47 | make_dir(dir) |
Christopher Ferris | 01bd32e | 2014-08-05 12:19:27 -0700 | [diff] [blame] | 48 | return open(full_path, "w") |
Pavel Chupin | f12a18b | 2012-12-12 13:11:48 +0400 | [diff] [blame] | 49 | |
| 50 | |
Elliott Hughes | 103ccde | 2013-10-16 14:27:59 -0700 | [diff] [blame] | 51 | syscall_stub_header = "/* " + warning + " */\n" + \ |
| 52 | """ |
Elliott Hughes | ed74484 | 2013-11-07 10:31:05 -0800 | [diff] [blame] | 53 | #include <private/bionic_asm.h> |
Pavel Chupin | f12a18b | 2012-12-12 13:11:48 +0400 | [diff] [blame] | 54 | |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 55 | ENTRY(%(func)s) |
Pavel Chupin | f12a18b | 2012-12-12 13:11:48 +0400 | [diff] [blame] | 56 | """ |
| 57 | |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 58 | |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 59 | # |
| 60 | # ARM assembler templates for each syscall stub |
| 61 | # |
| 62 | |
| 63 | arm_eabi_call_default = syscall_stub_header + """\ |
| 64 | mov ip, r7 |
Christopher Ferris | f5a9123 | 2016-04-27 18:31:02 -0700 | [diff] [blame] | 65 | .cfi_register r7, ip |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 66 | ldr r7, =%(__NR_name)s |
| 67 | swi #0 |
| 68 | mov r7, ip |
Christopher Ferris | f5a9123 | 2016-04-27 18:31:02 -0700 | [diff] [blame] | 69 | .cfi_restore r7 |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 70 | cmn r0, #(MAX_ERRNO + 1) |
| 71 | bxls lr |
| 72 | neg r0, r0 |
Elliott Hughes | 011e111 | 2014-09-08 15:25:01 -0700 | [diff] [blame] | 73 | b __set_errno_internal |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 74 | END(%(func)s) |
| 75 | """ |
| 76 | |
| 77 | arm_eabi_call_long = syscall_stub_header + """\ |
| 78 | mov ip, sp |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 79 | stmfd sp!, {r4, r5, r6, r7} |
Christopher Ferris | ed45970 | 2013-12-02 17:44:53 -0800 | [diff] [blame] | 80 | .cfi_def_cfa_offset 16 |
| 81 | .cfi_rel_offset r4, 0 |
| 82 | .cfi_rel_offset r5, 4 |
| 83 | .cfi_rel_offset r6, 8 |
| 84 | .cfi_rel_offset r7, 12 |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 85 | ldmfd ip, {r4, r5, r6} |
| 86 | ldr r7, =%(__NR_name)s |
| 87 | swi #0 |
| 88 | ldmfd sp!, {r4, r5, r6, r7} |
Christopher Ferris | ed45970 | 2013-12-02 17:44:53 -0800 | [diff] [blame] | 89 | .cfi_def_cfa_offset 0 |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 90 | cmn r0, #(MAX_ERRNO + 1) |
| 91 | bxls lr |
| 92 | neg r0, r0 |
Elliott Hughes | 011e111 | 2014-09-08 15:25:01 -0700 | [diff] [blame] | 93 | b __set_errno_internal |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 94 | END(%(func)s) |
| 95 | """ |
| 96 | |
| 97 | |
| 98 | # |
Colin Cross | d1973ca | 2014-01-21 19:50:58 -0800 | [diff] [blame] | 99 | # Arm64 assembler templates for each syscall stub |
| 100 | # |
| 101 | |
| 102 | arm64_call = syscall_stub_header + """\ |
Colin Cross | d1973ca | 2014-01-21 19:50:58 -0800 | [diff] [blame] | 103 | mov x8, %(__NR_name)s |
| 104 | svc #0 |
| 105 | |
Colin Cross | d1973ca | 2014-01-21 19:50:58 -0800 | [diff] [blame] | 106 | cmn x0, #(MAX_ERRNO + 1) |
| 107 | cneg x0, x0, hi |
Elliott Hughes | 011e111 | 2014-09-08 15:25:01 -0700 | [diff] [blame] | 108 | b.hi __set_errno_internal |
Colin Cross | d1973ca | 2014-01-21 19:50:58 -0800 | [diff] [blame] | 109 | |
| 110 | ret |
| 111 | END(%(func)s) |
| 112 | """ |
| 113 | |
| 114 | |
| 115 | # |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 116 | # MIPS assembler templates for each syscall stub |
| 117 | # |
| 118 | |
Elliott Hughes | 9abbbdc | 2014-02-19 14:54:31 -0800 | [diff] [blame] | 119 | mips_call = syscall_stub_header + """\ |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 120 | .set noreorder |
Elliott Hughes | eae27dc | 2014-02-19 12:20:00 -0800 | [diff] [blame] | 121 | .cpload t9 |
| 122 | li v0, %(__NR_name)s |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 123 | syscall |
Elliott Hughes | eae27dc | 2014-02-19 12:20:00 -0800 | [diff] [blame] | 124 | bnez a3, 1f |
| 125 | move a0, v0 |
| 126 | j ra |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 127 | nop |
| 128 | 1: |
Elliott Hughes | 011e111 | 2014-09-08 15:25:01 -0700 | [diff] [blame] | 129 | la t9,__set_errno_internal |
Elliott Hughes | eae27dc | 2014-02-19 12:20:00 -0800 | [diff] [blame] | 130 | j t9 |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 131 | nop |
| 132 | .set reorder |
Elliott Hughes | 9abbbdc | 2014-02-19 14:54:31 -0800 | [diff] [blame] | 133 | END(%(func)s) |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 134 | """ |
| 135 | |
| 136 | |
Elliott Hughes | cd6780b | 2013-02-07 14:07:00 -0800 | [diff] [blame] | 137 | # |
Chris Dearman | 5043212 | 2014-02-05 16:59:23 -0800 | [diff] [blame] | 138 | # MIPS64 assembler templates for each syscall stub |
| 139 | # |
| 140 | |
Elliott Hughes | 9abbbdc | 2014-02-19 14:54:31 -0800 | [diff] [blame] | 141 | mips64_call = syscall_stub_header + """\ |
Chris Dearman | 5043212 | 2014-02-05 16:59:23 -0800 | [diff] [blame] | 142 | .set push |
| 143 | .set noreorder |
| 144 | li v0, %(__NR_name)s |
| 145 | syscall |
| 146 | bnez a3, 1f |
| 147 | move a0, v0 |
| 148 | j ra |
| 149 | nop |
| 150 | 1: |
| 151 | move t0, ra |
| 152 | bal 2f |
| 153 | nop |
| 154 | 2: |
| 155 | .cpsetup ra, t1, 2b |
Elliott Hughes | 011e111 | 2014-09-08 15:25:01 -0700 | [diff] [blame] | 156 | LA t9,__set_errno_internal |
Chris Dearman | 5043212 | 2014-02-05 16:59:23 -0800 | [diff] [blame] | 157 | .cpreturn |
| 158 | j t9 |
| 159 | move ra, t0 |
| 160 | .set pop |
Elliott Hughes | 9abbbdc | 2014-02-19 14:54:31 -0800 | [diff] [blame] | 161 | END(%(func)s) |
Chris Dearman | 5043212 | 2014-02-05 16:59:23 -0800 | [diff] [blame] | 162 | """ |
| 163 | |
| 164 | |
| 165 | # |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 166 | # x86 assembler templates for each syscall stub |
| 167 | # |
| 168 | |
Christopher Ferris | e4bc756 | 2014-01-06 16:39:10 -0800 | [diff] [blame] | 169 | x86_registers = [ "ebx", "ecx", "edx", "esi", "edi", "ebp" ] |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 170 | |
Mingwei Shi | be91052 | 2015-11-12 07:02:14 +0000 | [diff] [blame] | 171 | x86_call_prepare = """\ |
| 172 | |
| 173 | call __kernel_syscall |
| 174 | pushl %eax |
| 175 | .cfi_adjust_cfa_offset 4 |
| 176 | .cfi_rel_offset eax, 0 |
| 177 | |
| 178 | """ |
| 179 | |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 180 | x86_call = """\ |
| 181 | movl $%(__NR_name)s, %%eax |
Mingwei Shi | be91052 | 2015-11-12 07:02:14 +0000 | [diff] [blame] | 182 | call *(%%esp) |
| 183 | addl $4, %%esp |
| 184 | |
Elliott Hughes | 9aceab5 | 2013-03-12 14:57:30 -0700 | [diff] [blame] | 185 | cmpl $-MAX_ERRNO, %%eax |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 186 | jb 1f |
| 187 | negl %%eax |
| 188 | pushl %%eax |
Elliott Hughes | 011e111 | 2014-09-08 15:25:01 -0700 | [diff] [blame] | 189 | call __set_errno_internal |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 190 | addl $4, %%esp |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 191 | 1: |
| 192 | """ |
| 193 | |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 194 | x86_return = """\ |
| 195 | ret |
| 196 | END(%(func)s) |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 197 | """ |
| 198 | |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 199 | |
Elliott Hughes | cd6780b | 2013-02-07 14:07:00 -0800 | [diff] [blame] | 200 | # |
Pavel Chupin | f12a18b | 2012-12-12 13:11:48 +0400 | [diff] [blame] | 201 | # x86_64 assembler templates for each syscall stub |
| 202 | # |
| 203 | |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 204 | x86_64_call = """\ |
| 205 | movl $%(__NR_name)s, %%eax |
Pavel Chupin | f12a18b | 2012-12-12 13:11:48 +0400 | [diff] [blame] | 206 | syscall |
| 207 | cmpq $-MAX_ERRNO, %%rax |
| 208 | jb 1f |
| 209 | negl %%eax |
| 210 | movl %%eax, %%edi |
Elliott Hughes | 011e111 | 2014-09-08 15:25:01 -0700 | [diff] [blame] | 211 | call __set_errno_internal |
Pavel Chupin | f12a18b | 2012-12-12 13:11:48 +0400 | [diff] [blame] | 212 | 1: |
| 213 | ret |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 214 | END(%(func)s) |
Pavel Chupin | f12a18b | 2012-12-12 13:11:48 +0400 | [diff] [blame] | 215 | """ |
| 216 | |
Raghu Gandham | 1fa0d84 | 2012-01-27 17:51:42 -0800 | [diff] [blame] | 217 | |
David 'Digit' Turner | 95d751f | 2010-12-16 16:47:14 +0100 | [diff] [blame] | 218 | def param_uses_64bits(param): |
| 219 | """Returns True iff a syscall parameter description corresponds |
| 220 | to a 64-bit type.""" |
| 221 | param = param.strip() |
| 222 | # First, check that the param type begins with one of the known |
| 223 | # 64-bit types. |
| 224 | if not ( \ |
| 225 | param.startswith("int64_t") or param.startswith("uint64_t") or \ |
| 226 | param.startswith("loff_t") or param.startswith("off64_t") or \ |
| 227 | param.startswith("long long") or param.startswith("unsigned long long") or |
| 228 | param.startswith("signed long long") ): |
| 229 | return False |
| 230 | |
| 231 | # Second, check that there is no pointer type here |
| 232 | if param.find("*") >= 0: |
| 233 | return False |
| 234 | |
| 235 | # Ok |
| 236 | return True |
| 237 | |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 238 | |
David 'Digit' Turner | 95d751f | 2010-12-16 16:47:14 +0100 | [diff] [blame] | 239 | def count_arm_param_registers(params): |
| 240 | """This function is used to count the number of register used |
Elliott Hughes | cd6780b | 2013-02-07 14:07:00 -0800 | [diff] [blame] | 241 | to pass parameters when invoking an ARM system call. |
David 'Digit' Turner | 95d751f | 2010-12-16 16:47:14 +0100 | [diff] [blame] | 242 | This is because the ARM EABI mandates that 64-bit quantities |
| 243 | must be passed in an even+odd register pair. So, for example, |
| 244 | something like: |
| 245 | |
| 246 | foo(int fd, off64_t pos) |
| 247 | |
| 248 | would actually need 4 registers: |
| 249 | r0 -> int |
| 250 | r1 -> unused |
| 251 | r2-r3 -> pos |
| 252 | """ |
| 253 | count = 0 |
| 254 | for param in params: |
| 255 | if param_uses_64bits(param): |
| 256 | if (count & 1) != 0: |
| 257 | count += 1 |
| 258 | count += 2 |
| 259 | else: |
| 260 | count += 1 |
| 261 | return count |
| 262 | |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 263 | |
David 'Digit' Turner | 95d751f | 2010-12-16 16:47:14 +0100 | [diff] [blame] | 264 | def count_generic_param_registers(params): |
| 265 | count = 0 |
| 266 | for param in params: |
| 267 | if param_uses_64bits(param): |
| 268 | count += 2 |
| 269 | else: |
| 270 | count += 1 |
| 271 | return count |
| 272 | |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 273 | |
Pavel Chupin | f12a18b | 2012-12-12 13:11:48 +0400 | [diff] [blame] | 274 | def count_generic_param_registers64(params): |
| 275 | count = 0 |
| 276 | for param in params: |
| 277 | count += 1 |
| 278 | return count |
| 279 | |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 280 | |
Elliott Hughes | cda6209 | 2013-03-22 13:50:44 -0700 | [diff] [blame] | 281 | # This lets us support regular system calls like __NR_write and also weird |
| 282 | # ones like __ARM_NR_cacheflush, where the NR doesn't come at the start. |
| 283 | def make__NR_name(name): |
Christopher Ferris | 01bd32e | 2014-08-05 12:19:27 -0700 | [diff] [blame] | 284 | if name.startswith("__ARM_NR_"): |
Elliott Hughes | cda6209 | 2013-03-22 13:50:44 -0700 | [diff] [blame] | 285 | return name |
| 286 | else: |
| 287 | return "__NR_%s" % (name) |
| 288 | |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 289 | |
Elliott Hughes | fff6e27 | 2013-10-24 17:03:20 -0700 | [diff] [blame] | 290 | def add_footer(pointer_length, stub, syscall): |
| 291 | # Add any aliases for this syscall. |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 292 | aliases = syscall["aliases"] |
| 293 | for alias in aliases: |
Christopher Ferris | fa5faa0 | 2015-03-24 16:50:46 -0700 | [diff] [blame] | 294 | stub += "\nALIAS_SYMBOL(%s, %s)\n" % (alias, syscall["func"]) |
Elliott Hughes | fff6e27 | 2013-10-24 17:03:20 -0700 | [diff] [blame] | 295 | |
Nick Kralevich | 00490ae | 2015-02-03 11:27:25 -0800 | [diff] [blame] | 296 | # Use hidden visibility on LP64 for any functions beginning with underscores. |
| 297 | # Force hidden visibility for any functions which begin with 3 underscores |
| 298 | if (pointer_length == 64 and syscall["func"].startswith("__")) or syscall["func"].startswith("___"): |
Elliott Hughes | d465eb4 | 2014-02-19 18:59:19 -0800 | [diff] [blame] | 299 | stub += '.hidden ' + syscall["func"] + '\n' |
Elliott Hughes | fff6e27 | 2013-10-24 17:03:20 -0700 | [diff] [blame] | 300 | |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 301 | return stub |
| 302 | |
| 303 | |
| 304 | def arm_eabi_genstub(syscall): |
| 305 | num_regs = count_arm_param_registers(syscall["params"]) |
| 306 | if num_regs > 4: |
| 307 | return arm_eabi_call_long % syscall |
| 308 | return arm_eabi_call_default % syscall |
| 309 | |
| 310 | |
Colin Cross | d1973ca | 2014-01-21 19:50:58 -0800 | [diff] [blame] | 311 | def arm64_genstub(syscall): |
| 312 | return arm64_call % syscall |
| 313 | |
| 314 | |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 315 | def mips_genstub(syscall): |
| 316 | return mips_call % syscall |
| 317 | |
| 318 | |
Chris Dearman | 5043212 | 2014-02-05 16:59:23 -0800 | [diff] [blame] | 319 | def mips64_genstub(syscall): |
| 320 | return mips64_call % syscall |
| 321 | |
| 322 | |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 323 | def x86_genstub(syscall): |
| 324 | result = syscall_stub_header % syscall |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 325 | |
| 326 | numparams = count_generic_param_registers(syscall["params"]) |
Mingwei Shi | be91052 | 2015-11-12 07:02:14 +0000 | [diff] [blame] | 327 | stack_bias = numparams*4 + 8 |
Christopher Ferris | e4bc756 | 2014-01-06 16:39:10 -0800 | [diff] [blame] | 328 | offset = 0 |
| 329 | mov_result = "" |
Christopher Ferris | 15b91e9 | 2014-05-29 18:17:09 -0700 | [diff] [blame] | 330 | first_push = True |
Christopher Ferris | e4bc756 | 2014-01-06 16:39:10 -0800 | [diff] [blame] | 331 | for register in x86_registers[:numparams]: |
| 332 | result += " pushl %%%s\n" % register |
Christopher Ferris | 15b91e9 | 2014-05-29 18:17:09 -0700 | [diff] [blame] | 333 | if first_push: |
| 334 | result += " .cfi_def_cfa_offset 8\n" |
| 335 | result += " .cfi_rel_offset %s, 0\n" % register |
| 336 | first_push = False |
| 337 | else: |
| 338 | result += " .cfi_adjust_cfa_offset 4\n" |
| 339 | result += " .cfi_rel_offset %s, 0\n" % register |
Christopher Ferris | e4bc756 | 2014-01-06 16:39:10 -0800 | [diff] [blame] | 340 | mov_result += " mov %d(%%esp), %%%s\n" % (stack_bias+offset, register) |
Christopher Ferris | e4bc756 | 2014-01-06 16:39:10 -0800 | [diff] [blame] | 341 | offset += 4 |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 342 | |
Mingwei Shi | be91052 | 2015-11-12 07:02:14 +0000 | [diff] [blame] | 343 | result += x86_call_prepare |
Christopher Ferris | 15b91e9 | 2014-05-29 18:17:09 -0700 | [diff] [blame] | 344 | result += mov_result |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 345 | result += x86_call % syscall |
| 346 | |
Christopher Ferris | e4bc756 | 2014-01-06 16:39:10 -0800 | [diff] [blame] | 347 | for register in reversed(x86_registers[:numparams]): |
| 348 | result += " popl %%%s\n" % register |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 349 | |
| 350 | result += x86_return % syscall |
| 351 | return result |
| 352 | |
Serban Constantinescu | feaa89a | 2013-10-07 16:49:09 +0100 | [diff] [blame] | 353 | |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 354 | def x86_genstub_socketcall(syscall): |
| 355 | # %ebx <--- Argument 1 - The call id of the needed vectored |
| 356 | # syscall (socket, bind, recv, etc) |
| 357 | # %ecx <--- Argument 2 - Pointer to the rest of the arguments |
| 358 | # from the original function called (socket()) |
| 359 | |
| 360 | result = syscall_stub_header % syscall |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 361 | |
| 362 | # save the regs we need |
Christopher Ferris | e4bc756 | 2014-01-06 16:39:10 -0800 | [diff] [blame] | 363 | result += " pushl %ebx\n" |
Christopher Ferris | e4bc756 | 2014-01-06 16:39:10 -0800 | [diff] [blame] | 364 | result += " .cfi_def_cfa_offset 8\n" |
| 365 | result += " .cfi_rel_offset ebx, 0\n" |
Christopher Ferris | 15b91e9 | 2014-05-29 18:17:09 -0700 | [diff] [blame] | 366 | result += " pushl %ecx\n" |
| 367 | result += " .cfi_adjust_cfa_offset 4\n" |
| 368 | result += " .cfi_rel_offset ecx, 0\n" |
Mingwei Shi | be91052 | 2015-11-12 07:02:14 +0000 | [diff] [blame] | 369 | stack_bias = 16 |
| 370 | |
| 371 | result += x86_call_prepare |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 372 | |
| 373 | # set the call id (%ebx) |
Christopher Ferris | e4bc756 | 2014-01-06 16:39:10 -0800 | [diff] [blame] | 374 | result += " mov $%d, %%ebx\n" % syscall["socketcall_id"] |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 375 | |
| 376 | # set the pointer to the rest of the args into %ecx |
Christopher Ferris | e4bc756 | 2014-01-06 16:39:10 -0800 | [diff] [blame] | 377 | result += " mov %esp, %ecx\n" |
| 378 | result += " addl $%d, %%ecx\n" % (stack_bias) |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 379 | |
| 380 | # now do the syscall code itself |
| 381 | result += x86_call % syscall |
| 382 | |
| 383 | # now restore the saved regs |
Christopher Ferris | e4bc756 | 2014-01-06 16:39:10 -0800 | [diff] [blame] | 384 | result += " popl %ecx\n" |
| 385 | result += " popl %ebx\n" |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 386 | |
| 387 | # epilog |
| 388 | result += x86_return % syscall |
| 389 | return result |
| 390 | |
| 391 | |
| 392 | def x86_64_genstub(syscall): |
| 393 | result = syscall_stub_header % syscall |
| 394 | num_regs = count_generic_param_registers64(syscall["params"]) |
| 395 | if (num_regs > 3): |
| 396 | # rcx is used as 4th argument. Kernel wants it at r10. |
| 397 | result += " movq %rcx, %r10\n" |
| 398 | |
| 399 | result += x86_64_call % syscall |
| 400 | return result |
| 401 | |
| 402 | |
Elliott Hughes | dc1fb70 | 2014-08-20 11:16:11 -0700 | [diff] [blame] | 403 | class SysCallsTxtParser: |
| 404 | def __init__(self): |
| 405 | self.syscalls = [] |
| 406 | self.lineno = 0 |
| 407 | |
| 408 | def E(self, msg): |
| 409 | print "%d: %s" % (self.lineno, msg) |
| 410 | |
| 411 | def parse_line(self, line): |
| 412 | """ parse a syscall spec line. |
| 413 | |
| 414 | line processing, format is |
| 415 | return type func_name[|alias_list][:syscall_name[:socketcall_id]] ( [paramlist] ) architecture_list |
| 416 | """ |
| 417 | pos_lparen = line.find('(') |
| 418 | E = self.E |
| 419 | if pos_lparen < 0: |
| 420 | E("missing left parenthesis in '%s'" % line) |
| 421 | return |
| 422 | |
| 423 | pos_rparen = line.rfind(')') |
| 424 | if pos_rparen < 0 or pos_rparen <= pos_lparen: |
| 425 | E("missing or misplaced right parenthesis in '%s'" % line) |
| 426 | return |
| 427 | |
| 428 | return_type = line[:pos_lparen].strip().split() |
| 429 | if len(return_type) < 2: |
| 430 | E("missing return type in '%s'" % line) |
| 431 | return |
| 432 | |
| 433 | syscall_func = return_type[-1] |
| 434 | return_type = string.join(return_type[:-1],' ') |
| 435 | socketcall_id = -1 |
| 436 | |
| 437 | pos_colon = syscall_func.find(':') |
| 438 | if pos_colon < 0: |
| 439 | syscall_name = syscall_func |
| 440 | else: |
| 441 | if pos_colon == 0 or pos_colon+1 >= len(syscall_func): |
| 442 | E("misplaced colon in '%s'" % line) |
| 443 | return |
| 444 | |
| 445 | # now find if there is a socketcall_id for a dispatch-type syscall |
| 446 | # after the optional 2nd colon |
| 447 | pos_colon2 = syscall_func.find(':', pos_colon + 1) |
| 448 | if pos_colon2 < 0: |
| 449 | syscall_name = syscall_func[pos_colon+1:] |
| 450 | syscall_func = syscall_func[:pos_colon] |
| 451 | else: |
| 452 | if pos_colon2+1 >= len(syscall_func): |
| 453 | E("misplaced colon2 in '%s'" % line) |
| 454 | return |
| 455 | syscall_name = syscall_func[(pos_colon+1):pos_colon2] |
| 456 | socketcall_id = int(syscall_func[pos_colon2+1:]) |
| 457 | syscall_func = syscall_func[:pos_colon] |
| 458 | |
| 459 | alias_delim = syscall_func.find('|') |
| 460 | if alias_delim > 0: |
| 461 | alias_list = syscall_func[alias_delim+1:].strip() |
| 462 | syscall_func = syscall_func[:alias_delim] |
| 463 | alias_delim = syscall_name.find('|') |
| 464 | if alias_delim > 0: |
| 465 | syscall_name = syscall_name[:alias_delim] |
| 466 | syscall_aliases = string.split(alias_list, ',') |
| 467 | else: |
| 468 | syscall_aliases = [] |
| 469 | |
| 470 | if pos_rparen > pos_lparen+1: |
| 471 | syscall_params = line[pos_lparen+1:pos_rparen].split(',') |
| 472 | params = string.join(syscall_params,',') |
| 473 | else: |
| 474 | syscall_params = [] |
| 475 | params = "void" |
| 476 | |
| 477 | t = { |
| 478 | "name" : syscall_name, |
| 479 | "func" : syscall_func, |
| 480 | "aliases" : syscall_aliases, |
| 481 | "params" : syscall_params, |
| 482 | "decl" : "%-15s %s (%s);" % (return_type, syscall_func, params), |
| 483 | "socketcall_id" : socketcall_id |
| 484 | } |
| 485 | |
| 486 | # Parse the architecture list. |
| 487 | arch_list = line[pos_rparen+1:].strip() |
| 488 | if arch_list == "all": |
| 489 | for arch in all_arches: |
| 490 | t[arch] = True |
| 491 | else: |
| 492 | for arch in string.split(arch_list, ','): |
| 493 | if arch in all_arches: |
| 494 | t[arch] = True |
| 495 | else: |
| 496 | E("invalid syscall architecture '%s' in '%s'" % (arch, line)) |
| 497 | return |
| 498 | |
| 499 | self.syscalls.append(t) |
| 500 | |
| 501 | logging.debug(t) |
| 502 | |
| 503 | |
| 504 | def parse_file(self, file_path): |
| 505 | logging.debug("parse_file: %s" % file_path) |
| 506 | fp = open(file_path) |
| 507 | for line in fp.xreadlines(): |
| 508 | self.lineno += 1 |
| 509 | line = line.strip() |
| 510 | if not line: continue |
| 511 | if line[0] == '#': continue |
| 512 | self.parse_line(line) |
| 513 | |
| 514 | fp.close() |
| 515 | |
| 516 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 517 | class State: |
| 518 | def __init__(self): |
| 519 | self.old_stubs = [] |
| 520 | self.new_stubs = [] |
| 521 | self.other_files = [] |
| 522 | self.syscalls = [] |
| 523 | |
Pavel Chupin | f12a18b | 2012-12-12 13:11:48 +0400 | [diff] [blame] | 524 | |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 525 | def process_file(self, input): |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 526 | parser = SysCallsTxtParser() |
| 527 | parser.parse_file(input) |
| 528 | self.syscalls = parser.syscalls |
| 529 | parser = None |
| 530 | |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 531 | for syscall in self.syscalls: |
| 532 | syscall["__NR_name"] = make__NR_name(syscall["name"]) |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 533 | |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 534 | if syscall.has_key("arm"): |
Elliott Hughes | fff6e27 | 2013-10-24 17:03:20 -0700 | [diff] [blame] | 535 | syscall["asm-arm"] = add_footer(32, arm_eabi_genstub(syscall), syscall) |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 536 | |
Colin Cross | d1973ca | 2014-01-21 19:50:58 -0800 | [diff] [blame] | 537 | if syscall.has_key("arm64"): |
| 538 | syscall["asm-arm64"] = add_footer(64, arm64_genstub(syscall), syscall) |
| 539 | |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 540 | if syscall.has_key("x86"): |
| 541 | if syscall["socketcall_id"] >= 0: |
Elliott Hughes | fff6e27 | 2013-10-24 17:03:20 -0700 | [diff] [blame] | 542 | syscall["asm-x86"] = add_footer(32, x86_genstub_socketcall(syscall), syscall) |
The Android Open Source Project | 4e468ed | 2008-12-17 18:03:48 -0800 | [diff] [blame] | 543 | else: |
Elliott Hughes | fff6e27 | 2013-10-24 17:03:20 -0700 | [diff] [blame] | 544 | syscall["asm-x86"] = add_footer(32, x86_genstub(syscall), syscall) |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 545 | elif syscall["socketcall_id"] >= 0: |
Elliott Hughes | d612165 | 2013-09-25 22:43:36 -0700 | [diff] [blame] | 546 | E("socketcall_id for dispatch syscalls is only supported for x86 in '%s'" % t) |
The Android Open Source Project | 4e468ed | 2008-12-17 18:03:48 -0800 | [diff] [blame] | 547 | return |
Elliott Hughes | cd6780b | 2013-02-07 14:07:00 -0800 | [diff] [blame] | 548 | |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 549 | if syscall.has_key("mips"): |
Elliott Hughes | fff6e27 | 2013-10-24 17:03:20 -0700 | [diff] [blame] | 550 | syscall["asm-mips"] = add_footer(32, mips_genstub(syscall), syscall) |
The Android Open Source Project | 4e468ed | 2008-12-17 18:03:48 -0800 | [diff] [blame] | 551 | |
Chris Dearman | 5043212 | 2014-02-05 16:59:23 -0800 | [diff] [blame] | 552 | if syscall.has_key("mips64"): |
| 553 | syscall["asm-mips64"] = add_footer(64, mips64_genstub(syscall), syscall) |
| 554 | |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 555 | if syscall.has_key("x86_64"): |
Elliott Hughes | fff6e27 | 2013-10-24 17:03:20 -0700 | [diff] [blame] | 556 | syscall["asm-x86_64"] = add_footer(64, x86_64_genstub(syscall), syscall) |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 557 | |
Elliott Hughes | 1b91c6c | 2013-03-22 18:56:24 -0700 | [diff] [blame] | 558 | # Scan a Linux kernel asm/unistd.h file containing __NR_* constants |
| 559 | # and write out equivalent SYS_* constants for glibc source compatibility. |
Elliott Hughes | 5c2772f | 2013-03-21 22:15:06 -0700 | [diff] [blame] | 560 | def scan_linux_unistd_h(self, fp, path): |
| 561 | pattern = re.compile(r'^#define __NR_([a-z]\S+) .*') |
| 562 | syscalls = set() # MIPS defines everything three times; work around that. |
| 563 | for line in open(path): |
| 564 | m = re.search(pattern, line) |
| 565 | if m: |
| 566 | syscalls.add(m.group(1)) |
| 567 | for syscall in sorted(syscalls): |
Elliott Hughes | cda6209 | 2013-03-22 13:50:44 -0700 | [diff] [blame] | 568 | fp.write("#define SYS_%s %s\n" % (syscall, make__NR_name(syscall))) |
Elliott Hughes | 8ecf225 | 2013-03-21 18:06:55 -0700 | [diff] [blame] | 569 | |
| 570 | |
Elliott Hughes | 1b91c6c | 2013-03-22 18:56:24 -0700 | [diff] [blame] | 571 | def gen_glibc_syscalls_h(self): |
Elliott Hughes | cda6209 | 2013-03-22 13:50:44 -0700 | [diff] [blame] | 572 | # TODO: generate a separate file for each architecture, like glibc's bits/syscall.h. |
Elliott Hughes | 8aabbd7 | 2016-05-02 12:47:58 -0700 | [diff] [blame] | 573 | glibc_syscalls_h_path = "include/bits/glibc-syscalls.h" |
Elliott Hughes | dc1fb70 | 2014-08-20 11:16:11 -0700 | [diff] [blame] | 574 | logging.info("generating " + glibc_syscalls_h_path) |
Elliott Hughes | 9724ce3 | 2013-03-21 19:43:54 -0700 | [diff] [blame] | 575 | glibc_fp = create_file(glibc_syscalls_h_path) |
Elliott Hughes | 103ccde | 2013-10-16 14:27:59 -0700 | [diff] [blame] | 576 | glibc_fp.write("/* %s */\n" % warning) |
Elliott Hughes | 9724ce3 | 2013-03-21 19:43:54 -0700 | [diff] [blame] | 577 | glibc_fp.write("#ifndef _BIONIC_GLIBC_SYSCALLS_H_\n") |
| 578 | glibc_fp.write("#define _BIONIC_GLIBC_SYSCALLS_H_\n") |
| 579 | |
Serban Constantinescu | feaa89a | 2013-10-07 16:49:09 +0100 | [diff] [blame] | 580 | glibc_fp.write("#if defined(__aarch64__)\n") |
Christopher Ferris | 01bd32e | 2014-08-05 12:19:27 -0700 | [diff] [blame] | 581 | self.scan_linux_unistd_h(glibc_fp, os.path.join(bionic_libc_root, "kernel/uapi/asm-generic/unistd.h")) |
Serban Constantinescu | feaa89a | 2013-10-07 16:49:09 +0100 | [diff] [blame] | 582 | glibc_fp.write("#elif defined(__arm__)\n") |
Christopher Ferris | 01bd32e | 2014-08-05 12:19:27 -0700 | [diff] [blame] | 583 | self.scan_linux_unistd_h(glibc_fp, os.path.join(bionic_libc_root, "kernel/uapi/asm-arm/asm/unistd.h")) |
Elliott Hughes | 5c2772f | 2013-03-21 22:15:06 -0700 | [diff] [blame] | 584 | glibc_fp.write("#elif defined(__mips__)\n") |
Christopher Ferris | 01bd32e | 2014-08-05 12:19:27 -0700 | [diff] [blame] | 585 | self.scan_linux_unistd_h(glibc_fp, os.path.join(bionic_libc_root, "kernel/uapi/asm-mips/asm/unistd.h")) |
Elliott Hughes | 5c2772f | 2013-03-21 22:15:06 -0700 | [diff] [blame] | 586 | glibc_fp.write("#elif defined(__i386__)\n") |
Christopher Ferris | 01bd32e | 2014-08-05 12:19:27 -0700 | [diff] [blame] | 587 | self.scan_linux_unistd_h(glibc_fp, os.path.join(bionic_libc_root, "kernel/uapi/asm-x86/asm/unistd_32.h")) |
Pavel Chupin | f12a18b | 2012-12-12 13:11:48 +0400 | [diff] [blame] | 588 | glibc_fp.write("#elif defined(__x86_64__)\n") |
Christopher Ferris | 01bd32e | 2014-08-05 12:19:27 -0700 | [diff] [blame] | 589 | self.scan_linux_unistd_h(glibc_fp, os.path.join(bionic_libc_root, "kernel/uapi/asm-x86/asm/unistd_64.h")) |
Elliott Hughes | 5c2772f | 2013-03-21 22:15:06 -0700 | [diff] [blame] | 590 | glibc_fp.write("#endif\n") |
| 591 | |
| 592 | glibc_fp.write("#endif /* _BIONIC_GLIBC_SYSCALLS_H_ */\n") |
| 593 | glibc_fp.close() |
| 594 | self.other_files.append(glibc_syscalls_h_path) |
| 595 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 596 | |
Elliott Hughes | d612165 | 2013-09-25 22:43:36 -0700 | [diff] [blame] | 597 | # Write each syscall stub. |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 598 | def gen_syscall_stubs(self): |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 599 | for syscall in self.syscalls: |
Elliott Hughes | d612165 | 2013-09-25 22:43:36 -0700 | [diff] [blame] | 600 | for arch in all_arches: |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 601 | if syscall.has_key("asm-%s" % arch): |
| 602 | filename = "arch-%s/syscalls/%s.S" % (arch, syscall["func"]) |
Elliott Hughes | dc1fb70 | 2014-08-20 11:16:11 -0700 | [diff] [blame] | 603 | logging.info(">>> generating " + filename) |
Elliott Hughes | d612165 | 2013-09-25 22:43:36 -0700 | [diff] [blame] | 604 | fp = create_file(filename) |
Elliott Hughes | 0437f3f | 2013-10-07 23:53:13 -0700 | [diff] [blame] | 605 | fp.write(syscall["asm-%s" % arch]) |
Elliott Hughes | d612165 | 2013-09-25 22:43:36 -0700 | [diff] [blame] | 606 | fp.close() |
| 607 | self.new_stubs.append(filename) |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 608 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 609 | |
Elliott Hughes | d612165 | 2013-09-25 22:43:36 -0700 | [diff] [blame] | 610 | def regenerate(self): |
Elliott Hughes | dc1fb70 | 2014-08-20 11:16:11 -0700 | [diff] [blame] | 611 | logging.info("scanning for existing architecture-specific stub files...") |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 612 | |
Elliott Hughes | d612165 | 2013-09-25 22:43:36 -0700 | [diff] [blame] | 613 | for arch in all_arches: |
Christopher Ferris | 01bd32e | 2014-08-05 12:19:27 -0700 | [diff] [blame] | 614 | arch_dir = "arch-" + arch |
Elliott Hughes | dc1fb70 | 2014-08-20 11:16:11 -0700 | [diff] [blame] | 615 | logging.info("scanning " + os.path.join(bionic_libc_root, arch_dir)) |
Christopher Ferris | 01bd32e | 2014-08-05 12:19:27 -0700 | [diff] [blame] | 616 | rel_path = os.path.join(arch_dir, "syscalls") |
| 617 | for file in os.listdir(os.path.join(bionic_libc_root, rel_path)): |
| 618 | if file.endswith(".S"): |
| 619 | self.old_stubs.append(os.path.join(rel_path, file)) |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 620 | |
Elliott Hughes | dc1fb70 | 2014-08-20 11:16:11 -0700 | [diff] [blame] | 621 | logging.info("found %d stub files" % len(self.old_stubs)) |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 622 | |
Pavel Chupin | f12a18b | 2012-12-12 13:11:48 +0400 | [diff] [blame] | 623 | if not os.path.exists(bionic_temp): |
Elliott Hughes | dc1fb70 | 2014-08-20 11:16:11 -0700 | [diff] [blame] | 624 | logging.info("creating %s..." % bionic_temp) |
Pavel Chupin | f12a18b | 2012-12-12 13:11:48 +0400 | [diff] [blame] | 625 | make_dir(bionic_temp) |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 626 | |
Elliott Hughes | dc1fb70 | 2014-08-20 11:16:11 -0700 | [diff] [blame] | 627 | logging.info("re-generating stubs and support files...") |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 628 | |
Elliott Hughes | 1b91c6c | 2013-03-22 18:56:24 -0700 | [diff] [blame] | 629 | self.gen_glibc_syscalls_h() |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 630 | self.gen_syscall_stubs() |
| 631 | |
Elliott Hughes | dc1fb70 | 2014-08-20 11:16:11 -0700 | [diff] [blame] | 632 | logging.info("comparing files...") |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 633 | adds = [] |
| 634 | edits = [] |
| 635 | |
| 636 | for stub in self.new_stubs + self.other_files: |
Christopher Ferris | 01bd32e | 2014-08-05 12:19:27 -0700 | [diff] [blame] | 637 | tmp_file = os.path.join(bionic_temp, stub) |
| 638 | libc_file = os.path.join(bionic_libc_root, stub) |
| 639 | if not os.path.exists(libc_file): |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 640 | # new file, git add it |
Elliott Hughes | dc1fb70 | 2014-08-20 11:16:11 -0700 | [diff] [blame] | 641 | logging.info("new file: " + stub) |
Christopher Ferris | 01bd32e | 2014-08-05 12:19:27 -0700 | [diff] [blame] | 642 | adds.append(libc_file) |
| 643 | shutil.copyfile(tmp_file, libc_file) |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 644 | |
Christopher Ferris | 01bd32e | 2014-08-05 12:19:27 -0700 | [diff] [blame] | 645 | elif not filecmp.cmp(tmp_file, libc_file): |
Elliott Hughes | dc1fb70 | 2014-08-20 11:16:11 -0700 | [diff] [blame] | 646 | logging.info("changed file: " + stub) |
Pavel Chupin | f12a18b | 2012-12-12 13:11:48 +0400 | [diff] [blame] | 647 | edits.append(stub) |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 648 | |
| 649 | deletes = [] |
| 650 | for stub in self.old_stubs: |
| 651 | if not stub in self.new_stubs: |
Elliott Hughes | dc1fb70 | 2014-08-20 11:16:11 -0700 | [diff] [blame] | 652 | logging.info("deleted file: " + stub) |
Christopher Ferris | 01bd32e | 2014-08-05 12:19:27 -0700 | [diff] [blame] | 653 | deletes.append(os.path.join(bionic_libc_root, stub)) |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 654 | |
Pavel Chupin | f12a18b | 2012-12-12 13:11:48 +0400 | [diff] [blame] | 655 | if not DRY_RUN: |
| 656 | if adds: |
| 657 | commands.getoutput("git add " + " ".join(adds)) |
| 658 | if deletes: |
| 659 | commands.getoutput("git rm " + " ".join(deletes)) |
| 660 | if edits: |
| 661 | for file in edits: |
Christopher Ferris | 01bd32e | 2014-08-05 12:19:27 -0700 | [diff] [blame] | 662 | shutil.copyfile(os.path.join(bionic_temp, file), |
| 663 | os.path.join(bionic_libc_root, file)) |
| 664 | commands.getoutput("git add " + " ".join((os.path.join(bionic_libc_root, file)) for file in edits)) |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 665 | |
Christopher Ferris | 01bd32e | 2014-08-05 12:19:27 -0700 | [diff] [blame] | 666 | commands.getoutput("git add %s" % (os.path.join(bionic_libc_root, "SYSCALLS.TXT"))) |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 667 | |
| 668 | if (not adds) and (not deletes) and (not edits): |
Elliott Hughes | dc1fb70 | 2014-08-20 11:16:11 -0700 | [diff] [blame] | 669 | logging.info("no changes detected!") |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 670 | else: |
Elliott Hughes | dc1fb70 | 2014-08-20 11:16:11 -0700 | [diff] [blame] | 671 | logging.info("ready to go!!") |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 672 | |
Elliott Hughes | dc1fb70 | 2014-08-20 11:16:11 -0700 | [diff] [blame] | 673 | logging.basicConfig(level=logging.INFO) |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 674 | |
| 675 | state = State() |
Christopher Ferris | 01bd32e | 2014-08-05 12:19:27 -0700 | [diff] [blame] | 676 | state.process_file(os.path.join(bionic_libc_root, "SYSCALLS.TXT")) |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 677 | state.regenerate() |