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