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