| 1 | diff --git a/ChangeLog b/ChangeLog |
| 2 | index c44c926094..cd499c5fe3 100644 |
| 3 | --- a/ChangeLog |
| 4 | +++ b/ChangeLog |
| 5 | @@ -1,3 +1,887 @@ |
| 6 | +2018-01-12 Dmitry V. Levin <ldv@altlinux.org> |
| 7 | + |
| 8 | + [BZ #22679] |
| 9 | + CVE-2018-1000001 |
| 10 | + * sysdeps/unix/sysv/linux/getcwd.c (__getcwd): Fall back to |
| 11 | + generic_getcwd if the path returned by getcwd syscall is not absolute. |
| 12 | + * io/tst-getcwd-abspath.c: New test. |
| 13 | + * io/Makefile (tests): Add tst-getcwd-abspath. |
| 14 | + |
| 15 | + (gaih_inet): Likewise. |
| 16 | + |
| 17 | +2017-12-30 Aurelien Jarno <aurelien@aurel32.net> |
| 18 | + |
| 19 | + [BZ #22625] |
| 20 | + * elf/dl-load.c (fillin_rpath): Check for empty tokens before dynamic |
| 21 | + string token expansion. Check for NULL pointer or empty string possibly |
| 22 | + returned by expand_dynamic_string_token. |
| 23 | + (decompose_rpath): Check for empty path after dynamic string |
| 24 | + token expansion. |
| 25 | + |
| 26 | +2017-12-18 Dmitry V. Levin <ldv@altlinux.org> |
| 27 | + |
| 28 | + [BZ #22627] |
| 29 | + * elf/dl-load.c (_dl_init_paths): Remove _dl_dst_substitute preparatory |
| 30 | + code and invocation. |
| 31 | + |
| 32 | +2017-12-14 Florian Weimer <fweimer@redhat.com> |
| 33 | + |
| 34 | + [BZ #22607] |
| 35 | + CVE-2017-1000409 |
| 36 | + * elf/dl-load.c (_dl_init_paths): Compute number of components in |
| 37 | + the expanded path string. |
| 38 | + |
| 39 | +2017-12-14 Florian Weimer <fweimer@redhat.com> |
| 40 | + |
| 41 | + [BZ #22606] |
| 42 | + CVE-2017-1000408 |
| 43 | + * elf/dl-load.c (system_dirs): Update comment. |
| 44 | + (nsystem_dirs_len): Use array_length. |
| 45 | + (_dl_init_paths): Use nsystem_dirs_len to compute the array size. |
| 46 | + |
| 47 | +2017-11-02 Florian Weimer <fweimer@redhat.com> |
| 48 | + |
| 49 | + Add array_length and array_end macros. |
| 50 | + * include/array_length.h: New file. |
| 51 | + |
| 52 | +2017-11-02 Florian Weimer <fweimer@redhat.com> |
| 53 | + |
| 54 | + [BZ #22332] |
| 55 | + * posix/tst-glob-tilde.c (do_noescape): New variable. |
| 56 | + (one_test): Process it. |
| 57 | + (do_test): Set do_noescape. Add unescaping test case. |
| 58 | + |
| 59 | +2017-10-22 Paul Eggert <eggert@cs.ucla.edu> |
| 60 | + |
| 61 | + [BZ #22332] |
| 62 | + * posix/glob.c (__glob): Fix buffer overflow during GLOB_TILDE |
| 63 | + unescaping. |
| 64 | + |
| 65 | +2017-10-21 Florian Weimer <fweimer@redhat.com> |
| 66 | + |
| 67 | + * posix/Makefile (tests): Add tst-glob-tilde. |
| 68 | + (tests-special): Add tst-glob-tilde-mem.out |
| 69 | + (tst-glob-tilde-ENV): Set MALLOC_TRACE. |
| 70 | + (tst-glob-tilde-mem.out): Add mtrace check. |
| 71 | + * posix/tst-glob-tilde.c: New file. |
| 72 | + |
| 73 | +2017-10-20 Paul Eggert <eggert@cs.ucla.edu> |
| 74 | + |
| 75 | + [BZ #22320] |
| 76 | + CVE-2017-15670 |
| 77 | + * posix/glob.c (__glob): Fix one-byte overflow. |
| 78 | + |
| 79 | +2017-09-08 Adhemerval Zanella <adhemerval.zanella@linaro.org> |
| 80 | + |
| 81 | + [BZ #1062] |
| 82 | + CVE-2017-15671 |
| 83 | + * posix/Makefile (routines): Add globfree, globfree64, and |
| 84 | + glob_pattern_p. |
| 85 | + * posix/flexmember.h: New file. |
| 86 | + * posix/glob_internal.h: Likewise. |
| 87 | + * posix/glob_pattern_p.c: Likewise. |
| 88 | + * posix/globfree.c: Likewise. |
| 89 | + * posix/globfree64.c: Likewise. |
| 90 | + * sysdeps/gnu/globfree64.c: Likewise. |
| 91 | + * sysdeps/unix/sysv/linux/alpha/globfree.c: Likewise. |
| 92 | + * sysdeps/unix/sysv/linux/mips/mips64/n64/globfree64.c: Likewise. |
| 93 | + * sysdeps/unix/sysv/linux/oldglob.c: Likewise. |
| 94 | + * sysdeps/unix/sysv/linux/wordsize-64/globfree64.c: Likewise. |
| 95 | + * sysdeps/unix/sysv/linux/x86_64/x32/globfree.c: Likewise. |
| 96 | + * sysdeps/wordsize-64/globfree.c: Likewise. |
| 97 | + * sysdeps/wordsize-64/globfree64.c: Likewise. |
| 98 | + * posix/glob.c (HAVE_CONFIG_H): Use !_LIBC instead. |
| 99 | + [NDEBUG): Remove comments. |
| 100 | + (GLOB_ONLY_P, _AMIGA, VMS): Remove define. |
| 101 | + (dirent_type): New type. Use uint_fast8_t not |
| 102 | + uint8_t, as C99 does not require uint8_t. |
| 103 | + (DT_UNKNOWN, DT_DIR, DT_LNK): New macros. |
| 104 | + (struct readdir_result): Use dirent_type. Do not define skip_entry |
| 105 | + unless it is needed; this saves a byte on platforms lacking d_ino. |
| 106 | + (readdir_result_type, readdir_result_skip_entry): |
| 107 | + New functions, replacing ... |
| 108 | + (readdir_result_might_be_symlink, readdir_result_might_be_dir): |
| 109 | + these functions, which were removed. This makes the callers |
| 110 | + easier to read. All callers changed. |
| 111 | + (D_INO_TO_RESULT): Now empty if there is no d_ino. |
| 112 | + (size_add_wrapv, glob_use_alloca): New static functions. |
| 113 | + (glob, glob_in_dir): Check for size_t overflow in several places, |
| 114 | + and fix some size_t checks that were not quite right. |
| 115 | + Remove old code using SHELL since Bash no longer |
| 116 | + uses this. |
| 117 | + (glob, prefix_array): Separate MS code better. |
| 118 | + (glob_in_dir): Remove old Amiga and VMS code. |
| 119 | + (globfree, __glob_pattern_type, __glob_pattern_p): Move to |
| 120 | + separate files. |
| 121 | + (glob_in_dir): Do not rely on undefined behavior in accessing |
| 122 | + struct members beyond their bounds. Use a flexible array member |
| 123 | + instead |
| 124 | + (link_stat): Rename from link_exists2_p and return -1/0 instead of |
| 125 | + 0/1. Caller changed. |
| 126 | + (glob): Fix memory leaks. |
| 127 | + * posix/glob64 (globfree64): Move to separate file. |
| 128 | + * sysdeps/gnu/glob64.c (NO_GLOB_PATTERN_P): Remove define. |
| 129 | + (globfree64): Remove hidden alias. |
| 130 | + * sysdeps/unix/sysv/linux/Makefile (sysdeps_routines): Add |
| 131 | + oldglob. |
| 132 | + * sysdeps/unix/sysv/linux/alpha/glob.c (__new_globfree): Move to |
| 133 | + separate file. |
| 134 | + * sysdeps/unix/sysv/linux/i386/glob64.c (NO_GLOB_PATTERN_P): Remove |
| 135 | + define. |
| 136 | + Move compat code to separate file. |
| 137 | + * sysdeps/wordsize-64/glob.c (globfree): Move definitions to |
| 138 | + separate file. |
| 139 | + |
| 140 | +2017-08-20 H.J. Lu <hongjiu.lu@intel.com> |
| 141 | + |
| 142 | + [BZ #18822] |
| 143 | + * sysdeps/unix/sysv/linux/i386/glob64.c (__old_glob64): Add |
| 144 | + libc_hidden_proto and libc_hidden_def. |
| 145 | + |
| 146 | +2017-10-22 H.J. Lu <hongjiu.lu@intel.com> |
| 147 | + |
| 148 | + [BZ #21265] |
| 149 | + * sysdeps/x86/cpu-features-offsets.sym (XSAVE_STATE_SIZE_OFFSET): |
| 150 | + New. |
| 151 | + * sysdeps/x86/cpu-features.c: Include <libc-internal.h>. |
| 152 | + (get_common_indeces): Set xsave_state_size and |
| 153 | + bit_arch_XSAVEC_Usable if needed. |
| 154 | + (init_cpu_features): Remove bit_arch_Use_dl_runtime_resolve_slow |
| 155 | + and bit_arch_Use_dl_runtime_resolve_opt. |
| 156 | + * sysdeps/x86/cpu-features.h (bit_arch_Use_dl_runtime_resolve_opt): |
| 157 | + Removed. |
| 158 | + (bit_arch_Use_dl_runtime_resolve_slow): Likewise. |
| 159 | + (bit_arch_Prefer_No_AVX512): Updated. |
| 160 | + (bit_arch_MathVec_Prefer_No_AVX512): Likewise. |
| 161 | + (bit_arch_XSAVEC_Usable): New. |
| 162 | + (STATE_SAVE_OFFSET): Likewise. |
| 163 | + (STATE_SAVE_MASK): Likewise. |
| 164 | + [__ASSEMBLER__]: Include <cpu-features-offsets.h>. |
| 165 | + (cpu_features): Add xsave_state_size. |
| 166 | + (index_arch_Use_dl_runtime_resolve_opt): Removed. |
| 167 | + (index_arch_Use_dl_runtime_resolve_slow): Likewise. |
| 168 | + (index_arch_XSAVEC_Usable): New. |
| 169 | + * sysdeps/x86_64/dl-machine.h (elf_machine_runtime_setup): |
| 170 | + Replace _dl_runtime_resolve_sse, _dl_runtime_resolve_avx, |
| 171 | + _dl_runtime_resolve_avx_slow, _dl_runtime_resolve_avx_opt, |
| 172 | + _dl_runtime_resolve_avx512 and _dl_runtime_resolve_avx512_opt |
| 173 | + with _dl_runtime_resolve_fxsave, _dl_runtime_resolve_xsave and |
| 174 | + _dl_runtime_resolve_xsavec. |
| 175 | + * sysdeps/x86_64/dl-trampoline.S (DL_RUNTIME_UNALIGNED_VEC_SIZE): |
| 176 | + Removed. |
| 177 | + (DL_RUNTIME_RESOLVE_REALIGN_STACK): Check STATE_SAVE_ALIGNMENT |
| 178 | + instead of VEC_SIZE. |
| 179 | + (REGISTER_SAVE_BND0): Removed. |
| 180 | + (REGISTER_SAVE_BND1): Likewise. |
| 181 | + (REGISTER_SAVE_BND3): Likewise. |
| 182 | + (REGISTER_SAVE_RAX): Always defined to 0. |
| 183 | + (VMOV): Removed. |
| 184 | + (_dl_runtime_resolve_avx): Likewise. |
| 185 | + (_dl_runtime_resolve_avx_slow): Likewise. |
| 186 | + (_dl_runtime_resolve_avx_opt): Likewise. |
| 187 | + (_dl_runtime_resolve_avx512): Likewise. |
| 188 | + (_dl_runtime_resolve_avx512_opt): Likewise. |
| 189 | + (_dl_runtime_resolve_sse): Likewise. |
| 190 | + (_dl_runtime_resolve_sse_vex): Likewise. |
| 191 | + (USE_FXSAVE): New. |
| 192 | + (_dl_runtime_resolve_fxsave): Likewise. |
| 193 | + (USE_XSAVE): Likewise. |
| 194 | + (_dl_runtime_resolve_xsave): Likewise. |
| 195 | + (USE_XSAVEC): Likewise. |
| 196 | + (_dl_runtime_resolve_xsavec): Likewise. |
| 197 | + * sysdeps/x86_64/dl-trampoline.h (_dl_runtime_resolve_avx512): |
| 198 | + Removed. |
| 199 | + (_dl_runtime_resolve_avx512_opt): Likewise. |
| 200 | + (_dl_runtime_resolve_avx): Likewise. |
| 201 | + (_dl_runtime_resolve_avx_opt): Likewise. |
| 202 | + (_dl_runtime_resolve_sse): Likewise. |
| 203 | + (_dl_runtime_resolve_sse_vex): Likewise. |
| 204 | + (_dl_runtime_resolve_fxsave): New. |
| 205 | + (_dl_runtime_resolve_xsave): Likewise. |
| 206 | + (_dl_runtime_resolve_xsavec): Likewise. |
| 207 | + |
| 208 | +2017-10-19 H.J. Lu <hongjiu.lu@intel.com> |
| 209 | + |
| 210 | + * sysdeps/x86_64/Makefile (tests): Add tst-sse, tst-avx and |
| 211 | + tst-avx512. |
| 212 | + (test-extras): Add tst-avx-aux and tst-avx512-aux. |
| 213 | + (extra-test-objs): Add tst-avx-aux.o and tst-avx512-aux.o. |
| 214 | + (modules-names): Add tst-ssemod, tst-avxmod and tst-avx512mod. |
| 215 | + ($(objpfx)tst-sse): New rule. |
| 216 | + ($(objpfx)tst-avx): Likewise. |
| 217 | + ($(objpfx)tst-avx512): Likewise. |
| 218 | + (CFLAGS-tst-avx-aux.c): New. |
| 219 | + (CFLAGS-tst-avxmod.c): Likewise. |
| 220 | + (CFLAGS-tst-avx512-aux.c): Likewise. |
| 221 | + (CFLAGS-tst-avx512mod.c): Likewise. |
| 222 | + * sysdeps/x86_64/tst-avx-aux.c: New file. |
| 223 | + * sysdeps/x86_64/tst-avx.c: Likewise. |
| 224 | + * sysdeps/x86_64/tst-avx512-aux.c: Likewise. |
| 225 | + * sysdeps/x86_64/tst-avx512.c: Likewise. |
| 226 | + * sysdeps/x86_64/tst-avx512mod.c: Likewise. |
| 227 | + * sysdeps/x86_64/tst-avxmod.c: Likewise. |
| 228 | + * sysdeps/x86_64/tst-sse.c: Likewise. |
| 229 | + * sysdeps/x86_64/tst-ssemod.c: Likewise. |
| 230 | + |
| 231 | +2017-10-19 H.J. Lu <hongjiu.lu@intel.com> |
| 232 | + |
| 233 | + * sysdeps/x86_64/dl-trampoline.h (_dl_runtime_resolve): Don't |
| 234 | + adjust CFA when allocating register save area on re-aligned |
| 235 | + stack. |
| 236 | + |
| 237 | +2016-12-21 Joseph Myers <joseph@codesourcery.com> |
| 238 | + |
| 239 | + [BZ #20978] |
| 240 | + * nis/nss_nisplus/nisplus-alias.c (_nss_nisplus_getaliasbyname_r): |
| 241 | + Compare name == NULL, not name != NULL. |
| 242 | + |
| 243 | +2016-11-08 Joseph Myers <joseph@codesourcery.com> |
| 244 | + |
| 245 | + [BZ #20790] |
| 246 | + * sunrpc/rpc_parse.c (get_prog_declaration): Increase buffer size |
| 247 | + to MAXLINESIZE. |
| 248 | + * sunrpc/bug20790.x: New file. |
| 249 | + * sunrpc/Makefile [$(run-built-tests) = yes] (rpcgen-tests): New |
| 250 | + variable. |
| 251 | + [$(run-built-tests) = yes] (tests-special): Add $(rpcgen-tests). |
| 252 | + [$(run-built-tests) = yes] ($(rpcgen-tests)): New rule. |
| 253 | + |
| 254 | +2016-10-14 Steve Ellcey <sellcey@caviumnetworks.com> |
| 255 | + |
| 256 | + * sysdeps/ieee754/dbl-64/e_pow.c (checkint) Make conditions explicitly |
| 257 | + boolean. |
| 258 | + |
| 259 | +2017-07-19 DJ Delorie <dj@delorie.com> |
| 260 | + |
| 261 | + [BZ #21654] |
| 262 | + * grp/grp-merge.c (libc_hidden_def): Fix cast-after-dereference. |
| 263 | + |
| 264 | +2017-07-14 DJ Delorie <dj@redhat.com> |
| 265 | + |
| 266 | + [BZ #21654] |
| 267 | + * grp/grp_merge.c (__copy_grp): Align char** to minimum pointer |
| 268 | + alignment not char alignment. |
| 269 | + (__merge_grp): Likewise. |
| 270 | + |
| 271 | +2017-08-06 H.J. Lu <hongjiu.lu@intel.com> |
| 272 | + |
| 273 | + [BZ #21871] |
| 274 | + * sysdeps/x86/cpu-features.c (init_cpu_features): Set |
| 275 | + bit_arch_Use_dl_runtime_resolve_opt only with AVX512F. |
| 276 | + |
| 277 | +2017-02-27 Florian Weimer <fweimer@redhat.com> |
| 278 | + |
| 279 | + [BZ #21115] |
| 280 | + * sunrpc/clnt_udp.c (clntudp_call): Free ancillary data later. |
| 281 | + * sunrpc/Makefile (tests): Add tst-udp-error. |
| 282 | + (tst-udp-error): Link against libc.so explicitly. |
| 283 | + * sunrpc/tst-udp-error: New file. |
| 284 | + |
| 285 | +2017-01-24 James Clarke <jrtc27@jrtc27.com> |
| 286 | + |
| 287 | + * sysdeps/unix/sysv/linux/sh/sh3/ucontext_i.sym: Use new REG_R* |
| 288 | + constants instead of the old R* ones. |
| 289 | + * sysdeps/unix/sysv/linux/sh/sh4/ucontext_i.sym: Likewise. |
| 290 | + * sysdeps/unix/sysv/linux/sh/sys/ucontext.h (NGPREG): Rename... |
| 291 | + (NGREG): ... to this, to fit in with other architectures. |
| 292 | + (gpregset_t): Use new NGREG macro. |
| 293 | + [__USE_GNU]: Remove condition; all architectures other than tile |
| 294 | + are unconditional. |
| 295 | + (R*): Rename to REG_R*. |
| 296 | + |
| 297 | +2017-07-26 H.J. Lu <hongjiu.lu@intel.com> |
| 298 | + |
| 299 | + [BZ #21666] |
| 300 | + * misc/regexp.c (loc1): Add __attribute__ ((nocommon)); |
| 301 | + (loc2): Likewise. |
| 302 | + (locs): Likewise. |
| 303 | + |
| 304 | +2017-07-12 Szabolcs Nagy <szabolcs.nagy@arm.com> |
| 305 | + |
| 306 | + * sysdeps/aarch64/dl-machine.h (RTLD_START_1): Change _dl_argv to the |
| 307 | + hidden __GI__dl_argv symbol. |
| 308 | + |
| 309 | +2016-09-05 Aurelien Jarno <aurelien@aurel32.net> |
| 310 | + |
| 311 | + * conform/Makefile (conformtest-header-tests): Pass -I. to $(PERL). |
| 312 | + (linknamespace-symlists-tests): Likewise. |
| 313 | + (linknamespace-header-tests): Likewise. |
| 314 | + |
| 315 | +2017-07-06 Florian Weimer <fweimer@redhat.com> |
| 316 | + H.J. Lu <hongjiu.lu@intel.com> |
| 317 | + |
| 318 | + [BZ #21609] |
| 319 | + * sysdeps/x86_64/Makefile (sysdep-dl-routines): Add tls_get_addr. |
| 320 | + (gen-as-const-headers): Add rtld-offsets.sym. |
| 321 | + * sysdeps/x86_64/dl-tls.c: New file. |
| 322 | + * sysdeps/x86_64/rtld-offsets.sym: Likwise. |
| 323 | + * sysdeps/x86_64/tls_get_addr.S: Likewise. |
| 324 | + * sysdeps/x86_64/dl-tls.h: Add multiple inclusion guards. |
| 325 | + * sysdeps/x86_64/tlsdesc.sym (TI_MODULE_OFFSET): New. |
| 326 | + (TI_OFFSET_OFFSET): Likwise. |
| 327 | + |
| 328 | +2017-06-14 Florian Weimer <fweimer@redhat.com> |
| 329 | + |
| 330 | + * sysdeps/i386/i686/multiarch/strcspn-c.c: Add IS_IN (libc) guard. |
| 331 | + * sysdeps/i386/i686/multiarch/varshift.c: Likewise. |
| 332 | + |
| 333 | +2017-03-07 Siddhesh Poyarekar <siddhesh@sourceware.org> |
| 334 | + |
| 335 | + [BZ #21209] |
| 336 | + * elf/rtld.c (process_envvars): Ignore LD_HWCAP_MASK for |
| 337 | + AT_SECURE processes. |
| 338 | + * sysdeps/generic/unsecvars.h: Add LD_HWCAP_MASK. |
| 339 | + |
| 340 | +2017-06-19 Florian Weimer <fweimer@redhat.com> |
| 341 | + |
| 342 | + * elf/rtld.c (audit_list_string): New variable. |
| 343 | + (audit_list): Update comment. |
| 344 | + (struct audit_list_iter): Define. |
| 345 | + (audit_list_iter_init, audit_list_iter_next): New function. |
| 346 | + (dl_main): Use struct audit_list_iter to process audit modules. |
| 347 | + (process_dl_audit): Call dso_name_valid_for_suid. |
| 348 | + (process_envvars): Set audit_list_string instead of calling |
| 349 | + process_dl_audit. |
| 350 | + |
| 351 | +2017-06-19 Florian Weimer <fweimer@redhat.com> |
| 352 | + |
| 353 | + * elf/rtld.c (SECURE_NAME_LIMIT, SECURE_PATH_LIMIT): Define. |
| 354 | + (dso_name_valid_for_suid): New function. |
| 355 | + (handle_ld_preload): Likewise. |
| 356 | + (dl_main): Call it. Remove alloca. |
| 357 | + |
| 358 | +2017-06-19 Florian Weimer <fweimer@redhat.com> |
| 359 | + |
| 360 | + [BZ #21624] |
| 361 | + CVE-2017-1000366 |
| 362 | + * elf/rtld.c (process_envvars): Ignore LD_LIBRARY_PATH for |
| 363 | + __libc_enable_secure. |
| 364 | + |
| 365 | +2017-02-01 Andreas Schwab <schwab@linux-m68k.org> |
| 366 | + |
| 367 | + * sysdeps/m68k/m680x0/m68020/atomic-machine.h |
| 368 | + (__arch_compare_and_exchange_val_64_acq, atomic_exchange_acq) |
| 369 | + (atomic_exchange_and_add, atomic_add): Add casts to 64 bit asm |
| 370 | + operands. |
| 371 | + |
| 372 | +2017-05-12 Florian Weimer <fweimer@redhat.com> |
| 373 | + |
| 374 | + [BZ #21386] |
| 375 | + * sysdeps/nptl/fork.c (__libc_fork): Remove assertions on the |
| 376 | + parent PID. The assertion in the child is incorrect with PID |
| 377 | + namespaces. |
| 378 | + |
| 379 | +2017-06-07 Arjun Shankar <arjun.is@lostca.se> |
| 380 | + |
| 381 | + * sysdeps/unix/sysv/linux/tst-clone2.c: Do not |
| 382 | + include test-skeleton.c. |
| 383 | + Include support/check.h and support/test-driver.c. |
| 384 | + |
| 385 | +2016-11-24 Adhemerval Zanella <adhemerval.zanella@linaro.org> |
| 386 | + |
| 387 | + * sysdeps/nptl/fork.c (__libc_fork): Remove pid cache setting. |
| 388 | + * nptl/allocatestack.c (allocate_stack): Likewise. |
| 389 | + (__reclaim_stacks): Likewise. |
| 390 | + (setxid_signal_thread): Obtain pid through syscall. |
| 391 | + * nptl/nptl-init.c (sigcancel_handler): Likewise. |
| 392 | + (sighandle_setxid): Likewise. |
| 393 | + * nptl/pthread_cancel.c (pthread_cancel): Likewise. |
| 394 | + * sysdeps/unix/sysv/linux/pthread_kill.c (__pthread_kill): Likewise. |
| 395 | + * sysdeps/unix/sysv/linux/pthread_sigqueue.c (pthread_sigqueue): |
| 396 | + Likewise. |
| 397 | + * sysdeps/unix/sysv/linux/createthread.c (create_thread): Likewise. |
| 398 | + * sysdeps/unix/sysv/linux/raise.c (raise): Remove old behaviour |
| 399 | + comment. |
| 400 | + * sysdeps/unix/sysv/linux/getpid.c: Remove file. |
| 401 | + * nptl/descr.h (struct pthread): Change comment about pid value. |
| 402 | + * nptl/pthread_getattr_np.c (pthread_getattr_np): Remove thread |
| 403 | + pid assert. |
| 404 | + * sysdeps/unix/sysv/linux/pthread-pids.h (__pthread_initialize_pids): |
| 405 | + Do not set pid value. |
| 406 | + * nptl_db/td_ta_thr_iter.c (iterate_thread_list): Remove thread |
| 407 | + pid cache check. |
| 408 | + * nptl_db/td_thr_validate.c (td_thr_validate): Likewise. |
| 409 | + * sysdeps/aarch64/nptl/tcb-offsets.sym: Remove pid offset. |
| 410 | + * sysdeps/alpha/nptl/tcb-offsets.sym: Likewise. |
| 411 | + * sysdeps/arm/nptl/tcb-offsets.sym: Likewise. |
| 412 | + * sysdeps/hppa/nptl/tcb-offsets.sym: Likewise. |
| 413 | + * sysdeps/i386/nptl/tcb-offsets.sym: Likewise. |
| 414 | + * sysdeps/ia64/nptl/tcb-offsets.sym: Likewise. |
| 415 | + * sysdeps/m68k/nptl/tcb-offsets.sym: Likewise. |
| 416 | + * sysdeps/microblaze/nptl/tcb-offsets.sym: Likewise. |
| 417 | + * sysdeps/mips/nptl/tcb-offsets.sym: Likewise. |
| 418 | + * sysdeps/nios2/nptl/tcb-offsets.sym: Likewise. |
| 419 | + * sysdeps/powerpc/nptl/tcb-offsets.sym: Likewise. |
| 420 | + * sysdeps/s390/nptl/tcb-offsets.sym: Likewise. |
| 421 | + * sysdeps/sh/nptl/tcb-offsets.sym: Likewise. |
| 422 | + * sysdeps/sparc/nptl/tcb-offsets.sym: Likewise. |
| 423 | + * sysdeps/tile/nptl/tcb-offsets.sym: Likewise. |
| 424 | + * sysdeps/x86_64/nptl/tcb-offsets.sym: Likewise. |
| 425 | + * sysdeps/unix/sysv/linux/aarch64/clone.S: Remove pid and tid caching. |
| 426 | + * sysdeps/unix/sysv/linux/alpha/clone.S: Likewise. |
| 427 | + * sysdeps/unix/sysv/linux/arm/clone.S: Likewise. |
| 428 | + * sysdeps/unix/sysv/linux/hppa/clone.S: Likewise. |
| 429 | + * sysdeps/unix/sysv/linux/i386/clone.S: Likewise. |
| 430 | + * sysdeps/unix/sysv/linux/ia64/clone2.S: Likewise. |
| 431 | + * sysdeps/unix/sysv/linux/mips/clone.S: Likewise. |
| 432 | + * sysdeps/unix/sysv/linux/nios2/clone.S: Likewise. |
| 433 | + * sysdeps/unix/sysv/linux/powerpc/powerpc32/clone.S: Likewise. |
| 434 | + * sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S: Likewise. |
| 435 | + * sysdeps/unix/sysv/linux/s390/s390-32/clone.S: Likewise. |
| 436 | + * sysdeps/unix/sysv/linux/s390/s390-64/clone.S: Likewise. |
| 437 | + * sysdeps/unix/sysv/linux/sh/clone.S: Likewise. |
| 438 | + * sysdeps/unix/sysv/linux/sparc/sparc32/clone.S: Likewise. |
| 439 | + * sysdeps/unix/sysv/linux/sparc/sparc64/clone.S: Likewise. |
| 440 | + * sysdeps/unix/sysv/linux/tile/clone.S: Likewise. |
| 441 | + * sysdeps/unix/sysv/linux/x86_64/clone.S: Likewise. |
| 442 | + * sysdeps/unix/sysv/linux/aarch64/vfork.S: Remove pid set and reset. |
| 443 | + * sysdeps/unix/sysv/linux/alpha/vfork.S: Likewise. |
| 444 | + * sysdeps/unix/sysv/linux/arm/vfork.S: Likewise. |
| 445 | + * sysdeps/unix/sysv/linux/i386/vfork.S: Likewise. |
| 446 | + * sysdeps/unix/sysv/linux/ia64/vfork.S: Likewise. |
| 447 | + * sysdeps/unix/sysv/linux/m68k/clone.S: Likewise. |
| 448 | + * sysdeps/unix/sysv/linux/m68k/vfork.S: Likewise. |
| 449 | + * sysdeps/unix/sysv/linux/mips/vfork.S: Likewise. |
| 450 | + * sysdeps/unix/sysv/linux/nios2/vfork.S: Likewise. |
| 451 | + * sysdeps/unix/sysv/linux/powerpc/powerpc32/vfork.S: Likewise. |
| 452 | + * sysdeps/unix/sysv/linux/powerpc/powerpc64/vfork.S: Likewise. |
| 453 | + * sysdeps/unix/sysv/linux/s390/s390-32/vfork.S: Likewise. |
| 454 | + * sysdeps/unix/sysv/linux/s390/s390-64/vfork.S: Likewise. |
| 455 | + * sysdeps/unix/sysv/linux/sh/vfork.S: Likewise. |
| 456 | + * sysdeps/unix/sysv/linux/sparc/sparc32/vfork.S: Likewise. |
| 457 | + * sysdeps/unix/sysv/linux/sparc/sparc64/vfork.S: Likewise. |
| 458 | + * sysdeps/unix/sysv/linux/tile/vfork.S: Likewise. |
| 459 | + * sysdeps/unix/sysv/linux/x86_64/vfork.S: Likewise. |
| 460 | + * sysdeps/unix/sysv/linux/hppa/pt-vfork.S: Likewise. |
| 461 | + * sysdeps/unix/sysv/linux/tst-clone2.c (f): Remove direct pthread |
| 462 | + struct access. |
| 463 | + (clone_test): Remove function. |
| 464 | + (do_test): Rewrite to take in consideration pid is not cached anymore. |
| 465 | + |
| 466 | +2016-09-26 Adhemerval Zanella <adhemerval.zanella@linaro.org> |
| 467 | + |
| 468 | + * sysdeps/unix/sysdep.h (__INTERNAL_SYSCALL0): New macro. |
| 469 | + (__INTERNAL_SYSCALL1): Likewise. |
| 470 | + (__INTERNAL_SYSCALL2): Likewise. |
| 471 | + (__INTERNAL_SYSCALL3): Likewise. |
| 472 | + (__INTERNAL_SYSCALL4): Likewise. |
| 473 | + (__INTERNAL_SYSCALL5): Likewise. |
| 474 | + (__INTERNAL_SYSCALL6): Likewise. |
| 475 | + (__INTERNAL_SYSCALL7): Likewise. |
| 476 | + (__INTERNAL_SYSCALL_NARGS_X): Likewise. |
| 477 | + (__INTERNAL_SYSCALL_NARGS): Likewise. |
| 478 | + (__INTERNAL_SYSCALL_DISP): Likewise. |
| 479 | + (INTERNAL_SYSCALL_CALL): Likewise. |
| 480 | + (__SYSCALL0): Rename to __INLINE_SYSCALL0. |
| 481 | + (__SYSCALL1): Rename to __INLINE_SYSCALL1. |
| 482 | + (__SYSCALL2): Rename to __INLINE_SYSCALL2. |
| 483 | + (__SYSCALL3): Rename to __INLINE_SYSCALL3. |
| 484 | + (__SYSCALL4): Rename to __INLINE_SYSCALL4. |
| 485 | + (__SYSCALL5): Rename to __INLINE_SYSCALL5. |
| 486 | + (__SYSCALL6): Rename to __INLINE_SYSCALL6. |
| 487 | + (__SYSCALL7): Rename to __INLINE_SYSCALL7. |
| 488 | + (__SYSCALL_NARGS_X): Rename to __INLINE_SYSCALL_NARGS_X. |
| 489 | + (__SYSCALL_NARGS): Rename to __INLINE_SYSCALL_NARGS. |
| 490 | + (__SYSCALL_DISP): Rename to __INLINE_SYSCALL_DISP. |
| 491 | + (__SYSCALL_CALL): Rename to INLINE_SYSCALL_CALL. |
| 492 | + (SYSCALL_CANCEL): Replace __SYSCALL_CALL with INLINE_SYSCALL_CALL. |
| 493 | + |
| 494 | +2017-04-28 H.J. Lu <hongjiu.lu@intel.com> |
| 495 | + |
| 496 | + [BZ #21396] |
| 497 | + * sysdeps/x86/cpu-features.c (init_cpu_features): Set |
| 498 | + Prefer_No_AVX512 if AVX512ER isn't available. |
| 499 | + * sysdeps/x86/cpu-features.h (bit_arch_Prefer_No_AVX512): New. |
| 500 | + (index_arch_Prefer_No_AVX512): Likewise. |
| 501 | + * sysdeps/x86_64/multiarch/memcpy.S (__new_memcpy): Don't use |
| 502 | + AVX512 version if Prefer_No_AVX512 is set. |
| 503 | + * sysdeps/x86_64/multiarch/memcpy_chk.S (__memcpy_chk): |
| 504 | + Likewise. |
| 505 | + * sysdeps/x86_64/multiarch/memmove.S (__libc_memmove): Likewise. |
| 506 | + * sysdeps/x86_64/multiarch/memmove_chk.S (__memmove_chk): |
| 507 | + Likewise. |
| 508 | + * sysdeps/x86_64/multiarch/mempcpy.S (__mempcpy): Likewise. |
| 509 | + * sysdeps/x86_64/multiarch/mempcpy_chk.S (__mempcpy_chk): |
| 510 | + Likewise. |
| 511 | + * sysdeps/x86_64/multiarch/memset.S (memset): Likewise. |
| 512 | + * sysdeps/x86_64/multiarch/memset_chk.S (__memset_chk): |
| 513 | + Likewise. |
| 514 | + |
| 515 | +2017-04-28 H.J. Lu <hongjiu.lu@intel.com> |
| 516 | + |
| 517 | + * sysdeps/x86/cpu-features.c (init_cpu_features): Set |
| 518 | + Prefer_No_VZEROUPPER if AVX512ER is available. |
| 519 | + * sysdeps/x86/cpu-features.h |
| 520 | + (bit_cpu_AVX512PF): New. |
| 521 | + (bit_cpu_AVX512ER): Likewise. |
| 522 | + (bit_cpu_AVX512CD): Likewise. |
| 523 | + (bit_cpu_AVX512BW): Likewise. |
| 524 | + (bit_cpu_AVX512VL): Likewise. |
| 525 | + (index_cpu_AVX512PF): Likewise. |
| 526 | + (index_cpu_AVX512ER): Likewise. |
| 527 | + (index_cpu_AVX512CD): Likewise. |
| 528 | + (index_cpu_AVX512BW): Likewise. |
| 529 | + (index_cpu_AVX512VL): Likewise. |
| 530 | + (reg_AVX512PF): Likewise. |
| 531 | + (reg_AVX512ER): Likewise. |
| 532 | + (reg_AVX512CD): Likewise. |
| 533 | + (reg_AVX512BW): Likewise. |
| 534 | + (reg_AVX512VL): Likewise. |
| 535 | + |
| 536 | +2017-01-05 Joseph Myers <joseph@codesourcery.com> |
| 537 | + |
| 538 | + [BZ #21026] |
| 539 | + * sysdeps/unix/sysv/linux/mips/mips64/n64/syscalls.list |
| 540 | + (readahead): New syscall entry. |
| 541 | + |
| 542 | +2017-04-07 H.J. Lu <hongjiu.lu@intel.com> |
| 543 | + |
| 544 | + [BZ #21258] |
| 545 | + * sysdeps/x86_64/dl-trampoline.S (_dl_runtime_resolve_opt): |
| 546 | + Define only if _dl_runtime_resolve is defined to |
| 547 | + _dl_runtime_resolve_sse_vex. |
| 548 | + * sysdeps/x86_64/dl-trampoline.h (_dl_runtime_resolve_opt): |
| 549 | + Fallthrough to _dl_runtime_resolve_sse_vex. |
| 550 | + |
| 551 | +2017-04-03 Mike Frysinger <vapier@gentoo.org> |
| 552 | + |
| 553 | + [BZ #21253] |
| 554 | + * sysdeps/unix/sysv/linux/spawni.c (__spawnix): Increase argv_size |
| 555 | + slack space by 32KiB. |
| 556 | + |
| 557 | +2017-03-31 Slava Barinov <v.barinov@samsung.com> |
| 558 | + |
| 559 | + [BZ #21289] |
| 560 | + * io/fts.h (fts_set): Replace __REDIRECT with __REDIRECT_NTH. |
| 561 | + |
| 562 | +2017-03-20 Mike Frysinger <vapier@gentoo.org> |
| 563 | + |
| 564 | + [BZ #21275] |
| 565 | + * sysdeps/unix/sysv/linux/spawni.c [__ia64__] (CLONE): Rename |
| 566 | + __stack to __stackbase. |
| 567 | + (STACK): Invert _STACK_GROWS_DOWN and _STACK_GROWS_UP order of |
| 568 | + checks so we can include defined(__ia64__) first. |
| 569 | + |
| 570 | +2017-03-15 John David Anglin <danglin@gcc.gnu.org> |
| 571 | + |
| 572 | + * sysdeps/hppa/dl-machine.h (DL_STACK_END): Define. |
| 573 | + (RTLD_START): Don't record stack end address in _dl_start_user. |
| 574 | + |
| 575 | +2017-01-30 H.J. Lu <hongjiu.lu@intel.com> |
| 576 | + |
| 577 | + [BZ #21081] |
| 578 | + * sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S |
| 579 | + (L(stosb)): Add VZEROUPPER before ret. |
| 580 | + |
| 581 | +2016-11-28 H.J. Lu <hongjiu.lu@intel.com> |
| 582 | + |
| 583 | + [BZ #20750] |
| 584 | + * sysdeps/x86_64/sysdep.h (JUMPTARGET): Check SHARED instead |
| 585 | + of PIC. |
| 586 | + |
| 587 | +2016-12-31 Florian Weimer <fweimer@redhat.com> |
| 588 | + |
| 589 | + [BZ #18784] |
| 590 | + CVE-2015-5180 |
| 591 | + * include/arpa/nameser_compat.h (T_QUERY_A_AND_AAAA): Rename from |
| 592 | + T_UNSPEC. Adjust value. |
| 593 | + * resolv/nss_dns/dns-host.c (_nss_dns_gethostbyname4_r): Use it. |
| 594 | + * resolv/res_query.c (__libc_res_nquery): Likewise. |
| 595 | + * resolv/res_mkquery.c (res_nmkquery): Check for out-of-range |
| 596 | + QTYPEs. |
| 597 | + * resolv/tst-resolv-qtypes.c: New file. |
| 598 | + * resolv/Makefile (xtests): Add tst-resolv-qtypes. |
| 599 | + (tst-resolv-qtypes): Link against libresolv and libpthread. |
| 600 | + |
| 601 | +2017-02-02 Siddhesh Poyarekar <siddhesh@sourceware.org> |
| 602 | + |
| 603 | + * sysdeps/generic/unsecvars.h: Add GLIBC_TUNABLES. |
| 604 | + |
| 605 | +2017-01-23 Rajalakshmi Srinivasaraghavan <raji@linux.vnet.ibm.com> |
| 606 | + Steven Munroe <sjmunroe@us.ibm.com> |
| 607 | + Tulio Magno Quites Machado Filho <tuliom@linux.vnet.ibm.com> |
| 608 | + |
| 609 | + [BZ #20822] |
| 610 | + * sysdeps/unix/sysv/linux/powerpc/elision-lock.c |
| 611 | + (__lll_lock_elision): Access adapt_count via C11 atomics. |
| 612 | + * sysdeps/unix/sysv/linux/powerpc/elision-trylock.c |
| 613 | + (__lll_trylock_elision): Likewise. |
| 614 | + * sysdeps/unix/sysv/linux/powerpc/elision-unlock.c |
| 615 | + (__lll_unlock_elision): Update adapt_count variable inside the |
| 616 | + critical section using C11 atomics. |
| 617 | + |
| 618 | +2016-12-24 Carlos O'Donell <carlos@redhat.com> |
| 619 | + |
| 620 | + [BZ #11941] |
| 621 | + * elf/dl-close.c (_dl_close): Take dl_load_lock to examine map. |
| 622 | + Remove assert (map->l_init_called); if DF_1_NODELETE is set. |
| 623 | + * elf/Makefile [ifeq (yes,$(build-shared))] (tests): Add |
| 624 | + tst-nodelete-dlclose. |
| 625 | + (modules-names): Add tst-nodelete-dlclose-dso and |
| 626 | + tst-nodelete-dlclose-plugin. |
| 627 | + ($(objpfx)tst-nodelete-dlclose-dso.so): Define. |
| 628 | + ($(objpfx)tst-nodelete-dlclose-plugin.so): Define. |
| 629 | + ($(objpfx)tst-nodelete-dlclose): Define. |
| 630 | + ($(objpfx)tst-nodelete-dlclose.out): Define. |
| 631 | + |
| 632 | +2016-08-02 Aurelien Jarno <aurelien@aurel32.net> |
| 633 | + |
| 634 | +2016-08-02 Aurelien Jarno <aurelien@aurel32.net> |
| 635 | + |
| 636 | + * sysdeps/alpha/fpu/s_ceil.c (__ceil): Add argument with itself |
| 637 | + when it is a NaN. |
| 638 | + [_IEEE_FP_INEXACT] Remove. |
| 639 | + * sysdeps/alpha/fpu/s_ceilf.c (__ceilf): Likewise. |
| 640 | + * sysdeps/alpha/fpu/s_floor.c (__floor): Add argument with itself |
| 641 | + when it is a NaN. |
| 642 | + [_IEEE_FP_INEXACT] Remove. |
| 643 | + * sysdeps/alpha/fpu/s_floorf.c (__floorf): Likewise. |
| 644 | + * sysdeps/alpha/fpu/s_rint.c (__rint): Add argument with itself |
| 645 | + when it is a NaN. |
| 646 | + * sysdeps/alpha/fpu/s_rintf.c (__rintf): Likewise. |
| 647 | + * sysdeps/alpha/fpu/s_trunc.c (__trunc): Return the input value |
| 648 | + when its absolute value is greater than 0x1.0p52. |
| 649 | + [_IEEE_FP_INEXACT] Remove. |
| 650 | + * sysdeps/alpha/fpu/s_truncf.c (__truncf): Return the input value |
| 651 | + when its absolute value is greater than 0x1.0p23. |
| 652 | + [_IEEE_FP_INEXACT] Remove. |
| 653 | + |
| 654 | +2016-11-30 H.J. Lu <hongjiu.lu@intel.com> |
| 655 | + |
| 656 | + [BZ #20495] |
| 657 | + [BZ #20508] |
| 658 | + * sysdeps/x86/cpu-features.c (init_cpu_features): For Intel |
| 659 | + processors, set Use_dl_runtime_resolve_slow and set |
| 660 | + Use_dl_runtime_resolve_opt if XGETBV suports ECX == 1. |
| 661 | + * sysdeps/x86/cpu-features.h (bit_arch_Use_dl_runtime_resolve_opt): |
| 662 | + New. |
| 663 | + (bit_arch_Use_dl_runtime_resolve_slow): Likewise. |
| 664 | + (index_arch_Use_dl_runtime_resolve_opt): Likewise. |
| 665 | + (index_arch_Use_dl_runtime_resolve_slow): Likewise. |
| 666 | + * sysdeps/x86_64/dl-machine.h (elf_machine_runtime_setup): Use |
| 667 | + _dl_runtime_resolve_avx512_opt and _dl_runtime_resolve_avx_opt |
| 668 | + if Use_dl_runtime_resolve_opt is set. Use |
| 669 | + _dl_runtime_resolve_slow if Use_dl_runtime_resolve_slow is set. |
| 670 | + * sysdeps/x86_64/dl-trampoline.S: Include <cpu-features.h>. |
| 671 | + (_dl_runtime_resolve_opt): New. Defined for AVX and AVX512. |
| 672 | + (_dl_runtime_resolve): Add one for _dl_runtime_resolve_sse_vex. |
| 673 | + * sysdeps/x86_64/dl-trampoline.h (_dl_runtime_resolve_avx_slow): |
| 674 | + New. |
| 675 | + (_dl_runtime_resolve_opt): Likewise. |
| 676 | + (_dl_runtime_profile): Define only if _dl_runtime_profile is |
| 677 | + defined. |
| 678 | + |
| 679 | +2016-11-24 Aurelien Jarno <aurelien@aurel32.net> |
| 680 | + |
| 681 | + * sysdeps/x86_64/memcpy_chk.S (__memcpy_chk): Check for SHARED |
| 682 | + instead of PIC. |
| 683 | + |
| 684 | +2016-11-23 Matthew Fortune <Matthew.Fortune@imgtec.com> |
| 685 | + Maciej W. Rozycki <macro@imgtec.com> |
| 686 | + |
| 687 | + * sysdeps/mips/mips32/crti.S (_init): Add `.insn' pseudo-op at |
| 688 | + `.Lno_weak_fn' label. |
| 689 | + * sysdeps/mips/mips64/n32/crti.S (_init): Likewise. |
| 690 | + * sysdeps/mips/mips64/n64/crti.S (_init): Likewise. |
| 691 | + |
| 692 | +2016-11-22 Adhemerval Zanella <adhemerva.zanella@linaro.org> |
| 693 | + |
| 694 | + [BZ #20847] |
| 695 | + * posix/execvpe.c (maybe_script_execute): Remove write past allocated |
| 696 | + array bounds. |
| 697 | + (__execvpe): Likewise. |
| 698 | + |
| 699 | +2016-11-15 Denis Kaganovich <mahatma@eu.by> |
| 700 | + Magnus Granberg <zorry@gentoo.org> |
| 701 | + Mike Frysinger <vapier@gentoo.org> |
| 702 | + |
| 703 | + [BZ #20662] |
| 704 | + * configure.ac (libc_cv_predef_stack_protector): Also check for |
| 705 | + __stack_chk_fail_local symbols. |
| 706 | + * configure: Regenerated. |
| 707 | + |
| 708 | +2016-11-03 Joseph Myers <joseph@codesourcery.com> |
| 709 | + |
| 710 | + * conform/Makefile ($(linknamespace-header-tests)): Also depend on |
| 711 | + $(linknamespace-symlists-tests). |
| 712 | + |
| 713 | +2016-11-06 Aurelien Jarno <aurelien@aurel32.net> |
| 714 | + |
| 715 | + * iconv/gconv.h (__gconv_info): Define __data element using a |
| 716 | + zero-length array. |
| 717 | + |
| 718 | +2016-10-25 Joseph Myers <joseph@codesourcery.com> |
| 719 | + |
| 720 | + * sysdeps/powerpc/powerpc32/power6/memset.S (memset): Use cmplwi |
| 721 | + instead of cmpli. |
| 722 | + * sysdeps/powerpc/powerpc64/power6/memset.S (memset): Use cmpldi |
| 723 | + instead of cmpli. |
| 724 | + |
| 725 | +2016-10-24 Adhemerval Zanella <adhemerval.zanella@linaro.org> |
| 726 | + |
| 727 | + * sysdeps/unix/sysv/linux/pread.c (__libc_pread): Use SYSCALL_LL_PRW. |
| 728 | + * sysdeps/unix/sysv/linux/pwrite.c (__libc_pwrite): Likewise. |
| 729 | + * sysdeps/unix/sysv/linux/pread64.c (__libc_pread64): Use |
| 730 | + SYSCALL_LL64_PRW. |
| 731 | + * sysdeps/unix/sysv/linux/pwrite64.c (__libc_pwrite64): Likewise. |
| 732 | + * sysdeps/unix/sysv/linux/sh/kernel-features.h: Define |
| 733 | + __ASSUME_PRW_DUMMY_ARG. |
| 734 | + * sysdeps/unix/sysv/linux/sh/pread.c: Remove file. |
| 735 | + * sysdeps/unix/sysv/linux/sh/pread64.c: Likewise. |
| 736 | + * sysdeps/unix/sysv/linux/sh/pwrite.c: Likewise. |
| 737 | + * sysdeps/unix/sysv/linux/sh/pwrite64.c: Likewise. |
| 738 | + * sysdeps/unix/sysv/linux/sysdep.h: Define SYSCALL_LL_PRW and |
| 739 | + SYSCALL_LL_PRW64 based on __ASSUME_PRW_DUMMY_ARG. |
| 740 | + |
| 741 | +2016-10-05 Tulio Magno Quites Machado Filho <tuliom@linux.vnet.ibm.com> |
| 742 | + |
| 743 | + * sysdeps/powerpc/fpu/libm-test-ulps: Regenerated. |
| 744 | + |
| 745 | +2016-09-20 Adhemerval Zanella <adhemerval.zanella@linaro.org> |
| 746 | + |
| 747 | + * sysdeps/unix/sysv/linux/spawni.c (__spawnix): Correctly block and unblock |
| 748 | + all signals when executing the clone vfork child. |
| 749 | + (SIGALL_SET): Remove macro. |
| 750 | + |
| 751 | + * nptl/Makefile (tests): Add tst-exec5. |
| 752 | + * nptl/tst-exec5.c: New file. |
| 753 | + * sysdeps/unix/sysv/linux/spawni.c (__spawni): Correctly enable and disable |
| 754 | + asynchronous cancellation. |
| 755 | + |
| 756 | +2016-09-19 Tulio Magno Quites Machado Filho <tuliom@linux.vnet.ibm.com> |
| 757 | + |
| 758 | + [BZ #20615] |
| 759 | + * sysdeps/powerpc/powerpc32/power9/multiarch/Implies: Replace |
| 760 | + fpu directory by non-fpu. |
| 761 | + * sysdeps/powerpc/powerpc64/power9/fpu/Implies: Remove dependency |
| 762 | + on non-fpu directory from a fpu directory. |
| 763 | + |
| 764 | +2016-09-02 Roland McGrath <roland@hack.frob.com> |
| 765 | + |
| 766 | + * sysdeps/arm/nacl/libc.abilist: Add GLIBC_2.24 A. |
| 767 | + |
| 768 | + * sysdeps/nacl/dup.c: Add libc_hidden_def. |
| 769 | + |
| 770 | +2016-09-02 Roland McGrath <roland@hack.frob.com> |
| 771 | + |
| 772 | + * sysdeps/posix/wait3.c: Don't treat STAT_LOC as a union, since it's |
| 773 | + not any more. |
| 774 | + |
| 775 | +2016-09-02 Roland McGrath <roland@hack.frob.com> |
| 776 | + |
| 777 | + * sysdeps/nacl/clock.c (clock): nacl_abi_clock_t -> nacl_irt_clock_t |
| 778 | + |
| 779 | +2016-08-17 Florian Weimer <fweimer@redhat.com> |
| 780 | + |
| 781 | + Reduce time to expected nptl/tst-once5 failure. |
| 782 | + * nptl/tst-once5.cc (TIMEOUT): Define. |
| 783 | + |
| 784 | +2016-08-18 Florian Weimer <fweimer@redhat.com> |
| 785 | + |
| 786 | + [BZ #16907] |
| 787 | + * argp/argp.h: Switch to __BEGIN_DECLS and __END_DECLS. |
| 788 | + (__THROW, __NTH, __attribute__, __restrict): Remove definitions. |
| 789 | + * argp/argp-fmtstream.h: Add __BEGIN_DECLS and __END_DECLS. |
| 790 | + (__attribute__): Remove definition. |
| 791 | + |
| 792 | +2016-08-15 Andreas Schwab <schwab@suse.de> |
| 793 | + |
| 794 | + [BZ #20435] |
| 795 | + * sysdeps/unix/sysv/linux/arm/setcontext.S (__startcontext): Mark |
| 796 | + as .cantunwind. |
| 797 | + |
| 798 | +2016-08-17 Florian Weimer <fweimer@redhat.com> |
| 799 | + |
| 800 | + [BZ #20452] |
| 801 | + Avoid additional copies of objects in libc.a in static libraries. |
| 802 | + * sysdeps/ia64/nptl/Makefile (libpthread-shared-only-routines): |
| 803 | + Add ptw-sysdep, ptw-sigblock, ptw-sigprocmask. |
| 804 | + * sysdeps/mips/Makefile (librt-shared-only-routines): Add |
| 805 | + rt-sysdep. |
| 806 | + * sysdeps/mips/nptl/Makefile (libpthread-shared-only-routines): |
| 807 | + Add nptl-sysdep. |
| 808 | + * sysdeps/s390/nptl/Makefile (libpthread-shared-only-routines): |
| 809 | + Add ptw-sysdep. |
| 810 | + * sysdeps/unix/alpha/Makefile (librt-shared-only-routines): Add |
| 811 | + rt-sysdep. |
| 812 | + * sysdeps/unix/sysv/linux/alpha/Makefile |
| 813 | + (libpthread-shared-only-routines): Add ptw-sysdep, |
| 814 | + ptw-sigprocmask, ptw-rt_sigaction. |
| 815 | + * sysdeps/unix/sysv/linux/ia64/Makefile |
| 816 | + (librt-shared-only-routines): Add rt-sysdep. |
| 817 | + * sysdeps/unix/sysv/linux/i386/Makefile |
| 818 | + (libpthread-shared-only-routines): Add libc-do-syscall. |
| 819 | + * sysdeps/unix/sysv/linux/microblaze/Makefile |
| 820 | + (libpthread-shared-only-routines): Add sysdep. |
| 821 | + * sysdeps/unix/sysv/linux/powerpc/Makefile |
| 822 | + (librt-shared-only-routines): Add rt-sysdep. |
| 823 | + (libpthread-shared-only-routines): Add sysdep. |
| 824 | + * sysdeps/unix/sysv/linux/s390/Makefile |
| 825 | + (librt-shared-only-routines): Add rt-sysdep. |
| 826 | + * sysdeps/unix/sysv/linux/sparc/Makefile |
| 827 | + (librt-shared-only-routines): Add rt-sysdep. |
| 828 | + (libpthread-shared-only-routines): Add sysdep. |
| 829 | + * sysdeps/unix/sysv/linux/tile/Makefile |
| 830 | + (libpthread-shared-only-routines): Likewise. |
| 831 | + |
| 832 | +2016-08-05 Aurelien Jarno <aurelien@aurel32.net> |
| 833 | + |
| 834 | + * sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/Makefile |
| 835 | + [$(subdir) = math && $(have-as-vis3) = yes] (libm-sysdep_routines): |
| 836 | + Remove s_fdimf-vis3, s_fdim-vis3. |
| 837 | + * sysdeps/sparc/sparc32/fpu/s_fdim.S: Delete file. |
| 838 | + * sysdeps/sparc/sparc32/fpu/s_fdimf.S: Likewise. |
| 839 | + * sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_fdim-vis3.S: Likewise. |
| 840 | + * sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_fdim.S: Likewise. |
| 841 | + * sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_fdimf-vis3.S: Likewise. |
| 842 | + * sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_fdimf.S: Likewise. |
| 843 | + * sysdeps/sparc/sparc32/sparcv9/fpu/s_fdim.S: Likewise. |
| 844 | + * sysdeps/sparc/sparc32/sparcv9/fpu/s_fdimf.S: Likewise. |
| 845 | + * sysdeps/sparc/sparc64/fpu/s_fdim.S: Likewise. |
| 846 | + * sysdeps/sparc/sparc64/fpu/s_fdimf.S: Likewise. |
| 847 | + |
| 848 | +2016-08-02 David S. Miller <davem@davemloft.net> |
| 849 | + |
| 850 | + * sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_nearbyint-vis3.S |
| 851 | + (__nearbyint_vis3): Don't check for sNaN before float register is |
| 852 | + loaded with the incoming argument. |
| 853 | + * sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_nearbyintf-vis3.S |
| 854 | + (__nearbyintf_vis3): Likewise. |
| 855 | + * sysdeps/sparc/sparc32/sparcv9/fpu/s_nearbyint.S (__nearbyint): |
| 856 | + Likewise. |
| 857 | + * sysdeps/sparc/sparc32/sparcv9/fpu/s_nearbyintf.S (__nearbyintf): |
| 858 | + Likewise. |
| 859 | + |
| 860 | +2016-08-03 Aurelien Jarno <aurelien@aurel32.net> |
| 861 | + |
| 862 | + * sysdeps/powerpc/ifunc-sel.h (ifunc_sel): Replace beqlr instructions |
| 863 | + by beq instructions jumping to the end of the function. |
| 864 | + * sysdeps/powerpc/ifunc-sel.h (ifunc_sel): Add "11", "12", "cr0" to the |
| 865 | + clobber list. Use "i" constraint instead of "X". |
| 866 | + (ifunc_one): Add "12" to the clobber list. Use "i" constraint instead |
| 867 | + of "X". |
| 868 | + |
| 869 | +2016-08-04 Carlos O'Donell <carlos@redhat.com> |
| 870 | + |
| 871 | + * po/de.po: Update from Translation Project. |
| 872 | + * po/fi.po: Likewise. |
| 873 | + * po/sv.po: Likewise. |
| 874 | + |
| 875 | +2016-08-02 Florian Weimer <fweimer@redhat.com> |
| 876 | + |
| 877 | + [BZ #20370] |
| 878 | + * malloc/arena.c (get_free_list): Update comment. Assert that |
| 879 | + arenas on the free list have no attached threads. |
| 880 | + (remove_from_free_list): New function. |
| 881 | + (reused_arena): Call it. |
| 882 | + |
| 883 | +2016-08-04 Florian Weimer <fweimer@redhat.com> |
| 884 | + |
| 885 | + Use sysdep.o from libc.a in static libraries. |
| 886 | + * sysdeps/unix/sysv/linux/i386/Makefile |
| 887 | + (libpthread-shared-only-routines): Add sysdep. |
| 888 | + (librt-shared-only-routines): Likewise. |
| 889 | + |
| 890 | 2016-08-01 Carlos O'Donell <carlos@redhat.com> |
| 891 | |
| 892 | * version.h (RELEASE): Set to "stable" |
| 893 | diff --git a/Makeconfig b/Makeconfig |
| 894 | index 03fd89c13e..ee379f5852 100644 |
| 895 | --- a/Makeconfig |
| 896 | +++ b/Makeconfig |
| 897 | @@ -394,6 +394,9 @@ ifndef after-link |
| 898 | after-link = |
| 899 | endif |
| 900 | |
| 901 | +# Additional libraries to link into every test. |
| 902 | +link-extra-libs-tests = $(libsupport) |
| 903 | + |
| 904 | # Command for linking PIE programs with the C library. |
| 905 | ifndef +link-pie |
| 906 | +link-pie-before-libc = $(CC) -pie -Wl,-O1 -nostdlib -nostartfiles -o $@ \ |
| 907 | @@ -503,7 +506,7 @@ link-libc = $(link-libc-rpath-link) $(link-libc-before-gnulib) $(gnulib) |
| 908 | link-libc-tests = $(link-libc-tests-rpath-link) \ |
| 909 | $(link-libc-before-gnulib) $(gnulib-tests) |
| 910 | # This is how to find at build-time things that will be installed there. |
| 911 | -rpath-dirs = math elf dlfcn nss nis rt resolv crypt mathvec |
| 912 | +rpath-dirs = math elf dlfcn nss nis rt resolv crypt mathvec support |
| 913 | rpath-link = \ |
| 914 | $(common-objdir):$(subst $(empty) ,:,$(patsubst ../$(subdir),.,$(rpath-dirs:%=$(common-objpfx)%))) |
| 915 | else |
| 916 | @@ -850,7 +853,7 @@ libio-include = -I$(..)libio |
| 917 | # List of non-library modules that we build. |
| 918 | built-modules = iconvprogs iconvdata ldconfig lddlibc4 libmemusage \ |
| 919 | libSegFault libpcprofile librpcsvc locale-programs \ |
| 920 | - memusagestat nonlib nscd extramodules libnldbl |
| 921 | + memusagestat nonlib nscd extramodules libnldbl libsupport |
| 922 | |
| 923 | in-module = $(subst -,_,$(firstword $(libof-$(basename $(@F))) \ |
| 924 | $(libof-$(<F)) \ |
| 925 | @@ -1089,6 +1092,12 @@ libm = $(common-objpfx)math/libm.a |
| 926 | libmvec = $(common-objpfx)mathvec/libmvec.a |
| 927 | endif |
| 928 | |
| 929 | +ifeq ($(build-shared),yes) |
| 930 | +libsupport = $(common-objpfx)support/libsupport_nonshared.a |
| 931 | +else |
| 932 | +libsupport = $(common-objpfx)support/libsupport.a |
| 933 | +endif |
| 934 | + |
| 935 | # These are the subdirectories containing the library source. The order |
| 936 | # is more or less arbitrary. The sorting step will take care of the |
| 937 | # dependencies. |
| 938 | @@ -1096,7 +1105,7 @@ all-subdirs = csu assert ctype locale intl catgets math setjmp signal \ |
| 939 | stdlib stdio-common libio malloc string wcsmbs time dirent \ |
| 940 | grp pwd posix io termios resource misc socket sysvipc gmon \ |
| 941 | gnulib iconv iconvdata wctype manual shadow gshadow po argp \ |
| 942 | - crypt localedata timezone rt conform debug mathvec \ |
| 943 | + crypt localedata timezone rt conform debug mathvec support \ |
| 944 | $(add-on-subdirs) dlfcn elf |
| 945 | |
| 946 | ifndef avoid-generated |
| 947 | diff --git a/NEWS b/NEWS |
| 948 | index b0447e7169..20e30028cf 100644 |
| 949 | --- a/NEWS |
| 950 | +++ b/NEWS |
| 951 | @@ -5,6 +5,68 @@ See the end for copying conditions. |
| 952 | Please send GNU C library bug reports via <http://sourceware.org/bugzilla/> |
| 953 | using `glibc' in the "product" field. |
| 954 | \f |
| 955 | +Version 2.24.1 |
| 956 | + |
| 957 | +Security related changes: |
| 958 | + |
| 959 | +* On ARM EABI (32-bit), generating a backtrace for execution contexts which |
| 960 | + have been created with makecontext could fail to terminate due to a |
| 961 | + missing .cantunwind annotation. This has been observed to lead to a hang |
| 962 | + (denial of service) in some Go applications compiled with gccgo. Reported |
| 963 | + by Andreas Schwab. (CVE-2016-6323) |
| 964 | + |
| 965 | +* The DNS stub resolver functions would crash due to a NULL pointer |
| 966 | + dereference when processing a query with a valid DNS question type which |
| 967 | + was used internally in the implementation. The stub resolver now uses a |
| 968 | + question type which is outside the range of valid question type values. |
| 969 | + (CVE-2015-5180) |
| 970 | + |
| 971 | +* CVE-2017-15670: The glob function, when invoked with GLOB_TILDE, suffered |
| 972 | + from a one-byte overflow during ~ operator processing (either on the stack |
| 973 | + or the heap, depending on the length of the user name). |
| 974 | + |
| 975 | +* CVE-2017-15671: The glob function, when invoked with GLOB_TILDE, |
| 976 | + would sometimes fail to free memory allocated during ~ operator |
| 977 | + processing, leading to a memory leak and, potentially, to a denial |
| 978 | + of service. |
| 979 | + |
| 980 | +* CVE-2017-15804: The glob function, when invoked with GLOB_TILDE and |
| 981 | + without GLOB_NOESCAPE, could write past the end of a buffer while |
| 982 | + unescaping user names. Reported by Tim Rühsen. |
| 983 | + |
| 984 | +* CVE-2017-1000408: Incorrect array size computation in _dl_init_paths leads |
| 985 | + to the allocation of too much memory. (This is not a security bug per se, |
| 986 | + it is mentioned here only because of the CVE assignment.) Reported by |
| 987 | + Qualys. |
| 988 | + |
| 989 | +* CVE-2017-1000409: Buffer overflow in _dl_init_paths due to miscomputation |
| 990 | + of the number of search path components. (This is not a security |
| 991 | + vulnerability per se because no trust boundary is crossed if the fix for |
| 992 | + CVE-2017-1000366 has been applied, but it is mentioned here only because |
| 993 | + of the CVE assignment.) Reported by Qualys. |
| 994 | + |
| 995 | + CVE-2017-16997: Incorrect handling of RPATH or RUNPATH containing $ORIGIN |
| 996 | + for AT_SECURE or SUID binaries could be used to load libraries from the |
| 997 | + current directory. |
| 998 | + |
| 999 | + CVE-2018-1000001: Buffer underflow in realpath function when getcwd function |
| 1000 | + succeeds without returning an absolute path due to unexpected behaviour |
| 1001 | + of the Linux kernel getcwd syscall. Reported by halfdog. |
| 1002 | + |
| 1003 | +The following bugs are resolved with this release: |
| 1004 | + |
| 1005 | + [20790] Fix rpcgen buffer overrun |
| 1006 | + [20978] Fix strlen on null pointer in nss_nisplus |
| 1007 | + [21209] Ignore and remove LD_HWCAP_MASK for AT_SECURE programs |
| 1008 | + [21265] x86-64: Use fxsave/xsave/xsavec in _dl_runtime_resolve |
| 1009 | + [21289] Fix symbol redirect for fts_set |
| 1010 | + [21386] Assertion in fork for distinct parent PID is incorrect |
| 1011 | + [21609] x86-64: Align the stack in __tls_get_addr |
| 1012 | + [21624] Unsafe alloca allows local attackers to alias stack and heap (CVE-2017-1000366) |
| 1013 | + [21654] nss: Fix invalid cast in group merging |
| 1014 | + [22679] getcwd(3) can succeed without returning an absolute path |
| 1015 | + (CVE-2018-1000001) |
| 1016 | +\f |
| 1017 | Version 2.24 |
| 1018 | |
| 1019 | * The minimum Linux kernel version that this version of the GNU C Library |
| 1020 | diff --git a/Rules b/Rules |
| 1021 | index 8306d36a07..a981965d2b 100644 |
| 1022 | --- a/Rules |
| 1023 | +++ b/Rules |
| 1024 | @@ -149,6 +149,7 @@ endif |
| 1025 | |
| 1026 | ifneq "$(strip $(binaries-shared-tests))" "" |
| 1027 | $(addprefix $(objpfx),$(binaries-shared-tests)): %: %.o \ |
| 1028 | + $(link-extra-libs-tests) \ |
| 1029 | $(sort $(filter $(common-objpfx)lib%,$(link-libc))) \ |
| 1030 | $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit) |
| 1031 | $(+link-tests) |
| 1032 | @@ -156,6 +157,7 @@ endif |
| 1033 | |
| 1034 | ifneq "$(strip $(binaries-pie-tests))" "" |
| 1035 | $(addprefix $(objpfx),$(binaries-pie-tests)): %: %.o \ |
| 1036 | + $(link-extra-libs-tests) \ |
| 1037 | $(sort $(filter $(common-objpfx)lib%,$(link-libc))) \ |
| 1038 | $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit) |
| 1039 | $(+link-pie-tests) |
| 1040 | @@ -177,6 +179,7 @@ endif |
| 1041 | |
| 1042 | ifneq "$(strip $(binaries-static-tests))" "" |
| 1043 | $(addprefix $(objpfx),$(binaries-static-tests)): %: %.o \ |
| 1044 | + $(link-extra-libs-tests) \ |
| 1045 | $(sort $(filter $(common-objpfx)lib%,$(link-libc-static-tests))) \ |
| 1046 | $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit) |
| 1047 | $(+link-static-tests) |
| 1048 | diff --git a/argp/argp-fmtstream.h b/argp/argp-fmtstream.h |
| 1049 | index bdeaa54dc2..e8c5797f38 100644 |
| 1050 | --- a/argp/argp-fmtstream.h |
| 1051 | +++ b/argp/argp-fmtstream.h |
| 1052 | @@ -29,21 +29,6 @@ |
| 1053 | #include <string.h> |
| 1054 | #include <unistd.h> |
| 1055 | |
| 1056 | -#ifndef __attribute__ |
| 1057 | -/* This feature is available in gcc versions 2.5 and later. */ |
| 1058 | -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || \ |
| 1059 | - defined __STRICT_ANSI__ |
| 1060 | -# define __attribute__(Spec) /* empty */ |
| 1061 | -# endif |
| 1062 | -/* The __-protected variants of `format' and `printf' attributes |
| 1063 | - are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ |
| 1064 | -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) || \ |
| 1065 | - defined __STRICT_ANSI__ |
| 1066 | -# define __format__ format |
| 1067 | -# define __printf__ printf |
| 1068 | -# endif |
| 1069 | -#endif |
| 1070 | - |
| 1071 | #if defined (__GNU_LIBRARY__) && defined (HAVE_LINEWRAP_H) |
| 1072 | /* line_wrap_stream is available, so use that. */ |
| 1073 | #define ARGP_FMTSTREAM_USE_LINEWRAP |
| 1074 | @@ -111,6 +96,8 @@ struct argp_fmtstream |
| 1075 | |
| 1076 | typedef struct argp_fmtstream *argp_fmtstream_t; |
| 1077 | |
| 1078 | +__BEGIN_DECLS |
| 1079 | + |
| 1080 | /* Return an argp_fmtstream that outputs to STREAM, and which prefixes lines |
| 1081 | written on it with LMARGIN spaces and limits them to RMARGIN columns |
| 1082 | total. If WMARGIN >= 0, words that extend past RMARGIN are wrapped by |
| 1083 | @@ -297,6 +284,8 @@ __argp_fmtstream_point (argp_fmtstream_t __fs) |
| 1084 | |
| 1085 | #endif /* __OPTIMIZE__ */ |
| 1086 | |
| 1087 | +__END_DECLS |
| 1088 | + |
| 1089 | #endif /* ARGP_FMTSTREAM_USE_LINEWRAP */ |
| 1090 | |
| 1091 | #endif /* argp-fmtstream.h */ |
| 1092 | diff --git a/argp/argp.h b/argp/argp.h |
| 1093 | index e67bbef739..7cb5a69f08 100644 |
| 1094 | --- a/argp/argp.h |
| 1095 | +++ b/argp/argp.h |
| 1096 | @@ -28,48 +28,12 @@ |
| 1097 | #define __need_error_t |
| 1098 | #include <errno.h> |
| 1099 | |
| 1100 | -#ifndef __THROW |
| 1101 | -# define __THROW |
| 1102 | -#endif |
| 1103 | -#ifndef __NTH |
| 1104 | -# define __NTH(fct) fct __THROW |
| 1105 | -#endif |
| 1106 | - |
| 1107 | -#ifndef __attribute__ |
| 1108 | -/* This feature is available in gcc versions 2.5 and later. */ |
| 1109 | -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || \ |
| 1110 | - defined __STRICT_ANSI__ |
| 1111 | -# define __attribute__(Spec) /* empty */ |
| 1112 | -# endif |
| 1113 | -/* The __-protected variants of `format' and `printf' attributes |
| 1114 | - are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ |
| 1115 | -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) || \ |
| 1116 | - defined __STRICT_ANSI__ |
| 1117 | -# define __format__ format |
| 1118 | -# define __printf__ printf |
| 1119 | -# endif |
| 1120 | -#endif |
| 1121 | - |
| 1122 | -/* GCC 2.95 and later have "__restrict"; C99 compilers have |
| 1123 | - "restrict", and "configure" may have defined "restrict". */ |
| 1124 | -#ifndef __restrict |
| 1125 | -# if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__)) |
| 1126 | -# if defined restrict || 199901L <= __STDC_VERSION__ |
| 1127 | -# define __restrict restrict |
| 1128 | -# else |
| 1129 | -# define __restrict |
| 1130 | -# endif |
| 1131 | -# endif |
| 1132 | -#endif |
| 1133 | - |
| 1134 | #ifndef __error_t_defined |
| 1135 | typedef int error_t; |
| 1136 | # define __error_t_defined |
| 1137 | #endif |
| 1138 | \f |
| 1139 | -#ifdef __cplusplus |
| 1140 | -extern "C" { |
| 1141 | -#endif |
| 1142 | +__BEGIN_DECLS |
| 1143 | |
| 1144 | /* A description of a particular option. A pointer to an array of |
| 1145 | these is passed in the OPTIONS field of an argp structure. Each option |
| 1146 | @@ -590,8 +554,6 @@ __NTH (__option_is_end (const struct argp_option *__opt)) |
| 1147 | # endif |
| 1148 | #endif /* Use extern inlines. */ |
| 1149 | |
| 1150 | -#ifdef __cplusplus |
| 1151 | -} |
| 1152 | -#endif |
| 1153 | +__END_DECLS |
| 1154 | |
| 1155 | #endif /* argp.h */ |
| 1156 | diff --git a/configure b/configure |
| 1157 | index 17625e1041..9b5a486048 100755 |
| 1158 | --- a/configure |
| 1159 | +++ b/configure |
| 1160 | @@ -6289,12 +6289,14 @@ echo >&5 "libc_undefs='$libc_undefs'" |
| 1161 | # symbols (resolved by the linker), so filter out unknown symbols. |
| 1162 | # This will fail to produce the correct result if the compiler |
| 1163 | # defaults to -fstack-protector but this produces an undefined symbol |
| 1164 | -# other than __stack_chk_fail. However, compilers like that have not |
| 1165 | -# been encountered in practice. |
| 1166 | -libc_undefs=`echo "$libc_undefs" | egrep '^(foobar|__stack_chk_fail)$'` |
| 1167 | +# other than __stack_chk_fail or __stack_chk_fail_local. However, |
| 1168 | +# compilers like that have not been encountered in practice. |
| 1169 | +libc_undefs=`echo "$libc_undefs" | \ |
| 1170 | + egrep '^(foobar|__stack_chk_fail|__stack_chk_fail_local)$'` |
| 1171 | case "$libc_undefs" in |
| 1172 | foobar) libc_cv_predef_stack_protector=no ;; |
| 1173 | '__stack_chk_fail |
| 1174 | +foobar'|'__stack_chk_fail_local |
| 1175 | foobar') libc_cv_predef_stack_protector=yes ;; |
| 1176 | *) as_fn_error $? "unexpected symbols in test: $libc_undefs" "$LINENO" 5 ;; |
| 1177 | esac |
| 1178 | diff --git a/configure.ac b/configure.ac |
| 1179 | index 33bcd62180..8277d9f727 100644 |
| 1180 | --- a/configure.ac |
| 1181 | +++ b/configure.ac |
| 1182 | @@ -1626,12 +1626,14 @@ echo >&AS_MESSAGE_LOG_FD "libc_undefs='$libc_undefs'" |
| 1183 | # symbols (resolved by the linker), so filter out unknown symbols. |
| 1184 | # This will fail to produce the correct result if the compiler |
| 1185 | # defaults to -fstack-protector but this produces an undefined symbol |
| 1186 | -# other than __stack_chk_fail. However, compilers like that have not |
| 1187 | -# been encountered in practice. |
| 1188 | -libc_undefs=`echo "$libc_undefs" | egrep '^(foobar|__stack_chk_fail)$'` |
| 1189 | +# other than __stack_chk_fail or __stack_chk_fail_local. However, |
| 1190 | +# compilers like that have not been encountered in practice. |
| 1191 | +libc_undefs=`echo "$libc_undefs" | \ |
| 1192 | + egrep '^(foobar|__stack_chk_fail|__stack_chk_fail_local)$'` |
| 1193 | case "$libc_undefs" in |
| 1194 | foobar) libc_cv_predef_stack_protector=no ;; |
| 1195 | '__stack_chk_fail |
| 1196 | +foobar'|'__stack_chk_fail_local |
| 1197 | foobar') libc_cv_predef_stack_protector=yes ;; |
| 1198 | *) AC_MSG_ERROR([unexpected symbols in test: $libc_undefs]) ;; |
| 1199 | esac], |
| 1200 | diff --git a/conform/Makefile b/conform/Makefile |
| 1201 | index 32a0937b06..7883624c81 100644 |
| 1202 | --- a/conform/Makefile |
| 1203 | +++ b/conform/Makefile |
| 1204 | @@ -196,13 +196,13 @@ $(conformtest-header-tests): $(objpfx)%/conform.out: \ |
| 1205 | conformtest.pl $(conformtest-headers-data) |
| 1206 | (set -e; std_hdr=$*; std=$${std_hdr%%/*}; hdr=$${std_hdr#*/}; \ |
| 1207 | mkdir -p $(@D)/scratch; \ |
| 1208 | - $(PERL) conformtest.pl --tmpdir=$(@D)/scratch --cc='$(CC)' \ |
| 1209 | + $(PERL) -I. conformtest.pl --tmpdir=$(@D)/scratch --cc='$(CC)' \ |
| 1210 | --flags='$(conformtest-cc-flags)' --standard=$$std \ |
| 1211 | --headers=$$hdr > $@); \ |
| 1212 | $(evaluate-test) |
| 1213 | |
| 1214 | $(linknamespace-symlists-tests): $(objpfx)symlist-%: list-header-symbols.pl |
| 1215 | - $(PERL) -w $< --tmpdir=$(objpfx) --cc='$(CC)' \ |
| 1216 | + $(PERL) -I. -w $< --tmpdir=$(objpfx) --cc='$(CC)' \ |
| 1217 | --flags='$(conformtest-cc-flags)' --standard=$* \ |
| 1218 | --headers="$(strip $(conformtest-headers-$*))" \ |
| 1219 | > $@ 2> $@.err; \ |
| 1220 | @@ -229,10 +229,11 @@ $(linknamespace-symlist-stdlibs-tests): $(objpfx)symlist-stdlibs-%: \ |
| 1221 | |
| 1222 | $(linknamespace-header-tests): $(objpfx)%/linknamespace.out: \ |
| 1223 | linknamespace.pl \ |
| 1224 | + $(linknamespace-symlists-tests) \ |
| 1225 | $(linknamespace-symlist-stdlibs-tests) |
| 1226 | (set -e; std_hdr=$*; std=$${std_hdr%%/*}; hdr=$${std_hdr#*/}; \ |
| 1227 | mkdir -p $(@D)/scratch; \ |
| 1228 | - $(PERL) -w $< --tmpdir=$(@D)/scratch --cc='$(CC)' \ |
| 1229 | + $(PERL) -I. -w $< --tmpdir=$(@D)/scratch --cc='$(CC)' \ |
| 1230 | --flags='$(conformtest-cc-flags)' --standard=$$std \ |
| 1231 | --stdsyms=$(objpfx)symlist-$$std --header=$$hdr \ |
| 1232 | --libsyms=$(objpfx)symlist-stdlibs-$$std \ |
| 1233 | diff --git a/elf/Makefile b/elf/Makefile |
| 1234 | index 593403c640..847a012f84 100644 |
| 1235 | --- a/elf/Makefile |
| 1236 | +++ b/elf/Makefile |
| 1237 | @@ -149,7 +149,8 @@ tests += loadtest restest1 preloadtest loadfail multiload origtest resolvfail \ |
| 1238 | tst-nodelete) \ |
| 1239 | tst-initorder tst-initorder2 tst-relsort1 tst-null-argv \ |
| 1240 | tst-ptrguard1 tst-tlsalign tst-tlsalign-extern tst-nodelete-opened \ |
| 1241 | - tst-nodelete2 tst-audit11 tst-audit12 tst-dlsym-error |
| 1242 | + tst-nodelete2 tst-audit11 tst-audit12 tst-dlsym-error \ |
| 1243 | + tst-nodelete-dlclose |
| 1244 | # reldep9 |
| 1245 | ifeq ($(build-hardcoded-path-in-tests),yes) |
| 1246 | tests += tst-dlopen-aout |
| 1247 | @@ -223,7 +224,8 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \ |
| 1248 | tst-array5dep tst-null-argv-lib \ |
| 1249 | tst-tlsalign-lib tst-nodelete-opened-lib tst-nodelete2mod \ |
| 1250 | tst-audit11mod1 tst-audit11mod2 tst-auditmod11 \ |
| 1251 | - tst-audit12mod1 tst-audit12mod2 tst-audit12mod3 tst-auditmod12 |
| 1252 | + tst-audit12mod1 tst-audit12mod2 tst-audit12mod3 tst-auditmod12 \ |
| 1253 | + tst-nodelete-dlclose-dso tst-nodelete-dlclose-plugin |
| 1254 | ifeq (yes,$(have-mtls-dialect-gnu2)) |
| 1255 | tests += tst-gnu2-tls1 |
| 1256 | modules-names += tst-gnu2-tls1mod |
| 1257 | @@ -1267,3 +1269,12 @@ $(objpfx)tst-ldconfig-X.out : tst-ldconfig-X.sh $(objpfx)ldconfig |
| 1258 | $(evaluate-test) |
| 1259 | |
| 1260 | $(objpfx)tst-dlsym-error: $(libdl) |
| 1261 | + |
| 1262 | +# The application depends on the DSO, and the DSO loads the plugin. |
| 1263 | +# The plugin also depends on the DSO. This creates the circular |
| 1264 | +# dependency via dlopen that we're testing to make sure works. |
| 1265 | +$(objpfx)tst-nodelete-dlclose-dso.so: $(libdl) |
| 1266 | +$(objpfx)tst-nodelete-dlclose-plugin.so: $(objpfx)tst-nodelete-dlclose-dso.so |
| 1267 | +$(objpfx)tst-nodelete-dlclose: $(objpfx)tst-nodelete-dlclose-dso.so |
| 1268 | +$(objpfx)tst-nodelete-dlclose.out: $(objpfx)tst-nodelete-dlclose-dso.so \ |
| 1269 | + $(objpfx)tst-nodelete-dlclose-plugin.so |
| 1270 | diff --git a/elf/dl-close.c b/elf/dl-close.c |
| 1271 | index 687d7de874..9f93ab7628 100644 |
| 1272 | --- a/elf/dl-close.c |
| 1273 | +++ b/elf/dl-close.c |
| 1274 | @@ -805,19 +805,37 @@ _dl_close (void *_map) |
| 1275 | { |
| 1276 | struct link_map *map = _map; |
| 1277 | |
| 1278 | - /* First see whether we can remove the object at all. */ |
| 1279 | + /* We must take the lock to examine the contents of map and avoid |
| 1280 | + concurrent dlopens. */ |
| 1281 | + __rtld_lock_lock_recursive (GL(dl_load_lock)); |
| 1282 | + |
| 1283 | + /* At this point we are guaranteed nobody else is touching the list of |
| 1284 | + loaded maps, but a concurrent dlclose might have freed our map |
| 1285 | + before we took the lock. There is no way to detect this (see below) |
| 1286 | + so we proceed assuming this isn't the case. First see whether we |
| 1287 | + can remove the object at all. */ |
| 1288 | if (__glibc_unlikely (map->l_flags_1 & DF_1_NODELETE)) |
| 1289 | { |
| 1290 | - assert (map->l_init_called); |
| 1291 | /* Nope. Do nothing. */ |
| 1292 | + __rtld_lock_unlock_recursive (GL(dl_load_lock)); |
| 1293 | return; |
| 1294 | } |
| 1295 | |
| 1296 | + /* At present this is an unreliable check except in the case where the |
| 1297 | + caller has recursively called dlclose and we are sure the link map |
| 1298 | + has not been freed. In a non-recursive dlclose the map itself |
| 1299 | + might have been freed and this access is potentially a data race |
| 1300 | + with whatever other use this memory might have now, or worse we |
| 1301 | + might silently corrupt memory if it looks enough like a link map. |
| 1302 | + POSIX has language in dlclose that appears to guarantee that this |
| 1303 | + should be a detectable case and given that dlclose should be threadsafe |
| 1304 | + we need this to be a reliable detection. |
| 1305 | + This is bug 20990. */ |
| 1306 | if (__builtin_expect (map->l_direct_opencount, 1) == 0) |
| 1307 | - GLRO(dl_signal_error) (0, map->l_name, NULL, N_("shared object not open")); |
| 1308 | - |
| 1309 | - /* Acquire the lock. */ |
| 1310 | - __rtld_lock_lock_recursive (GL(dl_load_lock)); |
| 1311 | + { |
| 1312 | + __rtld_lock_unlock_recursive (GL(dl_load_lock)); |
| 1313 | + _dl_signal_error (0, map->l_name, NULL, N_("shared object not open")); |
| 1314 | + } |
| 1315 | |
| 1316 | _dl_close_worker (map, false); |
| 1317 | |
| 1318 | diff --git a/elf/dl-load.c b/elf/dl-load.c |
| 1319 | index c0d6249373..1f774e139f 100644 |
| 1320 | --- a/elf/dl-load.c |
| 1321 | +++ b/elf/dl-load.c |
| 1322 | @@ -37,6 +37,7 @@ |
| 1323 | #include <sysdep.h> |
| 1324 | #include <stap-probe.h> |
| 1325 | #include <libc-internal.h> |
| 1326 | +#include <array_length.h> |
| 1327 | |
| 1328 | #include <dl-dst.h> |
| 1329 | #include <dl-load.h> |
| 1330 | @@ -103,7 +104,9 @@ static size_t ncapstr attribute_relro; |
| 1331 | static size_t max_capstrlen attribute_relro; |
| 1332 | |
| 1333 | |
| 1334 | -/* Get the generated information about the trusted directories. */ |
| 1335 | +/* Get the generated information about the trusted directories. Use |
| 1336 | + an array of concatenated strings to avoid relocations. See |
| 1337 | + gen-trusted-dirs.awk. */ |
| 1338 | #include "trusted-dirs.h" |
| 1339 | |
| 1340 | static const char system_dirs[] = SYSTEM_DIRS; |
| 1341 | @@ -111,9 +114,7 @@ static const size_t system_dirs_len[] = |
| 1342 | { |
| 1343 | SYSTEM_DIRS_LEN |
| 1344 | }; |
| 1345 | -#define nsystem_dirs_len \ |
| 1346 | - (sizeof (system_dirs_len) / sizeof (system_dirs_len[0])) |
| 1347 | - |
| 1348 | +#define nsystem_dirs_len array_length (system_dirs_len) |
| 1349 | |
| 1350 | static bool |
| 1351 | is_trusted_path (const char *path, size_t len) |
| 1352 | @@ -433,31 +434,40 @@ fillin_rpath (char *rpath, struct r_search_path_elem **result, const char *sep, |
| 1353 | { |
| 1354 | char *cp; |
| 1355 | size_t nelems = 0; |
| 1356 | - char *to_free; |
| 1357 | |
| 1358 | while ((cp = __strsep (&rpath, sep)) != NULL) |
| 1359 | { |
| 1360 | struct r_search_path_elem *dirp; |
| 1361 | + char *to_free = NULL; |
| 1362 | + size_t len = 0; |
| 1363 | |
| 1364 | - to_free = cp = expand_dynamic_string_token (l, cp, 1); |
| 1365 | + /* `strsep' can pass an empty string. */ |
| 1366 | + if (*cp != '\0') |
| 1367 | + { |
| 1368 | + to_free = cp = expand_dynamic_string_token (l, cp, 1); |
| 1369 | |
| 1370 | - size_t len = strlen (cp); |
| 1371 | + /* expand_dynamic_string_token can return NULL in case of empty |
| 1372 | + path or memory allocation failure. */ |
| 1373 | + if (cp == NULL) |
| 1374 | + continue; |
| 1375 | |
| 1376 | - /* `strsep' can pass an empty string. This has to be |
| 1377 | - interpreted as `use the current directory'. */ |
| 1378 | - if (len == 0) |
| 1379 | - { |
| 1380 | - static const char curwd[] = "./"; |
| 1381 | - cp = (char *) curwd; |
| 1382 | - } |
| 1383 | + /* Compute the length after dynamic string token expansion and |
| 1384 | + ignore empty paths. */ |
| 1385 | + len = strlen (cp); |
| 1386 | + if (len == 0) |
| 1387 | + { |
| 1388 | + free (to_free); |
| 1389 | + continue; |
| 1390 | + } |
| 1391 | |
| 1392 | - /* Remove trailing slashes (except for "/"). */ |
| 1393 | - while (len > 1 && cp[len - 1] == '/') |
| 1394 | - --len; |
| 1395 | + /* Remove trailing slashes (except for "/"). */ |
| 1396 | + while (len > 1 && cp[len - 1] == '/') |
| 1397 | + --len; |
| 1398 | |
| 1399 | - /* Now add one if there is none so far. */ |
| 1400 | - if (len > 0 && cp[len - 1] != '/') |
| 1401 | - cp[len++] = '/'; |
| 1402 | + /* Now add one if there is none so far. */ |
| 1403 | + if (len > 0 && cp[len - 1] != '/') |
| 1404 | + cp[len++] = '/'; |
| 1405 | + } |
| 1406 | |
| 1407 | /* Make sure we don't use untrusted directories if we run SUID. */ |
| 1408 | if (__glibc_unlikely (check_trusted) && !is_trusted_path (cp, len)) |
| 1409 | @@ -621,6 +631,14 @@ decompose_rpath (struct r_search_path_struct *sps, |
| 1410 | necessary. */ |
| 1411 | free (copy); |
| 1412 | |
| 1413 | + /* There is no path after expansion. */ |
| 1414 | + if (result[0] == NULL) |
| 1415 | + { |
| 1416 | + free (result); |
| 1417 | + sps->dirs = (struct r_search_path_elem **) -1; |
| 1418 | + return false; |
| 1419 | + } |
| 1420 | + |
| 1421 | sps->dirs = result; |
| 1422 | /* The caller will change this value if we haven't used a real malloc. */ |
| 1423 | sps->malloced = 1; |
| 1424 | @@ -688,9 +706,8 @@ _dl_init_paths (const char *llp) |
| 1425 | + ncapstr * sizeof (enum r_dir_status)) |
| 1426 | / sizeof (struct r_search_path_elem)); |
| 1427 | |
| 1428 | - rtld_search_dirs.dirs[0] = (struct r_search_path_elem *) |
| 1429 | - malloc ((sizeof (system_dirs) / sizeof (system_dirs[0])) |
| 1430 | - * round_size * sizeof (struct r_search_path_elem)); |
| 1431 | + rtld_search_dirs.dirs[0] = malloc (nsystem_dirs_len * round_size |
| 1432 | + * sizeof (*rtld_search_dirs.dirs[0])); |
| 1433 | if (rtld_search_dirs.dirs[0] == NULL) |
| 1434 | { |
| 1435 | errstring = N_("cannot create cache for search path"); |
| 1436 | @@ -776,37 +793,14 @@ _dl_init_paths (const char *llp) |
| 1437 | |
| 1438 | if (llp != NULL && *llp != '\0') |
| 1439 | { |
| 1440 | - size_t nllp; |
| 1441 | - const char *cp = llp; |
| 1442 | - char *llp_tmp; |
| 1443 | - |
| 1444 | -#ifdef SHARED |
| 1445 | - /* Expand DSTs. */ |
| 1446 | - size_t cnt = DL_DST_COUNT (llp, 1); |
| 1447 | - if (__glibc_likely (cnt == 0)) |
| 1448 | - llp_tmp = strdupa (llp); |
| 1449 | - else |
| 1450 | - { |
| 1451 | - /* Determine the length of the substituted string. */ |
| 1452 | - size_t total = DL_DST_REQUIRED (l, llp, strlen (llp), cnt); |
| 1453 | - |
| 1454 | - /* Allocate the necessary memory. */ |
| 1455 | - llp_tmp = (char *) alloca (total + 1); |
| 1456 | - llp_tmp = _dl_dst_substitute (l, llp, llp_tmp, 1); |
| 1457 | - } |
| 1458 | -#else |
| 1459 | - llp_tmp = strdupa (llp); |
| 1460 | -#endif |
| 1461 | + char *llp_tmp = strdupa (llp); |
| 1462 | |
| 1463 | /* Decompose the LD_LIBRARY_PATH contents. First determine how many |
| 1464 | elements it has. */ |
| 1465 | - nllp = 1; |
| 1466 | - while (*cp) |
| 1467 | - { |
| 1468 | - if (*cp == ':' || *cp == ';') |
| 1469 | - ++nllp; |
| 1470 | - ++cp; |
| 1471 | - } |
| 1472 | + size_t nllp = 1; |
| 1473 | + for (const char *cp = llp_tmp; *cp != '\0'; ++cp) |
| 1474 | + if (*cp == ':' || *cp == ';') |
| 1475 | + ++nllp; |
| 1476 | |
| 1477 | env_path_list.dirs = (struct r_search_path_elem **) |
| 1478 | malloc ((nllp + 1) * sizeof (struct r_search_path_elem *)); |
| 1479 | diff --git a/elf/rtld.c b/elf/rtld.c |
| 1480 | index 647661ca45..8f56d6edd3 100644 |
| 1481 | --- a/elf/rtld.c |
| 1482 | +++ b/elf/rtld.c |
| 1483 | @@ -99,14 +99,121 @@ uintptr_t __pointer_chk_guard_local |
| 1484 | strong_alias (__pointer_chk_guard_local, __pointer_chk_guard) |
| 1485 | #endif |
| 1486 | |
| 1487 | +/* Length limits for names and paths, to protect the dynamic linker, |
| 1488 | + particularly when __libc_enable_secure is active. */ |
| 1489 | +#ifdef NAME_MAX |
| 1490 | +# define SECURE_NAME_LIMIT NAME_MAX |
| 1491 | +#else |
| 1492 | +# define SECURE_NAME_LIMIT 255 |
| 1493 | +#endif |
| 1494 | +#ifdef PATH_MAX |
| 1495 | +# define SECURE_PATH_LIMIT PATH_MAX |
| 1496 | +#else |
| 1497 | +# define SECURE_PATH_LIMIT 1024 |
| 1498 | +#endif |
| 1499 | + |
| 1500 | +/* Check that AT_SECURE=0, or that the passed name does not contain |
| 1501 | + directories and is not overly long. Reject empty names |
| 1502 | + unconditionally. */ |
| 1503 | +static bool |
| 1504 | +dso_name_valid_for_suid (const char *p) |
| 1505 | +{ |
| 1506 | + if (__glibc_unlikely (__libc_enable_secure)) |
| 1507 | + { |
| 1508 | + /* Ignore pathnames with directories for AT_SECURE=1 |
| 1509 | + programs, and also skip overlong names. */ |
| 1510 | + size_t len = strlen (p); |
| 1511 | + if (len >= SECURE_NAME_LIMIT || memchr (p, '/', len) != NULL) |
| 1512 | + return false; |
| 1513 | + } |
| 1514 | + return *p != '\0'; |
| 1515 | +} |
| 1516 | |
| 1517 | -/* List of auditing DSOs. */ |
| 1518 | +/* LD_AUDIT variable contents. Must be processed before the |
| 1519 | + audit_list below. */ |
| 1520 | +const char *audit_list_string; |
| 1521 | + |
| 1522 | +/* Cyclic list of auditing DSOs. audit_list->next is the first |
| 1523 | + element. */ |
| 1524 | static struct audit_list |
| 1525 | { |
| 1526 | const char *name; |
| 1527 | struct audit_list *next; |
| 1528 | } *audit_list; |
| 1529 | |
| 1530 | +/* Iterator for audit_list_string followed by audit_list. */ |
| 1531 | +struct audit_list_iter |
| 1532 | +{ |
| 1533 | + /* Tail of audit_list_string still needing processing, or NULL. */ |
| 1534 | + const char *audit_list_tail; |
| 1535 | + |
| 1536 | + /* The list element returned in the previous iteration. NULL before |
| 1537 | + the first element. */ |
| 1538 | + struct audit_list *previous; |
| 1539 | + |
| 1540 | + /* Scratch buffer for returning a name which is part of |
| 1541 | + audit_list_string. */ |
| 1542 | + char fname[SECURE_NAME_LIMIT]; |
| 1543 | +}; |
| 1544 | + |
| 1545 | +/* Initialize an audit list iterator. */ |
| 1546 | +static void |
| 1547 | +audit_list_iter_init (struct audit_list_iter *iter) |
| 1548 | +{ |
| 1549 | + iter->audit_list_tail = audit_list_string; |
| 1550 | + iter->previous = NULL; |
| 1551 | +} |
| 1552 | + |
| 1553 | +/* Iterate through both audit_list_string and audit_list. */ |
| 1554 | +static const char * |
| 1555 | +audit_list_iter_next (struct audit_list_iter *iter) |
| 1556 | +{ |
| 1557 | + if (iter->audit_list_tail != NULL) |
| 1558 | + { |
| 1559 | + /* First iterate over audit_list_string. */ |
| 1560 | + while (*iter->audit_list_tail != '\0') |
| 1561 | + { |
| 1562 | + /* Split audit list at colon. */ |
| 1563 | + size_t len = strcspn (iter->audit_list_tail, ":"); |
| 1564 | + if (len > 0 && len < sizeof (iter->fname)) |
| 1565 | + { |
| 1566 | + memcpy (iter->fname, iter->audit_list_tail, len); |
| 1567 | + iter->fname[len] = '\0'; |
| 1568 | + } |
| 1569 | + else |
| 1570 | + /* Do not return this name to the caller. */ |
| 1571 | + iter->fname[0] = '\0'; |
| 1572 | + |
| 1573 | + /* Skip over the substring and the following delimiter. */ |
| 1574 | + iter->audit_list_tail += len; |
| 1575 | + if (*iter->audit_list_tail == ':') |
| 1576 | + ++iter->audit_list_tail; |
| 1577 | + |
| 1578 | + /* If the name is valid, return it. */ |
| 1579 | + if (dso_name_valid_for_suid (iter->fname)) |
| 1580 | + return iter->fname; |
| 1581 | + /* Otherwise, wrap around and try the next name. */ |
| 1582 | + } |
| 1583 | + /* Fall through to the procesing of audit_list. */ |
| 1584 | + } |
| 1585 | + |
| 1586 | + if (iter->previous == NULL) |
| 1587 | + { |
| 1588 | + if (audit_list == NULL) |
| 1589 | + /* No pre-parsed audit list. */ |
| 1590 | + return NULL; |
| 1591 | + /* Start of audit list. The first list element is at |
| 1592 | + audit_list->next (cyclic list). */ |
| 1593 | + iter->previous = audit_list->next; |
| 1594 | + return iter->previous->name; |
| 1595 | + } |
| 1596 | + if (iter->previous == audit_list) |
| 1597 | + /* Cyclic list wrap-around. */ |
| 1598 | + return NULL; |
| 1599 | + iter->previous = iter->previous->next; |
| 1600 | + return iter->previous->name; |
| 1601 | +} |
| 1602 | + |
| 1603 | #ifndef HAVE_INLINED_SYSCALLS |
| 1604 | /* Set nonzero during loading and initialization of executable and |
| 1605 | libraries, cleared before the executable's entry point runs. This |
| 1606 | @@ -730,6 +837,42 @@ static const char *preloadlist attribute_relro; |
| 1607 | /* Nonzero if information about versions has to be printed. */ |
| 1608 | static int version_info attribute_relro; |
| 1609 | |
| 1610 | +/* The LD_PRELOAD environment variable gives list of libraries |
| 1611 | + separated by white space or colons that are loaded before the |
| 1612 | + executable's dependencies and prepended to the global scope list. |
| 1613 | + (If the binary is running setuid all elements containing a '/' are |
| 1614 | + ignored since it is insecure.) Return the number of preloads |
| 1615 | + performed. */ |
| 1616 | +unsigned int |
| 1617 | +handle_ld_preload (const char *preloadlist, struct link_map *main_map) |
| 1618 | +{ |
| 1619 | + unsigned int npreloads = 0; |
| 1620 | + const char *p = preloadlist; |
| 1621 | + char fname[SECURE_PATH_LIMIT]; |
| 1622 | + |
| 1623 | + while (*p != '\0') |
| 1624 | + { |
| 1625 | + /* Split preload list at space/colon. */ |
| 1626 | + size_t len = strcspn (p, " :"); |
| 1627 | + if (len > 0 && len < sizeof (fname)) |
| 1628 | + { |
| 1629 | + memcpy (fname, p, len); |
| 1630 | + fname[len] = '\0'; |
| 1631 | + } |
| 1632 | + else |
| 1633 | + fname[0] = '\0'; |
| 1634 | + |
| 1635 | + /* Skip over the substring and the following delimiter. */ |
| 1636 | + p += len; |
| 1637 | + if (*p != '\0') |
| 1638 | + ++p; |
| 1639 | + |
| 1640 | + if (dso_name_valid_for_suid (fname)) |
| 1641 | + npreloads += do_preload (fname, main_map, "LD_PRELOAD"); |
| 1642 | + } |
| 1643 | + return npreloads; |
| 1644 | +} |
| 1645 | + |
| 1646 | static void |
| 1647 | dl_main (const ElfW(Phdr) *phdr, |
| 1648 | ElfW(Word) phnum, |
| 1649 | @@ -1257,11 +1400,13 @@ of this helper program; chances are you did not intend to run this program.\n\ |
| 1650 | GL(dl_rtld_map).l_tls_modid = _dl_next_tls_modid (); |
| 1651 | |
| 1652 | /* If we have auditing DSOs to load, do it now. */ |
| 1653 | - if (__glibc_unlikely (audit_list != NULL)) |
| 1654 | + bool need_security_init = true; |
| 1655 | + if (__glibc_unlikely (audit_list != NULL) |
| 1656 | + || __glibc_unlikely (audit_list_string != NULL)) |
| 1657 | { |
| 1658 | - /* Iterate over all entries in the list. The order is important. */ |
| 1659 | struct audit_ifaces *last_audit = NULL; |
| 1660 | - struct audit_list *al = audit_list->next; |
| 1661 | + struct audit_list_iter al_iter; |
| 1662 | + audit_list_iter_init (&al_iter); |
| 1663 | |
| 1664 | /* Since we start using the auditing DSOs right away we need to |
| 1665 | initialize the data structures now. */ |
| 1666 | @@ -1272,9 +1417,14 @@ of this helper program; chances are you did not intend to run this program.\n\ |
| 1667 | use different values (especially the pointer guard) and will |
| 1668 | fail later on. */ |
| 1669 | security_init (); |
| 1670 | + need_security_init = false; |
| 1671 | |
| 1672 | - do |
| 1673 | + while (true) |
| 1674 | { |
| 1675 | + const char *name = audit_list_iter_next (&al_iter); |
| 1676 | + if (name == NULL) |
| 1677 | + break; |
| 1678 | + |
| 1679 | int tls_idx = GL(dl_tls_max_dtv_idx); |
| 1680 | |
| 1681 | /* Now it is time to determine the layout of the static TLS |
| 1682 | @@ -1283,7 +1433,7 @@ of this helper program; chances are you did not intend to run this program.\n\ |
| 1683 | no DF_STATIC_TLS bit is set. The reason is that we know |
| 1684 | glibc will use the static model. */ |
| 1685 | struct dlmopen_args dlmargs; |
| 1686 | - dlmargs.fname = al->name; |
| 1687 | + dlmargs.fname = name; |
| 1688 | dlmargs.map = NULL; |
| 1689 | |
| 1690 | const char *objname; |
| 1691 | @@ -1296,7 +1446,7 @@ of this helper program; chances are you did not intend to run this program.\n\ |
| 1692 | not_loaded: |
| 1693 | _dl_error_printf ("\ |
| 1694 | ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n", |
| 1695 | - al->name, err_str); |
| 1696 | + name, err_str); |
| 1697 | if (malloced) |
| 1698 | free ((char *) err_str); |
| 1699 | } |
| 1700 | @@ -1400,10 +1550,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n", |
| 1701 | goto not_loaded; |
| 1702 | } |
| 1703 | } |
| 1704 | - |
| 1705 | - al = al->next; |
| 1706 | } |
| 1707 | - while (al != audit_list->next); |
| 1708 | |
| 1709 | /* If we have any auditing modules, announce that we already |
| 1710 | have two objects loaded. */ |
| 1711 | @@ -1481,23 +1628,8 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n", |
| 1712 | |
| 1713 | if (__glibc_unlikely (preloadlist != NULL)) |
| 1714 | { |
| 1715 | - /* The LD_PRELOAD environment variable gives list of libraries |
| 1716 | - separated by white space or colons that are loaded before the |
| 1717 | - executable's dependencies and prepended to the global scope |
| 1718 | - list. If the binary is running setuid all elements |
| 1719 | - containing a '/' are ignored since it is insecure. */ |
| 1720 | - char *list = strdupa (preloadlist); |
| 1721 | - char *p; |
| 1722 | - |
| 1723 | HP_TIMING_NOW (start); |
| 1724 | - |
| 1725 | - /* Prevent optimizing strsep. Speed is not important here. */ |
| 1726 | - while ((p = (strsep) (&list, " :")) != NULL) |
| 1727 | - if (p[0] != '\0' |
| 1728 | - && (__builtin_expect (! __libc_enable_secure, 1) |
| 1729 | - || strchr (p, '/') == NULL)) |
| 1730 | - npreloads += do_preload (p, main_map, "LD_PRELOAD"); |
| 1731 | - |
| 1732 | + npreloads += handle_ld_preload (preloadlist, main_map); |
| 1733 | HP_TIMING_NOW (stop); |
| 1734 | HP_TIMING_DIFF (diff, start, stop); |
| 1735 | HP_TIMING_ACCUM_NT (load_time, diff); |
| 1736 | @@ -1682,7 +1814,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n", |
| 1737 | if (tcbp == NULL) |
| 1738 | tcbp = init_tls (); |
| 1739 | |
| 1740 | - if (__glibc_likely (audit_list == NULL)) |
| 1741 | + if (__glibc_likely (need_security_init)) |
| 1742 | /* Initialize security features. But only if we have not done it |
| 1743 | earlier. */ |
| 1744 | security_init (); |
| 1745 | @@ -2313,9 +2445,7 @@ process_dl_audit (char *str) |
| 1746 | char *p; |
| 1747 | |
| 1748 | while ((p = (strsep) (&str, ":")) != NULL) |
| 1749 | - if (p[0] != '\0' |
| 1750 | - && (__builtin_expect (! __libc_enable_secure, 1) |
| 1751 | - || strchr (p, '/') == NULL)) |
| 1752 | + if (dso_name_valid_for_suid (p)) |
| 1753 | { |
| 1754 | /* This is using the local malloc, not the system malloc. The |
| 1755 | memory can never be freed. */ |
| 1756 | @@ -2379,7 +2509,7 @@ process_envvars (enum mode *modep) |
| 1757 | break; |
| 1758 | } |
| 1759 | if (memcmp (envline, "AUDIT", 5) == 0) |
| 1760 | - process_dl_audit (&envline[6]); |
| 1761 | + audit_list_string = &envline[6]; |
| 1762 | break; |
| 1763 | |
| 1764 | case 7: |
| 1765 | @@ -2423,7 +2553,8 @@ process_envvars (enum mode *modep) |
| 1766 | |
| 1767 | case 10: |
| 1768 | /* Mask for the important hardware capabilities. */ |
| 1769 | - if (memcmp (envline, "HWCAP_MASK", 10) == 0) |
| 1770 | + if (!__libc_enable_secure |
| 1771 | + && memcmp (envline, "HWCAP_MASK", 10) == 0) |
| 1772 | GLRO(dl_hwcap_mask) = __strtoul_internal (&envline[11], NULL, |
| 1773 | 0, 0); |
| 1774 | break; |
| 1775 | @@ -2437,7 +2568,8 @@ process_envvars (enum mode *modep) |
| 1776 | |
| 1777 | case 12: |
| 1778 | /* The library search path. */ |
| 1779 | - if (memcmp (envline, "LIBRARY_PATH", 12) == 0) |
| 1780 | + if (!__libc_enable_secure |
| 1781 | + && memcmp (envline, "LIBRARY_PATH", 12) == 0) |
| 1782 | { |
| 1783 | library_path = &envline[13]; |
| 1784 | break; |
| 1785 | diff --git a/elf/tst-nodelete-dlclose-dso.c b/elf/tst-nodelete-dlclose-dso.c |
| 1786 | new file mode 100644 |
| 1787 | index 0000000000..dd930f99cc |
| 1788 | --- /dev/null |
| 1789 | +++ b/elf/tst-nodelete-dlclose-dso.c |
| 1790 | @@ -0,0 +1,90 @@ |
| 1791 | +/* Bug 11941: Improper assert map->l_init_called in dlclose. |
| 1792 | + Copyright (C) 2016 Free Software Foundation, Inc. |
| 1793 | + This file is part of the GNU C Library. |
| 1794 | + |
| 1795 | + The GNU C Library is free software; you can redistribute it and/or |
| 1796 | + modify it under the terms of the GNU Lesser General Public |
| 1797 | + License as published by the Free Software Foundation; either |
| 1798 | + version 2.1 of the License, or (at your option) any later version. |
| 1799 | + |
| 1800 | + The GNU C Library is distributed in the hope that it will be useful, |
| 1801 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 1802 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 1803 | + Lesser General Public License for more details. |
| 1804 | + |
| 1805 | + You should have received a copy of the GNU Lesser General Public |
| 1806 | + License along with the GNU C Library; if not, see |
| 1807 | + <http://www.gnu.org/licenses/>. */ |
| 1808 | + |
| 1809 | +/* This is the primary DSO that is loaded by the appliation. This DSO |
| 1810 | + then loads a plugin with RTLD_NODELETE. This plugin depends on this |
| 1811 | + DSO. This dependency chain means that at application shutdown the |
| 1812 | + plugin will be destructed first. Thus by the time this DSO is |
| 1813 | + destructed we will be calling dlclose on an object that has already |
| 1814 | + been destructed. It is allowed to call dlclose in this way and |
| 1815 | + should not assert. */ |
| 1816 | +#include <stdio.h> |
| 1817 | +#include <stdlib.h> |
| 1818 | +#include <dlfcn.h> |
| 1819 | + |
| 1820 | +/* Plugin to load. */ |
| 1821 | +static void *plugin_lib = NULL; |
| 1822 | +/* Plugin function. */ |
| 1823 | +static void (*plugin_func) (void); |
| 1824 | +#define LIB_PLUGIN "tst-nodelete-dlclose-plugin.so" |
| 1825 | + |
| 1826 | +/* This function is never called but the plugin references it. |
| 1827 | + We do this to avoid any future --as-needed from removing the |
| 1828 | + plugin's DT_NEEDED on this DSO (required for the test). */ |
| 1829 | +void |
| 1830 | +primary_reference (void) |
| 1831 | +{ |
| 1832 | + printf ("INFO: Called primary_reference function.\n"); |
| 1833 | +} |
| 1834 | + |
| 1835 | +void |
| 1836 | +primary (void) |
| 1837 | +{ |
| 1838 | + char *error; |
| 1839 | + |
| 1840 | + plugin_lib = dlopen (LIB_PLUGIN, RTLD_NOW | RTLD_LOCAL | RTLD_NODELETE); |
| 1841 | + if (plugin_lib == NULL) |
| 1842 | + { |
| 1843 | + printf ("ERROR: Unable to load plugin library.\n"); |
| 1844 | + exit (EXIT_FAILURE); |
| 1845 | + } |
| 1846 | + dlerror (); |
| 1847 | + |
| 1848 | + plugin_func = (void (*) (void)) dlsym (plugin_lib, "plugin_func"); |
| 1849 | + error = dlerror (); |
| 1850 | + if (error != NULL) |
| 1851 | + { |
| 1852 | + printf ("ERROR: Unable to find symbol with error \"%s\".", |
| 1853 | + error); |
| 1854 | + exit (EXIT_FAILURE); |
| 1855 | + } |
| 1856 | + |
| 1857 | + return; |
| 1858 | +} |
| 1859 | + |
| 1860 | +__attribute__ ((destructor)) |
| 1861 | +static void |
| 1862 | +primary_dtor (void) |
| 1863 | +{ |
| 1864 | + int ret; |
| 1865 | + |
| 1866 | + printf ("INFO: Calling primary destructor.\n"); |
| 1867 | + |
| 1868 | + /* The destructor runs in the test driver also, which |
| 1869 | + hasn't called primary, in that case do nothing. */ |
| 1870 | + if (plugin_lib == NULL) |
| 1871 | + return; |
| 1872 | + |
| 1873 | + ret = dlclose (plugin_lib); |
| 1874 | + if (ret != 0) |
| 1875 | + { |
| 1876 | + printf ("ERROR: Calling dlclose failed with \"%s\"\n", |
| 1877 | + dlerror ()); |
| 1878 | + exit (EXIT_FAILURE); |
| 1879 | + } |
| 1880 | +} |
| 1881 | diff --git a/elf/tst-nodelete-dlclose-plugin.c b/elf/tst-nodelete-dlclose-plugin.c |
| 1882 | new file mode 100644 |
| 1883 | index 0000000000..8b295c1718 |
| 1884 | --- /dev/null |
| 1885 | +++ b/elf/tst-nodelete-dlclose-plugin.c |
| 1886 | @@ -0,0 +1,40 @@ |
| 1887 | +/* Bug 11941: Improper assert map->l_init_called in dlclose. |
| 1888 | + Copyright (C) 2016 Free Software Foundation, Inc. |
| 1889 | + This file is part of the GNU C Library. |
| 1890 | + |
| 1891 | + The GNU C Library is free software; you can redistribute it and/or |
| 1892 | + modify it under the terms of the GNU Lesser General Public |
| 1893 | + License as published by the Free Software Foundation; either |
| 1894 | + version 2.1 of the License, or (at your option) any later version. |
| 1895 | + |
| 1896 | + The GNU C Library is distributed in the hope that it will be useful, |
| 1897 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 1898 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 1899 | + Lesser General Public License for more details. |
| 1900 | + |
| 1901 | + You should have received a copy of the GNU Lesser General Public |
| 1902 | + License along with the GNU C Library; if not, see |
| 1903 | + <http://www.gnu.org/licenses/>. */ |
| 1904 | + |
| 1905 | +/* This DSO simulates a plugin with a dependency on the |
| 1906 | + primary DSO loaded by the appliation. */ |
| 1907 | +#include <stdio.h> |
| 1908 | + |
| 1909 | +extern void primary_reference (void); |
| 1910 | + |
| 1911 | +void |
| 1912 | +plugin_func (void) |
| 1913 | +{ |
| 1914 | + printf ("INFO: Calling plugin function.\n"); |
| 1915 | + /* Need a reference to the DSO to ensure that a potential --as-needed |
| 1916 | + doesn't remove the DT_NEEDED entry which we rely upon to ensure |
| 1917 | + destruction ordering. */ |
| 1918 | + primary_reference (); |
| 1919 | +} |
| 1920 | + |
| 1921 | +__attribute__ ((destructor)) |
| 1922 | +static void |
| 1923 | +plugin_dtor (void) |
| 1924 | +{ |
| 1925 | + printf ("INFO: Calling plugin destructor.\n"); |
| 1926 | +} |
| 1927 | diff --git a/elf/tst-nodelete-dlclose.c b/elf/tst-nodelete-dlclose.c |
| 1928 | new file mode 100644 |
| 1929 | index 0000000000..b3d07e1849 |
| 1930 | --- /dev/null |
| 1931 | +++ b/elf/tst-nodelete-dlclose.c |
| 1932 | @@ -0,0 +1,36 @@ |
| 1933 | +/* Bug 11941: Improper assert map->l_init_called in dlclose. |
| 1934 | + Copyright (C) 2016 Free Software Foundation, Inc. |
| 1935 | + This file is part of the GNU C Library. |
| 1936 | + |
| 1937 | + The GNU C Library is free software; you can redistribute it and/or |
| 1938 | + modify it under the terms of the GNU Lesser General Public |
| 1939 | + License as published by the Free Software Foundation; either |
| 1940 | + version 2.1 of the License, or (at your option) any later version. |
| 1941 | + |
| 1942 | + The GNU C Library is distributed in the hope that it will be useful, |
| 1943 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 1944 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 1945 | + Lesser General Public License for more details. |
| 1946 | + |
| 1947 | + You should have received a copy of the GNU Lesser General Public |
| 1948 | + License along with the GNU C Library; if not, see |
| 1949 | + <http://www.gnu.org/licenses/>. */ |
| 1950 | + |
| 1951 | +/* This simulates an application using the primary DSO which loads the |
| 1952 | + plugin DSO. */ |
| 1953 | +#include <stdio.h> |
| 1954 | +#include <stdlib.h> |
| 1955 | + |
| 1956 | +extern void primary (void); |
| 1957 | + |
| 1958 | +static int |
| 1959 | +do_test (void) |
| 1960 | +{ |
| 1961 | + printf ("INFO: Starting application.\n"); |
| 1962 | + primary (); |
| 1963 | + printf ("INFO: Exiting application.\n"); |
| 1964 | + return 0; |
| 1965 | +} |
| 1966 | + |
| 1967 | +#define TEST_FUNCTION do_test () |
| 1968 | +#include "../test-skeleton.c" |
| 1969 | diff --git a/extra-lib.mk b/extra-lib.mk |
| 1970 | index b10748d185..2552049135 100644 |
| 1971 | --- a/extra-lib.mk |
| 1972 | +++ b/extra-lib.mk |
| 1973 | @@ -5,6 +5,9 @@ |
| 1974 | # The variable $($(lib)-routines) defines the list of modules |
| 1975 | # to be included in that library. A sysdep Makefile can add to |
| 1976 | # $(lib)-sysdep_routines to include additional modules. |
| 1977 | +# |
| 1978 | +# Libraries listed in $(extra-libs-noinstall) are built, but not |
| 1979 | +# installed. |
| 1980 | |
| 1981 | lib := $(firstword $(extra-libs-left)) |
| 1982 | extra-libs-left := $(filter-out $(lib),$(extra-libs-left)) |
| 1983 | @@ -28,7 +31,9 @@ extra-objs := $(extra-objs) |
| 1984 | all-$(lib)-routines := $($(lib)-routines) $($(lib)-sysdep_routines) |
| 1985 | |
| 1986 | # Add each flavor of library to the lists of things to build and install. |
| 1987 | +ifeq (,$(filter $(lib), $(extra-libs-noinstall))) |
| 1988 | install-lib += $(foreach o,$(object-suffixes-$(lib)),$(lib:lib%=$(libtype$o))) |
| 1989 | +endif |
| 1990 | extra-objs += $(foreach o,$(filter-out .os .oS,$(object-suffixes-$(lib))),\ |
| 1991 | $(patsubst %,%$o,$(filter-out \ |
| 1992 | $($(lib)-shared-only-routines),\ |
| 1993 | diff --git a/grp/grp-merge.c b/grp/grp-merge.c |
| 1994 | index 0a1eb38d2c..5f79755798 100644 |
| 1995 | --- a/grp/grp-merge.c |
| 1996 | +++ b/grp/grp-merge.c |
| 1997 | @@ -85,6 +85,14 @@ __copy_grp (const struct group srcgrp, const size_t buflen, |
| 1998 | } |
| 1999 | members[i] = NULL; |
| 2000 | |
| 2001 | + /* Align for pointers. We can't simply align C because we need to |
| 2002 | + align destbuf[c]. */ |
| 2003 | + if ((((uintptr_t)destbuf + c) & (__alignof__(char **) - 1)) != 0) |
| 2004 | + { |
| 2005 | + uintptr_t mis_align = ((uintptr_t)destbuf + c) & (__alignof__(char **) - 1); |
| 2006 | + c += __alignof__(char **) - mis_align; |
| 2007 | + } |
| 2008 | + |
| 2009 | /* Copy the pointers from the members array into the buffer and assign them |
| 2010 | to the gr_mem member of destgrp. */ |
| 2011 | destgrp->gr_mem = (char **) &destbuf[c]; |
| 2012 | @@ -129,7 +137,7 @@ __merge_grp (struct group *savedgrp, char *savedbuf, char *savedend, |
| 2013 | |
| 2014 | /* Get the count of group members from the last sizeof (size_t) bytes in the |
| 2015 | mergegrp buffer. */ |
| 2016 | - savedmemcount = (size_t) *(savedend - sizeof (size_t)); |
| 2017 | + savedmemcount = *(size_t *) (savedend - sizeof (size_t)); |
| 2018 | |
| 2019 | /* Get the count of new members to add. */ |
| 2020 | for (memcount = 0; mergegrp->gr_mem[memcount]; memcount++) |
| 2021 | @@ -168,6 +176,14 @@ __merge_grp (struct group *savedgrp, char *savedbuf, char *savedend, |
| 2022 | /* Add the NULL-terminator. */ |
| 2023 | members[savedmemcount + memcount] = NULL; |
| 2024 | |
| 2025 | + /* Align for pointers. We can't simply align C because we need to |
| 2026 | + align savedbuf[c]. */ |
| 2027 | + if ((((uintptr_t)savedbuf + c) & (__alignof__(char **) - 1)) != 0) |
| 2028 | + { |
| 2029 | + uintptr_t mis_align = ((uintptr_t)savedbuf + c) & (__alignof__(char **) - 1); |
| 2030 | + c += __alignof__(char **) - mis_align; |
| 2031 | + } |
| 2032 | + |
| 2033 | /* Copy the member array back into the buffer after the member list and free |
| 2034 | the member array. */ |
| 2035 | savedgrp->gr_mem = (char **) &savedbuf[c]; |
| 2036 | diff --git a/iconv/gconv.h b/iconv/gconv.h |
| 2037 | index 8d8ce5813b..a87028047b 100644 |
| 2038 | --- a/iconv/gconv.h |
| 2039 | +++ b/iconv/gconv.h |
| 2040 | @@ -139,7 +139,7 @@ typedef struct __gconv_info |
| 2041 | { |
| 2042 | size_t __nsteps; |
| 2043 | struct __gconv_step *__steps; |
| 2044 | - __extension__ struct __gconv_step_data __data __flexarr; |
| 2045 | + __extension__ struct __gconv_step_data __data[0]; |
| 2046 | } *__gconv_t; |
| 2047 | |
| 2048 | /* Transliteration using the locale's data. */ |
| 2049 | diff --git a/include/arpa/nameser_compat.h b/include/arpa/nameser_compat.h |
| 2050 | index 2e735ede4c..7c0deed9ae 100644 |
| 2051 | --- a/include/arpa/nameser_compat.h |
| 2052 | +++ b/include/arpa/nameser_compat.h |
| 2053 | @@ -1,8 +1,8 @@ |
| 2054 | #ifndef _ARPA_NAMESER_COMPAT_ |
| 2055 | #include <resolv/arpa/nameser_compat.h> |
| 2056 | |
| 2057 | -/* Picksome unused number to represent lookups of IPv4 and IPv6 (i.e., |
| 2058 | - T_A and T_AAAA). */ |
| 2059 | -#define T_UNSPEC 62321 |
| 2060 | +/* The number is outside the 16-bit RR type range and is used |
| 2061 | + internally by the implementation. */ |
| 2062 | +#define T_QUERY_A_AND_AAAA 439963904 |
| 2063 | |
| 2064 | #endif |
| 2065 | diff --git a/include/array_length.h b/include/array_length.h |
| 2066 | new file mode 100644 |
| 2067 | index 0000000000..cb4a8b2a56 |
| 2068 | --- /dev/null |
| 2069 | +++ b/include/array_length.h |
| 2070 | @@ -0,0 +1,36 @@ |
| 2071 | +/* The array_length and array_end macros. |
| 2072 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 2073 | + This file is part of the GNU C Library. |
| 2074 | + |
| 2075 | + The GNU C Library is free software; you can redistribute it and/or |
| 2076 | + modify it under the terms of the GNU Lesser General Public |
| 2077 | + License as published by the Free Software Foundation; either |
| 2078 | + version 2.1 of the License, or (at your option) any later version. |
| 2079 | + |
| 2080 | + The GNU C Library is distributed in the hope that it will be useful, |
| 2081 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 2082 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 2083 | + Lesser General Public License for more details. |
| 2084 | + |
| 2085 | + You should have received a copy of the GNU Lesser General Public |
| 2086 | + License along with the GNU C Library; if not, see |
| 2087 | + <http://www.gnu.org/licenses/>. */ |
| 2088 | + |
| 2089 | +#ifndef _ARRAY_LENGTH_H |
| 2090 | +#define _ARRAY_LENGTH_H |
| 2091 | + |
| 2092 | +/* array_length (VAR) is the number of elements in the array VAR. VAR |
| 2093 | + must evaluate to an array, not a pointer. */ |
| 2094 | +#define array_length(var) \ |
| 2095 | + __extension__ ({ \ |
| 2096 | + _Static_assert (!__builtin_types_compatible_p \ |
| 2097 | + (__typeof (var), __typeof (&(var)[0])), \ |
| 2098 | + "argument must be an array"); \ |
| 2099 | + sizeof (var) / sizeof ((var)[0]); \ |
| 2100 | + }) |
| 2101 | + |
| 2102 | +/* array_end (VAR) is a pointer one past the end of the array VAR. |
| 2103 | + VAR must evaluate to an array, not a pointer. */ |
| 2104 | +#define array_end(var) (&(var)[array_length (var)]) |
| 2105 | + |
| 2106 | +#endif /* _ARRAY_LENGTH_H */ |
| 2107 | diff --git a/io/Makefile b/io/Makefile |
| 2108 | index deb6100156..1128f4881f 100644 |
| 2109 | --- a/io/Makefile |
| 2110 | +++ b/io/Makefile |
| 2111 | @@ -71,7 +71,8 @@ tests := test-utime test-stat test-stat2 test-lfs tst-getcwd \ |
| 2112 | tst-renameat tst-fchownat tst-fchmodat tst-faccessat \ |
| 2113 | tst-symlinkat tst-linkat tst-readlinkat tst-mkdirat \ |
| 2114 | tst-mknodat tst-mkfifoat tst-ttyname_r bug-ftw5 \ |
| 2115 | - tst-posix_fallocate tst-fts tst-fts-lfs |
| 2116 | + tst-posix_fallocate tst-posix_fallocate64 \ |
| 2117 | + tst-fts tst-fts-lfs tst-open-tmpfile tst-getcwd-abspath |
| 2118 | |
| 2119 | ifeq ($(run-built-tests),yes) |
| 2120 | tests-special += $(objpfx)ftwtest.out |
| 2121 | diff --git a/io/fts.h b/io/fts.h |
| 2122 | index 127a0d2721..b6b45206c8 100644 |
| 2123 | --- a/io/fts.h |
| 2124 | +++ b/io/fts.h |
| 2125 | @@ -193,7 +193,7 @@ FTS *__REDIRECT (fts_open, (char * const *, int, |
| 2126 | int (*)(const FTSENT **, const FTSENT **)), |
| 2127 | fts64_open); |
| 2128 | FTSENT *__REDIRECT (fts_read, (FTS *), fts64_read); |
| 2129 | -int __REDIRECT (fts_set, (FTS *, FTSENT *, int), fts64_set) __THROW; |
| 2130 | +int __REDIRECT_NTH (fts_set, (FTS *, FTSENT *, int), fts64_set); |
| 2131 | # else |
| 2132 | # define fts_children fts64_children |
| 2133 | # define fts_close fts64_close |
| 2134 | diff --git a/io/tst-getcwd-abspath.c b/io/tst-getcwd-abspath.c |
| 2135 | new file mode 100644 |
| 2136 | index 0000000000..3a3636f2ed |
| 2137 | --- /dev/null |
| 2138 | +++ b/io/tst-getcwd-abspath.c |
| 2139 | @@ -0,0 +1,66 @@ |
| 2140 | +/* BZ #22679 getcwd(3) should not succeed without returning an absolute path. |
| 2141 | + |
| 2142 | + Copyright (C) 2018 Free Software Foundation, Inc. |
| 2143 | + This file is part of the GNU C Library. |
| 2144 | + |
| 2145 | + The GNU C Library is free software; you can redistribute it and/or |
| 2146 | + modify it under the terms of the GNU Lesser General Public |
| 2147 | + License as published by the Free Software Foundation; either |
| 2148 | + version 2.1 of the License, or (at your option) any later version. |
| 2149 | + |
| 2150 | + The GNU C Library is distributed in the hope that it will be useful, |
| 2151 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 2152 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 2153 | + Lesser General Public License for more details. |
| 2154 | + |
| 2155 | + You should have received a copy of the GNU Lesser General Public |
| 2156 | + License along with the GNU C Library; if not, see |
| 2157 | + <https://www.gnu.org/licenses/>. */ |
| 2158 | + |
| 2159 | +#include <errno.h> |
| 2160 | +#include <stdio.h> |
| 2161 | +#include <stdlib.h> |
| 2162 | +#include <support/check.h> |
| 2163 | +#include <support/namespace.h> |
| 2164 | +#include <support/support.h> |
| 2165 | +#include <support/temp_file.h> |
| 2166 | +#include <support/test-driver.h> |
| 2167 | +#include <support/xunistd.h> |
| 2168 | +#include <unistd.h> |
| 2169 | + |
| 2170 | +static char *chroot_dir; |
| 2171 | + |
| 2172 | +/* The actual test. Run it in a subprocess, so that the test harness |
| 2173 | + can remove the temporary directory in --direct mode. */ |
| 2174 | +static void |
| 2175 | +getcwd_callback (void *closure) |
| 2176 | +{ |
| 2177 | + xchroot (chroot_dir); |
| 2178 | + |
| 2179 | + errno = 0; |
| 2180 | + char *cwd = getcwd (NULL, 0); |
| 2181 | + TEST_COMPARE (errno, ENOENT); |
| 2182 | + TEST_VERIFY (cwd == NULL); |
| 2183 | + |
| 2184 | + errno = 0; |
| 2185 | + cwd = realpath (".", NULL); |
| 2186 | + TEST_COMPARE (errno, ENOENT); |
| 2187 | + TEST_VERIFY (cwd == NULL); |
| 2188 | + |
| 2189 | + _exit (0); |
| 2190 | +} |
| 2191 | + |
| 2192 | +static int |
| 2193 | +do_test (void) |
| 2194 | +{ |
| 2195 | + support_become_root (); |
| 2196 | + if (!support_can_chroot ()) |
| 2197 | + return EXIT_UNSUPPORTED; |
| 2198 | + |
| 2199 | + chroot_dir = support_create_temp_directory ("tst-getcwd-abspath-"); |
| 2200 | + support_isolate_in_subprocess (getcwd_callback, NULL); |
| 2201 | + |
| 2202 | + return 0; |
| 2203 | +} |
| 2204 | + |
| 2205 | +#include <support/test-driver.c> |
| 2206 | diff --git a/localedata/ChangeLog b/localedata/ChangeLog |
| 2207 | index 4be8afc110..a7688e3df6 100644 |
| 2208 | --- a/localedata/ChangeLog |
| 2209 | +++ b/localedata/ChangeLog |
| 2210 | @@ -1,3 +1,17 @@ |
| 2211 | +2017-06-11 Santhosh Thottingal <santhosh.thottingal@gmail.com> |
| 2212 | + |
| 2213 | + [BZ #19922] |
| 2214 | + * locales/iso14651_t1_common: Add collation rules for U+07DA to U+07DF. |
| 2215 | + |
| 2216 | + [BZ #19919] |
| 2217 | + * locales/iso14651_t1_common: Correct collation of U+0D36 and U+0D37. |
| 2218 | + |
| 2219 | +2016-12-30 Mike Frysinger <vapier@gentoo.org> |
| 2220 | + |
| 2221 | + [BZ #20974] |
| 2222 | + * localedata/bs_BA (LC_MESSAGES): Delete "*." from the end of |
| 2223 | + yesexpr and noexpr. |
| 2224 | + |
| 2225 | 2016-07-07 Aurelien Jarno <aurelien@aurel32.net> |
| 2226 | |
| 2227 | * locales/de_LI (postal_fmt): Fix indentation. |
| 2228 | diff --git a/localedata/locales/bs_BA b/localedata/locales/bs_BA |
| 2229 | index a47f87eb37..68c2f9471a 100644 |
| 2230 | --- a/localedata/locales/bs_BA |
| 2231 | +++ b/localedata/locales/bs_BA |
| 2232 | @@ -148,8 +148,8 @@ copy "en_DK" |
| 2233 | END LC_CTYPE |
| 2234 | |
| 2235 | LC_MESSAGES |
| 2236 | -yesexpr "<U005E><U005B><U002B><U0031><U0064><U0044><U0079><U0059><U005D><U002A><U002E>" |
| 2237 | -noexpr "<U005E><U005B><U002D><U0030><U006E><U004E><U005D><U002A><U002E>" |
| 2238 | +yesexpr "<U005E><U005B><U002B><U0031><U0064><U0044><U0079><U0059><U005D>" |
| 2239 | +noexpr "<U005E><U005B><U002D><U0030><U006E><U004E><U005D>" |
| 2240 | yesstr "<U0064><U0061>" |
| 2241 | nostr "<U006E><U0065>" |
| 2242 | END LC_MESSAGES |
| 2243 | diff --git a/localedata/locales/iso14651_t1_common b/localedata/locales/iso14651_t1_common |
| 2244 | index eef75ba65e..0e64f26a12 100644 |
| 2245 | --- a/localedata/locales/iso14651_t1_common |
| 2246 | +++ b/localedata/locales/iso14651_t1_common |
| 2247 | @@ -1042,9 +1042,9 @@ collating-element <ml-bh> from "<U0D2D><U0D4D>" |
| 2248 | collating-element <ml-m> from "<U0D2E><U0D4D>" |
| 2249 | collating-element <ml-y> from "<U0D2F><U0D4D>" |
| 2250 | collating-element <ml-v> from "<U0D35><U0D4D>" |
| 2251 | -collating-element <ml-s> from "<U0D38><U0D4D>" |
| 2252 | collating-element <ml-ss> from "<U0D36><U0D4D>" |
| 2253 | collating-element <ml-sh> from "<U0D37><U0D4D>" |
| 2254 | +collating-element <ml-s> from "<U0D38><U0D4D>" |
| 2255 | collating-element <ml-h> from "<U0D39><U0D4D>" |
| 2256 | collating-element <ml-zh> from "<U0D34><U0D4D>" |
| 2257 | collating-element <ml-rr> from "<U0D31><U0D4D>" |
| 2258 | @@ -1103,8 +1103,8 @@ collating-symbol <ml-rra> |
| 2259 | collating-symbol <ml-la> |
| 2260 | collating-symbol <ml-lla> |
| 2261 | collating-symbol <ml-va> |
| 2262 | -collating-symbol <ml-sha> |
| 2263 | collating-symbol <ml-ssa> |
| 2264 | +collating-symbol <ml-sha> |
| 2265 | collating-symbol <ml-sa> |
| 2266 | collating-symbol <ml-ha> |
| 2267 | collating-symbol <ml-avagrah> |
| 2268 | @@ -1126,6 +1126,12 @@ collating-symbol <mlvs-o> |
| 2269 | collating-symbol <mlvs-au> |
| 2270 | collating-symbol <ml-visarga> |
| 2271 | collating-symbol <ml-virama> |
| 2272 | +collating-symbol <ml-atomic-chillu-k> |
| 2273 | +collating-symbol <ml-atomic-chillu-n> |
| 2274 | +collating-symbol <ml-atomic-chillu-nn> |
| 2275 | +collating-symbol <ml-atomic-chillu-l> |
| 2276 | +collating-symbol <ml-atomic-chillu-ll> |
| 2277 | +collating-symbol <ml-atomic-chillu-r> |
| 2278 | # |
| 2279 | # <BENGALI> |
| 2280 | # |
| 2281 | @@ -4552,6 +4558,12 @@ collating-symbol <TIB-subA> |
| 2282 | <mlvs-o> |
| 2283 | <mlvs-au> |
| 2284 | <ml-visarga> |
| 2285 | +<ml-atomic-chillu-k> |
| 2286 | +<ml-atomic-chillu-n> |
| 2287 | +<ml-atomic-chillu-nn> |
| 2288 | +<ml-atomic-chillu-l> |
| 2289 | +<ml-atomic-chillu-ll> |
| 2290 | +<ml-atomic-chillu-r> |
| 2291 | # |
| 2292 | # <BENGALI> |
| 2293 | # |
| 2294 | @@ -7252,6 +7264,7 @@ order_start <MALAYALAM>;forward;forward;forward;forward,position |
| 2295 | <U0D13> <mlvw-o>;<BAS>;<MIN>;IGNORE |
| 2296 | <U0D14> <mlvw-au>;<BAS>;<MIN>;IGNORE |
| 2297 | <ml-chillu-k> "<ml-ka><ml-virama>";<BAS>;<MIN>;IGNORE |
| 2298 | +<U0D7F> "<ml-ka><ml-virama>";<ml-atomic-chillu-k>;<MIN>;IGNORE |
| 2299 | <U0D15> "<ml-ka><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE |
| 2300 | <ml-kh> "<ml-kha><ml-virama>";<BAS>;<MIN>;IGNORE |
| 2301 | <U0D16> "<ml-kha><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE |
| 2302 | @@ -7280,6 +7293,7 @@ order_start <MALAYALAM>;forward;forward;forward;forward,position |
| 2303 | <ml-dh> "<ml-dha><ml-virama>";<BAS>;<MIN>;IGNORE |
| 2304 | <U0D22> "<ml-dha><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE |
| 2305 | <ml-chillu-nn> "<ml-nna><ml-virama>";<BAS>;<MIN>;IGNORE # ണ് = ണ + ് + zwj |
| 2306 | +<U0D7A> "<ml-nna><ml-virama>";<ml-atomic-chillu-nn>;<MIN>;IGNORE |
| 2307 | <U0D23> "<ml-nna><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE # ണ = ണ + ് + അ |
| 2308 | <ml-th> "<ml-tha><ml-virama>";<BAS>;<MIN>;IGNORE |
| 2309 | <U0D24> "<ml-tha><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE |
| 2310 | @@ -7290,6 +7304,7 @@ order_start <MALAYALAM>;forward;forward;forward;forward,position |
| 2311 | <ml-ddh> "<ml-ddha><ml-virama>";<BAS>;<MIN>;IGNORE |
| 2312 | <U0D27> "<ml-ddha><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE |
| 2313 | <ml-chillu-n> "<ml-na><ml-virama>";<BAS>;<MIN>;IGNORE # ന്= ന + ് + zwj |
| 2314 | +<U0D7B> "<ml-na><ml-virama>";<ml-atomic-chillu-n>;<MIN>;IGNORE |
| 2315 | <U0D28> "<ml-na><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE #ന = ന + ് + അ |
| 2316 | <ml-p> "<ml-pa><ml-virama>";<BAS>;<MIN>;IGNORE |
| 2317 | <U0D2A> "<ml-pa><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE |
| 2318 | @@ -7305,20 +7320,23 @@ order_start <MALAYALAM>;forward;forward;forward;forward,position |
| 2319 | <ml-y> "<ml-ya><ml-virama>";<BAS>;<MIN>;IGNORE |
| 2320 | <U0D2F> "<ml-ya><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE |
| 2321 | <ml-chillu-r> "<ml-ra><ml-virama>";<BAS>;<MIN>;IGNORE # ര = ര + ് + zwj |
| 2322 | +<U0D7C> "<ml-ra><ml-virama>";<ml-atomic-chillu-r>;<MIN>;IGNORE |
| 2323 | <U0D30> "<ml-ra><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE # ര = ര + ് + അ |
| 2324 | <ml-chillu-l> <ml-la>;<BAS>;<MIN>;IGNORE # ല് = ല + ് + zwj |
| 2325 | +<U0D7D> "<ml-la><ml-virama>";<ml-atomic-chillu-l>;<MIN>;IGNORE |
| 2326 | <U0D32> "<ml-la><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE # ല = ല + ് + അ |
| 2327 | <ml-v> "<ml-va><ml-virama>";<BAS>;<MIN>;IGNORE |
| 2328 | <U0D35> "<ml-va><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE |
| 2329 | <ml-ss> "<ml-ssa><ml-virama>";<BAS>;<MIN>;IGNORE |
| 2330 | -<U0D37> "<ml-ssa><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE |
| 2331 | +<U0D36> "<ml-ssa><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE |
| 2332 | <ml-sh> "<ml-sha><ml-virama>";<BAS>;<MIN>;IGNORE |
| 2333 | -<U0D36> "<ml-sha><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE |
| 2334 | +<U0D37> "<ml-sha><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE |
| 2335 | <ml-s> "<ml-sa><ml-virama>";<BAS>;<MIN>;IGNORE |
| 2336 | <U0D38> "<ml-sa><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE |
| 2337 | <ml-h> "<ml-ha><ml-virama>";<BAS>;<MIN>;IGNORE |
| 2338 | <U0D39> "<ml-ha><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE |
| 2339 | <ml-chillu-ll> "<ml-lla><ml-virama>";<BAS>;<MIN>;IGNORE # ള് = ള + ് + zwj |
| 2340 | +<U0D7E> "<ml-lla><ml-virama>";<ml-atomic-chillu-ll>;<MIN>;IGNORE |
| 2341 | <U0D33> "<ml-lla><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE # ള = ള + ് + അ |
| 2342 | <ml-zh> "<ml-zha><ml-virama>";<BAS>;<MIN>;IGNORE |
| 2343 | <U0D34> "<ml-zha><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE |
| 2344 | diff --git a/malloc/arena.c b/malloc/arena.c |
| 2345 | index 229783f3b7..4e16593d8b 100644 |
| 2346 | --- a/malloc/arena.c |
| 2347 | +++ b/malloc/arena.c |
| 2348 | @@ -702,8 +702,7 @@ _int_new_arena (size_t size) |
| 2349 | } |
| 2350 | |
| 2351 | |
| 2352 | -/* Remove an arena from free_list. The arena may be in use because it |
| 2353 | - was attached concurrently to a thread by reused_arena below. */ |
| 2354 | +/* Remove an arena from free_list. */ |
| 2355 | static mstate |
| 2356 | get_free_list (void) |
| 2357 | { |
| 2358 | @@ -718,7 +717,8 @@ get_free_list (void) |
| 2359 | free_list = result->next_free; |
| 2360 | |
| 2361 | /* The arena will be attached to this thread. */ |
| 2362 | - ++result->attached_threads; |
| 2363 | + assert (result->attached_threads == 0); |
| 2364 | + result->attached_threads = 1; |
| 2365 | |
| 2366 | detach_arena (replaced_arena); |
| 2367 | } |
| 2368 | @@ -735,6 +735,26 @@ get_free_list (void) |
| 2369 | return result; |
| 2370 | } |
| 2371 | |
| 2372 | +/* Remove the arena from the free list (if it is present). |
| 2373 | + free_list_lock must have been acquired by the caller. */ |
| 2374 | +static void |
| 2375 | +remove_from_free_list (mstate arena) |
| 2376 | +{ |
| 2377 | + mstate *previous = &free_list; |
| 2378 | + for (mstate p = free_list; p != NULL; p = p->next_free) |
| 2379 | + { |
| 2380 | + assert (p->attached_threads == 0); |
| 2381 | + if (p == arena) |
| 2382 | + { |
| 2383 | + /* Remove the requested arena from the list. */ |
| 2384 | + *previous = p->next_free; |
| 2385 | + break; |
| 2386 | + } |
| 2387 | + else |
| 2388 | + previous = &p->next_free; |
| 2389 | + } |
| 2390 | +} |
| 2391 | + |
| 2392 | /* Lock and return an arena that can be reused for memory allocation. |
| 2393 | Avoid AVOID_ARENA as we have already failed to allocate memory in |
| 2394 | it and it is currently locked. */ |
| 2395 | @@ -782,14 +802,25 @@ reused_arena (mstate avoid_arena) |
| 2396 | (void) mutex_lock (&result->mutex); |
| 2397 | |
| 2398 | out: |
| 2399 | - /* Attach the arena to the current thread. Note that we may have |
| 2400 | - selected an arena which was on free_list. */ |
| 2401 | + /* Attach the arena to the current thread. */ |
| 2402 | { |
| 2403 | /* Update the arena thread attachment counters. */ |
| 2404 | mstate replaced_arena = thread_arena; |
| 2405 | (void) mutex_lock (&free_list_lock); |
| 2406 | detach_arena (replaced_arena); |
| 2407 | + |
| 2408 | + /* We may have picked up an arena on the free list. We need to |
| 2409 | + preserve the invariant that no arena on the free list has a |
| 2410 | + positive attached_threads counter (otherwise, |
| 2411 | + arena_thread_freeres cannot use the counter to determine if the |
| 2412 | + arena needs to be put on the free list). We unconditionally |
| 2413 | + remove the selected arena from the free list. The caller of |
| 2414 | + reused_arena checked the free list and observed it to be empty, |
| 2415 | + so the list is very short. */ |
| 2416 | + remove_from_free_list (result); |
| 2417 | + |
| 2418 | ++result->attached_threads; |
| 2419 | + |
| 2420 | (void) mutex_unlock (&free_list_lock); |
| 2421 | } |
| 2422 | |
| 2423 | diff --git a/misc/regexp.c b/misc/regexp.c |
| 2424 | index 3b3668272f..b2a2c6e636 100644 |
| 2425 | --- a/misc/regexp.c |
| 2426 | +++ b/misc/regexp.c |
| 2427 | @@ -29,14 +29,15 @@ |
| 2428 | |
| 2429 | #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_23) |
| 2430 | |
| 2431 | -/* Define the variables used for the interface. */ |
| 2432 | -char *loc1; |
| 2433 | -char *loc2; |
| 2434 | +/* Define the variables used for the interface. Avoid .symver on common |
| 2435 | + symbol, which just creates a new common symbol, not an alias. */ |
| 2436 | +char *loc1 __attribute__ ((nocommon)); |
| 2437 | +char *loc2 __attribute__ ((nocommon)); |
| 2438 | compat_symbol (libc, loc1, loc1, GLIBC_2_0); |
| 2439 | compat_symbol (libc, loc2, loc2, GLIBC_2_0); |
| 2440 | |
| 2441 | /* Although we do not support the use we define this variable as well. */ |
| 2442 | -char *locs; |
| 2443 | +char *locs __attribute__ ((nocommon)); |
| 2444 | compat_symbol (libc, locs, locs, GLIBC_2_0); |
| 2445 | |
| 2446 | |
| 2447 | diff --git a/nis/nss_nisplus/nisplus-alias.c b/nis/nss_nisplus/nisplus-alias.c |
| 2448 | index 7f698b4e6d..cb5acce01d 100644 |
| 2449 | --- a/nis/nss_nisplus/nisplus-alias.c |
| 2450 | +++ b/nis/nss_nisplus/nisplus-alias.c |
| 2451 | @@ -291,7 +291,7 @@ _nss_nisplus_getaliasbyname_r (const char *name, struct aliasent *alias, |
| 2452 | return status; |
| 2453 | } |
| 2454 | |
| 2455 | - if (name != NULL) |
| 2456 | + if (name == NULL) |
| 2457 | { |
| 2458 | *errnop = EINVAL; |
| 2459 | return NSS_STATUS_UNAVAIL; |
| 2460 | diff --git a/nptl/Makefile b/nptl/Makefile |
| 2461 | index 0d8aadebed..fa925819ca 100644 |
| 2462 | --- a/nptl/Makefile |
| 2463 | +++ b/nptl/Makefile |
| 2464 | @@ -268,7 +268,7 @@ tests = tst-typesizes \ |
| 2465 | tst-flock1 tst-flock2 \ |
| 2466 | tst-signal1 tst-signal2 tst-signal3 tst-signal4 tst-signal5 \ |
| 2467 | tst-signal6 tst-signal7 \ |
| 2468 | - tst-exec1 tst-exec2 tst-exec3 tst-exec4 \ |
| 2469 | + tst-exec1 tst-exec2 tst-exec3 tst-exec4 tst-exec5 \ |
| 2470 | tst-exit1 tst-exit2 tst-exit3 \ |
| 2471 | tst-stdio1 tst-stdio2 \ |
| 2472 | tst-stack1 tst-stack2 tst-stack3 tst-stack4 tst-pthread-getattr \ |
| 2473 | diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c |
| 2474 | index 6b42b11d5a..7365ca606b 100644 |
| 2475 | --- a/nptl/allocatestack.c |
| 2476 | +++ b/nptl/allocatestack.c |
| 2477 | @@ -440,9 +440,6 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, |
| 2478 | SETUP_THREAD_SYSINFO (pd); |
| 2479 | #endif |
| 2480 | |
| 2481 | - /* The process ID is also the same as that of the caller. */ |
| 2482 | - pd->pid = THREAD_GETMEM (THREAD_SELF, pid); |
| 2483 | - |
| 2484 | /* Don't allow setxid until cloned. */ |
| 2485 | pd->setxid_futex = -1; |
| 2486 | |
| 2487 | @@ -579,9 +576,6 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, |
| 2488 | /* Don't allow setxid until cloned. */ |
| 2489 | pd->setxid_futex = -1; |
| 2490 | |
| 2491 | - /* The process ID is also the same as that of the caller. */ |
| 2492 | - pd->pid = THREAD_GETMEM (THREAD_SELF, pid); |
| 2493 | - |
| 2494 | /* Allocate the DTV for this thread. */ |
| 2495 | if (_dl_allocate_tls (TLS_TPADJ (pd)) == NULL) |
| 2496 | { |
| 2497 | @@ -875,9 +869,6 @@ __reclaim_stacks (void) |
| 2498 | /* This marks the stack as free. */ |
| 2499 | curp->tid = 0; |
| 2500 | |
| 2501 | - /* The PID field must be initialized for the new process. */ |
| 2502 | - curp->pid = self->pid; |
| 2503 | - |
| 2504 | /* Account for the size of the stack. */ |
| 2505 | stack_cache_actsize += curp->stackblock_size; |
| 2506 | |
| 2507 | @@ -903,13 +894,6 @@ __reclaim_stacks (void) |
| 2508 | } |
| 2509 | } |
| 2510 | |
| 2511 | - /* Reset the PIDs in any cached stacks. */ |
| 2512 | - list_for_each (runp, &stack_cache) |
| 2513 | - { |
| 2514 | - struct pthread *curp = list_entry (runp, struct pthread, list); |
| 2515 | - curp->pid = self->pid; |
| 2516 | - } |
| 2517 | - |
| 2518 | /* Add the stack of all running threads to the cache. */ |
| 2519 | list_splice (&stack_used, &stack_cache); |
| 2520 | |
| 2521 | @@ -1054,9 +1038,9 @@ setxid_signal_thread (struct xid_command *cmdp, struct pthread *t) |
| 2522 | return 0; |
| 2523 | |
| 2524 | int val; |
| 2525 | + pid_t pid = __getpid (); |
| 2526 | INTERNAL_SYSCALL_DECL (err); |
| 2527 | - val = INTERNAL_SYSCALL (tgkill, err, 3, THREAD_GETMEM (THREAD_SELF, pid), |
| 2528 | - t->tid, SIGSETXID); |
| 2529 | + val = INTERNAL_SYSCALL_CALL (tgkill, err, pid, t->tid, SIGSETXID); |
| 2530 | |
| 2531 | /* If this failed, it must have had not started yet or else exited. */ |
| 2532 | if (!INTERNAL_SYSCALL_ERROR_P (val, err)) |
| 2533 | diff --git a/nptl/descr.h b/nptl/descr.h |
| 2534 | index 8e4938deb5..bc92abf010 100644 |
| 2535 | --- a/nptl/descr.h |
| 2536 | +++ b/nptl/descr.h |
| 2537 | @@ -167,8 +167,8 @@ struct pthread |
| 2538 | therefore stack) used' flag. */ |
| 2539 | pid_t tid; |
| 2540 | |
| 2541 | - /* Process ID - thread group ID in kernel speak. */ |
| 2542 | - pid_t pid; |
| 2543 | + /* Ununsed. */ |
| 2544 | + pid_t pid_ununsed; |
| 2545 | |
| 2546 | /* List of robust mutexes the thread is holding. */ |
| 2547 | #ifdef __PTHREAD_MUTEX_HAVE_PREV |
| 2548 | diff --git a/nptl/nptl-init.c b/nptl/nptl-init.c |
| 2549 | index bdbdfedcef..48fab50c4e 100644 |
| 2550 | --- a/nptl/nptl-init.c |
| 2551 | +++ b/nptl/nptl-init.c |
| 2552 | @@ -184,18 +184,12 @@ __nptl_set_robust (struct pthread *self) |
| 2553 | static void |
| 2554 | sigcancel_handler (int sig, siginfo_t *si, void *ctx) |
| 2555 | { |
| 2556 | - /* Determine the process ID. It might be negative if the thread is |
| 2557 | - in the middle of a fork() call. */ |
| 2558 | - pid_t pid = THREAD_GETMEM (THREAD_SELF, pid); |
| 2559 | - if (__glibc_unlikely (pid < 0)) |
| 2560 | - pid = -pid; |
| 2561 | - |
| 2562 | /* Safety check. It would be possible to call this function for |
| 2563 | other signals and send a signal from another process. This is not |
| 2564 | correct and might even be a security problem. Try to catch as |
| 2565 | many incorrect invocations as possible. */ |
| 2566 | if (sig != SIGCANCEL |
| 2567 | - || si->si_pid != pid |
| 2568 | + || si->si_pid != __getpid() |
| 2569 | || si->si_code != SI_TKILL) |
| 2570 | return; |
| 2571 | |
| 2572 | @@ -243,19 +237,14 @@ struct xid_command *__xidcmd attribute_hidden; |
| 2573 | static void |
| 2574 | sighandler_setxid (int sig, siginfo_t *si, void *ctx) |
| 2575 | { |
| 2576 | - /* Determine the process ID. It might be negative if the thread is |
| 2577 | - in the middle of a fork() call. */ |
| 2578 | - pid_t pid = THREAD_GETMEM (THREAD_SELF, pid); |
| 2579 | int result; |
| 2580 | - if (__glibc_unlikely (pid < 0)) |
| 2581 | - pid = -pid; |
| 2582 | |
| 2583 | /* Safety check. It would be possible to call this function for |
| 2584 | other signals and send a signal from another process. This is not |
| 2585 | correct and might even be a security problem. Try to catch as |
| 2586 | many incorrect invocations as possible. */ |
| 2587 | if (sig != SIGSETXID |
| 2588 | - || si->si_pid != pid |
| 2589 | + || si->si_pid != __getpid () |
| 2590 | || si->si_code != SI_TKILL) |
| 2591 | return; |
| 2592 | |
| 2593 | diff --git a/nptl/pthread_cancel.c b/nptl/pthread_cancel.c |
| 2594 | index 1419baf988..89d02e1741 100644 |
| 2595 | --- a/nptl/pthread_cancel.c |
| 2596 | +++ b/nptl/pthread_cancel.c |
| 2597 | @@ -22,7 +22,7 @@ |
| 2598 | #include "pthreadP.h" |
| 2599 | #include <atomic.h> |
| 2600 | #include <sysdep.h> |
| 2601 | - |
| 2602 | +#include <unistd.h> |
| 2603 | |
| 2604 | int |
| 2605 | pthread_cancel (pthread_t th) |
| 2606 | @@ -66,19 +66,11 @@ pthread_cancel (pthread_t th) |
| 2607 | #ifdef SIGCANCEL |
| 2608 | /* The cancellation handler will take care of marking the |
| 2609 | thread as canceled. */ |
| 2610 | - INTERNAL_SYSCALL_DECL (err); |
| 2611 | - |
| 2612 | - /* One comment: The PID field in the TCB can temporarily be |
| 2613 | - changed (in fork). But this must not affect this code |
| 2614 | - here. Since this function would have to be called while |
| 2615 | - the thread is executing fork, it would have to happen in |
| 2616 | - a signal handler. But this is no allowed, pthread_cancel |
| 2617 | - is not guaranteed to be async-safe. */ |
| 2618 | - int val; |
| 2619 | - val = INTERNAL_SYSCALL (tgkill, err, 3, |
| 2620 | - THREAD_GETMEM (THREAD_SELF, pid), pd->tid, |
| 2621 | - SIGCANCEL); |
| 2622 | + pid_t pid = getpid (); |
| 2623 | |
| 2624 | + INTERNAL_SYSCALL_DECL (err); |
| 2625 | + int val = INTERNAL_SYSCALL_CALL (tgkill, err, pid, pd->tid, |
| 2626 | + SIGCANCEL); |
| 2627 | if (INTERNAL_SYSCALL_ERROR_P (val, err)) |
| 2628 | result = INTERNAL_SYSCALL_ERRNO (val, err); |
| 2629 | #else |
| 2630 | diff --git a/nptl/pthread_getattr_np.c b/nptl/pthread_getattr_np.c |
| 2631 | index fb906f0484..32d7484bf8 100644 |
| 2632 | --- a/nptl/pthread_getattr_np.c |
| 2633 | +++ b/nptl/pthread_getattr_np.c |
| 2634 | @@ -68,7 +68,6 @@ pthread_getattr_np (pthread_t thread_id, pthread_attr_t *attr) |
| 2635 | { |
| 2636 | /* No stack information available. This must be for the initial |
| 2637 | thread. Get the info in some magical way. */ |
| 2638 | - assert (abs (thread->pid) == thread->tid); |
| 2639 | |
| 2640 | /* Stack size limit. */ |
| 2641 | struct rlimit rl; |
| 2642 | diff --git a/nptl/tst-exec5.c b/nptl/tst-exec5.c |
| 2643 | new file mode 100644 |
| 2644 | index 0000000000..4327d8d41c |
| 2645 | --- /dev/null |
| 2646 | +++ b/nptl/tst-exec5.c |
| 2647 | @@ -0,0 +1,196 @@ |
| 2648 | +/* Check if posix_spawn does not act as a cancellation entrypoint. |
| 2649 | + Copyright (C) 2016 Free Software Foundation, Inc. |
| 2650 | + This file is part of the GNU C Library. |
| 2651 | + |
| 2652 | + The GNU C Library is free software; you can redistribute it and/or |
| 2653 | + modify it under the terms of the GNU Lesser General Public |
| 2654 | + License as published by the Free Software Foundation; either |
| 2655 | + version 2.1 of the License, or (at your option) any later version. |
| 2656 | + |
| 2657 | + The GNU C Library is distributed in the hope that it will be useful, |
| 2658 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 2659 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 2660 | + Lesser General Public License for more details. |
| 2661 | + |
| 2662 | + You should have received a copy of the GNU Lesser General Public |
| 2663 | + License along with the GNU C Library; if not, see |
| 2664 | + <http://www.gnu.org/licenses/>. */ |
| 2665 | + |
| 2666 | +#include <errno.h> |
| 2667 | +#include <paths.h> |
| 2668 | +#include <pthread.h> |
| 2669 | +#include <signal.h> |
| 2670 | +#include <spawn.h> |
| 2671 | +#include <stdbool.h> |
| 2672 | +#include <stdio.h> |
| 2673 | +#include <stdlib.h> |
| 2674 | +#include <unistd.h> |
| 2675 | +#include <sys/wait.h> |
| 2676 | + |
| 2677 | +static int do_test (void); |
| 2678 | +#define TEST_FUNCTION do_test () |
| 2679 | +#include <test-skeleton.c> |
| 2680 | + |
| 2681 | +static pthread_barrier_t b; |
| 2682 | + |
| 2683 | +static pid_t pid; |
| 2684 | +static int pipefd[2]; |
| 2685 | + |
| 2686 | +static void * |
| 2687 | +tf (void *arg) |
| 2688 | +{ |
| 2689 | + int r = pthread_barrier_wait (&b); |
| 2690 | + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) |
| 2691 | + { |
| 2692 | + puts ("error: pthread_barrier_wait failed"); |
| 2693 | + exit (1); |
| 2694 | + } |
| 2695 | + |
| 2696 | + posix_spawn_file_actions_t a; |
| 2697 | + if (posix_spawn_file_actions_init (&a) != 0) |
| 2698 | + { |
| 2699 | + puts ("error: spawn_file_actions_init failed"); |
| 2700 | + exit (1); |
| 2701 | + } |
| 2702 | + |
| 2703 | + if (posix_spawn_file_actions_adddup2 (&a, pipefd[1], STDOUT_FILENO) != 0) |
| 2704 | + { |
| 2705 | + puts ("error: spawn_file_actions_adddup2 failed"); |
| 2706 | + exit (1); |
| 2707 | + } |
| 2708 | + |
| 2709 | + if (posix_spawn_file_actions_addclose (&a, pipefd[0]) != 0) |
| 2710 | + { |
| 2711 | + puts ("error: spawn_file_actions_addclose"); |
| 2712 | + exit (1); |
| 2713 | + } |
| 2714 | + |
| 2715 | + char *argv[] = { (char *) _PATH_BSHELL, (char *) "-c", (char *) "echo $$", |
| 2716 | + NULL }; |
| 2717 | + if (posix_spawn (&pid, _PATH_BSHELL, &a, NULL, argv, NULL) != 0) |
| 2718 | + { |
| 2719 | + puts ("error: spawn failed"); |
| 2720 | + exit (1); |
| 2721 | + } |
| 2722 | + |
| 2723 | + return NULL; |
| 2724 | +} |
| 2725 | + |
| 2726 | + |
| 2727 | +static int |
| 2728 | +do_test (void) |
| 2729 | +{ |
| 2730 | + /* The test basically pipe a 'echo $$' created by a thread with a |
| 2731 | + cancellation pending. It then checks if the thread is not cancelled, |
| 2732 | + the process is created and if the output is the expected one. */ |
| 2733 | + |
| 2734 | + if (pipe (pipefd) != 0) |
| 2735 | + { |
| 2736 | + puts ("error: pipe failed"); |
| 2737 | + exit (1); |
| 2738 | + } |
| 2739 | + |
| 2740 | + /* Not interested in knowing when the pipe is closed. */ |
| 2741 | + if (sigignore (SIGPIPE) != 0) |
| 2742 | + { |
| 2743 | + puts ("error: sigignore failed"); |
| 2744 | + exit (1); |
| 2745 | + } |
| 2746 | + |
| 2747 | + /* To synchronize with the thread. */ |
| 2748 | + if (pthread_barrier_init (&b, NULL, 2) != 0) |
| 2749 | + { |
| 2750 | + puts ("error: pthread_barrier_init failed"); |
| 2751 | + exit (1); |
| 2752 | + } |
| 2753 | + |
| 2754 | + pthread_t th; |
| 2755 | + if (pthread_create (&th, NULL, &tf, NULL) != 0) |
| 2756 | + { |
| 2757 | + puts ("error: pthread_create failed"); |
| 2758 | + exit (1); |
| 2759 | + } |
| 2760 | + |
| 2761 | + if (pthread_cancel (th) != 0) |
| 2762 | + { |
| 2763 | + puts ("error: pthread_cancel failed"); |
| 2764 | + exit (1); |
| 2765 | + } |
| 2766 | + |
| 2767 | + int r = pthread_barrier_wait (&b); |
| 2768 | + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) |
| 2769 | + { |
| 2770 | + puts ("error: pthread_barrier_wait"); |
| 2771 | + exit (1); |
| 2772 | + } |
| 2773 | + |
| 2774 | + void *retval; |
| 2775 | + if (pthread_join (th, &retval) != 0) |
| 2776 | + { |
| 2777 | + puts ("error: pthread_join failed\n"); |
| 2778 | + } |
| 2779 | + if (retval == PTHREAD_CANCELED) |
| 2780 | + { |
| 2781 | + puts ("error: thread cancelled"); |
| 2782 | + exit (1); |
| 2783 | + } |
| 2784 | + |
| 2785 | + close (pipefd[1]); |
| 2786 | + |
| 2787 | + /* The global 'pid' should be set by thread posix_spawn calling. Check |
| 2788 | + below if it was executed correctly and with expected output. */ |
| 2789 | + |
| 2790 | + char buf[64]; |
| 2791 | + ssize_t n; |
| 2792 | + bool seen_pid = false; |
| 2793 | + while (TEMP_FAILURE_RETRY ((n = read (pipefd[0], buf, sizeof (buf)))) > 0) |
| 2794 | + { |
| 2795 | + /* We only expect to read the PID. */ |
| 2796 | + char *endp; |
| 2797 | + long int rpid = strtol (buf, &endp, 10); |
| 2798 | + |
| 2799 | + if (*endp != '\n') |
| 2800 | + { |
| 2801 | + printf ("error: didn't parse whole line: \"%s\"\n", buf); |
| 2802 | + exit (1); |
| 2803 | + } |
| 2804 | + if (endp == buf) |
| 2805 | + { |
| 2806 | + puts ("error: read empty line"); |
| 2807 | + exit (1); |
| 2808 | + } |
| 2809 | + |
| 2810 | + if (rpid != pid) |
| 2811 | + { |
| 2812 | + printf ("error: found \"%s\", expected PID %ld\n", buf, |
| 2813 | + (long int) pid); |
| 2814 | + exit (1); |
| 2815 | + } |
| 2816 | + |
| 2817 | + if (seen_pid) |
| 2818 | + { |
| 2819 | + puts ("error: found more than one PID line"); |
| 2820 | + exit (1); |
| 2821 | + } |
| 2822 | + |
| 2823 | + seen_pid = true; |
| 2824 | + } |
| 2825 | + |
| 2826 | + close (pipefd[0]); |
| 2827 | + |
| 2828 | + int status; |
| 2829 | + int err = waitpid (pid, &status, 0); |
| 2830 | + if (err != pid) |
| 2831 | + { |
| 2832 | + puts ("errnor: waitpid failed"); |
| 2833 | + exit (1); |
| 2834 | + } |
| 2835 | + |
| 2836 | + if (!seen_pid) |
| 2837 | + { |
| 2838 | + puts ("error: didn't get PID"); |
| 2839 | + exit (1); |
| 2840 | + } |
| 2841 | + |
| 2842 | + return 0; |
| 2843 | +} |
| 2844 | diff --git a/nptl/tst-once5.cc b/nptl/tst-once5.cc |
| 2845 | index 978d8271bd..513ac53f6f 100644 |
| 2846 | --- a/nptl/tst-once5.cc |
| 2847 | +++ b/nptl/tst-once5.cc |
| 2848 | @@ -75,5 +75,7 @@ do_test (void) |
| 2849 | return result; |
| 2850 | } |
| 2851 | |
| 2852 | +// The test currently hangs and is XFAILed. Reduce the timeout. |
| 2853 | +#define TIMEOUT 1 |
| 2854 | #define TEST_FUNCTION do_test () |
| 2855 | #include "../test-skeleton.c" |
| 2856 | diff --git a/nptl_db/structs.def b/nptl_db/structs.def |
| 2857 | index a9b621b126..1cb6a46391 100644 |
| 2858 | --- a/nptl_db/structs.def |
| 2859 | +++ b/nptl_db/structs.def |
| 2860 | @@ -48,7 +48,6 @@ DB_STRUCT (pthread) |
| 2861 | DB_STRUCT_FIELD (pthread, list) |
| 2862 | DB_STRUCT_FIELD (pthread, report_events) |
| 2863 | DB_STRUCT_FIELD (pthread, tid) |
| 2864 | -DB_STRUCT_FIELD (pthread, pid) |
| 2865 | DB_STRUCT_FIELD (pthread, start_routine) |
| 2866 | DB_STRUCT_FIELD (pthread, cancelhandling) |
| 2867 | DB_STRUCT_FIELD (pthread, schedpolicy) |
| 2868 | diff --git a/nptl_db/td_ta_thr_iter.c b/nptl_db/td_ta_thr_iter.c |
| 2869 | index a990fed150..9e5059956b 100644 |
| 2870 | --- a/nptl_db/td_ta_thr_iter.c |
| 2871 | +++ b/nptl_db/td_ta_thr_iter.c |
| 2872 | @@ -76,48 +76,28 @@ iterate_thread_list (td_thragent_t *ta, td_thr_iter_f *callback, |
| 2873 | if (ps_pdread (ta->ph, addr, copy, ta->ta_sizeof_pthread) != PS_OK) |
| 2874 | return TD_ERR; |
| 2875 | |
| 2876 | - /* Verify that this thread's pid field matches the child PID. |
| 2877 | - If its pid field is negative, it's about to do a fork or it |
| 2878 | - is the sole thread in a fork child. */ |
| 2879 | - psaddr_t pid; |
| 2880 | - err = DB_GET_FIELD_LOCAL (pid, ta, copy, pthread, pid, 0); |
| 2881 | - if (err == TD_OK && (pid_t) (uintptr_t) pid < 0) |
| 2882 | - { |
| 2883 | - if (-(pid_t) (uintptr_t) pid == match_pid) |
| 2884 | - /* It is about to do a fork, but is really still the parent PID. */ |
| 2885 | - pid = (psaddr_t) (uintptr_t) match_pid; |
| 2886 | - else |
| 2887 | - /* It must be a fork child, whose new PID is in the tid field. */ |
| 2888 | - err = DB_GET_FIELD_LOCAL (pid, ta, copy, pthread, tid, 0); |
| 2889 | - } |
| 2890 | + err = DB_GET_FIELD_LOCAL (schedpolicy, ta, copy, pthread, |
| 2891 | + schedpolicy, 0); |
| 2892 | if (err != TD_OK) |
| 2893 | break; |
| 2894 | + err = DB_GET_FIELD_LOCAL (schedprio, ta, copy, pthread, |
| 2895 | + schedparam_sched_priority, 0); |
| 2896 | + if (err != TD_OK) |
| 2897 | + break; |
| 2898 | + |
| 2899 | + /* Now test whether this thread matches the specified conditions. */ |
| 2900 | |
| 2901 | - if ((pid_t) (uintptr_t) pid == match_pid) |
| 2902 | + /* Only if the priority level is as high or higher. */ |
| 2903 | + int descr_pri = ((uintptr_t) schedpolicy == SCHED_OTHER |
| 2904 | + ? 0 : (uintptr_t) schedprio); |
| 2905 | + if (descr_pri >= ti_pri) |
| 2906 | { |
| 2907 | - err = DB_GET_FIELD_LOCAL (schedpolicy, ta, copy, pthread, |
| 2908 | - schedpolicy, 0); |
| 2909 | - if (err != TD_OK) |
| 2910 | - break; |
| 2911 | - err = DB_GET_FIELD_LOCAL (schedprio, ta, copy, pthread, |
| 2912 | - schedparam_sched_priority, 0); |
| 2913 | - if (err != TD_OK) |
| 2914 | - break; |
| 2915 | - |
| 2916 | - /* Now test whether this thread matches the specified conditions. */ |
| 2917 | - |
| 2918 | - /* Only if the priority level is as high or higher. */ |
| 2919 | - int descr_pri = ((uintptr_t) schedpolicy == SCHED_OTHER |
| 2920 | - ? 0 : (uintptr_t) schedprio); |
| 2921 | - if (descr_pri >= ti_pri) |
| 2922 | - { |
| 2923 | - /* Yep, it matches. Call the callback function. */ |
| 2924 | - td_thrhandle_t th; |
| 2925 | - th.th_ta_p = (td_thragent_t *) ta; |
| 2926 | - th.th_unique = addr; |
| 2927 | - if (callback (&th, cbdata_p) != 0) |
| 2928 | - return TD_DBERR; |
| 2929 | - } |
| 2930 | + /* Yep, it matches. Call the callback function. */ |
| 2931 | + td_thrhandle_t th; |
| 2932 | + th.th_ta_p = (td_thragent_t *) ta; |
| 2933 | + th.th_unique = addr; |
| 2934 | + if (callback (&th, cbdata_p) != 0) |
| 2935 | + return TD_DBERR; |
| 2936 | } |
| 2937 | |
| 2938 | /* Get the pointer to the next element. */ |
| 2939 | diff --git a/nptl_db/td_thr_validate.c b/nptl_db/td_thr_validate.c |
| 2940 | index f3c8a7bed6..9b89fecad2 100644 |
| 2941 | --- a/nptl_db/td_thr_validate.c |
| 2942 | +++ b/nptl_db/td_thr_validate.c |
| 2943 | @@ -80,28 +80,5 @@ td_thr_validate (const td_thrhandle_t *th) |
| 2944 | err = TD_OK; |
| 2945 | } |
| 2946 | |
| 2947 | - if (err == TD_OK) |
| 2948 | - { |
| 2949 | - /* Verify that this is not a stale element in a fork child. */ |
| 2950 | - pid_t match_pid = ps_getpid (th->th_ta_p->ph); |
| 2951 | - psaddr_t pid; |
| 2952 | - err = DB_GET_FIELD (pid, th->th_ta_p, th->th_unique, pthread, pid, 0); |
| 2953 | - if (err == TD_OK && (pid_t) (uintptr_t) pid < 0) |
| 2954 | - { |
| 2955 | - /* This was a thread that was about to fork, or it is the new sole |
| 2956 | - thread in a fork child. In the latter case, its tid was stored |
| 2957 | - via CLONE_CHILD_SETTID and so is already the proper child PID. */ |
| 2958 | - if (-(pid_t) (uintptr_t) pid == match_pid) |
| 2959 | - /* It is about to do a fork, but is really still the parent PID. */ |
| 2960 | - pid = (psaddr_t) (uintptr_t) match_pid; |
| 2961 | - else |
| 2962 | - /* It must be a fork child, whose new PID is in the tid field. */ |
| 2963 | - err = DB_GET_FIELD (pid, th->th_ta_p, th->th_unique, |
| 2964 | - pthread, tid, 0); |
| 2965 | - } |
| 2966 | - if (err == TD_OK && (pid_t) (uintptr_t) pid != match_pid) |
| 2967 | - err = TD_NOTHR; |
| 2968 | - } |
| 2969 | - |
| 2970 | return err; |
| 2971 | } |
| 2972 | diff --git a/po/de.po b/po/de.po |
| 2973 | index 1383e8c4a9..ca14c7e386 100644 |
| 2974 | --- a/po/de.po |
| 2975 | +++ b/po/de.po |
| 2976 | @@ -8,7 +8,7 @@ msgid "" |
| 2977 | msgstr "" |
| 2978 | "Project-Id-Version: GNU libc 2.22-pre1\n" |
| 2979 | "POT-Creation-Date: 2015-07-31 00:10-0400\n" |
| 2980 | -"PO-Revision-Date: 2015-08-31 18:30+0200\n" |
| 2981 | +"PO-Revision-Date: 2016-04-22 18:44+0200\n" |
| 2982 | "Last-Translator: Jochen Hein <jochen@jochen.org>\n" |
| 2983 | "Language-Team: German <translation-team-de@lists.sourceforge.net>\n" |
| 2984 | "Language: de\n" |
| 2985 | @@ -4479,13 +4479,13 @@ msgstr "" |
| 2986 | "%15s Cache ist dauerhaft\n" |
| 2987 | "%15s Cache wird gemeinsam verwendet\n" |
| 2988 | "%15Zu vorgeschlagene Größe\n" |
| 2989 | -"%15Zu Gesamtröße des Data-Pools\n" |
| 2990 | +"%15Zu Gesamtgröße des Data-Pools\n" |
| 2991 | "%15Zu Benutzter Speicher im Data-Pool\n" |
| 2992 | "%15lu Time to Live für positive Einträge in Sekunden\n" |
| 2993 | "%15lu Time to Live für negative Einträge in Sekunden\n" |
| 2994 | "%15<PRIuMAX> Cache-Hits bei positiven Einträgen\n" |
| 2995 | "%15<PRIuMAX> Cache-Hits bei positiven Einträgen\n" |
| 2996 | -"%15<PRIuMAX> Cache-Misses bei positiven Einträgen\n" |
| 2997 | +"%15<PRIuMAX> Cache-Misses bei positiven Einträgen\n" |
| 2998 | "%15<PRIuMAX> Cache-Misses bei negativen Einträgen\n" |
| 2999 | "%15lu%% Cache-Hit Verhältnis\n" |
| 3000 | "%15zu aktuelle Anzahl der Werte im Cache\n" |
| 3001 | diff --git a/po/fi.po b/po/fi.po |
| 3002 | index 17cb3e3e1d..8a2ab8358c 100644 |
| 3003 | --- a/po/fi.po |
| 3004 | +++ b/po/fi.po |
| 3005 | @@ -24,16 +24,16 @@ |
| 3006 | # |
| 3007 | msgid "" |
| 3008 | msgstr "" |
| 3009 | -"Project-Id-Version: libc 2.21-pre1\n" |
| 3010 | +"Project-Id-Version: libc 2.22-pre1\n" |
| 3011 | "POT-Creation-Date: 2015-07-31 00:10-0400\n" |
| 3012 | -"PO-Revision-Date: 2015-07-28 20:29+0300\n" |
| 3013 | +"PO-Revision-Date: 2016-05-26 21:14+0300\n" |
| 3014 | "Last-Translator: Lauri Nurmi <lanurmi@iki.fi>\n" |
| 3015 | "Language-Team: Finnish <translation-team-fi@lists.sourceforge.net>\n" |
| 3016 | "Language: fi\n" |
| 3017 | "MIME-Version: 1.0\n" |
| 3018 | "Content-Type: text/plain; charset=UTF-8\n" |
| 3019 | "Content-Transfer-Encoding: 8bit\n" |
| 3020 | -"X-Generator: Poedit 1.8.3\n" |
| 3021 | +"X-Generator: Poedit 1.8.7\n" |
| 3022 | "Plural-Forms: nplurals=2; plural=(n != 1);\n" |
| 3023 | |
| 3024 | #: argp/argp-help.c:227 |
| 3025 | @@ -126,7 +126,7 @@ msgid "%s%s%s:%u: %s%sUnexpected error: %s.\n" |
| 3026 | msgstr "%s%s%s:%u: %s%sOdottamaton virhe: %s.\n" |
| 3027 | |
| 3028 | #: assert/assert.c:101 |
| 3029 | -#, fuzzy, c-format |
| 3030 | +#, c-format |
| 3031 | msgid "" |
| 3032 | "%s%s%s:%u: %s%sAssertion `%s' failed.\n" |
| 3033 | "%n" |
| 3034 | @@ -169,12 +169,12 @@ msgstr "" |
| 3035 | #: malloc/memusagestat.c:563 nss/getent.c:973 nss/makedb.c:369 |
| 3036 | #: posix/getconf.c:486 sunrpc/rpcinfo.c:691 |
| 3037 | #: sysdeps/unix/sysv/linux/lddlibc4.c:61 |
| 3038 | -#, fuzzy, c-format |
| 3039 | +#, c-format |
| 3040 | msgid "" |
| 3041 | "For bug reporting instructions, please see:\n" |
| 3042 | "%s.\n" |
| 3043 | msgstr "" |
| 3044 | -"Ohjeet ohjelmistovioista ilmoittamiseen ovat osoitteessa\n" |
| 3045 | +"Katso ohjeet vikailmoitusten tekemiseen osoitteesta:\n" |
| 3046 | "%s.\n" |
| 3047 | |
| 3048 | #: catgets/gencat.c:245 debug/pcprofiledump.c:225 debug/xtrace.sh:64 |
| 3049 | @@ -321,9 +321,8 @@ msgstr "Käyttö: xtrace [VALITSIN]... OHJELMA [OHJELMANVALITSIN]...\\n" |
| 3050 | |
| 3051 | #: debug/xtrace.sh:32 elf/sotruss.sh:56 elf/sotruss.sh:67 elf/sotruss.sh:135 |
| 3052 | #: malloc/memusage.sh:26 |
| 3053 | -#, fuzzy |
| 3054 | msgid "Try \\`%s --help' or \\`%s --usage' for more information.\\n" |
| 3055 | -msgstr "Kokeile ”%s --help” tai ”%s --usage” saadaksesi lisää tietoa.\n" |
| 3056 | +msgstr "Kokeile ”%s --help” tai ”%s --usage” saadaksesi lisää tietoa.\\n" |
| 3057 | |
| 3058 | #: debug/xtrace.sh:38 |
| 3059 | #, fuzzy |
| 3060 | @@ -594,9 +593,8 @@ msgid "cannot enable executable stack as shared object requires" |
| 3061 | msgstr "jaettua objektikahvaa ei voi luoda" |
| 3062 | |
| 3063 | #: elf/dl-load.c:1339 |
| 3064 | -#, fuzzy |
| 3065 | msgid "cannot close file descriptor" |
| 3066 | -msgstr "tiedostoa %s ei voi sulkea" |
| 3067 | +msgstr "tiedostokahvaa ei voi sulkea" |
| 3068 | |
| 3069 | #: elf/dl-load.c:1568 |
| 3070 | msgid "file too short" |
| 3071 | @@ -796,9 +794,8 @@ msgid "Format to use: new, old or compat (default)" |
| 3072 | msgstr "Käytettävä muoto: ”new”, ”old” tai ”compat” (oletus)" |
| 3073 | |
| 3074 | #: elf/ldconfig.c:151 |
| 3075 | -#, fuzzy |
| 3076 | msgid "Ignore auxiliary cache file" |
| 3077 | -msgstr "Käytä CACHEa välimuistitiedostona" |
| 3078 | +msgstr "Jätä huomiotta apuvälimuistitiedosto" |
| 3079 | |
| 3080 | #: elf/ldconfig.c:159 |
| 3081 | msgid "Configure Dynamic Linker Run Time Bindings." |
| 3082 | @@ -1087,9 +1084,9 @@ msgid "invalid process ID '%s'" |
| 3083 | msgstr "virheellinen prosessi-ID ”%s”" |
| 3084 | |
| 3085 | #: elf/pldd.c:120 |
| 3086 | -#, fuzzy, c-format |
| 3087 | +#, c-format |
| 3088 | msgid "cannot open %s" |
| 3089 | -msgstr "laitetta %s ei voi avata" |
| 3090 | +msgstr "tiedostoa %s ei voi avata" |
| 3091 | |
| 3092 | #: elf/pldd.c:152 |
| 3093 | #, fuzzy, c-format |
| 3094 | @@ -1102,24 +1099,24 @@ msgid "cannot prepare reading %s/task" |
| 3095 | msgstr "ei voi avata laitetta %s lukutilaan" |
| 3096 | |
| 3097 | #: elf/pldd.c:168 |
| 3098 | -#, fuzzy, c-format |
| 3099 | +#, c-format |
| 3100 | msgid "invalid thread ID '%s'" |
| 3101 | -msgstr "virheellinen prosessi-ID ”%s”" |
| 3102 | +msgstr "virheellinen säie-ID ”%s”" |
| 3103 | |
| 3104 | #: elf/pldd.c:179 |
| 3105 | -#, fuzzy, c-format |
| 3106 | +#, c-format |
| 3107 | msgid "cannot attach to process %lu" |
| 3108 | -msgstr "tiedostoa ”%s” ei voi avata" |
| 3109 | +msgstr "ei voida kiinnittyä prosessiin %lu" |
| 3110 | |
| 3111 | #: elf/pldd.c:294 |
| 3112 | #, c-format |
| 3113 | msgid "cannot get information about process %lu" |
| 3114 | -msgstr "" |
| 3115 | +msgstr "tietojen saaminen prosessista %lu ei onnistu" |
| 3116 | |
| 3117 | #: elf/pldd.c:307 |
| 3118 | -#, fuzzy, c-format |
| 3119 | +#, c-format |
| 3120 | msgid "process %lu is no ELF program" |
| 3121 | -msgstr "ohjelma %lu ei ole käytettävissä\n" |
| 3122 | +msgstr "prosessi %lu ei ole ELF-ohjelma" |
| 3123 | |
| 3124 | #: elf/readelflib.c:34 |
| 3125 | #, c-format |
| 3126 | @@ -1203,7 +1200,7 @@ msgstr "%s kohde ei saa olla hakemisto\n" |
| 3127 | #: elf/sln.c:184 |
| 3128 | #, c-format |
| 3129 | msgid "%s: failed to remove the old destination\n" |
| 3130 | -msgstr "" |
| 3131 | +msgstr "%s: vanhan kohteen poistaminen epäonnistui\n" |
| 3132 | |
| 3133 | #: elf/sln.c:192 |
| 3134 | #, c-format |
| 3135 | @@ -1237,9 +1234,8 @@ msgid "Mandatory arguments to long options are also mandatory for any correspond |
| 3136 | msgstr "Pakolliset argumentit pitkille valitsimille ovat pakollisia kaikille vastaaville lyhyille valitsimille.\\n" |
| 3137 | |
| 3138 | #: elf/sotruss.sh:55 |
| 3139 | -#, fuzzy |
| 3140 | msgid "%s: option requires an argument -- '%s'\\n" |
| 3141 | -msgstr "%s: valitsin ”%s” vaatii argumentin\n" |
| 3142 | +msgstr "%s: valitsin vaatii argumentin -- ”%c”\\n" |
| 3143 | |
| 3144 | #: elf/sotruss.sh:61 |
| 3145 | msgid "%s: option is ambiguous; possibilities:" |
| 3146 | @@ -1507,7 +1503,6 @@ msgid "unknown iconv() error %d" |
| 3147 | msgstr "tuntematon iconv()-virhe %d" |
| 3148 | |
| 3149 | #: iconv/iconv_prog.c:791 |
| 3150 | -#, fuzzy |
| 3151 | msgid "" |
| 3152 | "The following list contains all the coded character sets known. This does\n" |
| 3153 | "not necessarily mean that all combinations of these names can be used for\n" |
| 3154 | @@ -1516,9 +1511,9 @@ msgid "" |
| 3155 | "\n" |
| 3156 | " " |
| 3157 | msgstr "" |
| 3158 | -"Seuraavassa listassa ovat kaikki tunnetut koodatut merkistöt. Se ei\n" |
| 3159 | +"Seuraavassa listassa ovat kaikki tunnetut koodatut merkistöt. Tämä ei\n" |
| 3160 | "kuitenkaan välttämättä tarkoita sitä, että kaikkia näiden nimien\n" |
| 3161 | -"yhdistelmiä voidaan käyttää FROM- ja TO-komentoriviparametreina. Yksi\n" |
| 3162 | +"yhdistelmiä voisi käyttää FROM- ja TO-komentoriviparametreina. Yksi\n" |
| 3163 | "koodattu merkistö voi olla listalla useilla eri nimillä (aliaksilla).\n" |
| 3164 | "\n" |
| 3165 | " " |
| 3166 | @@ -2733,14 +2728,12 @@ msgid "locale.alias file to consult when making archive" |
| 3167 | msgstr "Arkistoa luotaessa käytettävä locale.alias-tiedosto" |
| 3168 | |
| 3169 | #: locale/programs/localedef.c:150 |
| 3170 | -#, fuzzy |
| 3171 | msgid "Generate little-endian output" |
| 3172 | -msgstr "Tuota little-endian-koodia" |
| 3173 | +msgstr "Tuota little-endian-muotoa" |
| 3174 | |
| 3175 | #: locale/programs/localedef.c:152 |
| 3176 | -#, fuzzy |
| 3177 | msgid "Generate big-endian output" |
| 3178 | -msgstr "Tuota big-endian-koodia" |
| 3179 | +msgstr "Tuota big-endian-muotoa" |
| 3180 | |
| 3181 | #: locale/programs/localedef.c:157 |
| 3182 | msgid "Compile locale specification" |
| 3183 | @@ -4275,10 +4268,9 @@ msgid "" |
| 3184 | msgstr "" |
| 3185 | |
| 3186 | #: nscd/nscd.c:635 |
| 3187 | -#, fuzzy, c-format |
| 3188 | -#| msgid "lstat failed" |
| 3189 | +#, c-format |
| 3190 | msgid "'wait' failed\n" |
| 3191 | -msgstr "tiedoston tilan luku epäonnistui" |
| 3192 | +msgstr "”wait” epäonnistui\n" |
| 3193 | |
| 3194 | #: nscd/nscd.c:642 |
| 3195 | #, c-format |
| 3196 | @@ -4670,9 +4662,9 @@ msgid "cannot create temporary file" |
| 3197 | msgstr "tilapäistä tiedostoa ei voi luoda" |
| 3198 | |
| 3199 | #: nss/makedb.c:304 |
| 3200 | -#, fuzzy, c-format |
| 3201 | +#, c-format |
| 3202 | msgid "cannot stat newly created file" |
| 3203 | -msgstr "tiedoston ”%s” tilaa ei voi lukea: %s" |
| 3204 | +msgstr "juuri luodun tiedoston tilaa ei voi lukea" |
| 3205 | |
| 3206 | #: nss/makedb.c:315 |
| 3207 | #, c-format |
| 3208 | @@ -4680,9 +4672,9 @@ msgid "cannot rename temporary file" |
| 3209 | msgstr "tilapäistä tiedostoa ei voi nimetä uudelleen" |
| 3210 | |
| 3211 | #: nss/makedb.c:531 nss/makedb.c:554 |
| 3212 | -#, fuzzy, c-format |
| 3213 | +#, c-format |
| 3214 | msgid "cannot create search tree" |
| 3215 | -msgstr "hakupolulle ei voi luoda välimuistia" |
| 3216 | +msgstr "hakupuuta ei voi luoda" |
| 3217 | |
| 3218 | #: nss/makedb.c:560 |
| 3219 | msgid "duplicate key" |
| 3220 | @@ -4699,9 +4691,9 @@ msgid "failed to write new database file" |
| 3221 | msgstr "uuden tietokantatiedoston kirjoittaminen epäonnistui" |
| 3222 | |
| 3223 | #: nss/makedb.c:812 |
| 3224 | -#, fuzzy, c-format |
| 3225 | +#, c-format |
| 3226 | msgid "cannot stat database file" |
| 3227 | -msgstr "tiedoston ”%s” tilaa ei voi lukea: %s" |
| 3228 | +msgstr "tietokantatiedoston tilaa ei voi lukea" |
| 3229 | |
| 3230 | #: nss/makedb.c:817 |
| 3231 | #, fuzzy, c-format |
| 3232 | @@ -4709,9 +4701,9 @@ msgid "cannot map database file" |
| 3233 | msgstr "Karttatietokannassa ei ole enempää tietueita" |
| 3234 | |
| 3235 | #: nss/makedb.c:820 |
| 3236 | -#, fuzzy, c-format |
| 3237 | +#, c-format |
| 3238 | msgid "file not a database file" |
| 3239 | -msgstr "luettaessa profilointidatatiedoston tilaa" |
| 3240 | +msgstr "tiedosto ei ole tietokantatiedosto" |
| 3241 | |
| 3242 | #: nss/makedb.c:871 |
| 3243 | #, fuzzy, c-format |
| 3244 | @@ -4726,7 +4718,7 @@ msgstr "Käyttö: %s [-v määrittely] muuttujanimi [polku]\n" |
| 3245 | #: posix/getconf.c:403 |
| 3246 | #, c-format |
| 3247 | msgid " %s -a [pathname]\n" |
| 3248 | -msgstr "" |
| 3249 | +msgstr " %s -a [polku]\n" |
| 3250 | |
| 3251 | #: posix/getconf.c:479 |
| 3252 | #, c-format |
| 3253 | @@ -5094,11 +5086,11 @@ msgstr "Laitetta irrotettu" |
| 3254 | |
| 3255 | #: stdio-common/psiginfo.c:139 |
| 3256 | msgid "Signal sent by kill()" |
| 3257 | -msgstr "" |
| 3258 | +msgstr "Signaalin lähetti kill()" |
| 3259 | |
| 3260 | #: stdio-common/psiginfo.c:142 |
| 3261 | msgid "Signal sent by sigqueue()" |
| 3262 | -msgstr "" |
| 3263 | +msgstr "Signaalin lähetti sigqueue()" |
| 3264 | |
| 3265 | #: stdio-common/psiginfo.c:145 |
| 3266 | msgid "Signal generated by the expiration of a timer" |
| 3267 | @@ -5114,7 +5106,7 @@ msgstr "" |
| 3268 | |
| 3269 | #: stdio-common/psiginfo.c:157 |
| 3270 | msgid "Signal sent by tkill()" |
| 3271 | -msgstr "" |
| 3272 | +msgstr "Signaalin lähetti tkill()" |
| 3273 | |
| 3274 | #: stdio-common/psiginfo.c:162 |
| 3275 | msgid "Signal generated by the completion of an asynchronous name lookup request" |
| 3276 | @@ -5296,9 +5288,8 @@ msgid "Failed (unspecified error)" |
| 3277 | msgstr "Epäonnistui (määrittelemätön virhe)" |
| 3278 | |
| 3279 | #: sunrpc/clnt_raw.c:115 |
| 3280 | -#, fuzzy |
| 3281 | msgid "clnt_raw.c: fatal header serialization error" |
| 3282 | -msgstr "clnt_raw.c: vakava otsikon serialisointivirhe" |
| 3283 | +msgstr "clnt_raw.c: vakava otsikon sarjallistamisvirhe" |
| 3284 | |
| 3285 | #: sunrpc/pm_getmaps.c:77 |
| 3286 | msgid "pmap_getmaps.c: rpc problem" |
| 3287 | @@ -6825,9 +6816,8 @@ msgid "Interrupted by a signal" |
| 3288 | msgstr "Signaalin keskeyttämä" |
| 3289 | |
| 3290 | #: sysdeps/posix/gai_strerror-strs.h:17 |
| 3291 | -#, fuzzy |
| 3292 | msgid "Parameter string not correctly encoded" |
| 3293 | -msgstr "Parametrimerkkijono on väärin koodattu" |
| 3294 | +msgstr "Parametrimerkkijono ei ole koodattu oikein" |
| 3295 | |
| 3296 | #: sysdeps/unix/sysv/linux/i386/readelflib.c:65 |
| 3297 | #, c-format |
| 3298 | diff --git a/po/sv.po b/po/sv.po |
| 3299 | index 49d1f23904..e046577b08 100644 |
| 3300 | --- a/po/sv.po |
| 3301 | +++ b/po/sv.po |
| 3302 | @@ -1,13 +1,17 @@ |
| 3303 | # GNU libc message catalog for Swedish |
| 3304 | -# Copyright © 1996, 1998, 2001, 2002, 2003, 2006, 2008, 2009, 2011, 2012, 2013, 2014, 2015 Free Software Foundation, Inc. |
| 3305 | +# Copyright © 1996, 1998, 2001, 2002, 2003, 2006, 2008, 2009, 2011, 2012, 2013, 2014, 2015, 2016 Free Software Foundation, Inc. |
| 3306 | # This file is distributed under the same license as the glibc package. |
| 3307 | -# Jan Djärv <jan.h.d@swipnet.se>, 1996, 1998, 2001, 2002, 2003, 2006, 2007, 2008, 2009, 2011, 2012, 2013, 2014, 2015 |
| 3308 | +# |
| 3309 | +# Jan Djärv <jan.h.d@swipnet.se>, 1996, 1998, 2001, 2002, 2003, 2006, 2007, 2008, 2009, 2011, 2012, 2013, 2014, 2015. |
| 3310 | +# Göran Uddeborg <goeran@uddeborg.se>, 2016. |
| 3311 | +# |
| 3312 | +# $Revision: 1.3 $ |
| 3313 | msgid "" |
| 3314 | msgstr "" |
| 3315 | -"Project-Id-Version: libc 2.21-pre1\n" |
| 3316 | +"Project-Id-Version: libc 2.22-pre1\n" |
| 3317 | "POT-Creation-Date: 2015-07-31 00:10-0400\n" |
| 3318 | -"PO-Revision-Date: 2015-01-24 10:35+0100\n" |
| 3319 | -"Last-Translator: Jan Djärv <jan.h.d@swipnet.se>\n" |
| 3320 | +"PO-Revision-Date: 2016-08-02 17:17+0200\n" |
| 3321 | +"Last-Translator: Göran Uddeborg <goeran@uddeborg.se>\n" |
| 3322 | "Language-Team: Swedish <tp-sv@listor.tp-sv.se>\n" |
| 3323 | "Language: sv\n" |
| 3324 | "MIME-Version: 1.0\n" |
| 3325 | @@ -48,7 +52,7 @@ msgstr " [FLAGGA...]" |
| 3326 | #: argp/argp-help.c:1643 |
| 3327 | #, c-format |
| 3328 | msgid "Try `%s --help' or `%s --usage' for more information.\n" |
| 3329 | -msgstr "Försök med \"%s --help\" eller \"%s --usage\" för mer information\n" |
| 3330 | +msgstr "Försök med ”%s --help” eller ”%s --usage” för mer information.\n" |
| 3331 | |
| 3332 | #: argp/argp-help.c:1671 |
| 3333 | #, c-format |
| 3334 | @@ -304,11 +308,11 @@ msgstr "Användning: xtrace [FLAGGA]... PROGRAM [PROGRAMFLAGGA}...\\n" |
| 3335 | #: debug/xtrace.sh:32 elf/sotruss.sh:56 elf/sotruss.sh:67 elf/sotruss.sh:135 |
| 3336 | #: malloc/memusage.sh:26 |
| 3337 | msgid "Try \\`%s --help' or \\`%s --usage' for more information.\\n" |
| 3338 | -msgstr "Försök med \\\"%s --help\\\" eller \\\"%s --usage\\\" för mer information\\n" |
| 3339 | +msgstr "Försök med ”%s --help” eller ”%s --usage” för mer information\\n" |
| 3340 | |
| 3341 | #: debug/xtrace.sh:38 |
| 3342 | msgid "%s: option '%s' requires an argument.\\n" |
| 3343 | -msgstr "%s: flaggan \\\"%s\\\" kräver ett argument\\n" |
| 3344 | +msgstr "%s: flaggan ”%s” kräver ett argument.\\n" |
| 3345 | |
| 3346 | #: debug/xtrace.sh:45 |
| 3347 | msgid "" |
| 3348 | @@ -332,19 +336,17 @@ msgstr "" |
| 3349 | " --usage Visa en kort hjälptext\n" |
| 3350 | " -V,--version Visa versionsinformation och avsluta\n" |
| 3351 | "\n" |
| 3352 | -"Obligatoriska argument för långa flaggor är obligatoriska även för\n" |
| 3353 | +"Obligatoriska argument för långa flaggor är obligatoriska även för\n" |
| 3354 | "motsvarande korta.\n" |
| 3355 | |
| 3356 | #: debug/xtrace.sh:57 elf/ldd.bash.in:55 elf/sotruss.sh:49 |
| 3357 | #: malloc/memusage.sh:64 |
| 3358 | msgid "For bug reporting instructions, please see:\\\\n%s.\\\\n" |
| 3359 | -msgstr "" |
| 3360 | -"För felrapporteringsinstruktioner, se:\\\\n%s.\\\\n\n" |
| 3361 | -"Rapportera fel eller synpunkter på översättningen till <tp-sv@listor.tp-sv.se>.\\\\n" |
| 3362 | +msgstr "För felrapporteringsinstruktioner, se:\\\\n%s.\\\\nRapportera fel eller synpunkter på översättningen till:\\\\n<tp-sv@listor.tp-sv.se>.\\\\n" |
| 3363 | |
| 3364 | #: debug/xtrace.sh:125 |
| 3365 | msgid "xtrace: unrecognized option \\`$1'\\n" |
| 3366 | -msgstr "xtrace: okänd flagga \"$1\"\\n" |
| 3367 | +msgstr "xtrace: okänd flagga ”$1”\\n" |
| 3368 | |
| 3369 | #: debug/xtrace.sh:138 |
| 3370 | msgid "No program name given\\n" |
| 3371 | @@ -353,12 +355,12 @@ msgstr "Inget programnamn givet\\n" |
| 3372 | #: debug/xtrace.sh:146 |
| 3373 | #, sh-format |
| 3374 | msgid "executable \\`$program' not found\\n" |
| 3375 | -msgstr "program \"$program\" hittades inte\\n" |
| 3376 | +msgstr "program ”$program” hittades inte\\n" |
| 3377 | |
| 3378 | #: debug/xtrace.sh:150 |
| 3379 | #, sh-format |
| 3380 | msgid "\\`$program' is no executable\\n" |
| 3381 | -msgstr "\"$program\" är inte en körbar binär\\n" |
| 3382 | +msgstr "”$program” är inte en körbar binär\\n" |
| 3383 | |
| 3384 | #: dlfcn/dlinfo.c:63 |
| 3385 | msgid "RTLD_SELF used in code not dynamically loaded" |
| 3386 | @@ -396,7 +398,7 @@ msgstr ", OS ABI: %s %d.%d.%d" |
| 3387 | #: elf/cache.c:157 elf/ldconfig.c:1340 |
| 3388 | #, c-format |
| 3389 | msgid "Can't open cache file %s\n" |
| 3390 | -msgstr "Kan inte öppna cache-fil \"%s\"\n" |
| 3391 | +msgstr "Kan inte öppna cache-filen %s\n" |
| 3392 | |
| 3393 | #: elf/cache.c:171 |
| 3394 | #, c-format |
| 3395 | @@ -416,7 +418,7 @@ msgstr "%d bibliotek hittades i cache \"%s\"\n" |
| 3396 | #: elf/cache.c:426 |
| 3397 | #, c-format |
| 3398 | msgid "Can't create temporary cache file %s" |
| 3399 | -msgstr "Kan inte skapa temporär cache-fil \"%s\"" |
| 3400 | +msgstr "Kan inte skapa en temporär cache-fil %s" |
| 3401 | |
| 3402 | #: elf/cache.c:434 elf/cache.c:444 elf/cache.c:448 elf/cache.c:453 |
| 3403 | #, c-format |
| 3404 | @@ -829,7 +831,7 @@ msgstr "Kan inte ta status (lstat) på %s" |
| 3405 | #: elf/ldconfig.c:609 |
| 3406 | #, c-format |
| 3407 | msgid "Ignored file %s since it is not a regular file." |
| 3408 | -msgstr "Ignorerar fil %s eftersom den inte är en vanlig fil" |
| 3409 | +msgstr "Ignorerar fil %s eftersom den inte är en vanlig fil." |
| 3410 | |
| 3411 | #: elf/ldconfig.c:618 |
| 3412 | #, c-format |
| 3413 | @@ -951,7 +953,7 @@ msgstr "" |
| 3414 | |
| 3415 | #: elf/ldd.bash.in:80 |
| 3416 | msgid "ldd: option \\`$1' is ambiguous" |
| 3417 | -msgstr "ldd: flaggan \"$1\" är tvetydig" |
| 3418 | +msgstr "ldd: flaggan ”$1” är tvetydig" |
| 3419 | |
| 3420 | #: elf/ldd.bash.in:87 |
| 3421 | msgid "unrecognized option" |
| 3422 | @@ -959,7 +961,7 @@ msgstr "okänd flagga" |
| 3423 | |
| 3424 | #: elf/ldd.bash.in:88 elf/ldd.bash.in:125 |
| 3425 | msgid "Try \\`ldd --help' for more information." |
| 3426 | -msgstr "Försök med \"ldd --help\" för mer information" |
| 3427 | +msgstr "Försök med \"ldd --help\" för mer information." |
| 3428 | |
| 3429 | #: elf/ldd.bash.in:124 |
| 3430 | msgid "missing file arguments" |
| 3431 | @@ -1028,10 +1030,9 @@ msgid "cannot read object name" |
| 3432 | msgstr "kan inte läsa objektnamn" |
| 3433 | |
| 3434 | #: elf/pldd-xx.c:219 |
| 3435 | -#, fuzzy, c-format |
| 3436 | -#| msgid "cannot allocate memory for program header" |
| 3437 | +#, c-format |
| 3438 | msgid "cannot allocate buffer for object name" |
| 3439 | -msgstr "kan inte allokera minne för programhuvud" |
| 3440 | +msgstr "kan inte allokera en buffert för objektnamn" |
| 3441 | |
| 3442 | #: elf/pldd.c:64 |
| 3443 | msgid "List dynamic shared objects loaded into process." |
| 3444 | @@ -1212,11 +1213,11 @@ msgstr "" |
| 3445 | |
| 3446 | #: elf/sotruss.sh:46 |
| 3447 | msgid "Mandatory arguments to long options are also mandatory for any corresponding\\nshort options.\\n" |
| 3448 | -msgstr "Obligatoriska respektive valfria argument för långa flaggor är obligatoriska respektive\\nvalfria även för korta.\\n" |
| 3449 | +msgstr "Obligatoriska respektive valfria argument för långa flaggor är obligatoriska\\nrespektive valfria även för korta.\\n" |
| 3450 | |
| 3451 | #: elf/sotruss.sh:55 |
| 3452 | msgid "%s: option requires an argument -- '%s'\\n" |
| 3453 | -msgstr "%s: flaggan kräver ett argument -- \\\"%s\\\"\\n" |
| 3454 | +msgstr "%s: flaggan kräver ett argument — ”%s”\\n" |
| 3455 | |
| 3456 | #: elf/sotruss.sh:61 |
| 3457 | msgid "%s: option is ambiguous; possibilities:" |
| 3458 | @@ -1240,7 +1241,7 @@ msgstr "" |
| 3459 | |
| 3460 | #: elf/sotruss.sh:134 |
| 3461 | msgid "%s: unrecognized option '%c%s'\\n" |
| 3462 | -msgstr "%s: okänd flagga \\\"%c%s\\\"\\n" |
| 3463 | +msgstr "%s: okänd flagga ”%c%s”\\n" |
| 3464 | |
| 3465 | #: elf/sprof.c:77 |
| 3466 | msgid "Output selection:" |
| 3467 | @@ -1260,7 +1261,7 @@ msgstr "generera anropsgraf" |
| 3468 | |
| 3469 | #: elf/sprof.c:89 |
| 3470 | msgid "Read and display shared object profiling data." |
| 3471 | -msgstr "Läs och visa profildata för delat objekt" |
| 3472 | +msgstr "Läs och visa profildata för delat objekt." |
| 3473 | |
| 3474 | #: elf/sprof.c:94 |
| 3475 | msgid "SHOBJ [PROFDATA]" |
| 3476 | @@ -1622,7 +1623,7 @@ msgstr "Fel: .netrc kan läsas av andra." |
| 3477 | |
| 3478 | #: inet/ruserpass.c:185 |
| 3479 | msgid "Remove password or make file unreadable by others." |
| 3480 | -msgstr "Ta bort lösenord eller gör filen oläsbar för andra" |
| 3481 | +msgstr "Ta bort lösenord eller gör filen oläsbar för andra." |
| 3482 | |
| 3483 | #: inet/ruserpass.c:277 |
| 3484 | #, c-format |
| 3485 | @@ -2182,12 +2183,12 @@ msgstr "Inget namn definierat i teckenuppsättning" |
| 3486 | #: locale/programs/ld-ctype.c:479 |
| 3487 | #, c-format |
| 3488 | msgid "character L'\\u%0*x' in class `%s' must be in class `%s'" |
| 3489 | -msgstr "tecken L\"\\u%0*x\" i klass \"%s\" måste vara i klass \"%s\"" |
| 3490 | +msgstr "tecken L'\\u%0*x' i klassen ”%s” måste vara i klassen ”%s”" |
| 3491 | |
| 3492 | #: locale/programs/ld-ctype.c:494 |
| 3493 | #, c-format |
| 3494 | msgid "character L'\\u%0*x' in class `%s' must not be in class `%s'" |
| 3495 | -msgstr "tecken L\"\\u%0*x\" i klass \"%s\" får inte vara i klass \"%s\"" |
| 3496 | +msgstr "tecken L'\\u%0*x' i klassen ”%s” får inte vara i klassen ”%s”" |
| 3497 | |
| 3498 | #: locale/programs/ld-ctype.c:508 locale/programs/ld-ctype.c:566 |
| 3499 | #, c-format |
| 3500 | @@ -2611,7 +2612,7 @@ msgstr "Skriv mer information" |
| 3501 | |
| 3502 | #: locale/programs/locale.c:85 |
| 3503 | msgid "Get locale-specific information." |
| 3504 | -msgstr "Hämta lokalspecifik information" |
| 3505 | +msgstr "Hämta lokalspecifik information." |
| 3506 | |
| 3507 | #: locale/programs/locale.c:88 |
| 3508 | msgid "" |
| 3509 | @@ -3022,7 +3023,7 @@ msgstr "felaktig mcheck_status, biblioteket är felaktigt\n" |
| 3510 | |
| 3511 | #: malloc/memusage.sh:32 |
| 3512 | msgid "%s: option '%s' requires an argument\\n" |
| 3513 | -msgstr "%s: flaggan \\\"%s\\\" kräver ett argument\\n" |
| 3514 | +msgstr "%s: flaggan ”%s” kräver ett argument\\n" |
| 3515 | |
| 3516 | #: malloc/memusage.sh:38 |
| 3517 | msgid "" |
| 3518 | @@ -3091,11 +3092,11 @@ msgstr "" |
| 3519 | |
| 3520 | #: malloc/memusage.sh:191 |
| 3521 | msgid "memusage: option \\`${1##*=}' is ambiguous" |
| 3522 | -msgstr "memusage: flaggan \"${1##*=}\" är tvetydig" |
| 3523 | +msgstr "memusage: flaggan ”${1##*=}” är tvetydig" |
| 3524 | |
| 3525 | #: malloc/memusage.sh:200 |
| 3526 | msgid "memusage: unrecognized option \\`$1'" |
| 3527 | -msgstr "memusage: okänd flagga \"$1\"" |
| 3528 | +msgstr "memusage: okänd flagga ”$1”" |
| 3529 | |
| 3530 | #: malloc/memusage.sh:213 |
| 3531 | msgid "No program name given" |
| 3532 | @@ -3341,7 +3342,7 @@ msgstr "Kan inte skapa process hos server" |
| 3533 | |
| 3534 | #: nis/nis_error.h:48 |
| 3535 | msgid "Master server busy, full dump rescheduled." |
| 3536 | -msgstr "Huvudserver är upptagen, full dump åter schemalagd" |
| 3537 | +msgstr "Huvudserver är upptagen, full dump åter schemalagd." |
| 3538 | |
| 3539 | #: nis/nis_local_names.c:121 |
| 3540 | #, c-format |
| 3541 | @@ -3511,7 +3512,7 @@ msgstr "\t\tRättigheter : " |
| 3542 | |
| 3543 | #: nis/nis_print.c:290 |
| 3544 | msgid "Linked Object Type : " |
| 3545 | -msgstr "Länkad objekttyp: " |
| 3546 | +msgstr "Länkad objekttyp : " |
| 3547 | |
| 3548 | #: nis/nis_print.c:292 |
| 3549 | #, c-format |
| 3550 | @@ -3802,15 +3803,14 @@ msgid " (first)" |
| 3551 | msgstr " (första)" |
| 3552 | |
| 3553 | #: nscd/cache.c:288 |
| 3554 | -#, fuzzy, c-format |
| 3555 | -#| msgid "cannot stat() file `%s': %s" |
| 3556 | +#, c-format |
| 3557 | msgid "checking for monitored file `%s': %s" |
| 3558 | -msgstr "kan inte ta status på fil \"%s\": %s" |
| 3559 | +msgstr "kontrollerar den övervakade filen ”%s”: %s" |
| 3560 | |
| 3561 | #: nscd/cache.c:298 |
| 3562 | #, c-format |
| 3563 | msgid "monitored file `%s` changed (mtime)" |
| 3564 | -msgstr "" |
| 3565 | +msgstr "den övervakade filen ”%s” ändrades (mtime)" |
| 3566 | |
| 3567 | #: nscd/cache.c:341 |
| 3568 | #, c-format |
| 3569 | @@ -3906,34 +3906,32 @@ msgstr "kan inte få uttag (socket) att acceptera förbindelser: %s" |
| 3570 | #: nscd/connections.c:973 |
| 3571 | #, c-format |
| 3572 | msgid "disabled inotify-based monitoring for file `%s': %s" |
| 3573 | -msgstr "" |
| 3574 | +msgstr "avaktiverade inotify-baserad övervakning för filen ”%s”: %s" |
| 3575 | |
| 3576 | #: nscd/connections.c:977 |
| 3577 | #, c-format |
| 3578 | msgid "monitoring file `%s` (%d)" |
| 3579 | -msgstr "" |
| 3580 | +msgstr "övervakar filen ”%s” (%d)" |
| 3581 | |
| 3582 | #: nscd/connections.c:990 |
| 3583 | #, c-format |
| 3584 | msgid "disabled inotify-based monitoring for directory `%s': %s" |
| 3585 | -msgstr "" |
| 3586 | +msgstr "avaktiverade inotify-baserad övervakning av katalogen ”%s”: %s" |
| 3587 | |
| 3588 | #: nscd/connections.c:994 |
| 3589 | -#, fuzzy, c-format |
| 3590 | -#| msgid "Can't open directory %s" |
| 3591 | +#, c-format |
| 3592 | msgid "monitoring directory `%s` (%d)" |
| 3593 | -msgstr "Kan inte öppna katalog %s" |
| 3594 | +msgstr "övervakar katalogen ”%s” (%d)" |
| 3595 | |
| 3596 | #: nscd/connections.c:1022 |
| 3597 | -#, fuzzy, c-format |
| 3598 | -#| msgid "register trace file %s for database %s" |
| 3599 | +#, c-format |
| 3600 | msgid "monitoring file %s for database %s" |
| 3601 | -msgstr "registrera spårningsfil %s för databas %s" |
| 3602 | +msgstr "övervakar filen %s för databas %s" |
| 3603 | |
| 3604 | #: nscd/connections.c:1032 |
| 3605 | #, c-format |
| 3606 | msgid "stat failed for file `%s'; will try again later: %s" |
| 3607 | -msgstr "" |
| 3608 | +msgstr "stat misslyckades för filen ”%s”; kommer försöka igen senare: %s" |
| 3609 | |
| 3610 | #: nscd/connections.c:1151 |
| 3611 | #, c-format |
| 3612 | @@ -4032,44 +4030,42 @@ msgstr "handle_request: begäran mottagen (Version = %d)" |
| 3613 | #: nscd/connections.c:1963 |
| 3614 | #, c-format |
| 3615 | msgid "ignored inotify event for `%s` (file exists)" |
| 3616 | -msgstr "" |
| 3617 | +msgstr "ignorerade inotify-händelse för ”%s” (filen finns)" |
| 3618 | |
| 3619 | #: nscd/connections.c:1968 |
| 3620 | #, c-format |
| 3621 | msgid "monitored file `%s` was %s, removing watch" |
| 3622 | -msgstr "" |
| 3623 | +msgstr "den övervakade filen ”%s” var %s, tar bort vakten" |
| 3624 | |
| 3625 | #: nscd/connections.c:1976 nscd/connections.c:2018 |
| 3626 | #, c-format |
| 3627 | msgid "failed to remove file watch `%s`: %s" |
| 3628 | -msgstr "" |
| 3629 | +msgstr "misslyckades att ta bort filvakt ”%s”: %s" |
| 3630 | |
| 3631 | #: nscd/connections.c:1991 |
| 3632 | #, c-format |
| 3633 | msgid "monitored file `%s` was written to" |
| 3634 | -msgstr "" |
| 3635 | +msgstr "den övervakade filen ”%s” skrevs till" |
| 3636 | |
| 3637 | #: nscd/connections.c:2015 |
| 3638 | #, c-format |
| 3639 | msgid "monitored parent directory `%s` was %s, removing watch on `%s`" |
| 3640 | -msgstr "" |
| 3641 | +msgstr "den övervakade föräldrakatalogen ”%s” var %s, tar bort vakten av ”%s”" |
| 3642 | |
| 3643 | #: nscd/connections.c:2041 |
| 3644 | #, c-format |
| 3645 | msgid "monitored file `%s` was %s, adding watch" |
| 3646 | -msgstr "" |
| 3647 | +msgstr "den övervakade filen ”%s” var %s, lägger till vakt" |
| 3648 | |
| 3649 | #: nscd/connections.c:2053 |
| 3650 | -#, fuzzy, c-format |
| 3651 | -#| msgid "failed to load shared object `%s'" |
| 3652 | +#, c-format |
| 3653 | msgid "failed to add file watch `%s`: %s" |
| 3654 | -msgstr "misslyckades med att ladda delat objekt \"%s\"" |
| 3655 | +msgstr "misslyckades med att lägga till filvakt ”%s”: %s" |
| 3656 | |
| 3657 | #: nscd/connections.c:2247 nscd/connections.c:2428 |
| 3658 | -#, fuzzy, c-format |
| 3659 | -#| msgid "disabled inotify after read error %d" |
| 3660 | +#, c-format |
| 3661 | msgid "disabled inotify-based monitoring after read error %d" |
| 3662 | -msgstr "inaktiverade inotify efter läsfel %d" |
| 3663 | +msgstr "avaktiverade inotify-baserad övervakning efter läsfel %d" |
| 3664 | |
| 3665 | #: nscd/connections.c:2543 |
| 3666 | msgid "could not initialize conditional variable" |
| 3667 | @@ -4199,7 +4195,7 @@ msgstr "Använd separat cache för varje användare" |
| 3668 | |
| 3669 | #: nscd/nscd.c:122 |
| 3670 | msgid "Name Service Cache Daemon." |
| 3671 | -msgstr "Namntjänst cache-demon" |
| 3672 | +msgstr "Cache-demon för namntjänsten." |
| 3673 | |
| 3674 | #: nscd/nscd.c:155 nss/getent.c:1007 nss/makedb.c:206 |
| 3675 | #, c-format |
| 3676 | @@ -4531,11 +4527,11 @@ msgstr "Access Vector Cache (AVC) startad" |
| 3677 | |
| 3678 | #: nscd/selinux.c:368 |
| 3679 | msgid "Error querying policy for undefined object classes or permissions." |
| 3680 | -msgstr "Fel när policy för odefinierade objektklasser eller rättigheter hämtades" |
| 3681 | +msgstr "Fel när policy för odefinierade objektklasser eller rättigheter hämtades." |
| 3682 | |
| 3683 | #: nscd/selinux.c:375 |
| 3684 | msgid "Error getting security class for nscd." |
| 3685 | -msgstr "Fel när säkerhetsklass för nscd hämtades" |
| 3686 | +msgstr "Fel när säkerhetsklass för nscd hämtades." |
| 3687 | |
| 3688 | #: nscd/selinux.c:380 |
| 3689 | #, c-format |
| 3690 | @@ -4609,7 +4605,7 @@ msgstr "inaktivera DIN-kodning" |
| 3691 | |
| 3692 | #: nss/getent.c:64 |
| 3693 | msgid "Get entries from administrative database." |
| 3694 | -msgstr "Hämta poster från den administrativa databasen" |
| 3695 | +msgstr "Hämta poster från den administrativa databasen." |
| 3696 | |
| 3697 | #: nss/getent.c:148 nss/getent.c:477 nss/getent.c:522 |
| 3698 | #, c-format |
| 3699 | @@ -4652,7 +4648,7 @@ msgstr "Genererad rad som inte ingår i iterationen" |
| 3700 | |
| 3701 | #: nss/makedb.c:131 |
| 3702 | msgid "Create simple database from textual input." |
| 3703 | -msgstr "Skapa en enkel databas från textuell indata" |
| 3704 | +msgstr "Skapa en enkel databas från textuell indata." |
| 3705 | |
| 3706 | #: nss/makedb.c:134 |
| 3707 | msgid "" |
| 3708 | @@ -5412,7 +5408,7 @@ msgstr "Kan inte ange netid-flaggan utan TIRPC!\n" |
| 3709 | #: sunrpc/rpc_main.c:1374 |
| 3710 | #, c-format |
| 3711 | msgid "Cannot use table flags with newstyle!\n" |
| 3712 | -msgstr "Kan inte ange tabellflaggor med ny stil\n" |
| 3713 | +msgstr "Kan inte ange tabellflaggor med ny stil!\n" |
| 3714 | |
| 3715 | #: sunrpc/rpc_main.c:1393 |
| 3716 | #, c-format |
| 3717 | @@ -7270,18 +7266,9 @@ msgstr "tidszonsförkortning skiljer sig från POSIX-standarden" |
| 3718 | |
| 3719 | #: timezone/zic.c:2789 |
| 3720 | msgid "too many, or too long, time zone abbreviations" |
| 3721 | -msgstr "för många eller för långa tidszonförkortningar" |
| 3722 | +msgstr "för många eller för långa tidszonsförkortningar" |
| 3723 | |
| 3724 | #: timezone/zic.c:2829 |
| 3725 | #, c-format |
| 3726 | msgid "%s: Can't create directory %s: %s\n" |
| 3727 | msgstr "%s: Kan inte skapa katalog %s: %s\n" |
| 3728 | - |
| 3729 | -#~ msgid "cannot load any more object with static TLS" |
| 3730 | -#~ msgstr "kan inte ladda fler objekt med statiskt TLS" |
| 3731 | - |
| 3732 | -#~ msgid "%s: no PLTREL found in object %s\n" |
| 3733 | -#~ msgstr "%s: hittade inga PLTREL i objekt %s\n" |
| 3734 | - |
| 3735 | -#~ msgid "cannot create internal descriptors" |
| 3736 | -#~ msgstr "kan inte skapa interna deskriptorer" |
| 3737 | diff --git a/posix/Makefile b/posix/Makefile |
| 3738 | index 5b0e298f75..82a4020c76 100644 |
| 3739 | --- a/posix/Makefile |
| 3740 | +++ b/posix/Makefile |
| 3741 | @@ -43,7 +43,7 @@ routines := \ |
| 3742 | getpgid setpgid getpgrp bsd-getpgrp setpgrp getsid setsid \ |
| 3743 | getresuid getresgid setresuid setresgid \ |
| 3744 | pathconf sysconf fpathconf \ |
| 3745 | - glob glob64 fnmatch regex \ |
| 3746 | + glob glob64 globfree globfree64 glob_pattern_p fnmatch regex \ |
| 3747 | confstr \ |
| 3748 | getopt getopt1 getopt_init \ |
| 3749 | sched_setp sched_getp sched_sets sched_gets sched_yield sched_primax \ |
| 3750 | @@ -90,7 +90,7 @@ tests := tstgetopt testfnm runtests runptests \ |
| 3751 | bug-getopt5 tst-getopt_long1 bug-regex34 bug-regex35 \ |
| 3752 | tst-pathconf tst-getaddrinfo4 tst-rxspencer-no-utf8 \ |
| 3753 | tst-fnmatch3 bug-regex36 tst-getaddrinfo5 \ |
| 3754 | - tst-posix_spawn-fd |
| 3755 | + tst-posix_spawn-fd tst-glob-tilde |
| 3756 | xtests := bug-ga2 |
| 3757 | ifeq (yes,$(build-shared)) |
| 3758 | test-srcs := globtest |
| 3759 | @@ -133,7 +133,8 @@ tests-special += $(objpfx)bug-regex2-mem.out $(objpfx)bug-regex14-mem.out \ |
| 3760 | $(objpfx)tst-rxspencer-no-utf8-mem.out $(objpfx)tst-pcre-mem.out \ |
| 3761 | $(objpfx)tst-boost-mem.out $(objpfx)tst-getconf.out \ |
| 3762 | $(objpfx)bug-glob2-mem.out $(objpfx)tst-vfork3-mem.out \ |
| 3763 | - $(objpfx)tst-fnmatch-mem.out $(objpfx)bug-regex36-mem.out |
| 3764 | + $(objpfx)tst-fnmatch-mem.out $(objpfx)bug-regex36-mem.out \ |
| 3765 | + $(objpfx)tst-glob-tilde-mem.out |
| 3766 | xtests-special += $(objpfx)bug-ga2-mem.out |
| 3767 | endif |
| 3768 | |
| 3769 | @@ -340,6 +341,12 @@ $(objpfx)bug-glob2-mem.out: $(objpfx)bug-glob2.out |
| 3770 | $(common-objpfx)malloc/mtrace $(objpfx)bug-glob2.mtrace > $@; \ |
| 3771 | $(evaluate-test) |
| 3772 | |
| 3773 | +tst-glob-tilde-ENV = MALLOC_TRACE=$(objpfx)tst-glob-tilde.mtrace |
| 3774 | + |
| 3775 | +$(objpfx)tst-glob-tilde-mem.out: $(objpfx)tst-glob-tilde.out |
| 3776 | + $(common-objpfx)malloc/mtrace $(objpfx)tst-glob-tilde.mtrace > $@; \ |
| 3777 | + $(evaluate-test) |
| 3778 | + |
| 3779 | $(inst_libexecdir)/getconf: $(inst_bindir)/getconf \ |
| 3780 | $(objpfx)getconf.speclist FORCE |
| 3781 | $(addprefix $(..)./scripts/mkinstalldirs ,\ |
| 3782 | diff --git a/posix/execvpe.c b/posix/execvpe.c |
| 3783 | index d933f9c92a..7cdb06a611 100644 |
| 3784 | --- a/posix/execvpe.c |
| 3785 | +++ b/posix/execvpe.c |
| 3786 | @@ -48,12 +48,13 @@ maybe_script_execute (const char *file, char *const argv[], char *const envp[]) |
| 3787 | } |
| 3788 | } |
| 3789 | |
| 3790 | - /* Construct an argument list for the shell. */ |
| 3791 | + /* Construct an argument list for the shell. It will contain at minimum 3 |
| 3792 | + arguments (current shell, script, and an ending NULL. */ |
| 3793 | char *new_argv[argc + 1]; |
| 3794 | new_argv[0] = (char *) _PATH_BSHELL; |
| 3795 | new_argv[1] = (char *) file; |
| 3796 | if (argc > 1) |
| 3797 | - memcpy (new_argv + 2, argv + 1, argc * sizeof(char *)); |
| 3798 | + memcpy (new_argv + 2, argv + 1, (argc - 1) * sizeof(char *)); |
| 3799 | else |
| 3800 | new_argv[2] = NULL; |
| 3801 | |
| 3802 | @@ -91,10 +92,11 @@ __execvpe (const char *file, char *const argv[], char *const envp[]) |
| 3803 | /* Although GLIBC does not enforce NAME_MAX, we set it as the maximum |
| 3804 | size to avoid unbounded stack allocation. Same applies for |
| 3805 | PATH_MAX. */ |
| 3806 | - size_t file_len = __strnlen (file, NAME_MAX + 1); |
| 3807 | + size_t file_len = __strnlen (file, NAME_MAX) + 1; |
| 3808 | size_t path_len = __strnlen (path, PATH_MAX - 1) + 1; |
| 3809 | |
| 3810 | - if ((file_len > NAME_MAX) |
| 3811 | + /* NAME_MAX does not include the terminating null character. */ |
| 3812 | + if (((file_len-1) > NAME_MAX) |
| 3813 | || !__libc_alloca_cutoff (path_len + file_len + 1)) |
| 3814 | { |
| 3815 | errno = ENAMETOOLONG; |
| 3816 | @@ -103,6 +105,9 @@ __execvpe (const char *file, char *const argv[], char *const envp[]) |
| 3817 | |
| 3818 | const char *subp; |
| 3819 | bool got_eacces = false; |
| 3820 | + /* The resulting string maximum size would be potentially a entry |
| 3821 | + in PATH plus '/' (path_len + 1) and then the the resulting file name |
| 3822 | + plus '\0' (file_len since it already accounts for the '\0'). */ |
| 3823 | char buffer[path_len + file_len + 1]; |
| 3824 | for (const char *p = path; ; p = subp) |
| 3825 | { |
| 3826 | @@ -123,7 +128,7 @@ __execvpe (const char *file, char *const argv[], char *const envp[]) |
| 3827 | execute. */ |
| 3828 | char *pend = mempcpy (buffer, p, subp - p); |
| 3829 | *pend = '/'; |
| 3830 | - memcpy (pend + (p < subp), file, file_len + 1); |
| 3831 | + memcpy (pend + (p < subp), file, file_len); |
| 3832 | |
| 3833 | __execve (buffer, argv, envp); |
| 3834 | |
| 3835 | diff --git a/posix/flexmember.h b/posix/flexmember.h |
| 3836 | new file mode 100644 |
| 3837 | index 0000000000..107c1f09e9 |
| 3838 | --- /dev/null |
| 3839 | +++ b/posix/flexmember.h |
| 3840 | @@ -0,0 +1,45 @@ |
| 3841 | +/* Sizes of structs with flexible array members. |
| 3842 | + |
| 3843 | + Copyright 2016-2017 Free Software Foundation, Inc. |
| 3844 | + |
| 3845 | + This file is part of the GNU C Library. |
| 3846 | + |
| 3847 | + The GNU C Library is free software; you can redistribute it and/or |
| 3848 | + modify it under the terms of the GNU Lesser General Public |
| 3849 | + License as published by the Free Software Foundation; either |
| 3850 | + version 2.1 of the License, or (at your option) any later version. |
| 3851 | + |
| 3852 | + The GNU C Library is distributed in the hope that it will be useful, |
| 3853 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 3854 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 3855 | + Lesser General Public License for more details. |
| 3856 | + |
| 3857 | + You should have received a copy of the GNU Lesser General Public |
| 3858 | + License along with the GNU C Library; if not, see |
| 3859 | + <http://www.gnu.org/licenses/>. |
| 3860 | + |
| 3861 | + Written by Paul Eggert. */ |
| 3862 | + |
| 3863 | +#include <stddef.h> |
| 3864 | + |
| 3865 | +/* Nonzero multiple of alignment of TYPE, suitable for FLEXSIZEOF below. |
| 3866 | + On older platforms without _Alignof, use a pessimistic bound that is |
| 3867 | + safe in practice even if FLEXIBLE_ARRAY_MEMBER is 1. |
| 3868 | + On newer platforms, use _Alignof to get a tighter bound. */ |
| 3869 | + |
| 3870 | +#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 |
| 3871 | +# define FLEXALIGNOF(type) (sizeof (type) & ~ (sizeof (type) - 1)) |
| 3872 | +#else |
| 3873 | +# define FLEXALIGNOF(type) _Alignof (type) |
| 3874 | +#endif |
| 3875 | + |
| 3876 | +/* Upper bound on the size of a struct of type TYPE with a flexible |
| 3877 | + array member named MEMBER that is followed by N bytes of other data. |
| 3878 | + This is not simply sizeof (TYPE) + N, since it may require |
| 3879 | + alignment on unusually picky C11 platforms, and |
| 3880 | + FLEXIBLE_ARRAY_MEMBER may be 1 on pre-C11 platforms. |
| 3881 | + Yield a value less than N if and only if arithmetic overflow occurs. */ |
| 3882 | + |
| 3883 | +#define FLEXSIZEOF(type, member, n) \ |
| 3884 | + ((offsetof (type, member) + FLEXALIGNOF (type) - 1 + (n)) \ |
| 3885 | + & ~ (FLEXALIGNOF (type) - 1)) |
| 3886 | diff --git a/posix/glob.c b/posix/glob.c |
| 3887 | index ea4b0b61eb..f3fa807700 100644 |
| 3888 | --- a/posix/glob.c |
| 3889 | +++ b/posix/glob.c |
| 3890 | @@ -15,7 +15,7 @@ |
| 3891 | License along with the GNU C Library; if not, see |
| 3892 | <http://www.gnu.org/licenses/>. */ |
| 3893 | |
| 3894 | -#ifdef HAVE_CONFIG_H |
| 3895 | +#ifndef _LIBC |
| 3896 | # include <config.h> |
| 3897 | #endif |
| 3898 | |
| 3899 | @@ -27,29 +27,15 @@ |
| 3900 | #include <stdbool.h> |
| 3901 | #include <stddef.h> |
| 3902 | #include <stdint.h> |
| 3903 | - |
| 3904 | -/* Outcomment the following line for production quality code. */ |
| 3905 | -/* #define NDEBUG 1 */ |
| 3906 | #include <assert.h> |
| 3907 | +#include <unistd.h> |
| 3908 | |
| 3909 | -#include <stdio.h> /* Needed on stupid SunOS for assert. */ |
| 3910 | - |
| 3911 | -#if !defined _LIBC || !defined GLOB_ONLY_P |
| 3912 | -#if defined HAVE_UNISTD_H || defined _LIBC |
| 3913 | -# include <unistd.h> |
| 3914 | -# ifndef POSIX |
| 3915 | -# ifdef _POSIX_VERSION |
| 3916 | -# define POSIX |
| 3917 | -# endif |
| 3918 | -# endif |
| 3919 | +#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ |
| 3920 | +# define WINDOWS32 |
| 3921 | #endif |
| 3922 | |
| 3923 | -#include <pwd.h> |
| 3924 | - |
| 3925 | -#if defined HAVE_STDINT_H || defined _LIBC |
| 3926 | -# include <stdint.h> |
| 3927 | -#elif !defined UINTPTR_MAX |
| 3928 | -# define UINTPTR_MAX (~((size_t) 0)) |
| 3929 | +#ifndef WINDOWS32 |
| 3930 | +# include <pwd.h> |
| 3931 | #endif |
| 3932 | |
| 3933 | #include <errno.h> |
| 3934 | @@ -57,24 +43,7 @@ |
| 3935 | # define __set_errno(val) errno = (val) |
| 3936 | #endif |
| 3937 | |
| 3938 | -#if defined HAVE_DIRENT_H || defined __GNU_LIBRARY__ |
| 3939 | -# include <dirent.h> |
| 3940 | -#else |
| 3941 | -# define dirent direct |
| 3942 | -# ifdef HAVE_SYS_NDIR_H |
| 3943 | -# include <sys/ndir.h> |
| 3944 | -# endif |
| 3945 | -# ifdef HAVE_SYS_DIR_H |
| 3946 | -# include <sys/dir.h> |
| 3947 | -# endif |
| 3948 | -# ifdef HAVE_NDIR_H |
| 3949 | -# include <ndir.h> |
| 3950 | -# endif |
| 3951 | -# ifdef HAVE_VMSDIR_H |
| 3952 | -# include "vmsdir.h" |
| 3953 | -# endif /* HAVE_VMSDIR_H */ |
| 3954 | -#endif |
| 3955 | - |
| 3956 | +#include <dirent.h> |
| 3957 | #include <stdlib.h> |
| 3958 | #include <string.h> |
| 3959 | #include <alloca.h> |
| 3960 | @@ -87,27 +56,29 @@ |
| 3961 | # define opendir(name) __opendir (name) |
| 3962 | # define readdir(str) __readdir64 (str) |
| 3963 | # define getpwnam_r(name, bufp, buf, len, res) \ |
| 3964 | - __getpwnam_r (name, bufp, buf, len, res) |
| 3965 | + __getpwnam_r (name, bufp, buf, len, res) |
| 3966 | # ifndef __stat64 |
| 3967 | # define __stat64(fname, buf) __xstat64 (_STAT_VER, fname, buf) |
| 3968 | # endif |
| 3969 | # define struct_stat64 struct stat64 |
| 3970 | +# define FLEXIBLE_ARRAY_MEMBER |
| 3971 | #else /* !_LIBC */ |
| 3972 | -# include "getlogin_r.h" |
| 3973 | -# include "mempcpy.h" |
| 3974 | -# include "stat-macros.h" |
| 3975 | -# include "strdup.h" |
| 3976 | -# define __stat64(fname, buf) stat (fname, buf) |
| 3977 | -# define struct_stat64 struct stat |
| 3978 | -# define __stat(fname, buf) stat (fname, buf) |
| 3979 | -# define __alloca alloca |
| 3980 | -# define __readdir readdir |
| 3981 | -# define __readdir64 readdir64 |
| 3982 | -# define __glob_pattern_p glob_pattern_p |
| 3983 | +# define __getlogin_r(buf, len) getlogin_r (buf, len) |
| 3984 | +# define __stat64(fname, buf) stat (fname, buf) |
| 3985 | +# define __fxstatat64(_, d, f, st, flag) fstatat (d, f, st, flag) |
| 3986 | +# define struct_stat64 struct stat |
| 3987 | +# ifndef __MVS__ |
| 3988 | +# define __alloca alloca |
| 3989 | +# endif |
| 3990 | +# define __readdir readdir |
| 3991 | +# define COMPILE_GLOB64 |
| 3992 | #endif /* _LIBC */ |
| 3993 | |
| 3994 | #include <fnmatch.h> |
| 3995 | |
| 3996 | +#include <flexmember.h> |
| 3997 | +#include <glob_internal.h> |
| 3998 | + |
| 3999 | #ifdef _SC_GETPW_R_SIZE_MAX |
| 4000 | # define GETPW_R_SIZE_MAX() sysconf (_SC_GETPW_R_SIZE_MAX) |
| 4001 | #else |
| 4002 | @@ -121,61 +92,59 @@ |
| 4003 | \f |
| 4004 | static const char *next_brace_sub (const char *begin, int flags) __THROWNL; |
| 4005 | |
| 4006 | +typedef uint_fast8_t dirent_type; |
| 4007 | + |
| 4008 | +#if !defined _LIBC && !defined HAVE_STRUCT_DIRENT_D_TYPE |
| 4009 | +/* Any distinct values will do here. |
| 4010 | + Undef any existing macros out of the way. */ |
| 4011 | +# undef DT_UNKNOWN |
| 4012 | +# undef DT_DIR |
| 4013 | +# undef DT_LNK |
| 4014 | +# define DT_UNKNOWN 0 |
| 4015 | +# define DT_DIR 1 |
| 4016 | +# define DT_LNK 2 |
| 4017 | +#endif |
| 4018 | + |
| 4019 | /* A representation of a directory entry which does not depend on the |
| 4020 | layout of struct dirent, or the size of ino_t. */ |
| 4021 | struct readdir_result |
| 4022 | { |
| 4023 | const char *name; |
| 4024 | -# if defined _DIRENT_HAVE_D_TYPE || defined HAVE_STRUCT_DIRENT_D_TYPE |
| 4025 | - uint8_t type; |
| 4026 | -# endif |
| 4027 | +#if defined _DIRENT_HAVE_D_TYPE || defined HAVE_STRUCT_DIRENT_D_TYPE |
| 4028 | + dirent_type type; |
| 4029 | +#endif |
| 4030 | +#if defined _LIBC || defined D_INO_IN_DIRENT |
| 4031 | bool skip_entry; |
| 4032 | +#endif |
| 4033 | }; |
| 4034 | |
| 4035 | -# if defined _DIRENT_HAVE_D_TYPE || defined HAVE_STRUCT_DIRENT_D_TYPE |
| 4036 | -/* Initializer based on the d_type member of struct dirent. */ |
| 4037 | -# define D_TYPE_TO_RESULT(source) (source)->d_type, |
| 4038 | - |
| 4039 | -/* True if the directory entry D might be a symbolic link. */ |
| 4040 | -static bool |
| 4041 | -readdir_result_might_be_symlink (struct readdir_result d) |
| 4042 | -{ |
| 4043 | - return d.type == DT_UNKNOWN || d.type == DT_LNK; |
| 4044 | -} |
| 4045 | - |
| 4046 | -/* True if the directory entry D might be a directory. */ |
| 4047 | -static bool |
| 4048 | -readdir_result_might_be_dir (struct readdir_result d) |
| 4049 | -{ |
| 4050 | - return d.type == DT_DIR || readdir_result_might_be_symlink (d); |
| 4051 | -} |
| 4052 | -# else /* defined _DIRENT_HAVE_D_TYPE || defined HAVE_STRUCT_DIRENT_D_TYPE */ |
| 4053 | -# define D_TYPE_TO_RESULT(source) |
| 4054 | - |
| 4055 | -/* If we do not have type information, symbolic links and directories |
| 4056 | - are always a possibility. */ |
| 4057 | - |
| 4058 | -static bool |
| 4059 | -readdir_result_might_be_symlink (struct readdir_result d) |
| 4060 | +/* Initialize and return type member of struct readdir_result. */ |
| 4061 | +static dirent_type |
| 4062 | +readdir_result_type (struct readdir_result d) |
| 4063 | { |
| 4064 | - return true; |
| 4065 | +#if defined _DIRENT_HAVE_D_TYPE || defined HAVE_STRUCT_DIRENT_D_TYPE |
| 4066 | +# define D_TYPE_TO_RESULT(source) (source)->d_type, |
| 4067 | + return d.type; |
| 4068 | +#else |
| 4069 | +# define D_TYPE_TO_RESULT(source) |
| 4070 | + return DT_UNKNOWN; |
| 4071 | +#endif |
| 4072 | } |
| 4073 | |
| 4074 | +/* Initialize and return skip_entry member of struct readdir_result. */ |
| 4075 | static bool |
| 4076 | -readdir_result_might_be_dir (struct readdir_result d) |
| 4077 | +readdir_result_skip_entry (struct readdir_result d) |
| 4078 | { |
| 4079 | - return true; |
| 4080 | -} |
| 4081 | - |
| 4082 | -# endif /* defined _DIRENT_HAVE_D_TYPE || defined HAVE_STRUCT_DIRENT_D_TYPE */ |
| 4083 | - |
| 4084 | -# if (defined POSIX || defined WINDOWS32) && !defined __GNU_LIBRARY__ |
| 4085 | /* Initializer for skip_entry. POSIX does not require that the d_ino |
| 4086 | field be present, and some systems do not provide it. */ |
| 4087 | -# define D_INO_TO_RESULT(source) false, |
| 4088 | -# else |
| 4089 | -# define D_INO_TO_RESULT(source) (source)->d_ino == 0, |
| 4090 | -# endif |
| 4091 | +#if defined _LIBC || defined D_INO_IN_DIRENT |
| 4092 | +# define D_INO_TO_RESULT(source) (source)->d_ino == 0, |
| 4093 | + return d.skip_entry; |
| 4094 | +#else |
| 4095 | +# define D_INO_TO_RESULT(source) |
| 4096 | + return false; |
| 4097 | +#endif |
| 4098 | +} |
| 4099 | |
| 4100 | /* Construct an initializer for a struct readdir_result object from a |
| 4101 | struct dirent *. No copy of the name is made. */ |
| 4102 | @@ -186,8 +155,6 @@ readdir_result_might_be_dir (struct readdir_result d) |
| 4103 | D_INO_TO_RESULT (source) \ |
| 4104 | } |
| 4105 | |
| 4106 | -#endif /* !defined _LIBC || !defined GLOB_ONLY_P */ |
| 4107 | - |
| 4108 | /* Call gl_readdir on STREAM. This macro can be overridden to reduce |
| 4109 | type safety if an old interface version needs to be supported. */ |
| 4110 | #ifndef GL_READDIR |
| 4111 | @@ -225,18 +192,55 @@ convert_dirent64 (const struct dirent64 *source) |
| 4112 | } |
| 4113 | #endif |
| 4114 | |
| 4115 | +#ifndef _LIBC |
| 4116 | +/* The results of opendir() in this file are not used with dirfd and fchdir, |
| 4117 | + and we do not leak fds to any single-threaded code that could use stdio, |
| 4118 | + therefore save some unnecessary recursion in fchdir.c and opendir_safer.c. |
| 4119 | + FIXME - if the kernel ever adds support for multi-thread safety for |
| 4120 | + avoiding standard fds, then we should use opendir_safer. */ |
| 4121 | +# ifdef GNULIB_defined_opendir |
| 4122 | +# undef opendir |
| 4123 | +# endif |
| 4124 | +# ifdef GNULIB_defined_closedir |
| 4125 | +# undef closedir |
| 4126 | +# endif |
| 4127 | |
| 4128 | -#ifndef attribute_hidden |
| 4129 | -# define attribute_hidden |
| 4130 | +/* Just use malloc. */ |
| 4131 | +# define __libc_use_alloca(n) false |
| 4132 | +# define alloca_account(len, avar) ((void) (len), (void) (avar), (void *) 0) |
| 4133 | +# define extend_alloca_account(buf, len, newlen, avar) \ |
| 4134 | + ((void) (buf), (void) (len), (void) (newlen), (void) (avar), (void *) 0) |
| 4135 | #endif |
| 4136 | |
| 4137 | +/* Set *R = A + B. Return true if the answer is mathematically |
| 4138 | + incorrect due to overflow; in this case, *R is the low order |
| 4139 | + bits of the correct answer. */ |
| 4140 | + |
| 4141 | +static bool |
| 4142 | +size_add_wrapv (size_t a, size_t b, size_t *r) |
| 4143 | +{ |
| 4144 | +#if 5 <= __GNUC__ && !defined __ICC |
| 4145 | + return __builtin_add_overflow (a, b, r); |
| 4146 | +#else |
| 4147 | + *r = a + b; |
| 4148 | + return *r < a; |
| 4149 | +#endif |
| 4150 | +} |
| 4151 | + |
| 4152 | +static bool |
| 4153 | +glob_use_alloca (size_t alloca_used, size_t len) |
| 4154 | +{ |
| 4155 | + size_t size; |
| 4156 | + return (!size_add_wrapv (alloca_used, len, &size) |
| 4157 | + && __libc_use_alloca (size)); |
| 4158 | +} |
| 4159 | + |
| 4160 | static int glob_in_dir (const char *pattern, const char *directory, |
| 4161 | int flags, int (*errfunc) (const char *, int), |
| 4162 | glob_t *pglob, size_t alloca_used); |
| 4163 | extern int __glob_pattern_type (const char *pattern, int quote) |
| 4164 | attribute_hidden; |
| 4165 | |
| 4166 | -#if !defined _LIBC || !defined GLOB_ONLY_P |
| 4167 | static int prefix_array (const char *prefix, char **array, size_t n) __THROWNL; |
| 4168 | static int collated_compare (const void *, const void *) __THROWNL; |
| 4169 | |
| 4170 | @@ -265,16 +269,15 @@ next_brace_sub (const char *cp, int flags) |
| 4171 | return *cp != '\0' ? cp : NULL; |
| 4172 | } |
| 4173 | |
| 4174 | -#endif /* !defined _LIBC || !defined GLOB_ONLY_P */ |
| 4175 | |
| 4176 | /* Do glob searching for PATTERN, placing results in PGLOB. |
| 4177 | The bits defined above may be set in FLAGS. |
| 4178 | If a directory cannot be opened or read and ERRFUNC is not nil, |
| 4179 | it is called with the pathname that caused the error, and the |
| 4180 | - `errno' value from the failing call; if it returns non-zero |
| 4181 | - `glob' returns GLOB_ABORTED; if it returns zero, the error is ignored. |
| 4182 | + 'errno' value from the failing call; if it returns non-zero |
| 4183 | + 'glob' returns GLOB_ABORTED; if it returns zero, the error is ignored. |
| 4184 | If memory cannot be allocated for PGLOB, GLOB_NOSPACE is returned. |
| 4185 | - Otherwise, `glob' returns zero. */ |
| 4186 | + Otherwise, 'glob' returns zero. */ |
| 4187 | int |
| 4188 | #ifdef GLOB_ATTRIBUTE |
| 4189 | GLOB_ATTRIBUTE |
| 4190 | @@ -292,9 +295,7 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4191 | int malloc_dirname = 0; |
| 4192 | glob_t dirs; |
| 4193 | int retval = 0; |
| 4194 | -#ifdef _LIBC |
| 4195 | size_t alloca_used = 0; |
| 4196 | -#endif |
| 4197 | |
| 4198 | if (pattern == NULL || pglob == NULL || (flags & ~__GLOB_FLAGS) != 0) |
| 4199 | { |
| 4200 | @@ -308,7 +309,7 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4201 | flags |= GLOB_ONLYDIR; |
| 4202 | |
| 4203 | if (!(flags & GLOB_DOOFFS)) |
| 4204 | - /* Have to do this so `globfree' knows where to start freeing. It |
| 4205 | + /* Have to do this so 'globfree' knows where to start freeing. It |
| 4206 | also makes all the code that uses gl_offs simpler. */ |
| 4207 | pglob->gl_offs = 0; |
| 4208 | |
| 4209 | @@ -350,14 +351,12 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4210 | size_t rest_len; |
| 4211 | char *onealt; |
| 4212 | size_t pattern_len = strlen (pattern) - 1; |
| 4213 | -#ifdef _LIBC |
| 4214 | - int alloca_onealt = __libc_use_alloca (alloca_used + pattern_len); |
| 4215 | + int alloca_onealt = glob_use_alloca (alloca_used, pattern_len); |
| 4216 | if (alloca_onealt) |
| 4217 | onealt = alloca_account (pattern_len, alloca_used); |
| 4218 | else |
| 4219 | -#endif |
| 4220 | { |
| 4221 | - onealt = (char *) malloc (pattern_len); |
| 4222 | + onealt = malloc (pattern_len); |
| 4223 | if (onealt == NULL) |
| 4224 | { |
| 4225 | if (!(flags & GLOB_APPEND)) |
| 4226 | @@ -377,11 +376,9 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4227 | next = next_brace_sub (begin + 1, flags); |
| 4228 | if (next == NULL) |
| 4229 | { |
| 4230 | - /* It is an illegal expression. */ |
| 4231 | + /* It is an invalid expression. */ |
| 4232 | illegal_brace: |
| 4233 | -#ifdef _LIBC |
| 4234 | if (__glibc_unlikely (!alloca_onealt)) |
| 4235 | -#endif |
| 4236 | free (onealt); |
| 4237 | return glob (pattern, flags & ~GLOB_BRACE, errfunc, pglob); |
| 4238 | } |
| 4239 | @@ -429,9 +426,7 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4240 | /* If we got an error, return it. */ |
| 4241 | if (result && result != GLOB_NOMATCH) |
| 4242 | { |
| 4243 | -#ifdef _LIBC |
| 4244 | if (__glibc_unlikely (!alloca_onealt)) |
| 4245 | -#endif |
| 4246 | free (onealt); |
| 4247 | if (!(flags & GLOB_APPEND)) |
| 4248 | { |
| 4249 | @@ -450,9 +445,7 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4250 | assert (next != NULL); |
| 4251 | } |
| 4252 | |
| 4253 | -#ifdef _LIBC |
| 4254 | if (__glibc_unlikely (!alloca_onealt)) |
| 4255 | -#endif |
| 4256 | free (onealt); |
| 4257 | |
| 4258 | if (pglob->gl_pathc != firstc) |
| 4259 | @@ -489,14 +482,16 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4260 | |
| 4261 | /* Find the filename. */ |
| 4262 | filename = strrchr (pattern, '/'); |
| 4263 | + |
| 4264 | #if defined __MSDOS__ || defined WINDOWS32 |
| 4265 | - /* The case of "d:pattern". Since `:' is not allowed in |
| 4266 | + /* The case of "d:pattern". Since ':' is not allowed in |
| 4267 | file names, we can safely assume that wherever it |
| 4268 | happens in pattern, it signals the filename part. This |
| 4269 | is so we could some day support patterns like "[a-z]:foo". */ |
| 4270 | if (filename == NULL) |
| 4271 | filename = strchr (pattern, ':'); |
| 4272 | #endif /* __MSDOS__ || WINDOWS32 */ |
| 4273 | + |
| 4274 | dirname_modified = 0; |
| 4275 | if (filename == NULL) |
| 4276 | { |
| 4277 | @@ -521,11 +516,7 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4278 | } |
| 4279 | |
| 4280 | filename = pattern; |
| 4281 | -#ifdef _AMIGA |
| 4282 | - dirname = (char *) ""; |
| 4283 | -#else |
| 4284 | dirname = (char *) "."; |
| 4285 | -#endif |
| 4286 | dirlen = 0; |
| 4287 | } |
| 4288 | } |
| 4289 | @@ -549,22 +540,21 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4290 | char *drive_spec; |
| 4291 | |
| 4292 | ++dirlen; |
| 4293 | - drive_spec = (char *) __alloca (dirlen + 1); |
| 4294 | + drive_spec = __alloca (dirlen + 1); |
| 4295 | *((char *) mempcpy (drive_spec, pattern, dirlen)) = '\0'; |
| 4296 | /* For now, disallow wildcards in the drive spec, to |
| 4297 | prevent infinite recursion in glob. */ |
| 4298 | if (__glob_pattern_p (drive_spec, !(flags & GLOB_NOESCAPE))) |
| 4299 | return GLOB_NOMATCH; |
| 4300 | - /* If this is "d:pattern", we need to copy `:' to DIRNAME |
| 4301 | + /* If this is "d:pattern", we need to copy ':' to DIRNAME |
| 4302 | as well. If it's "d:/pattern", don't remove the slash |
| 4303 | from "d:/", since "d:" and "d:/" are not the same.*/ |
| 4304 | } |
| 4305 | #endif |
| 4306 | -#ifdef _LIBC |
| 4307 | - if (__libc_use_alloca (alloca_used + dirlen + 1)) |
| 4308 | + |
| 4309 | + if (glob_use_alloca (alloca_used, dirlen + 1)) |
| 4310 | newp = alloca_account (dirlen + 1, alloca_used); |
| 4311 | else |
| 4312 | -#endif |
| 4313 | { |
| 4314 | newp = malloc (dirlen + 1); |
| 4315 | if (newp == NULL) |
| 4316 | @@ -575,14 +565,17 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4317 | dirname = newp; |
| 4318 | ++filename; |
| 4319 | |
| 4320 | - if (filename[0] == '\0' |
| 4321 | #if defined __MSDOS__ || defined WINDOWS32 |
| 4322 | - && dirname[dirlen - 1] != ':' |
| 4323 | - && (dirlen < 3 || dirname[dirlen - 2] != ':' |
| 4324 | - || dirname[dirlen - 1] != '/') |
| 4325 | + bool drive_root = (dirlen > 1 |
| 4326 | + && (dirname[dirlen - 1] == ':' |
| 4327 | + || (dirlen > 2 && dirname[dirlen - 2] == ':' |
| 4328 | + && dirname[dirlen - 1] == '/'))); |
| 4329 | +#else |
| 4330 | + bool drive_root = false; |
| 4331 | #endif |
| 4332 | - && dirlen > 1) |
| 4333 | - /* "pattern/". Expand "pattern", appending slashes. */ |
| 4334 | + |
| 4335 | + if (filename[0] == '\0' && dirlen > 1 && !drive_root) |
| 4336 | + /* "pattern/". Expand "pattern", appending slashes. */ |
| 4337 | { |
| 4338 | int orig_flags = flags; |
| 4339 | if (!(flags & GLOB_NOESCAPE) && dirname[dirlen - 1] == '\\') |
| 4340 | @@ -615,7 +608,6 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4341 | } |
| 4342 | } |
| 4343 | |
| 4344 | -#ifndef VMS |
| 4345 | if ((flags & (GLOB_TILDE|GLOB_TILDE_CHECK)) && dirname[0] == '~') |
| 4346 | { |
| 4347 | if (dirname[1] == '\0' || dirname[1] == '/' |
| 4348 | @@ -625,100 +617,127 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4349 | /* Look up home directory. */ |
| 4350 | char *home_dir = getenv ("HOME"); |
| 4351 | int malloc_home_dir = 0; |
| 4352 | -# ifdef _AMIGA |
| 4353 | - if (home_dir == NULL || home_dir[0] == '\0') |
| 4354 | - home_dir = "SYS:"; |
| 4355 | -# else |
| 4356 | -# ifdef WINDOWS32 |
| 4357 | - if (home_dir == NULL || home_dir[0] == '\0') |
| 4358 | - home_dir = "c:/users/default"; /* poor default */ |
| 4359 | -# else |
| 4360 | if (home_dir == NULL || home_dir[0] == '\0') |
| 4361 | { |
| 4362 | +#ifdef WINDOWS32 |
| 4363 | + /* Windows NT defines HOMEDRIVE and HOMEPATH. But give |
| 4364 | + preference to HOME, because the user can change HOME. */ |
| 4365 | + const char *home_drive = getenv ("HOMEDRIVE"); |
| 4366 | + const char *home_path = getenv ("HOMEPATH"); |
| 4367 | + |
| 4368 | + if (home_drive != NULL && home_path != NULL) |
| 4369 | + { |
| 4370 | + size_t home_drive_len = strlen (home_drive); |
| 4371 | + size_t home_path_len = strlen (home_path); |
| 4372 | + char *mem = alloca (home_drive_len + home_path_len + 1); |
| 4373 | + |
| 4374 | + memcpy (mem, home_drive, home_drive_len); |
| 4375 | + memcpy (mem + home_drive_len, home_path, home_path_len + 1); |
| 4376 | + home_dir = mem; |
| 4377 | + } |
| 4378 | + else |
| 4379 | + home_dir = "c:/users/default"; /* poor default */ |
| 4380 | +#else |
| 4381 | int success; |
| 4382 | char *name; |
| 4383 | + int malloc_name = 0; |
| 4384 | size_t buflen = GET_LOGIN_NAME_MAX () + 1; |
| 4385 | |
| 4386 | if (buflen == 0) |
| 4387 | - /* `sysconf' does not support _SC_LOGIN_NAME_MAX. Try |
| 4388 | + /* 'sysconf' does not support _SC_LOGIN_NAME_MAX. Try |
| 4389 | a moderate value. */ |
| 4390 | buflen = 20; |
| 4391 | - name = alloca_account (buflen, alloca_used); |
| 4392 | + if (glob_use_alloca (alloca_used, buflen)) |
| 4393 | + name = alloca_account (buflen, alloca_used); |
| 4394 | + else |
| 4395 | + { |
| 4396 | + name = malloc (buflen); |
| 4397 | + if (name == NULL) |
| 4398 | + { |
| 4399 | + retval = GLOB_NOSPACE; |
| 4400 | + goto out; |
| 4401 | + } |
| 4402 | + malloc_name = 1; |
| 4403 | + } |
| 4404 | |
| 4405 | success = __getlogin_r (name, buflen) == 0; |
| 4406 | if (success) |
| 4407 | { |
| 4408 | struct passwd *p; |
| 4409 | -# if defined HAVE_GETPWNAM_R || defined _LIBC |
| 4410 | - long int pwbuflen = GETPW_R_SIZE_MAX (); |
| 4411 | + char *malloc_pwtmpbuf = NULL; |
| 4412 | char *pwtmpbuf; |
| 4413 | +# if defined HAVE_GETPWNAM_R || defined _LIBC |
| 4414 | + long int pwbuflenmax = GETPW_R_SIZE_MAX (); |
| 4415 | + size_t pwbuflen = pwbuflenmax; |
| 4416 | struct passwd pwbuf; |
| 4417 | - int malloc_pwtmpbuf = 0; |
| 4418 | int save = errno; |
| 4419 | |
| 4420 | -# ifndef _LIBC |
| 4421 | - if (pwbuflen == -1) |
| 4422 | - /* `sysconf' does not support _SC_GETPW_R_SIZE_MAX. |
| 4423 | +# ifndef _LIBC |
| 4424 | + if (! (0 < pwbuflenmax && pwbuflenmax <= SIZE_MAX)) |
| 4425 | + /* 'sysconf' does not support _SC_GETPW_R_SIZE_MAX. |
| 4426 | Try a moderate value. */ |
| 4427 | pwbuflen = 1024; |
| 4428 | -# endif |
| 4429 | - if (__libc_use_alloca (alloca_used + pwbuflen)) |
| 4430 | +# endif |
| 4431 | + if (glob_use_alloca (alloca_used, pwbuflen)) |
| 4432 | pwtmpbuf = alloca_account (pwbuflen, alloca_used); |
| 4433 | else |
| 4434 | { |
| 4435 | pwtmpbuf = malloc (pwbuflen); |
| 4436 | if (pwtmpbuf == NULL) |
| 4437 | { |
| 4438 | + if (__glibc_unlikely (malloc_name)) |
| 4439 | + free (name); |
| 4440 | retval = GLOB_NOSPACE; |
| 4441 | goto out; |
| 4442 | } |
| 4443 | - malloc_pwtmpbuf = 1; |
| 4444 | + malloc_pwtmpbuf = pwtmpbuf; |
| 4445 | } |
| 4446 | |
| 4447 | while (getpwnam_r (name, &pwbuf, pwtmpbuf, pwbuflen, &p) |
| 4448 | != 0) |
| 4449 | { |
| 4450 | + size_t newlen; |
| 4451 | + bool v; |
| 4452 | if (errno != ERANGE) |
| 4453 | { |
| 4454 | p = NULL; |
| 4455 | break; |
| 4456 | } |
| 4457 | - |
| 4458 | - if (!malloc_pwtmpbuf |
| 4459 | - && __libc_use_alloca (alloca_used |
| 4460 | - + 2 * pwbuflen)) |
| 4461 | + v = size_add_wrapv (pwbuflen, pwbuflen, &newlen); |
| 4462 | + if (!v && malloc_pwtmpbuf == NULL |
| 4463 | + && glob_use_alloca (alloca_used, newlen)) |
| 4464 | pwtmpbuf = extend_alloca_account (pwtmpbuf, pwbuflen, |
| 4465 | - 2 * pwbuflen, |
| 4466 | - alloca_used); |
| 4467 | + newlen, alloca_used); |
| 4468 | else |
| 4469 | { |
| 4470 | - char *newp = realloc (malloc_pwtmpbuf |
| 4471 | - ? pwtmpbuf : NULL, |
| 4472 | - 2 * pwbuflen); |
| 4473 | + char *newp = (v ? NULL |
| 4474 | + : realloc (malloc_pwtmpbuf, newlen)); |
| 4475 | if (newp == NULL) |
| 4476 | { |
| 4477 | - if (__glibc_unlikely (malloc_pwtmpbuf)) |
| 4478 | - free (pwtmpbuf); |
| 4479 | + free (malloc_pwtmpbuf); |
| 4480 | + if (__glibc_unlikely (malloc_name)) |
| 4481 | + free (name); |
| 4482 | retval = GLOB_NOSPACE; |
| 4483 | goto out; |
| 4484 | } |
| 4485 | - pwtmpbuf = newp; |
| 4486 | - pwbuflen = 2 * pwbuflen; |
| 4487 | - malloc_pwtmpbuf = 1; |
| 4488 | + malloc_pwtmpbuf = pwtmpbuf = newp; |
| 4489 | } |
| 4490 | + pwbuflen = newlen; |
| 4491 | __set_errno (save); |
| 4492 | } |
| 4493 | -# else |
| 4494 | +# else |
| 4495 | p = getpwnam (name); |
| 4496 | -# endif |
| 4497 | +# endif |
| 4498 | + if (__glibc_unlikely (malloc_name)) |
| 4499 | + free (name); |
| 4500 | if (p != NULL) |
| 4501 | { |
| 4502 | - if (!malloc_pwtmpbuf) |
| 4503 | + if (malloc_pwtmpbuf == NULL) |
| 4504 | home_dir = p->pw_dir; |
| 4505 | else |
| 4506 | { |
| 4507 | size_t home_dir_len = strlen (p->pw_dir) + 1; |
| 4508 | - if (__libc_use_alloca (alloca_used + home_dir_len)) |
| 4509 | + if (glob_use_alloca (alloca_used, home_dir_len)) |
| 4510 | home_dir = alloca_account (home_dir_len, |
| 4511 | alloca_used); |
| 4512 | else |
| 4513 | @@ -733,26 +752,32 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4514 | malloc_home_dir = 1; |
| 4515 | } |
| 4516 | memcpy (home_dir, p->pw_dir, home_dir_len); |
| 4517 | - |
| 4518 | - free (pwtmpbuf); |
| 4519 | } |
| 4520 | } |
| 4521 | + free (malloc_pwtmpbuf); |
| 4522 | } |
| 4523 | + else |
| 4524 | + { |
| 4525 | + if (__glibc_unlikely (malloc_name)) |
| 4526 | + free (name); |
| 4527 | + } |
| 4528 | +#endif /* WINDOWS32 */ |
| 4529 | } |
| 4530 | if (home_dir == NULL || home_dir[0] == '\0') |
| 4531 | { |
| 4532 | + if (__glibc_unlikely (malloc_home_dir)) |
| 4533 | + free (home_dir); |
| 4534 | if (flags & GLOB_TILDE_CHECK) |
| 4535 | { |
| 4536 | - if (__glibc_unlikely (malloc_home_dir)) |
| 4537 | - free (home_dir); |
| 4538 | retval = GLOB_NOMATCH; |
| 4539 | goto out; |
| 4540 | } |
| 4541 | else |
| 4542 | - home_dir = (char *) "~"; /* No luck. */ |
| 4543 | + { |
| 4544 | + home_dir = (char *) "~"; /* No luck. */ |
| 4545 | + malloc_home_dir = 0; |
| 4546 | + } |
| 4547 | } |
| 4548 | -# endif /* WINDOWS32 */ |
| 4549 | -# endif |
| 4550 | /* Now construct the full directory. */ |
| 4551 | if (dirname[1] == '\0') |
| 4552 | { |
| 4553 | @@ -767,8 +792,7 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4554 | { |
| 4555 | char *newp; |
| 4556 | size_t home_len = strlen (home_dir); |
| 4557 | - int use_alloca = __libc_use_alloca (alloca_used |
| 4558 | - + home_len + dirlen); |
| 4559 | + int use_alloca = glob_use_alloca (alloca_used, home_len + dirlen); |
| 4560 | if (use_alloca) |
| 4561 | newp = alloca_account (home_len + dirlen, alloca_used); |
| 4562 | else |
| 4563 | @@ -792,12 +816,15 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4564 | dirname = newp; |
| 4565 | dirlen += home_len - 1; |
| 4566 | malloc_dirname = !use_alloca; |
| 4567 | + |
| 4568 | + if (__glibc_unlikely (malloc_home_dir)) |
| 4569 | + free (home_dir); |
| 4570 | } |
| 4571 | dirname_modified = 1; |
| 4572 | } |
| 4573 | -# if !defined _AMIGA && !defined WINDOWS32 |
| 4574 | else |
| 4575 | { |
| 4576 | +#ifndef WINDOWS32 |
| 4577 | char *end_name = strchr (dirname, '/'); |
| 4578 | char *user_name; |
| 4579 | int malloc_user_name = 0; |
| 4580 | @@ -819,7 +846,7 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4581 | else |
| 4582 | { |
| 4583 | char *newp; |
| 4584 | - if (__libc_use_alloca (alloca_used + (end_name - dirname))) |
| 4585 | + if (glob_use_alloca (alloca_used, end_name - dirname)) |
| 4586 | newp = alloca_account (end_name - dirname, alloca_used); |
| 4587 | else |
| 4588 | { |
| 4589 | @@ -836,11 +863,11 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4590 | char *p = mempcpy (newp, dirname + 1, |
| 4591 | unescape - dirname - 1); |
| 4592 | char *q = unescape; |
| 4593 | - while (*q != '\0') |
| 4594 | + while (q != end_name) |
| 4595 | { |
| 4596 | if (*q == '\\') |
| 4597 | { |
| 4598 | - if (q[1] == '\0') |
| 4599 | + if (q + 1 == end_name) |
| 4600 | { |
| 4601 | /* "~fo\\o\\" unescape to user_name "foo\\", |
| 4602 | but "~fo\\o\\/" unescape to user_name |
| 4603 | @@ -856,7 +883,7 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4604 | *p = '\0'; |
| 4605 | } |
| 4606 | else |
| 4607 | - *((char *) mempcpy (newp, dirname + 1, end_name - dirname)) |
| 4608 | + *((char *) mempcpy (newp, dirname + 1, end_name - dirname - 1)) |
| 4609 | = '\0'; |
| 4610 | user_name = newp; |
| 4611 | } |
| 4612 | @@ -864,20 +891,21 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4613 | /* Look up specific user's home directory. */ |
| 4614 | { |
| 4615 | struct passwd *p; |
| 4616 | + char *malloc_pwtmpbuf = NULL; |
| 4617 | # if defined HAVE_GETPWNAM_R || defined _LIBC |
| 4618 | - long int buflen = GETPW_R_SIZE_MAX (); |
| 4619 | + long int buflenmax = GETPW_R_SIZE_MAX (); |
| 4620 | + size_t buflen = buflenmax; |
| 4621 | char *pwtmpbuf; |
| 4622 | - int malloc_pwtmpbuf = 0; |
| 4623 | struct passwd pwbuf; |
| 4624 | int save = errno; |
| 4625 | |
| 4626 | # ifndef _LIBC |
| 4627 | - if (buflen == -1) |
| 4628 | - /* `sysconf' does not support _SC_GETPW_R_SIZE_MAX. Try a |
| 4629 | + if (! (0 <= buflenmax && buflenmax <= SIZE_MAX)) |
| 4630 | + /* Perhaps 'sysconf' does not support _SC_GETPW_R_SIZE_MAX. Try a |
| 4631 | moderate value. */ |
| 4632 | buflen = 1024; |
| 4633 | # endif |
| 4634 | - if (__libc_use_alloca (alloca_used + buflen)) |
| 4635 | + if (glob_use_alloca (alloca_used, buflen)) |
| 4636 | pwtmpbuf = alloca_account (buflen, alloca_used); |
| 4637 | else |
| 4638 | { |
| 4639 | @@ -890,32 +918,32 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4640 | retval = GLOB_NOSPACE; |
| 4641 | goto out; |
| 4642 | } |
| 4643 | - malloc_pwtmpbuf = 1; |
| 4644 | + malloc_pwtmpbuf = pwtmpbuf; |
| 4645 | } |
| 4646 | |
| 4647 | while (getpwnam_r (user_name, &pwbuf, pwtmpbuf, buflen, &p) != 0) |
| 4648 | { |
| 4649 | + size_t newlen; |
| 4650 | + bool v; |
| 4651 | if (errno != ERANGE) |
| 4652 | { |
| 4653 | p = NULL; |
| 4654 | break; |
| 4655 | } |
| 4656 | - if (!malloc_pwtmpbuf |
| 4657 | - && __libc_use_alloca (alloca_used + 2 * buflen)) |
| 4658 | + v = size_add_wrapv (buflen, buflen, &newlen); |
| 4659 | + if (!v && malloc_pwtmpbuf == NULL |
| 4660 | + && glob_use_alloca (alloca_used, newlen)) |
| 4661 | pwtmpbuf = extend_alloca_account (pwtmpbuf, buflen, |
| 4662 | - 2 * buflen, alloca_used); |
| 4663 | + newlen, alloca_used); |
| 4664 | else |
| 4665 | { |
| 4666 | - char *newp = realloc (malloc_pwtmpbuf ? pwtmpbuf : NULL, |
| 4667 | - 2 * buflen); |
| 4668 | + char *newp = v ? NULL : realloc (malloc_pwtmpbuf, newlen); |
| 4669 | if (newp == NULL) |
| 4670 | { |
| 4671 | - if (__glibc_unlikely (malloc_pwtmpbuf)) |
| 4672 | - free (pwtmpbuf); |
| 4673 | + free (malloc_pwtmpbuf); |
| 4674 | goto nomem_getpw; |
| 4675 | } |
| 4676 | - pwtmpbuf = newp; |
| 4677 | - malloc_pwtmpbuf = 1; |
| 4678 | + malloc_pwtmpbuf = pwtmpbuf = newp; |
| 4679 | } |
| 4680 | __set_errno (save); |
| 4681 | } |
| 4682 | @@ -936,7 +964,7 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4683 | free (dirname); |
| 4684 | malloc_dirname = 0; |
| 4685 | |
| 4686 | - if (__libc_use_alloca (alloca_used + home_len + rest_len + 1)) |
| 4687 | + if (glob_use_alloca (alloca_used, home_len + rest_len + 1)) |
| 4688 | dirname = alloca_account (home_len + rest_len + 1, |
| 4689 | alloca_used); |
| 4690 | else |
| 4691 | @@ -944,8 +972,7 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4692 | dirname = malloc (home_len + rest_len + 1); |
| 4693 | if (dirname == NULL) |
| 4694 | { |
| 4695 | - if (__glibc_unlikely (malloc_pwtmpbuf)) |
| 4696 | - free (pwtmpbuf); |
| 4697 | + free (malloc_pwtmpbuf); |
| 4698 | retval = GLOB_NOSPACE; |
| 4699 | goto out; |
| 4700 | } |
| 4701 | @@ -957,24 +984,24 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4702 | dirlen = home_len + rest_len; |
| 4703 | dirname_modified = 1; |
| 4704 | |
| 4705 | - if (__glibc_unlikely (malloc_pwtmpbuf)) |
| 4706 | - free (pwtmpbuf); |
| 4707 | + free (malloc_pwtmpbuf); |
| 4708 | } |
| 4709 | else |
| 4710 | { |
| 4711 | - if (__glibc_unlikely (malloc_pwtmpbuf)) |
| 4712 | - free (pwtmpbuf); |
| 4713 | + free (malloc_pwtmpbuf); |
| 4714 | |
| 4715 | if (flags & GLOB_TILDE_CHECK) |
| 4716 | - /* We have to regard it as an error if we cannot find the |
| 4717 | - home directory. */ |
| 4718 | - return GLOB_NOMATCH; |
| 4719 | + { |
| 4720 | + /* We have to regard it as an error if we cannot find the |
| 4721 | + home directory. */ |
| 4722 | + retval = GLOB_NOMATCH; |
| 4723 | + goto out; |
| 4724 | + } |
| 4725 | } |
| 4726 | } |
| 4727 | +#endif /* !WINDOWS32 */ |
| 4728 | } |
| 4729 | -# endif /* Not Amiga && not WINDOWS32. */ |
| 4730 | } |
| 4731 | -#endif /* Not VMS. */ |
| 4732 | |
| 4733 | /* Now test whether we looked for "~" or "~NAME". In this case we |
| 4734 | can give the answer now. */ |
| 4735 | @@ -993,19 +1020,18 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4736 | size_t newcount = pglob->gl_pathc + pglob->gl_offs; |
| 4737 | char **new_gl_pathv; |
| 4738 | |
| 4739 | - if (newcount > UINTPTR_MAX - (1 + 1) |
| 4740 | - || newcount + 1 + 1 > ~((size_t) 0) / sizeof (char *)) |
| 4741 | + if (newcount > SIZE_MAX / sizeof (char *) - 2) |
| 4742 | { |
| 4743 | nospace: |
| 4744 | free (pglob->gl_pathv); |
| 4745 | pglob->gl_pathv = NULL; |
| 4746 | pglob->gl_pathc = 0; |
| 4747 | - return GLOB_NOSPACE; |
| 4748 | + retval = GLOB_NOSPACE; |
| 4749 | + goto out; |
| 4750 | } |
| 4751 | |
| 4752 | - new_gl_pathv |
| 4753 | - = (char **) realloc (pglob->gl_pathv, |
| 4754 | - (newcount + 1 + 1) * sizeof (char *)); |
| 4755 | + new_gl_pathv = realloc (pglob->gl_pathv, |
| 4756 | + (newcount + 2) * sizeof (char *)); |
| 4757 | if (new_gl_pathv == NULL) |
| 4758 | goto nospace; |
| 4759 | pglob->gl_pathv = new_gl_pathv; |
| 4760 | @@ -1019,12 +1045,19 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4761 | p = mempcpy (pglob->gl_pathv[newcount], dirname, dirlen); |
| 4762 | p[0] = '/'; |
| 4763 | p[1] = '\0'; |
| 4764 | + if (__glibc_unlikely (malloc_dirname)) |
| 4765 | + free (dirname); |
| 4766 | } |
| 4767 | else |
| 4768 | { |
| 4769 | - pglob->gl_pathv[newcount] = strdup (dirname); |
| 4770 | - if (pglob->gl_pathv[newcount] == NULL) |
| 4771 | - goto nospace; |
| 4772 | + if (__glibc_unlikely (malloc_dirname)) |
| 4773 | + pglob->gl_pathv[newcount] = dirname; |
| 4774 | + else |
| 4775 | + { |
| 4776 | + pglob->gl_pathv[newcount] = strdup (dirname); |
| 4777 | + if (pglob->gl_pathv[newcount] == NULL) |
| 4778 | + goto nospace; |
| 4779 | + } |
| 4780 | } |
| 4781 | pglob->gl_pathv[++newcount] = NULL; |
| 4782 | ++pglob->gl_pathc; |
| 4783 | @@ -1034,7 +1067,8 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4784 | } |
| 4785 | |
| 4786 | /* Not found. */ |
| 4787 | - return GLOB_NOMATCH; |
| 4788 | + retval = GLOB_NOMATCH; |
| 4789 | + goto out; |
| 4790 | } |
| 4791 | |
| 4792 | meta = __glob_pattern_type (dirname, !(flags & GLOB_NOESCAPE)); |
| 4793 | @@ -1080,7 +1114,10 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4794 | if (status != 0) |
| 4795 | { |
| 4796 | if ((flags & GLOB_NOCHECK) == 0 || status != GLOB_NOMATCH) |
| 4797 | - return status; |
| 4798 | + { |
| 4799 | + retval = status; |
| 4800 | + goto out; |
| 4801 | + } |
| 4802 | goto no_matches; |
| 4803 | } |
| 4804 | |
| 4805 | @@ -1091,19 +1128,6 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4806 | { |
| 4807 | size_t old_pathc; |
| 4808 | |
| 4809 | -#ifdef SHELL |
| 4810 | - { |
| 4811 | - /* Make globbing interruptible in the bash shell. */ |
| 4812 | - extern int interrupt_state; |
| 4813 | - |
| 4814 | - if (interrupt_state) |
| 4815 | - { |
| 4816 | - globfree (&dirs); |
| 4817 | - return GLOB_ABORTED; |
| 4818 | - } |
| 4819 | - } |
| 4820 | -#endif /* SHELL. */ |
| 4821 | - |
| 4822 | old_pathc = pglob->gl_pathc; |
| 4823 | status = glob_in_dir (filename, dirs.gl_pathv[i], |
| 4824 | ((flags | GLOB_APPEND) |
| 4825 | @@ -1118,7 +1142,8 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4826 | globfree (&dirs); |
| 4827 | globfree (pglob); |
| 4828 | pglob->gl_pathc = 0; |
| 4829 | - return status; |
| 4830 | + retval = status; |
| 4831 | + goto out; |
| 4832 | } |
| 4833 | |
| 4834 | /* Stick the directory on the front of each name. */ |
| 4835 | @@ -1129,13 +1154,14 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4836 | globfree (&dirs); |
| 4837 | globfree (pglob); |
| 4838 | pglob->gl_pathc = 0; |
| 4839 | - return GLOB_NOSPACE; |
| 4840 | + retval = GLOB_NOSPACE; |
| 4841 | + goto out; |
| 4842 | } |
| 4843 | } |
| 4844 | |
| 4845 | flags |= GLOB_MAGCHAR; |
| 4846 | |
| 4847 | - /* We have ignored the GLOB_NOCHECK flag in the `glob_in_dir' calls. |
| 4848 | + /* We have ignored the GLOB_NOCHECK flag in the 'glob_in_dir' calls. |
| 4849 | But if we have not found any matching entry and the GLOB_NOCHECK |
| 4850 | flag was set we must return the input pattern itself. */ |
| 4851 | if (pglob->gl_pathc + pglob->gl_offs == oldcount) |
| 4852 | @@ -1147,28 +1173,28 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4853 | size_t newcount = pglob->gl_pathc + pglob->gl_offs; |
| 4854 | char **new_gl_pathv; |
| 4855 | |
| 4856 | - if (newcount > UINTPTR_MAX - 2 |
| 4857 | - || newcount + 2 > ~((size_t) 0) / sizeof (char *)) |
| 4858 | + if (newcount > SIZE_MAX / sizeof (char *) - 2) |
| 4859 | { |
| 4860 | nospace2: |
| 4861 | globfree (&dirs); |
| 4862 | - return GLOB_NOSPACE; |
| 4863 | + retval = GLOB_NOSPACE; |
| 4864 | + goto out; |
| 4865 | } |
| 4866 | |
| 4867 | - new_gl_pathv = (char **) realloc (pglob->gl_pathv, |
| 4868 | - (newcount + 2) |
| 4869 | - * sizeof (char *)); |
| 4870 | + new_gl_pathv = realloc (pglob->gl_pathv, |
| 4871 | + (newcount + 2) * sizeof (char *)); |
| 4872 | if (new_gl_pathv == NULL) |
| 4873 | goto nospace2; |
| 4874 | pglob->gl_pathv = new_gl_pathv; |
| 4875 | |
| 4876 | - pglob->gl_pathv[newcount] = __strdup (pattern); |
| 4877 | + pglob->gl_pathv[newcount] = strdup (pattern); |
| 4878 | if (pglob->gl_pathv[newcount] == NULL) |
| 4879 | { |
| 4880 | globfree (&dirs); |
| 4881 | globfree (pglob); |
| 4882 | pglob->gl_pathc = 0; |
| 4883 | - return GLOB_NOSPACE; |
| 4884 | + retval = GLOB_NOSPACE; |
| 4885 | + goto out; |
| 4886 | } |
| 4887 | |
| 4888 | ++pglob->gl_pathc; |
| 4889 | @@ -1180,7 +1206,8 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4890 | else |
| 4891 | { |
| 4892 | globfree (&dirs); |
| 4893 | - return GLOB_NOMATCH; |
| 4894 | + retval = GLOB_NOMATCH; |
| 4895 | + goto out; |
| 4896 | } |
| 4897 | } |
| 4898 | |
| 4899 | @@ -1226,7 +1253,8 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4900 | flags = orig_flags; |
| 4901 | goto no_matches; |
| 4902 | } |
| 4903 | - return status; |
| 4904 | + retval = status; |
| 4905 | + goto out; |
| 4906 | } |
| 4907 | |
| 4908 | if (dirlen > 0) |
| 4909 | @@ -1238,7 +1266,8 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4910 | { |
| 4911 | globfree (pglob); |
| 4912 | pglob->gl_pathc = 0; |
| 4913 | - return GLOB_NOSPACE; |
| 4914 | + retval = GLOB_NOSPACE; |
| 4915 | + goto out; |
| 4916 | } |
| 4917 | } |
| 4918 | } |
| 4919 | @@ -1263,7 +1292,8 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), |
| 4920 | { |
| 4921 | globfree (pglob); |
| 4922 | pglob->gl_pathc = 0; |
| 4923 | - return GLOB_NOSPACE; |
| 4924 | + retval = GLOB_NOSPACE; |
| 4925 | + goto out; |
| 4926 | } |
| 4927 | strcpy (&new[len - 2], "/"); |
| 4928 | pglob->gl_pathv[i] = new; |
| 4929 | @@ -1289,32 +1319,12 @@ libc_hidden_def (glob) |
| 4930 | #endif |
| 4931 | |
| 4932 | |
| 4933 | -#if !defined _LIBC || !defined GLOB_ONLY_P |
| 4934 | - |
| 4935 | -/* Free storage allocated in PGLOB by a previous `glob' call. */ |
| 4936 | -void |
| 4937 | -globfree (glob_t *pglob) |
| 4938 | -{ |
| 4939 | - if (pglob->gl_pathv != NULL) |
| 4940 | - { |
| 4941 | - size_t i; |
| 4942 | - for (i = 0; i < pglob->gl_pathc; ++i) |
| 4943 | - free (pglob->gl_pathv[pglob->gl_offs + i]); |
| 4944 | - free (pglob->gl_pathv); |
| 4945 | - pglob->gl_pathv = NULL; |
| 4946 | - } |
| 4947 | -} |
| 4948 | -#if defined _LIBC && !defined globfree |
| 4949 | -libc_hidden_def (globfree) |
| 4950 | -#endif |
| 4951 | - |
| 4952 | - |
| 4953 | /* Do a collated comparison of A and B. */ |
| 4954 | static int |
| 4955 | collated_compare (const void *a, const void *b) |
| 4956 | { |
| 4957 | - const char *const s1 = *(const char *const * const) a; |
| 4958 | - const char *const s2 = *(const char *const * const) b; |
| 4959 | + char *const *ps1 = a; char *s1 = *ps1; |
| 4960 | + char *const *ps2 = b; char *s2 = *ps2; |
| 4961 | |
| 4962 | if (s1 == s2) |
| 4963 | return 0; |
| 4964 | @@ -1335,28 +1345,24 @@ prefix_array (const char *dirname, char **array, size_t n) |
| 4965 | { |
| 4966 | size_t i; |
| 4967 | size_t dirlen = strlen (dirname); |
| 4968 | -#if defined __MSDOS__ || defined WINDOWS32 |
| 4969 | - int sep_char = '/'; |
| 4970 | -# define DIRSEP_CHAR sep_char |
| 4971 | -#else |
| 4972 | -# define DIRSEP_CHAR '/' |
| 4973 | -#endif |
| 4974 | + char dirsep_char = '/'; |
| 4975 | |
| 4976 | if (dirlen == 1 && dirname[0] == '/') |
| 4977 | /* DIRNAME is just "/", so normal prepending would get us "//foo". |
| 4978 | We want "/foo" instead, so don't prepend any chars from DIRNAME. */ |
| 4979 | dirlen = 0; |
| 4980 | + |
| 4981 | #if defined __MSDOS__ || defined WINDOWS32 |
| 4982 | - else if (dirlen > 1) |
| 4983 | + if (dirlen > 1) |
| 4984 | { |
| 4985 | if (dirname[dirlen - 1] == '/' && dirname[dirlen - 2] == ':') |
| 4986 | /* DIRNAME is "d:/". Don't prepend the slash from DIRNAME. */ |
| 4987 | --dirlen; |
| 4988 | else if (dirname[dirlen - 1] == ':') |
| 4989 | { |
| 4990 | - /* DIRNAME is "d:". Use `:' instead of `/'. */ |
| 4991 | + /* DIRNAME is "d:". Use ':' instead of '/'. */ |
| 4992 | --dirlen; |
| 4993 | - sep_char = ':'; |
| 4994 | + dirsep_char = ':'; |
| 4995 | } |
| 4996 | } |
| 4997 | #endif |
| 4998 | @@ -1364,7 +1370,7 @@ prefix_array (const char *dirname, char **array, size_t n) |
| 4999 | for (i = 0; i < n; ++i) |
| 5000 | { |
| 5001 | size_t eltlen = strlen (array[i]) + 1; |
| 5002 | - char *new = (char *) malloc (dirlen + 1 + eltlen); |
| 5003 | + char *new = malloc (dirlen + 1 + eltlen); |
| 5004 | if (new == NULL) |
| 5005 | { |
| 5006 | while (i > 0) |
| 5007 | @@ -1374,7 +1380,7 @@ prefix_array (const char *dirname, char **array, size_t n) |
| 5008 | |
| 5009 | { |
| 5010 | char *endp = mempcpy (new, dirname, dirlen); |
| 5011 | - *endp++ = DIRSEP_CHAR; |
| 5012 | + *endp++ = dirsep_char; |
| 5013 | mempcpy (endp, array[i], eltlen); |
| 5014 | } |
| 5015 | free (array[i]); |
| 5016 | @@ -1384,103 +1390,57 @@ prefix_array (const char *dirname, char **array, size_t n) |
| 5017 | return 0; |
| 5018 | } |
| 5019 | |
| 5020 | - |
| 5021 | -/* We must not compile this function twice. */ |
| 5022 | -#if !defined _LIBC || !defined NO_GLOB_PATTERN_P |
| 5023 | -int |
| 5024 | -__glob_pattern_type (const char *pattern, int quote) |
| 5025 | -{ |
| 5026 | - const char *p; |
| 5027 | - int ret = 0; |
| 5028 | - |
| 5029 | - for (p = pattern; *p != '\0'; ++p) |
| 5030 | - switch (*p) |
| 5031 | - { |
| 5032 | - case '?': |
| 5033 | - case '*': |
| 5034 | - return 1; |
| 5035 | - |
| 5036 | - case '\\': |
| 5037 | - if (quote) |
| 5038 | - { |
| 5039 | - if (p[1] != '\0') |
| 5040 | - ++p; |
| 5041 | - ret |= 2; |
| 5042 | - } |
| 5043 | - break; |
| 5044 | - |
| 5045 | - case '[': |
| 5046 | - ret |= 4; |
| 5047 | - break; |
| 5048 | - |
| 5049 | - case ']': |
| 5050 | - if (ret & 4) |
| 5051 | - return 1; |
| 5052 | - break; |
| 5053 | - } |
| 5054 | - |
| 5055 | - return ret; |
| 5056 | -} |
| 5057 | - |
| 5058 | -/* Return nonzero if PATTERN contains any metacharacters. |
| 5059 | - Metacharacters can be quoted with backslashes if QUOTE is nonzero. */ |
| 5060 | -int |
| 5061 | -__glob_pattern_p (const char *pattern, int quote) |
| 5062 | -{ |
| 5063 | - return __glob_pattern_type (pattern, quote) == 1; |
| 5064 | -} |
| 5065 | -# ifdef _LIBC |
| 5066 | -weak_alias (__glob_pattern_p, glob_pattern_p) |
| 5067 | -# endif |
| 5068 | -#endif |
| 5069 | - |
| 5070 | -#endif /* !GLOB_ONLY_P */ |
| 5071 | - |
| 5072 | - |
| 5073 | /* We put this in a separate function mainly to allow the memory |
| 5074 | allocated with alloca to be recycled. */ |
| 5075 | -#if !defined _LIBC || !defined GLOB_ONLY_P |
| 5076 | static int |
| 5077 | __attribute_noinline__ |
| 5078 | -link_exists2_p (const char *dir, size_t dirlen, const char *fname, |
| 5079 | - glob_t *pglob |
| 5080 | -# ifndef _LIBC |
| 5081 | - , int flags |
| 5082 | +link_stat (const char *dir, size_t dirlen, const char *fname, |
| 5083 | + glob_t *pglob |
| 5084 | +# if !defined _LIBC && !HAVE_FSTATAT |
| 5085 | + , int flags |
| 5086 | # endif |
| 5087 | - ) |
| 5088 | + ) |
| 5089 | { |
| 5090 | size_t fnamelen = strlen (fname); |
| 5091 | - char *fullname = (char *) __alloca (dirlen + 1 + fnamelen + 1); |
| 5092 | + char *fullname = __alloca (dirlen + 1 + fnamelen + 1); |
| 5093 | struct stat st; |
| 5094 | -# ifndef _LIBC |
| 5095 | - struct_stat64 st64; |
| 5096 | -# endif |
| 5097 | |
| 5098 | mempcpy (mempcpy (mempcpy (fullname, dir, dirlen), "/", 1), |
| 5099 | fname, fnamelen + 1); |
| 5100 | |
| 5101 | -# ifdef _LIBC |
| 5102 | - return (*pglob->gl_stat) (fullname, &st) == 0; |
| 5103 | -# else |
| 5104 | - return ((__builtin_expect (flags & GLOB_ALTDIRFUNC, 0) |
| 5105 | - ? (*pglob->gl_stat) (fullname, &st) |
| 5106 | - : __stat64 (fullname, &st64)) == 0); |
| 5107 | +# if !defined _LIBC && !HAVE_FSTATAT |
| 5108 | + if (__builtin_expect ((flags & GLOB_ALTDIRFUNC) == 0, 1)) |
| 5109 | + { |
| 5110 | + struct_stat64 st64; |
| 5111 | + return __stat64 (fullname, &st64); |
| 5112 | + } |
| 5113 | # endif |
| 5114 | + return (*pglob->gl_stat) (fullname, &st); |
| 5115 | } |
| 5116 | -# ifdef _LIBC |
| 5117 | -# define link_exists_p(dfd, dirname, dirnamelen, fname, pglob, flags) \ |
| 5118 | - (__builtin_expect (flags & GLOB_ALTDIRFUNC, 0) \ |
| 5119 | - ? link_exists2_p (dirname, dirnamelen, fname, pglob) \ |
| 5120 | - : ({ struct stat64 st64; \ |
| 5121 | - __fxstatat64 (_STAT_VER, dfd, fname, &st64, 0) == 0; })) |
| 5122 | + |
| 5123 | +/* Return true if DIR/FNAME exists. */ |
| 5124 | +static int |
| 5125 | +link_exists_p (int dfd, const char *dir, size_t dirlen, const char *fname, |
| 5126 | + glob_t *pglob, int flags) |
| 5127 | +{ |
| 5128 | + int status; |
| 5129 | +# if defined _LIBC || HAVE_FSTATAT |
| 5130 | + if (__builtin_expect (flags & GLOB_ALTDIRFUNC, 0)) |
| 5131 | + status = link_stat (dir, dirlen, fname, pglob); |
| 5132 | + else |
| 5133 | + { |
| 5134 | + /* dfd cannot be -1 here, because dirfd never returns -1 on |
| 5135 | + glibc, or on hosts that have fstatat. */ |
| 5136 | + struct_stat64 st64; |
| 5137 | + status = __fxstatat64 (_STAT_VER, dfd, fname, &st64, 0); |
| 5138 | + } |
| 5139 | # else |
| 5140 | -# define link_exists_p(dfd, dirname, dirnamelen, fname, pglob, flags) \ |
| 5141 | - link_exists2_p (dirname, dirnamelen, fname, pglob, flags) |
| 5142 | + status = link_stat (dir, dirlen, fname, pglob, flags); |
| 5143 | # endif |
| 5144 | -#endif |
| 5145 | - |
| 5146 | + return status == 0 || errno == EOVERFLOW; |
| 5147 | +} |
| 5148 | |
| 5149 | -/* Like `glob', but PATTERN is a final pathname component, |
| 5150 | +/* Like 'glob', but PATTERN is a final pathname component, |
| 5151 | and matches are searched for in DIRECTORY. |
| 5152 | The GLOB_NOSORT bit in FLAGS is ignored. No sorting is ever done. |
| 5153 | The GLOB_APPEND flag is assumed to be set (always appends). */ |
| 5154 | @@ -1491,25 +1451,25 @@ glob_in_dir (const char *pattern, const char *directory, int flags, |
| 5155 | { |
| 5156 | size_t dirlen = strlen (directory); |
| 5157 | void *stream = NULL; |
| 5158 | - struct globnames |
| 5159 | - { |
| 5160 | - struct globnames *next; |
| 5161 | - size_t count; |
| 5162 | - char *name[64]; |
| 5163 | - }; |
| 5164 | -#define INITIAL_COUNT sizeof (init_names.name) / sizeof (init_names.name[0]) |
| 5165 | - struct globnames init_names; |
| 5166 | - struct globnames *names = &init_names; |
| 5167 | - struct globnames *names_alloca = &init_names; |
| 5168 | +# define GLOBNAMES_MEMBERS(nnames) \ |
| 5169 | + struct globnames *next; size_t count; char *name[nnames]; |
| 5170 | + struct globnames { GLOBNAMES_MEMBERS (FLEXIBLE_ARRAY_MEMBER) }; |
| 5171 | + struct { GLOBNAMES_MEMBERS (64) } init_names_buf; |
| 5172 | + struct globnames *init_names = (struct globnames *) &init_names_buf; |
| 5173 | + struct globnames *names = init_names; |
| 5174 | + struct globnames *names_alloca = init_names; |
| 5175 | size_t nfound = 0; |
| 5176 | size_t cur = 0; |
| 5177 | int meta; |
| 5178 | int save; |
| 5179 | + int result; |
| 5180 | |
| 5181 | - alloca_used += sizeof (init_names); |
| 5182 | + alloca_used += sizeof init_names_buf; |
| 5183 | |
| 5184 | - init_names.next = NULL; |
| 5185 | - init_names.count = INITIAL_COUNT; |
| 5186 | + init_names->next = NULL; |
| 5187 | + init_names->count = ((sizeof init_names_buf |
| 5188 | + - offsetof (struct globnames, name)) |
| 5189 | + / sizeof init_names->name[0]); |
| 5190 | |
| 5191 | meta = __glob_pattern_type (pattern, !(flags & GLOB_NOESCAPE)); |
| 5192 | if (meta == 0 && (flags & (GLOB_NOCHECK|GLOB_NOMAGIC))) |
| 5193 | @@ -1529,14 +1489,16 @@ glob_in_dir (const char *pattern, const char *directory, int flags, |
| 5194 | struct_stat64 st64; |
| 5195 | } ust; |
| 5196 | size_t patlen = strlen (pattern); |
| 5197 | - int alloca_fullname = __libc_use_alloca (alloca_used |
| 5198 | - + dirlen + 1 + patlen + 1); |
| 5199 | + size_t fullsize; |
| 5200 | + bool alloca_fullname |
| 5201 | + = (! size_add_wrapv (dirlen + 1, patlen + 1, &fullsize) |
| 5202 | + && glob_use_alloca (alloca_used, fullsize)); |
| 5203 | char *fullname; |
| 5204 | if (alloca_fullname) |
| 5205 | - fullname = alloca_account (dirlen + 1 + patlen + 1, alloca_used); |
| 5206 | + fullname = alloca_account (fullsize, alloca_used); |
| 5207 | else |
| 5208 | { |
| 5209 | - fullname = malloc (dirlen + 1 + patlen + 1); |
| 5210 | + fullname = malloc (fullsize); |
| 5211 | if (fullname == NULL) |
| 5212 | return GLOB_NOSPACE; |
| 5213 | } |
| 5214 | @@ -1544,9 +1506,11 @@ glob_in_dir (const char *pattern, const char *directory, int flags, |
| 5215 | mempcpy (mempcpy (mempcpy (fullname, directory, dirlen), |
| 5216 | "/", 1), |
| 5217 | pattern, patlen + 1); |
| 5218 | - if ((__builtin_expect (flags & GLOB_ALTDIRFUNC, 0) |
| 5219 | + if (((__builtin_expect (flags & GLOB_ALTDIRFUNC, 0) |
| 5220 | ? (*pglob->gl_stat) (fullname, &ust.st) |
| 5221 | - : __stat64 (fullname, &ust.st64)) == 0) |
| 5222 | + : __stat64 (fullname, &ust.st64)) |
| 5223 | + == 0) |
| 5224 | + || errno == EOVERFLOW) |
| 5225 | /* We found this file to be existing. Now tell the rest |
| 5226 | of the function to copy this name into the result. */ |
| 5227 | flags |= GLOB_NOCHECK; |
| 5228 | @@ -1568,16 +1532,10 @@ glob_in_dir (const char *pattern, const char *directory, int flags, |
| 5229 | } |
| 5230 | else |
| 5231 | { |
| 5232 | -#ifdef _LIBC |
| 5233 | int dfd = (__builtin_expect (flags & GLOB_ALTDIRFUNC, 0) |
| 5234 | ? -1 : dirfd ((DIR *) stream)); |
| 5235 | -#endif |
| 5236 | int fnm_flags = ((!(flags & GLOB_PERIOD) ? FNM_PERIOD : 0) |
| 5237 | - | ((flags & GLOB_NOESCAPE) ? FNM_NOESCAPE : 0) |
| 5238 | -#if defined _AMIGA || defined VMS |
| 5239 | - | FNM_CASEFOLD |
| 5240 | -#endif |
| 5241 | - ); |
| 5242 | + | ((flags & GLOB_NOESCAPE) ? FNM_NOESCAPE : 0)); |
| 5243 | flags |= GLOB_MAGCHAR; |
| 5244 | |
| 5245 | while (1) |
| 5246 | @@ -1597,19 +1555,24 @@ glob_in_dir (const char *pattern, const char *directory, int flags, |
| 5247 | } |
| 5248 | if (d.name == NULL) |
| 5249 | break; |
| 5250 | - if (d.skip_entry) |
| 5251 | + if (readdir_result_skip_entry (d)) |
| 5252 | continue; |
| 5253 | |
| 5254 | /* If we shall match only directories use the information |
| 5255 | provided by the dirent call if possible. */ |
| 5256 | - if ((flags & GLOB_ONLYDIR) && !readdir_result_might_be_dir (d)) |
| 5257 | - continue; |
| 5258 | + if (flags & GLOB_ONLYDIR) |
| 5259 | + switch (readdir_result_type (d)) |
| 5260 | + { |
| 5261 | + case DT_DIR: case DT_LNK: case DT_UNKNOWN: break; |
| 5262 | + default: continue; |
| 5263 | + } |
| 5264 | |
| 5265 | if (fnmatch (pattern, d.name, fnm_flags) == 0) |
| 5266 | { |
| 5267 | /* If the file we found is a symlink we have to |
| 5268 | make sure the target file exists. */ |
| 5269 | - if (!readdir_result_might_be_symlink (d) |
| 5270 | + dirent_type type = readdir_result_type (d); |
| 5271 | + if (! (type == DT_LNK || type == DT_UNKNOWN) |
| 5272 | || link_exists_p (dfd, directory, dirlen, d.name, |
| 5273 | pglob, flags)) |
| 5274 | { |
| 5275 | @@ -1617,10 +1580,13 @@ glob_in_dir (const char *pattern, const char *directory, int flags, |
| 5276 | { |
| 5277 | struct globnames *newnames; |
| 5278 | size_t count = names->count * 2; |
| 5279 | - size_t size = (sizeof (struct globnames) |
| 5280 | - + ((count - INITIAL_COUNT) |
| 5281 | - * sizeof (char *))); |
| 5282 | - if (__libc_use_alloca (alloca_used + size)) |
| 5283 | + size_t nameoff = offsetof (struct globnames, name); |
| 5284 | + size_t size = FLEXSIZEOF (struct globnames, name, |
| 5285 | + count * sizeof (char *)); |
| 5286 | + if ((SIZE_MAX - nameoff) / 2 / sizeof (char *) |
| 5287 | + < names->count) |
| 5288 | + goto memory_error; |
| 5289 | + if (glob_use_alloca (alloca_used, size)) |
| 5290 | newnames = names_alloca |
| 5291 | = alloca_account (size, alloca_used); |
| 5292 | else if ((newnames = malloc (size)) |
| 5293 | @@ -1636,6 +1602,8 @@ glob_in_dir (const char *pattern, const char *directory, int flags, |
| 5294 | goto memory_error; |
| 5295 | ++cur; |
| 5296 | ++nfound; |
| 5297 | + if (SIZE_MAX - pglob->gl_offs <= nfound) |
| 5298 | + goto memory_error; |
| 5299 | } |
| 5300 | } |
| 5301 | } |
| 5302 | @@ -1646,29 +1614,27 @@ glob_in_dir (const char *pattern, const char *directory, int flags, |
| 5303 | { |
| 5304 | size_t len = strlen (pattern); |
| 5305 | nfound = 1; |
| 5306 | - names->name[cur] = (char *) malloc (len + 1); |
| 5307 | + names->name[cur] = malloc (len + 1); |
| 5308 | if (names->name[cur] == NULL) |
| 5309 | goto memory_error; |
| 5310 | *((char *) mempcpy (names->name[cur++], pattern, len)) = '\0'; |
| 5311 | } |
| 5312 | |
| 5313 | - int result = GLOB_NOMATCH; |
| 5314 | + result = GLOB_NOMATCH; |
| 5315 | if (nfound != 0) |
| 5316 | { |
| 5317 | + char **new_gl_pathv; |
| 5318 | result = 0; |
| 5319 | |
| 5320 | - if (pglob->gl_pathc > UINTPTR_MAX - pglob->gl_offs |
| 5321 | - || pglob->gl_pathc + pglob->gl_offs > UINTPTR_MAX - nfound |
| 5322 | - || pglob->gl_pathc + pglob->gl_offs + nfound > UINTPTR_MAX - 1 |
| 5323 | - || (pglob->gl_pathc + pglob->gl_offs + nfound + 1 |
| 5324 | - > UINTPTR_MAX / sizeof (char *))) |
| 5325 | + if (SIZE_MAX / sizeof (char *) - pglob->gl_pathc |
| 5326 | + < pglob->gl_offs + nfound + 1) |
| 5327 | goto memory_error; |
| 5328 | |
| 5329 | - char **new_gl_pathv; |
| 5330 | new_gl_pathv |
| 5331 | - = (char **) realloc (pglob->gl_pathv, |
| 5332 | - (pglob->gl_pathc + pglob->gl_offs + nfound + 1) |
| 5333 | - * sizeof (char *)); |
| 5334 | + = realloc (pglob->gl_pathv, |
| 5335 | + (pglob->gl_pathc + pglob->gl_offs + nfound + 1) |
| 5336 | + * sizeof (char *)); |
| 5337 | + |
| 5338 | if (new_gl_pathv == NULL) |
| 5339 | { |
| 5340 | memory_error: |
| 5341 | @@ -1684,7 +1650,7 @@ glob_in_dir (const char *pattern, const char *directory, int flags, |
| 5342 | and this is the block assigned to OLD here. */ |
| 5343 | if (names == NULL) |
| 5344 | { |
| 5345 | - assert (old == &init_names); |
| 5346 | + assert (old == init_names); |
| 5347 | break; |
| 5348 | } |
| 5349 | cur = names->count; |
| 5350 | @@ -1710,7 +1676,7 @@ glob_in_dir (const char *pattern, const char *directory, int flags, |
| 5351 | and this is the block assigned to OLD here. */ |
| 5352 | if (names == NULL) |
| 5353 | { |
| 5354 | - assert (old == &init_names); |
| 5355 | + assert (old == init_names); |
| 5356 | break; |
| 5357 | } |
| 5358 | cur = names->count; |
| 5359 | diff --git a/posix/glob64.c b/posix/glob64.c |
| 5360 | index a5f5a7f9e2..39e54afe8b 100644 |
| 5361 | --- a/posix/glob64.c |
| 5362 | +++ b/posix/glob64.c |
| 5363 | @@ -43,10 +43,4 @@ glob64 (const char *pattern, int flags, |
| 5364 | } |
| 5365 | libc_hidden_def (glob64) |
| 5366 | |
| 5367 | -void |
| 5368 | -globfree64 (glob64_t *pglob) |
| 5369 | -{ |
| 5370 | -} |
| 5371 | -libc_hidden_def (globfree64) |
| 5372 | - |
| 5373 | stub_warning (glob64) |
| 5374 | diff --git a/posix/glob_internal.h b/posix/glob_internal.h |
| 5375 | new file mode 100644 |
| 5376 | index 0000000000..12c93660b7 |
| 5377 | --- /dev/null |
| 5378 | +++ b/posix/glob_internal.h |
| 5379 | @@ -0,0 +1,57 @@ |
| 5380 | +/* Shared definition for glob and glob_pattern_p. |
| 5381 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 5382 | + This file is part of the GNU C Library. |
| 5383 | + |
| 5384 | + The GNU C Library is free software; you can redistribute it and/or |
| 5385 | + modify it under the terms of the GNU Lesser General Public |
| 5386 | + License as published by the Free Software Foundation; either |
| 5387 | + version 2.1 of the License, or (at your option) any later version. |
| 5388 | + |
| 5389 | + The GNU C Library is distributed in the hope that it will be useful, |
| 5390 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 5391 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 5392 | + Lesser General Public License for more details. |
| 5393 | + |
| 5394 | + You should have received a copy of the GNU Lesser General Public |
| 5395 | + License along with the GNU C Library; if not, see |
| 5396 | + <http://www.gnu.org/licenses/>. */ |
| 5397 | + |
| 5398 | +#ifndef GLOB_INTERNAL_H |
| 5399 | +# define GLOB_INTERNAL_H |
| 5400 | + |
| 5401 | +static inline int |
| 5402 | +__glob_pattern_type (const char *pattern, int quote) |
| 5403 | +{ |
| 5404 | + const char *p; |
| 5405 | + int ret = 0; |
| 5406 | + |
| 5407 | + for (p = pattern; *p != '\0'; ++p) |
| 5408 | + switch (*p) |
| 5409 | + { |
| 5410 | + case '?': |
| 5411 | + case '*': |
| 5412 | + return 1; |
| 5413 | + |
| 5414 | + case '\\': |
| 5415 | + if (quote) |
| 5416 | + { |
| 5417 | + if (p[1] != '\0') |
| 5418 | + ++p; |
| 5419 | + ret |= 2; |
| 5420 | + } |
| 5421 | + break; |
| 5422 | + |
| 5423 | + case '[': |
| 5424 | + ret |= 4; |
| 5425 | + break; |
| 5426 | + |
| 5427 | + case ']': |
| 5428 | + if (ret & 4) |
| 5429 | + return 1; |
| 5430 | + break; |
| 5431 | + } |
| 5432 | + |
| 5433 | + return ret; |
| 5434 | +} |
| 5435 | + |
| 5436 | +#endif /* GLOB_INTERNAL_H */ |
| 5437 | diff --git a/posix/glob_pattern_p.c b/posix/glob_pattern_p.c |
| 5438 | new file mode 100644 |
| 5439 | index 0000000000..a17d337182 |
| 5440 | --- /dev/null |
| 5441 | +++ b/posix/glob_pattern_p.c |
| 5442 | @@ -0,0 +1,33 @@ |
| 5443 | +/* Return nonzero if PATTERN contains any metacharacters. |
| 5444 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 5445 | + This file is part of the GNU C Library. |
| 5446 | + |
| 5447 | + The GNU C Library is free software; you can redistribute it and/or |
| 5448 | + modify it under the terms of the GNU Lesser General Public |
| 5449 | + License as published by the Free Software Foundation; either |
| 5450 | + version 2.1 of the License, or (at your option) any later version. |
| 5451 | + |
| 5452 | + The GNU C Library is distributed in the hope that it will be useful, |
| 5453 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 5454 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 5455 | + Lesser General Public License for more details. |
| 5456 | + |
| 5457 | + You should have received a copy of the GNU Lesser General Public |
| 5458 | + License along with the GNU C Library; if not, see |
| 5459 | + <http://www.gnu.org/licenses/>. */ |
| 5460 | + |
| 5461 | +#ifndef _LIBC |
| 5462 | +# include <config.h> |
| 5463 | +#endif |
| 5464 | + |
| 5465 | +#include <glob.h> |
| 5466 | +#include "glob_internal.h" |
| 5467 | + |
| 5468 | +/* Return nonzero if PATTERN contains any metacharacters. |
| 5469 | + Metacharacters can be quoted with backslashes if QUOTE is nonzero. */ |
| 5470 | +int |
| 5471 | +__glob_pattern_p (const char *pattern, int quote) |
| 5472 | +{ |
| 5473 | + return __glob_pattern_type (pattern, quote) == 1; |
| 5474 | +} |
| 5475 | +weak_alias (__glob_pattern_p, glob_pattern_p) |
| 5476 | diff --git a/posix/globfree.c b/posix/globfree.c |
| 5477 | new file mode 100644 |
| 5478 | index 0000000000..042e29d9b0 |
| 5479 | --- /dev/null |
| 5480 | +++ b/posix/globfree.c |
| 5481 | @@ -0,0 +1,41 @@ |
| 5482 | +/* Frees the dynamically allocated storage from an earlier call to glob. |
| 5483 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 5484 | + This file is part of the GNU C Library. |
| 5485 | + |
| 5486 | + The GNU C Library is free software; you can redistribute it and/or |
| 5487 | + modify it under the terms of the GNU Lesser General Public |
| 5488 | + License as published by the Free Software Foundation; either |
| 5489 | + version 2.1 of the License, or (at your option) any later version. |
| 5490 | + |
| 5491 | + The GNU C Library is distributed in the hope that it will be useful, |
| 5492 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 5493 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 5494 | + Lesser General Public License for more details. |
| 5495 | + |
| 5496 | + You should have received a copy of the GNU Lesser General Public |
| 5497 | + License along with the GNU C Library; if not, see |
| 5498 | + <http://www.gnu.org/licenses/>. */ |
| 5499 | + |
| 5500 | +#ifndef _LIBC |
| 5501 | +# include <config.h> |
| 5502 | +#endif |
| 5503 | + |
| 5504 | +#include <glob.h> |
| 5505 | +#include <stdlib.h> |
| 5506 | + |
| 5507 | +/* Free storage allocated in PGLOB by a previous `glob' call. */ |
| 5508 | +void |
| 5509 | +globfree (glob_t *pglob) |
| 5510 | +{ |
| 5511 | + if (pglob->gl_pathv != NULL) |
| 5512 | + { |
| 5513 | + size_t i; |
| 5514 | + for (i = 0; i < pglob->gl_pathc; ++i) |
| 5515 | + free (pglob->gl_pathv[pglob->gl_offs + i]); |
| 5516 | + free (pglob->gl_pathv); |
| 5517 | + pglob->gl_pathv = NULL; |
| 5518 | + } |
| 5519 | +} |
| 5520 | +#ifndef globfree |
| 5521 | +libc_hidden_def (globfree) |
| 5522 | +#endif |
| 5523 | diff --git a/sysdeps/unix/sysv/linux/sh/pread.c b/posix/globfree64.c |
| 5524 | similarity index 68% |
| 5525 | rename from sysdeps/unix/sysv/linux/sh/pread.c |
| 5526 | rename to posix/globfree64.c |
| 5527 | index d3f99f35db..c9f8908a4e 100644 |
| 5528 | --- a/sysdeps/unix/sysv/linux/sh/pread.c |
| 5529 | +++ b/posix/globfree64.c |
| 5530 | @@ -1,6 +1,6 @@ |
| 5531 | -/* Copyright (C) 1997-2016 Free Software Foundation, Inc. |
| 5532 | +/* Frees the dynamically allocated storage from an earlier call to glob. |
| 5533 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 5534 | This file is part of the GNU C Library. |
| 5535 | - Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. |
| 5536 | |
| 5537 | The GNU C Library is free software; you can redistribute it and/or |
| 5538 | modify it under the terms of the GNU Lesser General Public |
| 5539 | @@ -16,8 +16,16 @@ |
| 5540 | License along with the GNU C Library; if not, see |
| 5541 | <http://www.gnu.org/licenses/>. */ |
| 5542 | |
| 5543 | -/* SH4 ABI does not really require argument alignment for 64-bits, but |
| 5544 | - the kernel interface for pread adds a dummy long argument before the |
| 5545 | - offset. */ |
| 5546 | -#define __ALIGNMENT_ARG |
| 5547 | -#include <sysdeps/unix/sysv/linux/pread.c> |
| 5548 | +#ifndef _LIBC |
| 5549 | +# include <config.h> |
| 5550 | +#endif |
| 5551 | + |
| 5552 | +#include <glob.h> |
| 5553 | +#include <stdlib.h> |
| 5554 | + |
| 5555 | +/* Free storage allocated in PGLOB by a previous `glob' call. */ |
| 5556 | +void |
| 5557 | +globfree64 (glob64_t *pglob) |
| 5558 | +{ |
| 5559 | +} |
| 5560 | +libc_hidden_def (globfree64) |
| 5561 | diff --git a/posix/tst-glob-tilde.c b/posix/tst-glob-tilde.c |
| 5562 | new file mode 100644 |
| 5563 | index 0000000000..6886f4371f |
| 5564 | --- /dev/null |
| 5565 | +++ b/posix/tst-glob-tilde.c |
| 5566 | @@ -0,0 +1,143 @@ |
| 5567 | +/* Check for GLOB_TIDLE heap allocation issues (bugs 22320, 22325, 22332). |
| 5568 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 5569 | + This file is part of the GNU C Library. |
| 5570 | + |
| 5571 | + The GNU C Library is free software; you can redistribute it and/or |
| 5572 | + modify it under the terms of the GNU Lesser General Public |
| 5573 | + License as published by the Free Software Foundation; either |
| 5574 | + version 2.1 of the License, or (at your option) any later version. |
| 5575 | + |
| 5576 | + The GNU C Library is distributed in the hope that it will be useful, |
| 5577 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 5578 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 5579 | + Lesser General Public License for more details. |
| 5580 | + |
| 5581 | + You should have received a copy of the GNU Lesser General Public |
| 5582 | + License along with the GNU C Library; if not, see |
| 5583 | + <http://www.gnu.org/licenses/>. */ |
| 5584 | + |
| 5585 | +#include <glob.h> |
| 5586 | +#include <mcheck.h> |
| 5587 | +#include <nss.h> |
| 5588 | +#include <pwd.h> |
| 5589 | +#include <stdlib.h> |
| 5590 | +#include <string.h> |
| 5591 | +#include <support/check.h> |
| 5592 | +#include <support/support.h> |
| 5593 | + |
| 5594 | +/* Flag which indicates whether to pass the GLOB_ONLYDIR flag. */ |
| 5595 | +static int do_onlydir; |
| 5596 | + |
| 5597 | +/* Flag which indicates whether to pass the GLOB_NOCHECK flag. */ |
| 5598 | +static int do_nocheck; |
| 5599 | + |
| 5600 | +/* Flag which indicates whether to pass the GLOB_MARK flag. */ |
| 5601 | +static int do_mark; |
| 5602 | + |
| 5603 | +/* Flag which indicates whether to pass the GLOB_NOESCAPE flag. */ |
| 5604 | +static int do_noescape; |
| 5605 | + |
| 5606 | +static void |
| 5607 | +one_test (const char *prefix, const char *middle, const char *suffix) |
| 5608 | +{ |
| 5609 | + char *pattern = xasprintf ("%s%s%s", prefix, middle, suffix); |
| 5610 | + int flags = GLOB_TILDE; |
| 5611 | + if (do_onlydir) |
| 5612 | + flags |= GLOB_ONLYDIR; |
| 5613 | + if (do_nocheck) |
| 5614 | + flags |= GLOB_NOCHECK; |
| 5615 | + if (do_mark) |
| 5616 | + flags |= GLOB_MARK; |
| 5617 | + if (do_noescape) |
| 5618 | + flags |= GLOB_NOESCAPE; |
| 5619 | + glob_t gl; |
| 5620 | + /* This glob call might result in crashes or memory leaks. */ |
| 5621 | + if (glob (pattern, flags, NULL, &gl) == 0) |
| 5622 | + globfree (&gl); |
| 5623 | + free (pattern); |
| 5624 | +} |
| 5625 | + |
| 5626 | +enum |
| 5627 | + { |
| 5628 | + /* The largest base being tested. */ |
| 5629 | + largest_base_size = 500000, |
| 5630 | + |
| 5631 | + /* The actual size is the base size plus a variable whose absolute |
| 5632 | + value is not greater than this. This helps malloc to trigger |
| 5633 | + overflows. */ |
| 5634 | + max_size_skew = 16, |
| 5635 | + |
| 5636 | + /* The maximum string length supported by repeating_string |
| 5637 | + below. */ |
| 5638 | + repeat_size = largest_base_size + max_size_skew, |
| 5639 | + }; |
| 5640 | + |
| 5641 | +/* Used to construct strings which repeat a single character 'x'. */ |
| 5642 | +static char *repeat; |
| 5643 | + |
| 5644 | +/* Return a string of SIZE characters. */ |
| 5645 | +const char * |
| 5646 | +repeating_string (int size) |
| 5647 | +{ |
| 5648 | + TEST_VERIFY (size >= 0); |
| 5649 | + TEST_VERIFY (size <= repeat_size); |
| 5650 | + const char *repeated_shifted = repeat + repeat_size - size; |
| 5651 | + TEST_VERIFY (strlen (repeated_shifted) == size); |
| 5652 | + return repeated_shifted; |
| 5653 | +} |
| 5654 | + |
| 5655 | +static int |
| 5656 | +do_test (void) |
| 5657 | +{ |
| 5658 | + /* Avoid network-based NSS modules and initialize nss_files with a |
| 5659 | + dummy lookup. This has to come before mtrace because NSS does |
| 5660 | + not free all memory. */ |
| 5661 | + __nss_configure_lookup ("passwd", "files"); |
| 5662 | + (void) getpwnam ("root"); |
| 5663 | + |
| 5664 | + mtrace (); |
| 5665 | + |
| 5666 | + repeat = xmalloc (repeat_size + 1); |
| 5667 | + memset (repeat, 'x', repeat_size); |
| 5668 | + repeat[repeat_size] = '\0'; |
| 5669 | + |
| 5670 | + /* These numbers control the size of the user name. The values |
| 5671 | + cover the minimum (0), a typical size (8), a large |
| 5672 | + stack-allocated size (100000), and a somewhat large |
| 5673 | + heap-allocated size (largest_base_size). */ |
| 5674 | + static const int base_sizes[] = { 0, 8, 100, 100000, largest_base_size, -1 }; |
| 5675 | + |
| 5676 | + for (do_onlydir = 0; do_onlydir < 2; ++do_onlydir) |
| 5677 | + for (do_nocheck = 0; do_nocheck < 2; ++do_nocheck) |
| 5678 | + for (do_mark = 0; do_mark < 2; ++do_mark) |
| 5679 | + for (do_noescape = 0; do_noescape < 2; ++do_noescape) |
| 5680 | + for (int base_idx = 0; base_sizes[base_idx] >= 0; ++base_idx) |
| 5681 | + { |
| 5682 | + for (int size_skew = -max_size_skew; size_skew <= max_size_skew; |
| 5683 | + ++size_skew) |
| 5684 | + { |
| 5685 | + int size = base_sizes[base_idx] + size_skew; |
| 5686 | + if (size < 0) |
| 5687 | + continue; |
| 5688 | + |
| 5689 | + const char *user_name = repeating_string (size); |
| 5690 | + one_test ("~", user_name, "/a/b"); |
| 5691 | + one_test ("~", user_name, "x\\x\\x////x\\a"); |
| 5692 | + } |
| 5693 | + |
| 5694 | + const char *user_name = repeating_string (base_sizes[base_idx]); |
| 5695 | + one_test ("~", user_name, ""); |
| 5696 | + one_test ("~", user_name, "/"); |
| 5697 | + one_test ("~", user_name, "/a"); |
| 5698 | + one_test ("~", user_name, "/*/*"); |
| 5699 | + one_test ("~", user_name, "\\/"); |
| 5700 | + one_test ("/~", user_name, ""); |
| 5701 | + one_test ("*/~", user_name, "/a/b"); |
| 5702 | + } |
| 5703 | + |
| 5704 | + free (repeat); |
| 5705 | + |
| 5706 | + return 0; |
| 5707 | +} |
| 5708 | + |
| 5709 | +#include <support/test-driver.c> |
| 5710 | diff --git a/resolv/Makefile b/resolv/Makefile |
| 5711 | index 8be41d3ae1..a4c86b9762 100644 |
| 5712 | --- a/resolv/Makefile |
| 5713 | +++ b/resolv/Makefile |
| 5714 | @@ -40,6 +40,9 @@ ifeq ($(have-thread-library),yes) |
| 5715 | extra-libs += libanl |
| 5716 | routines += gai_sigqueue |
| 5717 | tests += tst-res_hconf_reorder |
| 5718 | + |
| 5719 | +# This test sends millions of packets and is rather slow. |
| 5720 | +xtests += tst-resolv-qtypes |
| 5721 | endif |
| 5722 | extra-libs-others = $(extra-libs) |
| 5723 | libresolv-routines := gethnamaddr res_comp res_debug \ |
| 5724 | @@ -117,3 +120,5 @@ tst-leaks2-ENV = MALLOC_TRACE=$(objpfx)tst-leaks2.mtrace |
| 5725 | $(objpfx)mtrace-tst-leaks2.out: $(objpfx)tst-leaks2.out |
| 5726 | $(common-objpfx)malloc/mtrace $(objpfx)tst-leaks2.mtrace > $@; \ |
| 5727 | $(evaluate-test) |
| 5728 | + |
| 5729 | +$(objpfx)tst-resolv-qtypes: $(objpfx)libresolv.so $(shared-thread-library) |
| 5730 | diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c |
| 5731 | index 5f9e35701b..d16fa4b8ed 100644 |
| 5732 | --- a/resolv/nss_dns/dns-host.c |
| 5733 | +++ b/resolv/nss_dns/dns-host.c |
| 5734 | @@ -323,7 +323,7 @@ _nss_dns_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat, |
| 5735 | |
| 5736 | int olderr = errno; |
| 5737 | enum nss_status status; |
| 5738 | - int n = __libc_res_nsearch (&_res, name, C_IN, T_UNSPEC, |
| 5739 | + int n = __libc_res_nsearch (&_res, name, C_IN, T_QUERY_A_AND_AAAA, |
| 5740 | host_buffer.buf->buf, 2048, &host_buffer.ptr, |
| 5741 | &ans2p, &nans2p, &resplen2, &ans2p_malloced); |
| 5742 | if (n >= 0) |
| 5743 | diff --git a/resolv/res_mkquery.c b/resolv/res_mkquery.c |
| 5744 | index 12f9730199..d80b5318e5 100644 |
| 5745 | --- a/resolv/res_mkquery.c |
| 5746 | +++ b/resolv/res_mkquery.c |
| 5747 | @@ -103,6 +103,10 @@ res_nmkquery(res_state statp, |
| 5748 | int n; |
| 5749 | u_char *dnptrs[20], **dpp, **lastdnptr; |
| 5750 | |
| 5751 | + if (class < 0 || class > 65535 |
| 5752 | + || type < 0 || type > 65535) |
| 5753 | + return -1; |
| 5754 | + |
| 5755 | #ifdef DEBUG |
| 5756 | if (statp->options & RES_DEBUG) |
| 5757 | printf(";; res_nmkquery(%s, %s, %s, %s)\n", |
| 5758 | diff --git a/resolv/res_query.c b/resolv/res_query.c |
| 5759 | index 944d1a90f5..07dc6f6583 100644 |
| 5760 | --- a/resolv/res_query.c |
| 5761 | +++ b/resolv/res_query.c |
| 5762 | @@ -122,7 +122,7 @@ __libc_res_nquery(res_state statp, |
| 5763 | int n, use_malloc = 0; |
| 5764 | u_int oflags = statp->_flags; |
| 5765 | |
| 5766 | - size_t bufsize = (type == T_UNSPEC ? 2 : 1) * QUERYSIZE; |
| 5767 | + size_t bufsize = (type == T_QUERY_A_AND_AAAA ? 2 : 1) * QUERYSIZE; |
| 5768 | u_char *buf = alloca (bufsize); |
| 5769 | u_char *query1 = buf; |
| 5770 | int nquery1 = -1; |
| 5771 | @@ -137,7 +137,7 @@ __libc_res_nquery(res_state statp, |
| 5772 | printf(";; res_query(%s, %d, %d)\n", name, class, type); |
| 5773 | #endif |
| 5774 | |
| 5775 | - if (type == T_UNSPEC) |
| 5776 | + if (type == T_QUERY_A_AND_AAAA) |
| 5777 | { |
| 5778 | n = res_nmkquery(statp, QUERY, name, class, T_A, NULL, 0, NULL, |
| 5779 | query1, bufsize); |
| 5780 | @@ -190,7 +190,7 @@ __libc_res_nquery(res_state statp, |
| 5781 | if (__builtin_expect (n <= 0, 0) && !use_malloc) { |
| 5782 | /* Retry just in case res_nmkquery failed because of too |
| 5783 | short buffer. Shouldn't happen. */ |
| 5784 | - bufsize = (type == T_UNSPEC ? 2 : 1) * MAXPACKET; |
| 5785 | + bufsize = (type == T_QUERY_A_AND_AAAA ? 2 : 1) * MAXPACKET; |
| 5786 | buf = malloc (bufsize); |
| 5787 | if (buf != NULL) { |
| 5788 | query1 = buf; |
| 5789 | diff --git a/resolv/tst-resolv-qtypes.c b/resolv/tst-resolv-qtypes.c |
| 5790 | new file mode 100644 |
| 5791 | index 0000000000..b3e60c693b |
| 5792 | --- /dev/null |
| 5793 | +++ b/resolv/tst-resolv-qtypes.c |
| 5794 | @@ -0,0 +1,185 @@ |
| 5795 | +/* Exercise low-level query functions with different QTYPEs. |
| 5796 | + Copyright (C) 2016 Free Software Foundation, Inc. |
| 5797 | + This file is part of the GNU C Library. |
| 5798 | + |
| 5799 | + The GNU C Library is free software; you can redistribute it and/or |
| 5800 | + modify it under the terms of the GNU Lesser General Public |
| 5801 | + License as published by the Free Software Foundation; either |
| 5802 | + version 2.1 of the License, or (at your option) any later version. |
| 5803 | + |
| 5804 | + The GNU C Library is distributed in the hope that it will be useful, |
| 5805 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 5806 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 5807 | + Lesser General Public License for more details. |
| 5808 | + |
| 5809 | + You should have received a copy of the GNU Lesser General Public |
| 5810 | + License along with the GNU C Library; if not, see |
| 5811 | + <http://www.gnu.org/licenses/>. */ |
| 5812 | + |
| 5813 | +#include <resolv.h> |
| 5814 | +#include <string.h> |
| 5815 | +#include <support/check.h> |
| 5816 | +#include <support/check_nss.h> |
| 5817 | +#include <support/resolv_test.h> |
| 5818 | +#include <support/support.h> |
| 5819 | +#include <support/test-driver.h> |
| 5820 | +#include <support/xmemstream.h> |
| 5821 | + |
| 5822 | +/* If ture, the response function will send the actual response packet |
| 5823 | + over TCP instead of UDP. */ |
| 5824 | +static volatile bool force_tcp; |
| 5825 | + |
| 5826 | +/* Send back a fake resource record matching the QTYPE. */ |
| 5827 | +static void |
| 5828 | +response (const struct resolv_response_context *ctx, |
| 5829 | + struct resolv_response_builder *b, |
| 5830 | + const char *qname, uint16_t qclass, uint16_t qtype) |
| 5831 | +{ |
| 5832 | + if (force_tcp && ctx->tcp) |
| 5833 | + { |
| 5834 | + resolv_response_init (b, (struct resolv_response_flags) { .tc = 1 }); |
| 5835 | + resolv_response_add_question (b, qname, qclass, qtype); |
| 5836 | + return; |
| 5837 | + } |
| 5838 | + |
| 5839 | + resolv_response_init (b, (struct resolv_response_flags) { }); |
| 5840 | + resolv_response_add_question (b, qname, qclass, qtype); |
| 5841 | + resolv_response_section (b, ns_s_an); |
| 5842 | + resolv_response_open_record (b, qname, qclass, qtype, 0); |
| 5843 | + resolv_response_add_data (b, &qtype, sizeof (qtype)); |
| 5844 | + resolv_response_close_record (b); |
| 5845 | +} |
| 5846 | + |
| 5847 | +static const const char *domain = "www.example.com"; |
| 5848 | + |
| 5849 | +static int |
| 5850 | +wrap_res_query (int type, unsigned char *answer, int answer_length) |
| 5851 | +{ |
| 5852 | + return res_query (domain, C_IN, type, answer, answer_length); |
| 5853 | +} |
| 5854 | + |
| 5855 | +static int |
| 5856 | +wrap_res_search (int type, unsigned char *answer, int answer_length) |
| 5857 | +{ |
| 5858 | + return res_query (domain, C_IN, type, answer, answer_length); |
| 5859 | +} |
| 5860 | + |
| 5861 | +static int |
| 5862 | +wrap_res_querydomain (int type, unsigned char *answer, int answer_length) |
| 5863 | +{ |
| 5864 | + return res_querydomain ("www", "example.com", C_IN, type, |
| 5865 | + answer, answer_length); |
| 5866 | +} |
| 5867 | + |
| 5868 | +static int |
| 5869 | +wrap_res_send (int type, unsigned char *answer, int answer_length) |
| 5870 | +{ |
| 5871 | + unsigned char buf[512]; |
| 5872 | + int ret = res_mkquery (QUERY, domain, C_IN, type, |
| 5873 | + (const unsigned char *) "", 0, NULL, |
| 5874 | + buf, sizeof (buf)); |
| 5875 | + if (type < 0 || type >= 65536) |
| 5876 | + { |
| 5877 | + /* res_mkquery fails for out-of-range record types. */ |
| 5878 | + TEST_VERIFY_EXIT (ret == -1); |
| 5879 | + return -1; |
| 5880 | + } |
| 5881 | + TEST_VERIFY_EXIT (ret > 12); /* DNS header length. */ |
| 5882 | + return res_send (buf, ret, answer, answer_length); |
| 5883 | +} |
| 5884 | + |
| 5885 | +static int |
| 5886 | +wrap_res_nquery (int type, unsigned char *answer, int answer_length) |
| 5887 | +{ |
| 5888 | + return res_nquery (&_res, domain, C_IN, type, answer, answer_length); |
| 5889 | +} |
| 5890 | + |
| 5891 | +static int |
| 5892 | +wrap_res_nsearch (int type, unsigned char *answer, int answer_length) |
| 5893 | +{ |
| 5894 | + return res_nquery (&_res, domain, C_IN, type, answer, answer_length); |
| 5895 | +} |
| 5896 | + |
| 5897 | +static int |
| 5898 | +wrap_res_nquerydomain (int type, unsigned char *answer, int answer_length) |
| 5899 | +{ |
| 5900 | + return res_nquerydomain (&_res, "www", "example.com", C_IN, type, |
| 5901 | + answer, answer_length); |
| 5902 | +} |
| 5903 | + |
| 5904 | +static int |
| 5905 | +wrap_res_nsend (int type, unsigned char *answer, int answer_length) |
| 5906 | +{ |
| 5907 | + unsigned char buf[512]; |
| 5908 | + int ret = res_nmkquery (&_res, QUERY, domain, C_IN, type, |
| 5909 | + (const unsigned char *) "", 0, NULL, |
| 5910 | + buf, sizeof (buf)); |
| 5911 | + if (type < 0 || type >= 65536) |
| 5912 | + { |
| 5913 | + /* res_mkquery fails for out-of-range record types. */ |
| 5914 | + TEST_VERIFY_EXIT (ret == -1); |
| 5915 | + return -1; |
| 5916 | + } |
| 5917 | + TEST_VERIFY_EXIT (ret > 12); /* DNS header length. */ |
| 5918 | + return res_nsend (&_res, buf, ret, answer, answer_length); |
| 5919 | +} |
| 5920 | + |
| 5921 | +static void |
| 5922 | +test_function (const char *fname, |
| 5923 | + int (*func) (int type, |
| 5924 | + unsigned char *answer, int answer_length)) |
| 5925 | +{ |
| 5926 | + unsigned char buf[512]; |
| 5927 | + for (int tcp = 0; tcp < 2; ++tcp) |
| 5928 | + { |
| 5929 | + force_tcp = tcp; |
| 5930 | + for (unsigned int type = 1; type <= 65535; ++type) |
| 5931 | + { |
| 5932 | + if (test_verbose) |
| 5933 | + printf ("info: sending QTYPE %d with %s (tcp=%d)\n", |
| 5934 | + type, fname, tcp); |
| 5935 | + int ret = func (type, buf, sizeof (buf)); |
| 5936 | + if (ret != 47) |
| 5937 | + FAIL_EXIT1 ("%s tcp=%d qtype=%d return value %d", |
| 5938 | + fname,tcp, type, ret); |
| 5939 | + /* One question, one answer record. */ |
| 5940 | + TEST_VERIFY (memcmp (buf + 4, "\0\1\0\1\0\0\0\0", 8) == 0); |
| 5941 | + /* Question section. */ |
| 5942 | + static const char qname[] = "\3www\7example\3com"; |
| 5943 | + size_t qname_length = sizeof (qname); |
| 5944 | + TEST_VERIFY (memcmp (buf + 12, qname, qname_length) == 0); |
| 5945 | + /* RDATA part of answer. */ |
| 5946 | + uint16_t type16 = type; |
| 5947 | + TEST_VERIFY (memcmp (buf + ret - 2, &type16, sizeof (type16)) == 0); |
| 5948 | + } |
| 5949 | + } |
| 5950 | + |
| 5951 | + TEST_VERIFY (func (-1, buf, sizeof (buf) == -1)); |
| 5952 | + TEST_VERIFY (func (65536, buf, sizeof (buf) == -1)); |
| 5953 | +} |
| 5954 | + |
| 5955 | +static int |
| 5956 | +do_test (void) |
| 5957 | +{ |
| 5958 | + struct resolv_redirect_config config = |
| 5959 | + { |
| 5960 | + .response_callback = response, |
| 5961 | + }; |
| 5962 | + struct resolv_test *obj = resolv_test_start (config); |
| 5963 | + |
| 5964 | + test_function ("res_query", &wrap_res_query); |
| 5965 | + test_function ("res_search", &wrap_res_search); |
| 5966 | + test_function ("res_querydomain", &wrap_res_querydomain); |
| 5967 | + test_function ("res_send", &wrap_res_send); |
| 5968 | + |
| 5969 | + test_function ("res_nquery", &wrap_res_nquery); |
| 5970 | + test_function ("res_nsearch", &wrap_res_nsearch); |
| 5971 | + test_function ("res_nquerydomain", &wrap_res_nquerydomain); |
| 5972 | + test_function ("res_nsend", &wrap_res_nsend); |
| 5973 | + |
| 5974 | + resolv_test_end (obj); |
| 5975 | + return 0; |
| 5976 | +} |
| 5977 | + |
| 5978 | +#define TIMEOUT 300 |
| 5979 | +#include <support/test-driver.c> |
| 5980 | diff --git a/scripts/backport-support.sh b/scripts/backport-support.sh |
| 5981 | new file mode 100644 |
| 5982 | index 0000000000..2ece7ce575 |
| 5983 | --- /dev/null |
| 5984 | +++ b/scripts/backport-support.sh |
| 5985 | @@ -0,0 +1,110 @@ |
| 5986 | +#!/bin/bash |
| 5987 | +# Create a patch which backports the support/ subdirectory. |
| 5988 | +# Copyright (C) 2017 Free Software Foundation, Inc. |
| 5989 | +# This file is part of the GNU C Library. |
| 5990 | + |
| 5991 | +# The GNU C Library is free software; you can redistribute it and/or |
| 5992 | +# modify it under the terms of the GNU Lesser General Public |
| 5993 | +# License as published by the Free Software Foundation; either |
| 5994 | +# version 2.1 of the License, or (at your option) any later version. |
| 5995 | + |
| 5996 | +# The GNU C Library is distributed in the hope that it will be useful, |
| 5997 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 5998 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 5999 | +# Lesser General Public License for more details. |
| 6000 | + |
| 6001 | +# You should have received a copy of the GNU Lesser General Public |
| 6002 | +# License along with the GNU C Library; if not, see |
| 6003 | +# <http://www.gnu.org/licenses/>. |
| 6004 | + |
| 6005 | +# This script does not backport the Makefile tweaks outside the |
| 6006 | +# support/ directory (which need to be backported separately), or the |
| 6007 | +# changes to test-skeleton.c (which should not be backported). |
| 6008 | + |
| 6009 | +set -e |
| 6010 | + |
| 6011 | +export LC_ALL=C |
| 6012 | +export GIT_CONFIG=/dev/null |
| 6013 | +export GTT_CONFIG_NOSYSTEM=0 |
| 6014 | +export GIT_PAGER= |
| 6015 | + |
| 6016 | +usage () { |
| 6017 | + cat >&2 <<EOF |
| 6018 | +usage: $0 {patch|commit} |
| 6019 | +EOF |
| 6020 | + exit 1 |
| 6021 | +} |
| 6022 | + |
| 6023 | +if test $# -ne 1 ; then |
| 6024 | + usage |
| 6025 | +fi |
| 6026 | + |
| 6027 | +command="$1" |
| 6028 | + |
| 6029 | +case "$command" in |
| 6030 | + patch|commit) |
| 6031 | + ;; |
| 6032 | + *) |
| 6033 | + usage |
| 6034 | + ;; |
| 6035 | +esac |
| 6036 | + |
| 6037 | +# The upstream branch to work on. |
| 6038 | +branch=origin/master |
| 6039 | + |
| 6040 | +# The commit which added the support/ directory. |
| 6041 | +initial_commit=c23de0aacbeaa7a091609b35764bed931475a16d |
| 6042 | + |
| 6043 | +# We backport the support directory and this script. Directories need |
| 6044 | +# to end in a /. |
| 6045 | +patch_targets="support/ scripts/backport-support.sh" |
| 6046 | + |
| 6047 | +latest_commit="$(git log --max-count=1 --pretty=format:%H "$branch" -- \ |
| 6048 | + $patch_targets)" |
| 6049 | + |
| 6050 | +# Simplify the branch name somewhat for reporting. |
| 6051 | +branch_name="$(echo "$branch" | sed s,^origin/,,)" |
| 6052 | + |
| 6053 | +command_patch () { |
| 6054 | + cat <<EOF |
| 6055 | +This patch creates the contents of the support/ directory up to this |
| 6056 | +upstream commit on the $branch_name branch: |
| 6057 | + |
| 6058 | +EOF |
| 6059 | + git log --max-count=1 "$latest_commit" |
| 6060 | + echo |
| 6061 | + git diff "$initial_commit"^.."$latest_commit" $patch_targets |
| 6062 | + echo "# Before applying the patch, run this command:" >&2 |
| 6063 | + echo "# rm -rf $patch_targets" >&2 |
| 6064 | +} |
| 6065 | + |
| 6066 | +command_commit () { |
| 6067 | + git status --porcelain | while read line ; do |
| 6068 | + echo "error: working copy is not clean, cannot commit" >&2 |
| 6069 | + exit 1 |
| 6070 | + done |
| 6071 | + for path in $patch_targets; do |
| 6072 | + echo "# Processing $path" >&2 |
| 6073 | + case "$path" in |
| 6074 | + [a-zA-Z0-9]*/) |
| 6075 | + # Directory. |
| 6076 | + git rm --cached --ignore-unmatch -r "$path" |
| 6077 | + rm -rf "$path" |
| 6078 | + git read-tree --prefix="$path" "$latest_commit":"$path" |
| 6079 | + git checkout "$path" |
| 6080 | + ;; |
| 6081 | + *) |
| 6082 | + # File. |
| 6083 | + git show "$latest_commit":"$path" > "$path" |
| 6084 | + git add "$path" |
| 6085 | + esac |
| 6086 | + done |
| 6087 | + git commit -m "Synchronize support/ infrastructure with $branch_name |
| 6088 | + |
| 6089 | +This commit updates the support/ subdirectory to |
| 6090 | +commit $latest_commit |
| 6091 | +on the $branch_name branch. |
| 6092 | +" |
| 6093 | +} |
| 6094 | + |
| 6095 | +command_$command |
| 6096 | diff --git a/sunrpc/Makefile b/sunrpc/Makefile |
| 6097 | index 789ef423e5..1e91905011 100644 |
| 6098 | --- a/sunrpc/Makefile |
| 6099 | +++ b/sunrpc/Makefile |
| 6100 | @@ -96,13 +96,18 @@ rpcgen-objs = rpc_main.o rpc_hout.o rpc_cout.o rpc_parse.o \ |
| 6101 | extra-objs = $(rpcgen-objs) $(addprefix cross-,$(rpcgen-objs)) |
| 6102 | others += rpcgen |
| 6103 | |
| 6104 | -tests = tst-xdrmem tst-xdrmem2 test-rpcent |
| 6105 | +tests = tst-xdrmem tst-xdrmem2 test-rpcent tst-udp-error |
| 6106 | xtests := tst-getmyaddr |
| 6107 | |
| 6108 | ifeq ($(have-thread-library),yes) |
| 6109 | xtests += thrsvc |
| 6110 | endif |
| 6111 | |
| 6112 | +ifeq ($(run-built-tests),yes) |
| 6113 | +rpcgen-tests := $(objpfx)bug20790.out |
| 6114 | +tests-special += $(rpcgen-tests) |
| 6115 | +endif |
| 6116 | + |
| 6117 | headers += $(rpcsvc:%.x=rpcsvc/%.h) |
| 6118 | extra-libs := librpcsvc |
| 6119 | extra-libs-others := librpcsvc # Make it in `others' pass, not `lib' pass. |
| 6120 | @@ -153,6 +158,7 @@ BUILD_CPPFLAGS += $(sunrpc-CPPFLAGS) |
| 6121 | $(objpfx)tst-getmyaddr: $(common-objpfx)linkobj/libc.so |
| 6122 | $(objpfx)tst-xdrmem: $(common-objpfx)linkobj/libc.so |
| 6123 | $(objpfx)tst-xdrmem2: $(common-objpfx)linkobj/libc.so |
| 6124 | +$(objpfx)tst-udp-error: $(common-objpfx)linkobj/libc.so |
| 6125 | |
| 6126 | $(objpfx)rpcgen: $(addprefix $(objpfx),$(rpcgen-objs)) |
| 6127 | |
| 6128 | @@ -225,3 +231,9 @@ endif |
| 6129 | endif |
| 6130 | |
| 6131 | $(objpfx)thrsvc: $(common-objpfx)linkobj/libc.so $(shared-thread-library) |
| 6132 | + |
| 6133 | +ifeq ($(run-built-tests),yes) |
| 6134 | +$(rpcgen-tests): $(objpfx)%.out: %.x $(objpfx)rpcgen |
| 6135 | + $(built-program-cmd) -c $< -o $@; \ |
| 6136 | + $(evaluate-test) |
| 6137 | +endif |
| 6138 | diff --git a/sunrpc/bug20790.x b/sunrpc/bug20790.x |
| 6139 | new file mode 100644 |
| 6140 | index 0000000000..a00c9b3830 |
| 6141 | --- /dev/null |
| 6142 | +++ b/sunrpc/bug20790.x |
| 6143 | @@ -0,0 +1 @@ |
| 6144 | +program TPROG { version TVERS { int FUNC(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) = 1; } = 1; } = 1; |
| 6145 | diff --git a/sunrpc/clnt_udp.c b/sunrpc/clnt_udp.c |
| 6146 | index 4d9acb1e6a..1de25cb771 100644 |
| 6147 | --- a/sunrpc/clnt_udp.c |
| 6148 | +++ b/sunrpc/clnt_udp.c |
| 6149 | @@ -421,9 +421,9 @@ send_again: |
| 6150 | cmsg = CMSG_NXTHDR (&msg, cmsg)) |
| 6151 | if (cmsg->cmsg_level == SOL_IP && cmsg->cmsg_type == IP_RECVERR) |
| 6152 | { |
| 6153 | - free (cbuf); |
| 6154 | e = (struct sock_extended_err *) CMSG_DATA(cmsg); |
| 6155 | cu->cu_error.re_errno = e->ee_errno; |
| 6156 | + free (cbuf); |
| 6157 | return (cu->cu_error.re_status = RPC_CANTRECV); |
| 6158 | } |
| 6159 | free (cbuf); |
| 6160 | diff --git a/sunrpc/rpc_parse.c b/sunrpc/rpc_parse.c |
| 6161 | index 1a1df6d8c2..505a6554cf 100644 |
| 6162 | --- a/sunrpc/rpc_parse.c |
| 6163 | +++ b/sunrpc/rpc_parse.c |
| 6164 | @@ -521,7 +521,7 @@ static void |
| 6165 | get_prog_declaration (declaration * dec, defkind dkind, int num /* arg number */ ) |
| 6166 | { |
| 6167 | token tok; |
| 6168 | - char name[10]; /* argument name */ |
| 6169 | + char name[MAXLINESIZE]; /* argument name */ |
| 6170 | |
| 6171 | if (dkind == DEF_PROGRAM) |
| 6172 | { |
| 6173 | diff --git a/sunrpc/tst-udp-error.c b/sunrpc/tst-udp-error.c |
| 6174 | new file mode 100644 |
| 6175 | index 0000000000..1efc02f5c6 |
| 6176 | --- /dev/null |
| 6177 | +++ b/sunrpc/tst-udp-error.c |
| 6178 | @@ -0,0 +1,62 @@ |
| 6179 | +/* Check for use-after-free in clntudp_call (bug 21115). |
| 6180 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 6181 | + This file is part of the GNU C Library. |
| 6182 | + |
| 6183 | + The GNU C Library is free software; you can redistribute it and/or |
| 6184 | + modify it under the terms of the GNU Lesser General Public |
| 6185 | + License as published by the Free Software Foundation; either |
| 6186 | + version 2.1 of the License, or (at your option) any later version. |
| 6187 | + |
| 6188 | + The GNU C Library is distributed in the hope that it will be useful, |
| 6189 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 6190 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 6191 | + Lesser General Public License for more details. |
| 6192 | + |
| 6193 | + You should have received a copy of the GNU Lesser General Public |
| 6194 | + License along with the GNU C Library; if not, see |
| 6195 | + <http://www.gnu.org/licenses/>. */ |
| 6196 | + |
| 6197 | +#include <netinet/in.h> |
| 6198 | +#include <rpc/clnt.h> |
| 6199 | +#include <rpc/svc.h> |
| 6200 | +#include <support/check.h> |
| 6201 | +#include <support/namespace.h> |
| 6202 | +#include <support/xsocket.h> |
| 6203 | +#include <unistd.h> |
| 6204 | + |
| 6205 | +static int |
| 6206 | +do_test (void) |
| 6207 | +{ |
| 6208 | + support_become_root (); |
| 6209 | + support_enter_network_namespace (); |
| 6210 | + |
| 6211 | + /* Obtain a likely-unused port number. */ |
| 6212 | + struct sockaddr_in sin = |
| 6213 | + { |
| 6214 | + .sin_family = AF_INET, |
| 6215 | + .sin_addr.s_addr = htonl (INADDR_LOOPBACK), |
| 6216 | + }; |
| 6217 | + { |
| 6218 | + int fd = xsocket (AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); |
| 6219 | + xbind (fd, (struct sockaddr *) &sin, sizeof (sin)); |
| 6220 | + socklen_t sinlen = sizeof (sin); |
| 6221 | + xgetsockname (fd, (struct sockaddr *) &sin, &sinlen); |
| 6222 | + /* Close the socket, so that we will receive an error below. */ |
| 6223 | + close (fd); |
| 6224 | + } |
| 6225 | + |
| 6226 | + int sock = RPC_ANYSOCK; |
| 6227 | + CLIENT *clnt = clntudp_create |
| 6228 | + (&sin, 1, 2, (struct timeval) { 1, 0 }, &sock); |
| 6229 | + TEST_VERIFY_EXIT (clnt != NULL); |
| 6230 | + TEST_VERIFY (clnt_call (clnt, 3, |
| 6231 | + (xdrproc_t) xdr_void, NULL, |
| 6232 | + (xdrproc_t) xdr_void, NULL, |
| 6233 | + ((struct timeval) { 3, 0 })) |
| 6234 | + == RPC_CANTRECV); |
| 6235 | + clnt_destroy (clnt); |
| 6236 | + |
| 6237 | + return 0; |
| 6238 | +} |
| 6239 | + |
| 6240 | +#include <support/test-driver.c> |
| 6241 | diff --git a/support/Makefile b/support/Makefile |
| 6242 | new file mode 100644 |
| 6243 | index 0000000000..20b0343ade |
| 6244 | --- /dev/null |
| 6245 | +++ b/support/Makefile |
| 6246 | @@ -0,0 +1,146 @@ |
| 6247 | +# Makefile for support library, used only at build and test time |
| 6248 | +# Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 6249 | +# This file is part of the GNU C Library. |
| 6250 | + |
| 6251 | +# The GNU C Library is free software; you can redistribute it and/or |
| 6252 | +# modify it under the terms of the GNU Lesser General Public |
| 6253 | +# License as published by the Free Software Foundation; either |
| 6254 | +# version 2.1 of the License, or (at your option) any later version. |
| 6255 | + |
| 6256 | +# The GNU C Library is distributed in the hope that it will be useful, |
| 6257 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 6258 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 6259 | +# Lesser General Public License for more details. |
| 6260 | + |
| 6261 | +# You should have received a copy of the GNU Lesser General Public |
| 6262 | +# License along with the GNU C Library; if not, see |
| 6263 | +# <http://www.gnu.org/licenses/>. |
| 6264 | + |
| 6265 | +subdir := support |
| 6266 | + |
| 6267 | +include ../Makeconfig |
| 6268 | + |
| 6269 | +extra-libs := libsupport |
| 6270 | +extra-libs-others = $(extra-libs) |
| 6271 | +extra-libs-noinstall := $(extra-libs) |
| 6272 | + |
| 6273 | +libsupport-routines = \ |
| 6274 | + check \ |
| 6275 | + check_addrinfo \ |
| 6276 | + check_dns_packet \ |
| 6277 | + check_hostent \ |
| 6278 | + check_netent \ |
| 6279 | + delayed_exit \ |
| 6280 | + ignore_stderr \ |
| 6281 | + oom_error \ |
| 6282 | + resolv_test \ |
| 6283 | + set_fortify_handler \ |
| 6284 | + support-xstat \ |
| 6285 | + support_become_root \ |
| 6286 | + support_can_chroot \ |
| 6287 | + support_capture_subprocess \ |
| 6288 | + support_capture_subprocess_check \ |
| 6289 | + support_enter_network_namespace \ |
| 6290 | + support_format_address_family \ |
| 6291 | + support_format_addrinfo \ |
| 6292 | + support_format_dns_packet \ |
| 6293 | + support_format_herrno \ |
| 6294 | + support_format_hostent \ |
| 6295 | + support_format_netent \ |
| 6296 | + support_isolate_in_subprocess \ |
| 6297 | + support_record_failure \ |
| 6298 | + support_run_diff \ |
| 6299 | + support_shared_allocate \ |
| 6300 | + support_write_file_string \ |
| 6301 | + support_test_main \ |
| 6302 | + support_test_verify_impl \ |
| 6303 | + temp_file \ |
| 6304 | + write_message \ |
| 6305 | + xaccept \ |
| 6306 | + xaccept4 \ |
| 6307 | + xasprintf \ |
| 6308 | + xbind \ |
| 6309 | + xcalloc \ |
| 6310 | + xchroot \ |
| 6311 | + xclose \ |
| 6312 | + xconnect \ |
| 6313 | + xdup2 \ |
| 6314 | + xfclose \ |
| 6315 | + xfopen \ |
| 6316 | + xfork \ |
| 6317 | + xgetsockname \ |
| 6318 | + xlisten \ |
| 6319 | + xmalloc \ |
| 6320 | + xmemstream \ |
| 6321 | + xmkdir \ |
| 6322 | + xmmap \ |
| 6323 | + xmunmap \ |
| 6324 | + xopen \ |
| 6325 | + xpipe \ |
| 6326 | + xpoll \ |
| 6327 | + xpthread_attr_destroy \ |
| 6328 | + xpthread_attr_init \ |
| 6329 | + xpthread_attr_setdetachstate \ |
| 6330 | + xpthread_attr_setstacksize \ |
| 6331 | + xpthread_barrier_destroy \ |
| 6332 | + xpthread_barrier_init \ |
| 6333 | + xpthread_barrier_wait \ |
| 6334 | + xpthread_cancel \ |
| 6335 | + xpthread_check_return \ |
| 6336 | + xpthread_cond_wait \ |
| 6337 | + xpthread_create \ |
| 6338 | + xpthread_detach \ |
| 6339 | + xpthread_join \ |
| 6340 | + xpthread_mutex_consistent \ |
| 6341 | + xpthread_mutex_destroy \ |
| 6342 | + xpthread_mutex_init \ |
| 6343 | + xpthread_mutex_lock \ |
| 6344 | + xpthread_mutex_unlock \ |
| 6345 | + xpthread_mutexattr_destroy \ |
| 6346 | + xpthread_mutexattr_init \ |
| 6347 | + xpthread_mutexattr_setprotocol \ |
| 6348 | + xpthread_mutexattr_setpshared \ |
| 6349 | + xpthread_mutexattr_setrobust \ |
| 6350 | + xpthread_mutexattr_settype \ |
| 6351 | + xpthread_once \ |
| 6352 | + xpthread_sigmask \ |
| 6353 | + xpthread_spin_lock \ |
| 6354 | + xpthread_spin_unlock \ |
| 6355 | + xrealloc \ |
| 6356 | + xrecvfrom \ |
| 6357 | + xsendto \ |
| 6358 | + xsetsockopt \ |
| 6359 | + xsocket \ |
| 6360 | + xstrdup \ |
| 6361 | + xwaitpid \ |
| 6362 | + xwrite \ |
| 6363 | + |
| 6364 | +libsupport-static-only-routines := $(libsupport-routines) |
| 6365 | +# Only build one variant of the library. |
| 6366 | +libsupport-inhibit-o := .os |
| 6367 | +ifeq ($(build-shared),yes) |
| 6368 | +libsupport-inhibit-o += .o |
| 6369 | +endif |
| 6370 | + |
| 6371 | +tests = \ |
| 6372 | + README-testing \ |
| 6373 | + tst-support-namespace \ |
| 6374 | + tst-support_capture_subprocess \ |
| 6375 | + tst-support_format_dns_packet \ |
| 6376 | + tst-support_record_failure \ |
| 6377 | + |
| 6378 | +ifeq ($(run-built-tests),yes) |
| 6379 | +tests-special = \ |
| 6380 | + $(objpfx)tst-support_record_failure-2.out |
| 6381 | + |
| 6382 | +$(objpfx)tst-support_record_failure-2.out: tst-support_record_failure-2.sh \ |
| 6383 | + $(objpfx)tst-support_record_failure |
| 6384 | + $(SHELL) $< $(common-objpfx) '$(test-program-prefix-before-env)' \ |
| 6385 | + '$(run-program-env)' '$(test-program-prefix-after-env)' \ |
| 6386 | + > $@; \ |
| 6387 | + $(evaluate-test) |
| 6388 | +endif |
| 6389 | + |
| 6390 | +$(objpfx)tst-support_format_dns_packet: $(common-objpfx)resolv/libresolv.so |
| 6391 | + |
| 6392 | +include ../Rules |
| 6393 | diff --git a/support/README b/support/README |
| 6394 | new file mode 100644 |
| 6395 | index 0000000000..476cfcda59 |
| 6396 | --- /dev/null |
| 6397 | +++ b/support/README |
| 6398 | @@ -0,0 +1,29 @@ |
| 6399 | +This subdirectory contains infrastructure which is not put into |
| 6400 | +installed libraries, but may be linked into programs (installed or |
| 6401 | +not) and tests. |
| 6402 | + |
| 6403 | +# Error-checking wrappers |
| 6404 | + |
| 6405 | +These wrappers test for error return codes an terminate the process on |
| 6406 | +error. They are declared in these header files: |
| 6407 | + |
| 6408 | +* support.h |
| 6409 | +* xsignal.h |
| 6410 | +* xthread.h |
| 6411 | + |
| 6412 | +In general, new wrappers should be added to support.h if possible. |
| 6413 | +However, support.h must remain fully compatible with C90 and therefore |
| 6414 | +cannot include headers which use identifers not reserved in C90. If |
| 6415 | +the wrappers need additional types, additional headers such as |
| 6416 | +signal.h need to be introduced. |
| 6417 | + |
| 6418 | +# Test framework |
| 6419 | + |
| 6420 | +The test framework provides a main program for tests, including a |
| 6421 | +timeout for hanging tests. See README-testing.c for a minimal |
| 6422 | +example, and test-driver.c for details how to use it. The following |
| 6423 | +header files provide related declarations: |
| 6424 | + |
| 6425 | +* check.h |
| 6426 | +* temp_file.h |
| 6427 | +* test-driver.h |
| 6428 | diff --git a/support/README-testing.c b/support/README-testing.c |
| 6429 | new file mode 100644 |
| 6430 | index 0000000000..9d289c3020 |
| 6431 | --- /dev/null |
| 6432 | +++ b/support/README-testing.c |
| 6433 | @@ -0,0 +1,19 @@ |
| 6434 | +/* This file contains an example test case which shows minimal use of |
| 6435 | + the test framework. Additional testing hooks are described in |
| 6436 | + <support/test-driver.c>. */ |
| 6437 | + |
| 6438 | +/* This function will be called from the test driver. */ |
| 6439 | +static int |
| 6440 | +do_test (void) |
| 6441 | +{ |
| 6442 | + if (3 == 5) |
| 6443 | + /* Indicate failure. */ |
| 6444 | + return 1; |
| 6445 | + else |
| 6446 | + /* Indicate success. */ |
| 6447 | + return 0; |
| 6448 | +} |
| 6449 | + |
| 6450 | +/* This file references do_test above and contains the definition of |
| 6451 | + the main function. */ |
| 6452 | +#include <support/test-driver.c> |
| 6453 | diff --git a/support/capture_subprocess.h b/support/capture_subprocess.h |
| 6454 | new file mode 100644 |
| 6455 | index 0000000000..43caf9bce4 |
| 6456 | --- /dev/null |
| 6457 | +++ b/support/capture_subprocess.h |
| 6458 | @@ -0,0 +1,61 @@ |
| 6459 | +/* Capture output from a subprocess. |
| 6460 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 6461 | + This file is part of the GNU C Library. |
| 6462 | + |
| 6463 | + The GNU C Library is free software; you can redistribute it and/or |
| 6464 | + modify it under the terms of the GNU Lesser General Public |
| 6465 | + License as published by the Free Software Foundation; either |
| 6466 | + version 2.1 of the License, or (at your option) any later version. |
| 6467 | + |
| 6468 | + The GNU C Library is distributed in the hope that it will be useful, |
| 6469 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 6470 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 6471 | + Lesser General Public License for more details. |
| 6472 | + |
| 6473 | + You should have received a copy of the GNU Lesser General Public |
| 6474 | + License along with the GNU C Library; if not, see |
| 6475 | + <http://www.gnu.org/licenses/>. */ |
| 6476 | + |
| 6477 | +#ifndef SUPPORT_CAPTURE_SUBPROCESS_H |
| 6478 | +#define SUPPORT_CAPTURE_SUBPROCESS_H |
| 6479 | + |
| 6480 | +#include <support/xmemstream.h> |
| 6481 | + |
| 6482 | +struct support_capture_subprocess |
| 6483 | +{ |
| 6484 | + struct xmemstream out; |
| 6485 | + struct xmemstream err; |
| 6486 | + int status; |
| 6487 | +}; |
| 6488 | + |
| 6489 | +/* Invoke CALLBACK (CLOSURE) in a subprocess and capture standard |
| 6490 | + output, standard error, and the exit status. The out.buffer and |
| 6491 | + err.buffer members in the result are null-terminated strings which |
| 6492 | + can be examined by the caller (out.out and err.out are NULL). */ |
| 6493 | +struct support_capture_subprocess support_capture_subprocess |
| 6494 | + (void (*callback) (void *), void *closure); |
| 6495 | + |
| 6496 | +/* Deallocate the subprocess data captured by |
| 6497 | + support_capture_subprocess. */ |
| 6498 | +void support_capture_subprocess_free (struct support_capture_subprocess *); |
| 6499 | + |
| 6500 | +enum support_capture_allow |
| 6501 | +{ |
| 6502 | + /* No output is allowed. */ |
| 6503 | + sc_allow_none = 0x01, |
| 6504 | + /* Output to stdout is permitted. */ |
| 6505 | + sc_allow_stdout = 0x02, |
| 6506 | + /* Output to standard error is permitted. */ |
| 6507 | + sc_allow_stderr = 0x04, |
| 6508 | +}; |
| 6509 | + |
| 6510 | +/* Check that the subprocess exited with STATUS and that only the |
| 6511 | + allowed outputs happened. ALLOWED is a combination of |
| 6512 | + support_capture_allow flags. Report errors under the CONTEXT |
| 6513 | + message. */ |
| 6514 | +void support_capture_subprocess_check (struct support_capture_subprocess *, |
| 6515 | + const char *context, int status, |
| 6516 | + int allowed) |
| 6517 | + __attribute__ ((nonnull (1, 2))); |
| 6518 | + |
| 6519 | +#endif /* SUPPORT_CAPTURE_SUBPROCESS_H */ |
| 6520 | diff --git a/support/check.c b/support/check.c |
| 6521 | new file mode 100644 |
| 6522 | index 0000000000..592f2bc856 |
| 6523 | --- /dev/null |
| 6524 | +++ b/support/check.c |
| 6525 | @@ -0,0 +1,57 @@ |
| 6526 | +/* Support code for reporting test results. |
| 6527 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 6528 | + This file is part of the GNU C Library. |
| 6529 | + |
| 6530 | + The GNU C Library is free software; you can redistribute it and/or |
| 6531 | + modify it under the terms of the GNU Lesser General Public |
| 6532 | + License as published by the Free Software Foundation; either |
| 6533 | + version 2.1 of the License, or (at your option) any later version. |
| 6534 | + |
| 6535 | + The GNU C Library is distributed in the hope that it will be useful, |
| 6536 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 6537 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 6538 | + Lesser General Public License for more details. |
| 6539 | + |
| 6540 | + You should have received a copy of the GNU Lesser General Public |
| 6541 | + License along with the GNU C Library; if not, see |
| 6542 | + <http://www.gnu.org/licenses/>. */ |
| 6543 | + |
| 6544 | +#include <support/check.h> |
| 6545 | + |
| 6546 | +#include <stdarg.h> |
| 6547 | +#include <stdio.h> |
| 6548 | +#include <stdlib.h> |
| 6549 | +#include <support/test-driver.h> |
| 6550 | + |
| 6551 | +static void |
| 6552 | +print_failure (const char *file, int line, const char *format, va_list ap) |
| 6553 | +{ |
| 6554 | + printf ("error: %s:%d: ", file, line); |
| 6555 | + vprintf (format, ap); |
| 6556 | + puts (""); |
| 6557 | +} |
| 6558 | + |
| 6559 | +int |
| 6560 | +support_print_failure_impl (const char *file, int line, |
| 6561 | + const char *format, ...) |
| 6562 | +{ |
| 6563 | + support_record_failure (); |
| 6564 | + va_list ap; |
| 6565 | + va_start (ap, format); |
| 6566 | + print_failure (file, line, format, ap); |
| 6567 | + va_end (ap); |
| 6568 | + return 1; |
| 6569 | +} |
| 6570 | + |
| 6571 | +void |
| 6572 | +support_exit_failure_impl (int status, const char *file, int line, |
| 6573 | + const char *format, ...) |
| 6574 | +{ |
| 6575 | + if (status != EXIT_SUCCESS && status != EXIT_UNSUPPORTED) |
| 6576 | + support_record_failure (); |
| 6577 | + va_list ap; |
| 6578 | + va_start (ap, format); |
| 6579 | + print_failure (file, line, format, ap); |
| 6580 | + va_end (ap); |
| 6581 | + exit (status); |
| 6582 | +} |
| 6583 | diff --git a/support/check.h b/support/check.h |
| 6584 | new file mode 100644 |
| 6585 | index 0000000000..1d244a3557 |
| 6586 | --- /dev/null |
| 6587 | +++ b/support/check.h |
| 6588 | @@ -0,0 +1,94 @@ |
| 6589 | +/* Functionality for reporting test results. |
| 6590 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 6591 | + This file is part of the GNU C Library. |
| 6592 | + |
| 6593 | + The GNU C Library is free software; you can redistribute it and/or |
| 6594 | + modify it under the terms of the GNU Lesser General Public |
| 6595 | + License as published by the Free Software Foundation; either |
| 6596 | + version 2.1 of the License, or (at your option) any later version. |
| 6597 | + |
| 6598 | + The GNU C Library is distributed in the hope that it will be useful, |
| 6599 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 6600 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 6601 | + Lesser General Public License for more details. |
| 6602 | + |
| 6603 | + You should have received a copy of the GNU Lesser General Public |
| 6604 | + License along with the GNU C Library; if not, see |
| 6605 | + <http://www.gnu.org/licenses/>. */ |
| 6606 | + |
| 6607 | +#ifndef SUPPORT_CHECK_H |
| 6608 | +#define SUPPORT_CHECK_H |
| 6609 | + |
| 6610 | +#include <sys/cdefs.h> |
| 6611 | + |
| 6612 | +__BEGIN_DECLS |
| 6613 | + |
| 6614 | +/* Record a test failure, print the failure message to standard output |
| 6615 | + and return 1. */ |
| 6616 | +#define FAIL_RET(...) \ |
| 6617 | + return support_print_failure_impl (__FILE__, __LINE__, __VA_ARGS__) |
| 6618 | + |
| 6619 | +/* Print the failure message and terminate the process with STATUS. |
| 6620 | + Record a the process as failed if STATUS is neither EXIT_SUCCESS |
| 6621 | + nor EXIT_UNSUPPORTED. */ |
| 6622 | +#define FAIL_EXIT(status, ...) \ |
| 6623 | + support_exit_failure_impl (status, __FILE__, __LINE__, __VA_ARGS__) |
| 6624 | + |
| 6625 | +/* Record a test failure, print the failure message and terminate with |
| 6626 | + exit status 1. */ |
| 6627 | +#define FAIL_EXIT1(...) \ |
| 6628 | + support_exit_failure_impl (1, __FILE__, __LINE__, __VA_ARGS__) |
| 6629 | + |
| 6630 | +/* Print failure message and terminate with as unsupported test (exit |
| 6631 | + status of 77). */ |
| 6632 | +#define FAIL_UNSUPPORTED(...) \ |
| 6633 | + support_exit_failure_impl (77, __FILE__, __LINE__, __VA_ARGS__) |
| 6634 | + |
| 6635 | +/* Record a test failure (but continue executing) if EXPR evaluates to |
| 6636 | + false. */ |
| 6637 | +#define TEST_VERIFY(expr) \ |
| 6638 | + ({ \ |
| 6639 | + if (expr) \ |
| 6640 | + ; \ |
| 6641 | + else \ |
| 6642 | + support_test_verify_impl (-1, __FILE__, __LINE__, #expr); \ |
| 6643 | + }) |
| 6644 | + |
| 6645 | +/* Record a test failure and exit if EXPR evaluates to false. */ |
| 6646 | +#define TEST_VERIFY_EXIT(expr) \ |
| 6647 | + ({ \ |
| 6648 | + if (expr) \ |
| 6649 | + ; \ |
| 6650 | + else \ |
| 6651 | + support_test_verify_impl (1, __FILE__, __LINE__, #expr); \ |
| 6652 | + }) |
| 6653 | + |
| 6654 | +int support_print_failure_impl (const char *file, int line, |
| 6655 | + const char *format, ...) |
| 6656 | + __attribute__ ((nonnull (1), format (printf, 3, 4))); |
| 6657 | +void support_exit_failure_impl (int exit_status, |
| 6658 | + const char *file, int line, |
| 6659 | + const char *format, ...) |
| 6660 | + __attribute__ ((noreturn, nonnull (2), format (printf, 4, 5))); |
| 6661 | +void support_test_verify_impl (int status, const char *file, int line, |
| 6662 | + const char *expr); |
| 6663 | + |
| 6664 | +/* Record a test failure. This function returns and does not |
| 6665 | + terminate the process. The failure counter is stored in a shared |
| 6666 | + memory mapping, so that failures reported in child processes are |
| 6667 | + visible to the parent process and test driver. This function |
| 6668 | + depends on initialization by an ELF constructor, so it can only be |
| 6669 | + invoked after the test driver has run. Note that this function |
| 6670 | + does not support reporting failures from a DSO. */ |
| 6671 | +void support_record_failure (void); |
| 6672 | + |
| 6673 | +/* Internal function called by the test driver. */ |
| 6674 | +int support_report_failure (int status) |
| 6675 | + __attribute__ ((weak, warn_unused_result)); |
| 6676 | + |
| 6677 | +/* Internal function used to test the failure recording framework. */ |
| 6678 | +void support_record_failure_reset (void); |
| 6679 | + |
| 6680 | +__END_DECLS |
| 6681 | + |
| 6682 | +#endif /* SUPPORT_CHECK_H */ |
| 6683 | diff --git a/support/check_addrinfo.c b/support/check_addrinfo.c |
| 6684 | new file mode 100644 |
| 6685 | index 0000000000..55895ace3c |
| 6686 | --- /dev/null |
| 6687 | +++ b/support/check_addrinfo.c |
| 6688 | @@ -0,0 +1,42 @@ |
| 6689 | +/* Compare struct addrinfo values against a formatted string. |
| 6690 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 6691 | + This file is part of the GNU C Library. |
| 6692 | + |
| 6693 | + The GNU C Library is free software; you can redistribute it and/or |
| 6694 | + modify it under the terms of the GNU Lesser General Public |
| 6695 | + License as published by the Free Software Foundation; either |
| 6696 | + version 2.1 of the License, or (at your option) any later version. |
| 6697 | + |
| 6698 | + The GNU C Library is distributed in the hope that it will be useful, |
| 6699 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 6700 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 6701 | + Lesser General Public License for more details. |
| 6702 | + |
| 6703 | + You should have received a copy of the GNU Lesser General Public |
| 6704 | + License along with the GNU C Library; if not, see |
| 6705 | + <http://www.gnu.org/licenses/>. */ |
| 6706 | + |
| 6707 | +#include <support/check_nss.h> |
| 6708 | + |
| 6709 | +#include <stdio.h> |
| 6710 | +#include <stdlib.h> |
| 6711 | +#include <support/check.h> |
| 6712 | +#include <support/format_nss.h> |
| 6713 | +#include <support/run_diff.h> |
| 6714 | + |
| 6715 | +void |
| 6716 | +check_addrinfo (const char *query_description, struct addrinfo *ai, int ret, |
| 6717 | + const char *expected) |
| 6718 | +{ |
| 6719 | + char *formatted = support_format_addrinfo (ai, ret); |
| 6720 | + if (strcmp (formatted, expected) != 0) |
| 6721 | + { |
| 6722 | + support_record_failure (); |
| 6723 | + printf ("error: addrinfo comparison failure\n"); |
| 6724 | + if (query_description != NULL) |
| 6725 | + printf ("query: %s\n", query_description); |
| 6726 | + support_run_diff ("expected", expected, |
| 6727 | + "actual", formatted); |
| 6728 | + } |
| 6729 | + free (formatted); |
| 6730 | +} |
| 6731 | diff --git a/support/check_dns_packet.c b/support/check_dns_packet.c |
| 6732 | new file mode 100644 |
| 6733 | index 0000000000..d2a31bed7b |
| 6734 | --- /dev/null |
| 6735 | +++ b/support/check_dns_packet.c |
| 6736 | @@ -0,0 +1,42 @@ |
| 6737 | +/* Check that a DNS packet buffer has the expected contents. |
| 6738 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 6739 | + This file is part of the GNU C Library. |
| 6740 | + |
| 6741 | + The GNU C Library is free software; you can redistribute it and/or |
| 6742 | + modify it under the terms of the GNU Lesser General Public |
| 6743 | + License as published by the Free Software Foundation; either |
| 6744 | + version 2.1 of the License, or (at your option) any later version. |
| 6745 | + |
| 6746 | + The GNU C Library is distributed in the hope that it will be useful, |
| 6747 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 6748 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 6749 | + Lesser General Public License for more details. |
| 6750 | + |
| 6751 | + You should have received a copy of the GNU Lesser General Public |
| 6752 | + License along with the GNU C Library; if not, see |
| 6753 | + <http://www.gnu.org/licenses/>. */ |
| 6754 | + |
| 6755 | +#include <support/check_nss.h> |
| 6756 | + |
| 6757 | +#include <stdio.h> |
| 6758 | +#include <stdlib.h> |
| 6759 | +#include <support/check.h> |
| 6760 | +#include <support/format_nss.h> |
| 6761 | +#include <support/run_diff.h> |
| 6762 | + |
| 6763 | +void |
| 6764 | +check_dns_packet (const char *query_description, |
| 6765 | + const unsigned char *buffer, size_t length, |
| 6766 | + const char *expected) |
| 6767 | +{ |
| 6768 | + char *formatted = support_format_dns_packet (buffer, length); |
| 6769 | + if (strcmp (formatted, expected) != 0) |
| 6770 | + { |
| 6771 | + support_record_failure (); |
| 6772 | + printf ("error: packet comparison failure\n"); |
| 6773 | + if (query_description != NULL) |
| 6774 | + printf ("query: %s\n", query_description); |
| 6775 | + support_run_diff ("expected", expected, "actual", formatted); |
| 6776 | + } |
| 6777 | + free (formatted); |
| 6778 | +} |
| 6779 | diff --git a/support/check_hostent.c b/support/check_hostent.c |
| 6780 | new file mode 100644 |
| 6781 | index 0000000000..890d672d50 |
| 6782 | --- /dev/null |
| 6783 | +++ b/support/check_hostent.c |
| 6784 | @@ -0,0 +1,42 @@ |
| 6785 | +/* Compare struct hostent values against a formatted string. |
| 6786 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 6787 | + This file is part of the GNU C Library. |
| 6788 | + |
| 6789 | + The GNU C Library is free software; you can redistribute it and/or |
| 6790 | + modify it under the terms of the GNU Lesser General Public |
| 6791 | + License as published by the Free Software Foundation; either |
| 6792 | + version 2.1 of the License, or (at your option) any later version. |
| 6793 | + |
| 6794 | + The GNU C Library is distributed in the hope that it will be useful, |
| 6795 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 6796 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 6797 | + Lesser General Public License for more details. |
| 6798 | + |
| 6799 | + You should have received a copy of the GNU Lesser General Public |
| 6800 | + License along with the GNU C Library; if not, see |
| 6801 | + <http://www.gnu.org/licenses/>. */ |
| 6802 | + |
| 6803 | +#include <support/check_nss.h> |
| 6804 | + |
| 6805 | +#include <stdio.h> |
| 6806 | +#include <stdlib.h> |
| 6807 | +#include <support/check.h> |
| 6808 | +#include <support/format_nss.h> |
| 6809 | +#include <support/run_diff.h> |
| 6810 | + |
| 6811 | +void |
| 6812 | +check_hostent (const char *query_description, struct hostent *h, |
| 6813 | + const char *expected) |
| 6814 | +{ |
| 6815 | + char *formatted = support_format_hostent (h); |
| 6816 | + if (strcmp (formatted, expected) != 0) |
| 6817 | + { |
| 6818 | + support_record_failure (); |
| 6819 | + printf ("error: hostent comparison failure\n"); |
| 6820 | + if (query_description != NULL) |
| 6821 | + printf ("query: %s\n", query_description); |
| 6822 | + support_run_diff ("expected", expected, |
| 6823 | + "actual", formatted); |
| 6824 | + } |
| 6825 | + free (formatted); |
| 6826 | +} |
| 6827 | diff --git a/support/check_netent.c b/support/check_netent.c |
| 6828 | new file mode 100644 |
| 6829 | index 0000000000..daa3083fd1 |
| 6830 | --- /dev/null |
| 6831 | +++ b/support/check_netent.c |
| 6832 | @@ -0,0 +1,42 @@ |
| 6833 | +/* Compare struct netent values against a formatted string. |
| 6834 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 6835 | + This file is part of the GNU C Library. |
| 6836 | + |
| 6837 | + The GNU C Library is free software; you can redistribute it and/or |
| 6838 | + modify it under the terms of the GNU Lesser General Public |
| 6839 | + License as published by the Free Software Foundation; either |
| 6840 | + version 2.1 of the License, or (at your option) any later version. |
| 6841 | + |
| 6842 | + The GNU C Library is distributed in the hope that it will be useful, |
| 6843 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 6844 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 6845 | + Lesser General Public License for more details. |
| 6846 | + |
| 6847 | + You should have received a copy of the GNU Lesser General Public |
| 6848 | + License along with the GNU C Library; if not, see |
| 6849 | + <http://www.gnu.org/licenses/>. */ |
| 6850 | + |
| 6851 | +#include <support/check_nss.h> |
| 6852 | + |
| 6853 | +#include <stdio.h> |
| 6854 | +#include <stdlib.h> |
| 6855 | +#include <support/check.h> |
| 6856 | +#include <support/format_nss.h> |
| 6857 | +#include <support/run_diff.h> |
| 6858 | + |
| 6859 | +void |
| 6860 | +check_netent (const char *query_description, struct netent *e, |
| 6861 | + const char *expected) |
| 6862 | +{ |
| 6863 | + char *formatted = support_format_netent (e); |
| 6864 | + if (strcmp (formatted, expected) != 0) |
| 6865 | + { |
| 6866 | + support_record_failure (); |
| 6867 | + printf ("error: netent comparison failure\n"); |
| 6868 | + if (query_description != NULL) |
| 6869 | + printf ("query: %s\n", query_description); |
| 6870 | + support_run_diff ("expected", expected, |
| 6871 | + "actual", formatted); |
| 6872 | + } |
| 6873 | + free (formatted); |
| 6874 | +} |
| 6875 | diff --git a/support/check_nss.h b/support/check_nss.h |
| 6876 | new file mode 100644 |
| 6877 | index 0000000000..2893f2c295 |
| 6878 | --- /dev/null |
| 6879 | +++ b/support/check_nss.h |
| 6880 | @@ -0,0 +1,42 @@ |
| 6881 | +/* Test verification functions for NSS- and DNS-related data. |
| 6882 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 6883 | + This file is part of the GNU C Library. |
| 6884 | + |
| 6885 | + The GNU C Library is free software; you can redistribute it and/or |
| 6886 | + modify it under the terms of the GNU Lesser General Public |
| 6887 | + License as published by the Free Software Foundation; either |
| 6888 | + version 2.1 of the License, or (at your option) any later version. |
| 6889 | + |
| 6890 | + The GNU C Library is distributed in the hope that it will be useful, |
| 6891 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 6892 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 6893 | + Lesser General Public License for more details. |
| 6894 | + |
| 6895 | + You should have received a copy of the GNU Lesser General Public |
| 6896 | + License along with the GNU C Library; if not, see |
| 6897 | + <http://www.gnu.org/licenses/>. */ |
| 6898 | + |
| 6899 | +#ifndef SUPPORT_CHECK_NSS_H |
| 6900 | +#define SUPPORT_CHECK_NSS_H |
| 6901 | + |
| 6902 | +#include <netdb.h> |
| 6903 | +#include <sys/cdefs.h> |
| 6904 | + |
| 6905 | +__BEGIN_DECLS |
| 6906 | + |
| 6907 | +/* Compare the data structures against the expected values (which have |
| 6908 | + to be formatted according to the support_format_* functions in |
| 6909 | + <support/format_nss.h>). If there is a difference, a delayed test |
| 6910 | + failure is recorded, and a diff is written to standard output. */ |
| 6911 | +void check_addrinfo (const char *query_description, |
| 6912 | + struct addrinfo *, int ret, const char *expected); |
| 6913 | +void check_dns_packet (const char *query_description, |
| 6914 | + const unsigned char *, size_t, const char *expected); |
| 6915 | +void check_hostent (const char *query_description, |
| 6916 | + struct hostent *, const char *expected); |
| 6917 | +void check_netent (const char *query_description, |
| 6918 | + struct netent *, const char *expected); |
| 6919 | + |
| 6920 | +__END_DECLS |
| 6921 | + |
| 6922 | +#endif /* SUPPORT_CHECK_NSS_H */ |
| 6923 | diff --git a/support/delayed_exit.c b/support/delayed_exit.c |
| 6924 | new file mode 100644 |
| 6925 | index 0000000000..67442f95df |
| 6926 | --- /dev/null |
| 6927 | +++ b/support/delayed_exit.c |
| 6928 | @@ -0,0 +1,55 @@ |
| 6929 | +/* Time-triggered process termination. |
| 6930 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 6931 | + This file is part of the GNU C Library. |
| 6932 | + |
| 6933 | + The GNU C Library is free software; you can redistribute it and/or |
| 6934 | + modify it under the terms of the GNU Lesser General Public |
| 6935 | + License as published by the Free Software Foundation; either |
| 6936 | + version 2.1 of the License, or (at your option) any later version. |
| 6937 | + |
| 6938 | + The GNU C Library is distributed in the hope that it will be useful, |
| 6939 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 6940 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 6941 | + Lesser General Public License for more details. |
| 6942 | + |
| 6943 | + You should have received a copy of the GNU Lesser General Public |
| 6944 | + License along with the GNU C Library; if not, see |
| 6945 | + <http://www.gnu.org/licenses/>. */ |
| 6946 | + |
| 6947 | +#include <support/xthread.h> |
| 6948 | +#include <support/xsignal.h> |
| 6949 | + |
| 6950 | +#include <stdint.h> |
| 6951 | +#include <stdio.h> |
| 6952 | +#include <stdlib.h> |
| 6953 | +#include <support/check.h> |
| 6954 | +#include <time.h> |
| 6955 | + |
| 6956 | +static void * |
| 6957 | +delayed_exit_thread (void *seconds_as_ptr) |
| 6958 | +{ |
| 6959 | + int seconds = (uintptr_t) seconds_as_ptr; |
| 6960 | + struct timespec delay = { seconds, 0 }; |
| 6961 | + struct timespec remaining = { 0 }; |
| 6962 | + if (nanosleep (&delay, &remaining) != 0) |
| 6963 | + FAIL_EXIT1 ("nanosleep: %m"); |
| 6964 | + /* Exit the process sucessfully. */ |
| 6965 | + exit (0); |
| 6966 | + return NULL; |
| 6967 | +} |
| 6968 | + |
| 6969 | +void |
| 6970 | +delayed_exit (int seconds) |
| 6971 | +{ |
| 6972 | + /* Create the new thread with all signals blocked. */ |
| 6973 | + sigset_t all_blocked; |
| 6974 | + sigfillset (&all_blocked); |
| 6975 | + sigset_t old_set; |
| 6976 | + xpthread_sigmask (SIG_SETMASK, &all_blocked, &old_set); |
| 6977 | + /* Create a detached thread. */ |
| 6978 | + pthread_t thr = xpthread_create |
| 6979 | + (NULL, delayed_exit_thread, (void *) (uintptr_t) seconds); |
| 6980 | + xpthread_detach (thr); |
| 6981 | + /* Restore the original signal mask. */ |
| 6982 | + xpthread_sigmask (SIG_SETMASK, &old_set, NULL); |
| 6983 | +} |
| 6984 | diff --git a/support/format_nss.h b/support/format_nss.h |
| 6985 | new file mode 100644 |
| 6986 | index 0000000000..fb4597c238 |
| 6987 | --- /dev/null |
| 6988 | +++ b/support/format_nss.h |
| 6989 | @@ -0,0 +1,41 @@ |
| 6990 | +/* String formatting functions for NSS- and DNS-related data. |
| 6991 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 6992 | + This file is part of the GNU C Library. |
| 6993 | + |
| 6994 | + The GNU C Library is free software; you can redistribute it and/or |
| 6995 | + modify it under the terms of the GNU Lesser General Public |
| 6996 | + License as published by the Free Software Foundation; either |
| 6997 | + version 2.1 of the License, or (at your option) any later version. |
| 6998 | + |
| 6999 | + The GNU C Library is distributed in the hope that it will be useful, |
| 7000 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 7001 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 7002 | + Lesser General Public License for more details. |
| 7003 | + |
| 7004 | + You should have received a copy of the GNU Lesser General Public |
| 7005 | + License along with the GNU C Library; if not, see |
| 7006 | + <http://www.gnu.org/licenses/>. */ |
| 7007 | + |
| 7008 | +#ifndef SUPPORT_FORMAT_NSS_H |
| 7009 | +#define SUPPORT_FORMAT_NSS_H |
| 7010 | + |
| 7011 | +#include <netdb.h> |
| 7012 | +#include <sys/cdefs.h> |
| 7013 | + |
| 7014 | +__BEGIN_DECLS |
| 7015 | + |
| 7016 | +/* The following functions format their arguments as human-readable |
| 7017 | + strings (which can span multiple lines). The caller must free the |
| 7018 | + returned buffer. For NULL pointers or failure status arguments, |
| 7019 | + error variables such as h_errno and errno are included in the |
| 7020 | + result. */ |
| 7021 | +char *support_format_address_family (int); |
| 7022 | +char *support_format_addrinfo (struct addrinfo *, int ret); |
| 7023 | +char *support_format_dns_packet (const unsigned char *buffer, size_t length); |
| 7024 | +char *support_format_herrno (int); |
| 7025 | +char *support_format_hostent (struct hostent *); |
| 7026 | +char *support_format_netent (struct netent *); |
| 7027 | + |
| 7028 | +__END_DECLS |
| 7029 | + |
| 7030 | +#endif /* SUPPORT_FORMAT_NSS_H */ |
| 7031 | diff --git a/support/ignore_stderr.c b/support/ignore_stderr.c |
| 7032 | new file mode 100644 |
| 7033 | index 0000000000..7b77a2cd56 |
| 7034 | --- /dev/null |
| 7035 | +++ b/support/ignore_stderr.c |
| 7036 | @@ -0,0 +1,38 @@ |
| 7037 | +/* Avoid all the buffer overflow messages on stderr. |
| 7038 | + Copyright (C) 2015-2017 Free Software Foundation, Inc. |
| 7039 | + This file is part of the GNU C Library. |
| 7040 | + |
| 7041 | + The GNU C Library is free software; you can redistribute it and/or |
| 7042 | + modify it under the terms of the GNU Lesser General Public |
| 7043 | + License as published by the Free Software Foundation; either |
| 7044 | + version 2.1 of the License, or (at your option) any later version. |
| 7045 | + |
| 7046 | + The GNU C Library is distributed in the hope that it will be useful, |
| 7047 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 7048 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 7049 | + Lesser General Public License for more details. |
| 7050 | + |
| 7051 | + You should have received a copy of the GNU Lesser General Public |
| 7052 | + License along with the GNU C Library; if not, see |
| 7053 | + <http://www.gnu.org/licenses/>. */ |
| 7054 | + |
| 7055 | +#include <support/support.h> |
| 7056 | + |
| 7057 | +#include <fcntl.h> |
| 7058 | +#include <paths.h> |
| 7059 | +#include <stdlib.h> |
| 7060 | +#include <unistd.h> |
| 7061 | + |
| 7062 | +void |
| 7063 | +ignore_stderr (void) |
| 7064 | +{ |
| 7065 | + int fd = open (_PATH_DEVNULL, O_WRONLY); |
| 7066 | + if (fd == -1) |
| 7067 | + close (STDERR_FILENO); |
| 7068 | + else |
| 7069 | + { |
| 7070 | + dup2 (fd, STDERR_FILENO); |
| 7071 | + close (fd); |
| 7072 | + } |
| 7073 | + setenv ("LIBC_FATAL_STDERR_", "1", 1); |
| 7074 | +} |
| 7075 | diff --git a/support/namespace.h b/support/namespace.h |
| 7076 | new file mode 100644 |
| 7077 | index 0000000000..e1ccaa1ef0 |
| 7078 | --- /dev/null |
| 7079 | +++ b/support/namespace.h |
| 7080 | @@ -0,0 +1,65 @@ |
| 7081 | +/* Entering namespaces for test case isolation. |
| 7082 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 7083 | + This file is part of the GNU C Library. |
| 7084 | + |
| 7085 | + The GNU C Library is free software; you can redistribute it and/or |
| 7086 | + modify it under the terms of the GNU Lesser General Public |
| 7087 | + License as published by the Free Software Foundation; either |
| 7088 | + version 2.1 of the License, or (at your option) any later version. |
| 7089 | + |
| 7090 | + The GNU C Library is distributed in the hope that it will be useful, |
| 7091 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 7092 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 7093 | + Lesser General Public License for more details. |
| 7094 | + |
| 7095 | + You should have received a copy of the GNU Lesser General Public |
| 7096 | + License along with the GNU C Library; if not, see |
| 7097 | + <http://www.gnu.org/licenses/>. */ |
| 7098 | + |
| 7099 | +#ifndef SUPPORT_NAMESPACE_H |
| 7100 | +#define SUPPORT_NAMESPACE_H |
| 7101 | + |
| 7102 | +#include <stdbool.h> |
| 7103 | +#include <sys/cdefs.h> |
| 7104 | + |
| 7105 | +__BEGIN_DECLS |
| 7106 | + |
| 7107 | +/* Attempts to become root (or acquire root-like privileges), possibly |
| 7108 | + with the help of user namespaces. Return true if (restricted) root |
| 7109 | + privileges could be attained in some way. Print diagnostics to |
| 7110 | + standard output. |
| 7111 | + |
| 7112 | + Note that this function generally has to be called before a process |
| 7113 | + becomes multi-threaded, otherwise it may fail with insufficient |
| 7114 | + privileges on systems which would support this operation for |
| 7115 | + single-threaded processes. */ |
| 7116 | +bool support_become_root (void); |
| 7117 | + |
| 7118 | +/* Return true if this process can perform a chroot operation. In |
| 7119 | + general, this is only possible if support_become_root has been |
| 7120 | + called. Note that the actual test is performed in a subprocess, |
| 7121 | + after fork, so that the file system root of the original process is |
| 7122 | + not changed. */ |
| 7123 | +bool support_can_chroot (void); |
| 7124 | + |
| 7125 | +/* Enter a network namespace (and a UTS namespace if possible) and |
| 7126 | + configure the loopback interface. Return true if a network |
| 7127 | + namespace could be created. Print diagnostics to standard output. |
| 7128 | + If a network namespace could be created, but networking in it could |
| 7129 | + not be configured, terminate the process. It is recommended to |
| 7130 | + call support_become_root before this function so that the process |
| 7131 | + has sufficient privileges. */ |
| 7132 | +bool support_enter_network_namespace (void); |
| 7133 | + |
| 7134 | +/* Return true if support_enter_network_namespace managed to enter a |
| 7135 | + UTS namespace. */ |
| 7136 | +bool support_in_uts_namespace (void); |
| 7137 | + |
| 7138 | +/* Invoke CALLBACK (CLOSURE) in a subprocess created using fork. |
| 7139 | + Terminate the calling process if the subprocess exits with a |
| 7140 | + non-zero exit status. */ |
| 7141 | +void support_isolate_in_subprocess (void (*callback) (void *), void *closure); |
| 7142 | + |
| 7143 | +__END_DECLS |
| 7144 | + |
| 7145 | +#endif |
| 7146 | diff --git a/sysdeps/sparc/sparc64/fpu/s_fdimf.S b/support/oom_error.c |
| 7147 | similarity index 69% |
| 7148 | rename from sysdeps/sparc/sparc64/fpu/s_fdimf.S |
| 7149 | rename to support/oom_error.c |
| 7150 | index 356c23c4e3..7816978273 100644 |
| 7151 | --- a/sysdeps/sparc/sparc64/fpu/s_fdimf.S |
| 7152 | +++ b/support/oom_error.c |
| 7153 | @@ -1,7 +1,6 @@ |
| 7154 | -/* Compute positive difference, sparc 64-bit. |
| 7155 | - Copyright (C) 2013-2016 Free Software Foundation, Inc. |
| 7156 | +/* Reporting out-of-memory errors. |
| 7157 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 7158 | This file is part of the GNU C Library. |
| 7159 | - Contributed by David S. Miller <davem@davemloft.net>. |
| 7160 | |
| 7161 | The GNU C Library is free software; you can redistribute it and/or |
| 7162 | modify it under the terms of the GNU Lesser General Public |
| 7163 | @@ -17,15 +16,14 @@ |
| 7164 | License along with the GNU C Library; if not, see |
| 7165 | <http://www.gnu.org/licenses/>. */ |
| 7166 | |
| 7167 | -#include <sysdep.h> |
| 7168 | +#include <support/support.h> |
| 7169 | |
| 7170 | -ENTRY(__fdimf) |
| 7171 | - fcmps %f1, %f3 |
| 7172 | - fbug 1f |
| 7173 | - nop |
| 7174 | - fzeros %f1 |
| 7175 | - fnegs %f1, %f3 |
| 7176 | -1: retl |
| 7177 | - fsubs %f1, %f3, %f0 |
| 7178 | -END(__fdimf) |
| 7179 | -weak_alias (__fdimf, fdimf) |
| 7180 | +#include <stdio.h> |
| 7181 | +#include <stdlib.h> |
| 7182 | + |
| 7183 | +void |
| 7184 | +oom_error (const char *function, size_t size) |
| 7185 | +{ |
| 7186 | + printf ("%s: unable to allocate %zu bytes: %m\n", function, size); |
| 7187 | + exit (1); |
| 7188 | +} |
| 7189 | diff --git a/support/resolv_test.c b/support/resolv_test.c |
| 7190 | new file mode 100644 |
| 7191 | index 0000000000..050cd7154b |
| 7192 | --- /dev/null |
| 7193 | +++ b/support/resolv_test.c |
| 7194 | @@ -0,0 +1,1202 @@ |
| 7195 | +/* DNS test framework and libresolv redirection. |
| 7196 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 7197 | + This file is part of the GNU C Library. |
| 7198 | + |
| 7199 | + The GNU C Library is free software; you can redistribute it and/or |
| 7200 | + modify it under the terms of the GNU Lesser General Public |
| 7201 | + License as published by the Free Software Foundation; either |
| 7202 | + version 2.1 of the License, or (at your option) any later version. |
| 7203 | + |
| 7204 | + The GNU C Library is distributed in the hope that it will be useful, |
| 7205 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 7206 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 7207 | + Lesser General Public License for more details. |
| 7208 | + |
| 7209 | + You should have received a copy of the GNU Lesser General Public |
| 7210 | + License along with the GNU C Library; if not, see |
| 7211 | + <http://www.gnu.org/licenses/>. */ |
| 7212 | + |
| 7213 | +#include <support/resolv_test.h> |
| 7214 | + |
| 7215 | +#include <arpa/inet.h> |
| 7216 | +#include <errno.h> |
| 7217 | +#include <fcntl.h> |
| 7218 | +#include <nss.h> |
| 7219 | +#include <resolv.h> |
| 7220 | +#include <search.h> |
| 7221 | +#include <stdlib.h> |
| 7222 | +#include <string.h> |
| 7223 | +#include <support/check.h> |
| 7224 | +#include <support/namespace.h> |
| 7225 | +#include <support/support.h> |
| 7226 | +#include <support/test-driver.h> |
| 7227 | +#include <support/xsocket.h> |
| 7228 | +#include <support/xthread.h> |
| 7229 | +#include <support/xunistd.h> |
| 7230 | +#include <sys/uio.h> |
| 7231 | +#include <unistd.h> |
| 7232 | + |
| 7233 | +/* Response builder. */ |
| 7234 | + |
| 7235 | +enum |
| 7236 | + { |
| 7237 | + max_response_length = 65536 |
| 7238 | + }; |
| 7239 | + |
| 7240 | +/* List of pointers to be freed. The hash table implementation |
| 7241 | + (struct hsearch_data) does not provide a way to deallocate all |
| 7242 | + objects, so this approach is used to avoid memory leaks. */ |
| 7243 | +struct to_be_freed |
| 7244 | +{ |
| 7245 | + struct to_be_freed *next; |
| 7246 | + void *ptr; |
| 7247 | +}; |
| 7248 | + |
| 7249 | +struct resolv_response_builder |
| 7250 | +{ |
| 7251 | + const unsigned char *query_buffer; |
| 7252 | + size_t query_length; |
| 7253 | + |
| 7254 | + size_t offset; /* Bytes written so far in buffer. */ |
| 7255 | + ns_sect section; /* Current section in the DNS packet. */ |
| 7256 | + unsigned int truncate_bytes; /* Bytes to remove at end of response. */ |
| 7257 | + bool drop; /* Discard generated response. */ |
| 7258 | + bool close; /* Close TCP client connection. */ |
| 7259 | + |
| 7260 | + /* Offset of the two-byte RDATA length field in the currently |
| 7261 | + written RDATA sub-structure. 0 if no RDATA is being written. */ |
| 7262 | + size_t current_rdata_offset; |
| 7263 | + |
| 7264 | + /* Hash table for locating targets for label compression. */ |
| 7265 | + struct hsearch_data compression_offsets; |
| 7266 | + /* List of pointers which need to be freed. Used for domain names |
| 7267 | + involved in label compression. */ |
| 7268 | + struct to_be_freed *to_be_freed; |
| 7269 | + |
| 7270 | + /* Must be last. Not zeroed for performance reasons. */ |
| 7271 | + unsigned char buffer[max_response_length]; |
| 7272 | +}; |
| 7273 | + |
| 7274 | +/* Response builder. */ |
| 7275 | + |
| 7276 | +/* Add a pointer to the list of pointers to be freed when B is |
| 7277 | + deallocated. */ |
| 7278 | +static void |
| 7279 | +response_push_pointer_to_free (struct resolv_response_builder *b, void *ptr) |
| 7280 | +{ |
| 7281 | + if (ptr == NULL) |
| 7282 | + return; |
| 7283 | + struct to_be_freed *e = xmalloc (sizeof (*e)); |
| 7284 | + *e = (struct to_be_freed) {b->to_be_freed, ptr}; |
| 7285 | + b->to_be_freed = e; |
| 7286 | +} |
| 7287 | + |
| 7288 | +void |
| 7289 | +resolv_response_init (struct resolv_response_builder *b, |
| 7290 | + struct resolv_response_flags flags) |
| 7291 | +{ |
| 7292 | + if (b->offset > 0) |
| 7293 | + FAIL_EXIT1 ("response_init: called at offset %zu", b->offset); |
| 7294 | + if (b->query_length < 12) |
| 7295 | + FAIL_EXIT1 ("response_init called for a query of size %zu", |
| 7296 | + b->query_length); |
| 7297 | + if (flags.rcode > 15) |
| 7298 | + FAIL_EXIT1 ("response_init: invalid RCODE %u", flags.rcode); |
| 7299 | + |
| 7300 | + /* Copy the transaction ID. */ |
| 7301 | + b->buffer[0] = b->query_buffer[0]; |
| 7302 | + b->buffer[1] = b->query_buffer[1]; |
| 7303 | + |
| 7304 | + /* Initialize the flags. */ |
| 7305 | + b->buffer[2] = 0x80; /* Mark as response. */ |
| 7306 | + b->buffer[2] |= b->query_buffer[2] & 0x01; /* Copy the RD bit. */ |
| 7307 | + if (flags.tc) |
| 7308 | + b->buffer[2] |= 0x02; |
| 7309 | + b->buffer[3] = 0x80 | flags.rcode; /* Always set RA. */ |
| 7310 | + |
| 7311 | + /* Fill in the initial section count values. */ |
| 7312 | + b->buffer[4] = flags.qdcount >> 8; |
| 7313 | + b->buffer[5] = flags.qdcount; |
| 7314 | + b->buffer[6] = flags.ancount >> 8; |
| 7315 | + b->buffer[7] = flags.ancount; |
| 7316 | + b->buffer[8] = flags.nscount >> 8; |
| 7317 | + b->buffer[9] = flags.nscount; |
| 7318 | + b->buffer[10] = flags.adcount >> 8; |
| 7319 | + b->buffer[11] = flags.adcount; |
| 7320 | + |
| 7321 | + b->offset = 12; |
| 7322 | +} |
| 7323 | + |
| 7324 | +void |
| 7325 | +resolv_response_section (struct resolv_response_builder *b, ns_sect section) |
| 7326 | +{ |
| 7327 | + if (b->offset == 0) |
| 7328 | + FAIL_EXIT1 ("resolv_response_section: response_init not called before"); |
| 7329 | + if (section < b->section) |
| 7330 | + FAIL_EXIT1 ("resolv_response_section: cannot go back to previous section"); |
| 7331 | + b->section = section; |
| 7332 | +} |
| 7333 | + |
| 7334 | +/* Add a single byte to B. */ |
| 7335 | +static inline void |
| 7336 | +response_add_byte (struct resolv_response_builder *b, unsigned char ch) |
| 7337 | +{ |
| 7338 | + if (b->offset == max_response_length) |
| 7339 | + FAIL_EXIT1 ("DNS response exceeds 64 KiB limit"); |
| 7340 | + b->buffer[b->offset] = ch; |
| 7341 | + ++b->offset; |
| 7342 | +} |
| 7343 | + |
| 7344 | +/* Add a 16-bit word VAL to B, in big-endian format. */ |
| 7345 | +static void |
| 7346 | +response_add_16 (struct resolv_response_builder *b, uint16_t val) |
| 7347 | +{ |
| 7348 | + response_add_byte (b, val >> 8); |
| 7349 | + response_add_byte (b, val); |
| 7350 | +} |
| 7351 | + |
| 7352 | +/* Increment the pers-section record counter in the packet header. */ |
| 7353 | +static void |
| 7354 | +response_count_increment (struct resolv_response_builder *b) |
| 7355 | +{ |
| 7356 | + unsigned int offset = b->section; |
| 7357 | + offset = 4 + 2 * offset; |
| 7358 | + ++b->buffer[offset + 1]; |
| 7359 | + if (b->buffer[offset + 1] == 0) |
| 7360 | + { |
| 7361 | + /* Carry. */ |
| 7362 | + ++b->buffer[offset]; |
| 7363 | + if (b->buffer[offset] == 0) |
| 7364 | + /* Overflow. */ |
| 7365 | + FAIL_EXIT1 ("too many records in section"); |
| 7366 | + } |
| 7367 | +} |
| 7368 | + |
| 7369 | +void |
| 7370 | +resolv_response_add_question (struct resolv_response_builder *b, |
| 7371 | + const char *name, uint16_t class, uint16_t type) |
| 7372 | +{ |
| 7373 | + if (b->offset == 0) |
| 7374 | + FAIL_EXIT1 ("resolv_response_add_question: " |
| 7375 | + "resolv_response_init not called"); |
| 7376 | + if (b->section != ns_s_qd) |
| 7377 | + FAIL_EXIT1 ("resolv_response_add_question: " |
| 7378 | + "must be called in the question section"); |
| 7379 | + |
| 7380 | + resolv_response_add_name (b, name); |
| 7381 | + response_add_16 (b, type); |
| 7382 | + response_add_16 (b, class); |
| 7383 | + |
| 7384 | + response_count_increment (b); |
| 7385 | +} |
| 7386 | + |
| 7387 | +void |
| 7388 | +resolv_response_add_name (struct resolv_response_builder *b, |
| 7389 | + const char *const origname) |
| 7390 | +{ |
| 7391 | + /* Normalized name. */ |
| 7392 | + char *name; |
| 7393 | + /* Normalized name with case preserved. */ |
| 7394 | + char *name_case; |
| 7395 | + { |
| 7396 | + size_t namelen = strlen (origname); |
| 7397 | + /* Remove trailing dots. FIXME: Handle trailing quoted dots. */ |
| 7398 | + while (namelen > 0 && origname[namelen - 1] == '.') |
| 7399 | + --namelen; |
| 7400 | + name = xmalloc (namelen + 1); |
| 7401 | + name_case = xmalloc (namelen + 1); |
| 7402 | + /* Copy and convert to lowercase. FIXME: This needs to normalize |
| 7403 | + escaping as well. */ |
| 7404 | + for (size_t i = 0; i < namelen; ++i) |
| 7405 | + { |
| 7406 | + char ch = origname[i]; |
| 7407 | + name_case[i] = ch; |
| 7408 | + if ('A' <= ch && ch <= 'Z') |
| 7409 | + ch = ch - 'A' + 'a'; |
| 7410 | + name[i] = ch; |
| 7411 | + } |
| 7412 | + name[namelen] = 0; |
| 7413 | + name_case[namelen] = 0; |
| 7414 | + } |
| 7415 | + char *name_start = name; |
| 7416 | + char *name_case_start = name_case; |
| 7417 | + |
| 7418 | + bool compression = false; |
| 7419 | + while (*name) |
| 7420 | + { |
| 7421 | + /* Search for a previous name we can reference. */ |
| 7422 | + ENTRY new_entry = |
| 7423 | + { |
| 7424 | + .key = name, |
| 7425 | + .data = (void *) (uintptr_t) b->offset, |
| 7426 | + }; |
| 7427 | + |
| 7428 | + /* If the label can be a compression target because it is at a |
| 7429 | + reachable offset, add it to the hash table. */ |
| 7430 | + ACTION action; |
| 7431 | + if (b->offset < (1 << 12)) |
| 7432 | + action = ENTER; |
| 7433 | + else |
| 7434 | + action = FIND; |
| 7435 | + |
| 7436 | + /* Search for known compression offsets in the hash table. */ |
| 7437 | + ENTRY *e; |
| 7438 | + if (hsearch_r (new_entry, action, &e, &b->compression_offsets) == 0) |
| 7439 | + { |
| 7440 | + if (action == FIND && errno == ESRCH) |
| 7441 | + /* Fall through. */ |
| 7442 | + e = NULL; |
| 7443 | + else |
| 7444 | + FAIL_EXIT1 ("hsearch_r failure in name compression: %m"); |
| 7445 | + } |
| 7446 | + |
| 7447 | + /* The name is known. Reference the previous location. */ |
| 7448 | + if (e != NULL && e->data != new_entry.data) |
| 7449 | + { |
| 7450 | + size_t old_offset = (uintptr_t) e->data; |
| 7451 | + response_add_byte (b, 0xC0 | (old_offset >> 8)); |
| 7452 | + response_add_byte (b, old_offset); |
| 7453 | + compression = true; |
| 7454 | + break; |
| 7455 | + } |
| 7456 | + |
| 7457 | + /* The name does not exist yet. Write one label. First, add |
| 7458 | + room for the label length. */ |
| 7459 | + size_t buffer_label_offset = b->offset; |
| 7460 | + response_add_byte (b, 0); |
| 7461 | + |
| 7462 | + /* Copy the label. */ |
| 7463 | + while (true) |
| 7464 | + { |
| 7465 | + char ch = *name_case; |
| 7466 | + if (ch == '\0') |
| 7467 | + break; |
| 7468 | + ++name; |
| 7469 | + ++name_case; |
| 7470 | + if (ch == '.') |
| 7471 | + break; |
| 7472 | + /* FIXME: Handle escaping. */ |
| 7473 | + response_add_byte (b, ch); |
| 7474 | + } |
| 7475 | + |
| 7476 | + /* Patch in the label length. */ |
| 7477 | + size_t label_length = b->offset - buffer_label_offset - 1; |
| 7478 | + if (label_length == 0) |
| 7479 | + FAIL_EXIT1 ("empty label in name compression: %s", origname); |
| 7480 | + if (label_length > 63) |
| 7481 | + FAIL_EXIT1 ("label too long in name compression: %s", origname); |
| 7482 | + b->buffer[buffer_label_offset] = label_length; |
| 7483 | + |
| 7484 | + /* Continue with the tail of the name and the next label. */ |
| 7485 | + } |
| 7486 | + |
| 7487 | + if (compression) |
| 7488 | + { |
| 7489 | + /* If we found an immediate match for the name, we have not put |
| 7490 | + it into the hash table, and can free it immediately. */ |
| 7491 | + if (name == name_start) |
| 7492 | + free (name_start); |
| 7493 | + else |
| 7494 | + response_push_pointer_to_free (b, name_start); |
| 7495 | + } |
| 7496 | + else |
| 7497 | + { |
| 7498 | + /* Terminate the sequence of labels. With compression, this is |
| 7499 | + implicit in the compression reference. */ |
| 7500 | + response_add_byte (b, 0); |
| 7501 | + response_push_pointer_to_free (b, name_start); |
| 7502 | + } |
| 7503 | + |
| 7504 | + free (name_case_start); |
| 7505 | +} |
| 7506 | + |
| 7507 | +void |
| 7508 | +resolv_response_open_record (struct resolv_response_builder *b, |
| 7509 | + const char *name, |
| 7510 | + uint16_t class, uint16_t type, uint32_t ttl) |
| 7511 | +{ |
| 7512 | + if (b->section == ns_s_qd) |
| 7513 | + FAIL_EXIT1 ("resolv_response_open_record called in question section"); |
| 7514 | + if (b->current_rdata_offset != 0) |
| 7515 | + FAIL_EXIT1 ("resolv_response_open_record called with open record"); |
| 7516 | + |
| 7517 | + resolv_response_add_name (b, name); |
| 7518 | + response_add_16 (b, type); |
| 7519 | + response_add_16 (b, class); |
| 7520 | + response_add_16 (b, ttl >> 16); |
| 7521 | + response_add_16 (b, ttl); |
| 7522 | + |
| 7523 | + b->current_rdata_offset = b->offset; |
| 7524 | + /* Add room for the RDATA length. */ |
| 7525 | + response_add_16 (b, 0); |
| 7526 | +} |
| 7527 | + |
| 7528 | + |
| 7529 | +void |
| 7530 | +resolv_response_close_record (struct resolv_response_builder *b) |
| 7531 | +{ |
| 7532 | + size_t rdata_offset = b->current_rdata_offset; |
| 7533 | + if (rdata_offset == 0) |
| 7534 | + FAIL_EXIT1 ("response_close_record called without open record"); |
| 7535 | + size_t rdata_length = b->offset - rdata_offset - 2; |
| 7536 | + if (rdata_length > 65535) |
| 7537 | + FAIL_EXIT1 ("RDATA length %zu exceeds limit", rdata_length); |
| 7538 | + b->buffer[rdata_offset] = rdata_length >> 8; |
| 7539 | + b->buffer[rdata_offset + 1] = rdata_length; |
| 7540 | + response_count_increment (b); |
| 7541 | + b->current_rdata_offset = 0; |
| 7542 | +} |
| 7543 | + |
| 7544 | +void |
| 7545 | +resolv_response_add_data (struct resolv_response_builder *b, |
| 7546 | + const void *data, size_t length) |
| 7547 | +{ |
| 7548 | + size_t remaining = max_response_length - b->offset; |
| 7549 | + if (remaining < length) |
| 7550 | + FAIL_EXIT1 ("resolv_response_add_data: not enough room for %zu bytes", |
| 7551 | + length); |
| 7552 | + memcpy (b->buffer + b->offset, data, length); |
| 7553 | + b->offset += length; |
| 7554 | +} |
| 7555 | + |
| 7556 | +void |
| 7557 | +resolv_response_drop (struct resolv_response_builder *b) |
| 7558 | +{ |
| 7559 | + b->drop = true; |
| 7560 | +} |
| 7561 | + |
| 7562 | +void |
| 7563 | +resolv_response_close (struct resolv_response_builder *b) |
| 7564 | +{ |
| 7565 | + b->close = true; |
| 7566 | +} |
| 7567 | + |
| 7568 | +void |
| 7569 | +resolv_response_truncate_data (struct resolv_response_builder *b, size_t count) |
| 7570 | +{ |
| 7571 | + if (count > 65535) |
| 7572 | + FAIL_EXIT1 ("resolv_response_truncate_data: argument too large: %zu", |
| 7573 | + count); |
| 7574 | + b->truncate_bytes = count; |
| 7575 | +} |
| 7576 | + |
| 7577 | + |
| 7578 | +size_t |
| 7579 | +resolv_response_length (const struct resolv_response_builder *b) |
| 7580 | +{ |
| 7581 | + return b->offset; |
| 7582 | +} |
| 7583 | + |
| 7584 | +unsigned char * |
| 7585 | +resolv_response_buffer (const struct resolv_response_builder *b) |
| 7586 | +{ |
| 7587 | + unsigned char *result = xmalloc (b->offset); |
| 7588 | + memcpy (result, b->buffer, b->offset); |
| 7589 | + return result; |
| 7590 | +} |
| 7591 | + |
| 7592 | +static struct resolv_response_builder * |
| 7593 | +response_builder_allocate |
| 7594 | + (const unsigned char *query_buffer, size_t query_length) |
| 7595 | +{ |
| 7596 | + struct resolv_response_builder *b = xmalloc (sizeof (*b)); |
| 7597 | + memset (b, 0, offsetof (struct resolv_response_builder, buffer)); |
| 7598 | + b->query_buffer = query_buffer; |
| 7599 | + b->query_length = query_length; |
| 7600 | + TEST_VERIFY_EXIT (hcreate_r (10000, &b->compression_offsets) != 0); |
| 7601 | + return b; |
| 7602 | +} |
| 7603 | + |
| 7604 | +static void |
| 7605 | +response_builder_free (struct resolv_response_builder *b) |
| 7606 | +{ |
| 7607 | + struct to_be_freed *current = b->to_be_freed; |
| 7608 | + while (current != NULL) |
| 7609 | + { |
| 7610 | + struct to_be_freed *next = current->next; |
| 7611 | + free (current->ptr); |
| 7612 | + free (current); |
| 7613 | + current = next; |
| 7614 | + } |
| 7615 | + hdestroy_r (&b->compression_offsets); |
| 7616 | + free (b); |
| 7617 | +} |
| 7618 | + |
| 7619 | +/* DNS query processing. */ |
| 7620 | + |
| 7621 | +/* Data extracted from the question section of a DNS packet. */ |
| 7622 | +struct query_info |
| 7623 | +{ |
| 7624 | + char qname[MAXDNAME]; |
| 7625 | + uint16_t qclass; |
| 7626 | + uint16_t qtype; |
| 7627 | + struct resolv_edns_info edns; |
| 7628 | +}; |
| 7629 | + |
| 7630 | +/* Update *INFO from the specified DNS packet. */ |
| 7631 | +static void |
| 7632 | +parse_query (struct query_info *info, |
| 7633 | + const unsigned char *buffer, size_t length) |
| 7634 | +{ |
| 7635 | + HEADER hd; |
| 7636 | + _Static_assert (sizeof (hd) == 12, "DNS header size"); |
| 7637 | + if (length < sizeof (hd)) |
| 7638 | + FAIL_EXIT1 ("malformed DNS query: too short: %zu bytes", length); |
| 7639 | + memcpy (&hd, buffer, sizeof (hd)); |
| 7640 | + |
| 7641 | + if (ntohs (hd.qdcount) != 1) |
| 7642 | + FAIL_EXIT1 ("malformed DNS query: wrong question count: %d", |
| 7643 | + (int) ntohs (hd.qdcount)); |
| 7644 | + if (ntohs (hd.ancount) != 0) |
| 7645 | + FAIL_EXIT1 ("malformed DNS query: wrong answer count: %d", |
| 7646 | + (int) ntohs (hd.ancount)); |
| 7647 | + if (ntohs (hd.nscount) != 0) |
| 7648 | + FAIL_EXIT1 ("malformed DNS query: wrong authority count: %d", |
| 7649 | + (int) ntohs (hd.nscount)); |
| 7650 | + if (ntohs (hd.arcount) > 1) |
| 7651 | + FAIL_EXIT1 ("malformed DNS query: wrong additional count: %d", |
| 7652 | + (int) ntohs (hd.arcount)); |
| 7653 | + |
| 7654 | + int ret = dn_expand (buffer, buffer + length, buffer + sizeof (hd), |
| 7655 | + info->qname, sizeof (info->qname)); |
| 7656 | + if (ret < 0) |
| 7657 | + FAIL_EXIT1 ("malformed DNS query: cannot uncompress QNAME"); |
| 7658 | + |
| 7659 | + /* Obtain QTYPE and QCLASS. */ |
| 7660 | + size_t remaining = length - (12 + ret); |
| 7661 | + struct |
| 7662 | + { |
| 7663 | + uint16_t qtype; |
| 7664 | + uint16_t qclass; |
| 7665 | + } qtype_qclass; |
| 7666 | + if (remaining < sizeof (qtype_qclass)) |
| 7667 | + FAIL_EXIT1 ("malformed DNS query: " |
| 7668 | + "query lacks QCLASS/QTYPE, QNAME: %s", info->qname); |
| 7669 | + memcpy (&qtype_qclass, buffer + 12 + ret, sizeof (qtype_qclass)); |
| 7670 | + info->qclass = ntohs (qtype_qclass.qclass); |
| 7671 | + info->qtype = ntohs (qtype_qclass.qtype); |
| 7672 | + |
| 7673 | + memset (&info->edns, 0, sizeof (info->edns)); |
| 7674 | + if (ntohs (hd.arcount) > 0) |
| 7675 | + { |
| 7676 | + /* Parse EDNS record. */ |
| 7677 | + struct __attribute__ ((packed, aligned (1))) |
| 7678 | + { |
| 7679 | + uint8_t root; |
| 7680 | + uint16_t rtype; |
| 7681 | + uint16_t payload; |
| 7682 | + uint8_t edns_extended_rcode; |
| 7683 | + uint8_t edns_version; |
| 7684 | + uint16_t flags; |
| 7685 | + uint16_t rdatalen; |
| 7686 | + } rr; |
| 7687 | + _Static_assert (sizeof (rr) == 11, "EDNS record size"); |
| 7688 | + |
| 7689 | + if (remaining < 4 + sizeof (rr)) |
| 7690 | + FAIL_EXIT1 ("mailformed DNS query: no room for EDNS record"); |
| 7691 | + memcpy (&rr, buffer + 12 + ret + 4, sizeof (rr)); |
| 7692 | + if (rr.root != 0) |
| 7693 | + FAIL_EXIT1 ("malformed DNS query: invalid OPT RNAME: %d\n", rr.root); |
| 7694 | + if (rr.rtype != htons (41)) |
| 7695 | + FAIL_EXIT1 ("malformed DNS query: invalid OPT type: %d\n", |
| 7696 | + ntohs (rr.rtype)); |
| 7697 | + info->edns.active = true; |
| 7698 | + info->edns.extended_rcode = rr.edns_extended_rcode; |
| 7699 | + info->edns.version = rr.edns_version; |
| 7700 | + info->edns.flags = ntohs (rr.flags); |
| 7701 | + info->edns.payload_size = ntohs (rr.payload); |
| 7702 | + } |
| 7703 | +} |
| 7704 | + |
| 7705 | + |
| 7706 | +/* Main testing framework. */ |
| 7707 | + |
| 7708 | +/* Per-server information. One struct is allocated for each test |
| 7709 | + server. */ |
| 7710 | +struct resolv_test_server |
| 7711 | +{ |
| 7712 | + /* Local address of the server. UDP and TCP use the same port. */ |
| 7713 | + struct sockaddr_in address; |
| 7714 | + |
| 7715 | + /* File descriptor of the UDP server, or -1 if this server is |
| 7716 | + disabled. */ |
| 7717 | + int socket_udp; |
| 7718 | + |
| 7719 | + /* File descriptor of the TCP server, or -1 if this server is |
| 7720 | + disabled. */ |
| 7721 | + int socket_tcp; |
| 7722 | + |
| 7723 | + /* Counter of the number of responses processed so far. */ |
| 7724 | + size_t response_number; |
| 7725 | + |
| 7726 | + /* Thread handles for the server threads (if not disabled in the |
| 7727 | + configuration). */ |
| 7728 | + pthread_t thread_udp; |
| 7729 | + pthread_t thread_tcp; |
| 7730 | +}; |
| 7731 | + |
| 7732 | +/* Main struct for keeping track of libresolv redirection and |
| 7733 | + testing. */ |
| 7734 | +struct resolv_test |
| 7735 | +{ |
| 7736 | + /* After initialization, any access to the struct must be performed |
| 7737 | + while this lock is acquired. */ |
| 7738 | + pthread_mutex_t lock; |
| 7739 | + |
| 7740 | + /* Data for each test server. */ |
| 7741 | + struct resolv_test_server servers[resolv_max_test_servers]; |
| 7742 | + |
| 7743 | + /* Used if config.single_thread_udp is true. */ |
| 7744 | + pthread_t thread_udp_single; |
| 7745 | + |
| 7746 | + struct resolv_redirect_config config; |
| 7747 | + bool termination_requested; |
| 7748 | +}; |
| 7749 | + |
| 7750 | +/* Function implementing a server thread. */ |
| 7751 | +typedef void (*thread_callback) (struct resolv_test *, int server_index); |
| 7752 | + |
| 7753 | +/* Storage for thread-specific data, for passing to the |
| 7754 | + thread_callback function. */ |
| 7755 | +struct thread_closure |
| 7756 | +{ |
| 7757 | + struct resolv_test *obj; /* Current test object. */ |
| 7758 | + thread_callback callback; /* Function to call. */ |
| 7759 | + int server_index; /* Index of the implemented server. */ |
| 7760 | +}; |
| 7761 | + |
| 7762 | +/* Wrap response_callback as a function which can be passed to |
| 7763 | + pthread_create. */ |
| 7764 | +static void * |
| 7765 | +thread_callback_wrapper (void *arg) |
| 7766 | +{ |
| 7767 | + struct thread_closure *closure = arg; |
| 7768 | + closure->callback (closure->obj, closure->server_index); |
| 7769 | + free (closure); |
| 7770 | + return NULL; |
| 7771 | +} |
| 7772 | + |
| 7773 | +/* Start a server thread for the specified SERVER_INDEX, implemented |
| 7774 | + by CALLBACK. */ |
| 7775 | +static pthread_t |
| 7776 | +start_server_thread (struct resolv_test *obj, int server_index, |
| 7777 | + thread_callback callback) |
| 7778 | +{ |
| 7779 | + struct thread_closure *closure = xmalloc (sizeof (*closure)); |
| 7780 | + *closure = (struct thread_closure) |
| 7781 | + { |
| 7782 | + .obj = obj, |
| 7783 | + .callback = callback, |
| 7784 | + .server_index = server_index, |
| 7785 | + }; |
| 7786 | + return xpthread_create (NULL, thread_callback_wrapper, closure); |
| 7787 | +} |
| 7788 | + |
| 7789 | +/* Process one UDP query. Return false if a termination requested has |
| 7790 | + been detected. */ |
| 7791 | +static bool |
| 7792 | +server_thread_udp_process_one (struct resolv_test *obj, int server_index) |
| 7793 | +{ |
| 7794 | + unsigned char query[512]; |
| 7795 | + struct sockaddr_storage peer; |
| 7796 | + socklen_t peerlen = sizeof (peer); |
| 7797 | + size_t length = xrecvfrom (obj->servers[server_index].socket_udp, |
| 7798 | + query, sizeof (query), 0, |
| 7799 | + (struct sockaddr *) &peer, &peerlen); |
| 7800 | + /* Check for termination. */ |
| 7801 | + { |
| 7802 | + bool termination_requested; |
| 7803 | + xpthread_mutex_lock (&obj->lock); |
| 7804 | + termination_requested = obj->termination_requested; |
| 7805 | + xpthread_mutex_unlock (&obj->lock); |
| 7806 | + if (termination_requested) |
| 7807 | + return false; |
| 7808 | + } |
| 7809 | + |
| 7810 | + |
| 7811 | + struct query_info qinfo; |
| 7812 | + parse_query (&qinfo, query, length); |
| 7813 | + if (test_verbose > 0) |
| 7814 | + { |
| 7815 | + if (test_verbose > 1) |
| 7816 | + printf ("info: UDP server %d: incoming query:" |
| 7817 | + " %zd bytes, %s/%u/%u, tnxid=0x%02x%02x\n", |
| 7818 | + server_index, length, qinfo.qname, qinfo.qclass, qinfo.qtype, |
| 7819 | + query[0], query[1]); |
| 7820 | + else |
| 7821 | + printf ("info: UDP server %d: incoming query:" |
| 7822 | + " %zd bytes, %s/%u/%u\n", |
| 7823 | + server_index, length, qinfo.qname, qinfo.qclass, qinfo.qtype); |
| 7824 | + } |
| 7825 | + |
| 7826 | + struct resolv_response_context ctx = |
| 7827 | + { |
| 7828 | + .query_buffer = query, |
| 7829 | + .query_length = length, |
| 7830 | + .server_index = server_index, |
| 7831 | + .tcp = false, |
| 7832 | + .edns = qinfo.edns, |
| 7833 | + }; |
| 7834 | + struct resolv_response_builder *b = response_builder_allocate (query, length); |
| 7835 | + obj->config.response_callback |
| 7836 | + (&ctx, b, qinfo.qname, qinfo.qclass, qinfo.qtype); |
| 7837 | + |
| 7838 | + if (b->drop) |
| 7839 | + { |
| 7840 | + if (test_verbose) |
| 7841 | + printf ("info: UDP server %d: dropping response to %s/%u/%u\n", |
| 7842 | + server_index, qinfo.qname, qinfo.qclass, qinfo.qtype); |
| 7843 | + } |
| 7844 | + else |
| 7845 | + { |
| 7846 | + if (test_verbose) |
| 7847 | + { |
| 7848 | + if (b->offset >= 12) |
| 7849 | + printf ("info: UDP server %d: sending response:" |
| 7850 | + " %zu bytes, RCODE %d (for %s/%u/%u)\n", |
| 7851 | + server_index, b->offset, b->buffer[3] & 0x0f, |
| 7852 | + qinfo.qname, qinfo.qclass, qinfo.qtype); |
| 7853 | + else |
| 7854 | + printf ("info: UDP server %d: sending response: %zu bytes" |
| 7855 | + " (for %s/%u/%u)\n", |
| 7856 | + server_index, b->offset, |
| 7857 | + qinfo.qname, qinfo.qclass, qinfo.qtype); |
| 7858 | + if (b->truncate_bytes > 0) |
| 7859 | + printf ("info: truncated by %u bytes\n", b->truncate_bytes); |
| 7860 | + } |
| 7861 | + size_t to_send = b->offset; |
| 7862 | + if (to_send < b->truncate_bytes) |
| 7863 | + to_send = 0; |
| 7864 | + else |
| 7865 | + to_send -= b->truncate_bytes; |
| 7866 | + |
| 7867 | + /* Ignore most errors here because the other end may have closed |
| 7868 | + the socket. */ |
| 7869 | + if (sendto (obj->servers[server_index].socket_udp, |
| 7870 | + b->buffer, to_send, 0, |
| 7871 | + (struct sockaddr *) &peer, peerlen) < 0) |
| 7872 | + TEST_VERIFY_EXIT (errno != EBADF); |
| 7873 | + } |
| 7874 | + response_builder_free (b); |
| 7875 | + return true; |
| 7876 | +} |
| 7877 | + |
| 7878 | +/* UDP thread_callback function. Variant for one thread per |
| 7879 | + server. */ |
| 7880 | +static void |
| 7881 | +server_thread_udp (struct resolv_test *obj, int server_index) |
| 7882 | +{ |
| 7883 | + while (server_thread_udp_process_one (obj, server_index)) |
| 7884 | + ; |
| 7885 | +} |
| 7886 | + |
| 7887 | +/* Single-threaded UDP processing function, for the single_thread_udp |
| 7888 | + case. */ |
| 7889 | +static void * |
| 7890 | +server_thread_udp_single (void *closure) |
| 7891 | +{ |
| 7892 | + struct resolv_test *obj = closure; |
| 7893 | + |
| 7894 | + struct pollfd fds[resolv_max_test_servers]; |
| 7895 | + for (int server_index = 0; server_index < resolv_max_test_servers; |
| 7896 | + ++server_index) |
| 7897 | + if (obj->config.servers[server_index].disable_udp) |
| 7898 | + fds[server_index] = (struct pollfd) {.fd = -1}; |
| 7899 | + else |
| 7900 | + { |
| 7901 | + fds[server_index] = (struct pollfd) |
| 7902 | + { |
| 7903 | + .fd = obj->servers[server_index].socket_udp, |
| 7904 | + .events = POLLIN |
| 7905 | + }; |
| 7906 | + |
| 7907 | + /* Make the socket non-blocking. */ |
| 7908 | + int flags = fcntl (obj->servers[server_index].socket_udp, F_GETFL, 0); |
| 7909 | + if (flags < 0) |
| 7910 | + FAIL_EXIT1 ("fcntl (F_GETFL): %m"); |
| 7911 | + flags |= O_NONBLOCK; |
| 7912 | + if (fcntl (obj->servers[server_index].socket_udp, F_SETFL, flags) < 0) |
| 7913 | + FAIL_EXIT1 ("fcntl (F_SETFL): %m"); |
| 7914 | + } |
| 7915 | + |
| 7916 | + while (true) |
| 7917 | + { |
| 7918 | + xpoll (fds, resolv_max_test_servers, -1); |
| 7919 | + for (int server_index = 0; server_index < resolv_max_test_servers; |
| 7920 | + ++server_index) |
| 7921 | + if (fds[server_index].revents != 0) |
| 7922 | + { |
| 7923 | + if (!server_thread_udp_process_one (obj, server_index)) |
| 7924 | + goto out; |
| 7925 | + fds[server_index].revents = 0; |
| 7926 | + } |
| 7927 | + } |
| 7928 | + |
| 7929 | + out: |
| 7930 | + return NULL; |
| 7931 | +} |
| 7932 | + |
| 7933 | +/* Start the single UDP handler thread (for the single_thread_udp |
| 7934 | + case). */ |
| 7935 | +static void |
| 7936 | +start_server_thread_udp_single (struct resolv_test *obj) |
| 7937 | +{ |
| 7938 | + obj->thread_udp_single |
| 7939 | + = xpthread_create (NULL, server_thread_udp_single, obj); |
| 7940 | +} |
| 7941 | + |
| 7942 | +/* Data describing a TCP client connect. */ |
| 7943 | +struct tcp_thread_closure |
| 7944 | +{ |
| 7945 | + struct resolv_test *obj; |
| 7946 | + int server_index; |
| 7947 | + int client_socket; |
| 7948 | +}; |
| 7949 | + |
| 7950 | +/* Read a complete DNS query packet. If EOF_OK, an immediate |
| 7951 | + end-of-file condition is acceptable. */ |
| 7952 | +static bool |
| 7953 | +read_fully (int fd, void *buf, size_t len, bool eof_ok) |
| 7954 | +{ |
| 7955 | + const void *const end = buf + len; |
| 7956 | + while (buf < end) |
| 7957 | + { |
| 7958 | + ssize_t ret = read (fd, buf, end - buf); |
| 7959 | + if (ret == 0) |
| 7960 | + { |
| 7961 | + if (!eof_ok) |
| 7962 | + { |
| 7963 | + support_record_failure (); |
| 7964 | + printf ("error: unexpected EOF on TCP connection\n"); |
| 7965 | + } |
| 7966 | + return false; |
| 7967 | + } |
| 7968 | + else if (ret < 0) |
| 7969 | + { |
| 7970 | + if (!eof_ok || errno != ECONNRESET) |
| 7971 | + { |
| 7972 | + support_record_failure (); |
| 7973 | + printf ("error: TCP read: %m\n"); |
| 7974 | + } |
| 7975 | + return false; |
| 7976 | + } |
| 7977 | + buf += ret; |
| 7978 | + eof_ok = false; |
| 7979 | + } |
| 7980 | + return true; |
| 7981 | +} |
| 7982 | + |
| 7983 | +/* Write an array of iovecs. Terminate the process on failure. */ |
| 7984 | +static void |
| 7985 | +writev_fully (int fd, struct iovec *buffers, size_t count) |
| 7986 | +{ |
| 7987 | + while (count > 0) |
| 7988 | + { |
| 7989 | + /* Skip zero-length write requests. */ |
| 7990 | + if (buffers->iov_len == 0) |
| 7991 | + { |
| 7992 | + ++buffers; |
| 7993 | + --count; |
| 7994 | + continue; |
| 7995 | + } |
| 7996 | + /* Try to rewrite the remaing buffers. */ |
| 7997 | + ssize_t ret = writev (fd, buffers, count); |
| 7998 | + if (ret < 0) |
| 7999 | + FAIL_EXIT1 ("writev: %m"); |
| 8000 | + if (ret == 0) |
| 8001 | + FAIL_EXIT1 ("writev: invalid return value zero"); |
| 8002 | + /* Find the buffers that were successfully written. */ |
| 8003 | + while (ret > 0) |
| 8004 | + { |
| 8005 | + if (count == 0) |
| 8006 | + FAIL_EXIT1 ("internal writev consistency failure"); |
| 8007 | + /* Current buffer was partially written. */ |
| 8008 | + if (buffers->iov_len > (size_t) ret) |
| 8009 | + { |
| 8010 | + buffers->iov_base += ret; |
| 8011 | + buffers->iov_len -= ret; |
| 8012 | + ret = 0; |
| 8013 | + } |
| 8014 | + else |
| 8015 | + { |
| 8016 | + ret -= buffers->iov_len; |
| 8017 | + buffers->iov_len = 0; |
| 8018 | + ++buffers; |
| 8019 | + --count; |
| 8020 | + } |
| 8021 | + } |
| 8022 | + } |
| 8023 | +} |
| 8024 | + |
| 8025 | +/* Thread callback for handling a single established TCP connection to |
| 8026 | + a client. */ |
| 8027 | +static void * |
| 8028 | +server_thread_tcp_client (void *arg) |
| 8029 | +{ |
| 8030 | + struct tcp_thread_closure *closure = arg; |
| 8031 | + |
| 8032 | + while (true) |
| 8033 | + { |
| 8034 | + /* Read packet length. */ |
| 8035 | + uint16_t query_length; |
| 8036 | + if (!read_fully (closure->client_socket, |
| 8037 | + &query_length, sizeof (query_length), true)) |
| 8038 | + break; |
| 8039 | + query_length = ntohs (query_length); |
| 8040 | + |
| 8041 | + /* Read the packet. */ |
| 8042 | + unsigned char *query_buffer = xmalloc (query_length); |
| 8043 | + read_fully (closure->client_socket, query_buffer, query_length, false); |
| 8044 | + |
| 8045 | + struct query_info qinfo; |
| 8046 | + parse_query (&qinfo, query_buffer, query_length); |
| 8047 | + if (test_verbose > 0) |
| 8048 | + { |
| 8049 | + if (test_verbose > 1) |
| 8050 | + printf ("info: UDP server %d: incoming query:" |
| 8051 | + " %d bytes, %s/%u/%u, tnxid=0x%02x%02x\n", |
| 8052 | + closure->server_index, query_length, |
| 8053 | + qinfo.qname, qinfo.qclass, qinfo.qtype, |
| 8054 | + query_buffer[0], query_buffer[1]); |
| 8055 | + else |
| 8056 | + printf ("info: TCP server %d: incoming query:" |
| 8057 | + " %u bytes, %s/%u/%u\n", |
| 8058 | + closure->server_index, query_length, |
| 8059 | + qinfo.qname, qinfo.qclass, qinfo.qtype); |
| 8060 | + } |
| 8061 | + |
| 8062 | + struct resolv_response_context ctx = |
| 8063 | + { |
| 8064 | + .query_buffer = query_buffer, |
| 8065 | + .query_length = query_length, |
| 8066 | + .server_index = closure->server_index, |
| 8067 | + .tcp = true, |
| 8068 | + .edns = qinfo.edns, |
| 8069 | + }; |
| 8070 | + struct resolv_response_builder *b = response_builder_allocate |
| 8071 | + (query_buffer, query_length); |
| 8072 | + closure->obj->config.response_callback |
| 8073 | + (&ctx, b, qinfo.qname, qinfo.qclass, qinfo.qtype); |
| 8074 | + |
| 8075 | + if (b->drop) |
| 8076 | + { |
| 8077 | + if (test_verbose) |
| 8078 | + printf ("info: TCP server %d: dropping response to %s/%u/%u\n", |
| 8079 | + closure->server_index, |
| 8080 | + qinfo.qname, qinfo.qclass, qinfo.qtype); |
| 8081 | + } |
| 8082 | + else |
| 8083 | + { |
| 8084 | + if (test_verbose) |
| 8085 | + printf ("info: TCP server %d: sending response: %zu bytes" |
| 8086 | + " (for %s/%u/%u)\n", |
| 8087 | + closure->server_index, b->offset, |
| 8088 | + qinfo.qname, qinfo.qclass, qinfo.qtype); |
| 8089 | + uint16_t length = htons (b->offset); |
| 8090 | + size_t to_send = b->offset; |
| 8091 | + if (to_send < b->truncate_bytes) |
| 8092 | + to_send = 0; |
| 8093 | + else |
| 8094 | + to_send -= b->truncate_bytes; |
| 8095 | + struct iovec buffers[2] = |
| 8096 | + { |
| 8097 | + {&length, sizeof (length)}, |
| 8098 | + {b->buffer, to_send} |
| 8099 | + }; |
| 8100 | + writev_fully (closure->client_socket, buffers, 2); |
| 8101 | + } |
| 8102 | + bool close_flag = b->close; |
| 8103 | + response_builder_free (b); |
| 8104 | + free (query_buffer); |
| 8105 | + if (close_flag) |
| 8106 | + break; |
| 8107 | + } |
| 8108 | + |
| 8109 | + xclose (closure->client_socket); |
| 8110 | + free (closure); |
| 8111 | + return NULL; |
| 8112 | +} |
| 8113 | + |
| 8114 | +/* thread_callback for the TCP case. Accept connections and create a |
| 8115 | + new thread for each client. */ |
| 8116 | +static void |
| 8117 | +server_thread_tcp (struct resolv_test *obj, int server_index) |
| 8118 | +{ |
| 8119 | + while (true) |
| 8120 | + { |
| 8121 | + /* Get the client conenction. */ |
| 8122 | + int client_socket = xaccept |
| 8123 | + (obj->servers[server_index].socket_tcp, NULL, NULL); |
| 8124 | + |
| 8125 | + /* Check for termination. */ |
| 8126 | + xpthread_mutex_lock (&obj->lock); |
| 8127 | + if (obj->termination_requested) |
| 8128 | + { |
| 8129 | + xpthread_mutex_unlock (&obj->lock); |
| 8130 | + xclose (client_socket); |
| 8131 | + break; |
| 8132 | + } |
| 8133 | + xpthread_mutex_unlock (&obj->lock); |
| 8134 | + |
| 8135 | + /* Spawn a new thread for handling this connection. */ |
| 8136 | + struct tcp_thread_closure *closure = xmalloc (sizeof (*closure)); |
| 8137 | + *closure = (struct tcp_thread_closure) |
| 8138 | + { |
| 8139 | + .obj = obj, |
| 8140 | + .server_index = server_index, |
| 8141 | + .client_socket = client_socket, |
| 8142 | + }; |
| 8143 | + |
| 8144 | + pthread_t thr |
| 8145 | + = xpthread_create (NULL, server_thread_tcp_client, closure); |
| 8146 | + /* TODO: We should keep track of this thread so that we can |
| 8147 | + block in resolv_test_end until it has exited. */ |
| 8148 | + xpthread_detach (thr); |
| 8149 | + } |
| 8150 | +} |
| 8151 | + |
| 8152 | +/* Create UDP and TCP server sockets. */ |
| 8153 | +static void |
| 8154 | +make_server_sockets (struct resolv_test_server *server) |
| 8155 | +{ |
| 8156 | + while (true) |
| 8157 | + { |
| 8158 | + server->socket_udp = xsocket (AF_INET, SOCK_DGRAM, IPPROTO_UDP); |
| 8159 | + server->socket_tcp = xsocket (AF_INET, SOCK_STREAM, IPPROTO_TCP); |
| 8160 | + |
| 8161 | + /* Pick the address for the UDP socket. */ |
| 8162 | + server->address = (struct sockaddr_in) |
| 8163 | + { |
| 8164 | + .sin_family = AF_INET, |
| 8165 | + .sin_addr = {.s_addr = htonl (INADDR_LOOPBACK)} |
| 8166 | + }; |
| 8167 | + xbind (server->socket_udp, |
| 8168 | + (struct sockaddr *)&server->address, sizeof (server->address)); |
| 8169 | + |
| 8170 | + /* Retrieve the address. */ |
| 8171 | + socklen_t addrlen = sizeof (server->address); |
| 8172 | + xgetsockname (server->socket_udp, |
| 8173 | + (struct sockaddr *)&server->address, &addrlen); |
| 8174 | + |
| 8175 | + /* Bind the TCP socket to the same address. */ |
| 8176 | + { |
| 8177 | + int on = 1; |
| 8178 | + xsetsockopt (server->socket_tcp, SOL_SOCKET, SO_REUSEADDR, |
| 8179 | + &on, sizeof (on)); |
| 8180 | + } |
| 8181 | + if (bind (server->socket_tcp, |
| 8182 | + (struct sockaddr *)&server->address, |
| 8183 | + sizeof (server->address)) != 0) |
| 8184 | + { |
| 8185 | + /* Port collision. The UDP bind succeeded, but the TCP BIND |
| 8186 | + failed. We assume here that the kernel will pick the |
| 8187 | + next local UDP address randomly. */ |
| 8188 | + if (errno == EADDRINUSE) |
| 8189 | + { |
| 8190 | + xclose (server->socket_udp); |
| 8191 | + xclose (server->socket_tcp); |
| 8192 | + continue; |
| 8193 | + } |
| 8194 | + FAIL_EXIT1 ("TCP bind: %m"); |
| 8195 | + } |
| 8196 | + xlisten (server->socket_tcp, 5); |
| 8197 | + break; |
| 8198 | + } |
| 8199 | +} |
| 8200 | + |
| 8201 | +/* One-time initialization of NSS. */ |
| 8202 | +static void |
| 8203 | +resolv_redirect_once (void) |
| 8204 | +{ |
| 8205 | + /* Only use nss_dns. */ |
| 8206 | + __nss_configure_lookup ("hosts", "dns"); |
| 8207 | + __nss_configure_lookup ("networks", "dns"); |
| 8208 | + /* Enter a network namespace for isolation and firewall state |
| 8209 | + cleanup. The tests will still work if these steps fail, but they |
| 8210 | + may be less reliable. */ |
| 8211 | + support_become_root (); |
| 8212 | + support_enter_network_namespace (); |
| 8213 | +} |
| 8214 | +pthread_once_t resolv_redirect_once_var = PTHREAD_ONCE_INIT; |
| 8215 | + |
| 8216 | +void |
| 8217 | +resolv_test_init (void) |
| 8218 | +{ |
| 8219 | + /* Perform one-time initialization of NSS. */ |
| 8220 | + xpthread_once (&resolv_redirect_once_var, resolv_redirect_once); |
| 8221 | +} |
| 8222 | + |
| 8223 | +/* Copy the search path from CONFIG.search to the _res object. */ |
| 8224 | +static void |
| 8225 | +set_search_path (struct resolv_redirect_config config) |
| 8226 | +{ |
| 8227 | + memset (_res.defdname, 0, sizeof (_res.defdname)); |
| 8228 | + memset (_res.dnsrch, 0, sizeof (_res.dnsrch)); |
| 8229 | + |
| 8230 | + char *current = _res.defdname; |
| 8231 | + char *end = current + sizeof (_res.defdname); |
| 8232 | + |
| 8233 | + for (unsigned int i = 0; |
| 8234 | + i < sizeof (config.search) / sizeof (config.search[0]); ++i) |
| 8235 | + { |
| 8236 | + if (config.search[i] == NULL) |
| 8237 | + continue; |
| 8238 | + |
| 8239 | + size_t length = strlen (config.search[i]) + 1; |
| 8240 | + size_t remaining = end - current; |
| 8241 | + TEST_VERIFY_EXIT (length <= remaining); |
| 8242 | + memcpy (current, config.search[i], length); |
| 8243 | + _res.dnsrch[i] = current; |
| 8244 | + current += length; |
| 8245 | + } |
| 8246 | +} |
| 8247 | + |
| 8248 | +struct resolv_test * |
| 8249 | +resolv_test_start (struct resolv_redirect_config config) |
| 8250 | +{ |
| 8251 | + /* Apply configuration defaults. */ |
| 8252 | + if (config.nscount == 0) |
| 8253 | + config.nscount = resolv_max_test_servers; |
| 8254 | + |
| 8255 | + struct resolv_test *obj = xmalloc (sizeof (*obj)); |
| 8256 | + *obj = (struct resolv_test) { |
| 8257 | + .config = config, |
| 8258 | + .lock = PTHREAD_MUTEX_INITIALIZER, |
| 8259 | + }; |
| 8260 | + |
| 8261 | + resolv_test_init (); |
| 8262 | + |
| 8263 | + /* Create all the servers, to reserve the necessary ports. */ |
| 8264 | + for (int server_index = 0; server_index < config.nscount; ++server_index) |
| 8265 | + make_server_sockets (obj->servers + server_index); |
| 8266 | + |
| 8267 | + /* Start server threads. Disable the server ports, as |
| 8268 | + requested. */ |
| 8269 | + for (int server_index = 0; server_index < config.nscount; ++server_index) |
| 8270 | + { |
| 8271 | + struct resolv_test_server *server = obj->servers + server_index; |
| 8272 | + if (config.servers[server_index].disable_udp) |
| 8273 | + { |
| 8274 | + xclose (server->socket_udp); |
| 8275 | + server->socket_udp = -1; |
| 8276 | + } |
| 8277 | + else if (!config.single_thread_udp) |
| 8278 | + server->thread_udp = start_server_thread (obj, server_index, |
| 8279 | + server_thread_udp); |
| 8280 | + if (config.servers[server_index].disable_tcp) |
| 8281 | + { |
| 8282 | + xclose (server->socket_tcp); |
| 8283 | + server->socket_tcp = -1; |
| 8284 | + } |
| 8285 | + else |
| 8286 | + server->thread_tcp = start_server_thread (obj, server_index, |
| 8287 | + server_thread_tcp); |
| 8288 | + } |
| 8289 | + if (config.single_thread_udp) |
| 8290 | + start_server_thread_udp_single (obj); |
| 8291 | + |
| 8292 | + int timeout = 1; |
| 8293 | + |
| 8294 | + /* Initialize libresolv. */ |
| 8295 | + TEST_VERIFY_EXIT (res_init () == 0); |
| 8296 | + |
| 8297 | + /* Disable IPv6 name server addresses. The code below only |
| 8298 | + overrides the IPv4 addresses. */ |
| 8299 | + __res_iclose (&_res, true); |
| 8300 | + _res._u._ext.nscount = 0; |
| 8301 | + |
| 8302 | + /* Redirect queries to the server socket. */ |
| 8303 | + if (test_verbose) |
| 8304 | + { |
| 8305 | + printf ("info: old timeout value: %d\n", _res.retrans); |
| 8306 | + printf ("info: old retry attempt value: %d\n", _res.retry); |
| 8307 | + printf ("info: old _res.options: 0x%lx\n", _res.options); |
| 8308 | + printf ("info: old _res.nscount value: %d\n", _res.nscount); |
| 8309 | + printf ("info: old _res.ndots value: %d\n", _res.ndots); |
| 8310 | + } |
| 8311 | + _res.retrans = timeout; |
| 8312 | + _res.retry = 4; |
| 8313 | + _res.nscount = config.nscount; |
| 8314 | + _res.options = RES_INIT | RES_RECURSE | RES_DEFNAMES | RES_DNSRCH; |
| 8315 | + _res.ndots = 1; |
| 8316 | + if (test_verbose) |
| 8317 | + { |
| 8318 | + printf ("info: new timeout value: %d\n", _res.retrans); |
| 8319 | + printf ("info: new retry attempt value: %d\n", _res.retry); |
| 8320 | + printf ("info: new _res.options: 0x%lx\n", _res.options); |
| 8321 | + printf ("info: new _res.nscount value: %d\n", _res.nscount); |
| 8322 | + printf ("info: new _res.ndots value: %d\n", _res.ndots); |
| 8323 | + } |
| 8324 | + for (int server_index = 0; server_index < config.nscount; ++server_index) |
| 8325 | + { |
| 8326 | + _res.nsaddr_list[server_index] = obj->servers[server_index].address; |
| 8327 | + if (test_verbose) |
| 8328 | + { |
| 8329 | + char buf[256]; |
| 8330 | + TEST_VERIFY_EXIT |
| 8331 | + (inet_ntop (AF_INET, &obj->servers[server_index].address.sin_addr, |
| 8332 | + buf, sizeof (buf)) != NULL); |
| 8333 | + printf ("info: server %d: %s/%u\n", |
| 8334 | + server_index, buf, |
| 8335 | + htons (obj->servers[server_index].address.sin_port)); |
| 8336 | + } |
| 8337 | + } |
| 8338 | + |
| 8339 | + set_search_path (config); |
| 8340 | + |
| 8341 | + return obj; |
| 8342 | +} |
| 8343 | + |
| 8344 | +void |
| 8345 | +resolv_test_end (struct resolv_test *obj) |
| 8346 | +{ |
| 8347 | + res_close (); |
| 8348 | + |
| 8349 | + xpthread_mutex_lock (&obj->lock); |
| 8350 | + obj->termination_requested = true; |
| 8351 | + xpthread_mutex_unlock (&obj->lock); |
| 8352 | + |
| 8353 | + /* Send trigger packets to unblock the server threads. */ |
| 8354 | + for (int server_index = 0; server_index < obj->config.nscount; |
| 8355 | + ++server_index) |
| 8356 | + { |
| 8357 | + if (!obj->config.servers[server_index].disable_udp) |
| 8358 | + { |
| 8359 | + int sock = xsocket (AF_INET, SOCK_DGRAM, IPPROTO_UDP); |
| 8360 | + xsendto (sock, "", 1, 0, |
| 8361 | + (struct sockaddr *) &obj->servers[server_index].address, |
| 8362 | + sizeof (obj->servers[server_index].address)); |
| 8363 | + xclose (sock); |
| 8364 | + } |
| 8365 | + if (!obj->config.servers[server_index].disable_tcp) |
| 8366 | + { |
| 8367 | + int sock = xsocket (AF_INET, SOCK_STREAM, IPPROTO_TCP); |
| 8368 | + xconnect (sock, |
| 8369 | + (struct sockaddr *) &obj->servers[server_index].address, |
| 8370 | + sizeof (obj->servers[server_index].address)); |
| 8371 | + xclose (sock); |
| 8372 | + } |
| 8373 | + } |
| 8374 | + |
| 8375 | + if (obj->config.single_thread_udp) |
| 8376 | + xpthread_join (obj->thread_udp_single); |
| 8377 | + |
| 8378 | + /* Wait for the server threads to terminate. */ |
| 8379 | + for (int server_index = 0; server_index < obj->config.nscount; |
| 8380 | + ++server_index) |
| 8381 | + { |
| 8382 | + if (!obj->config.servers[server_index].disable_udp) |
| 8383 | + { |
| 8384 | + if (!obj->config.single_thread_udp) |
| 8385 | + xpthread_join (obj->servers[server_index].thread_udp); |
| 8386 | + xclose (obj->servers[server_index].socket_udp); |
| 8387 | + } |
| 8388 | + if (!obj->config.servers[server_index].disable_tcp) |
| 8389 | + { |
| 8390 | + xpthread_join (obj->servers[server_index].thread_tcp); |
| 8391 | + xclose (obj->servers[server_index].socket_tcp); |
| 8392 | + } |
| 8393 | + } |
| 8394 | + |
| 8395 | + free (obj); |
| 8396 | +} |
| 8397 | diff --git a/support/resolv_test.h b/support/resolv_test.h |
| 8398 | new file mode 100644 |
| 8399 | index 0000000000..6498751569 |
| 8400 | --- /dev/null |
| 8401 | +++ b/support/resolv_test.h |
| 8402 | @@ -0,0 +1,180 @@ |
| 8403 | +/* DNS test framework and libresolv redirection. |
| 8404 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 8405 | + This file is part of the GNU C Library. |
| 8406 | + |
| 8407 | + The GNU C Library is free software; you can redistribute it and/or |
| 8408 | + modify it under the terms of the GNU Lesser General Public |
| 8409 | + License as published by the Free Software Foundation; either |
| 8410 | + version 2.1 of the License, or (at your option) any later version. |
| 8411 | + |
| 8412 | + The GNU C Library is distributed in the hope that it will be useful, |
| 8413 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 8414 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 8415 | + Lesser General Public License for more details. |
| 8416 | + |
| 8417 | + You should have received a copy of the GNU Lesser General Public |
| 8418 | + License along with the GNU C Library; if not, see |
| 8419 | + <http://www.gnu.org/licenses/>. */ |
| 8420 | + |
| 8421 | +#ifndef SUPPORT_RESOLV_TEST_H |
| 8422 | +#define SUPPORT_RESOLV_TEST_H |
| 8423 | + |
| 8424 | +#include <arpa/nameser.h> |
| 8425 | +#include <stdbool.h> |
| 8426 | +#include <sys/cdefs.h> |
| 8427 | + |
| 8428 | +__BEGIN_DECLS |
| 8429 | + |
| 8430 | +/* Information about EDNS properties of a DNS query. */ |
| 8431 | +struct resolv_edns_info |
| 8432 | +{ |
| 8433 | + bool active; |
| 8434 | + uint8_t extended_rcode; |
| 8435 | + uint8_t version; |
| 8436 | + uint16_t flags; |
| 8437 | + uint16_t payload_size; |
| 8438 | +}; |
| 8439 | + |
| 8440 | +/* This struct provides context information when the response callback |
| 8441 | + specified in struct resolv_redirect_config is invoked. */ |
| 8442 | +struct resolv_response_context |
| 8443 | +{ |
| 8444 | + const unsigned char *query_buffer; |
| 8445 | + size_t query_length; |
| 8446 | + int server_index; |
| 8447 | + bool tcp; |
| 8448 | + struct resolv_edns_info edns; |
| 8449 | +}; |
| 8450 | + |
| 8451 | +/* This opaque struct is used to construct responses from within the |
| 8452 | + response callback function. */ |
| 8453 | +struct resolv_response_builder; |
| 8454 | + |
| 8455 | +/* This opaque struct collects information about the resolver testing |
| 8456 | + currently in progress. */ |
| 8457 | +struct resolv_test; |
| 8458 | + |
| 8459 | +enum |
| 8460 | + { |
| 8461 | + /* Maximum number of test servers supported by the framework. */ |
| 8462 | + resolv_max_test_servers = 3, |
| 8463 | + }; |
| 8464 | + |
| 8465 | +/* Configuration settings specific to individual test servers. */ |
| 8466 | +struct resolv_redirect_server_config |
| 8467 | +{ |
| 8468 | + bool disable_tcp; /* If true, no TCP server is listening. */ |
| 8469 | + bool disable_udp; /* If true, no UDP server is listening. */ |
| 8470 | +}; |
| 8471 | + |
| 8472 | +/* Instructions for setting up the libresolv redirection. */ |
| 8473 | +struct resolv_redirect_config |
| 8474 | +{ |
| 8475 | + /* The response_callback function is called for every incoming DNS |
| 8476 | + packet, over UDP or TCP. It must be specified, the other |
| 8477 | + configuration settings are optional. */ |
| 8478 | + void (*response_callback) (const struct resolv_response_context *, |
| 8479 | + struct resolv_response_builder *, |
| 8480 | + const char *qname, |
| 8481 | + uint16_t qclass, uint16_t qtype); |
| 8482 | + |
| 8483 | + /* Per-server configuration. */ |
| 8484 | + struct resolv_redirect_server_config servers[resolv_max_test_servers]; |
| 8485 | + |
| 8486 | + /* Search path entries. The first entry serves as the default |
| 8487 | + domain name as well. */ |
| 8488 | + const char *search[7]; |
| 8489 | + |
| 8490 | + /* Number of servers to activate in resolv. 0 means the default, |
| 8491 | + resolv_max_test_servers. */ |
| 8492 | + int nscount; |
| 8493 | + |
| 8494 | + /* If true, use a single thread to process all UDP queries. This |
| 8495 | + may results in more predictable ordering of queries and |
| 8496 | + responses. */ |
| 8497 | + bool single_thread_udp; |
| 8498 | +}; |
| 8499 | + |
| 8500 | +/* Configure NSS to use, nss_dns only for aplicable databases, and try |
| 8501 | + to put the process into a network namespace for better isolation. |
| 8502 | + This may have to be called before resolv_test_start, before the |
| 8503 | + process creates any threads. Otherwise, initialization is |
| 8504 | + performed by resolv_test_start implicitly. */ |
| 8505 | +void resolv_test_init (void); |
| 8506 | + |
| 8507 | +/* Initiate resolver testing. This updates the _res variable as |
| 8508 | + needed. As a side effect, NSS is reconfigured to use nss_dns only |
| 8509 | + for aplicable databases, and the process may enter a network |
| 8510 | + namespace for better isolation. */ |
| 8511 | +struct resolv_test *resolv_test_start (struct resolv_redirect_config); |
| 8512 | + |
| 8513 | +/* Call this function at the end of resolver testing, to free |
| 8514 | + resources and report pending errors (if any). */ |
| 8515 | +void resolv_test_end (struct resolv_test *); |
| 8516 | + |
| 8517 | +/* The remaining facilities in this file are used for constructing |
| 8518 | + response packets from the response_callback function. */ |
| 8519 | + |
| 8520 | +/* Special settings for constructing responses from the callback. */ |
| 8521 | +struct resolv_response_flags |
| 8522 | +{ |
| 8523 | + /* 4-bit response code to incorporate into the response. */ |
| 8524 | + unsigned char rcode; |
| 8525 | + |
| 8526 | + /* If true, the TC (truncation) flag will be set. */ |
| 8527 | + bool tc; |
| 8528 | + |
| 8529 | + /* Initial section count values. Can be used to artificially |
| 8530 | + increase the counts, for malformed packet testing.*/ |
| 8531 | + unsigned short qdcount; |
| 8532 | + unsigned short ancount; |
| 8533 | + unsigned short nscount; |
| 8534 | + unsigned short adcount; |
| 8535 | +}; |
| 8536 | + |
| 8537 | +/* Begin a new response with the requested flags. Must be called |
| 8538 | + first. */ |
| 8539 | +void resolv_response_init (struct resolv_response_builder *, |
| 8540 | + struct resolv_response_flags); |
| 8541 | + |
| 8542 | +/* Switches to the section in the response packet. Only forward |
| 8543 | + movement is supported. */ |
| 8544 | +void resolv_response_section (struct resolv_response_builder *, ns_sect); |
| 8545 | + |
| 8546 | +/* Add a question record to the question section. */ |
| 8547 | +void resolv_response_add_question (struct resolv_response_builder *, |
| 8548 | + const char *name, uint16_t class, |
| 8549 | + uint16_t type); |
| 8550 | +/* Starts a new resource record with the specified owner name, class, |
| 8551 | + type, and TTL. Data is supplied with resolv_response_add_data or |
| 8552 | + resolv_response_add_name. */ |
| 8553 | +void resolv_response_open_record (struct resolv_response_builder *, |
| 8554 | + const char *name, uint16_t class, |
| 8555 | + uint16_t type, uint32_t ttl); |
| 8556 | + |
| 8557 | +/* Add unstructed bytes to the RDATA part of a resource record. */ |
| 8558 | +void resolv_response_add_data (struct resolv_response_builder *, |
| 8559 | + const void *, size_t); |
| 8560 | + |
| 8561 | +/* Add a compressed domain name to the RDATA part of a resource |
| 8562 | + record. */ |
| 8563 | +void resolv_response_add_name (struct resolv_response_builder *, |
| 8564 | + const char *name); |
| 8565 | + |
| 8566 | +/* Mark the end of the constructed record. Must be called last. */ |
| 8567 | +void resolv_response_close_record (struct resolv_response_builder *); |
| 8568 | + |
| 8569 | +/* Drop this query packet (that is, do not send a response, not even |
| 8570 | + an empty packet). */ |
| 8571 | +void resolv_response_drop (struct resolv_response_builder *); |
| 8572 | + |
| 8573 | +/* In TCP mode, close the connection after this packet (if a response |
| 8574 | + is sent). */ |
| 8575 | +void resolv_response_close (struct resolv_response_builder *); |
| 8576 | + |
| 8577 | +/* The size of the response packet built so far. */ |
| 8578 | +size_t resolv_response_length (const struct resolv_response_builder *); |
| 8579 | + |
| 8580 | +__END_DECLS |
| 8581 | + |
| 8582 | +#endif /* SUPPORT_RESOLV_TEST_H */ |
| 8583 | diff --git a/support/run_diff.h b/support/run_diff.h |
| 8584 | new file mode 100644 |
| 8585 | index 0000000000..f65b5dd22c |
| 8586 | --- /dev/null |
| 8587 | +++ b/support/run_diff.h |
| 8588 | @@ -0,0 +1,31 @@ |
| 8589 | +/* Invoke the system diff tool to compare two strings. |
| 8590 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 8591 | + This file is part of the GNU C Library. |
| 8592 | + |
| 8593 | + The GNU C Library is free software; you can redistribute it and/or |
| 8594 | + modify it under the terms of the GNU Lesser General Public |
| 8595 | + License as published by the Free Software Foundation; either |
| 8596 | + version 2.1 of the License, or (at your option) any later version. |
| 8597 | + |
| 8598 | + The GNU C Library is distributed in the hope that it will be useful, |
| 8599 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 8600 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 8601 | + Lesser General Public License for more details. |
| 8602 | + |
| 8603 | + You should have received a copy of the GNU Lesser General Public |
| 8604 | + License along with the GNU C Library; if not, see |
| 8605 | + <http://www.gnu.org/licenses/>. */ |
| 8606 | + |
| 8607 | +#ifndef SUPPORT_RUN_DIFF_H |
| 8608 | +#define SUPPORT_RUN_DIFF_H |
| 8609 | + |
| 8610 | +/* Compare the two NUL-terminated strings LEFT and RIGHT using the |
| 8611 | + diff tool. Label the sides of the diff with LEFT_LABEL and |
| 8612 | + RIGHT_LABEL, respectively. |
| 8613 | + |
| 8614 | + This function assumes that LEFT and RIGHT are different |
| 8615 | + strings. */ |
| 8616 | +void support_run_diff (const char *left_label, const char *left, |
| 8617 | + const char *right_label, const char *right); |
| 8618 | + |
| 8619 | +#endif /* SUPPORT_RUN_DIFF_H */ |
| 8620 | diff --git a/support/set_fortify_handler.c b/support/set_fortify_handler.c |
| 8621 | new file mode 100644 |
| 8622 | index 0000000000..f434a8082a |
| 8623 | --- /dev/null |
| 8624 | +++ b/support/set_fortify_handler.c |
| 8625 | @@ -0,0 +1,34 @@ |
| 8626 | +/* Set signal handler for use in fortify tests. |
| 8627 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 8628 | + This file is part of the GNU C Library. |
| 8629 | + |
| 8630 | + The GNU C Library is free software; you can redistribute it and/or |
| 8631 | + modify it under the terms of the GNU Lesser General Public |
| 8632 | + License as published by the Free Software Foundation; either |
| 8633 | + version 2.1 of the License, or (at your option) any later version. |
| 8634 | + |
| 8635 | + The GNU C Library is distributed in the hope that it will be useful, |
| 8636 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 8637 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 8638 | + Lesser General Public License for more details. |
| 8639 | + |
| 8640 | + You should have received a copy of the GNU Lesser General Public |
| 8641 | + License along with the GNU C Library; if not, see |
| 8642 | + <http://www.gnu.org/licenses/>. */ |
| 8643 | + |
| 8644 | +#include <support/support.h> |
| 8645 | + |
| 8646 | +#include <signal.h> |
| 8647 | + |
| 8648 | +void |
| 8649 | +set_fortify_handler (void (*handler) (int sig)) |
| 8650 | +{ |
| 8651 | + struct sigaction sa; |
| 8652 | + |
| 8653 | + sa.sa_handler = handler; |
| 8654 | + sa.sa_flags = 0; |
| 8655 | + sigemptyset (&sa.sa_mask); |
| 8656 | + |
| 8657 | + sigaction (SIGABRT, &sa, NULL); |
| 8658 | + ignore_stderr (); |
| 8659 | +} |
| 8660 | diff --git a/support/support-xstat.c b/support/support-xstat.c |
| 8661 | new file mode 100644 |
| 8662 | index 0000000000..86a81ec601 |
| 8663 | --- /dev/null |
| 8664 | +++ b/support/support-xstat.c |
| 8665 | @@ -0,0 +1,30 @@ |
| 8666 | +/* stat64 with error checking. |
| 8667 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 8668 | + This file is part of the GNU C Library. |
| 8669 | + |
| 8670 | + The GNU C Library is free software; you can redistribute it and/or |
| 8671 | + modify it under the terms of the GNU Lesser General Public |
| 8672 | + License as published by the Free Software Foundation; either |
| 8673 | + version 2.1 of the License, or (at your option) any later version. |
| 8674 | + |
| 8675 | + The GNU C Library is distributed in the hope that it will be useful, |
| 8676 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 8677 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 8678 | + Lesser General Public License for more details. |
| 8679 | + |
| 8680 | + You should have received a copy of the GNU Lesser General Public |
| 8681 | + License along with the GNU C Library; if not, see |
| 8682 | + <http://www.gnu.org/licenses/>. */ |
| 8683 | + |
| 8684 | +/* NB: Non-standard file name to avoid sysdeps override for xstat. */ |
| 8685 | + |
| 8686 | +#include <support/check.h> |
| 8687 | +#include <support/xunistd.h> |
| 8688 | +#include <sys/stat.h> |
| 8689 | + |
| 8690 | +void |
| 8691 | +xstat (const char *path, struct stat64 *result) |
| 8692 | +{ |
| 8693 | + if (stat64 (path, result) != 0) |
| 8694 | + FAIL_EXIT1 ("stat64 (\"%s\"): %m", path); |
| 8695 | +} |
| 8696 | diff --git a/support/support.h b/support/support.h |
| 8697 | new file mode 100644 |
| 8698 | index 0000000000..4b5f04c2cc |
| 8699 | --- /dev/null |
| 8700 | +++ b/support/support.h |
| 8701 | @@ -0,0 +1,74 @@ |
| 8702 | +/* Common extra functions. |
| 8703 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 8704 | + This file is part of the GNU C Library. |
| 8705 | + |
| 8706 | + The GNU C Library is free software; you can redistribute it and/or |
| 8707 | + modify it under the terms of the GNU Lesser General Public |
| 8708 | + License as published by the Free Software Foundation; either |
| 8709 | + version 2.1 of the License, or (at your option) any later version. |
| 8710 | + |
| 8711 | + The GNU C Library is distributed in the hope that it will be useful, |
| 8712 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 8713 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 8714 | + Lesser General Public License for more details. |
| 8715 | + |
| 8716 | + You should have received a copy of the GNU Lesser General Public |
| 8717 | + License along with the GNU C Library; if not, see |
| 8718 | + <http://www.gnu.org/licenses/>. */ |
| 8719 | + |
| 8720 | +/* This header file should only contain definitions compatible with |
| 8721 | + C90. (Using __attribute__ is fine because <features.h> provides a |
| 8722 | + fallback.) */ |
| 8723 | + |
| 8724 | +#ifndef SUPPORT_H |
| 8725 | +#define SUPPORT_H |
| 8726 | + |
| 8727 | +#include <stddef.h> |
| 8728 | +#include <sys/cdefs.h> |
| 8729 | + |
| 8730 | +__BEGIN_DECLS |
| 8731 | + |
| 8732 | +/* Write a message to standard output. Can be used in signal |
| 8733 | + handlers. */ |
| 8734 | +void write_message (const char *message) __attribute__ ((nonnull (1))); |
| 8735 | + |
| 8736 | +/* Avoid all the buffer overflow messages on stderr. */ |
| 8737 | +void ignore_stderr (void); |
| 8738 | + |
| 8739 | +/* Set fortification error handler. Used when tests want to verify that bad |
| 8740 | + code is caught by the library. */ |
| 8741 | +void set_fortify_handler (void (*handler) (int sig)); |
| 8742 | + |
| 8743 | +/* Report an out-of-memory error for the allocation of SIZE bytes in |
| 8744 | + FUNCTION, terminating the process. */ |
| 8745 | +void oom_error (const char *function, size_t size) |
| 8746 | + __attribute__ ((nonnull (1))); |
| 8747 | + |
| 8748 | +/* Return a pointer to a memory region of SIZE bytes. The memory is |
| 8749 | + initialized to zero and will be shared with subprocesses (across |
| 8750 | + fork). The returned pointer must be freed using |
| 8751 | + support_shared_free; it is not compatible with the malloc |
| 8752 | + functions. */ |
| 8753 | +void *support_shared_allocate (size_t size); |
| 8754 | + |
| 8755 | +/* Deallocate a pointer returned by support_shared_allocate. */ |
| 8756 | +void support_shared_free (void *); |
| 8757 | + |
| 8758 | +/* Write CONTENTS to the file PATH. Create or truncate the file as |
| 8759 | + needed. The file mode is 0666 masked by the umask. Terminate the |
| 8760 | + process on error. */ |
| 8761 | +void support_write_file_string (const char *path, const char *contents); |
| 8762 | + |
| 8763 | +/* Error-checking wrapper functions which terminate the process on |
| 8764 | + error. */ |
| 8765 | + |
| 8766 | +void *xmalloc (size_t) __attribute__ ((malloc)); |
| 8767 | +void *xcalloc (size_t n, size_t s) __attribute__ ((malloc)); |
| 8768 | +void *xrealloc (void *p, size_t n); |
| 8769 | +char *xasprintf (const char *format, ...) |
| 8770 | + __attribute__ ((format (printf, 1, 2), malloc)); |
| 8771 | +char *xstrdup (const char *); |
| 8772 | + |
| 8773 | +__END_DECLS |
| 8774 | + |
| 8775 | +#endif /* SUPPORT_H */ |
| 8776 | diff --git a/sysdeps/sparc/sparc32/sparcv9/fpu/s_fdim.S b/support/support_become_root.c |
| 8777 | similarity index 57% |
| 8778 | rename from sysdeps/sparc/sparc32/sparcv9/fpu/s_fdim.S |
| 8779 | rename to support/support_become_root.c |
| 8780 | index 37f7f44dfa..3fa0bd4ac0 100644 |
| 8781 | --- a/sysdeps/sparc/sparc32/sparcv9/fpu/s_fdim.S |
| 8782 | +++ b/support/support_become_root.c |
| 8783 | @@ -1,7 +1,6 @@ |
| 8784 | -/* Compute positive difference, sparc 32-bit+v9. |
| 8785 | - Copyright (C) 2013-2016 Free Software Foundation, Inc. |
| 8786 | +/* Acquire root privileges. |
| 8787 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 8788 | This file is part of the GNU C Library. |
| 8789 | - Contributed by David S. Miller <davem@davemloft.net>. |
| 8790 | |
| 8791 | The GNU C Library is free software; you can redistribute it and/or |
| 8792 | modify it under the terms of the GNU Lesser General Public |
| 8793 | @@ -17,24 +16,25 @@ |
| 8794 | License along with the GNU C Library; if not, see |
| 8795 | <http://www.gnu.org/licenses/>. */ |
| 8796 | |
| 8797 | -#include <sysdep.h> |
| 8798 | -#include <math_ldbl_opt.h> |
| 8799 | +#include <support/namespace.h> |
| 8800 | |
| 8801 | -ENTRY(__fdim) |
| 8802 | - std %o0, [%sp + 72] |
| 8803 | - std %o2, [%sp + 80] |
| 8804 | - ldd [%sp + 72], %f0 |
| 8805 | - ldd [%sp + 80], %f2 |
| 8806 | - fcmpd %f0, %f2 |
| 8807 | - fbug 1f |
| 8808 | - nop |
| 8809 | - fzero %f0 |
| 8810 | - fnegd %f0, %f2 |
| 8811 | -1: retl |
| 8812 | - fsubd %f0, %f2, %f0 |
| 8813 | -END(__fdim) |
| 8814 | -weak_alias (__fdim, fdim) |
| 8815 | +#include <sched.h> |
| 8816 | +#include <stdio.h> |
| 8817 | +#include <unistd.h> |
| 8818 | |
| 8819 | -#if LONG_DOUBLE_COMPAT(libm, GLIBC_2_1) |
| 8820 | -compat_symbol (libm, __fdim, fdiml, GLIBC_2_1); |
| 8821 | +bool |
| 8822 | +support_become_root (void) |
| 8823 | +{ |
| 8824 | +#ifdef CLONE_NEWUSER |
| 8825 | + if (unshare (CLONE_NEWUSER | CLONE_NEWNS) == 0) |
| 8826 | + /* Even if we do not have UID zero, we have extended privileges at |
| 8827 | + this point. */ |
| 8828 | + return true; |
| 8829 | #endif |
| 8830 | + if (setuid (0) != 0) |
| 8831 | + { |
| 8832 | + printf ("warning: could not become root outside namespace (%m)\n"); |
| 8833 | + return false; |
| 8834 | + } |
| 8835 | + return true; |
| 8836 | +} |
| 8837 | diff --git a/support/support_can_chroot.c b/support/support_can_chroot.c |
| 8838 | new file mode 100644 |
| 8839 | index 0000000000..0dfd2deb54 |
| 8840 | --- /dev/null |
| 8841 | +++ b/support/support_can_chroot.c |
| 8842 | @@ -0,0 +1,65 @@ |
| 8843 | +/* Return true if the process can perform a chroot operation. |
| 8844 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 8845 | + This file is part of the GNU C Library. |
| 8846 | + |
| 8847 | + The GNU C Library is free software; you can redistribute it and/or |
| 8848 | + modify it under the terms of the GNU Lesser General Public |
| 8849 | + License as published by the Free Software Foundation; either |
| 8850 | + version 2.1 of the License, or (at your option) any later version. |
| 8851 | + |
| 8852 | + The GNU C Library is distributed in the hope that it will be useful, |
| 8853 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 8854 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 8855 | + Lesser General Public License for more details. |
| 8856 | + |
| 8857 | + You should have received a copy of the GNU Lesser General Public |
| 8858 | + License along with the GNU C Library; if not, see |
| 8859 | + <http://www.gnu.org/licenses/>. */ |
| 8860 | + |
| 8861 | +#include <errno.h> |
| 8862 | +#include <stdio.h> |
| 8863 | +#include <support/check.h> |
| 8864 | +#include <support/namespace.h> |
| 8865 | +#include <support/support.h> |
| 8866 | +#include <sys/stat.h> |
| 8867 | +#include <unistd.h> |
| 8868 | +#include <xunistd.h> |
| 8869 | + |
| 8870 | +static void |
| 8871 | +callback (void *closure) |
| 8872 | +{ |
| 8873 | + int *result = closure; |
| 8874 | + struct stat64 before; |
| 8875 | + xstat ("/dev", &before); |
| 8876 | + if (chroot ("/dev") != 0) |
| 8877 | + { |
| 8878 | + *result = errno; |
| 8879 | + return; |
| 8880 | + } |
| 8881 | + struct stat64 after; |
| 8882 | + xstat ("/", &after); |
| 8883 | + TEST_VERIFY (before.st_dev == after.st_dev); |
| 8884 | + TEST_VERIFY (before.st_ino == after.st_ino); |
| 8885 | + *result = 0; |
| 8886 | +} |
| 8887 | + |
| 8888 | +bool |
| 8889 | +support_can_chroot (void) |
| 8890 | +{ |
| 8891 | + int *result = support_shared_allocate (sizeof (*result)); |
| 8892 | + *result = 0; |
| 8893 | + support_isolate_in_subprocess (callback, result); |
| 8894 | + bool ok = *result == 0; |
| 8895 | + if (!ok) |
| 8896 | + { |
| 8897 | + static bool already_warned; |
| 8898 | + if (!already_warned) |
| 8899 | + { |
| 8900 | + already_warned = true; |
| 8901 | + errno = *result; |
| 8902 | + printf ("warning: this process does not support chroot: %m\n"); |
| 8903 | + } |
| 8904 | + } |
| 8905 | + support_shared_free (result); |
| 8906 | + return ok; |
| 8907 | +} |
| 8908 | diff --git a/support/support_capture_subprocess.c b/support/support_capture_subprocess.c |
| 8909 | new file mode 100644 |
| 8910 | index 0000000000..030f124252 |
| 8911 | --- /dev/null |
| 8912 | +++ b/support/support_capture_subprocess.c |
| 8913 | @@ -0,0 +1,108 @@ |
| 8914 | +/* Capture output from a subprocess. |
| 8915 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 8916 | + This file is part of the GNU C Library. |
| 8917 | + |
| 8918 | + The GNU C Library is free software; you can redistribute it and/or |
| 8919 | + modify it under the terms of the GNU Lesser General Public |
| 8920 | + License as published by the Free Software Foundation; either |
| 8921 | + version 2.1 of the License, or (at your option) any later version. |
| 8922 | + |
| 8923 | + The GNU C Library is distributed in the hope that it will be useful, |
| 8924 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 8925 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 8926 | + Lesser General Public License for more details. |
| 8927 | + |
| 8928 | + You should have received a copy of the GNU Lesser General Public |
| 8929 | + License along with the GNU C Library; if not, see |
| 8930 | + <http://www.gnu.org/licenses/>. */ |
| 8931 | + |
| 8932 | +#include <support/capture_subprocess.h> |
| 8933 | + |
| 8934 | +#include <errno.h> |
| 8935 | +#include <stdlib.h> |
| 8936 | +#include <support/check.h> |
| 8937 | +#include <support/xunistd.h> |
| 8938 | +#include <support/xsocket.h> |
| 8939 | + |
| 8940 | +static void |
| 8941 | +transfer (const char *what, struct pollfd *pfd, struct xmemstream *stream) |
| 8942 | +{ |
| 8943 | + if (pfd->revents != 0) |
| 8944 | + { |
| 8945 | + char buf[1024]; |
| 8946 | + ssize_t ret = TEMP_FAILURE_RETRY (read (pfd->fd, buf, sizeof (buf))); |
| 8947 | + if (ret < 0) |
| 8948 | + { |
| 8949 | + support_record_failure (); |
| 8950 | + printf ("error: reading from subprocess %s: %m", what); |
| 8951 | + pfd->events = 0; |
| 8952 | + pfd->revents = 0; |
| 8953 | + } |
| 8954 | + else if (ret == 0) |
| 8955 | + { |
| 8956 | + /* EOF reached. Stop listening. */ |
| 8957 | + pfd->events = 0; |
| 8958 | + pfd->revents = 0; |
| 8959 | + } |
| 8960 | + else |
| 8961 | + /* Store the data just read. */ |
| 8962 | + TEST_VERIFY (fwrite (buf, ret, 1, stream->out) == 1); |
| 8963 | + } |
| 8964 | +} |
| 8965 | + |
| 8966 | +struct support_capture_subprocess |
| 8967 | +support_capture_subprocess (void (*callback) (void *), void *closure) |
| 8968 | +{ |
| 8969 | + struct support_capture_subprocess result; |
| 8970 | + xopen_memstream (&result.out); |
| 8971 | + xopen_memstream (&result.err); |
| 8972 | + |
| 8973 | + int stdout_pipe[2]; |
| 8974 | + xpipe (stdout_pipe); |
| 8975 | + int stderr_pipe[2]; |
| 8976 | + xpipe (stderr_pipe); |
| 8977 | + |
| 8978 | + TEST_VERIFY (fflush (stdout) == 0); |
| 8979 | + TEST_VERIFY (fflush (stderr) == 0); |
| 8980 | + |
| 8981 | + pid_t pid = xfork (); |
| 8982 | + if (pid == 0) |
| 8983 | + { |
| 8984 | + xclose (stdout_pipe[0]); |
| 8985 | + xclose (stderr_pipe[0]); |
| 8986 | + xdup2 (stdout_pipe[1], STDOUT_FILENO); |
| 8987 | + xdup2 (stderr_pipe[1], STDERR_FILENO); |
| 8988 | + callback (closure); |
| 8989 | + _exit (0); |
| 8990 | + } |
| 8991 | + xclose (stdout_pipe[1]); |
| 8992 | + xclose (stderr_pipe[1]); |
| 8993 | + |
| 8994 | + struct pollfd fds[2] = |
| 8995 | + { |
| 8996 | + { .fd = stdout_pipe[0], .events = POLLIN }, |
| 8997 | + { .fd = stderr_pipe[0], .events = POLLIN }, |
| 8998 | + }; |
| 8999 | + |
| 9000 | + do |
| 9001 | + { |
| 9002 | + xpoll (fds, 2, -1); |
| 9003 | + transfer ("stdout", &fds[0], &result.out); |
| 9004 | + transfer ("stderr", &fds[1], &result.err); |
| 9005 | + } |
| 9006 | + while (fds[0].events != 0 || fds[1].events != 0); |
| 9007 | + xclose (stdout_pipe[0]); |
| 9008 | + xclose (stderr_pipe[0]); |
| 9009 | + |
| 9010 | + xfclose_memstream (&result.out); |
| 9011 | + xfclose_memstream (&result.err); |
| 9012 | + xwaitpid (pid, &result.status, 0); |
| 9013 | + return result; |
| 9014 | +} |
| 9015 | + |
| 9016 | +void |
| 9017 | +support_capture_subprocess_free (struct support_capture_subprocess *p) |
| 9018 | +{ |
| 9019 | + free (p->out.buffer); |
| 9020 | + free (p->err.buffer); |
| 9021 | +} |
| 9022 | diff --git a/support/support_capture_subprocess_check.c b/support/support_capture_subprocess_check.c |
| 9023 | new file mode 100644 |
| 9024 | index 0000000000..708c89f331 |
| 9025 | --- /dev/null |
| 9026 | +++ b/support/support_capture_subprocess_check.c |
| 9027 | @@ -0,0 +1,67 @@ |
| 9028 | +/* Verify capture output from a subprocess. |
| 9029 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 9030 | + This file is part of the GNU C Library. |
| 9031 | + |
| 9032 | + The GNU C Library is free software; you can redistribute it and/or |
| 9033 | + modify it under the terms of the GNU Lesser General Public |
| 9034 | + License as published by the Free Software Foundation; either |
| 9035 | + version 2.1 of the License, or (at your option) any later version. |
| 9036 | + |
| 9037 | + The GNU C Library is distributed in the hope that it will be useful, |
| 9038 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9039 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 9040 | + Lesser General Public License for more details. |
| 9041 | + |
| 9042 | + You should have received a copy of the GNU Lesser General Public |
| 9043 | + License along with the GNU C Library; if not, see |
| 9044 | + <http://www.gnu.org/licenses/>. */ |
| 9045 | + |
| 9046 | +#include <stdbool.h> |
| 9047 | +#include <stdio.h> |
| 9048 | +#include <support/capture_subprocess.h> |
| 9049 | +#include <support/check.h> |
| 9050 | + |
| 9051 | +static void |
| 9052 | +print_context (const char *context, bool *failed) |
| 9053 | +{ |
| 9054 | + if (*failed) |
| 9055 | + /* Do not duplicate message. */ |
| 9056 | + return; |
| 9057 | + support_record_failure (); |
| 9058 | + printf ("error: subprocess failed: %s\n", context); |
| 9059 | +} |
| 9060 | + |
| 9061 | +void |
| 9062 | +support_capture_subprocess_check (struct support_capture_subprocess *proc, |
| 9063 | + const char *context, int status, |
| 9064 | + int allowed) |
| 9065 | +{ |
| 9066 | + TEST_VERIFY ((allowed & sc_allow_none) |
| 9067 | + || (allowed & sc_allow_stdout) |
| 9068 | + || (allowed & sc_allow_stderr)); |
| 9069 | + TEST_VERIFY (!((allowed & sc_allow_none) |
| 9070 | + && ((allowed & sc_allow_stdout) |
| 9071 | + || (allowed & sc_allow_stderr)))); |
| 9072 | + |
| 9073 | + bool failed = false; |
| 9074 | + if (proc->status != status) |
| 9075 | + { |
| 9076 | + print_context (context, &failed); |
| 9077 | + printf ("error: expected exit status: %d\n", status); |
| 9078 | + printf ("error: actual exit status: %d\n", status); |
| 9079 | + } |
| 9080 | + if (!(allowed & sc_allow_stdout) && proc->out.length != 0) |
| 9081 | + { |
| 9082 | + print_context (context, &failed); |
| 9083 | + printf ("error: unexpected output from subprocess\n"); |
| 9084 | + fwrite (proc->out.buffer, proc->out.length, 1, stdout); |
| 9085 | + puts ("\n"); |
| 9086 | + } |
| 9087 | + if (!(allowed & sc_allow_stderr) && proc->err.length != 0) |
| 9088 | + { |
| 9089 | + print_context (context, &failed); |
| 9090 | + printf ("error: unexpected error output from subprocess\n"); |
| 9091 | + fwrite (proc->err.buffer, proc->err.length, 1, stdout); |
| 9092 | + puts ("\n"); |
| 9093 | + } |
| 9094 | +} |
| 9095 | diff --git a/support/support_enter_network_namespace.c b/support/support_enter_network_namespace.c |
| 9096 | new file mode 100644 |
| 9097 | index 0000000000..28b0ee29cf |
| 9098 | --- /dev/null |
| 9099 | +++ b/support/support_enter_network_namespace.c |
| 9100 | @@ -0,0 +1,75 @@ |
| 9101 | +/* Enter a network namespace. |
| 9102 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 9103 | + This file is part of the GNU C Library. |
| 9104 | + |
| 9105 | + The GNU C Library is free software; you can redistribute it and/or |
| 9106 | + modify it under the terms of the GNU Lesser General Public |
| 9107 | + License as published by the Free Software Foundation; either |
| 9108 | + version 2.1 of the License, or (at your option) any later version. |
| 9109 | + |
| 9110 | + The GNU C Library is distributed in the hope that it will be useful, |
| 9111 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9112 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 9113 | + Lesser General Public License for more details. |
| 9114 | + |
| 9115 | + You should have received a copy of the GNU Lesser General Public |
| 9116 | + License along with the GNU C Library; if not, see |
| 9117 | + <http://www.gnu.org/licenses/>. */ |
| 9118 | + |
| 9119 | +#include <support/namespace.h> |
| 9120 | + |
| 9121 | +#include <net/if.h> |
| 9122 | +#include <sched.h> |
| 9123 | +#include <stdio.h> |
| 9124 | +#include <string.h> |
| 9125 | +#include <support/check.h> |
| 9126 | +#include <support/xsocket.h> |
| 9127 | +#include <support/xunistd.h> |
| 9128 | +#include <sys/ioctl.h> |
| 9129 | +#include <unistd.h> |
| 9130 | + |
| 9131 | +static bool in_uts_namespace; |
| 9132 | + |
| 9133 | +bool |
| 9134 | +support_enter_network_namespace (void) |
| 9135 | +{ |
| 9136 | +#ifdef CLONE_NEWUTS |
| 9137 | + if (unshare (CLONE_NEWUTS) == 0) |
| 9138 | + in_uts_namespace = true; |
| 9139 | + else |
| 9140 | + printf ("warning: unshare (CLONE_NEWUTS) failed: %m\n"); |
| 9141 | +#endif |
| 9142 | + |
| 9143 | +#ifdef CLONE_NEWNET |
| 9144 | + if (unshare (CLONE_NEWNET) == 0) |
| 9145 | + { |
| 9146 | + /* Bring up the loopback interface. */ |
| 9147 | + int fd = xsocket (AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0); |
| 9148 | + struct ifreq req; |
| 9149 | + strcpy (req.ifr_name, "lo"); |
| 9150 | + TEST_VERIFY_EXIT (ioctl (fd, SIOCGIFFLAGS, &req) == 0); |
| 9151 | + bool already_up = req.ifr_flags & IFF_UP; |
| 9152 | + if (already_up) |
| 9153 | + /* This means that we likely have not achieved isolation from |
| 9154 | + the parent namespace. */ |
| 9155 | + printf ("warning: loopback interface already exists" |
| 9156 | + " in new network namespace\n"); |
| 9157 | + else |
| 9158 | + { |
| 9159 | + req.ifr_flags |= IFF_UP | IFF_RUNNING; |
| 9160 | + TEST_VERIFY_EXIT (ioctl (fd, SIOCSIFFLAGS, &req) == 0); |
| 9161 | + } |
| 9162 | + xclose (fd); |
| 9163 | + |
| 9164 | + return !already_up; |
| 9165 | + } |
| 9166 | +#endif |
| 9167 | + printf ("warning: could not enter network namespace\n"); |
| 9168 | + return false; |
| 9169 | +} |
| 9170 | + |
| 9171 | +bool |
| 9172 | +support_in_uts_namespace (void) |
| 9173 | +{ |
| 9174 | + return in_uts_namespace; |
| 9175 | +} |
| 9176 | diff --git a/sysdeps/sparc/sparc32/sparcv9/fpu/s_fdimf.S b/support/support_format_address_family.c |
| 9177 | similarity index 63% |
| 9178 | rename from sysdeps/sparc/sparc32/sparcv9/fpu/s_fdimf.S |
| 9179 | rename to support/support_format_address_family.c |
| 9180 | index 9e0e3f21be..5d42c42a45 100644 |
| 9181 | --- a/sysdeps/sparc/sparc32/sparcv9/fpu/s_fdimf.S |
| 9182 | +++ b/support/support_format_address_family.c |
| 9183 | @@ -1,7 +1,6 @@ |
| 9184 | -/* Compute positive difference, sparc 32-bit+v9. |
| 9185 | - Copyright (C) 2013-2016 Free Software Foundation, Inc. |
| 9186 | +/* Convert an address family to a string. |
| 9187 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 9188 | This file is part of the GNU C Library. |
| 9189 | - Contributed by David S. Miller <davem@davemloft.net>. |
| 9190 | |
| 9191 | The GNU C Library is free software; you can redistribute it and/or |
| 9192 | modify it under the terms of the GNU Lesser General Public |
| 9193 | @@ -17,19 +16,20 @@ |
| 9194 | License along with the GNU C Library; if not, see |
| 9195 | <http://www.gnu.org/licenses/>. */ |
| 9196 | |
| 9197 | -#include <sysdep.h> |
| 9198 | +#include <support/format_nss.h> |
| 9199 | |
| 9200 | -ENTRY(__fdimf) |
| 9201 | - st %o0, [%sp + 72] |
| 9202 | - st %o1, [%sp + 76] |
| 9203 | - ld [%sp + 72], %f0 |
| 9204 | - ld [%sp + 76], %f1 |
| 9205 | - fcmps %f0, %f1 |
| 9206 | - fbug 1f |
| 9207 | - nop |
| 9208 | - fzeros %f0 |
| 9209 | - fnegs %f0, %f1 |
| 9210 | -1: retl |
| 9211 | - fsubs %f0, %f1, %f0 |
| 9212 | -END(__fdimf) |
| 9213 | -weak_alias (__fdimf, fdimf) |
| 9214 | +#include <support/support.h> |
| 9215 | + |
| 9216 | +char * |
| 9217 | +support_format_address_family (int family) |
| 9218 | +{ |
| 9219 | + switch (family) |
| 9220 | + { |
| 9221 | + case AF_INET: |
| 9222 | + return xstrdup ("INET"); |
| 9223 | + case AF_INET6: |
| 9224 | + return xstrdup ("INET6"); |
| 9225 | + default: |
| 9226 | + return xasprintf ("<unknown address family %d>", family); |
| 9227 | + } |
| 9228 | +} |
| 9229 | diff --git a/support/support_format_addrinfo.c b/support/support_format_addrinfo.c |
| 9230 | new file mode 100644 |
| 9231 | index 0000000000..eedb030591 |
| 9232 | --- /dev/null |
| 9233 | +++ b/support/support_format_addrinfo.c |
| 9234 | @@ -0,0 +1,239 @@ |
| 9235 | +/* Convert struct addrinfo values to a string. |
| 9236 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 9237 | + This file is part of the GNU C Library. |
| 9238 | + |
| 9239 | + The GNU C Library is free software; you can redistribute it and/or |
| 9240 | + modify it under the terms of the GNU Lesser General Public |
| 9241 | + License as published by the Free Software Foundation; either |
| 9242 | + version 2.1 of the License, or (at your option) any later version. |
| 9243 | + |
| 9244 | + The GNU C Library is distributed in the hope that it will be useful, |
| 9245 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9246 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 9247 | + Lesser General Public License for more details. |
| 9248 | + |
| 9249 | + You should have received a copy of the GNU Lesser General Public |
| 9250 | + License along with the GNU C Library; if not, see |
| 9251 | + <http://www.gnu.org/licenses/>. */ |
| 9252 | + |
| 9253 | +#include <support/format_nss.h> |
| 9254 | + |
| 9255 | +#include <arpa/inet.h> |
| 9256 | +#include <errno.h> |
| 9257 | +#include <stdio.h> |
| 9258 | +#include <support/support.h> |
| 9259 | +#include <support/xmemstream.h> |
| 9260 | + |
| 9261 | +static size_t |
| 9262 | +socket_address_length (int family) |
| 9263 | +{ |
| 9264 | + switch (family) |
| 9265 | + { |
| 9266 | + case AF_INET: |
| 9267 | + return sizeof (struct sockaddr_in); |
| 9268 | + case AF_INET6: |
| 9269 | + return sizeof (struct sockaddr_in6); |
| 9270 | + default: |
| 9271 | + return -1; |
| 9272 | + } |
| 9273 | +} |
| 9274 | + |
| 9275 | +static void |
| 9276 | +format_ai_flags_1 (FILE *out, struct addrinfo *ai, int flag, const char *name, |
| 9277 | + int * flags_printed) |
| 9278 | +{ |
| 9279 | + if ((ai->ai_flags & flag) != 0) |
| 9280 | + fprintf (out, " %s", name); |
| 9281 | + *flags_printed |= flag; |
| 9282 | +} |
| 9283 | + |
| 9284 | +static void |
| 9285 | +format_ai_flags (FILE *out, struct addrinfo *ai) |
| 9286 | +{ |
| 9287 | + if (ai == NULL) |
| 9288 | + return; |
| 9289 | + |
| 9290 | + if (ai->ai_flags != 0) |
| 9291 | + { |
| 9292 | + fprintf (out, "flags:"); |
| 9293 | + int flags_printed = 0; |
| 9294 | +#define FLAG(flag) format_ai_flags_1 (out, ai, flag, #flag, &flags_printed) |
| 9295 | + FLAG (AI_PASSIVE); |
| 9296 | + FLAG (AI_CANONNAME); |
| 9297 | + FLAG (AI_NUMERICHOST); |
| 9298 | + FLAG (AI_V4MAPPED); |
| 9299 | + FLAG (AI_ALL); |
| 9300 | + FLAG (AI_ADDRCONFIG); |
| 9301 | + FLAG (AI_IDN); |
| 9302 | + FLAG (AI_CANONIDN); |
| 9303 | + FLAG (AI_IDN_ALLOW_UNASSIGNED); |
| 9304 | + FLAG (AI_IDN_USE_STD3_ASCII_RULES); |
| 9305 | + FLAG (AI_NUMERICSERV); |
| 9306 | +#undef FLAG |
| 9307 | + int remaining = ai->ai_flags & ~flags_printed; |
| 9308 | + if (remaining != 0) |
| 9309 | + fprintf (out, " %08x", remaining); |
| 9310 | + fprintf (out, "\n"); |
| 9311 | + } |
| 9312 | + |
| 9313 | + /* Report flag mismatches within the list. */ |
| 9314 | + int flags = ai->ai_flags; |
| 9315 | + int index = 1; |
| 9316 | + ai = ai->ai_next; |
| 9317 | + while (ai != NULL) |
| 9318 | + { |
| 9319 | + if (ai->ai_flags != flags) |
| 9320 | + fprintf (out, "error: flags at %d: 0x%x expected, 0x%x actual\n", |
| 9321 | + index, flags, ai->ai_flags); |
| 9322 | + ai = ai->ai_next; |
| 9323 | + ++index; |
| 9324 | + } |
| 9325 | +} |
| 9326 | + |
| 9327 | +static void |
| 9328 | +format_ai_canonname (FILE *out, struct addrinfo *ai) |
| 9329 | +{ |
| 9330 | + if (ai == NULL) |
| 9331 | + return; |
| 9332 | + if (ai->ai_canonname != NULL) |
| 9333 | + fprintf (out, "canonname: %s\n", ai->ai_canonname); |
| 9334 | + |
| 9335 | + /* Report incorrectly set ai_canonname fields on subsequent list |
| 9336 | + entries. */ |
| 9337 | + int index = 1; |
| 9338 | + ai = ai->ai_next; |
| 9339 | + while (ai != NULL) |
| 9340 | + { |
| 9341 | + if (ai->ai_canonname != NULL) |
| 9342 | + fprintf (out, "error: canonname set at %d: %s\n", |
| 9343 | + index, ai->ai_canonname); |
| 9344 | + ai = ai->ai_next; |
| 9345 | + ++index; |
| 9346 | + } |
| 9347 | +} |
| 9348 | + |
| 9349 | +static void |
| 9350 | +format_ai_one (FILE *out, struct addrinfo *ai) |
| 9351 | +{ |
| 9352 | + { |
| 9353 | + char type_buf[32]; |
| 9354 | + const char *type_str; |
| 9355 | + char proto_buf[32]; |
| 9356 | + const char *proto_str; |
| 9357 | + |
| 9358 | + /* ai_socktype */ |
| 9359 | + switch (ai->ai_socktype) |
| 9360 | + { |
| 9361 | + case SOCK_RAW: |
| 9362 | + type_str = "RAW"; |
| 9363 | + break; |
| 9364 | + case SOCK_DGRAM: |
| 9365 | + type_str = "DGRAM"; |
| 9366 | + break; |
| 9367 | + case SOCK_STREAM: |
| 9368 | + type_str = "STREAM"; |
| 9369 | + break; |
| 9370 | + default: |
| 9371 | + snprintf (type_buf, sizeof (type_buf), "%d", ai->ai_socktype); |
| 9372 | + type_str = type_buf; |
| 9373 | + } |
| 9374 | + |
| 9375 | + /* ai_protocol */ |
| 9376 | + switch (ai->ai_protocol) |
| 9377 | + { |
| 9378 | + case IPPROTO_IP: |
| 9379 | + proto_str = "IP"; |
| 9380 | + break; |
| 9381 | + case IPPROTO_UDP: |
| 9382 | + proto_str = "UDP"; |
| 9383 | + break; |
| 9384 | + case IPPROTO_TCP: |
| 9385 | + proto_str = "TCP"; |
| 9386 | + break; |
| 9387 | + default: |
| 9388 | + snprintf (proto_buf, sizeof (proto_buf), "%d", ai->ai_protocol); |
| 9389 | + proto_str = proto_buf; |
| 9390 | + } |
| 9391 | + fprintf (out, "address: %s/%s", type_str, proto_str); |
| 9392 | + } |
| 9393 | + |
| 9394 | + /* ai_addrlen */ |
| 9395 | + if (ai->ai_addrlen != socket_address_length (ai->ai_family)) |
| 9396 | + { |
| 9397 | + char *family = support_format_address_family (ai->ai_family); |
| 9398 | + fprintf (out, "error: invalid address length %d for %s\n", |
| 9399 | + ai->ai_addrlen, family); |
| 9400 | + free (family); |
| 9401 | + } |
| 9402 | + |
| 9403 | + /* ai_addr */ |
| 9404 | + { |
| 9405 | + char buf[128]; |
| 9406 | + uint16_t port; |
| 9407 | + const char *ret; |
| 9408 | + switch (ai->ai_family) |
| 9409 | + { |
| 9410 | + case AF_INET: |
| 9411 | + { |
| 9412 | + struct sockaddr_in *sin = (struct sockaddr_in *) ai->ai_addr; |
| 9413 | + ret = inet_ntop (AF_INET, &sin->sin_addr, buf, sizeof (buf)); |
| 9414 | + port = sin->sin_port; |
| 9415 | + } |
| 9416 | + break; |
| 9417 | + case AF_INET6: |
| 9418 | + { |
| 9419 | + struct sockaddr_in6 *sin = (struct sockaddr_in6 *) ai->ai_addr; |
| 9420 | + ret = inet_ntop (AF_INET6, &sin->sin6_addr, buf, sizeof (buf)); |
| 9421 | + port = sin->sin6_port; |
| 9422 | + } |
| 9423 | + break; |
| 9424 | + default: |
| 9425 | + errno = EAFNOSUPPORT; |
| 9426 | + ret = NULL; |
| 9427 | + } |
| 9428 | + if (ret == NULL) |
| 9429 | + fprintf (out, "error: inet_top failed: %m\n"); |
| 9430 | + else |
| 9431 | + fprintf (out, " %s %u\n", buf, ntohs (port)); |
| 9432 | + } |
| 9433 | +} |
| 9434 | + |
| 9435 | +/* Format all the addresses in one address family. */ |
| 9436 | +static void |
| 9437 | +format_ai_family (FILE *out, struct addrinfo *ai, int family) |
| 9438 | +{ |
| 9439 | + while (ai) |
| 9440 | + { |
| 9441 | + if (ai->ai_family == family) |
| 9442 | + format_ai_one (out, ai); |
| 9443 | + ai = ai->ai_next; |
| 9444 | + } |
| 9445 | +} |
| 9446 | + |
| 9447 | +char * |
| 9448 | +support_format_addrinfo (struct addrinfo *ai, int ret) |
| 9449 | +{ |
| 9450 | + int errno_copy = errno; |
| 9451 | + |
| 9452 | + struct xmemstream mem; |
| 9453 | + xopen_memstream (&mem); |
| 9454 | + if (ret != 0) |
| 9455 | + { |
| 9456 | + fprintf (mem.out, "error: %s\n", gai_strerror (ret)); |
| 9457 | + if (ret == EAI_SYSTEM) |
| 9458 | + { |
| 9459 | + errno = errno_copy; |
| 9460 | + fprintf (mem.out, "error: %m\n"); |
| 9461 | + } |
| 9462 | + } |
| 9463 | + else |
| 9464 | + { |
| 9465 | + format_ai_flags (mem.out, ai); |
| 9466 | + format_ai_canonname (mem.out, ai); |
| 9467 | + format_ai_family (mem.out, ai, AF_INET); |
| 9468 | + format_ai_family (mem.out, ai, AF_INET6); |
| 9469 | + } |
| 9470 | + |
| 9471 | + xfclose_memstream (&mem); |
| 9472 | + return mem.buffer; |
| 9473 | +} |
| 9474 | diff --git a/support/support_format_dns_packet.c b/support/support_format_dns_packet.c |
| 9475 | new file mode 100644 |
| 9476 | index 0000000000..2992c57971 |
| 9477 | --- /dev/null |
| 9478 | +++ b/support/support_format_dns_packet.c |
| 9479 | @@ -0,0 +1,222 @@ |
| 9480 | +/* Convert a DNS packet to a human-readable representation. |
| 9481 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 9482 | + This file is part of the GNU C Library. |
| 9483 | + |
| 9484 | + The GNU C Library is free software; you can redistribute it and/or |
| 9485 | + modify it under the terms of the GNU Lesser General Public |
| 9486 | + License as published by the Free Software Foundation; either |
| 9487 | + version 2.1 of the License, or (at your option) any later version. |
| 9488 | + |
| 9489 | + The GNU C Library is distributed in the hope that it will be useful, |
| 9490 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9491 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 9492 | + Lesser General Public License for more details. |
| 9493 | + |
| 9494 | + You should have received a copy of the GNU Lesser General Public |
| 9495 | + License along with the GNU C Library; if not, see |
| 9496 | + <http://www.gnu.org/licenses/>. */ |
| 9497 | + |
| 9498 | +#include <support/format_nss.h> |
| 9499 | + |
| 9500 | +#include <arpa/inet.h> |
| 9501 | +#include <resolv.h> |
| 9502 | +#include <support/check.h> |
| 9503 | +#include <support/support.h> |
| 9504 | +#include <support/xmemstream.h> |
| 9505 | + |
| 9506 | +struct in_buffer |
| 9507 | +{ |
| 9508 | + const unsigned char *data; |
| 9509 | + size_t size; |
| 9510 | +}; |
| 9511 | + |
| 9512 | +static inline bool |
| 9513 | +extract_8 (struct in_buffer *in, unsigned char *value) |
| 9514 | +{ |
| 9515 | + if (in->size == 0) |
| 9516 | + return false; |
| 9517 | + *value = in->data[0]; |
| 9518 | + ++in->data; |
| 9519 | + --in->size; |
| 9520 | + return true; |
| 9521 | +} |
| 9522 | + |
| 9523 | +static inline bool |
| 9524 | +extract_16 (struct in_buffer *in, unsigned short *value) |
| 9525 | +{ |
| 9526 | + if (in->size < 2) |
| 9527 | + return false; |
| 9528 | + *value = (in->data[0] << 8) | in->data[1]; |
| 9529 | + in->data += 2; |
| 9530 | + in->size -= 2; |
| 9531 | + return true; |
| 9532 | +} |
| 9533 | + |
| 9534 | +static inline bool |
| 9535 | +extract_32 (struct in_buffer *in, unsigned *value) |
| 9536 | +{ |
| 9537 | + if (in->size < 4) |
| 9538 | + return false; |
| 9539 | + unsigned a = in->data[0]; |
| 9540 | + unsigned b = in->data[1]; |
| 9541 | + unsigned c = in->data[2]; |
| 9542 | + unsigned d = in->data[3]; |
| 9543 | + *value = (a << 24) | (b << 16) | (c << 8) | d; |
| 9544 | + in->data += 4; |
| 9545 | + in->size -= 4; |
| 9546 | + return true; |
| 9547 | +} |
| 9548 | + |
| 9549 | +static inline bool |
| 9550 | +extract_bytes (struct in_buffer *in, size_t length, struct in_buffer *value) |
| 9551 | +{ |
| 9552 | + if (in->size < length) |
| 9553 | + return false; |
| 9554 | + *value = (struct in_buffer) {in->data, length}; |
| 9555 | + in->data += length; |
| 9556 | + in->size -= length; |
| 9557 | + return true; |
| 9558 | +} |
| 9559 | + |
| 9560 | +struct dname |
| 9561 | +{ |
| 9562 | + char name[MAXDNAME + 1]; |
| 9563 | +}; |
| 9564 | + |
| 9565 | +static bool |
| 9566 | +extract_name (struct in_buffer full, struct in_buffer *in, struct dname *value) |
| 9567 | +{ |
| 9568 | + const unsigned char *full_end = full.data + full.size; |
| 9569 | + /* Sanity checks; these indicate buffer misuse. */ |
| 9570 | + TEST_VERIFY_EXIT |
| 9571 | + (!(in->data < full.data || in->data > full_end |
| 9572 | + || in->size > (size_t) (full_end - in->data))); |
| 9573 | + int ret = dn_expand (full.data, full_end, in->data, |
| 9574 | + value->name, sizeof (value->name)); |
| 9575 | + if (ret < 0) |
| 9576 | + return false; |
| 9577 | + in->data += ret; |
| 9578 | + in->size -= ret; |
| 9579 | + return true; |
| 9580 | +} |
| 9581 | + |
| 9582 | +char * |
| 9583 | +support_format_dns_packet (const unsigned char *buffer, size_t length) |
| 9584 | +{ |
| 9585 | + struct in_buffer full = { buffer, length }; |
| 9586 | + struct in_buffer in = full; |
| 9587 | + struct xmemstream mem; |
| 9588 | + xopen_memstream (&mem); |
| 9589 | + |
| 9590 | + unsigned short txnid; |
| 9591 | + unsigned short flags; |
| 9592 | + unsigned short qdcount; |
| 9593 | + unsigned short ancount; |
| 9594 | + unsigned short nscount; |
| 9595 | + unsigned short adcount; |
| 9596 | + if (!(extract_16 (&in, &txnid) |
| 9597 | + && extract_16 (&in, &flags) |
| 9598 | + && extract_16 (&in, &qdcount) |
| 9599 | + && extract_16 (&in, &ancount) |
| 9600 | + && extract_16 (&in, &nscount) |
| 9601 | + && extract_16 (&in, &adcount))) |
| 9602 | + { |
| 9603 | + fprintf (mem.out, "error: could not parse DNS header\n"); |
| 9604 | + goto out; |
| 9605 | + } |
| 9606 | + if (qdcount != 1) |
| 9607 | + { |
| 9608 | + fprintf (mem.out, "error: question count is %d, not 1\n", qdcount); |
| 9609 | + goto out; |
| 9610 | + } |
| 9611 | + struct dname qname; |
| 9612 | + if (!extract_name (full, &in, &qname)) |
| 9613 | + { |
| 9614 | + fprintf (mem.out, "error: malformed QNAME\n"); |
| 9615 | + goto out; |
| 9616 | + } |
| 9617 | + unsigned short qtype; |
| 9618 | + unsigned short qclass; |
| 9619 | + if (!(extract_16 (&in, &qtype) |
| 9620 | + && extract_16 (&in, &qclass))) |
| 9621 | + { |
| 9622 | + fprintf (mem.out, "error: malformed question\n"); |
| 9623 | + goto out; |
| 9624 | + } |
| 9625 | + if (qtype != T_A && qtype != T_AAAA && qtype != T_PTR) |
| 9626 | + { |
| 9627 | + fprintf (mem.out, "error: unsupported QTYPE %d\n", qtype); |
| 9628 | + goto out; |
| 9629 | + } |
| 9630 | + |
| 9631 | + fprintf (mem.out, "name: %s\n", qname.name); |
| 9632 | + |
| 9633 | + for (int i = 0; i < ancount; ++i) |
| 9634 | + { |
| 9635 | + struct dname rname; |
| 9636 | + if (!extract_name (full, &in, &rname)) |
| 9637 | + { |
| 9638 | + fprintf (mem.out, "error: malformed record name\n"); |
| 9639 | + goto out; |
| 9640 | + } |
| 9641 | + unsigned short rtype; |
| 9642 | + unsigned short rclass; |
| 9643 | + unsigned ttl; |
| 9644 | + unsigned short rdlen; |
| 9645 | + struct in_buffer rdata; |
| 9646 | + if (!(extract_16 (&in, &rtype) |
| 9647 | + && extract_16 (&in, &rclass) |
| 9648 | + && extract_32 (&in, &ttl) |
| 9649 | + && extract_16 (&in, &rdlen) |
| 9650 | + && extract_bytes (&in, rdlen, &rdata))) |
| 9651 | + { |
| 9652 | + fprintf (mem.out, "error: malformed record header\n"); |
| 9653 | + goto out; |
| 9654 | + } |
| 9655 | + /* Skip non-matching record types. */ |
| 9656 | + if ((rtype != qtype && rtype != T_CNAME) || rclass != qclass) |
| 9657 | + continue; |
| 9658 | + switch (rtype) |
| 9659 | + { |
| 9660 | + case T_A: |
| 9661 | + if (rdlen == 4) |
| 9662 | + fprintf (mem.out, "address: %d.%d.%d.%d\n", |
| 9663 | + rdata.data[0], |
| 9664 | + rdata.data[1], |
| 9665 | + rdata.data[2], |
| 9666 | + rdata.data[3]); |
| 9667 | + else |
| 9668 | + fprintf (mem.out, "error: A record of size %d: %s\n", |
| 9669 | + rdlen, rname.name); |
| 9670 | + break; |
| 9671 | + case T_AAAA: |
| 9672 | + { |
| 9673 | + if (rdlen == 16) |
| 9674 | + { |
| 9675 | + char buf[100]; |
| 9676 | + if (inet_ntop (AF_INET6, rdata.data, buf, sizeof (buf)) == NULL) |
| 9677 | + fprintf (mem.out, "error: AAAA record decoding failed: %m\n"); |
| 9678 | + else |
| 9679 | + fprintf (mem.out, "address: %s\n", buf); |
| 9680 | + } |
| 9681 | + else |
| 9682 | + fprintf (mem.out, "error: AAAA record of size %d: %s\n", |
| 9683 | + rdlen, rname.name); |
| 9684 | + } |
| 9685 | + break; |
| 9686 | + case T_CNAME: |
| 9687 | + case T_PTR: |
| 9688 | + { |
| 9689 | + struct dname name; |
| 9690 | + if (extract_name (full, &rdata, &name)) |
| 9691 | + fprintf (mem.out, "name: %s\n", name.name); |
| 9692 | + else |
| 9693 | + fprintf (mem.out, "error: malformed CNAME/PTR record\n"); |
| 9694 | + } |
| 9695 | + } |
| 9696 | + } |
| 9697 | + |
| 9698 | + out: |
| 9699 | + xfclose_memstream (&mem); |
| 9700 | + return mem.buffer; |
| 9701 | +} |
| 9702 | diff --git a/support/support_format_herrno.c b/support/support_format_herrno.c |
| 9703 | new file mode 100644 |
| 9704 | index 0000000000..493d6ae962 |
| 9705 | --- /dev/null |
| 9706 | +++ b/support/support_format_herrno.c |
| 9707 | @@ -0,0 +1,45 @@ |
| 9708 | +/* Convert a h_errno error code to a string. |
| 9709 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 9710 | + This file is part of the GNU C Library. |
| 9711 | + |
| 9712 | + The GNU C Library is free software; you can redistribute it and/or |
| 9713 | + modify it under the terms of the GNU Lesser General Public |
| 9714 | + License as published by the Free Software Foundation; either |
| 9715 | + version 2.1 of the License, or (at your option) any later version. |
| 9716 | + |
| 9717 | + The GNU C Library is distributed in the hope that it will be useful, |
| 9718 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9719 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 9720 | + Lesser General Public License for more details. |
| 9721 | + |
| 9722 | + You should have received a copy of the GNU Lesser General Public |
| 9723 | + License along with the GNU C Library; if not, see |
| 9724 | + <http://www.gnu.org/licenses/>. */ |
| 9725 | + |
| 9726 | +#include <support/format_nss.h> |
| 9727 | + |
| 9728 | +#include <support/support.h> |
| 9729 | + |
| 9730 | +char * |
| 9731 | +support_format_herrno (int code) |
| 9732 | +{ |
| 9733 | + const char *errstr; |
| 9734 | + switch (code) |
| 9735 | + { |
| 9736 | + case HOST_NOT_FOUND: |
| 9737 | + errstr = "HOST_NOT_FOUND"; |
| 9738 | + break; |
| 9739 | + case NO_ADDRESS: |
| 9740 | + errstr = "NO_ADDRESS"; |
| 9741 | + break; |
| 9742 | + case NO_RECOVERY: |
| 9743 | + errstr = "NO_RECOVERY"; |
| 9744 | + break; |
| 9745 | + case TRY_AGAIN: |
| 9746 | + errstr = "TRY_AGAIN"; |
| 9747 | + break; |
| 9748 | + default: |
| 9749 | + return xasprintf ("<invalid h_errno value %d>\n", code); |
| 9750 | + } |
| 9751 | + return xstrdup (errstr); |
| 9752 | +} |
| 9753 | diff --git a/support/support_format_hostent.c b/support/support_format_hostent.c |
| 9754 | new file mode 100644 |
| 9755 | index 0000000000..5b5f26082e |
| 9756 | --- /dev/null |
| 9757 | +++ b/support/support_format_hostent.c |
| 9758 | @@ -0,0 +1,75 @@ |
| 9759 | +/* Convert a struct hostent object to a string. |
| 9760 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 9761 | + This file is part of the GNU C Library. |
| 9762 | + |
| 9763 | + The GNU C Library is free software; you can redistribute it and/or |
| 9764 | + modify it under the terms of the GNU Lesser General Public |
| 9765 | + License as published by the Free Software Foundation; either |
| 9766 | + version 2.1 of the License, or (at your option) any later version. |
| 9767 | + |
| 9768 | + The GNU C Library is distributed in the hope that it will be useful, |
| 9769 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9770 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 9771 | + Lesser General Public License for more details. |
| 9772 | + |
| 9773 | + You should have received a copy of the GNU Lesser General Public |
| 9774 | + License along with the GNU C Library; if not, see |
| 9775 | + <http://www.gnu.org/licenses/>. */ |
| 9776 | + |
| 9777 | +#include <support/format_nss.h> |
| 9778 | + |
| 9779 | +#include <arpa/inet.h> |
| 9780 | +#include <stdio.h> |
| 9781 | +#include <support/support.h> |
| 9782 | +#include <support/xmemstream.h> |
| 9783 | + |
| 9784 | +static int |
| 9785 | +address_length (int family) |
| 9786 | +{ |
| 9787 | + switch (family) |
| 9788 | + { |
| 9789 | + case AF_INET: |
| 9790 | + return 4; |
| 9791 | + case AF_INET6: |
| 9792 | + return 16; |
| 9793 | + } |
| 9794 | + return -1; |
| 9795 | +} |
| 9796 | + |
| 9797 | +char * |
| 9798 | +support_format_hostent (struct hostent *h) |
| 9799 | +{ |
| 9800 | + if (h == NULL) |
| 9801 | + { |
| 9802 | + char *value = support_format_herrno (h_errno); |
| 9803 | + char *result = xasprintf ("error: %s\n", value); |
| 9804 | + free (value); |
| 9805 | + return result; |
| 9806 | + } |
| 9807 | + |
| 9808 | + struct xmemstream mem; |
| 9809 | + xopen_memstream (&mem); |
| 9810 | + |
| 9811 | + fprintf (mem.out, "name: %s\n", h->h_name); |
| 9812 | + for (char **alias = h->h_aliases; *alias != NULL; ++alias) |
| 9813 | + fprintf (mem.out, "alias: %s\n", *alias); |
| 9814 | + for (unsigned i = 0; h->h_addr_list[i] != NULL; ++i) |
| 9815 | + { |
| 9816 | + char buf[128]; |
| 9817 | + if (inet_ntop (h->h_addrtype, h->h_addr_list[i], |
| 9818 | + buf, sizeof (buf)) == NULL) |
| 9819 | + fprintf (mem.out, "error: inet_ntop failed: %m\n"); |
| 9820 | + else |
| 9821 | + fprintf (mem.out, "address: %s\n", buf); |
| 9822 | + } |
| 9823 | + if (h->h_length != address_length (h->h_addrtype)) |
| 9824 | + { |
| 9825 | + char *family = support_format_address_family (h->h_addrtype); |
| 9826 | + fprintf (mem.out, "error: invalid address length %d for %s\n", |
| 9827 | + h->h_length, family); |
| 9828 | + free (family); |
| 9829 | + } |
| 9830 | + |
| 9831 | + xfclose_memstream (&mem); |
| 9832 | + return mem.buffer; |
| 9833 | +} |
| 9834 | diff --git a/support/support_format_netent.c b/support/support_format_netent.c |
| 9835 | new file mode 100644 |
| 9836 | index 0000000000..020f5720d9 |
| 9837 | --- /dev/null |
| 9838 | +++ b/support/support_format_netent.c |
| 9839 | @@ -0,0 +1,52 @@ |
| 9840 | +/* Convert a struct netent object to a string. |
| 9841 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 9842 | + This file is part of the GNU C Library. |
| 9843 | + |
| 9844 | + The GNU C Library is free software; you can redistribute it and/or |
| 9845 | + modify it under the terms of the GNU Lesser General Public |
| 9846 | + License as published by the Free Software Foundation; either |
| 9847 | + version 2.1 of the License, or (at your option) any later version. |
| 9848 | + |
| 9849 | + The GNU C Library is distributed in the hope that it will be useful, |
| 9850 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9851 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 9852 | + Lesser General Public License for more details. |
| 9853 | + |
| 9854 | + You should have received a copy of the GNU Lesser General Public |
| 9855 | + License along with the GNU C Library; if not, see |
| 9856 | + <http://www.gnu.org/licenses/>. */ |
| 9857 | + |
| 9858 | +#include <support/format_nss.h> |
| 9859 | + |
| 9860 | +#include <arpa/inet.h> |
| 9861 | +#include <stdio.h> |
| 9862 | +#include <support/support.h> |
| 9863 | +#include <support/xmemstream.h> |
| 9864 | + |
| 9865 | +char * |
| 9866 | +support_format_netent (struct netent *e) |
| 9867 | +{ |
| 9868 | + if (e == NULL) |
| 9869 | + { |
| 9870 | + char *value = support_format_herrno (h_errno); |
| 9871 | + char *result = xasprintf ("error: %s\n", value); |
| 9872 | + free (value); |
| 9873 | + return result; |
| 9874 | + } |
| 9875 | + |
| 9876 | + struct xmemstream mem; |
| 9877 | + xopen_memstream (&mem); |
| 9878 | + |
| 9879 | + if (e->n_name != NULL) |
| 9880 | + fprintf (mem.out, "name: %s\n", e->n_name); |
| 9881 | + for (char **ap = e->n_aliases; *ap != NULL; ++ap) |
| 9882 | + fprintf (mem.out, "alias: %s\n", *ap); |
| 9883 | + if (e->n_addrtype != AF_INET) |
| 9884 | + fprintf (mem.out, "addrtype: %d\n", e->n_addrtype); |
| 9885 | + /* On alpha, e->n_net is an unsigned long. */ |
| 9886 | + unsigned int n_net = e->n_net; |
| 9887 | + fprintf (mem.out, "net: 0x%08x\n", n_net); |
| 9888 | + |
| 9889 | + xfclose_memstream (&mem); |
| 9890 | + return mem.buffer; |
| 9891 | +} |
| 9892 | diff --git a/support/support_isolate_in_subprocess.c b/support/support_isolate_in_subprocess.c |
| 9893 | new file mode 100644 |
| 9894 | index 0000000000..cf48614383 |
| 9895 | --- /dev/null |
| 9896 | +++ b/support/support_isolate_in_subprocess.c |
| 9897 | @@ -0,0 +1,38 @@ |
| 9898 | +/* Run a function in a subprocess. |
| 9899 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 9900 | + This file is part of the GNU C Library. |
| 9901 | + |
| 9902 | + The GNU C Library is free software; you can redistribute it and/or |
| 9903 | + modify it under the terms of the GNU Lesser General Public |
| 9904 | + License as published by the Free Software Foundation; either |
| 9905 | + version 2.1 of the License, or (at your option) any later version. |
| 9906 | + |
| 9907 | + The GNU C Library is distributed in the hope that it will be useful, |
| 9908 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9909 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 9910 | + Lesser General Public License for more details. |
| 9911 | + |
| 9912 | + You should have received a copy of the GNU Lesser General Public |
| 9913 | + License along with the GNU C Library; if not, see |
| 9914 | + <http://www.gnu.org/licenses/>. */ |
| 9915 | + |
| 9916 | +#include <support/check.h> |
| 9917 | +#include <support/xunistd.h> |
| 9918 | + |
| 9919 | +void |
| 9920 | +support_isolate_in_subprocess (void (*callback) (void *), void *closure) |
| 9921 | +{ |
| 9922 | + pid_t pid = xfork (); |
| 9923 | + if (pid == 0) |
| 9924 | + { |
| 9925 | + /* Child process. */ |
| 9926 | + callback (closure); |
| 9927 | + _exit (0); |
| 9928 | + } |
| 9929 | + |
| 9930 | + /* Parent process. */ |
| 9931 | + int status; |
| 9932 | + xwaitpid (pid, &status, 0); |
| 9933 | + if (status != 0) |
| 9934 | + FAIL_EXIT1 ("child process exited with status %d", status); |
| 9935 | +} |
| 9936 | diff --git a/support/support_record_failure.c b/support/support_record_failure.c |
| 9937 | new file mode 100644 |
| 9938 | index 0000000000..684055c746 |
| 9939 | --- /dev/null |
| 9940 | +++ b/support/support_record_failure.c |
| 9941 | @@ -0,0 +1,106 @@ |
| 9942 | +/* Global test failure counter. |
| 9943 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 9944 | + This file is part of the GNU C Library. |
| 9945 | + |
| 9946 | + The GNU C Library is free software; you can redistribute it and/or |
| 9947 | + modify it under the terms of the GNU Lesser General Public |
| 9948 | + License as published by the Free Software Foundation; either |
| 9949 | + version 2.1 of the License, or (at your option) any later version. |
| 9950 | + |
| 9951 | + The GNU C Library is distributed in the hope that it will be useful, |
| 9952 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9953 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 9954 | + Lesser General Public License for more details. |
| 9955 | + |
| 9956 | + You should have received a copy of the GNU Lesser General Public |
| 9957 | + License along with the GNU C Library; if not, see |
| 9958 | + <http://www.gnu.org/licenses/>. */ |
| 9959 | + |
| 9960 | +#include <support/check.h> |
| 9961 | +#include <support/support.h> |
| 9962 | +#include <support/test-driver.h> |
| 9963 | + |
| 9964 | +#include <stdbool.h> |
| 9965 | +#include <stdio.h> |
| 9966 | +#include <stdlib.h> |
| 9967 | +#include <sys/mman.h> |
| 9968 | +#include <unistd.h> |
| 9969 | + |
| 9970 | +/* This structure keeps track of test failures. The counter is |
| 9971 | + incremented on each failure. The failed member is set to true if a |
| 9972 | + failure is detected, so that even if the counter wraps around to |
| 9973 | + zero, the failure of a test can be detected. |
| 9974 | + |
| 9975 | + The init constructor function below puts *state on a shared |
| 9976 | + annonymous mapping, so that failure reports from subprocesses |
| 9977 | + propagate to the parent process. */ |
| 9978 | +struct test_failures |
| 9979 | +{ |
| 9980 | + unsigned int counter; |
| 9981 | + unsigned int failed; |
| 9982 | +}; |
| 9983 | +static struct test_failures *state; |
| 9984 | + |
| 9985 | +static __attribute__ ((constructor)) void |
| 9986 | +init (void) |
| 9987 | +{ |
| 9988 | + void *ptr = mmap (NULL, sizeof (*state), PROT_READ | PROT_WRITE, |
| 9989 | + MAP_ANONYMOUS | MAP_SHARED, -1, 0); |
| 9990 | + if (ptr == MAP_FAILED) |
| 9991 | + { |
| 9992 | + printf ("error: could not map %zu bytes: %m\n", sizeof (*state)); |
| 9993 | + exit (1); |
| 9994 | + } |
| 9995 | + /* Zero-initialization of the struct is sufficient. */ |
| 9996 | + state = ptr; |
| 9997 | +} |
| 9998 | + |
| 9999 | +void |
| 10000 | +support_record_failure (void) |
| 10001 | +{ |
| 10002 | + if (state == NULL) |
| 10003 | + { |
| 10004 | + write_message |
| 10005 | + ("error: support_record_failure called without initialization\n"); |
| 10006 | + _exit (1); |
| 10007 | + } |
| 10008 | + /* Relaxed MO is sufficient because we are only interested in the |
| 10009 | + values themselves, in isolation. */ |
| 10010 | + __atomic_store_n (&state->failed, 1, __ATOMIC_RELEASE); |
| 10011 | + __atomic_add_fetch (&state->counter, 1, __ATOMIC_RELEASE); |
| 10012 | +} |
| 10013 | + |
| 10014 | +int |
| 10015 | +support_report_failure (int status) |
| 10016 | +{ |
| 10017 | + if (state == NULL) |
| 10018 | + { |
| 10019 | + write_message |
| 10020 | + ("error: support_report_failure called without initialization\n"); |
| 10021 | + return 1; |
| 10022 | + } |
| 10023 | + |
| 10024 | + /* Relaxed MO is sufficient because acquire test result reporting |
| 10025 | + assumes that exiting from the main thread happens before the |
| 10026 | + error reporting via support_record_failure, which requires some |
| 10027 | + form of external synchronization. */ |
| 10028 | + bool failed = __atomic_load_n (&state->failed, __ATOMIC_RELAXED); |
| 10029 | + if (failed) |
| 10030 | + printf ("error: %u test failures\n", |
| 10031 | + __atomic_load_n (&state->counter, __ATOMIC_RELAXED)); |
| 10032 | + |
| 10033 | + if ((status == 0 || status == EXIT_UNSUPPORTED) && failed) |
| 10034 | + /* If we have a recorded failure, it overrides a non-failure |
| 10035 | + report from the test function. */ |
| 10036 | + status = 1; |
| 10037 | + return status; |
| 10038 | +} |
| 10039 | + |
| 10040 | +void |
| 10041 | +support_record_failure_reset (void) |
| 10042 | +{ |
| 10043 | + /* Only used for testing the test framework, with external |
| 10044 | + synchronization, but use release MO for consistency. */ |
| 10045 | + __atomic_store_n (&state->failed, 0, __ATOMIC_RELAXED); |
| 10046 | + __atomic_add_fetch (&state->counter, 0, __ATOMIC_RELAXED); |
| 10047 | +} |
| 10048 | diff --git a/support/support_run_diff.c b/support/support_run_diff.c |
| 10049 | new file mode 100644 |
| 10050 | index 0000000000..f5155de727 |
| 10051 | --- /dev/null |
| 10052 | +++ b/support/support_run_diff.c |
| 10053 | @@ -0,0 +1,76 @@ |
| 10054 | +/* Invoke the system diff tool to compare two strings. |
| 10055 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 10056 | + This file is part of the GNU C Library. |
| 10057 | + |
| 10058 | + The GNU C Library is free software; you can redistribute it and/or |
| 10059 | + modify it under the terms of the GNU Lesser General Public |
| 10060 | + License as published by the Free Software Foundation; either |
| 10061 | + version 2.1 of the License, or (at your option) any later version. |
| 10062 | + |
| 10063 | + The GNU C Library is distributed in the hope that it will be useful, |
| 10064 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10065 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 10066 | + Lesser General Public License for more details. |
| 10067 | + |
| 10068 | + You should have received a copy of the GNU Lesser General Public |
| 10069 | + License along with the GNU C Library; if not, see |
| 10070 | + <http://www.gnu.org/licenses/>. */ |
| 10071 | + |
| 10072 | +#include <support/run_diff.h> |
| 10073 | + |
| 10074 | +#include <stdio.h> |
| 10075 | +#include <stdlib.h> |
| 10076 | +#include <string.h> |
| 10077 | +#include <support/check.h> |
| 10078 | +#include <support/support.h> |
| 10079 | +#include <support/temp_file.h> |
| 10080 | +#include <support/xunistd.h> |
| 10081 | +#include <sys/wait.h> |
| 10082 | + |
| 10083 | +static char * |
| 10084 | +write_to_temp_file (const char *prefix, const char *str) |
| 10085 | +{ |
| 10086 | + char *template = xasprintf ("run_diff-%s", prefix); |
| 10087 | + char *name = NULL; |
| 10088 | + int fd = create_temp_file (template, &name); |
| 10089 | + TEST_VERIFY_EXIT (fd >= 0); |
| 10090 | + free (template); |
| 10091 | + xwrite (fd, str, strlen (str)); |
| 10092 | + xclose (fd); |
| 10093 | + return name; |
| 10094 | +} |
| 10095 | + |
| 10096 | +void |
| 10097 | +support_run_diff (const char *left_label, const char *left, |
| 10098 | + const char *right_label, const char *right) |
| 10099 | +{ |
| 10100 | + /* Ensure that the diff command output is ordered properly with |
| 10101 | + standard output. */ |
| 10102 | + TEST_VERIFY_EXIT (fflush (stdout) == 0); |
| 10103 | + |
| 10104 | + char *left_path = write_to_temp_file ("left-diff", left); |
| 10105 | + char *right_path = write_to_temp_file ("right-diff", right); |
| 10106 | + |
| 10107 | + pid_t pid = xfork (); |
| 10108 | + if (pid == 0) |
| 10109 | + { |
| 10110 | + execlp ("diff", "diff", "-u", |
| 10111 | + "--label", left_label, "--label", right_label, |
| 10112 | + "--", left_path, right_path, |
| 10113 | + NULL); |
| 10114 | + _exit (17); |
| 10115 | + } |
| 10116 | + else |
| 10117 | + { |
| 10118 | + int status; |
| 10119 | + xwaitpid (pid, &status, 0); |
| 10120 | + if (!WIFEXITED (status) || WEXITSTATUS (status) != 1) |
| 10121 | + printf ("warning: could not run diff, exit status: %d\n" |
| 10122 | + "*** %s ***\n%s\n" |
| 10123 | + "*** %s ***\n%s\n", |
| 10124 | + status, left_label, left, right_label, right); |
| 10125 | + } |
| 10126 | + |
| 10127 | + free (right_path); |
| 10128 | + free (left_path); |
| 10129 | +} |
| 10130 | diff --git a/support/support_shared_allocate.c b/support/support_shared_allocate.c |
| 10131 | new file mode 100644 |
| 10132 | index 0000000000..61d088e8cf |
| 10133 | --- /dev/null |
| 10134 | +++ b/support/support_shared_allocate.c |
| 10135 | @@ -0,0 +1,57 @@ |
| 10136 | +/* Allocate a memory region shared across processes. |
| 10137 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 10138 | + This file is part of the GNU C Library. |
| 10139 | + |
| 10140 | + The GNU C Library is free software; you can redistribute it and/or |
| 10141 | + modify it under the terms of the GNU Lesser General Public |
| 10142 | + License as published by the Free Software Foundation; either |
| 10143 | + version 2.1 of the License, or (at your option) any later version. |
| 10144 | + |
| 10145 | + The GNU C Library is distributed in the hope that it will be useful, |
| 10146 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10147 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 10148 | + Lesser General Public License for more details. |
| 10149 | + |
| 10150 | + You should have received a copy of the GNU Lesser General Public |
| 10151 | + License along with the GNU C Library; if not, see |
| 10152 | + <http://www.gnu.org/licenses/>. */ |
| 10153 | + |
| 10154 | +#include <errno.h> |
| 10155 | +#include <stddef.h> |
| 10156 | +#include <support/support.h> |
| 10157 | +#include <support/xunistd.h> |
| 10158 | +#include <sys/mman.h> |
| 10159 | + |
| 10160 | +/* Header for the allocation. It contains the size of the allocation |
| 10161 | + for subsequent unmapping. */ |
| 10162 | +struct header |
| 10163 | +{ |
| 10164 | + size_t total_size; |
| 10165 | + char data[] __attribute__ ((aligned (__alignof__ (max_align_t)))); |
| 10166 | +}; |
| 10167 | + |
| 10168 | +void * |
| 10169 | +support_shared_allocate (size_t size) |
| 10170 | +{ |
| 10171 | + size_t total_size = size + offsetof (struct header, data); |
| 10172 | + if (total_size < size) |
| 10173 | + { |
| 10174 | + errno = ENOMEM; |
| 10175 | + oom_error (__func__, size); |
| 10176 | + return NULL; |
| 10177 | + } |
| 10178 | + else |
| 10179 | + { |
| 10180 | + struct header *result = xmmap (NULL, total_size, PROT_READ | PROT_WRITE, |
| 10181 | + MAP_ANONYMOUS | MAP_SHARED, -1); |
| 10182 | + result->total_size = total_size; |
| 10183 | + return &result->data; |
| 10184 | + } |
| 10185 | +} |
| 10186 | + |
| 10187 | +void |
| 10188 | +support_shared_free (void *data) |
| 10189 | +{ |
| 10190 | + struct header *header = data - offsetof (struct header, data); |
| 10191 | + xmunmap (header, header->total_size); |
| 10192 | +} |
| 10193 | diff --git a/support/support_test_main.c b/support/support_test_main.c |
| 10194 | new file mode 100644 |
| 10195 | index 0000000000..914d64f603 |
| 10196 | --- /dev/null |
| 10197 | +++ b/support/support_test_main.c |
| 10198 | @@ -0,0 +1,423 @@ |
| 10199 | +/* Main worker function for the test driver. |
| 10200 | + Copyright (C) 1998-2017 Free Software Foundation, Inc. |
| 10201 | + This file is part of the GNU C Library. |
| 10202 | + |
| 10203 | + The GNU C Library is free software; you can redistribute it and/or |
| 10204 | + modify it under the terms of the GNU Lesser General Public |
| 10205 | + License as published by the Free Software Foundation; either |
| 10206 | + version 2.1 of the License, or (at your option) any later version. |
| 10207 | + |
| 10208 | + The GNU C Library is distributed in the hope that it will be useful, |
| 10209 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10210 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 10211 | + Lesser General Public License for more details. |
| 10212 | + |
| 10213 | + You should have received a copy of the GNU Lesser General Public |
| 10214 | + License along with the GNU C Library; if not, see |
| 10215 | + <http://www.gnu.org/licenses/>. */ |
| 10216 | + |
| 10217 | +#include <support/test-driver.h> |
| 10218 | +#include <support/check.h> |
| 10219 | +#include <support/temp_file-internal.h> |
| 10220 | + |
| 10221 | +#include <assert.h> |
| 10222 | +#include <errno.h> |
| 10223 | +#include <getopt.h> |
| 10224 | +#include <malloc.h> |
| 10225 | +#include <signal.h> |
| 10226 | +#include <stdbool.h> |
| 10227 | +#include <stdlib.h> |
| 10228 | +#include <string.h> |
| 10229 | +#include <sys/param.h> |
| 10230 | +#include <sys/resource.h> |
| 10231 | +#include <sys/types.h> |
| 10232 | +#include <sys/wait.h> |
| 10233 | +#include <time.h> |
| 10234 | +#include <unistd.h> |
| 10235 | + |
| 10236 | +static const struct option default_options[] = |
| 10237 | +{ |
| 10238 | + TEST_DEFAULT_OPTIONS |
| 10239 | + { NULL, 0, NULL, 0 } |
| 10240 | +}; |
| 10241 | + |
| 10242 | +/* Show people how to run the program. */ |
| 10243 | +static void |
| 10244 | +usage (const struct option *options) |
| 10245 | +{ |
| 10246 | + size_t i; |
| 10247 | + |
| 10248 | + printf ("Usage: %s [options]\n" |
| 10249 | + "\n" |
| 10250 | + "Environment Variables:\n" |
| 10251 | + " TIMEOUTFACTOR An integer used to scale the timeout\n" |
| 10252 | + " TMPDIR Where to place temporary files\n" |
| 10253 | + " TEST_COREDUMPS Do not disable coredumps if set\n" |
| 10254 | + "\n", |
| 10255 | + program_invocation_short_name); |
| 10256 | + printf ("Options:\n"); |
| 10257 | + for (i = 0; options[i].name; ++i) |
| 10258 | + { |
| 10259 | + int indent; |
| 10260 | + |
| 10261 | + indent = printf (" --%s", options[i].name); |
| 10262 | + if (options[i].has_arg == required_argument) |
| 10263 | + indent += printf (" <arg>"); |
| 10264 | + printf ("%*s", 25 - indent, ""); |
| 10265 | + switch (options[i].val) |
| 10266 | + { |
| 10267 | + case 'v': |
| 10268 | + printf ("Increase the output verbosity"); |
| 10269 | + break; |
| 10270 | + case OPT_DIRECT: |
| 10271 | + printf ("Run the test directly (instead of forking & monitoring)"); |
| 10272 | + break; |
| 10273 | + case OPT_TESTDIR: |
| 10274 | + printf ("Override the TMPDIR env var"); |
| 10275 | + break; |
| 10276 | + } |
| 10277 | + printf ("\n"); |
| 10278 | + } |
| 10279 | +} |
| 10280 | + |
| 10281 | +/* The PID of the test process. */ |
| 10282 | +static pid_t test_pid; |
| 10283 | + |
| 10284 | +/* The cleanup handler passed to test_main. */ |
| 10285 | +static void (*cleanup_function) (void); |
| 10286 | + |
| 10287 | +/* Timeout handler. We kill the child and exit with an error. */ |
| 10288 | +static void |
| 10289 | +__attribute__ ((noreturn)) |
| 10290 | +signal_handler (int sig) |
| 10291 | +{ |
| 10292 | + int killed; |
| 10293 | + int status; |
| 10294 | + |
| 10295 | + assert (test_pid > 1); |
| 10296 | + /* Kill the whole process group. */ |
| 10297 | + kill (-test_pid, SIGKILL); |
| 10298 | + /* In case setpgid failed in the child, kill it individually too. */ |
| 10299 | + kill (test_pid, SIGKILL); |
| 10300 | + |
| 10301 | + /* Wait for it to terminate. */ |
| 10302 | + int i; |
| 10303 | + for (i = 0; i < 5; ++i) |
| 10304 | + { |
| 10305 | + killed = waitpid (test_pid, &status, WNOHANG|WUNTRACED); |
| 10306 | + if (killed != 0) |
| 10307 | + break; |
| 10308 | + |
| 10309 | + /* Delay, give the system time to process the kill. If the |
| 10310 | + nanosleep() call return prematurely, all the better. We |
| 10311 | + won't restart it since this probably means the child process |
| 10312 | + finally died. */ |
| 10313 | + struct timespec ts; |
| 10314 | + ts.tv_sec = 0; |
| 10315 | + ts.tv_nsec = 100000000; |
| 10316 | + nanosleep (&ts, NULL); |
| 10317 | + } |
| 10318 | + if (killed != 0 && killed != test_pid) |
| 10319 | + { |
| 10320 | + printf ("Failed to kill test process: %m\n"); |
| 10321 | + exit (1); |
| 10322 | + } |
| 10323 | + |
| 10324 | + if (cleanup_function != NULL) |
| 10325 | + cleanup_function (); |
| 10326 | + |
| 10327 | + if (sig == SIGINT) |
| 10328 | + { |
| 10329 | + signal (sig, SIG_DFL); |
| 10330 | + raise (sig); |
| 10331 | + } |
| 10332 | + |
| 10333 | + if (killed == 0 || (WIFSIGNALED (status) && WTERMSIG (status) == SIGKILL)) |
| 10334 | + puts ("Timed out: killed the child process"); |
| 10335 | + else if (WIFSTOPPED (status)) |
| 10336 | + printf ("Timed out: the child process was %s\n", |
| 10337 | + strsignal (WSTOPSIG (status))); |
| 10338 | + else if (WIFSIGNALED (status)) |
| 10339 | + printf ("Timed out: the child process got signal %s\n", |
| 10340 | + strsignal (WTERMSIG (status))); |
| 10341 | + else |
| 10342 | + printf ("Timed out: killed the child process but it exited %d\n", |
| 10343 | + WEXITSTATUS (status)); |
| 10344 | + |
| 10345 | + /* Exit with an error. */ |
| 10346 | + exit (1); |
| 10347 | +} |
| 10348 | + |
| 10349 | +/* Run test_function or test_function_argv. */ |
| 10350 | +static int |
| 10351 | +run_test_function (int argc, char **argv, const struct test_config *config) |
| 10352 | +{ |
| 10353 | + if (config->test_function != NULL) |
| 10354 | + return config->test_function (); |
| 10355 | + else if (config->test_function_argv != NULL) |
| 10356 | + return config->test_function_argv (argc, argv); |
| 10357 | + else |
| 10358 | + { |
| 10359 | + printf ("error: no test function defined\n"); |
| 10360 | + exit (1); |
| 10361 | + } |
| 10362 | +} |
| 10363 | + |
| 10364 | +static bool test_main_called; |
| 10365 | + |
| 10366 | +const char *test_dir = NULL; |
| 10367 | +unsigned int test_verbose = 0; |
| 10368 | + |
| 10369 | +/* If test failure reporting has been linked in, it may contribute |
| 10370 | + additional test failures. */ |
| 10371 | +static int |
| 10372 | +adjust_exit_status (int status) |
| 10373 | +{ |
| 10374 | + if (support_report_failure != NULL) |
| 10375 | + return support_report_failure (status); |
| 10376 | + return status; |
| 10377 | +} |
| 10378 | + |
| 10379 | +int |
| 10380 | +support_test_main (int argc, char **argv, const struct test_config *config) |
| 10381 | +{ |
| 10382 | + if (test_main_called) |
| 10383 | + { |
| 10384 | + printf ("error: test_main called for a second time\n"); |
| 10385 | + exit (1); |
| 10386 | + } |
| 10387 | + test_main_called = true; |
| 10388 | + const struct option *options; |
| 10389 | + if (config->options != NULL) |
| 10390 | + options = config->options; |
| 10391 | + else |
| 10392 | + options = default_options; |
| 10393 | + |
| 10394 | + cleanup_function = config->cleanup_function; |
| 10395 | + |
| 10396 | + int direct = 0; /* Directly call the test function? */ |
| 10397 | + int status; |
| 10398 | + int opt; |
| 10399 | + unsigned int timeoutfactor = 1; |
| 10400 | + pid_t termpid; |
| 10401 | + |
| 10402 | + if (!config->no_mallopt) |
| 10403 | + { |
| 10404 | + /* Make uses of freed and uninitialized memory known. Do not |
| 10405 | + pull in a definition for mallopt if it has not been defined |
| 10406 | + already. */ |
| 10407 | + extern __typeof__ (mallopt) mallopt __attribute__ ((weak)); |
| 10408 | + if (mallopt != NULL) |
| 10409 | + mallopt (M_PERTURB, 42); |
| 10410 | + } |
| 10411 | + |
| 10412 | + while ((opt = getopt_long (argc, argv, "+", options, NULL)) != -1) |
| 10413 | + switch (opt) |
| 10414 | + { |
| 10415 | + case '?': |
| 10416 | + usage (options); |
| 10417 | + exit (1); |
| 10418 | + case 'v': |
| 10419 | + ++test_verbose; |
| 10420 | + break; |
| 10421 | + case OPT_DIRECT: |
| 10422 | + direct = 1; |
| 10423 | + break; |
| 10424 | + case OPT_TESTDIR: |
| 10425 | + test_dir = optarg; |
| 10426 | + break; |
| 10427 | + default: |
| 10428 | + if (config->cmdline_function != NULL) |
| 10429 | + config->cmdline_function (opt); |
| 10430 | + } |
| 10431 | + |
| 10432 | + /* If set, read the test TIMEOUTFACTOR value from the environment. |
| 10433 | + This value is used to scale the default test timeout values. */ |
| 10434 | + char *envstr_timeoutfactor = getenv ("TIMEOUTFACTOR"); |
| 10435 | + if (envstr_timeoutfactor != NULL) |
| 10436 | + { |
| 10437 | + char *envstr_conv = envstr_timeoutfactor; |
| 10438 | + unsigned long int env_fact; |
| 10439 | + |
| 10440 | + env_fact = strtoul (envstr_timeoutfactor, &envstr_conv, 0); |
| 10441 | + if (*envstr_conv == '\0' && envstr_conv != envstr_timeoutfactor) |
| 10442 | + timeoutfactor = MAX (env_fact, 1); |
| 10443 | + } |
| 10444 | + |
| 10445 | + /* Set TMPDIR to specified test directory. */ |
| 10446 | + if (test_dir != NULL) |
| 10447 | + { |
| 10448 | + setenv ("TMPDIR", test_dir, 1); |
| 10449 | + |
| 10450 | + if (chdir (test_dir) < 0) |
| 10451 | + { |
| 10452 | + printf ("chdir: %m\n"); |
| 10453 | + exit (1); |
| 10454 | + } |
| 10455 | + } |
| 10456 | + else |
| 10457 | + { |
| 10458 | + test_dir = getenv ("TMPDIR"); |
| 10459 | + if (test_dir == NULL || test_dir[0] == '\0') |
| 10460 | + test_dir = "/tmp"; |
| 10461 | + } |
| 10462 | + if (support_set_test_dir != NULL) |
| 10463 | + support_set_test_dir (test_dir); |
| 10464 | + |
| 10465 | + int timeout = config->timeout; |
| 10466 | + if (timeout == 0) |
| 10467 | + timeout = DEFAULT_TIMEOUT; |
| 10468 | + |
| 10469 | + /* Make sure we see all message, even those on stdout. */ |
| 10470 | + setvbuf (stdout, NULL, _IONBF, 0); |
| 10471 | + |
| 10472 | + /* Make sure temporary files are deleted. */ |
| 10473 | + if (support_delete_temp_files != NULL) |
| 10474 | + atexit (support_delete_temp_files); |
| 10475 | + |
| 10476 | + /* Correct for the possible parameters. */ |
| 10477 | + argv[optind - 1] = argv[0]; |
| 10478 | + argv += optind - 1; |
| 10479 | + argc -= optind - 1; |
| 10480 | + |
| 10481 | + /* Call the initializing function, if one is available. */ |
| 10482 | + if (config->prepare_function != NULL) |
| 10483 | + config->prepare_function (argc, argv); |
| 10484 | + |
| 10485 | + const char *envstr_direct = getenv ("TEST_DIRECT"); |
| 10486 | + if (envstr_direct != NULL) |
| 10487 | + { |
| 10488 | + FILE *f = fopen (envstr_direct, "w"); |
| 10489 | + if (f == NULL) |
| 10490 | + { |
| 10491 | + printf ("cannot open TEST_DIRECT output file '%s': %m\n", |
| 10492 | + envstr_direct); |
| 10493 | + exit (1); |
| 10494 | + } |
| 10495 | + |
| 10496 | + fprintf (f, "timeout=%u\ntimeoutfactor=%u\n", |
| 10497 | + config->timeout, timeoutfactor); |
| 10498 | + if (config->expected_status != 0) |
| 10499 | + fprintf (f, "exit=%u\n", config->expected_status); |
| 10500 | + if (config->expected_signal != 0) |
| 10501 | + fprintf (f, "signal=%s\n", strsignal (config->expected_signal)); |
| 10502 | + |
| 10503 | + if (support_print_temp_files != NULL) |
| 10504 | + support_print_temp_files (f); |
| 10505 | + |
| 10506 | + fclose (f); |
| 10507 | + direct = 1; |
| 10508 | + } |
| 10509 | + |
| 10510 | + bool disable_coredumps; |
| 10511 | + { |
| 10512 | + const char *coredumps = getenv ("TEST_COREDUMPS"); |
| 10513 | + disable_coredumps = coredumps == NULL || coredumps[0] == '\0'; |
| 10514 | + } |
| 10515 | + |
| 10516 | + /* If we are not expected to fork run the function immediately. */ |
| 10517 | + if (direct) |
| 10518 | + return adjust_exit_status (run_test_function (argc, argv, config)); |
| 10519 | + |
| 10520 | + /* Set up the test environment: |
| 10521 | + - prevent core dumps |
| 10522 | + - set up the timer |
| 10523 | + - fork and execute the function. */ |
| 10524 | + |
| 10525 | + test_pid = fork (); |
| 10526 | + if (test_pid == 0) |
| 10527 | + { |
| 10528 | + /* This is the child. */ |
| 10529 | + if (disable_coredumps) |
| 10530 | + { |
| 10531 | + /* Try to avoid dumping core. This is necessary because we |
| 10532 | + run the test from the source tree, and the coredumps |
| 10533 | + would end up there (and not in the build tree). */ |
| 10534 | + struct rlimit core_limit; |
| 10535 | + core_limit.rlim_cur = 0; |
| 10536 | + core_limit.rlim_max = 0; |
| 10537 | + setrlimit (RLIMIT_CORE, &core_limit); |
| 10538 | + } |
| 10539 | + |
| 10540 | + /* We put the test process in its own pgrp so that if it bogusly |
| 10541 | + generates any job control signals, they won't hit the whole build. */ |
| 10542 | + if (setpgid (0, 0) != 0) |
| 10543 | + printf ("Failed to set the process group ID: %m\n"); |
| 10544 | + |
| 10545 | + /* Execute the test function and exit with the return value. */ |
| 10546 | + exit (run_test_function (argc, argv, config)); |
| 10547 | + } |
| 10548 | + else if (test_pid < 0) |
| 10549 | + { |
| 10550 | + printf ("Cannot fork test program: %m\n"); |
| 10551 | + exit (1); |
| 10552 | + } |
| 10553 | + |
| 10554 | + /* Set timeout. */ |
| 10555 | + signal (SIGALRM, signal_handler); |
| 10556 | + alarm (timeout * timeoutfactor); |
| 10557 | + |
| 10558 | + /* Make sure we clean up if the wrapper gets interrupted. */ |
| 10559 | + signal (SIGINT, signal_handler); |
| 10560 | + |
| 10561 | + /* Wait for the regular termination. */ |
| 10562 | + termpid = TEMP_FAILURE_RETRY (waitpid (test_pid, &status, 0)); |
| 10563 | + if (termpid == -1) |
| 10564 | + { |
| 10565 | + printf ("Waiting for test program failed: %m\n"); |
| 10566 | + exit (1); |
| 10567 | + } |
| 10568 | + if (termpid != test_pid) |
| 10569 | + { |
| 10570 | + printf ("Oops, wrong test program terminated: expected %ld, got %ld\n", |
| 10571 | + (long int) test_pid, (long int) termpid); |
| 10572 | + exit (1); |
| 10573 | + } |
| 10574 | + |
| 10575 | + /* Process terminated normaly without timeout etc. */ |
| 10576 | + if (WIFEXITED (status)) |
| 10577 | + { |
| 10578 | + if (config->expected_status == 0) |
| 10579 | + { |
| 10580 | + if (config->expected_signal == 0) |
| 10581 | + /* Exit with the return value of the test. */ |
| 10582 | + return adjust_exit_status (WEXITSTATUS (status)); |
| 10583 | + else |
| 10584 | + { |
| 10585 | + printf ("Expected signal '%s' from child, got none\n", |
| 10586 | + strsignal (config->expected_signal)); |
| 10587 | + exit (1); |
| 10588 | + } |
| 10589 | + } |
| 10590 | + else |
| 10591 | + { |
| 10592 | + /* Non-zero exit status is expected */ |
| 10593 | + if (WEXITSTATUS (status) != config->expected_status) |
| 10594 | + { |
| 10595 | + printf ("Expected status %d, got %d\n", |
| 10596 | + config->expected_status, WEXITSTATUS (status)); |
| 10597 | + exit (1); |
| 10598 | + } |
| 10599 | + } |
| 10600 | + return adjust_exit_status (0); |
| 10601 | + } |
| 10602 | + /* Process was killed by timer or other signal. */ |
| 10603 | + else |
| 10604 | + { |
| 10605 | + if (config->expected_signal == 0) |
| 10606 | + { |
| 10607 | + printf ("Didn't expect signal from child: got `%s'\n", |
| 10608 | + strsignal (WTERMSIG (status))); |
| 10609 | + exit (1); |
| 10610 | + } |
| 10611 | + else if (WTERMSIG (status) != config->expected_signal) |
| 10612 | + { |
| 10613 | + printf ("Incorrect signal from child: got `%s', need `%s'\n", |
| 10614 | + strsignal (WTERMSIG (status)), |
| 10615 | + strsignal (config->expected_signal)); |
| 10616 | + exit (1); |
| 10617 | + } |
| 10618 | + |
| 10619 | + return adjust_exit_status (0); |
| 10620 | + } |
| 10621 | +} |
| 10622 | diff --git a/support/support_test_verify_impl.c b/support/support_test_verify_impl.c |
| 10623 | new file mode 100644 |
| 10624 | index 0000000000..5bae38f8b1 |
| 10625 | --- /dev/null |
| 10626 | +++ b/support/support_test_verify_impl.c |
| 10627 | @@ -0,0 +1,33 @@ |
| 10628 | +/* Implementation of the TEST_VERIFY and TEST_VERIFY_EXIT macros. |
| 10629 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 10630 | + This file is part of the GNU C Library. |
| 10631 | + |
| 10632 | + The GNU C Library is free software; you can redistribute it and/or |
| 10633 | + modify it under the terms of the GNU Lesser General Public |
| 10634 | + License as published by the Free Software Foundation; either |
| 10635 | + version 2.1 of the License, or (at your option) any later version. |
| 10636 | + |
| 10637 | + The GNU C Library is distributed in the hope that it will be useful, |
| 10638 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10639 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 10640 | + Lesser General Public License for more details. |
| 10641 | + |
| 10642 | + You should have received a copy of the GNU Lesser General Public |
| 10643 | + License along with the GNU C Library; if not, see |
| 10644 | + <http://www.gnu.org/licenses/>. */ |
| 10645 | + |
| 10646 | +#include <support/check.h> |
| 10647 | + |
| 10648 | +#include <stdio.h> |
| 10649 | +#include <stdlib.h> |
| 10650 | + |
| 10651 | +void |
| 10652 | +support_test_verify_impl (int status, const char *file, int line, |
| 10653 | + const char *expr) |
| 10654 | +{ |
| 10655 | + support_record_failure (); |
| 10656 | + printf ("error: %s:%d: not true: %s\n", file, line, expr); |
| 10657 | + if (status >= 0) |
| 10658 | + exit (status); |
| 10659 | + |
| 10660 | +} |
| 10661 | diff --git a/support/support_write_file_string.c b/support/support_write_file_string.c |
| 10662 | new file mode 100644 |
| 10663 | index 0000000000..48e89597f3 |
| 10664 | --- /dev/null |
| 10665 | +++ b/support/support_write_file_string.c |
| 10666 | @@ -0,0 +1,39 @@ |
| 10667 | +/* Write a string to a file. |
| 10668 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 10669 | + This file is part of the GNU C Library. |
| 10670 | + |
| 10671 | + The GNU C Library is free software; you can redistribute it and/or |
| 10672 | + modify it under the terms of the GNU Lesser General Public |
| 10673 | + License as published by the Free Software Foundation; either |
| 10674 | + version 2.1 of the License, or (at your option) any later version. |
| 10675 | + |
| 10676 | + The GNU C Library is distributed in the hope that it will be useful, |
| 10677 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10678 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 10679 | + Lesser General Public License for more details. |
| 10680 | + |
| 10681 | + You should have received a copy of the GNU Lesser General Public |
| 10682 | + License along with the GNU C Library; if not, see |
| 10683 | + <http://www.gnu.org/licenses/>. */ |
| 10684 | + |
| 10685 | +#include <fcntl.h> |
| 10686 | +#include <string.h> |
| 10687 | +#include <support/check.h> |
| 10688 | +#include <xunistd.h> |
| 10689 | + |
| 10690 | +void |
| 10691 | +support_write_file_string (const char *path, const char *contents) |
| 10692 | +{ |
| 10693 | + int fd = xopen (path, O_CREAT | O_TRUNC | O_WRONLY, 0666); |
| 10694 | + const char *end = contents + strlen (contents); |
| 10695 | + for (const char *p = contents; p < end; ) |
| 10696 | + { |
| 10697 | + ssize_t ret = write (fd, p, end - p); |
| 10698 | + if (ret < 0) |
| 10699 | + FAIL_EXIT1 ("cannot write to \"%s\": %m", path); |
| 10700 | + if (ret == 0) |
| 10701 | + FAIL_EXIT1 ("zero-length write to \"%s\"", path); |
| 10702 | + p += ret; |
| 10703 | + } |
| 10704 | + xclose (fd); |
| 10705 | +} |
| 10706 | diff --git a/support/temp_file-internal.h b/support/temp_file-internal.h |
| 10707 | new file mode 100644 |
| 10708 | index 0000000000..fb6cceb065 |
| 10709 | --- /dev/null |
| 10710 | +++ b/support/temp_file-internal.h |
| 10711 | @@ -0,0 +1,31 @@ |
| 10712 | +/* Internal weak declarations for temporary file handling. |
| 10713 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 10714 | + This file is part of the GNU C Library. |
| 10715 | + |
| 10716 | + The GNU C Library is free software; you can redistribute it and/or |
| 10717 | + modify it under the terms of the GNU Lesser General Public |
| 10718 | + License as published by the Free Software Foundation; either |
| 10719 | + version 2.1 of the License, or (at your option) any later version. |
| 10720 | + |
| 10721 | + The GNU C Library is distributed in the hope that it will be useful, |
| 10722 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10723 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 10724 | + Lesser General Public License for more details. |
| 10725 | + |
| 10726 | + You should have received a copy of the GNU Lesser General Public |
| 10727 | + License along with the GNU C Library; if not, see |
| 10728 | + <http://www.gnu.org/licenses/>. */ |
| 10729 | + |
| 10730 | +#ifndef SUPPORT_TEMP_FILE_INTERNAL_H |
| 10731 | +#define SUPPORT_TEMP_FILE_INTERNAL_H |
| 10732 | + |
| 10733 | +/* These functions are called by the test driver if they are |
| 10734 | + defined. Tests should not call them directly. */ |
| 10735 | + |
| 10736 | +#include <stdio.h> |
| 10737 | + |
| 10738 | +void support_set_test_dir (const char *name) __attribute__ ((weak)); |
| 10739 | +void support_delete_temp_files (void) __attribute__ ((weak)); |
| 10740 | +void support_print_temp_files (FILE *) __attribute__ ((weak)); |
| 10741 | + |
| 10742 | +#endif /* SUPPORT_TEMP_FILE_INTERNAL_H */ |
| 10743 | diff --git a/support/temp_file.c b/support/temp_file.c |
| 10744 | new file mode 100644 |
| 10745 | index 0000000000..fdb2477ab9 |
| 10746 | --- /dev/null |
| 10747 | +++ b/support/temp_file.c |
| 10748 | @@ -0,0 +1,132 @@ |
| 10749 | +/* Temporary file handling for tests. |
| 10750 | + Copyright (C) 1998-2017 Free Software Foundation, Inc. |
| 10751 | + This file is part of the GNU C Library. |
| 10752 | + |
| 10753 | + The GNU C Library is free software; you can redistribute it and/or |
| 10754 | + modify it under the terms of the GNU Lesser General Public |
| 10755 | + License as published by the Free Software Foundation; either |
| 10756 | + version 2.1 of the License, or (at your option) any later version. |
| 10757 | + |
| 10758 | + The GNU C Library is distributed in the hope that it will be useful, |
| 10759 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10760 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 10761 | + Lesser General Public License for more details. |
| 10762 | + |
| 10763 | + You should have received a copy of the GNU Lesser General Public |
| 10764 | + License along with the GNU C Library; if not, see |
| 10765 | + <http://www.gnu.org/licenses/>. */ |
| 10766 | + |
| 10767 | +/* This is required to get an mkstemp which can create large files on |
| 10768 | + some 32-bit platforms. */ |
| 10769 | +#define _FILE_OFFSET_BITS 64 |
| 10770 | + |
| 10771 | +#include <support/temp_file.h> |
| 10772 | +#include <support/temp_file-internal.h> |
| 10773 | +#include <support/support.h> |
| 10774 | + |
| 10775 | +#include <paths.h> |
| 10776 | +#include <stdio.h> |
| 10777 | +#include <stdlib.h> |
| 10778 | +#include <string.h> |
| 10779 | +#include <unistd.h> |
| 10780 | + |
| 10781 | +/* List of temporary files. */ |
| 10782 | +static struct temp_name_list |
| 10783 | +{ |
| 10784 | + struct temp_name_list *next; |
| 10785 | + char *name; |
| 10786 | + pid_t owner; |
| 10787 | +} *temp_name_list; |
| 10788 | + |
| 10789 | +/* Location of the temporary files. Set by the test skeleton via |
| 10790 | + support_set_test_dir. The string is not be freed. */ |
| 10791 | +static const char *test_dir = _PATH_TMP; |
| 10792 | + |
| 10793 | +void |
| 10794 | +add_temp_file (const char *name) |
| 10795 | +{ |
| 10796 | + struct temp_name_list *newp |
| 10797 | + = (struct temp_name_list *) xcalloc (sizeof (*newp), 1); |
| 10798 | + char *newname = strdup (name); |
| 10799 | + if (newname != NULL) |
| 10800 | + { |
| 10801 | + newp->name = newname; |
| 10802 | + newp->next = temp_name_list; |
| 10803 | + newp->owner = getpid (); |
| 10804 | + temp_name_list = newp; |
| 10805 | + } |
| 10806 | + else |
| 10807 | + free (newp); |
| 10808 | +} |
| 10809 | + |
| 10810 | +int |
| 10811 | +create_temp_file (const char *base, char **filename) |
| 10812 | +{ |
| 10813 | + char *fname; |
| 10814 | + int fd; |
| 10815 | + |
| 10816 | + fname = (char *) xmalloc (strlen (test_dir) + 1 + strlen (base) |
| 10817 | + + sizeof ("XXXXXX")); |
| 10818 | + strcpy (stpcpy (stpcpy (stpcpy (fname, test_dir), "/"), base), "XXXXXX"); |
| 10819 | + |
| 10820 | + fd = mkstemp (fname); |
| 10821 | + if (fd == -1) |
| 10822 | + { |
| 10823 | + printf ("cannot open temporary file '%s': %m\n", fname); |
| 10824 | + free (fname); |
| 10825 | + return -1; |
| 10826 | + } |
| 10827 | + |
| 10828 | + add_temp_file (fname); |
| 10829 | + if (filename != NULL) |
| 10830 | + *filename = fname; |
| 10831 | + else |
| 10832 | + free (fname); |
| 10833 | + |
| 10834 | + return fd; |
| 10835 | +} |
| 10836 | + |
| 10837 | +/* Helper functions called by the test skeleton follow. */ |
| 10838 | + |
| 10839 | +void |
| 10840 | +support_set_test_dir (const char *path) |
| 10841 | +{ |
| 10842 | + test_dir = path; |
| 10843 | +} |
| 10844 | + |
| 10845 | +void |
| 10846 | +support_delete_temp_files (void) |
| 10847 | +{ |
| 10848 | + pid_t pid = getpid (); |
| 10849 | + while (temp_name_list != NULL) |
| 10850 | + { |
| 10851 | + /* Only perform the removal if the path was registed in the same |
| 10852 | + process, as identified by the PID. (This assumes that the |
| 10853 | + parent process which registered the temporary file sticks |
| 10854 | + around, to prevent PID reuse.) */ |
| 10855 | + if (temp_name_list->owner == pid) |
| 10856 | + { |
| 10857 | + if (remove (temp_name_list->name) != 0) |
| 10858 | + printf ("warning: could not remove temporary file: %s: %m\n", |
| 10859 | + temp_name_list->name); |
| 10860 | + } |
| 10861 | + free (temp_name_list->name); |
| 10862 | + |
| 10863 | + struct temp_name_list *next = temp_name_list->next; |
| 10864 | + free (temp_name_list); |
| 10865 | + temp_name_list = next; |
| 10866 | + } |
| 10867 | +} |
| 10868 | + |
| 10869 | +void |
| 10870 | +support_print_temp_files (FILE *f) |
| 10871 | +{ |
| 10872 | + if (temp_name_list != NULL) |
| 10873 | + { |
| 10874 | + struct temp_name_list *n; |
| 10875 | + fprintf (f, "temp_files=(\n"); |
| 10876 | + for (n = temp_name_list; n != NULL; n = n->next) |
| 10877 | + fprintf (f, " '%s'\n", n->name); |
| 10878 | + fprintf (f, ")\n"); |
| 10879 | + } |
| 10880 | +} |
| 10881 | diff --git a/support/temp_file.h b/support/temp_file.h |
| 10882 | new file mode 100644 |
| 10883 | index 0000000000..6fed8df1ea |
| 10884 | --- /dev/null |
| 10885 | +++ b/support/temp_file.h |
| 10886 | @@ -0,0 +1,37 @@ |
| 10887 | +/* Declarations for temporary file handling. |
| 10888 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 10889 | + This file is part of the GNU C Library. |
| 10890 | + |
| 10891 | + The GNU C Library is free software; you can redistribute it and/or |
| 10892 | + modify it under the terms of the GNU Lesser General Public |
| 10893 | + License as published by the Free Software Foundation; either |
| 10894 | + version 2.1 of the License, or (at your option) any later version. |
| 10895 | + |
| 10896 | + The GNU C Library is distributed in the hope that it will be useful, |
| 10897 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10898 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 10899 | + Lesser General Public License for more details. |
| 10900 | + |
| 10901 | + You should have received a copy of the GNU Lesser General Public |
| 10902 | + License along with the GNU C Library; if not, see |
| 10903 | + <http://www.gnu.org/licenses/>. */ |
| 10904 | + |
| 10905 | +#ifndef SUPPORT_TEMP_FILE_H |
| 10906 | +#define SUPPORT_TEMP_FILE_H |
| 10907 | + |
| 10908 | +#include <sys/cdefs.h> |
| 10909 | + |
| 10910 | +__BEGIN_DECLS |
| 10911 | + |
| 10912 | +/* Schedule a temporary file for deletion on exit. */ |
| 10913 | +void add_temp_file (const char *name); |
| 10914 | + |
| 10915 | +/* Create a temporary file. Return the opened file descriptor on |
| 10916 | + success, or -1 on failure. Write the file name to *FILENAME if |
| 10917 | + FILENAME is not NULL. In this case, the caller is expected to free |
| 10918 | + *FILENAME. */ |
| 10919 | +int create_temp_file (const char *base, char **filename); |
| 10920 | + |
| 10921 | +__END_DECLS |
| 10922 | + |
| 10923 | +#endif /* SUPPORT_TEMP_FILE_H */ |
| 10924 | diff --git a/support/test-driver.c b/support/test-driver.c |
| 10925 | new file mode 100644 |
| 10926 | index 0000000000..482066dbeb |
| 10927 | --- /dev/null |
| 10928 | +++ b/support/test-driver.c |
| 10929 | @@ -0,0 +1,156 @@ |
| 10930 | +/* Main function for test programs. |
| 10931 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 10932 | + This file is part of the GNU C Library. |
| 10933 | + |
| 10934 | + The GNU C Library is free software; you can redistribute it and/or |
| 10935 | + modify it under the terms of the GNU Lesser General Public |
| 10936 | + License as published by the Free Software Foundation; either |
| 10937 | + version 2.1 of the License, or (at your option) any later version. |
| 10938 | + |
| 10939 | + The GNU C Library is distributed in the hope that it will be useful, |
| 10940 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10941 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 10942 | + Lesser General Public License for more details. |
| 10943 | + |
| 10944 | + You should have received a copy of the GNU Lesser General Public |
| 10945 | + License along with the GNU C Library; if not, see |
| 10946 | + <http://www.gnu.org/licenses/>. */ |
| 10947 | + |
| 10948 | +/* This file should be included from test cases. It will define a |
| 10949 | + main function which provides the test wrapper. |
| 10950 | + |
| 10951 | + It assumes that the test case defines a function |
| 10952 | + |
| 10953 | + int do_test (void); |
| 10954 | + |
| 10955 | + and arranges for that function being called under the test wrapper. |
| 10956 | + The do_test function should return 0 to indicate a passing test, 1 |
| 10957 | + to indicate a failing test, or 77 to indicate an unsupported test. |
| 10958 | + Other result values could be used to indicate a failing test, but |
| 10959 | + the result of the expression is passed to exit and exit only |
| 10960 | + returns the lower 8 bits of its input. A non-zero return with some |
| 10961 | + values could cause a test to incorrectly be considered passing when |
| 10962 | + it really failed. For this reason, the function should always |
| 10963 | + return 0 (EXIT_SUCCESS), 1 (EXIT_FAILURE), or 77 |
| 10964 | + (EXIT_UNSUPPORTED). |
| 10965 | + |
| 10966 | + The test function may print out diagnostic or warning messages as well |
| 10967 | + as messages about failures. These messages should be printed to stdout |
| 10968 | + and not stderr so that the output is properly ordered with respect to |
| 10969 | + the rest of the glibc testsuite run output. |
| 10970 | + |
| 10971 | + Several preprocessors macros can be defined before including this |
| 10972 | + file. |
| 10973 | + |
| 10974 | + The name of the do_test function can be changed with the |
| 10975 | + TEST_FUNCTION macro. It must expand to the desired function name. |
| 10976 | + |
| 10977 | + If the test case needs access to command line parameters, it must |
| 10978 | + define the TEST_FUNCTION_ARGV macro with the name of the test |
| 10979 | + function. It must have the following type: |
| 10980 | + |
| 10981 | + int TEST_FUNCTION_ARGV (int argc, char **argv); |
| 10982 | + |
| 10983 | + This overrides the do_test default function and is incompatible |
| 10984 | + with the TEST_FUNCTION macro. |
| 10985 | + |
| 10986 | + If PREPARE is defined, it must expand to the name of a function of |
| 10987 | + the type |
| 10988 | + |
| 10989 | + void PREPARE (int argc, char **); |
| 10990 | + |
| 10991 | + This function will be called early, after parsing the command line, |
| 10992 | + but before running the test, in the parent process which acts as |
| 10993 | + the test supervisor. |
| 10994 | + |
| 10995 | + If CLEANUP_HANDLER is defined, it must expand to the name of a |
| 10996 | + function of the type |
| 10997 | + |
| 10998 | + void CLEANUP_HANDLER (void); |
| 10999 | + |
| 11000 | + This function will be called from the timeout (SIGALRM) signal |
| 11001 | + handler. |
| 11002 | + |
| 11003 | + If EXPECTED_SIGNAL is defined, it must expanded to a constant which |
| 11004 | + denotes the expected signal number. |
| 11005 | + |
| 11006 | + If EXPECTED_STATUS is defined, it must expand to the expected exit |
| 11007 | + status. |
| 11008 | + |
| 11009 | + If TIMEOUT is defined, it must be positive constant. It overrides |
| 11010 | + the default test timeout and is measured in seconds. |
| 11011 | + |
| 11012 | + If TEST_NO_MALLOPT is defined, the test wrapper will not call |
| 11013 | + mallopt. |
| 11014 | + |
| 11015 | + Custom command line handling can be implemented by defining the |
| 11016 | + CMDLINE_OPTION macro (after including the <getopt.h> header; this |
| 11017 | + requires _GNU_SOURCE to be defined). This macro must expand to a |
| 11018 | + to a comma-separated list of braced initializers for struct option |
| 11019 | + from <getopt.h>, with a trailing comma. CMDLINE_PROCESS can be |
| 11020 | + defined as the name of a function which is called to process these |
| 11021 | + options. The function is passed the option character/number and |
| 11022 | + has this type: |
| 11023 | + |
| 11024 | + void CMDLINE_PROCESS (int); |
| 11025 | +*/ |
| 11026 | + |
| 11027 | +#include <support/test-driver.h> |
| 11028 | + |
| 11029 | +#include <string.h> |
| 11030 | + |
| 11031 | +int |
| 11032 | +main (int argc, char **argv) |
| 11033 | +{ |
| 11034 | + struct test_config test_config; |
| 11035 | + memset (&test_config, 0, sizeof (test_config)); |
| 11036 | + |
| 11037 | +#ifdef PREPARE |
| 11038 | + test_config.prepare_function = (PREPARE); |
| 11039 | +#endif |
| 11040 | + |
| 11041 | +#if defined (TEST_FUNCTION) && defined (TEST_FUNCTON_ARGV) |
| 11042 | +# error TEST_FUNCTION and TEST_FUNCTION_ARGV cannot be defined at the same time |
| 11043 | +#endif |
| 11044 | +#if defined (TEST_FUNCTION) |
| 11045 | + test_config.test_function = TEST_FUNCTION; |
| 11046 | +#elif defined (TEST_FUNCTION_ARGV) |
| 11047 | + test_config.test_function_argv = TEST_FUNCTION_ARGV; |
| 11048 | +#else |
| 11049 | + test_config.test_function = do_test; |
| 11050 | +#endif |
| 11051 | + |
| 11052 | +#ifdef CLEANUP_HANDLER |
| 11053 | + test_config.cleanup_function = CLEANUP_HANDLER; |
| 11054 | +#endif |
| 11055 | + |
| 11056 | +#ifdef EXPECTED_SIGNAL |
| 11057 | + test_config.expected_signal = (EXPECTED_SIGNAL); |
| 11058 | +#endif |
| 11059 | + |
| 11060 | +#ifdef EXPECTED_STATUS |
| 11061 | + test_config.expected_status = (EXPECTED_STATUS); |
| 11062 | +#endif |
| 11063 | + |
| 11064 | +#ifdef TEST_NO_MALLOPT |
| 11065 | + test_config.no_mallopt = 1; |
| 11066 | +#endif |
| 11067 | + |
| 11068 | +#ifdef TIMEOUT |
| 11069 | + test_config.timeout = TIMEOUT; |
| 11070 | +#endif |
| 11071 | + |
| 11072 | +#ifdef CMDLINE_OPTIONS |
| 11073 | + struct option options[] = |
| 11074 | + { |
| 11075 | + CMDLINE_OPTIONS |
| 11076 | + TEST_DEFAULT_OPTIONS |
| 11077 | + }; |
| 11078 | + test_config.options = &options; |
| 11079 | +#endif |
| 11080 | +#ifdef CMDLINE_PROCESS |
| 11081 | + test_config.cmdline_function = CMDLINE_PROCESS; |
| 11082 | +#endif |
| 11083 | + |
| 11084 | + return support_test_main (argc, argv, &test_config); |
| 11085 | +} |
| 11086 | diff --git a/support/test-driver.h b/support/test-driver.h |
| 11087 | new file mode 100644 |
| 11088 | index 0000000000..af1971a9ca |
| 11089 | --- /dev/null |
| 11090 | +++ b/support/test-driver.h |
| 11091 | @@ -0,0 +1,74 @@ |
| 11092 | +/* Interfaces for the test driver. |
| 11093 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 11094 | + This file is part of the GNU C Library. |
| 11095 | + |
| 11096 | + The GNU C Library is free software; you can redistribute it and/or |
| 11097 | + modify it under the terms of the GNU Lesser General Public |
| 11098 | + License as published by the Free Software Foundation; either |
| 11099 | + version 2.1 of the License, or (at your option) any later version. |
| 11100 | + |
| 11101 | + The GNU C Library is distributed in the hope that it will be useful, |
| 11102 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11103 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11104 | + Lesser General Public License for more details. |
| 11105 | + |
| 11106 | + You should have received a copy of the GNU Lesser General Public |
| 11107 | + License along with the GNU C Library; if not, see |
| 11108 | + <http://www.gnu.org/licenses/>. */ |
| 11109 | + |
| 11110 | +#ifndef SUPPORT_TEST_DRIVER_H |
| 11111 | +#define SUPPORT_TEST_DRIVER_H |
| 11112 | + |
| 11113 | +#include <sys/cdefs.h> |
| 11114 | + |
| 11115 | +__BEGIN_DECLS |
| 11116 | + |
| 11117 | +struct test_config |
| 11118 | +{ |
| 11119 | + void (*prepare_function) (int argc, char **argv); |
| 11120 | + int (*test_function) (void); |
| 11121 | + int (*test_function_argv) (int argc, char **argv); |
| 11122 | + void (*cleanup_function) (void); |
| 11123 | + void (*cmdline_function) (int); |
| 11124 | + const void *options; /* Custom options if not NULL. */ |
| 11125 | + int timeout; /* Test timeout in seconds. */ |
| 11126 | + int expected_status; /* Expected exit status. */ |
| 11127 | + int expected_signal; /* If non-zero, expect termination by signal. */ |
| 11128 | + char no_mallopt; /* Boolean flag to disable mallopt. */ |
| 11129 | +}; |
| 11130 | + |
| 11131 | +enum |
| 11132 | + { |
| 11133 | + /* Test exit status which indicates that the feature is |
| 11134 | + unsupported. */ |
| 11135 | + EXIT_UNSUPPORTED = 77, |
| 11136 | + |
| 11137 | + /* Default timeout is twenty seconds. Tests should normally |
| 11138 | + complete faster than this, but if they don't, that's abnormal |
| 11139 | + (a bug) anyways. */ |
| 11140 | + DEFAULT_TIMEOUT = 20, |
| 11141 | + |
| 11142 | + /* Used for command line argument parsing. */ |
| 11143 | + OPT_DIRECT = 1000, |
| 11144 | + OPT_TESTDIR, |
| 11145 | + }; |
| 11146 | + |
| 11147 | +/* Options provided by the test driver. */ |
| 11148 | +#define TEST_DEFAULT_OPTIONS \ |
| 11149 | + { "verbose", no_argument, NULL, 'v' }, \ |
| 11150 | + { "direct", no_argument, NULL, OPT_DIRECT }, \ |
| 11151 | + { "test-dir", required_argument, NULL, OPT_TESTDIR }, \ |
| 11152 | + |
| 11153 | +/* The directory the test should use for temporary files. */ |
| 11154 | +extern const char *test_dir; |
| 11155 | + |
| 11156 | +/* The number of --verbose arguments specified during program |
| 11157 | + invocation. This variable can be used to control the verbosity of |
| 11158 | + tests. */ |
| 11159 | +extern unsigned int test_verbose; |
| 11160 | + |
| 11161 | +int support_test_main (int argc, char **argv, const struct test_config *); |
| 11162 | + |
| 11163 | +__END_DECLS |
| 11164 | + |
| 11165 | +#endif /* SUPPORT_TEST_DRIVER_H */ |
| 11166 | diff --git a/support/tst-support-namespace.c b/support/tst-support-namespace.c |
| 11167 | new file mode 100644 |
| 11168 | index 0000000000..a50b074f5e |
| 11169 | --- /dev/null |
| 11170 | +++ b/support/tst-support-namespace.c |
| 11171 | @@ -0,0 +1,34 @@ |
| 11172 | +/* Test entering namespaces. |
| 11173 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 11174 | + This file is part of the GNU C Library. |
| 11175 | + |
| 11176 | + The GNU C Library is free software; you can redistribute it and/or |
| 11177 | + modify it under the terms of the GNU Lesser General Public |
| 11178 | + License as published by the Free Software Foundation; either |
| 11179 | + version 2.1 of the License, or (at your option) any later version. |
| 11180 | + |
| 11181 | + The GNU C Library is distributed in the hope that it will be useful, |
| 11182 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11183 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11184 | + Lesser General Public License for more details. |
| 11185 | + |
| 11186 | + You should have received a copy of the GNU Lesser General Public |
| 11187 | + License along with the GNU C Library; if not, see |
| 11188 | + <http://www.gnu.org/licenses/>. */ |
| 11189 | + |
| 11190 | +#include <stdio.h> |
| 11191 | +#include <support/namespace.h> |
| 11192 | + |
| 11193 | +static int |
| 11194 | +do_test (void) |
| 11195 | +{ |
| 11196 | + if (support_become_root ()) |
| 11197 | + printf ("info: acquired root-like privileges\n"); |
| 11198 | + if (support_enter_network_namespace ()) |
| 11199 | + printf ("info: entered network namespace\n"); |
| 11200 | + if (support_in_uts_namespace ()) |
| 11201 | + printf ("info: also entered UTS namespace\n"); |
| 11202 | + return 0; |
| 11203 | +} |
| 11204 | + |
| 11205 | +#include <support/test-driver.c> |
| 11206 | diff --git a/support/tst-support_capture_subprocess.c b/support/tst-support_capture_subprocess.c |
| 11207 | new file mode 100644 |
| 11208 | index 0000000000..5672fba0f7 |
| 11209 | --- /dev/null |
| 11210 | +++ b/support/tst-support_capture_subprocess.c |
| 11211 | @@ -0,0 +1,188 @@ |
| 11212 | +/* Test capturing output from a subprocess. |
| 11213 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 11214 | + This file is part of the GNU C Library. |
| 11215 | + |
| 11216 | + The GNU C Library is free software; you can redistribute it and/or |
| 11217 | + modify it under the terms of the GNU Lesser General Public |
| 11218 | + License as published by the Free Software Foundation; either |
| 11219 | + version 2.1 of the License, or (at your option) any later version. |
| 11220 | + |
| 11221 | + The GNU C Library is distributed in the hope that it will be useful, |
| 11222 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11223 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11224 | + Lesser General Public License for more details. |
| 11225 | + |
| 11226 | + You should have received a copy of the GNU Lesser General Public |
| 11227 | + License along with the GNU C Library; if not, see |
| 11228 | + <http://www.gnu.org/licenses/>. */ |
| 11229 | + |
| 11230 | +#include <stdbool.h> |
| 11231 | +#include <stdio.h> |
| 11232 | +#include <stdlib.h> |
| 11233 | +#include <string.h> |
| 11234 | +#include <support/capture_subprocess.h> |
| 11235 | +#include <support/check.h> |
| 11236 | +#include <support/support.h> |
| 11237 | +#include <sys/wait.h> |
| 11238 | +#include <unistd.h> |
| 11239 | + |
| 11240 | +/* Write one byte at *P to FD and advance *P. Do nothing if *P is |
| 11241 | + '\0'. */ |
| 11242 | +static void |
| 11243 | +transfer (const unsigned char **p, int fd) |
| 11244 | +{ |
| 11245 | + if (**p != '\0') |
| 11246 | + { |
| 11247 | + TEST_VERIFY (write (fd, *p, 1) == 1); |
| 11248 | + ++*p; |
| 11249 | + } |
| 11250 | +} |
| 11251 | + |
| 11252 | +/* Determine the order in which stdout and stderr are written. */ |
| 11253 | +enum write_mode { out_first, err_first, interleave, |
| 11254 | + write_mode_last = interleave }; |
| 11255 | + |
| 11256 | +/* Describe what to write in the subprocess. */ |
| 11257 | +struct test |
| 11258 | +{ |
| 11259 | + char *out; |
| 11260 | + char *err; |
| 11261 | + enum write_mode write_mode; |
| 11262 | + int signal; |
| 11263 | + int status; |
| 11264 | +}; |
| 11265 | + |
| 11266 | +/* For use with support_capture_subprocess. */ |
| 11267 | +static void |
| 11268 | +callback (void *closure) |
| 11269 | +{ |
| 11270 | + const struct test *test = closure; |
| 11271 | + bool mode_ok = false; |
| 11272 | + switch (test->write_mode) |
| 11273 | + { |
| 11274 | + case out_first: |
| 11275 | + TEST_VERIFY (fputs (test->out, stdout) >= 0); |
| 11276 | + TEST_VERIFY (fflush (stdout) == 0); |
| 11277 | + TEST_VERIFY (fputs (test->err, stderr) >= 0); |
| 11278 | + TEST_VERIFY (fflush (stderr) == 0); |
| 11279 | + mode_ok = true; |
| 11280 | + break; |
| 11281 | + case err_first: |
| 11282 | + TEST_VERIFY (fputs (test->err, stderr) >= 0); |
| 11283 | + TEST_VERIFY (fflush (stderr) == 0); |
| 11284 | + TEST_VERIFY (fputs (test->out, stdout) >= 0); |
| 11285 | + TEST_VERIFY (fflush (stdout) == 0); |
| 11286 | + mode_ok = true; |
| 11287 | + break; |
| 11288 | + case interleave: |
| 11289 | + { |
| 11290 | + const unsigned char *pout = (const unsigned char *) test->out; |
| 11291 | + const unsigned char *perr = (const unsigned char *) test->err; |
| 11292 | + do |
| 11293 | + { |
| 11294 | + transfer (&pout, STDOUT_FILENO); |
| 11295 | + transfer (&perr, STDERR_FILENO); |
| 11296 | + } |
| 11297 | + while (*pout != '\0' || *perr != '\0'); |
| 11298 | + } |
| 11299 | + mode_ok = true; |
| 11300 | + break; |
| 11301 | + } |
| 11302 | + TEST_VERIFY (mode_ok); |
| 11303 | + |
| 11304 | + if (test->signal != 0) |
| 11305 | + raise (test->signal); |
| 11306 | + exit (test->status); |
| 11307 | +} |
| 11308 | + |
| 11309 | +/* Create a heap-allocated random string of letters. */ |
| 11310 | +static char * |
| 11311 | +random_string (size_t length) |
| 11312 | +{ |
| 11313 | + char *result = xmalloc (length + 1); |
| 11314 | + for (size_t i = 0; i < length; ++i) |
| 11315 | + result[i] = 'a' + (rand () % 26); |
| 11316 | + result[length] = '\0'; |
| 11317 | + return result; |
| 11318 | +} |
| 11319 | + |
| 11320 | +/* Check that the specific stream from the captured subprocess matches |
| 11321 | + expectations. */ |
| 11322 | +static void |
| 11323 | +check_stream (const char *what, const struct xmemstream *stream, |
| 11324 | + const char *expected) |
| 11325 | +{ |
| 11326 | + if (strcmp (stream->buffer, expected) != 0) |
| 11327 | + { |
| 11328 | + support_record_failure (); |
| 11329 | + printf ("error: captured %s data incorrect\n" |
| 11330 | + " expected: %s\n" |
| 11331 | + " actual: %s\n", |
| 11332 | + what, expected, stream->buffer); |
| 11333 | + } |
| 11334 | + if (stream->length != strlen (expected)) |
| 11335 | + { |
| 11336 | + support_record_failure (); |
| 11337 | + printf ("error: captured %s data length incorrect\n" |
| 11338 | + " expected: %zu\n" |
| 11339 | + " actual: %zu\n", |
| 11340 | + what, strlen (expected), stream->length); |
| 11341 | + } |
| 11342 | +} |
| 11343 | + |
| 11344 | +static int |
| 11345 | +do_test (void) |
| 11346 | +{ |
| 11347 | + const int lengths[] = {0, 1, 17, 512, 20000, -1}; |
| 11348 | + |
| 11349 | + /* Test multiple combinations of support_capture_subprocess. |
| 11350 | + |
| 11351 | + length_idx_stdout: Index into the lengths array above, |
| 11352 | + controls how many bytes are written by the subprocess to |
| 11353 | + standard output. |
| 11354 | + length_idx_stderr: Same for standard error. |
| 11355 | + write_mode: How standard output and standard error writes are |
| 11356 | + ordered. |
| 11357 | + signal: Exit with no signal if zero, with SIGTERM if one. |
| 11358 | + status: Process exit status: 0 if zero, 3 if one. */ |
| 11359 | + for (int length_idx_stdout = 0; lengths[length_idx_stdout] >= 0; |
| 11360 | + ++length_idx_stdout) |
| 11361 | + for (int length_idx_stderr = 0; lengths[length_idx_stderr] >= 0; |
| 11362 | + ++length_idx_stderr) |
| 11363 | + for (int write_mode = 0; write_mode < write_mode_last; ++write_mode) |
| 11364 | + for (int signal = 0; signal < 2; ++signal) |
| 11365 | + for (int status = 0; status < 2; ++status) |
| 11366 | + { |
| 11367 | + struct test test = |
| 11368 | + { |
| 11369 | + .out = random_string (lengths[length_idx_stdout]), |
| 11370 | + .err = random_string (lengths[length_idx_stderr]), |
| 11371 | + .write_mode = write_mode, |
| 11372 | + .signal = signal * SIGTERM, /* 0 or SIGTERM. */ |
| 11373 | + .status = status * 3, /* 0 or 3. */ |
| 11374 | + }; |
| 11375 | + TEST_VERIFY (strlen (test.out) == lengths[length_idx_stdout]); |
| 11376 | + TEST_VERIFY (strlen (test.err) == lengths[length_idx_stderr]); |
| 11377 | + |
| 11378 | + struct support_capture_subprocess result |
| 11379 | + = support_capture_subprocess (callback, &test); |
| 11380 | + check_stream ("stdout", &result.out, test.out); |
| 11381 | + check_stream ("stderr", &result.err, test.err); |
| 11382 | + if (test.signal != 0) |
| 11383 | + { |
| 11384 | + TEST_VERIFY (WIFSIGNALED (result.status)); |
| 11385 | + TEST_VERIFY (WTERMSIG (result.status) == test.signal); |
| 11386 | + } |
| 11387 | + else |
| 11388 | + { |
| 11389 | + TEST_VERIFY (WIFEXITED (result.status)); |
| 11390 | + TEST_VERIFY (WEXITSTATUS (result.status) == test.status); |
| 11391 | + } |
| 11392 | + support_capture_subprocess_free (&result); |
| 11393 | + free (test.out); |
| 11394 | + free (test.err); |
| 11395 | + } |
| 11396 | + return 0; |
| 11397 | +} |
| 11398 | + |
| 11399 | +#include <support/test-driver.c> |
| 11400 | diff --git a/support/tst-support_format_dns_packet.c b/support/tst-support_format_dns_packet.c |
| 11401 | new file mode 100644 |
| 11402 | index 0000000000..9c8589c09c |
| 11403 | --- /dev/null |
| 11404 | +++ b/support/tst-support_format_dns_packet.c |
| 11405 | @@ -0,0 +1,101 @@ |
| 11406 | +/* Tests for the support_format_dns_packet function. |
| 11407 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 11408 | + This file is part of the GNU C Library. |
| 11409 | + |
| 11410 | + The GNU C Library is free software; you can redistribute it and/or |
| 11411 | + modify it under the terms of the GNU Lesser General Public |
| 11412 | + License as published by the Free Software Foundation; either |
| 11413 | + version 2.1 of the License, or (at your option) any later version. |
| 11414 | + |
| 11415 | + The GNU C Library is distributed in the hope that it will be useful, |
| 11416 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11417 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11418 | + Lesser General Public License for more details. |
| 11419 | + |
| 11420 | + You should have received a copy of the GNU Lesser General Public |
| 11421 | + License along with the GNU C Library; if not, see |
| 11422 | + <http://www.gnu.org/licenses/>. */ |
| 11423 | + |
| 11424 | +#include <support/check.h> |
| 11425 | +#include <support/format_nss.h> |
| 11426 | +#include <support/run_diff.h> |
| 11427 | + |
| 11428 | +#include <stdio.h> |
| 11429 | +#include <stdlib.h> |
| 11430 | +#include <string.h> |
| 11431 | + |
| 11432 | +static void |
| 11433 | +check_packet (const void *buffer, size_t length, |
| 11434 | + const char *name, const char *expected) |
| 11435 | +{ |
| 11436 | + char *actual = support_format_dns_packet (buffer, length); |
| 11437 | + if (strcmp (actual, expected) != 0) |
| 11438 | + { |
| 11439 | + support_record_failure (); |
| 11440 | + printf ("error: formatted packet does not match: %s\n", name); |
| 11441 | + support_run_diff ("expected", expected, |
| 11442 | + "actual", actual); |
| 11443 | + } |
| 11444 | + free (actual); |
| 11445 | +} |
| 11446 | + |
| 11447 | +static void |
| 11448 | +test_aaaa_length (void) |
| 11449 | +{ |
| 11450 | + static const char packet[] = |
| 11451 | + /* Header: Response with two records. */ |
| 11452 | + "\x12\x34\x80\x00\x00\x01\x00\x02\x00\x00\x00\x00" |
| 11453 | + /* Question section. www.example/IN/AAAA. */ |
| 11454 | + "\x03www\x07""example\x00\x00\x1c\x00\x01" |
| 11455 | + /* Answer section. www.example AAAA [corrupted]. */ |
| 11456 | + "\xc0\x0c" |
| 11457 | + "\x00\x1c\x00\x01\x00\x00\x00\x00\x00\x10" |
| 11458 | + "\x20\x01\x0d\xb8\x05\x06\x07\x08" |
| 11459 | + "\x11\x12\x13\x14\x15\x16\x17\x18" |
| 11460 | + /* www.example AAAA [corrupted]. */ |
| 11461 | + "\xc0\x0c" |
| 11462 | + "\x00\x1c\x00\x01\x00\x00\x00\x00\x00\x11" |
| 11463 | + "\x01\x02\x03\x04\x05\x06\x07\x08" |
| 11464 | + "\x11\x12\x13\x14\x15\x16\x17\x18" "\xff"; |
| 11465 | + check_packet (packet, sizeof (packet) - 1, __func__, |
| 11466 | + "name: www.example\n" |
| 11467 | + "address: 2001:db8:506:708:1112:1314:1516:1718\n" |
| 11468 | + "error: AAAA record of size 17: www.example\n"); |
| 11469 | +} |
| 11470 | + |
| 11471 | +static void |
| 11472 | +test_multiple_cnames (void) |
| 11473 | +{ |
| 11474 | + static const char packet[] = |
| 11475 | + /* Header: Response with three records. */ |
| 11476 | + "\x12\x34\x80\x00\x00\x01\x00\x03\x00\x00\x00\x00" |
| 11477 | + /* Question section. www.example/IN/A. */ |
| 11478 | + "\x03www\x07""example\x00\x00\x01\x00\x01" |
| 11479 | + /* Answer section. www.example CNAME www1.example. */ |
| 11480 | + "\xc0\x0c" |
| 11481 | + "\x00\x05\x00\x01\x00\x00\x00\x00\x00\x07" |
| 11482 | + "\x04www1\xc0\x10" |
| 11483 | + /* www1 CNAME www2. */ |
| 11484 | + "\x04www1\xc0\x10" |
| 11485 | + "\x00\x05\x00\x01\x00\x00\x00\x00\x00\x07" |
| 11486 | + "\x04www2\xc0\x10" |
| 11487 | + /* www2 A 192.0.2.1. */ |
| 11488 | + "\x04www2\xc0\x10" |
| 11489 | + "\x00\x01\x00\x01\x00\x00\x00\x00\x00\x04" |
| 11490 | + "\xc0\x00\x02\x01"; |
| 11491 | + check_packet (packet, sizeof (packet) - 1, __func__, |
| 11492 | + "name: www.example\n" |
| 11493 | + "name: www1.example\n" |
| 11494 | + "name: www2.example\n" |
| 11495 | + "address: 192.0.2.1\n"); |
| 11496 | +} |
| 11497 | + |
| 11498 | +static int |
| 11499 | +do_test (void) |
| 11500 | +{ |
| 11501 | + test_aaaa_length (); |
| 11502 | + test_multiple_cnames (); |
| 11503 | + return 0; |
| 11504 | +} |
| 11505 | + |
| 11506 | +#include <support/test-driver.c> |
| 11507 | diff --git a/support/tst-support_record_failure-2.sh b/support/tst-support_record_failure-2.sh |
| 11508 | new file mode 100644 |
| 11509 | index 0000000000..2c9372cc29 |
| 11510 | --- /dev/null |
| 11511 | +++ b/support/tst-support_record_failure-2.sh |
| 11512 | @@ -0,0 +1,69 @@ |
| 11513 | +#!/bin/sh |
| 11514 | +# Test failure recording (with and without --direct). |
| 11515 | +# Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 11516 | +# This file is part of the GNU C Library. |
| 11517 | + |
| 11518 | +# The GNU C Library is free software; you can redistribute it and/or |
| 11519 | +# modify it under the terms of the GNU Lesser General Public |
| 11520 | +# License as published by the Free Software Foundation; either |
| 11521 | +# version 2.1 of the License, or (at your option) any later version. |
| 11522 | +# |
| 11523 | +# The GNU C Library is distributed in the hope that it will be useful, |
| 11524 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11525 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11526 | +# Lesser General Public License for more details. |
| 11527 | +# |
| 11528 | +# You should have received a copy of the GNU Lesser General Public |
| 11529 | +# License along with the GNU C Library; if not, see |
| 11530 | +# <http://www.gnu.org/licenses/>. */ |
| 11531 | + |
| 11532 | +set -e |
| 11533 | + |
| 11534 | +common_objpfx=$1; shift |
| 11535 | +test_program_prefix_before_env=$1; shift |
| 11536 | +run_program_env=$1; shift |
| 11537 | +test_program_prefix_after_env=$1; shift |
| 11538 | + |
| 11539 | +run_test () { |
| 11540 | + expected_status="$1" |
| 11541 | + expected_output="$2" |
| 11542 | + shift 2 |
| 11543 | + args="${common_objpfx}support/tst-support_record_failure $*" |
| 11544 | + echo "running: $args" |
| 11545 | + set +e |
| 11546 | + output="$(${test_program_prefix_before_env} \ |
| 11547 | + ${run_program} ${test_program_prefix_after_env} $args)" |
| 11548 | + status=$? |
| 11549 | + set -e |
| 11550 | + echo " exit status: $status" |
| 11551 | + if test "$output" != "$expected_output" ; then |
| 11552 | + echo "error: unexpected output: $output" |
| 11553 | + exit 1 |
| 11554 | + fi |
| 11555 | + if test "$status" -ne "$expected_status" ; then |
| 11556 | + echo "error: exit status $expected_status expected" |
| 11557 | + exit 1 |
| 11558 | + fi |
| 11559 | +} |
| 11560 | + |
| 11561 | +different_status () { |
| 11562 | + direct="$1" |
| 11563 | + run_test 1 "error: 1 test failures" $direct --status=0 |
| 11564 | + run_test 1 "error: 1 test failures" $direct --status=1 |
| 11565 | + run_test 2 "error: 1 test failures" $direct --status=2 |
| 11566 | + run_test 1 "error: 1 test failures" $direct --status=77 |
| 11567 | + run_test 2 "error: tst-support_record_failure.c:109: not true: false |
| 11568 | +error: 1 test failures" $direct --test-verify |
| 11569 | + run_test 2 "error: tst-support_record_failure.c:109: not true: false |
| 11570 | +info: execution passed failed TEST_VERIFY |
| 11571 | +error: 1 test failures" $direct --test-verify --verbose |
| 11572 | +} |
| 11573 | + |
| 11574 | +different_status |
| 11575 | +different_status --direct |
| 11576 | + |
| 11577 | +run_test 1 "error: tst-support_record_failure.c:116: not true: false |
| 11578 | +error: 1 test failures" --test-verify-exit |
| 11579 | +# --direct does not print the summary error message if exit is called. |
| 11580 | +run_test 1 "error: tst-support_record_failure.c:116: not true: false" \ |
| 11581 | + --direct --test-verify-exit |
| 11582 | diff --git a/support/tst-support_record_failure.c b/support/tst-support_record_failure.c |
| 11583 | new file mode 100644 |
| 11584 | index 0000000000..e739e739c3 |
| 11585 | --- /dev/null |
| 11586 | +++ b/support/tst-support_record_failure.c |
| 11587 | @@ -0,0 +1,153 @@ |
| 11588 | +/* Test support_record_failure state sharing. |
| 11589 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 11590 | + This file is part of the GNU C Library. |
| 11591 | + |
| 11592 | + The GNU C Library is free software; you can redistribute it and/or |
| 11593 | + modify it under the terms of the GNU Lesser General Public |
| 11594 | + License as published by the Free Software Foundation; either |
| 11595 | + version 2.1 of the License, or (at your option) any later version. |
| 11596 | + |
| 11597 | + The GNU C Library is distributed in the hope that it will be useful, |
| 11598 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11599 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11600 | + Lesser General Public License for more details. |
| 11601 | + |
| 11602 | + You should have received a copy of the GNU Lesser General Public |
| 11603 | + License along with the GNU C Library; if not, see |
| 11604 | + <http://www.gnu.org/licenses/>. */ |
| 11605 | + |
| 11606 | +#include <support/check.h> |
| 11607 | +#include <support/support.h> |
| 11608 | +#include <support/test-driver.h> |
| 11609 | +#include <support/xunistd.h> |
| 11610 | + |
| 11611 | +#include <getopt.h> |
| 11612 | +#include <stdbool.h> |
| 11613 | +#include <stdlib.h> |
| 11614 | +#include <stdio.h> |
| 11615 | +#include <string.h> |
| 11616 | + |
| 11617 | +static int exit_status_with_failure = -1; |
| 11618 | +static bool test_verify; |
| 11619 | +static bool test_verify_exit; |
| 11620 | +enum |
| 11621 | + { |
| 11622 | + OPT_STATUS = 10001, |
| 11623 | + OPT_TEST_VERIFY, |
| 11624 | + OPT_TEST_VERIFY_EXIT, |
| 11625 | + }; |
| 11626 | +#define CMDLINE_OPTIONS \ |
| 11627 | + { "status", required_argument, NULL, OPT_STATUS }, \ |
| 11628 | + { "test-verify", no_argument, NULL, OPT_TEST_VERIFY }, \ |
| 11629 | + { "test-verify-exit", no_argument, NULL, OPT_TEST_VERIFY_EXIT }, |
| 11630 | +static void |
| 11631 | +cmdline_process (int c) |
| 11632 | +{ |
| 11633 | + switch (c) |
| 11634 | + { |
| 11635 | + case OPT_STATUS: |
| 11636 | + exit_status_with_failure = atoi (optarg); |
| 11637 | + break; |
| 11638 | + case OPT_TEST_VERIFY: |
| 11639 | + test_verify = true; |
| 11640 | + break; |
| 11641 | + case OPT_TEST_VERIFY_EXIT: |
| 11642 | + test_verify_exit = true; |
| 11643 | + break; |
| 11644 | + } |
| 11645 | +} |
| 11646 | +#define CMDLINE_PROCESS cmdline_process |
| 11647 | + |
| 11648 | +static void |
| 11649 | +check_failure_reporting (int phase, int zero, int unsupported) |
| 11650 | +{ |
| 11651 | + int status = support_report_failure (0); |
| 11652 | + if (status != zero) |
| 11653 | + { |
| 11654 | + printf ("real-error (phase %d): support_report_failure (0) == %d\n", |
| 11655 | + phase, status); |
| 11656 | + exit (1); |
| 11657 | + } |
| 11658 | + status = support_report_failure (1); |
| 11659 | + if (status != 1) |
| 11660 | + { |
| 11661 | + printf ("real-error (phase %d): support_report_failure (1) == %d\n", |
| 11662 | + phase, status); |
| 11663 | + exit (1); |
| 11664 | + } |
| 11665 | + status = support_report_failure (2); |
| 11666 | + if (status != 2) |
| 11667 | + { |
| 11668 | + printf ("real-error (phase %d): support_report_failure (2) == %d\n", |
| 11669 | + phase, status); |
| 11670 | + exit (1); |
| 11671 | + } |
| 11672 | + status = support_report_failure (EXIT_UNSUPPORTED); |
| 11673 | + if (status != unsupported) |
| 11674 | + { |
| 11675 | + printf ("real-error (phase %d): " |
| 11676 | + "support_report_failure (EXIT_UNSUPPORTED) == %d\n", |
| 11677 | + phase, status); |
| 11678 | + exit (1); |
| 11679 | + } |
| 11680 | +} |
| 11681 | + |
| 11682 | +static int |
| 11683 | +do_test (void) |
| 11684 | +{ |
| 11685 | + if (exit_status_with_failure >= 0) |
| 11686 | + { |
| 11687 | + /* External invocation with requested error status. Used by |
| 11688 | + tst-support_report_failure-2.sh. */ |
| 11689 | + support_record_failure (); |
| 11690 | + return exit_status_with_failure; |
| 11691 | + } |
| 11692 | + TEST_VERIFY (true); |
| 11693 | + TEST_VERIFY_EXIT (true); |
| 11694 | + if (test_verify) |
| 11695 | + { |
| 11696 | + TEST_VERIFY (false); |
| 11697 | + if (test_verbose) |
| 11698 | + printf ("info: execution passed failed TEST_VERIFY\n"); |
| 11699 | + return 2; /* Expected exit status. */ |
| 11700 | + } |
| 11701 | + if (test_verify_exit) |
| 11702 | + { |
| 11703 | + TEST_VERIFY_EXIT (false); |
| 11704 | + return 3; /* Not reached. Expected exit status is 1. */ |
| 11705 | + } |
| 11706 | + |
| 11707 | + printf ("info: This test tests the test framework.\n" |
| 11708 | + "info: It reports some expected errors on stdout.\n"); |
| 11709 | + |
| 11710 | + /* Check that the status is passed through unchanged. */ |
| 11711 | + check_failure_reporting (1, 0, EXIT_UNSUPPORTED); |
| 11712 | + |
| 11713 | + /* Check state propagation from a subprocess. */ |
| 11714 | + pid_t pid = xfork (); |
| 11715 | + if (pid == 0) |
| 11716 | + { |
| 11717 | + support_record_failure (); |
| 11718 | + _exit (0); |
| 11719 | + } |
| 11720 | + int status; |
| 11721 | + xwaitpid (pid, &status, 0); |
| 11722 | + if (status != 0) |
| 11723 | + { |
| 11724 | + printf ("real-error: incorrect status from subprocess: %d\n", status); |
| 11725 | + return 1; |
| 11726 | + } |
| 11727 | + check_failure_reporting (2, 1, 1); |
| 11728 | + |
| 11729 | + /* Also test directly in the parent process. */ |
| 11730 | + support_record_failure_reset (); |
| 11731 | + check_failure_reporting (3, 0, EXIT_UNSUPPORTED); |
| 11732 | + support_record_failure (); |
| 11733 | + check_failure_reporting (4, 1, 1); |
| 11734 | + |
| 11735 | + /* We need to mask the failure above. */ |
| 11736 | + support_record_failure_reset (); |
| 11737 | + return 0; |
| 11738 | +} |
| 11739 | + |
| 11740 | +#include <support/test-driver.c> |
| 11741 | diff --git a/sysdeps/unix/sysv/linux/sh/pwrite64.c b/support/write_message.c |
| 11742 | similarity index 68% |
| 11743 | rename from sysdeps/unix/sysv/linux/sh/pwrite64.c |
| 11744 | rename to support/write_message.c |
| 11745 | index 683a5d9886..f03ed931d6 100644 |
| 11746 | --- a/sysdeps/unix/sysv/linux/sh/pwrite64.c |
| 11747 | +++ b/support/write_message.c |
| 11748 | @@ -1,6 +1,6 @@ |
| 11749 | -/* Copyright (C) 1997-2016 Free Software Foundation, Inc. |
| 11750 | +/* Write a message to standard output. |
| 11751 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 11752 | This file is part of the GNU C Library. |
| 11753 | - Contributed by Ralf Baechle <ralf@gnu.org>, 1998. |
| 11754 | |
| 11755 | The GNU C Library is free software; you can redistribute it and/or |
| 11756 | modify it under the terms of the GNU Lesser General Public |
| 11757 | @@ -16,8 +16,14 @@ |
| 11758 | License along with the GNU C Library; if not, see |
| 11759 | <http://www.gnu.org/licenses/>. */ |
| 11760 | |
| 11761 | -/* SH4 ABI does not really require argument alignment for 64-bits, but |
| 11762 | - the kernel interface for pread adds a dummy long argument before the |
| 11763 | - offset. */ |
| 11764 | -#define __ALIGNMENT_ARG |
| 11765 | -#include <sysdeps/unix/sysv/linux/pwrite64.c> |
| 11766 | +#include <support/support.h> |
| 11767 | + |
| 11768 | +#include <string.h> |
| 11769 | +#include <unistd.h> |
| 11770 | + |
| 11771 | +void |
| 11772 | +write_message (const char *message) |
| 11773 | +{ |
| 11774 | + ssize_t unused __attribute__ ((unused)); |
| 11775 | + unused = write (STDOUT_FILENO, message, strlen (message)); |
| 11776 | +} |
| 11777 | diff --git a/support/xaccept.c b/support/xaccept.c |
| 11778 | new file mode 100644 |
| 11779 | index 0000000000..7b25af3b05 |
| 11780 | --- /dev/null |
| 11781 | +++ b/support/xaccept.c |
| 11782 | @@ -0,0 +1,32 @@ |
| 11783 | +/* accept with error checking. |
| 11784 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 11785 | + This file is part of the GNU C Library. |
| 11786 | + |
| 11787 | + The GNU C Library is free software; you can redistribute it and/or |
| 11788 | + modify it under the terms of the GNU Lesser General Public |
| 11789 | + License as published by the Free Software Foundation; either |
| 11790 | + version 2.1 of the License, or (at your option) any later version. |
| 11791 | + |
| 11792 | + The GNU C Library is distributed in the hope that it will be useful, |
| 11793 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11794 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11795 | + Lesser General Public License for more details. |
| 11796 | + |
| 11797 | + You should have received a copy of the GNU Lesser General Public |
| 11798 | + License along with the GNU C Library; if not, see |
| 11799 | + <http://www.gnu.org/licenses/>. */ |
| 11800 | + |
| 11801 | +#include <support/xsocket.h> |
| 11802 | + |
| 11803 | +#include <stdio.h> |
| 11804 | +#include <stdlib.h> |
| 11805 | +#include <support/check.h> |
| 11806 | + |
| 11807 | +int |
| 11808 | +xaccept (int fd, struct sockaddr *sa, socklen_t *salen) |
| 11809 | +{ |
| 11810 | + int clientfd = accept (fd, sa, salen); |
| 11811 | + if (clientfd < 0) |
| 11812 | + FAIL_EXIT1 ("accept (%d): %m", fd); |
| 11813 | + return clientfd; |
| 11814 | +} |
| 11815 | diff --git a/support/xaccept4.c b/support/xaccept4.c |
| 11816 | new file mode 100644 |
| 11817 | index 0000000000..67dd95e9fb |
| 11818 | --- /dev/null |
| 11819 | +++ b/support/xaccept4.c |
| 11820 | @@ -0,0 +1,32 @@ |
| 11821 | +/* accept4 with error checking. |
| 11822 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 11823 | + This file is part of the GNU C Library. |
| 11824 | + |
| 11825 | + The GNU C Library is free software; you can redistribute it and/or |
| 11826 | + modify it under the terms of the GNU Lesser General Public |
| 11827 | + License as published by the Free Software Foundation; either |
| 11828 | + version 2.1 of the License, or (at your option) any later version. |
| 11829 | + |
| 11830 | + The GNU C Library is distributed in the hope that it will be useful, |
| 11831 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11832 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11833 | + Lesser General Public License for more details. |
| 11834 | + |
| 11835 | + You should have received a copy of the GNU Lesser General Public |
| 11836 | + License along with the GNU C Library; if not, see |
| 11837 | + <http://www.gnu.org/licenses/>. */ |
| 11838 | + |
| 11839 | +#include <support/xsocket.h> |
| 11840 | + |
| 11841 | +#include <stdio.h> |
| 11842 | +#include <stdlib.h> |
| 11843 | +#include <support/check.h> |
| 11844 | + |
| 11845 | +int |
| 11846 | +xaccept4 (int fd, struct sockaddr *sa, socklen_t *salen, int flags) |
| 11847 | +{ |
| 11848 | + int clientfd = accept4 (fd, sa, salen, flags); |
| 11849 | + if (clientfd < 0) |
| 11850 | + FAIL_EXIT1 ("accept4 (%d, 0x%x): %m", fd, flags); |
| 11851 | + return clientfd; |
| 11852 | +} |
| 11853 | diff --git a/support/xasprintf.c b/support/xasprintf.c |
| 11854 | new file mode 100644 |
| 11855 | index 0000000000..5157680fa2 |
| 11856 | --- /dev/null |
| 11857 | +++ b/support/xasprintf.c |
| 11858 | @@ -0,0 +1,36 @@ |
| 11859 | +/* Error-checking wrapper for asprintf. |
| 11860 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 11861 | + This file is part of the GNU C Library. |
| 11862 | + |
| 11863 | + The GNU C Library is free software; you can redistribute it and/or |
| 11864 | + modify it under the terms of the GNU Lesser General Public |
| 11865 | + License as published by the Free Software Foundation; either |
| 11866 | + version 2.1 of the License, or (at your option) any later version. |
| 11867 | + |
| 11868 | + The GNU C Library is distributed in the hope that it will be useful, |
| 11869 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11870 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11871 | + Lesser General Public License for more details. |
| 11872 | + |
| 11873 | + You should have received a copy of the GNU Lesser General Public |
| 11874 | + License along with the GNU C Library; if not, see |
| 11875 | + <http://www.gnu.org/licenses/>. */ |
| 11876 | + |
| 11877 | +#include <support/support.h> |
| 11878 | + |
| 11879 | +#include <stdarg.h> |
| 11880 | +#include <stdio.h> |
| 11881 | +#include <stdlib.h> |
| 11882 | +#include <support/check.h> |
| 11883 | + |
| 11884 | +char * |
| 11885 | +xasprintf (const char *format, ...) |
| 11886 | +{ |
| 11887 | + va_list ap; |
| 11888 | + va_start (ap, format); |
| 11889 | + char *result; |
| 11890 | + if (vasprintf (&result, format, ap) < 0) |
| 11891 | + FAIL_EXIT1 ("asprintf: %m"); |
| 11892 | + va_end (ap); |
| 11893 | + return result; |
| 11894 | +} |
| 11895 | diff --git a/support/xbind.c b/support/xbind.c |
| 11896 | new file mode 100644 |
| 11897 | index 0000000000..cfc6dd8fa8 |
| 11898 | --- /dev/null |
| 11899 | +++ b/support/xbind.c |
| 11900 | @@ -0,0 +1,30 @@ |
| 11901 | +/* bind with error checking. |
| 11902 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 11903 | + This file is part of the GNU C Library. |
| 11904 | + |
| 11905 | + The GNU C Library is free software; you can redistribute it and/or |
| 11906 | + modify it under the terms of the GNU Lesser General Public |
| 11907 | + License as published by the Free Software Foundation; either |
| 11908 | + version 2.1 of the License, or (at your option) any later version. |
| 11909 | + |
| 11910 | + The GNU C Library is distributed in the hope that it will be useful, |
| 11911 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11912 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11913 | + Lesser General Public License for more details. |
| 11914 | + |
| 11915 | + You should have received a copy of the GNU Lesser General Public |
| 11916 | + License along with the GNU C Library; if not, see |
| 11917 | + <http://www.gnu.org/licenses/>. */ |
| 11918 | + |
| 11919 | +#include <support/xsocket.h> |
| 11920 | + |
| 11921 | +#include <stdio.h> |
| 11922 | +#include <stdlib.h> |
| 11923 | +#include <support/check.h> |
| 11924 | + |
| 11925 | +void |
| 11926 | +xbind (int fd, const struct sockaddr *sa, socklen_t sa_len) |
| 11927 | +{ |
| 11928 | + if (bind (fd, sa, sa_len) != 0) |
| 11929 | + FAIL_EXIT1 ("bind (%d), family %d: %m", fd, sa->sa_family); |
| 11930 | +} |
| 11931 | diff --git a/sysdeps/unix/sysv/linux/sh/pread64.c b/support/xcalloc.c |
| 11932 | similarity index 67% |
| 11933 | rename from sysdeps/unix/sysv/linux/sh/pread64.c |
| 11934 | rename to support/xcalloc.c |
| 11935 | index b2e8a25788..135f42dab2 100644 |
| 11936 | --- a/sysdeps/unix/sysv/linux/sh/pread64.c |
| 11937 | +++ b/support/xcalloc.c |
| 11938 | @@ -1,6 +1,6 @@ |
| 11939 | -/* Copyright (C) 1997-2016 Free Software Foundation, Inc. |
| 11940 | +/* Error-checking wrapper for calloc. |
| 11941 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 11942 | This file is part of the GNU C Library. |
| 11943 | - Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. |
| 11944 | |
| 11945 | The GNU C Library is free software; you can redistribute it and/or |
| 11946 | modify it under the terms of the GNU Lesser General Public |
| 11947 | @@ -16,8 +16,19 @@ |
| 11948 | License along with the GNU C Library; if not, see |
| 11949 | <http://www.gnu.org/licenses/>. */ |
| 11950 | |
| 11951 | -/* SH4 ABI does not really require argument alignment for 64-bits, but |
| 11952 | - the kernel interface for pread adds a dummy long argument before the |
| 11953 | - offset. */ |
| 11954 | -#define __ALIGNMENT_ARG |
| 11955 | -#include <sysdeps/unix/sysv/linux/pread64.c> |
| 11956 | +#include <support/support.h> |
| 11957 | + |
| 11958 | +#include <stdarg.h> |
| 11959 | +#include <stdio.h> |
| 11960 | +#include <stdlib.h> |
| 11961 | + |
| 11962 | +void * |
| 11963 | +xcalloc (size_t n, size_t s) |
| 11964 | +{ |
| 11965 | + void *p; |
| 11966 | + |
| 11967 | + p = calloc (n, s); |
| 11968 | + if (p == NULL) |
| 11969 | + oom_error ("calloc", n * s); |
| 11970 | + return p; |
| 11971 | +} |
| 11972 | diff --git a/support/xchroot.c b/support/xchroot.c |
| 11973 | new file mode 100644 |
| 11974 | index 0000000000..abcc299e00 |
| 11975 | --- /dev/null |
| 11976 | +++ b/support/xchroot.c |
| 11977 | @@ -0,0 +1,28 @@ |
| 11978 | +/* chroot with error checking. |
| 11979 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 11980 | + This file is part of the GNU C Library. |
| 11981 | + |
| 11982 | + The GNU C Library is free software; you can redistribute it and/or |
| 11983 | + modify it under the terms of the GNU Lesser General Public |
| 11984 | + License as published by the Free Software Foundation; either |
| 11985 | + version 2.1 of the License, or (at your option) any later version. |
| 11986 | + |
| 11987 | + The GNU C Library is distributed in the hope that it will be useful, |
| 11988 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11989 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11990 | + Lesser General Public License for more details. |
| 11991 | + |
| 11992 | + You should have received a copy of the GNU Lesser General Public |
| 11993 | + License along with the GNU C Library; if not, see |
| 11994 | + <http://www.gnu.org/licenses/>. */ |
| 11995 | + |
| 11996 | +#include <support/check.h> |
| 11997 | +#include <support/xunistd.h> |
| 11998 | +#include <sys/stat.h> |
| 11999 | + |
| 12000 | +void |
| 12001 | +xchroot (const char *path) |
| 12002 | +{ |
| 12003 | + if (chroot (path) != 0) |
| 12004 | + FAIL_EXIT1 ("chroot (\"%s\"): %m", path); |
| 12005 | +} |
| 12006 | diff --git a/support/xclose.c b/support/xclose.c |
| 12007 | new file mode 100644 |
| 12008 | index 0000000000..c931e08421 |
| 12009 | --- /dev/null |
| 12010 | +++ b/support/xclose.c |
| 12011 | @@ -0,0 +1,28 @@ |
| 12012 | +/* close with error checking. |
| 12013 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 12014 | + This file is part of the GNU C Library. |
| 12015 | + |
| 12016 | + The GNU C Library is free software; you can redistribute it and/or |
| 12017 | + modify it under the terms of the GNU Lesser General Public |
| 12018 | + License as published by the Free Software Foundation; either |
| 12019 | + version 2.1 of the License, or (at your option) any later version. |
| 12020 | + |
| 12021 | + The GNU C Library is distributed in the hope that it will be useful, |
| 12022 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12023 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12024 | + Lesser General Public License for more details. |
| 12025 | + |
| 12026 | + You should have received a copy of the GNU Lesser General Public |
| 12027 | + License along with the GNU C Library; if not, see |
| 12028 | + <http://www.gnu.org/licenses/>. */ |
| 12029 | + |
| 12030 | +#include <support/xunistd.h> |
| 12031 | +#include <support/check.h> |
| 12032 | +#include <errno.h> |
| 12033 | + |
| 12034 | +void |
| 12035 | +xclose (int fd) |
| 12036 | +{ |
| 12037 | + if (close (fd) < 0 && errno != EINTR) |
| 12038 | + FAIL_EXIT1 ("close of descriptor %d failed: %m", fd); |
| 12039 | +} |
| 12040 | diff --git a/support/xconnect.c b/support/xconnect.c |
| 12041 | new file mode 100644 |
| 12042 | index 0000000000..0266dbc643 |
| 12043 | --- /dev/null |
| 12044 | +++ b/support/xconnect.c |
| 12045 | @@ -0,0 +1,30 @@ |
| 12046 | +/* connect with error checking. |
| 12047 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 12048 | + This file is part of the GNU C Library. |
| 12049 | + |
| 12050 | + The GNU C Library is free software; you can redistribute it and/or |
| 12051 | + modify it under the terms of the GNU Lesser General Public |
| 12052 | + License as published by the Free Software Foundation; either |
| 12053 | + version 2.1 of the License, or (at your option) any later version. |
| 12054 | + |
| 12055 | + The GNU C Library is distributed in the hope that it will be useful, |
| 12056 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12057 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12058 | + Lesser General Public License for more details. |
| 12059 | + |
| 12060 | + You should have received a copy of the GNU Lesser General Public |
| 12061 | + License along with the GNU C Library; if not, see |
| 12062 | + <http://www.gnu.org/licenses/>. */ |
| 12063 | + |
| 12064 | +#include <support/xsocket.h> |
| 12065 | + |
| 12066 | +#include <stdio.h> |
| 12067 | +#include <stdlib.h> |
| 12068 | +#include <support/check.h> |
| 12069 | + |
| 12070 | +void |
| 12071 | +xconnect (int fd, const struct sockaddr *sa, socklen_t sa_len) |
| 12072 | +{ |
| 12073 | + if (connect (fd, sa, sa_len) != 0) |
| 12074 | + FAIL_EXIT1 ("connect (%d), family %d: %m", fd, sa->sa_family); |
| 12075 | +} |
| 12076 | diff --git a/support/xdup2.c b/support/xdup2.c |
| 12077 | new file mode 100644 |
| 12078 | index 0000000000..dc08c94518 |
| 12079 | --- /dev/null |
| 12080 | +++ b/support/xdup2.c |
| 12081 | @@ -0,0 +1,28 @@ |
| 12082 | +/* dup2 with error checking. |
| 12083 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 12084 | + This file is part of the GNU C Library. |
| 12085 | + |
| 12086 | + The GNU C Library is free software; you can redistribute it and/or |
| 12087 | + modify it under the terms of the GNU Lesser General Public |
| 12088 | + License as published by the Free Software Foundation; either |
| 12089 | + version 2.1 of the License, or (at your option) any later version. |
| 12090 | + |
| 12091 | + The GNU C Library is distributed in the hope that it will be useful, |
| 12092 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12093 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12094 | + Lesser General Public License for more details. |
| 12095 | + |
| 12096 | + You should have received a copy of the GNU Lesser General Public |
| 12097 | + License along with the GNU C Library; if not, see |
| 12098 | + <http://www.gnu.org/licenses/>. */ |
| 12099 | + |
| 12100 | +#include <support/xunistd.h> |
| 12101 | + |
| 12102 | +#include <support/check.h> |
| 12103 | + |
| 12104 | +void |
| 12105 | +xdup2 (int from, int to) |
| 12106 | +{ |
| 12107 | + if (dup2 (from, to) < 0) |
| 12108 | + FAIL_EXIT1 ("dup2 (%d, %d): %m", from, to); |
| 12109 | +} |
| 12110 | diff --git a/support/xfclose.c b/support/xfclose.c |
| 12111 | new file mode 100644 |
| 12112 | index 0000000000..2737f05044 |
| 12113 | --- /dev/null |
| 12114 | +++ b/support/xfclose.c |
| 12115 | @@ -0,0 +1,33 @@ |
| 12116 | +/* fclose with error checking. |
| 12117 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 12118 | + This file is part of the GNU C Library. |
| 12119 | + |
| 12120 | + The GNU C Library is free software; you can redistribute it and/or |
| 12121 | + modify it under the terms of the GNU Lesser General Public |
| 12122 | + License as published by the Free Software Foundation; either |
| 12123 | + version 2.1 of the License, or (at your option) any later version. |
| 12124 | + |
| 12125 | + The GNU C Library is distributed in the hope that it will be useful, |
| 12126 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12127 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12128 | + Lesser General Public License for more details. |
| 12129 | + |
| 12130 | + You should have received a copy of the GNU Lesser General Public |
| 12131 | + License along with the GNU C Library; if not, see |
| 12132 | + <http://www.gnu.org/licenses/>. */ |
| 12133 | + |
| 12134 | +#include <support/xstdio.h> |
| 12135 | + |
| 12136 | +#include <support/check.h> |
| 12137 | +#include <stdlib.h> |
| 12138 | + |
| 12139 | +void |
| 12140 | +xfclose (FILE *fp) |
| 12141 | +{ |
| 12142 | + if (ferror (fp)) |
| 12143 | + FAIL_EXIT1 ("stdio stream closed with pending errors"); |
| 12144 | + if (fflush (fp) != 0) |
| 12145 | + FAIL_EXIT1 ("fflush: %m"); |
| 12146 | + if (fclose (fp) != 0) |
| 12147 | + FAIL_EXIT1 ("fclose: %m"); |
| 12148 | +} |
| 12149 | diff --git a/sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_fdimf-vis3.S b/support/xfopen.c |
| 12150 | similarity index 67% |
| 12151 | rename from sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_fdimf-vis3.S |
| 12152 | rename to support/xfopen.c |
| 12153 | index 081fc15b62..14532a09f3 100644 |
| 12154 | --- a/sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_fdimf-vis3.S |
| 12155 | +++ b/support/xfopen.c |
| 12156 | @@ -1,7 +1,6 @@ |
| 12157 | -/* Compute positive difference, sparc 32-bit+v9+vis3. |
| 12158 | - Copyright (C) 2013-2016 Free Software Foundation, Inc. |
| 12159 | +/* fopen with error checking. |
| 12160 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 12161 | This file is part of the GNU C Library. |
| 12162 | - Contributed by David S. Miller <davem@davemloft.net>. |
| 12163 | |
| 12164 | The GNU C Library is free software; you can redistribute it and/or |
| 12165 | modify it under the terms of the GNU Lesser General Public |
| 12166 | @@ -17,16 +16,16 @@ |
| 12167 | License along with the GNU C Library; if not, see |
| 12168 | <http://www.gnu.org/licenses/>. */ |
| 12169 | |
| 12170 | -#include <sysdep.h> |
| 12171 | +#include <support/xstdio.h> |
| 12172 | |
| 12173 | -ENTRY(__fdimf_vis3) |
| 12174 | - movwtos %o0, %f0 |
| 12175 | - movwtos %o1, %f1 |
| 12176 | - fcmps %f0, %f1 |
| 12177 | - fbug 1f |
| 12178 | - nop |
| 12179 | - fzeros %f0 |
| 12180 | - fnegs %f0, %f1 |
| 12181 | -1: retl |
| 12182 | - fsubs %f0, %f1, %f0 |
| 12183 | -END(__fdimf_vis3) |
| 12184 | +#include <support/check.h> |
| 12185 | +#include <stdlib.h> |
| 12186 | + |
| 12187 | +FILE * |
| 12188 | +xfopen (const char *path, const char *mode) |
| 12189 | +{ |
| 12190 | + FILE *fp = fopen (path, mode); |
| 12191 | + if (fp == NULL) |
| 12192 | + FAIL_EXIT1 ("could not open %s (mode \"%s\"): %m", path, mode); |
| 12193 | + return fp; |
| 12194 | +} |
| 12195 | diff --git a/support/xfork.c b/support/xfork.c |
| 12196 | new file mode 100644 |
| 12197 | index 0000000000..aa52ba62c5 |
| 12198 | --- /dev/null |
| 12199 | +++ b/support/xfork.c |
| 12200 | @@ -0,0 +1,32 @@ |
| 12201 | +/* fork with error checking. |
| 12202 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 12203 | + This file is part of the GNU C Library. |
| 12204 | + |
| 12205 | + The GNU C Library is free software; you can redistribute it and/or |
| 12206 | + modify it under the terms of the GNU Lesser General Public |
| 12207 | + License as published by the Free Software Foundation; either |
| 12208 | + version 2.1 of the License, or (at your option) any later version. |
| 12209 | + |
| 12210 | + The GNU C Library is distributed in the hope that it will be useful, |
| 12211 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12212 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12213 | + Lesser General Public License for more details. |
| 12214 | + |
| 12215 | + You should have received a copy of the GNU Lesser General Public |
| 12216 | + License along with the GNU C Library; if not, see |
| 12217 | + <http://www.gnu.org/licenses/>. */ |
| 12218 | + |
| 12219 | +#include <support/xunistd.h> |
| 12220 | + |
| 12221 | +#include <stdio.h> |
| 12222 | +#include <stdlib.h> |
| 12223 | +#include <support/check.h> |
| 12224 | + |
| 12225 | +pid_t |
| 12226 | +xfork (void) |
| 12227 | +{ |
| 12228 | + pid_t result = fork (); |
| 12229 | + if (result < 0) |
| 12230 | + FAIL_EXIT1 ("fork: %m"); |
| 12231 | + return result; |
| 12232 | +} |
| 12233 | diff --git a/support/xgetsockname.c b/support/xgetsockname.c |
| 12234 | new file mode 100644 |
| 12235 | index 0000000000..c3bd884f8d |
| 12236 | --- /dev/null |
| 12237 | +++ b/support/xgetsockname.c |
| 12238 | @@ -0,0 +1,30 @@ |
| 12239 | +/* getsockname with error checking. |
| 12240 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 12241 | + This file is part of the GNU C Library. |
| 12242 | + |
| 12243 | + The GNU C Library is free software; you can redistribute it and/or |
| 12244 | + modify it under the terms of the GNU Lesser General Public |
| 12245 | + License as published by the Free Software Foundation; either |
| 12246 | + version 2.1 of the License, or (at your option) any later version. |
| 12247 | + |
| 12248 | + The GNU C Library is distributed in the hope that it will be useful, |
| 12249 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12250 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12251 | + Lesser General Public License for more details. |
| 12252 | + |
| 12253 | + You should have received a copy of the GNU Lesser General Public |
| 12254 | + License along with the GNU C Library; if not, see |
| 12255 | + <http://www.gnu.org/licenses/>. */ |
| 12256 | + |
| 12257 | +#include <support/xsocket.h> |
| 12258 | + |
| 12259 | +#include <stdio.h> |
| 12260 | +#include <stdlib.h> |
| 12261 | +#include <support/check.h> |
| 12262 | + |
| 12263 | +void |
| 12264 | +xgetsockname (int fd, struct sockaddr *sa, socklen_t *plen) |
| 12265 | +{ |
| 12266 | + if (getsockname (fd, sa, plen) != 0) |
| 12267 | + FAIL_EXIT1 ("setsockopt (%d): %m", fd); |
| 12268 | +} |
| 12269 | diff --git a/support/xlisten.c b/support/xlisten.c |
| 12270 | new file mode 100644 |
| 12271 | index 0000000000..1953e5900a |
| 12272 | --- /dev/null |
| 12273 | +++ b/support/xlisten.c |
| 12274 | @@ -0,0 +1,30 @@ |
| 12275 | +/* listen with error checking. |
| 12276 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 12277 | + This file is part of the GNU C Library. |
| 12278 | + |
| 12279 | + The GNU C Library is free software; you can redistribute it and/or |
| 12280 | + modify it under the terms of the GNU Lesser General Public |
| 12281 | + License as published by the Free Software Foundation; either |
| 12282 | + version 2.1 of the License, or (at your option) any later version. |
| 12283 | + |
| 12284 | + The GNU C Library is distributed in the hope that it will be useful, |
| 12285 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12286 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12287 | + Lesser General Public License for more details. |
| 12288 | + |
| 12289 | + You should have received a copy of the GNU Lesser General Public |
| 12290 | + License along with the GNU C Library; if not, see |
| 12291 | + <http://www.gnu.org/licenses/>. */ |
| 12292 | + |
| 12293 | +#include <support/xsocket.h> |
| 12294 | + |
| 12295 | +#include <stdio.h> |
| 12296 | +#include <stdlib.h> |
| 12297 | +#include <support/check.h> |
| 12298 | + |
| 12299 | +void |
| 12300 | +xlisten (int fd, int backlog) |
| 12301 | +{ |
| 12302 | + if (listen (fd, backlog) != 0) |
| 12303 | + FAIL_EXIT1 ("listen (%d, %d): %m", fd, backlog); |
| 12304 | +} |
| 12305 | diff --git a/support/xmalloc.c b/support/xmalloc.c |
| 12306 | new file mode 100644 |
| 12307 | index 0000000000..450f699789 |
| 12308 | --- /dev/null |
| 12309 | +++ b/support/xmalloc.c |
| 12310 | @@ -0,0 +1,34 @@ |
| 12311 | +/* Error-checking wrapper for malloc. |
| 12312 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 12313 | + This file is part of the GNU C Library. |
| 12314 | + |
| 12315 | + The GNU C Library is free software; you can redistribute it and/or |
| 12316 | + modify it under the terms of the GNU Lesser General Public |
| 12317 | + License as published by the Free Software Foundation; either |
| 12318 | + version 2.1 of the License, or (at your option) any later version. |
| 12319 | + |
| 12320 | + The GNU C Library is distributed in the hope that it will be useful, |
| 12321 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12322 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12323 | + Lesser General Public License for more details. |
| 12324 | + |
| 12325 | + You should have received a copy of the GNU Lesser General Public |
| 12326 | + License along with the GNU C Library; if not, see |
| 12327 | + <http://www.gnu.org/licenses/>. */ |
| 12328 | + |
| 12329 | +#include <support/support.h> |
| 12330 | + |
| 12331 | +#include <stdarg.h> |
| 12332 | +#include <stdio.h> |
| 12333 | +#include <stdlib.h> |
| 12334 | + |
| 12335 | +void * |
| 12336 | +xmalloc (size_t n) |
| 12337 | +{ |
| 12338 | + void *p; |
| 12339 | + |
| 12340 | + p = malloc (n); |
| 12341 | + if (p == NULL) |
| 12342 | + oom_error ("malloc", n); |
| 12343 | + return p; |
| 12344 | +} |
| 12345 | diff --git a/sysdeps/sparc/sparc32/fpu/s_fdim.S b/support/xmemstream.c |
| 12346 | similarity index 54% |
| 12347 | rename from sysdeps/sparc/sparc32/fpu/s_fdim.S |
| 12348 | rename to support/xmemstream.c |
| 12349 | index e93970faae..bce6dc9170 100644 |
| 12350 | --- a/sysdeps/sparc/sparc32/fpu/s_fdim.S |
| 12351 | +++ b/support/xmemstream.c |
| 12352 | @@ -1,7 +1,6 @@ |
| 12353 | -/* Compute positive difference, sparc 32-bit. |
| 12354 | - Copyright (C) 2013-2016 Free Software Foundation, Inc. |
| 12355 | +/* Error-checking wrappers for memstream functions. |
| 12356 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 12357 | This file is part of the GNU C Library. |
| 12358 | - Contributed by David S. Miller <davem@davemloft.net>. |
| 12359 | |
| 12360 | The GNU C Library is free software; you can redistribute it and/or |
| 12361 | modify it under the terms of the GNU Lesser General Public |
| 12362 | @@ -17,26 +16,27 @@ |
| 12363 | License along with the GNU C Library; if not, see |
| 12364 | <http://www.gnu.org/licenses/>. */ |
| 12365 | |
| 12366 | -#include <sysdep.h> |
| 12367 | -#include <math_ldbl_opt.h> |
| 12368 | +#include <support/xmemstream.h> |
| 12369 | |
| 12370 | -ENTRY(__fdim) |
| 12371 | - std %o0, [%sp + 72] |
| 12372 | - std %o2, [%sp + 80] |
| 12373 | - ldd [%sp + 72], %f0 |
| 12374 | - ldd [%sp + 80], %f2 |
| 12375 | - fcmpd %f0, %f2 |
| 12376 | - st %g0, [%sp + 72] |
| 12377 | - fbug 1f |
| 12378 | - st %g0, [%sp + 76] |
| 12379 | - ldd [%sp + 72], %f0 |
| 12380 | - fnegs %f0, %f2 |
| 12381 | - fmovs %f1, %f3 |
| 12382 | -1: retl |
| 12383 | - fsubd %f0, %f2, %f0 |
| 12384 | -END(__fdim) |
| 12385 | -weak_alias (__fdim, fdim) |
| 12386 | +#include <errno.h> |
| 12387 | +#include <stdlib.h> |
| 12388 | +#include <support/check.h> |
| 12389 | +#include <support/xstdio.h> |
| 12390 | |
| 12391 | -#if LONG_DOUBLE_COMPAT(libm, GLIBC_2_1) |
| 12392 | -compat_symbol (libm, __fdim, fdiml, GLIBC_2_1); |
| 12393 | -#endif |
| 12394 | +void |
| 12395 | +xopen_memstream (struct xmemstream *stream) |
| 12396 | +{ |
| 12397 | + int old_errno = errno; |
| 12398 | + *stream = (struct xmemstream) {}; |
| 12399 | + stream->out = open_memstream (&stream->buffer, &stream->length); |
| 12400 | + if (stream->out == NULL) |
| 12401 | + FAIL_EXIT1 ("open_memstream: %m"); |
| 12402 | + errno = old_errno; |
| 12403 | +} |
| 12404 | + |
| 12405 | +void |
| 12406 | +xfclose_memstream (struct xmemstream *stream) |
| 12407 | +{ |
| 12408 | + xfclose (stream->out); |
| 12409 | + stream->out = NULL; |
| 12410 | +} |
| 12411 | diff --git a/support/xmemstream.h b/support/xmemstream.h |
| 12412 | new file mode 100644 |
| 12413 | index 0000000000..e5ba231e4d |
| 12414 | --- /dev/null |
| 12415 | +++ b/support/xmemstream.h |
| 12416 | @@ -0,0 +1,49 @@ |
| 12417 | +/* Error-checking wrappers for memstream functions. |
| 12418 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 12419 | + This file is part of the GNU C Library. |
| 12420 | + |
| 12421 | + The GNU C Library is free software; you can redistribute it and/or |
| 12422 | + modify it under the terms of the GNU Lesser General Public |
| 12423 | + License as published by the Free Software Foundation; either |
| 12424 | + version 2.1 of the License, or (at your option) any later version. |
| 12425 | + |
| 12426 | + The GNU C Library is distributed in the hope that it will be useful, |
| 12427 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12428 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12429 | + Lesser General Public License for more details. |
| 12430 | + |
| 12431 | + You should have received a copy of the GNU Lesser General Public |
| 12432 | + License along with the GNU C Library; if not, see |
| 12433 | + <http://www.gnu.org/licenses/>. */ |
| 12434 | + |
| 12435 | +#ifndef SUPPORT_XMEMSTREAM_H |
| 12436 | +#define SUPPORT_XMEMSTREAM_H |
| 12437 | + |
| 12438 | +#include <stdio.h> |
| 12439 | +#include <sys/cdefs.h> |
| 12440 | + |
| 12441 | +__BEGIN_DECLS |
| 12442 | + |
| 12443 | +/* Wrappers for other libc functions. */ |
| 12444 | +struct xmemstream |
| 12445 | +{ |
| 12446 | + FILE *out; |
| 12447 | + char *buffer; |
| 12448 | + size_t length; |
| 12449 | +}; |
| 12450 | + |
| 12451 | +/* Create a new in-memory stream. Initializes *STREAM. After this |
| 12452 | + function returns, STREAM->out is a file descriptor open for |
| 12453 | + writing. errno is preserved, so that the %m format specifier can |
| 12454 | + be used for writing to STREAM->out. */ |
| 12455 | +void xopen_memstream (struct xmemstream *stream); |
| 12456 | + |
| 12457 | +/* Closes STREAM->OUT. After this function returns, STREAM->buffer |
| 12458 | + and STREAM->length denote a memory range which contains the bytes |
| 12459 | + written to the output stream. The caller should free |
| 12460 | + STREAM->buffer. */ |
| 12461 | +void xfclose_memstream (struct xmemstream *stream); |
| 12462 | + |
| 12463 | +__END_DECLS |
| 12464 | + |
| 12465 | +#endif /* SUPPORT_XMEMSTREAM_H */ |
| 12466 | diff --git a/support/xmkdir.c b/support/xmkdir.c |
| 12467 | new file mode 100644 |
| 12468 | index 0000000000..ea17d49391 |
| 12469 | --- /dev/null |
| 12470 | +++ b/support/xmkdir.c |
| 12471 | @@ -0,0 +1,28 @@ |
| 12472 | +/* mkdir with error checking. |
| 12473 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 12474 | + This file is part of the GNU C Library. |
| 12475 | + |
| 12476 | + The GNU C Library is free software; you can redistribute it and/or |
| 12477 | + modify it under the terms of the GNU Lesser General Public |
| 12478 | + License as published by the Free Software Foundation; either |
| 12479 | + version 2.1 of the License, or (at your option) any later version. |
| 12480 | + |
| 12481 | + The GNU C Library is distributed in the hope that it will be useful, |
| 12482 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12483 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12484 | + Lesser General Public License for more details. |
| 12485 | + |
| 12486 | + You should have received a copy of the GNU Lesser General Public |
| 12487 | + License along with the GNU C Library; if not, see |
| 12488 | + <http://www.gnu.org/licenses/>. */ |
| 12489 | + |
| 12490 | +#include <support/check.h> |
| 12491 | +#include <support/xunistd.h> |
| 12492 | +#include <sys/stat.h> |
| 12493 | + |
| 12494 | +void |
| 12495 | +xmkdir (const char *path, mode_t mode) |
| 12496 | +{ |
| 12497 | + if (mkdir (path, mode) != 0) |
| 12498 | + FAIL_EXIT1 ("mkdir (\"%s\", 0%o): %m", path, mode); |
| 12499 | +} |
| 12500 | diff --git a/support/xmmap.c b/support/xmmap.c |
| 12501 | new file mode 100644 |
| 12502 | index 0000000000..435b1eb733 |
| 12503 | --- /dev/null |
| 12504 | +++ b/support/xmmap.c |
| 12505 | @@ -0,0 +1,31 @@ |
| 12506 | +/* mmap with error checking. |
| 12507 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 12508 | + This file is part of the GNU C Library. |
| 12509 | + |
| 12510 | + The GNU C Library is free software; you can redistribute it and/or |
| 12511 | + modify it under the terms of the GNU Lesser General Public |
| 12512 | + License as published by the Free Software Foundation; either |
| 12513 | + version 2.1 of the License, or (at your option) any later version. |
| 12514 | + |
| 12515 | + The GNU C Library is distributed in the hope that it will be useful, |
| 12516 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12517 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12518 | + Lesser General Public License for more details. |
| 12519 | + |
| 12520 | + You should have received a copy of the GNU Lesser General Public |
| 12521 | + License along with the GNU C Library; if not, see |
| 12522 | + <http://www.gnu.org/licenses/>. */ |
| 12523 | + |
| 12524 | +#include <support/check.h> |
| 12525 | +#include <support/xunistd.h> |
| 12526 | +#include <sys/mman.h> |
| 12527 | + |
| 12528 | +void * |
| 12529 | +xmmap (void *addr, size_t length, int prot, int flags, int fd) |
| 12530 | +{ |
| 12531 | + void *result = mmap (addr, length, prot, flags, fd, 0); |
| 12532 | + if (result == MAP_FAILED) |
| 12533 | + FAIL_EXIT1 ("mmap of %zu bytes, prot=0x%x, flags=0x%x: %m", |
| 12534 | + length, prot, flags); |
| 12535 | + return result; |
| 12536 | +} |
| 12537 | diff --git a/support/xmunmap.c b/support/xmunmap.c |
| 12538 | new file mode 100644 |
| 12539 | index 0000000000..6ef5a4a468 |
| 12540 | --- /dev/null |
| 12541 | +++ b/support/xmunmap.c |
| 12542 | @@ -0,0 +1,28 @@ |
| 12543 | +/* munmap with error checking. |
| 12544 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 12545 | + This file is part of the GNU C Library. |
| 12546 | + |
| 12547 | + The GNU C Library is free software; you can redistribute it and/or |
| 12548 | + modify it under the terms of the GNU Lesser General Public |
| 12549 | + License as published by the Free Software Foundation; either |
| 12550 | + version 2.1 of the License, or (at your option) any later version. |
| 12551 | + |
| 12552 | + The GNU C Library is distributed in the hope that it will be useful, |
| 12553 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12554 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12555 | + Lesser General Public License for more details. |
| 12556 | + |
| 12557 | + You should have received a copy of the GNU Lesser General Public |
| 12558 | + License along with the GNU C Library; if not, see |
| 12559 | + <http://www.gnu.org/licenses/>. */ |
| 12560 | + |
| 12561 | +#include <support/check.h> |
| 12562 | +#include <support/xunistd.h> |
| 12563 | +#include <sys/mman.h> |
| 12564 | + |
| 12565 | +void |
| 12566 | +xmunmap (void *addr, size_t length) |
| 12567 | +{ |
| 12568 | + if (munmap (addr, length) != 0) |
| 12569 | + FAIL_EXIT1 ("munmap of %zu bytes: %m", length); |
| 12570 | +} |
| 12571 | diff --git a/support/xopen.c b/support/xopen.c |
| 12572 | new file mode 100644 |
| 12573 | index 0000000000..7f033a03a7 |
| 12574 | --- /dev/null |
| 12575 | +++ b/support/xopen.c |
| 12576 | @@ -0,0 +1,30 @@ |
| 12577 | +/* open64 with error checking. |
| 12578 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 12579 | + This file is part of the GNU C Library. |
| 12580 | + |
| 12581 | + The GNU C Library is free software; you can redistribute it and/or |
| 12582 | + modify it under the terms of the GNU Lesser General Public |
| 12583 | + License as published by the Free Software Foundation; either |
| 12584 | + version 2.1 of the License, or (at your option) any later version. |
| 12585 | + |
| 12586 | + The GNU C Library is distributed in the hope that it will be useful, |
| 12587 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12588 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12589 | + Lesser General Public License for more details. |
| 12590 | + |
| 12591 | + You should have received a copy of the GNU Lesser General Public |
| 12592 | + License along with the GNU C Library; if not, see |
| 12593 | + <http://www.gnu.org/licenses/>. */ |
| 12594 | + |
| 12595 | +#include <support/check.h> |
| 12596 | +#include <support/xunistd.h> |
| 12597 | +#include <fcntl.h> |
| 12598 | + |
| 12599 | +int |
| 12600 | +xopen (const char *path, int flags, mode_t mode) |
| 12601 | +{ |
| 12602 | + int ret = open64 (path, flags, mode); |
| 12603 | + if (ret < 0) |
| 12604 | + FAIL_EXIT1 ("open64 (\"%s\", 0x%x, 0%o): %m", path, flags, mode); |
| 12605 | + return ret; |
| 12606 | +} |
| 12607 | diff --git a/support/xpipe.c b/support/xpipe.c |
| 12608 | new file mode 100644 |
| 12609 | index 0000000000..89a64a55c1 |
| 12610 | --- /dev/null |
| 12611 | +++ b/support/xpipe.c |
| 12612 | @@ -0,0 +1,28 @@ |
| 12613 | +/* pipe with error checking. |
| 12614 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 12615 | + This file is part of the GNU C Library. |
| 12616 | + |
| 12617 | + The GNU C Library is free software; you can redistribute it and/or |
| 12618 | + modify it under the terms of the GNU Lesser General Public |
| 12619 | + License as published by the Free Software Foundation; either |
| 12620 | + version 2.1 of the License, or (at your option) any later version. |
| 12621 | + |
| 12622 | + The GNU C Library is distributed in the hope that it will be useful, |
| 12623 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12624 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12625 | + Lesser General Public License for more details. |
| 12626 | + |
| 12627 | + You should have received a copy of the GNU Lesser General Public |
| 12628 | + License along with the GNU C Library; if not, see |
| 12629 | + <http://www.gnu.org/licenses/>. */ |
| 12630 | + |
| 12631 | +#include <support/xunistd.h> |
| 12632 | + |
| 12633 | +#include <support/check.h> |
| 12634 | + |
| 12635 | +void |
| 12636 | +xpipe (int fds[2]) |
| 12637 | +{ |
| 12638 | + if (pipe (fds) < 0) |
| 12639 | + FAIL_EXIT1 ("pipe: %m"); |
| 12640 | +} |
| 12641 | diff --git a/support/xpoll.c b/support/xpoll.c |
| 12642 | new file mode 100644 |
| 12643 | index 0000000000..bec2521ffc |
| 12644 | --- /dev/null |
| 12645 | +++ b/support/xpoll.c |
| 12646 | @@ -0,0 +1,32 @@ |
| 12647 | +/* poll with error checking. |
| 12648 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 12649 | + This file is part of the GNU C Library. |
| 12650 | + |
| 12651 | + The GNU C Library is free software; you can redistribute it and/or |
| 12652 | + modify it under the terms of the GNU Lesser General Public |
| 12653 | + License as published by the Free Software Foundation; either |
| 12654 | + version 2.1 of the License, or (at your option) any later version. |
| 12655 | + |
| 12656 | + The GNU C Library is distributed in the hope that it will be useful, |
| 12657 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12658 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12659 | + Lesser General Public License for more details. |
| 12660 | + |
| 12661 | + You should have received a copy of the GNU Lesser General Public |
| 12662 | + License along with the GNU C Library; if not, see |
| 12663 | + <http://www.gnu.org/licenses/>. */ |
| 12664 | + |
| 12665 | +#include <support/xsocket.h> |
| 12666 | + |
| 12667 | +#include <stdio.h> |
| 12668 | +#include <stdlib.h> |
| 12669 | +#include <support/check.h> |
| 12670 | + |
| 12671 | +int |
| 12672 | +xpoll (struct pollfd *fds, nfds_t nfds, int timeout) |
| 12673 | +{ |
| 12674 | + int ret = poll (fds, nfds, timeout); |
| 12675 | + if (ret < 0) |
| 12676 | + FAIL_EXIT1 ("poll: %m"); |
| 12677 | + return ret; |
| 12678 | +} |
| 12679 | diff --git a/support/xpthread_attr_destroy.c b/support/xpthread_attr_destroy.c |
| 12680 | new file mode 100644 |
| 12681 | index 0000000000..664c809e9f |
| 12682 | --- /dev/null |
| 12683 | +++ b/support/xpthread_attr_destroy.c |
| 12684 | @@ -0,0 +1,26 @@ |
| 12685 | +/* pthread_attr_destroy with error checking. |
| 12686 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 12687 | + This file is part of the GNU C Library. |
| 12688 | + |
| 12689 | + The GNU C Library is free software; you can redistribute it and/or |
| 12690 | + modify it under the terms of the GNU Lesser General Public |
| 12691 | + License as published by the Free Software Foundation; either |
| 12692 | + version 2.1 of the License, or (at your option) any later version. |
| 12693 | + |
| 12694 | + The GNU C Library is distributed in the hope that it will be useful, |
| 12695 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12696 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12697 | + Lesser General Public License for more details. |
| 12698 | + |
| 12699 | + You should have received a copy of the GNU Lesser General Public |
| 12700 | + License along with the GNU C Library; if not, see |
| 12701 | + <http://www.gnu.org/licenses/>. */ |
| 12702 | + |
| 12703 | +#include <support/xthread.h> |
| 12704 | + |
| 12705 | +void |
| 12706 | +xpthread_attr_destroy (pthread_attr_t *attr) |
| 12707 | +{ |
| 12708 | + xpthread_check_return ("pthread_attr_destroy", |
| 12709 | + pthread_attr_destroy (attr)); |
| 12710 | +} |
| 12711 | diff --git a/support/xpthread_attr_init.c b/support/xpthread_attr_init.c |
| 12712 | new file mode 100644 |
| 12713 | index 0000000000..2e30ade9ab |
| 12714 | --- /dev/null |
| 12715 | +++ b/support/xpthread_attr_init.c |
| 12716 | @@ -0,0 +1,25 @@ |
| 12717 | +/* pthread_attr_init with error checking. |
| 12718 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 12719 | + This file is part of the GNU C Library. |
| 12720 | + |
| 12721 | + The GNU C Library is free software; you can redistribute it and/or |
| 12722 | + modify it under the terms of the GNU Lesser General Public |
| 12723 | + License as published by the Free Software Foundation; either |
| 12724 | + version 2.1 of the License, or (at your option) any later version. |
| 12725 | + |
| 12726 | + The GNU C Library is distributed in the hope that it will be useful, |
| 12727 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12728 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12729 | + Lesser General Public License for more details. |
| 12730 | + |
| 12731 | + You should have received a copy of the GNU Lesser General Public |
| 12732 | + License along with the GNU C Library; if not, see |
| 12733 | + <http://www.gnu.org/licenses/>. */ |
| 12734 | + |
| 12735 | +#include <support/xthread.h> |
| 12736 | + |
| 12737 | +void |
| 12738 | +xpthread_attr_init (pthread_attr_t *attr) |
| 12739 | +{ |
| 12740 | + xpthread_check_return ("pthread_attr_init", pthread_attr_init (attr)); |
| 12741 | +} |
| 12742 | diff --git a/support/xpthread_attr_setdetachstate.c b/support/xpthread_attr_setdetachstate.c |
| 12743 | new file mode 100644 |
| 12744 | index 0000000000..b544dbaa42 |
| 12745 | --- /dev/null |
| 12746 | +++ b/support/xpthread_attr_setdetachstate.c |
| 12747 | @@ -0,0 +1,27 @@ |
| 12748 | +/* pthread_attr_setdetachstate with error checking. |
| 12749 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 12750 | + This file is part of the GNU C Library. |
| 12751 | + |
| 12752 | + The GNU C Library is free software; you can redistribute it and/or |
| 12753 | + modify it under the terms of the GNU Lesser General Public |
| 12754 | + License as published by the Free Software Foundation; either |
| 12755 | + version 2.1 of the License, or (at your option) any later version. |
| 12756 | + |
| 12757 | + The GNU C Library is distributed in the hope that it will be useful, |
| 12758 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12759 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12760 | + Lesser General Public License for more details. |
| 12761 | + |
| 12762 | + You should have received a copy of the GNU Lesser General Public |
| 12763 | + License along with the GNU C Library; if not, see |
| 12764 | + <http://www.gnu.org/licenses/>. */ |
| 12765 | + |
| 12766 | +#include <support/xthread.h> |
| 12767 | + |
| 12768 | +void |
| 12769 | +xpthread_attr_setdetachstate (pthread_attr_t *attr, int detachstate) |
| 12770 | +{ |
| 12771 | + xpthread_check_return ("pthread_attr_setdetachstate", |
| 12772 | + pthread_attr_setdetachstate (attr, |
| 12773 | + detachstate)); |
| 12774 | +} |
| 12775 | diff --git a/support/xpthread_attr_setstacksize.c b/support/xpthread_attr_setstacksize.c |
| 12776 | new file mode 100644 |
| 12777 | index 0000000000..02d06310a9 |
| 12778 | --- /dev/null |
| 12779 | +++ b/support/xpthread_attr_setstacksize.c |
| 12780 | @@ -0,0 +1,26 @@ |
| 12781 | +/* pthread_attr_setstacksize with error checking. |
| 12782 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 12783 | + This file is part of the GNU C Library. |
| 12784 | + |
| 12785 | + The GNU C Library is free software; you can redistribute it and/or |
| 12786 | + modify it under the terms of the GNU Lesser General Public |
| 12787 | + License as published by the Free Software Foundation; either |
| 12788 | + version 2.1 of the License, or (at your option) any later version. |
| 12789 | + |
| 12790 | + The GNU C Library is distributed in the hope that it will be useful, |
| 12791 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12792 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12793 | + Lesser General Public License for more details. |
| 12794 | + |
| 12795 | + You should have received a copy of the GNU Lesser General Public |
| 12796 | + License along with the GNU C Library; if not, see |
| 12797 | + <http://www.gnu.org/licenses/>. */ |
| 12798 | + |
| 12799 | +#include <support/xthread.h> |
| 12800 | + |
| 12801 | +void |
| 12802 | +xpthread_attr_setstacksize (pthread_attr_t *attr, size_t stacksize) |
| 12803 | +{ |
| 12804 | + xpthread_check_return ("pthread_attr_setstacksize", |
| 12805 | + pthread_attr_setstacksize (attr, stacksize)); |
| 12806 | +} |
| 12807 | diff --git a/support/xpthread_barrier_destroy.c b/support/xpthread_barrier_destroy.c |
| 12808 | new file mode 100644 |
| 12809 | index 0000000000..efc0719a63 |
| 12810 | --- /dev/null |
| 12811 | +++ b/support/xpthread_barrier_destroy.c |
| 12812 | @@ -0,0 +1,26 @@ |
| 12813 | +/* pthread_barrier_destroy with error checking. |
| 12814 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 12815 | + This file is part of the GNU C Library. |
| 12816 | + |
| 12817 | + The GNU C Library is free software; you can redistribute it and/or |
| 12818 | + modify it under the terms of the GNU Lesser General Public |
| 12819 | + License as published by the Free Software Foundation; either |
| 12820 | + version 2.1 of the License, or (at your option) any later version. |
| 12821 | + |
| 12822 | + The GNU C Library is distributed in the hope that it will be useful, |
| 12823 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12824 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12825 | + Lesser General Public License for more details. |
| 12826 | + |
| 12827 | + You should have received a copy of the GNU Lesser General Public |
| 12828 | + License along with the GNU C Library; if not, see |
| 12829 | + <http://www.gnu.org/licenses/>. */ |
| 12830 | + |
| 12831 | +#include <support/xthread.h> |
| 12832 | + |
| 12833 | +void |
| 12834 | +xpthread_barrier_destroy (pthread_barrier_t *barrier) |
| 12835 | +{ |
| 12836 | + xpthread_check_return ("pthread_barrier_destroy", |
| 12837 | + pthread_barrier_destroy (barrier)); |
| 12838 | +} |
| 12839 | diff --git a/sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_fdim-vis3.S b/support/xpthread_barrier_init.c |
| 12840 | similarity index 65% |
| 12841 | rename from sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_fdim-vis3.S |
| 12842 | rename to support/xpthread_barrier_init.c |
| 12843 | index 4a479b1a59..b32dad1315 100644 |
| 12844 | --- a/sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_fdim-vis3.S |
| 12845 | +++ b/support/xpthread_barrier_init.c |
| 12846 | @@ -1,7 +1,6 @@ |
| 12847 | -/* Compute positive difference, sparc 32-bit+v9+vis3. |
| 12848 | - Copyright (C) 2013-2016 Free Software Foundation, Inc. |
| 12849 | +/* pthread_barrier_init with error checking. |
| 12850 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 12851 | This file is part of the GNU C Library. |
| 12852 | - Contributed by David S. Miller <davem@davemloft.net>. |
| 12853 | |
| 12854 | The GNU C Library is free software; you can redistribute it and/or |
| 12855 | modify it under the terms of the GNU Lesser General Public |
| 12856 | @@ -17,18 +16,12 @@ |
| 12857 | License along with the GNU C Library; if not, see |
| 12858 | <http://www.gnu.org/licenses/>. */ |
| 12859 | |
| 12860 | -#include <sysdep.h> |
| 12861 | +#include <support/xthread.h> |
| 12862 | |
| 12863 | -ENTRY(__fdim_vis3) |
| 12864 | - movwtos %o0, %f0 |
| 12865 | - movwtos %o1, %f1 |
| 12866 | - movwtos %o2, %f2 |
| 12867 | - movwtos %o3, %f3 |
| 12868 | - fcmpd %f0, %f2 |
| 12869 | - fbug 1f |
| 12870 | - nop |
| 12871 | - fzero %f0 |
| 12872 | - fnegd %f0, %f2 |
| 12873 | -1: retl |
| 12874 | - fsubd %f0, %f2, %f0 |
| 12875 | -END(__fdim_vis3) |
| 12876 | +void |
| 12877 | +xpthread_barrier_init (pthread_barrier_t *barrier, |
| 12878 | + pthread_barrierattr_t *attr, unsigned int count) |
| 12879 | +{ |
| 12880 | + xpthread_check_return ("pthread_barrier_init", |
| 12881 | + pthread_barrier_init (barrier, attr, count)); |
| 12882 | +} |
| 12883 | diff --git a/support/xpthread_barrier_wait.c b/support/xpthread_barrier_wait.c |
| 12884 | new file mode 100644 |
| 12885 | index 0000000000..7cee44d0a3 |
| 12886 | --- /dev/null |
| 12887 | +++ b/support/xpthread_barrier_wait.c |
| 12888 | @@ -0,0 +1,28 @@ |
| 12889 | +/* pthread_barrier_wait with error checking. |
| 12890 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 12891 | + This file is part of the GNU C Library. |
| 12892 | + |
| 12893 | + The GNU C Library is free software; you can redistribute it and/or |
| 12894 | + modify it under the terms of the GNU Lesser General Public |
| 12895 | + License as published by the Free Software Foundation; either |
| 12896 | + version 2.1 of the License, or (at your option) any later version. |
| 12897 | + |
| 12898 | + The GNU C Library is distributed in the hope that it will be useful, |
| 12899 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12900 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12901 | + Lesser General Public License for more details. |
| 12902 | + |
| 12903 | + You should have received a copy of the GNU Lesser General Public |
| 12904 | + License along with the GNU C Library; if not, see |
| 12905 | + <http://www.gnu.org/licenses/>. */ |
| 12906 | + |
| 12907 | +#include <support/xthread.h> |
| 12908 | + |
| 12909 | +int |
| 12910 | +xpthread_barrier_wait (pthread_barrier_t *barrier) |
| 12911 | +{ |
| 12912 | + int ret = pthread_barrier_wait (barrier); |
| 12913 | + if (ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD) |
| 12914 | + xpthread_check_return ("pthread_barrier_wait", ret); |
| 12915 | + return ret == PTHREAD_BARRIER_SERIAL_THREAD; |
| 12916 | +} |
| 12917 | diff --git a/support/xpthread_cancel.c b/support/xpthread_cancel.c |
| 12918 | new file mode 100644 |
| 12919 | index 0000000000..3af16f9b54 |
| 12920 | --- /dev/null |
| 12921 | +++ b/support/xpthread_cancel.c |
| 12922 | @@ -0,0 +1,25 @@ |
| 12923 | +/* pthread_cancel with error checking. |
| 12924 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 12925 | + This file is part of the GNU C Library. |
| 12926 | + |
| 12927 | + The GNU C Library is free software; you can redistribute it and/or |
| 12928 | + modify it under the terms of the GNU Lesser General Public |
| 12929 | + License as published by the Free Software Foundation; either |
| 12930 | + version 2.1 of the License, or (at your option) any later version. |
| 12931 | + |
| 12932 | + The GNU C Library is distributed in the hope that it will be useful, |
| 12933 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12934 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12935 | + Lesser General Public License for more details. |
| 12936 | + |
| 12937 | + You should have received a copy of the GNU Lesser General Public |
| 12938 | + License along with the GNU C Library; if not, see |
| 12939 | + <http://www.gnu.org/licenses/>. */ |
| 12940 | + |
| 12941 | +#include <support/xthread.h> |
| 12942 | + |
| 12943 | +void |
| 12944 | +xpthread_cancel (pthread_t thr) |
| 12945 | +{ |
| 12946 | + xpthread_check_return ("pthread_cancel", pthread_cancel (thr)); |
| 12947 | +} |
| 12948 | diff --git a/support/xpthread_check_return.c b/support/xpthread_check_return.c |
| 12949 | new file mode 100644 |
| 12950 | index 0000000000..3094d82e9c |
| 12951 | --- /dev/null |
| 12952 | +++ b/support/xpthread_check_return.c |
| 12953 | @@ -0,0 +1,34 @@ |
| 12954 | +/* Return value checking for pthread functions, exit variant. |
| 12955 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 12956 | + This file is part of the GNU C Library. |
| 12957 | + |
| 12958 | + The GNU C Library is free software; you can redistribute it and/or |
| 12959 | + modify it under the terms of the GNU Lesser General Public |
| 12960 | + License as published by the Free Software Foundation; either |
| 12961 | + version 2.1 of the License, or (at your option) any later version. |
| 12962 | + |
| 12963 | + The GNU C Library is distributed in the hope that it will be useful, |
| 12964 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12965 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12966 | + Lesser General Public License for more details. |
| 12967 | + |
| 12968 | + You should have received a copy of the GNU Lesser General Public |
| 12969 | + License along with the GNU C Library; if not, see |
| 12970 | + <http://www.gnu.org/licenses/>. */ |
| 12971 | + |
| 12972 | +#include <support/xthread.h> |
| 12973 | + |
| 12974 | +#include <errno.h> |
| 12975 | +#include <stdio.h> |
| 12976 | +#include <stdlib.h> |
| 12977 | +#include <support/check.h> |
| 12978 | + |
| 12979 | +void |
| 12980 | +xpthread_check_return (const char *function, int value) |
| 12981 | +{ |
| 12982 | + if (value != 0) |
| 12983 | + { |
| 12984 | + errno = value; |
| 12985 | + FAIL_EXIT1 ("%s: %m", function); |
| 12986 | + } |
| 12987 | +} |
| 12988 | diff --git a/support/xpthread_cond_wait.c b/support/xpthread_cond_wait.c |
| 12989 | new file mode 100644 |
| 12990 | index 0000000000..b0e9b2a232 |
| 12991 | --- /dev/null |
| 12992 | +++ b/support/xpthread_cond_wait.c |
| 12993 | @@ -0,0 +1,26 @@ |
| 12994 | +/* pthread_cond_wait with error checking. |
| 12995 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 12996 | + This file is part of the GNU C Library. |
| 12997 | + |
| 12998 | + The GNU C Library is free software; you can redistribute it and/or |
| 12999 | + modify it under the terms of the GNU Lesser General Public |
| 13000 | + License as published by the Free Software Foundation; either |
| 13001 | + version 2.1 of the License, or (at your option) any later version. |
| 13002 | + |
| 13003 | + The GNU C Library is distributed in the hope that it will be useful, |
| 13004 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13005 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13006 | + Lesser General Public License for more details. |
| 13007 | + |
| 13008 | + You should have received a copy of the GNU Lesser General Public |
| 13009 | + License along with the GNU C Library; if not, see |
| 13010 | + <http://www.gnu.org/licenses/>. */ |
| 13011 | + |
| 13012 | +#include <support/xthread.h> |
| 13013 | + |
| 13014 | +void |
| 13015 | +xpthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex) |
| 13016 | +{ |
| 13017 | + xpthread_check_return |
| 13018 | + ("pthread_cond_wait", pthread_cond_wait (cond, mutex)); |
| 13019 | +} |
| 13020 | diff --git a/support/xpthread_create.c b/support/xpthread_create.c |
| 13021 | new file mode 100644 |
| 13022 | index 0000000000..98c63e54c3 |
| 13023 | --- /dev/null |
| 13024 | +++ b/support/xpthread_create.c |
| 13025 | @@ -0,0 +1,29 @@ |
| 13026 | +/* pthread_create with error checking. |
| 13027 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 13028 | + This file is part of the GNU C Library. |
| 13029 | + |
| 13030 | + The GNU C Library is free software; you can redistribute it and/or |
| 13031 | + modify it under the terms of the GNU Lesser General Public |
| 13032 | + License as published by the Free Software Foundation; either |
| 13033 | + version 2.1 of the License, or (at your option) any later version. |
| 13034 | + |
| 13035 | + The GNU C Library is distributed in the hope that it will be useful, |
| 13036 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13037 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13038 | + Lesser General Public License for more details. |
| 13039 | + |
| 13040 | + You should have received a copy of the GNU Lesser General Public |
| 13041 | + License along with the GNU C Library; if not, see |
| 13042 | + <http://www.gnu.org/licenses/>. */ |
| 13043 | + |
| 13044 | +#include <support/xthread.h> |
| 13045 | + |
| 13046 | +pthread_t |
| 13047 | +xpthread_create (pthread_attr_t *attr, |
| 13048 | + void *(*thread_func) (void *), void *closure) |
| 13049 | +{ |
| 13050 | + pthread_t thr; |
| 13051 | + xpthread_check_return |
| 13052 | + ("pthread_create", pthread_create (&thr, attr, thread_func, closure)); |
| 13053 | + return thr; |
| 13054 | +} |
| 13055 | diff --git a/support/xpthread_detach.c b/support/xpthread_detach.c |
| 13056 | new file mode 100644 |
| 13057 | index 0000000000..2088af2f57 |
| 13058 | --- /dev/null |
| 13059 | +++ b/support/xpthread_detach.c |
| 13060 | @@ -0,0 +1,25 @@ |
| 13061 | +/* pthread_detach with error checking. |
| 13062 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 13063 | + This file is part of the GNU C Library. |
| 13064 | + |
| 13065 | + The GNU C Library is free software; you can redistribute it and/or |
| 13066 | + modify it under the terms of the GNU Lesser General Public |
| 13067 | + License as published by the Free Software Foundation; either |
| 13068 | + version 2.1 of the License, or (at your option) any later version. |
| 13069 | + |
| 13070 | + The GNU C Library is distributed in the hope that it will be useful, |
| 13071 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13072 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13073 | + Lesser General Public License for more details. |
| 13074 | + |
| 13075 | + You should have received a copy of the GNU Lesser General Public |
| 13076 | + License along with the GNU C Library; if not, see |
| 13077 | + <http://www.gnu.org/licenses/>. */ |
| 13078 | + |
| 13079 | +#include <support/xthread.h> |
| 13080 | + |
| 13081 | +void |
| 13082 | +xpthread_detach (pthread_t thr) |
| 13083 | +{ |
| 13084 | + xpthread_check_return ("pthread_detach", pthread_detach (thr)); |
| 13085 | +} |
| 13086 | diff --git a/support/xpthread_join.c b/support/xpthread_join.c |
| 13087 | new file mode 100644 |
| 13088 | index 0000000000..f23bb9a5ae |
| 13089 | --- /dev/null |
| 13090 | +++ b/support/xpthread_join.c |
| 13091 | @@ -0,0 +1,27 @@ |
| 13092 | +/* pthread_join with error checking. |
| 13093 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 13094 | + This file is part of the GNU C Library. |
| 13095 | + |
| 13096 | + The GNU C Library is free software; you can redistribute it and/or |
| 13097 | + modify it under the terms of the GNU Lesser General Public |
| 13098 | + License as published by the Free Software Foundation; either |
| 13099 | + version 2.1 of the License, or (at your option) any later version. |
| 13100 | + |
| 13101 | + The GNU C Library is distributed in the hope that it will be useful, |
| 13102 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13103 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13104 | + Lesser General Public License for more details. |
| 13105 | + |
| 13106 | + You should have received a copy of the GNU Lesser General Public |
| 13107 | + License along with the GNU C Library; if not, see |
| 13108 | + <http://www.gnu.org/licenses/>. */ |
| 13109 | + |
| 13110 | +#include <support/xthread.h> |
| 13111 | + |
| 13112 | +void * |
| 13113 | +xpthread_join (pthread_t thr) |
| 13114 | +{ |
| 13115 | + void *result; |
| 13116 | + xpthread_check_return ("pthread_join", pthread_join (thr, &result)); |
| 13117 | + return result; |
| 13118 | +} |
| 13119 | diff --git a/support/xpthread_mutex_consistent.c b/support/xpthread_mutex_consistent.c |
| 13120 | new file mode 100644 |
| 13121 | index 0000000000..52364be365 |
| 13122 | --- /dev/null |
| 13123 | +++ b/support/xpthread_mutex_consistent.c |
| 13124 | @@ -0,0 +1,26 @@ |
| 13125 | +/* pthread_mutex_consistent with error checking. |
| 13126 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 13127 | + This file is part of the GNU C Library. |
| 13128 | + |
| 13129 | + The GNU C Library is free software; you can redistribute it and/or |
| 13130 | + modify it under the terms of the GNU Lesser General Public |
| 13131 | + License as published by the Free Software Foundation; either |
| 13132 | + version 2.1 of the License, or (at your option) any later version. |
| 13133 | + |
| 13134 | + The GNU C Library is distributed in the hope that it will be useful, |
| 13135 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13136 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13137 | + Lesser General Public License for more details. |
| 13138 | + |
| 13139 | + You should have received a copy of the GNU Lesser General Public |
| 13140 | + License along with the GNU C Library; if not, see |
| 13141 | + <http://www.gnu.org/licenses/>. */ |
| 13142 | + |
| 13143 | +#include <support/xthread.h> |
| 13144 | + |
| 13145 | +void |
| 13146 | +xpthread_mutex_consistent (pthread_mutex_t *mutex) |
| 13147 | +{ |
| 13148 | + xpthread_check_return ("pthread_mutex_consistent", |
| 13149 | + pthread_mutex_consistent (mutex)); |
| 13150 | +} |
| 13151 | diff --git a/support/xpthread_mutex_destroy.c b/support/xpthread_mutex_destroy.c |
| 13152 | new file mode 100644 |
| 13153 | index 0000000000..f11f8f0acd |
| 13154 | --- /dev/null |
| 13155 | +++ b/support/xpthread_mutex_destroy.c |
| 13156 | @@ -0,0 +1,26 @@ |
| 13157 | +/* pthread_mutex_destroy with error checking. |
| 13158 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 13159 | + This file is part of the GNU C Library. |
| 13160 | + |
| 13161 | + The GNU C Library is free software; you can redistribute it and/or |
| 13162 | + modify it under the terms of the GNU Lesser General Public |
| 13163 | + License as published by the Free Software Foundation; either |
| 13164 | + version 2.1 of the License, or (at your option) any later version. |
| 13165 | + |
| 13166 | + The GNU C Library is distributed in the hope that it will be useful, |
| 13167 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13168 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13169 | + Lesser General Public License for more details. |
| 13170 | + |
| 13171 | + You should have received a copy of the GNU Lesser General Public |
| 13172 | + License along with the GNU C Library; if not, see |
| 13173 | + <http://www.gnu.org/licenses/>. */ |
| 13174 | + |
| 13175 | +#include <support/xthread.h> |
| 13176 | + |
| 13177 | +void |
| 13178 | +xpthread_mutex_destroy (pthread_mutex_t *mutex) |
| 13179 | +{ |
| 13180 | + xpthread_check_return ("pthread_mutex_destroy", |
| 13181 | + pthread_mutex_destroy (mutex)); |
| 13182 | +} |
| 13183 | diff --git a/support/xpthread_mutex_init.c b/support/xpthread_mutex_init.c |
| 13184 | new file mode 100644 |
| 13185 | index 0000000000..2d16d1b9d9 |
| 13186 | --- /dev/null |
| 13187 | +++ b/support/xpthread_mutex_init.c |
| 13188 | @@ -0,0 +1,26 @@ |
| 13189 | +/* pthread_mutex_init with error checking. |
| 13190 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 13191 | + This file is part of the GNU C Library. |
| 13192 | + |
| 13193 | + The GNU C Library is free software; you can redistribute it and/or |
| 13194 | + modify it under the terms of the GNU Lesser General Public |
| 13195 | + License as published by the Free Software Foundation; either |
| 13196 | + version 2.1 of the License, or (at your option) any later version. |
| 13197 | + |
| 13198 | + The GNU C Library is distributed in the hope that it will be useful, |
| 13199 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13200 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13201 | + Lesser General Public License for more details. |
| 13202 | + |
| 13203 | + You should have received a copy of the GNU Lesser General Public |
| 13204 | + License along with the GNU C Library; if not, see |
| 13205 | + <http://www.gnu.org/licenses/>. */ |
| 13206 | + |
| 13207 | +#include <support/xthread.h> |
| 13208 | + |
| 13209 | +void |
| 13210 | +xpthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) |
| 13211 | +{ |
| 13212 | + xpthread_check_return ("pthread_mutex_init", |
| 13213 | + pthread_mutex_init (mutex, attr)); |
| 13214 | +} |
| 13215 | diff --git a/support/xpthread_mutex_lock.c b/support/xpthread_mutex_lock.c |
| 13216 | new file mode 100644 |
| 13217 | index 0000000000..af727b45f3 |
| 13218 | --- /dev/null |
| 13219 | +++ b/support/xpthread_mutex_lock.c |
| 13220 | @@ -0,0 +1,25 @@ |
| 13221 | +/* pthread_mutex_lock with error checking. |
| 13222 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 13223 | + This file is part of the GNU C Library. |
| 13224 | + |
| 13225 | + The GNU C Library is free software; you can redistribute it and/or |
| 13226 | + modify it under the terms of the GNU Lesser General Public |
| 13227 | + License as published by the Free Software Foundation; either |
| 13228 | + version 2.1 of the License, or (at your option) any later version. |
| 13229 | + |
| 13230 | + The GNU C Library is distributed in the hope that it will be useful, |
| 13231 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13232 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13233 | + Lesser General Public License for more details. |
| 13234 | + |
| 13235 | + You should have received a copy of the GNU Lesser General Public |
| 13236 | + License along with the GNU C Library; if not, see |
| 13237 | + <http://www.gnu.org/licenses/>. */ |
| 13238 | + |
| 13239 | +#include <support/xthread.h> |
| 13240 | + |
| 13241 | +void |
| 13242 | +xpthread_mutex_lock (pthread_mutex_t *mutex) |
| 13243 | +{ |
| 13244 | + xpthread_check_return ("pthread_mutex_lock", pthread_mutex_lock (mutex)); |
| 13245 | +} |
| 13246 | diff --git a/support/xpthread_mutex_unlock.c b/support/xpthread_mutex_unlock.c |
| 13247 | new file mode 100644 |
| 13248 | index 0000000000..161b41edf6 |
| 13249 | --- /dev/null |
| 13250 | +++ b/support/xpthread_mutex_unlock.c |
| 13251 | @@ -0,0 +1,25 @@ |
| 13252 | +/* pthread_mutex_unlock with error checking. |
| 13253 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 13254 | + This file is part of the GNU C Library. |
| 13255 | + |
| 13256 | + The GNU C Library is free software; you can redistribute it and/or |
| 13257 | + modify it under the terms of the GNU Lesser General Public |
| 13258 | + License as published by the Free Software Foundation; either |
| 13259 | + version 2.1 of the License, or (at your option) any later version. |
| 13260 | + |
| 13261 | + The GNU C Library is distributed in the hope that it will be useful, |
| 13262 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13263 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13264 | + Lesser General Public License for more details. |
| 13265 | + |
| 13266 | + You should have received a copy of the GNU Lesser General Public |
| 13267 | + License along with the GNU C Library; if not, see |
| 13268 | + <http://www.gnu.org/licenses/>. */ |
| 13269 | + |
| 13270 | +#include <support/xthread.h> |
| 13271 | + |
| 13272 | +void |
| 13273 | +xpthread_mutex_unlock (pthread_mutex_t *mutex) |
| 13274 | +{ |
| 13275 | + xpthread_check_return ("pthread_mutex_unlock", pthread_mutex_unlock (mutex)); |
| 13276 | +} |
| 13277 | diff --git a/support/xpthread_mutexattr_destroy.c b/support/xpthread_mutexattr_destroy.c |
| 13278 | new file mode 100644 |
| 13279 | index 0000000000..c699e32b41 |
| 13280 | --- /dev/null |
| 13281 | +++ b/support/xpthread_mutexattr_destroy.c |
| 13282 | @@ -0,0 +1,26 @@ |
| 13283 | +/* pthread_mutexattr_destroy with error checking. |
| 13284 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 13285 | + This file is part of the GNU C Library. |
| 13286 | + |
| 13287 | + The GNU C Library is free software; you can redistribute it and/or |
| 13288 | + modify it under the terms of the GNU Lesser General Public |
| 13289 | + License as published by the Free Software Foundation; either |
| 13290 | + version 2.1 of the License, or (at your option) any later version. |
| 13291 | + |
| 13292 | + The GNU C Library is distributed in the hope that it will be useful, |
| 13293 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13294 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13295 | + Lesser General Public License for more details. |
| 13296 | + |
| 13297 | + You should have received a copy of the GNU Lesser General Public |
| 13298 | + License along with the GNU C Library; if not, see |
| 13299 | + <http://www.gnu.org/licenses/>. */ |
| 13300 | + |
| 13301 | +#include <support/xthread.h> |
| 13302 | + |
| 13303 | +void |
| 13304 | +xpthread_mutexattr_destroy (pthread_mutexattr_t *attr) |
| 13305 | +{ |
| 13306 | + xpthread_check_return ("pthread_mutexattr_destroy", |
| 13307 | + pthread_mutexattr_destroy (attr)); |
| 13308 | +} |
| 13309 | diff --git a/support/xpthread_mutexattr_init.c b/support/xpthread_mutexattr_init.c |
| 13310 | new file mode 100644 |
| 13311 | index 0000000000..fa93fab178 |
| 13312 | --- /dev/null |
| 13313 | +++ b/support/xpthread_mutexattr_init.c |
| 13314 | @@ -0,0 +1,25 @@ |
| 13315 | +/* pthread_mutexattr_init with error checking. |
| 13316 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 13317 | + This file is part of the GNU C Library. |
| 13318 | + |
| 13319 | + The GNU C Library is free software; you can redistribute it and/or |
| 13320 | + modify it under the terms of the GNU Lesser General Public |
| 13321 | + License as published by the Free Software Foundation; either |
| 13322 | + version 2.1 of the License, or (at your option) any later version. |
| 13323 | + |
| 13324 | + The GNU C Library is distributed in the hope that it will be useful, |
| 13325 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13326 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13327 | + Lesser General Public License for more details. |
| 13328 | + |
| 13329 | + You should have received a copy of the GNU Lesser General Public |
| 13330 | + License along with the GNU C Library; if not, see |
| 13331 | + <http://www.gnu.org/licenses/>. */ |
| 13332 | + |
| 13333 | +#include <support/xthread.h> |
| 13334 | + |
| 13335 | +void |
| 13336 | +xpthread_mutexattr_init (pthread_mutexattr_t *attr) |
| 13337 | +{ |
| 13338 | + xpthread_check_return ("pthread_mutexattr_init", pthread_mutexattr_init (attr)); |
| 13339 | +} |
| 13340 | diff --git a/sysdeps/sparc/sparc64/fpu/s_fdim.S b/support/xpthread_mutexattr_setprotocol.c |
| 13341 | similarity index 67% |
| 13342 | rename from sysdeps/sparc/sparc64/fpu/s_fdim.S |
| 13343 | rename to support/xpthread_mutexattr_setprotocol.c |
| 13344 | index 7fae72a251..353f75e3d7 100644 |
| 13345 | --- a/sysdeps/sparc/sparc64/fpu/s_fdim.S |
| 13346 | +++ b/support/xpthread_mutexattr_setprotocol.c |
| 13347 | @@ -1,7 +1,6 @@ |
| 13348 | -/* Compute positive difference, sparc 64-bit. |
| 13349 | - Copyright (C) 2013-2016 Free Software Foundation, Inc. |
| 13350 | +/* pthread_mutexattr_setprotocol with error checking. |
| 13351 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 13352 | This file is part of the GNU C Library. |
| 13353 | - Contributed by David S. Miller <davem@davemloft.net>. |
| 13354 | |
| 13355 | The GNU C Library is free software; you can redistribute it and/or |
| 13356 | modify it under the terms of the GNU Lesser General Public |
| 13357 | @@ -17,16 +16,11 @@ |
| 13358 | License along with the GNU C Library; if not, see |
| 13359 | <http://www.gnu.org/licenses/>. */ |
| 13360 | |
| 13361 | -#include <sysdep.h> |
| 13362 | -#include <math_ldbl_opt.h> |
| 13363 | +#include <support/xthread.h> |
| 13364 | |
| 13365 | -ENTRY(__fdim) |
| 13366 | - fcmpd %f0, %f2 |
| 13367 | - fbug 1f |
| 13368 | - nop |
| 13369 | - fzero %f0 |
| 13370 | - fnegd %f0, %f2 |
| 13371 | -1: retl |
| 13372 | - fsubd %f0, %f2, %f0 |
| 13373 | -END(__fdim) |
| 13374 | -weak_alias (__fdim, fdim) |
| 13375 | +void |
| 13376 | +xpthread_mutexattr_setprotocol (pthread_mutexattr_t *attr, int flag) |
| 13377 | +{ |
| 13378 | + xpthread_check_return ("pthread_mutexattr_setprotocol", |
| 13379 | + pthread_mutexattr_setprotocol (attr, flag)); |
| 13380 | +} |
| 13381 | diff --git a/support/xpthread_mutexattr_setpshared.c b/support/xpthread_mutexattr_setpshared.c |
| 13382 | new file mode 100644 |
| 13383 | index 0000000000..242da1aeca |
| 13384 | --- /dev/null |
| 13385 | +++ b/support/xpthread_mutexattr_setpshared.c |
| 13386 | @@ -0,0 +1,26 @@ |
| 13387 | +/* pthread_mutexattr_setpshared with error checking. |
| 13388 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 13389 | + This file is part of the GNU C Library. |
| 13390 | + |
| 13391 | + The GNU C Library is free software; you can redistribute it and/or |
| 13392 | + modify it under the terms of the GNU Lesser General Public |
| 13393 | + License as published by the Free Software Foundation; either |
| 13394 | + version 2.1 of the License, or (at your option) any later version. |
| 13395 | + |
| 13396 | + The GNU C Library is distributed in the hope that it will be useful, |
| 13397 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13398 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13399 | + Lesser General Public License for more details. |
| 13400 | + |
| 13401 | + You should have received a copy of the GNU Lesser General Public |
| 13402 | + License along with the GNU C Library; if not, see |
| 13403 | + <http://www.gnu.org/licenses/>. */ |
| 13404 | + |
| 13405 | +#include <support/xthread.h> |
| 13406 | + |
| 13407 | +void |
| 13408 | +xpthread_mutexattr_setpshared (pthread_mutexattr_t *attr, int flag) |
| 13409 | +{ |
| 13410 | + xpthread_check_return ("pthread_mutexattr_setpshared", |
| 13411 | + pthread_mutexattr_setpshared (attr, flag)); |
| 13412 | +} |
| 13413 | diff --git a/support/xpthread_mutexattr_setrobust.c b/support/xpthread_mutexattr_setrobust.c |
| 13414 | new file mode 100644 |
| 13415 | index 0000000000..d7d6fa8630 |
| 13416 | --- /dev/null |
| 13417 | +++ b/support/xpthread_mutexattr_setrobust.c |
| 13418 | @@ -0,0 +1,26 @@ |
| 13419 | +/* pthread_mutexattr_setrobust with error checking. |
| 13420 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 13421 | + This file is part of the GNU C Library. |
| 13422 | + |
| 13423 | + The GNU C Library is free software; you can redistribute it and/or |
| 13424 | + modify it under the terms of the GNU Lesser General Public |
| 13425 | + License as published by the Free Software Foundation; either |
| 13426 | + version 2.1 of the License, or (at your option) any later version. |
| 13427 | + |
| 13428 | + The GNU C Library is distributed in the hope that it will be useful, |
| 13429 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13430 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13431 | + Lesser General Public License for more details. |
| 13432 | + |
| 13433 | + You should have received a copy of the GNU Lesser General Public |
| 13434 | + License along with the GNU C Library; if not, see |
| 13435 | + <http://www.gnu.org/licenses/>. */ |
| 13436 | + |
| 13437 | +#include <support/xthread.h> |
| 13438 | + |
| 13439 | +void |
| 13440 | +xpthread_mutexattr_setrobust (pthread_mutexattr_t *attr, int flag) |
| 13441 | +{ |
| 13442 | + xpthread_check_return ("pthread_mutexattr_setrobust", |
| 13443 | + pthread_mutexattr_setrobust (attr, flag)); |
| 13444 | +} |
| 13445 | diff --git a/support/xpthread_mutexattr_settype.c b/support/xpthread_mutexattr_settype.c |
| 13446 | new file mode 100644 |
| 13447 | index 0000000000..cf22170b56 |
| 13448 | --- /dev/null |
| 13449 | +++ b/support/xpthread_mutexattr_settype.c |
| 13450 | @@ -0,0 +1,26 @@ |
| 13451 | +/* pthread_mutexattr_settype with error checking. |
| 13452 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 13453 | + This file is part of the GNU C Library. |
| 13454 | + |
| 13455 | + The GNU C Library is free software; you can redistribute it and/or |
| 13456 | + modify it under the terms of the GNU Lesser General Public |
| 13457 | + License as published by the Free Software Foundation; either |
| 13458 | + version 2.1 of the License, or (at your option) any later version. |
| 13459 | + |
| 13460 | + The GNU C Library is distributed in the hope that it will be useful, |
| 13461 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13462 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13463 | + Lesser General Public License for more details. |
| 13464 | + |
| 13465 | + You should have received a copy of the GNU Lesser General Public |
| 13466 | + License along with the GNU C Library; if not, see |
| 13467 | + <http://www.gnu.org/licenses/>. */ |
| 13468 | + |
| 13469 | +#include <support/xthread.h> |
| 13470 | + |
| 13471 | +void |
| 13472 | +xpthread_mutexattr_settype (pthread_mutexattr_t *attr, int flag) |
| 13473 | +{ |
| 13474 | + xpthread_check_return ("pthread_mutexattr_settype", |
| 13475 | + pthread_mutexattr_settype (attr, flag)); |
| 13476 | +} |
| 13477 | diff --git a/support/xpthread_once.c b/support/xpthread_once.c |
| 13478 | new file mode 100644 |
| 13479 | index 0000000000..70d58dbab2 |
| 13480 | --- /dev/null |
| 13481 | +++ b/support/xpthread_once.c |
| 13482 | @@ -0,0 +1,25 @@ |
| 13483 | +/* pthread_once with error checking. |
| 13484 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 13485 | + This file is part of the GNU C Library. |
| 13486 | + |
| 13487 | + The GNU C Library is free software; you can redistribute it and/or |
| 13488 | + modify it under the terms of the GNU Lesser General Public |
| 13489 | + License as published by the Free Software Foundation; either |
| 13490 | + version 2.1 of the License, or (at your option) any later version. |
| 13491 | + |
| 13492 | + The GNU C Library is distributed in the hope that it will be useful, |
| 13493 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13494 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13495 | + Lesser General Public License for more details. |
| 13496 | + |
| 13497 | + You should have received a copy of the GNU Lesser General Public |
| 13498 | + License along with the GNU C Library; if not, see |
| 13499 | + <http://www.gnu.org/licenses/>. */ |
| 13500 | + |
| 13501 | +#include <support/xthread.h> |
| 13502 | + |
| 13503 | +void |
| 13504 | +xpthread_once (pthread_once_t *guard, void (*func) (void)) |
| 13505 | +{ |
| 13506 | + xpthread_check_return ("pthread_once", pthread_once (guard, func)); |
| 13507 | +} |
| 13508 | diff --git a/support/xpthread_sigmask.c b/support/xpthread_sigmask.c |
| 13509 | new file mode 100644 |
| 13510 | index 0000000000..0ba9ca02dc |
| 13511 | --- /dev/null |
| 13512 | +++ b/support/xpthread_sigmask.c |
| 13513 | @@ -0,0 +1,34 @@ |
| 13514 | +/* pthread_sigmask with error checking. |
| 13515 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 13516 | + This file is part of the GNU C Library. |
| 13517 | + |
| 13518 | + The GNU C Library is free software; you can redistribute it and/or |
| 13519 | + modify it under the terms of the GNU Lesser General Public |
| 13520 | + License as published by the Free Software Foundation; either |
| 13521 | + version 2.1 of the License, or (at your option) any later version. |
| 13522 | + |
| 13523 | + The GNU C Library is distributed in the hope that it will be useful, |
| 13524 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13525 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13526 | + Lesser General Public License for more details. |
| 13527 | + |
| 13528 | + You should have received a copy of the GNU Lesser General Public |
| 13529 | + License along with the GNU C Library; if not, see |
| 13530 | + <http://www.gnu.org/licenses/>. */ |
| 13531 | + |
| 13532 | +#include <support/xsignal.h> |
| 13533 | +#include <support/support.h> |
| 13534 | + |
| 13535 | +#include <unistd.h> |
| 13536 | + |
| 13537 | +void |
| 13538 | +xpthread_sigmask (int how, const sigset_t *set, sigset_t *oldset) |
| 13539 | +{ |
| 13540 | + if (pthread_sigmask (how, set, oldset) != 0) |
| 13541 | + { |
| 13542 | + write_message ("error: pthread_setmask failed\n"); |
| 13543 | + /* Do not use exit because pthread_sigmask can be called from a |
| 13544 | + signal handler. */ |
| 13545 | + _exit (1); |
| 13546 | + } |
| 13547 | +} |
| 13548 | diff --git a/support/xpthread_spin_lock.c b/support/xpthread_spin_lock.c |
| 13549 | new file mode 100644 |
| 13550 | index 0000000000..6975215b17 |
| 13551 | --- /dev/null |
| 13552 | +++ b/support/xpthread_spin_lock.c |
| 13553 | @@ -0,0 +1,25 @@ |
| 13554 | +/* pthread_spin_lock with error checking. |
| 13555 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 13556 | + This file is part of the GNU C Library. |
| 13557 | + |
| 13558 | + The GNU C Library is free software; you can redistribute it and/or |
| 13559 | + modify it under the terms of the GNU Lesser General Public |
| 13560 | + License as published by the Free Software Foundation; either |
| 13561 | + version 2.1 of the License, or (at your option) any later version. |
| 13562 | + |
| 13563 | + The GNU C Library is distributed in the hope that it will be useful, |
| 13564 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13565 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13566 | + Lesser General Public License for more details. |
| 13567 | + |
| 13568 | + You should have received a copy of the GNU Lesser General Public |
| 13569 | + License along with the GNU C Library; if not, see |
| 13570 | + <http://www.gnu.org/licenses/>. */ |
| 13571 | + |
| 13572 | +#include <support/xthread.h> |
| 13573 | + |
| 13574 | +void |
| 13575 | +xpthread_spin_lock (pthread_spinlock_t *lock) |
| 13576 | +{ |
| 13577 | + xpthread_check_return ("pthread_spin_lock", pthread_spin_lock (lock)); |
| 13578 | +} |
| 13579 | diff --git a/support/xpthread_spin_unlock.c b/support/xpthread_spin_unlock.c |
| 13580 | new file mode 100644 |
| 13581 | index 0000000000..4f19a44c48 |
| 13582 | --- /dev/null |
| 13583 | +++ b/support/xpthread_spin_unlock.c |
| 13584 | @@ -0,0 +1,25 @@ |
| 13585 | +/* pthread_spin_unlock with error checking. |
| 13586 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 13587 | + This file is part of the GNU C Library. |
| 13588 | + |
| 13589 | + The GNU C Library is free software; you can redistribute it and/or |
| 13590 | + modify it under the terms of the GNU Lesser General Public |
| 13591 | + License as published by the Free Software Foundation; either |
| 13592 | + version 2.1 of the License, or (at your option) any later version. |
| 13593 | + |
| 13594 | + The GNU C Library is distributed in the hope that it will be useful, |
| 13595 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13596 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13597 | + Lesser General Public License for more details. |
| 13598 | + |
| 13599 | + You should have received a copy of the GNU Lesser General Public |
| 13600 | + License along with the GNU C Library; if not, see |
| 13601 | + <http://www.gnu.org/licenses/>. */ |
| 13602 | + |
| 13603 | +#include <support/xthread.h> |
| 13604 | + |
| 13605 | +void |
| 13606 | +xpthread_spin_unlock (pthread_spinlock_t *lock) |
| 13607 | +{ |
| 13608 | + xpthread_check_return ("pthread_spin_unlock", pthread_spin_unlock (lock)); |
| 13609 | +} |
| 13610 | diff --git a/support/xrealloc.c b/support/xrealloc.c |
| 13611 | new file mode 100644 |
| 13612 | index 0000000000..00c313880c |
| 13613 | --- /dev/null |
| 13614 | +++ b/support/xrealloc.c |
| 13615 | @@ -0,0 +1,32 @@ |
| 13616 | +/* Error-checking wrapper for realloc. |
| 13617 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 13618 | + This file is part of the GNU C Library. |
| 13619 | + |
| 13620 | + The GNU C Library is free software; you can redistribute it and/or |
| 13621 | + modify it under the terms of the GNU Lesser General Public |
| 13622 | + License as published by the Free Software Foundation; either |
| 13623 | + version 2.1 of the License, or (at your option) any later version. |
| 13624 | + |
| 13625 | + The GNU C Library is distributed in the hope that it will be useful, |
| 13626 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13627 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13628 | + Lesser General Public License for more details. |
| 13629 | + |
| 13630 | + You should have received a copy of the GNU Lesser General Public |
| 13631 | + License along with the GNU C Library; if not, see |
| 13632 | + <http://www.gnu.org/licenses/>. */ |
| 13633 | + |
| 13634 | +#include <support/support.h> |
| 13635 | + |
| 13636 | +#include <stdarg.h> |
| 13637 | +#include <stdio.h> |
| 13638 | +#include <stdlib.h> |
| 13639 | + |
| 13640 | +void * |
| 13641 | +xrealloc (void *p, size_t n) |
| 13642 | +{ |
| 13643 | + void *result = realloc (p, n); |
| 13644 | + if (result == NULL && (n > 0 || p == NULL)) |
| 13645 | + oom_error ("realloc", n); |
| 13646 | + return result; |
| 13647 | +} |
| 13648 | diff --git a/support/xrecvfrom.c b/support/xrecvfrom.c |
| 13649 | new file mode 100644 |
| 13650 | index 0000000000..17809c4dd2 |
| 13651 | --- /dev/null |
| 13652 | +++ b/support/xrecvfrom.c |
| 13653 | @@ -0,0 +1,33 @@ |
| 13654 | +/* recvfrom with error checking. |
| 13655 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 13656 | + This file is part of the GNU C Library. |
| 13657 | + |
| 13658 | + The GNU C Library is free software; you can redistribute it and/or |
| 13659 | + modify it under the terms of the GNU Lesser General Public |
| 13660 | + License as published by the Free Software Foundation; either |
| 13661 | + version 2.1 of the License, or (at your option) any later version. |
| 13662 | + |
| 13663 | + The GNU C Library is distributed in the hope that it will be useful, |
| 13664 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13665 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13666 | + Lesser General Public License for more details. |
| 13667 | + |
| 13668 | + You should have received a copy of the GNU Lesser General Public |
| 13669 | + License along with the GNU C Library; if not, see |
| 13670 | + <http://www.gnu.org/licenses/>. */ |
| 13671 | + |
| 13672 | +#include <support/xsocket.h> |
| 13673 | + |
| 13674 | +#include <stdio.h> |
| 13675 | +#include <stdlib.h> |
| 13676 | +#include <support/check.h> |
| 13677 | + |
| 13678 | +size_t |
| 13679 | +xrecvfrom (int fd, void *buf, size_t buflen, int flags, |
| 13680 | + struct sockaddr *sa, socklen_t *salen) |
| 13681 | +{ |
| 13682 | + ssize_t ret = recvfrom (fd, buf, buflen, flags, sa, salen); |
| 13683 | + if (ret < 0) |
| 13684 | + FAIL_EXIT1 ("error: recvfrom (%d), %zu bytes buffer: %m", fd, buflen); |
| 13685 | + return ret; |
| 13686 | +} |
| 13687 | diff --git a/support/xsendto.c b/support/xsendto.c |
| 13688 | new file mode 100644 |
| 13689 | index 0000000000..20bddf6965 |
| 13690 | --- /dev/null |
| 13691 | +++ b/support/xsendto.c |
| 13692 | @@ -0,0 +1,35 @@ |
| 13693 | +/* sendto with error checking. |
| 13694 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 13695 | + This file is part of the GNU C Library. |
| 13696 | + |
| 13697 | + The GNU C Library is free software; you can redistribute it and/or |
| 13698 | + modify it under the terms of the GNU Lesser General Public |
| 13699 | + License as published by the Free Software Foundation; either |
| 13700 | + version 2.1 of the License, or (at your option) any later version. |
| 13701 | + |
| 13702 | + The GNU C Library is distributed in the hope that it will be useful, |
| 13703 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13704 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13705 | + Lesser General Public License for more details. |
| 13706 | + |
| 13707 | + You should have received a copy of the GNU Lesser General Public |
| 13708 | + License along with the GNU C Library; if not, see |
| 13709 | + <http://www.gnu.org/licenses/>. */ |
| 13710 | + |
| 13711 | +#include <support/xsocket.h> |
| 13712 | + |
| 13713 | +#include <stdio.h> |
| 13714 | +#include <stdlib.h> |
| 13715 | +#include <support/check.h> |
| 13716 | + |
| 13717 | +void |
| 13718 | +xsendto (int fd, const void *buf, size_t buflen, int flags, |
| 13719 | + const struct sockaddr *sa, socklen_t salen) |
| 13720 | +{ |
| 13721 | + ssize_t ret = sendto (fd, buf, buflen, flags, sa, salen); |
| 13722 | + if (ret < 0) |
| 13723 | + FAIL_EXIT1 ("sendto (%d), %zu bytes, family %d: %m", |
| 13724 | + fd, buflen, sa->sa_family); |
| 13725 | + if (ret != buflen) |
| 13726 | + FAIL_EXIT1 ("sendto (%d) sent %zd bytes instead of %zu", fd, ret, buflen); |
| 13727 | +} |
| 13728 | diff --git a/sysdeps/sparc/sparc32/fpu/s_fdimf.S b/support/xsetsockopt.c |
| 13729 | similarity index 62% |
| 13730 | rename from sysdeps/sparc/sparc32/fpu/s_fdimf.S |
| 13731 | rename to support/xsetsockopt.c |
| 13732 | index c3fe8afa98..9931882e75 100644 |
| 13733 | --- a/sysdeps/sparc/sparc32/fpu/s_fdimf.S |
| 13734 | +++ b/support/xsetsockopt.c |
| 13735 | @@ -1,7 +1,6 @@ |
| 13736 | -/* Compute positive difference, sparc 32-bit. |
| 13737 | - Copyright (C) 2013-2016 Free Software Foundation, Inc. |
| 13738 | +/* setsockopt with error checking. |
| 13739 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 13740 | This file is part of the GNU C Library. |
| 13741 | - Contributed by David S. Miller <davem@davemloft.net>. |
| 13742 | |
| 13743 | The GNU C Library is free software; you can redistribute it and/or |
| 13744 | modify it under the terms of the GNU Lesser General Public |
| 13745 | @@ -17,19 +16,16 @@ |
| 13746 | License along with the GNU C Library; if not, see |
| 13747 | <http://www.gnu.org/licenses/>. */ |
| 13748 | |
| 13749 | -#include <sysdep.h> |
| 13750 | +#include <support/xsocket.h> |
| 13751 | |
| 13752 | -ENTRY(__fdimf) |
| 13753 | - st %o0, [%sp + 72] |
| 13754 | - st %o1, [%sp + 76] |
| 13755 | - ld [%sp + 72], %f0 |
| 13756 | - ld [%sp + 76], %f1 |
| 13757 | - fcmps %f0, %f1 |
| 13758 | - fbug 1f |
| 13759 | - st %g0, [%sp + 72] |
| 13760 | - ld [%sp + 72], %f0 |
| 13761 | - fnegs %f0, %f1 |
| 13762 | -1: retl |
| 13763 | - fsubs %f0, %f1, %f0 |
| 13764 | -END(__fdimf) |
| 13765 | -weak_alias (__fdimf, fdimf) |
| 13766 | +#include <stdio.h> |
| 13767 | +#include <stdlib.h> |
| 13768 | +#include <support/check.h> |
| 13769 | + |
| 13770 | +void |
| 13771 | +xsetsockopt (int fd, int level, int name, const void *val, socklen_t vallen) |
| 13772 | +{ |
| 13773 | + if (setsockopt (fd, level, name, val, vallen) != 0) |
| 13774 | + FAIL_EXIT1 ("setsockopt (%d, %d, %d), %zu bytes: %m", |
| 13775 | + fd, level, name, (size_t) vallen); |
| 13776 | +} |
| 13777 | diff --git a/support/xsignal.h b/support/xsignal.h |
| 13778 | new file mode 100644 |
| 13779 | index 0000000000..3dc0d9d5ce |
| 13780 | --- /dev/null |
| 13781 | +++ b/support/xsignal.h |
| 13782 | @@ -0,0 +1,34 @@ |
| 13783 | +/* Support functionality for using signals. |
| 13784 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 13785 | + This file is part of the GNU C Library. |
| 13786 | + |
| 13787 | + The GNU C Library is free software; you can redistribute it and/or |
| 13788 | + modify it under the terms of the GNU Lesser General Public |
| 13789 | + License as published by the Free Software Foundation; either |
| 13790 | + version 2.1 of the License, or (at your option) any later version. |
| 13791 | + |
| 13792 | + The GNU C Library is distributed in the hope that it will be useful, |
| 13793 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13794 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13795 | + Lesser General Public License for more details. |
| 13796 | + |
| 13797 | + You should have received a copy of the GNU Lesser General Public |
| 13798 | + License along with the GNU C Library; if not, see |
| 13799 | + <http://www.gnu.org/licenses/>. */ |
| 13800 | + |
| 13801 | +#ifndef SUPPORT_SIGNAL_H |
| 13802 | +#define SUPPORT_SIGNAL_H |
| 13803 | + |
| 13804 | +#include <signal.h> |
| 13805 | +#include <sys/cdefs.h> |
| 13806 | + |
| 13807 | +__BEGIN_DECLS |
| 13808 | + |
| 13809 | +/* The following functions call the corresponding libpthread functions |
| 13810 | + and terminate the process on error. */ |
| 13811 | + |
| 13812 | +void xpthread_sigmask (int how, const sigset_t *set, sigset_t *oldset); |
| 13813 | + |
| 13814 | +__END_DECLS |
| 13815 | + |
| 13816 | +#endif /* SUPPORT_SIGNAL_H */ |
| 13817 | diff --git a/support/xsocket.c b/support/xsocket.c |
| 13818 | new file mode 100644 |
| 13819 | index 0000000000..c1deaee924 |
| 13820 | --- /dev/null |
| 13821 | +++ b/support/xsocket.c |
| 13822 | @@ -0,0 +1,32 @@ |
| 13823 | +/* socket with error checking. |
| 13824 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 13825 | + This file is part of the GNU C Library. |
| 13826 | + |
| 13827 | + The GNU C Library is free software; you can redistribute it and/or |
| 13828 | + modify it under the terms of the GNU Lesser General Public |
| 13829 | + License as published by the Free Software Foundation; either |
| 13830 | + version 2.1 of the License, or (at your option) any later version. |
| 13831 | + |
| 13832 | + The GNU C Library is distributed in the hope that it will be useful, |
| 13833 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13834 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13835 | + Lesser General Public License for more details. |
| 13836 | + |
| 13837 | + You should have received a copy of the GNU Lesser General Public |
| 13838 | + License along with the GNU C Library; if not, see |
| 13839 | + <http://www.gnu.org/licenses/>. */ |
| 13840 | + |
| 13841 | +#include <support/xsocket.h> |
| 13842 | + |
| 13843 | +#include <stdio.h> |
| 13844 | +#include <stdlib.h> |
| 13845 | +#include <support/check.h> |
| 13846 | + |
| 13847 | +int |
| 13848 | +xsocket (int domain, int type, int protocol) |
| 13849 | +{ |
| 13850 | + int fd = socket (domain, type, protocol); |
| 13851 | + if (fd < 0) |
| 13852 | + FAIL_EXIT1 ("socket (%d, %d, %d): %m\n", domain, type, protocol); |
| 13853 | + return fd; |
| 13854 | +} |
| 13855 | diff --git a/support/xsocket.h b/support/xsocket.h |
| 13856 | new file mode 100644 |
| 13857 | index 0000000000..d6724948d8 |
| 13858 | --- /dev/null |
| 13859 | +++ b/support/xsocket.h |
| 13860 | @@ -0,0 +1,39 @@ |
| 13861 | +/* Error-checking wrappers for socket functions. |
| 13862 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 13863 | + This file is part of the GNU C Library. |
| 13864 | + |
| 13865 | + The GNU C Library is free software; you can redistribute it and/or |
| 13866 | + modify it under the terms of the GNU Lesser General Public |
| 13867 | + License as published by the Free Software Foundation; either |
| 13868 | + version 2.1 of the License, or (at your option) any later version. |
| 13869 | + |
| 13870 | + The GNU C Library is distributed in the hope that it will be useful, |
| 13871 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13872 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13873 | + Lesser General Public License for more details. |
| 13874 | + |
| 13875 | + You should have received a copy of the GNU Lesser General Public |
| 13876 | + License along with the GNU C Library; if not, see |
| 13877 | + <http://www.gnu.org/licenses/>. */ |
| 13878 | + |
| 13879 | +#ifndef SUPPORT_XSOCKET_H |
| 13880 | +#define SUPPORT_XSOCKET_H |
| 13881 | + |
| 13882 | +#include <poll.h> |
| 13883 | +#include <sys/socket.h> |
| 13884 | +#include <sys/types.h> |
| 13885 | + |
| 13886 | +int xsocket (int, int, int); |
| 13887 | +void xsetsockopt (int, int, int, const void *, socklen_t); |
| 13888 | +void xgetsockname (int, struct sockaddr *, socklen_t *); |
| 13889 | +void xconnect (int, const struct sockaddr *, socklen_t); |
| 13890 | +void xbind (int, const struct sockaddr *, socklen_t); |
| 13891 | +void xlisten (int, int); |
| 13892 | +int xaccept (int, struct sockaddr *, socklen_t *); |
| 13893 | +int xaccept4 (int, struct sockaddr *, socklen_t *, int); |
| 13894 | +void xsendto (int, const void *, size_t, int, |
| 13895 | + const struct sockaddr *, socklen_t); |
| 13896 | +size_t xrecvfrom (int, void *, size_t, int, struct sockaddr *, socklen_t *); |
| 13897 | +int xpoll (struct pollfd *, nfds_t, int); |
| 13898 | + |
| 13899 | +#endif /* SUPPORT_XSOCKET_H */ |
| 13900 | diff --git a/support/xstdio.h b/support/xstdio.h |
| 13901 | new file mode 100644 |
| 13902 | index 0000000000..bcc2e863bf |
| 13903 | --- /dev/null |
| 13904 | +++ b/support/xstdio.h |
| 13905 | @@ -0,0 +1,32 @@ |
| 13906 | +/* Error-checking wrappers for stdio functions. |
| 13907 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 13908 | + This file is part of the GNU C Library. |
| 13909 | + |
| 13910 | + The GNU C Library is free software; you can redistribute it and/or |
| 13911 | + modify it under the terms of the GNU Lesser General Public |
| 13912 | + License as published by the Free Software Foundation; either |
| 13913 | + version 2.1 of the License, or (at your option) any later version. |
| 13914 | + |
| 13915 | + The GNU C Library is distributed in the hope that it will be useful, |
| 13916 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13917 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13918 | + Lesser General Public License for more details. |
| 13919 | + |
| 13920 | + You should have received a copy of the GNU Lesser General Public |
| 13921 | + License along with the GNU C Library; if not, see |
| 13922 | + <http://www.gnu.org/licenses/>. */ |
| 13923 | + |
| 13924 | +#ifndef SUPPORT_XSTDIO_H |
| 13925 | +#define SUPPORT_XSTDIO_H |
| 13926 | + |
| 13927 | +#include <stdio.h> |
| 13928 | +#include <sys/cdefs.h> |
| 13929 | + |
| 13930 | +__BEGIN_DECLS |
| 13931 | + |
| 13932 | +FILE *xfopen (const char *path, const char *mode); |
| 13933 | +void xfclose (FILE *); |
| 13934 | + |
| 13935 | +__END_DECLS |
| 13936 | + |
| 13937 | +#endif /* SUPPORT_XSTDIO_H */ |
| 13938 | diff --git a/support/xstrdup.c b/support/xstrdup.c |
| 13939 | new file mode 100644 |
| 13940 | index 0000000000..d6a8c04baf |
| 13941 | --- /dev/null |
| 13942 | +++ b/support/xstrdup.c |
| 13943 | @@ -0,0 +1,30 @@ |
| 13944 | +/* strdup with error checking. |
| 13945 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 13946 | + This file is part of the GNU C Library. |
| 13947 | + |
| 13948 | + The GNU C Library is free software; you can redistribute it and/or |
| 13949 | + modify it under the terms of the GNU Lesser General Public |
| 13950 | + License as published by the Free Software Foundation; either |
| 13951 | + version 2.1 of the License, or (at your option) any later version. |
| 13952 | + |
| 13953 | + The GNU C Library is distributed in the hope that it will be useful, |
| 13954 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13955 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13956 | + Lesser General Public License for more details. |
| 13957 | + |
| 13958 | + You should have received a copy of the GNU Lesser General Public |
| 13959 | + License along with the GNU C Library; if not, see |
| 13960 | + <http://www.gnu.org/licenses/>. */ |
| 13961 | + |
| 13962 | +#include <support/support.h> |
| 13963 | + |
| 13964 | +#include <string.h> |
| 13965 | + |
| 13966 | +char * |
| 13967 | +xstrdup (const char *s) |
| 13968 | +{ |
| 13969 | + char *p = strdup (s); |
| 13970 | + if (p == NULL) |
| 13971 | + oom_error ("strdup", strlen (s)); |
| 13972 | + return p; |
| 13973 | +} |
| 13974 | diff --git a/support/xthread.h b/support/xthread.h |
| 13975 | new file mode 100644 |
| 13976 | index 0000000000..6dd7e709be |
| 13977 | --- /dev/null |
| 13978 | +++ b/support/xthread.h |
| 13979 | @@ -0,0 +1,77 @@ |
| 13980 | +/* Support functionality for using threads. |
| 13981 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 13982 | + This file is part of the GNU C Library. |
| 13983 | + |
| 13984 | + The GNU C Library is free software; you can redistribute it and/or |
| 13985 | + modify it under the terms of the GNU Lesser General Public |
| 13986 | + License as published by the Free Software Foundation; either |
| 13987 | + version 2.1 of the License, or (at your option) any later version. |
| 13988 | + |
| 13989 | + The GNU C Library is distributed in the hope that it will be useful, |
| 13990 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13991 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13992 | + Lesser General Public License for more details. |
| 13993 | + |
| 13994 | + You should have received a copy of the GNU Lesser General Public |
| 13995 | + License along with the GNU C Library; if not, see |
| 13996 | + <http://www.gnu.org/licenses/>. */ |
| 13997 | + |
| 13998 | +#ifndef SUPPORT_THREAD_H |
| 13999 | +#define SUPPORT_THREAD_H |
| 14000 | + |
| 14001 | +#include <pthread.h> |
| 14002 | +#include <sys/cdefs.h> |
| 14003 | + |
| 14004 | +__BEGIN_DECLS |
| 14005 | + |
| 14006 | +/* Terminate the process (with exit status 0) after SECONDS have |
| 14007 | + elapsed, from a helper thread. The process is terminated with the |
| 14008 | + exit function, so atexit handlers are executed. */ |
| 14009 | +void delayed_exit (int seconds); |
| 14010 | + |
| 14011 | +/* Terminate the process (with exit status 1) if VALUE is not zero. |
| 14012 | + In that case, print a failure message to standard output mentioning |
| 14013 | + FUNCTION. The process is terminated with the exit function, so |
| 14014 | + atexit handlers are executed. */ |
| 14015 | +void xpthread_check_return (const char *function, int value); |
| 14016 | + |
| 14017 | +/* The following functions call the corresponding libpthread functions |
| 14018 | + and terminate the process on error. */ |
| 14019 | + |
| 14020 | +void xpthread_barrier_init (pthread_barrier_t *barrier, |
| 14021 | + pthread_barrierattr_t *attr, unsigned int count); |
| 14022 | +void xpthread_barrier_destroy (pthread_barrier_t *barrier); |
| 14023 | +void xpthread_mutexattr_destroy (pthread_mutexattr_t *); |
| 14024 | +void xpthread_mutexattr_init (pthread_mutexattr_t *); |
| 14025 | +void xpthread_mutexattr_setprotocol (pthread_mutexattr_t *, int); |
| 14026 | +void xpthread_mutexattr_setpshared (pthread_mutexattr_t *, int); |
| 14027 | +void xpthread_mutexattr_setrobust (pthread_mutexattr_t *, int); |
| 14028 | +void xpthread_mutexattr_settype (pthread_mutexattr_t *, int); |
| 14029 | +void xpthread_mutex_init (pthread_mutex_t *, const pthread_mutexattr_t *); |
| 14030 | +void xpthread_mutex_destroy (pthread_mutex_t *); |
| 14031 | +void xpthread_mutex_lock (pthread_mutex_t *mutex); |
| 14032 | +void xpthread_mutex_unlock (pthread_mutex_t *mutex); |
| 14033 | +void xpthread_mutex_consistent (pthread_mutex_t *); |
| 14034 | +void xpthread_spin_lock (pthread_spinlock_t *lock); |
| 14035 | +void xpthread_spin_unlock (pthread_spinlock_t *lock); |
| 14036 | +void xpthread_cond_wait (pthread_cond_t * cond, pthread_mutex_t * mutex); |
| 14037 | +pthread_t xpthread_create (pthread_attr_t *attr, |
| 14038 | + void *(*thread_func) (void *), void *closure); |
| 14039 | +void xpthread_detach (pthread_t thr); |
| 14040 | +void xpthread_cancel (pthread_t thr); |
| 14041 | +void *xpthread_join (pthread_t thr); |
| 14042 | +void xpthread_once (pthread_once_t *guard, void (*func) (void)); |
| 14043 | +void xpthread_attr_destroy (pthread_attr_t *attr); |
| 14044 | +void xpthread_attr_init (pthread_attr_t *attr); |
| 14045 | +void xpthread_attr_setdetachstate (pthread_attr_t *attr, |
| 14046 | + int detachstate); |
| 14047 | +void xpthread_attr_setstacksize (pthread_attr_t *attr, |
| 14048 | + size_t stacksize); |
| 14049 | + |
| 14050 | +/* This function returns non-zero if pthread_barrier_wait returned |
| 14051 | + PTHREAD_BARRIER_SERIAL_THREAD. */ |
| 14052 | +int xpthread_barrier_wait (pthread_barrier_t *barrier); |
| 14053 | + |
| 14054 | +__END_DECLS |
| 14055 | + |
| 14056 | +#endif /* SUPPORT_THREAD_H */ |
| 14057 | diff --git a/support/xunistd.h b/support/xunistd.h |
| 14058 | new file mode 100644 |
| 14059 | index 0000000000..151d743e1f |
| 14060 | --- /dev/null |
| 14061 | +++ b/support/xunistd.h |
| 14062 | @@ -0,0 +1,56 @@ |
| 14063 | +/* POSIX-specific extra functions. |
| 14064 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 14065 | + This file is part of the GNU C Library. |
| 14066 | + |
| 14067 | + The GNU C Library is free software; you can redistribute it and/or |
| 14068 | + modify it under the terms of the GNU Lesser General Public |
| 14069 | + License as published by the Free Software Foundation; either |
| 14070 | + version 2.1 of the License, or (at your option) any later version. |
| 14071 | + |
| 14072 | + The GNU C Library is distributed in the hope that it will be useful, |
| 14073 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14074 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14075 | + Lesser General Public License for more details. |
| 14076 | + |
| 14077 | + You should have received a copy of the GNU Lesser General Public |
| 14078 | + License along with the GNU C Library; if not, see |
| 14079 | + <http://www.gnu.org/licenses/>. */ |
| 14080 | + |
| 14081 | +/* These wrapper functions use POSIX types and therefore cannot be |
| 14082 | + declared in <support/support.h>. */ |
| 14083 | + |
| 14084 | +#ifndef SUPPORT_XUNISTD_H |
| 14085 | +#define SUPPORT_XUNISTD_H |
| 14086 | + |
| 14087 | +#include <sys/cdefs.h> |
| 14088 | +#include <sys/types.h> |
| 14089 | +#include <unistd.h> |
| 14090 | + |
| 14091 | +__BEGIN_DECLS |
| 14092 | + |
| 14093 | +struct stat64; |
| 14094 | + |
| 14095 | +pid_t xfork (void); |
| 14096 | +pid_t xwaitpid (pid_t, int *status, int flags); |
| 14097 | +void xpipe (int[2]); |
| 14098 | +void xdup2 (int, int); |
| 14099 | +int xopen (const char *path, int flags, mode_t); |
| 14100 | +void xstat (const char *path, struct stat64 *); |
| 14101 | +void xmkdir (const char *path, mode_t); |
| 14102 | +void xchroot (const char *path); |
| 14103 | + |
| 14104 | +/* Close the file descriptor. Ignore EINTR errors, but terminate the |
| 14105 | + process on other errors. */ |
| 14106 | +void xclose (int); |
| 14107 | + |
| 14108 | +/* Write the buffer. Retry on short writes. */ |
| 14109 | +void xwrite (int, const void *, size_t); |
| 14110 | + |
| 14111 | +/* Invoke mmap with a zero file offset. */ |
| 14112 | +void *xmmap (void *addr, size_t length, int prot, int flags, int fd); |
| 14113 | + |
| 14114 | +void xmunmap (void *addr, size_t length); |
| 14115 | + |
| 14116 | +__END_DECLS |
| 14117 | + |
| 14118 | +#endif /* SUPPORT_XUNISTD_H */ |
| 14119 | diff --git a/support/xwaitpid.c b/support/xwaitpid.c |
| 14120 | new file mode 100644 |
| 14121 | index 0000000000..204795e4c0 |
| 14122 | --- /dev/null |
| 14123 | +++ b/support/xwaitpid.c |
| 14124 | @@ -0,0 +1,33 @@ |
| 14125 | +/* waitpid with error checking. |
| 14126 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 14127 | + This file is part of the GNU C Library. |
| 14128 | + |
| 14129 | + The GNU C Library is free software; you can redistribute it and/or |
| 14130 | + modify it under the terms of the GNU Lesser General Public |
| 14131 | + License as published by the Free Software Foundation; either |
| 14132 | + version 2.1 of the License, or (at your option) any later version. |
| 14133 | + |
| 14134 | + The GNU C Library is distributed in the hope that it will be useful, |
| 14135 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14136 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14137 | + Lesser General Public License for more details. |
| 14138 | + |
| 14139 | + You should have received a copy of the GNU Lesser General Public |
| 14140 | + License along with the GNU C Library; if not, see |
| 14141 | + <http://www.gnu.org/licenses/>. */ |
| 14142 | + |
| 14143 | +#include <support/xunistd.h> |
| 14144 | + |
| 14145 | +#include <stdio.h> |
| 14146 | +#include <stdlib.h> |
| 14147 | +#include <support/check.h> |
| 14148 | +#include <sys/wait.h> |
| 14149 | + |
| 14150 | +int |
| 14151 | +xwaitpid (int pid, int *status, int flags) |
| 14152 | +{ |
| 14153 | + pid_t result = waitpid (pid, status, flags); |
| 14154 | + if (result < 0) |
| 14155 | + FAIL_EXIT1 ("waitpid: %m\n"); |
| 14156 | + return result; |
| 14157 | +} |
| 14158 | diff --git a/support/xwrite.c b/support/xwrite.c |
| 14159 | new file mode 100644 |
| 14160 | index 0000000000..134e8ee4c1 |
| 14161 | --- /dev/null |
| 14162 | +++ b/support/xwrite.c |
| 14163 | @@ -0,0 +1,39 @@ |
| 14164 | +/* write with error checking and retries. |
| 14165 | + Copyright (C) 2016-2017 Free Software Foundation, Inc. |
| 14166 | + This file is part of the GNU C Library. |
| 14167 | + |
| 14168 | + The GNU C Library is free software; you can redistribute it and/or |
| 14169 | + modify it under the terms of the GNU Lesser General Public |
| 14170 | + License as published by the Free Software Foundation; either |
| 14171 | + version 2.1 of the License, or (at your option) any later version. |
| 14172 | + |
| 14173 | + The GNU C Library is distributed in the hope that it will be useful, |
| 14174 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14175 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14176 | + Lesser General Public License for more details. |
| 14177 | + |
| 14178 | + You should have received a copy of the GNU Lesser General Public |
| 14179 | + License along with the GNU C Library; if not, see |
| 14180 | + <http://www.gnu.org/licenses/>. */ |
| 14181 | + |
| 14182 | +#include <support/xunistd.h> |
| 14183 | + |
| 14184 | +#include <support/check.h> |
| 14185 | + |
| 14186 | +void |
| 14187 | +xwrite (int fd, const void *buffer, size_t length) |
| 14188 | +{ |
| 14189 | + const char *p = buffer; |
| 14190 | + const char *end = p + length; |
| 14191 | + while (p < end) |
| 14192 | + { |
| 14193 | + ssize_t ret = write (fd, p, end - p); |
| 14194 | + if (ret < 0) |
| 14195 | + FAIL_EXIT1 ("write of %zu bytes failed after %td: %m", |
| 14196 | + length, p - (const char *) buffer); |
| 14197 | + if (ret == 0) |
| 14198 | + FAIL_EXIT1 ("write return 0 after writing %td bytes of %zu", |
| 14199 | + p - (const char *) buffer, length); |
| 14200 | + p += ret; |
| 14201 | + } |
| 14202 | +} |
| 14203 | diff --git a/sysdeps/aarch64/dl-machine.h b/sysdeps/aarch64/dl-machine.h |
| 14204 | index 282805e396..e86d8b5b63 100644 |
| 14205 | --- a/sysdeps/aarch64/dl-machine.h |
| 14206 | +++ b/sysdeps/aarch64/dl-machine.h |
| 14207 | @@ -172,8 +172,8 @@ _dl_start_user: \n\ |
| 14208 | cmp x0, #0 \n\ |
| 14209 | bne 1b \n\ |
| 14210 | // Update _dl_argv \n\ |
| 14211 | - adrp x3, _dl_argv \n\ |
| 14212 | - str x2, [x3, #:lo12:_dl_argv] \n\ |
| 14213 | + adrp x3, __GI__dl_argv \n\ |
| 14214 | + str x2, [x3, #:lo12:__GI__dl_argv] \n\ |
| 14215 | .L_done_stack_adjust: \n\ |
| 14216 | // compute envp \n\ |
| 14217 | add x3, x2, x1, lsl #3 \n\ |
| 14218 | diff --git a/sysdeps/aarch64/nptl/tcb-offsets.sym b/sysdeps/aarch64/nptl/tcb-offsets.sym |
| 14219 | index 0677aeabff..238647dd47 100644 |
| 14220 | --- a/sysdeps/aarch64/nptl/tcb-offsets.sym |
| 14221 | +++ b/sysdeps/aarch64/nptl/tcb-offsets.sym |
| 14222 | @@ -2,6 +2,5 @@ |
| 14223 | #include <tls.h> |
| 14224 | |
| 14225 | PTHREAD_MULTIPLE_THREADS_OFFSET offsetof (struct pthread, header.multiple_threads) |
| 14226 | -PTHREAD_PID_OFFSET offsetof (struct pthread, pid) |
| 14227 | PTHREAD_TID_OFFSET offsetof (struct pthread, tid) |
| 14228 | PTHREAD_SIZEOF sizeof (struct pthread) |
| 14229 | diff --git a/sysdeps/alpha/fpu/s_ceil.c b/sysdeps/alpha/fpu/s_ceil.c |
| 14230 | index c1ff864d4b..e9c350af1c 100644 |
| 14231 | --- a/sysdeps/alpha/fpu/s_ceil.c |
| 14232 | +++ b/sysdeps/alpha/fpu/s_ceil.c |
| 14233 | @@ -26,17 +26,16 @@ |
| 14234 | double |
| 14235 | __ceil (double x) |
| 14236 | { |
| 14237 | + if (isnan (x)) |
| 14238 | + return x + x; |
| 14239 | + |
| 14240 | if (isless (fabs (x), 9007199254740992.0)) /* 1 << DBL_MANT_DIG */ |
| 14241 | { |
| 14242 | double tmp1, new_x; |
| 14243 | |
| 14244 | new_x = -x; |
| 14245 | __asm ( |
| 14246 | -#ifdef _IEEE_FP_INEXACT |
| 14247 | - "cvttq/svim %2,%1\n\t" |
| 14248 | -#else |
| 14249 | "cvttq/svm %2,%1\n\t" |
| 14250 | -#endif |
| 14251 | "cvtqt/m %1,%0\n\t" |
| 14252 | : "=f"(new_x), "=&f"(tmp1) |
| 14253 | : "f"(new_x)); |
| 14254 | diff --git a/sysdeps/alpha/fpu/s_ceilf.c b/sysdeps/alpha/fpu/s_ceilf.c |
| 14255 | index 7e63a6fe94..77e01a99f7 100644 |
| 14256 | --- a/sysdeps/alpha/fpu/s_ceilf.c |
| 14257 | +++ b/sysdeps/alpha/fpu/s_ceilf.c |
| 14258 | @@ -25,6 +25,9 @@ |
| 14259 | float |
| 14260 | __ceilf (float x) |
| 14261 | { |
| 14262 | + if (isnanf (x)) |
| 14263 | + return x + x; |
| 14264 | + |
| 14265 | if (isless (fabsf (x), 16777216.0f)) /* 1 << FLT_MANT_DIG */ |
| 14266 | { |
| 14267 | /* Note that Alpha S_Floating is stored in registers in a |
| 14268 | @@ -36,11 +39,7 @@ __ceilf (float x) |
| 14269 | |
| 14270 | new_x = -x; |
| 14271 | __asm ("cvtst/s %3,%2\n\t" |
| 14272 | -#ifdef _IEEE_FP_INEXACT |
| 14273 | - "cvttq/svim %2,%1\n\t" |
| 14274 | -#else |
| 14275 | "cvttq/svm %2,%1\n\t" |
| 14276 | -#endif |
| 14277 | "cvtqt/m %1,%0\n\t" |
| 14278 | : "=f"(new_x), "=&f"(tmp1), "=&f"(tmp2) |
| 14279 | : "f"(new_x)); |
| 14280 | diff --git a/sysdeps/alpha/fpu/s_floor.c b/sysdeps/alpha/fpu/s_floor.c |
| 14281 | index 1a6f8c4617..9930f6be42 100644 |
| 14282 | --- a/sysdeps/alpha/fpu/s_floor.c |
| 14283 | +++ b/sysdeps/alpha/fpu/s_floor.c |
| 14284 | @@ -27,16 +27,15 @@ |
| 14285 | double |
| 14286 | __floor (double x) |
| 14287 | { |
| 14288 | + if (isnan (x)) |
| 14289 | + return x + x; |
| 14290 | + |
| 14291 | if (isless (fabs (x), 9007199254740992.0)) /* 1 << DBL_MANT_DIG */ |
| 14292 | { |
| 14293 | double tmp1, new_x; |
| 14294 | |
| 14295 | __asm ( |
| 14296 | -#ifdef _IEEE_FP_INEXACT |
| 14297 | - "cvttq/svim %2,%1\n\t" |
| 14298 | -#else |
| 14299 | "cvttq/svm %2,%1\n\t" |
| 14300 | -#endif |
| 14301 | "cvtqt/m %1,%0\n\t" |
| 14302 | : "=f"(new_x), "=&f"(tmp1) |
| 14303 | : "f"(x)); |
| 14304 | diff --git a/sysdeps/alpha/fpu/s_floorf.c b/sysdeps/alpha/fpu/s_floorf.c |
| 14305 | index 8cd80e2b42..015c04f40d 100644 |
| 14306 | --- a/sysdeps/alpha/fpu/s_floorf.c |
| 14307 | +++ b/sysdeps/alpha/fpu/s_floorf.c |
| 14308 | @@ -26,6 +26,9 @@ |
| 14309 | float |
| 14310 | __floorf (float x) |
| 14311 | { |
| 14312 | + if (isnanf (x)) |
| 14313 | + return x + x; |
| 14314 | + |
| 14315 | if (isless (fabsf (x), 16777216.0f)) /* 1 << FLT_MANT_DIG */ |
| 14316 | { |
| 14317 | /* Note that Alpha S_Floating is stored in registers in a |
| 14318 | @@ -36,11 +39,7 @@ __floorf (float x) |
| 14319 | float tmp1, tmp2, new_x; |
| 14320 | |
| 14321 | __asm ("cvtst/s %3,%2\n\t" |
| 14322 | -#ifdef _IEEE_FP_INEXACT |
| 14323 | - "cvttq/svim %2,%1\n\t" |
| 14324 | -#else |
| 14325 | "cvttq/svm %2,%1\n\t" |
| 14326 | -#endif |
| 14327 | "cvtqt/m %1,%0\n\t" |
| 14328 | : "=f"(new_x), "=&f"(tmp1), "=&f"(tmp2) |
| 14329 | : "f"(x)); |
| 14330 | diff --git a/sysdeps/alpha/fpu/s_rint.c b/sysdeps/alpha/fpu/s_rint.c |
| 14331 | index f33fe72c11..259348afc0 100644 |
| 14332 | --- a/sysdeps/alpha/fpu/s_rint.c |
| 14333 | +++ b/sysdeps/alpha/fpu/s_rint.c |
| 14334 | @@ -23,6 +23,9 @@ |
| 14335 | double |
| 14336 | __rint (double x) |
| 14337 | { |
| 14338 | + if (isnan (x)) |
| 14339 | + return x + x; |
| 14340 | + |
| 14341 | if (isless (fabs (x), 9007199254740992.0)) /* 1 << DBL_MANT_DIG */ |
| 14342 | { |
| 14343 | double tmp1, new_x; |
| 14344 | diff --git a/sysdeps/alpha/fpu/s_rintf.c b/sysdeps/alpha/fpu/s_rintf.c |
| 14345 | index 1400dfe8d7..645728ad5b 100644 |
| 14346 | --- a/sysdeps/alpha/fpu/s_rintf.c |
| 14347 | +++ b/sysdeps/alpha/fpu/s_rintf.c |
| 14348 | @@ -22,6 +22,9 @@ |
| 14349 | float |
| 14350 | __rintf (float x) |
| 14351 | { |
| 14352 | + if (isnanf (x)) |
| 14353 | + return x + x; |
| 14354 | + |
| 14355 | if (isless (fabsf (x), 16777216.0f)) /* 1 << FLT_MANT_DIG */ |
| 14356 | { |
| 14357 | /* Note that Alpha S_Floating is stored in registers in a |
| 14358 | diff --git a/sysdeps/alpha/fpu/s_trunc.c b/sysdeps/alpha/fpu/s_trunc.c |
| 14359 | index 16cb114a72..4b986a6926 100644 |
| 14360 | --- a/sysdeps/alpha/fpu/s_trunc.c |
| 14361 | +++ b/sysdeps/alpha/fpu/s_trunc.c |
| 14362 | @@ -28,12 +28,11 @@ __trunc (double x) |
| 14363 | double two52 = copysign (0x1.0p52, x); |
| 14364 | double r, tmp; |
| 14365 | |
| 14366 | + if (isgreaterequal (fabs (x), 0x1.0p52)) |
| 14367 | + return x; |
| 14368 | + |
| 14369 | __asm ( |
| 14370 | -#ifdef _IEEE_FP_INEXACT |
| 14371 | - "addt/suic %2, %3, %1\n\tsubt/suic %1, %3, %0" |
| 14372 | -#else |
| 14373 | "addt/suc %2, %3, %1\n\tsubt/suc %1, %3, %0" |
| 14374 | -#endif |
| 14375 | : "=&f"(r), "=&f"(tmp) |
| 14376 | : "f"(x), "f"(two52)); |
| 14377 | |
| 14378 | diff --git a/sysdeps/alpha/fpu/s_truncf.c b/sysdeps/alpha/fpu/s_truncf.c |
| 14379 | index 2290f28295..3e93356166 100644 |
| 14380 | --- a/sysdeps/alpha/fpu/s_truncf.c |
| 14381 | +++ b/sysdeps/alpha/fpu/s_truncf.c |
| 14382 | @@ -27,12 +27,11 @@ __truncf (float x) |
| 14383 | float two23 = copysignf (0x1.0p23, x); |
| 14384 | float r, tmp; |
| 14385 | |
| 14386 | + if (isgreaterequal (fabsf (x), 0x1.0p23)) |
| 14387 | + return x; |
| 14388 | + |
| 14389 | __asm ( |
| 14390 | -#ifdef _IEEE_FP_INEXACT |
| 14391 | - "adds/suic %2, %3, %1\n\tsubs/suic %1, %3, %0" |
| 14392 | -#else |
| 14393 | "adds/suc %2, %3, %1\n\tsubs/suc %1, %3, %0" |
| 14394 | -#endif |
| 14395 | : "=&f"(r), "=&f"(tmp) |
| 14396 | : "f"(x), "f"(two23)); |
| 14397 | |
| 14398 | diff --git a/sysdeps/alpha/nptl/tcb-offsets.sym b/sysdeps/alpha/nptl/tcb-offsets.sym |
| 14399 | index c21a791040..1005621b37 100644 |
| 14400 | --- a/sysdeps/alpha/nptl/tcb-offsets.sym |
| 14401 | +++ b/sysdeps/alpha/nptl/tcb-offsets.sym |
| 14402 | @@ -10,5 +10,4 @@ |
| 14403 | #define thread_offsetof(mem) (long)(offsetof(struct pthread, mem) - sizeof(struct pthread)) |
| 14404 | |
| 14405 | MULTIPLE_THREADS_OFFSET thread_offsetof (header.multiple_threads) |
| 14406 | -PID_OFFSET thread_offsetof (pid) |
| 14407 | TID_OFFSET thread_offsetof (tid) |
| 14408 | diff --git a/sysdeps/arm/nacl/libc.abilist b/sysdeps/arm/nacl/libc.abilist |
| 14409 | index 2f7751d167..dfa7198306 100644 |
| 14410 | --- a/sysdeps/arm/nacl/libc.abilist |
| 14411 | +++ b/sysdeps/arm/nacl/libc.abilist |
| 14412 | @@ -1840,4 +1840,5 @@ GLIBC_2.23 fts64_close F |
| 14413 | GLIBC_2.23 fts64_open F |
| 14414 | GLIBC_2.23 fts64_read F |
| 14415 | GLIBC_2.23 fts64_set F |
| 14416 | +GLIBC_2.24 GLIBC_2.24 A |
| 14417 | GLIBC_2.24 quick_exit F |
| 14418 | diff --git a/sysdeps/arm/nptl/tcb-offsets.sym b/sysdeps/arm/nptl/tcb-offsets.sym |
| 14419 | index 92cc441d3d..bf9c0a1c17 100644 |
| 14420 | --- a/sysdeps/arm/nptl/tcb-offsets.sym |
| 14421 | +++ b/sysdeps/arm/nptl/tcb-offsets.sym |
| 14422 | @@ -7,5 +7,4 @@ |
| 14423 | #define thread_offsetof(mem) (long)(offsetof(struct pthread, mem) - sizeof(struct pthread)) |
| 14424 | |
| 14425 | MULTIPLE_THREADS_OFFSET thread_offsetof (header.multiple_threads) |
| 14426 | -PID_OFFSET thread_offsetof (pid) |
| 14427 | TID_OFFSET thread_offsetof (tid) |
| 14428 | diff --git a/sysdeps/generic/unsecvars.h b/sysdeps/generic/unsecvars.h |
| 14429 | index d5b8119c9c..ac57bd5db0 100644 |
| 14430 | --- a/sysdeps/generic/unsecvars.h |
| 14431 | +++ b/sysdeps/generic/unsecvars.h |
| 14432 | @@ -4,11 +4,13 @@ |
| 14433 | #define UNSECURE_ENVVARS \ |
| 14434 | "GCONV_PATH\0" \ |
| 14435 | "GETCONF_DIR\0" \ |
| 14436 | + "GLIBC_TUNABLES\0" \ |
| 14437 | "HOSTALIASES\0" \ |
| 14438 | "LD_AUDIT\0" \ |
| 14439 | "LD_DEBUG\0" \ |
| 14440 | "LD_DEBUG_OUTPUT\0" \ |
| 14441 | "LD_DYNAMIC_WEAK\0" \ |
| 14442 | + "LD_HWCAP_MASK\0" \ |
| 14443 | "LD_LIBRARY_PATH\0" \ |
| 14444 | "LD_ORIGIN_PATH\0" \ |
| 14445 | "LD_PRELOAD\0" \ |
| 14446 | diff --git a/sysdeps/gnu/glob64.c b/sysdeps/gnu/glob64.c |
| 14447 | index d1e4e6f0d5..52e97e2f6a 100644 |
| 14448 | --- a/sysdeps/gnu/glob64.c |
| 14449 | +++ b/sysdeps/gnu/glob64.c |
| 14450 | @@ -15,11 +15,8 @@ |
| 14451 | #undef __stat |
| 14452 | #define __stat(file, buf) __xstat64 (_STAT_VER, file, buf) |
| 14453 | |
| 14454 | -#define NO_GLOB_PATTERN_P 1 |
| 14455 | - |
| 14456 | #define COMPILE_GLOB64 1 |
| 14457 | |
| 14458 | #include <posix/glob.c> |
| 14459 | |
| 14460 | libc_hidden_def (glob64) |
| 14461 | -libc_hidden_def (globfree64) |
| 14462 | diff --git a/sysdeps/gnu/globfree64.c b/sysdeps/gnu/globfree64.c |
| 14463 | new file mode 100644 |
| 14464 | index 0000000000..f092d0bf8b |
| 14465 | --- /dev/null |
| 14466 | +++ b/sysdeps/gnu/globfree64.c |
| 14467 | @@ -0,0 +1,10 @@ |
| 14468 | +#include <dirent.h> |
| 14469 | +#include <glob.h> |
| 14470 | +#include <sys/stat.h> |
| 14471 | + |
| 14472 | +#define glob_t glob64_t |
| 14473 | +#define globfree(pglob) globfree64 (pglob) |
| 14474 | + |
| 14475 | +#include <posix/globfree.c> |
| 14476 | + |
| 14477 | +libc_hidden_def (globfree64) |
| 14478 | diff --git a/sysdeps/hppa/dl-machine.h b/sysdeps/hppa/dl-machine.h |
| 14479 | index 9404211819..01bd5bf197 100644 |
| 14480 | --- a/sysdeps/hppa/dl-machine.h |
| 14481 | +++ b/sysdeps/hppa/dl-machine.h |
| 14482 | @@ -302,6 +302,10 @@ elf_machine_runtime_setup (struct link_map *l, int lazy, int profile) |
| 14483 | #define ARCH_LA_PLTENTER hppa_gnu_pltenter |
| 14484 | #define ARCH_LA_PLTEXIT hppa_gnu_pltexit |
| 14485 | |
| 14486 | +/* Adjust DL_STACK_END to get value we want in __libc_stack_end. */ |
| 14487 | +#define DL_STACK_END(cookie) \ |
| 14488 | + ((void *) (((long) (cookie)) + 0x160)) |
| 14489 | + |
| 14490 | /* Initial entry point code for the dynamic linker. |
| 14491 | The C function `_dl_start' is the real entry point; |
| 14492 | its return value is the user program's entry point. */ |
| 14493 | @@ -401,11 +405,6 @@ asm ( \ |
| 14494 | /* Save the entry point in %r3. */ \ |
| 14495 | " copy %ret0,%r3\n" \ |
| 14496 | \ |
| 14497 | - /* Remember the lowest stack address. */ \ |
| 14498 | -" addil LT'__libc_stack_end,%r19\n" \ |
| 14499 | -" ldw RT'__libc_stack_end(%r1),%r20\n" \ |
| 14500 | -" stw %sp,0(%r20)\n" \ |
| 14501 | - \ |
| 14502 | /* See if we were called as a command with the executable file \ |
| 14503 | name as an extra leading argument. */ \ |
| 14504 | " addil LT'_dl_skip_args,%r19\n" \ |
| 14505 | diff --git a/sysdeps/hppa/nptl/tcb-offsets.sym b/sysdeps/hppa/nptl/tcb-offsets.sym |
| 14506 | index c2f326ee3d..6e852f35b1 100644 |
| 14507 | --- a/sysdeps/hppa/nptl/tcb-offsets.sym |
| 14508 | +++ b/sysdeps/hppa/nptl/tcb-offsets.sym |
| 14509 | @@ -3,7 +3,6 @@ |
| 14510 | |
| 14511 | RESULT offsetof (struct pthread, result) |
| 14512 | TID offsetof (struct pthread, tid) |
| 14513 | -PID offsetof (struct pthread, pid) |
| 14514 | CANCELHANDLING offsetof (struct pthread, cancelhandling) |
| 14515 | CLEANUP_JMP_BUF offsetof (struct pthread, cleanup_jmp_buf) |
| 14516 | MULTIPLE_THREADS_OFFSET offsetof (struct pthread, header.multiple_threads) |
| 14517 | @@ -14,6 +13,5 @@ MUTEX_FUTEX offsetof (pthread_mutex_t, __data.__lock) |
| 14518 | -- This way we get the offset of a member in the struct pthread that |
| 14519 | -- preceeds the thread pointer (which points to the dtv). |
| 14520 | #define thread_offsetof(mem) (unsigned int)(offsetof(struct pthread, mem) - sizeof(struct pthread)) |
| 14521 | -PID_THREAD_OFFSET thread_offsetof (pid) |
| 14522 | TID_THREAD_OFFSET thread_offsetof (tid) |
| 14523 | MULTIPLE_THREADS_THREAD_OFFSET thread_offsetof (header.multiple_threads) |
| 14524 | diff --git a/sysdeps/i386/i686/multiarch/strcspn-c.c b/sysdeps/i386/i686/multiarch/strcspn-c.c |
| 14525 | index 6d61e190a8..ec230fb383 100644 |
| 14526 | --- a/sysdeps/i386/i686/multiarch/strcspn-c.c |
| 14527 | +++ b/sysdeps/i386/i686/multiarch/strcspn-c.c |
| 14528 | @@ -1,2 +1,4 @@ |
| 14529 | -#define __strcspn_sse2 __strcspn_ia32 |
| 14530 | -#include <sysdeps/x86_64/multiarch/strcspn-c.c> |
| 14531 | +#if IS_IN (libc) |
| 14532 | +# define __strcspn_sse2 __strcspn_ia32 |
| 14533 | +# include <sysdeps/x86_64/multiarch/strcspn-c.c> |
| 14534 | +#endif |
| 14535 | diff --git a/sysdeps/i386/i686/multiarch/varshift.c b/sysdeps/i386/i686/multiarch/varshift.c |
| 14536 | index 7760b966e2..6742a35d41 100644 |
| 14537 | --- a/sysdeps/i386/i686/multiarch/varshift.c |
| 14538 | +++ b/sysdeps/i386/i686/multiarch/varshift.c |
| 14539 | @@ -1 +1,3 @@ |
| 14540 | -#include <sysdeps/x86_64/multiarch/varshift.c> |
| 14541 | +#if IS_IN (libc) |
| 14542 | +# include <sysdeps/x86_64/multiarch/varshift.c> |
| 14543 | +#endif |
| 14544 | diff --git a/sysdeps/i386/nptl/tcb-offsets.sym b/sysdeps/i386/nptl/tcb-offsets.sym |
| 14545 | index 7bdf161b29..695a810386 100644 |
| 14546 | --- a/sysdeps/i386/nptl/tcb-offsets.sym |
| 14547 | +++ b/sysdeps/i386/nptl/tcb-offsets.sym |
| 14548 | @@ -4,7 +4,6 @@ |
| 14549 | |
| 14550 | RESULT offsetof (struct pthread, result) |
| 14551 | TID offsetof (struct pthread, tid) |
| 14552 | -PID offsetof (struct pthread, pid) |
| 14553 | CANCELHANDLING offsetof (struct pthread, cancelhandling) |
| 14554 | CLEANUP_JMP_BUF offsetof (struct pthread, cleanup_jmp_buf) |
| 14555 | MULTIPLE_THREADS_OFFSET offsetof (tcbhead_t, multiple_threads) |
| 14556 | diff --git a/sysdeps/ia64/nptl/Makefile b/sysdeps/ia64/nptl/Makefile |
| 14557 | index 48f1327446..1e6be8eea8 100644 |
| 14558 | --- a/sysdeps/ia64/nptl/Makefile |
| 14559 | +++ b/sysdeps/ia64/nptl/Makefile |
| 14560 | @@ -21,4 +21,5 @@ endif |
| 14561 | |
| 14562 | ifeq ($(subdir),nptl) |
| 14563 | libpthread-routines += ptw-sysdep ptw-sigblock ptw-sigprocmask |
| 14564 | +libpthread-shared-only-routines += ptw-sysdep ptw-sigblock ptw-sigprocmask |
| 14565 | endif |
| 14566 | diff --git a/sysdeps/ia64/nptl/tcb-offsets.sym b/sysdeps/ia64/nptl/tcb-offsets.sym |
| 14567 | index e1707ab1c8..b01f712be2 100644 |
| 14568 | --- a/sysdeps/ia64/nptl/tcb-offsets.sym |
| 14569 | +++ b/sysdeps/ia64/nptl/tcb-offsets.sym |
| 14570 | @@ -1,7 +1,6 @@ |
| 14571 | #include <sysdep.h> |
| 14572 | #include <tls.h> |
| 14573 | |
| 14574 | -PID offsetof (struct pthread, pid) - TLS_PRE_TCB_SIZE |
| 14575 | TID offsetof (struct pthread, tid) - TLS_PRE_TCB_SIZE |
| 14576 | MULTIPLE_THREADS_OFFSET offsetof (struct pthread, header.multiple_threads) - TLS_PRE_TCB_SIZE |
| 14577 | SYSINFO_OFFSET offsetof (tcbhead_t, __private) |
| 14578 | diff --git a/sysdeps/ieee754/dbl-64/e_pow.c b/sysdeps/ieee754/dbl-64/e_pow.c |
| 14579 | index 663fa392c2..bd758b5979 100644 |
| 14580 | --- a/sysdeps/ieee754/dbl-64/e_pow.c |
| 14581 | +++ b/sysdeps/ieee754/dbl-64/e_pow.c |
| 14582 | @@ -466,15 +466,15 @@ checkint (double x) |
| 14583 | return (n & 1) ? -1 : 1; /* odd or even */ |
| 14584 | if (k > 20) |
| 14585 | { |
| 14586 | - if (n << (k - 20)) |
| 14587 | + if (n << (k - 20) != 0) |
| 14588 | return 0; /* if not integer */ |
| 14589 | - return (n << (k - 21)) ? -1 : 1; |
| 14590 | + return (n << (k - 21) != 0) ? -1 : 1; |
| 14591 | } |
| 14592 | if (n) |
| 14593 | return 0; /*if not integer */ |
| 14594 | if (k == 20) |
| 14595 | return (m & 1) ? -1 : 1; |
| 14596 | - if (m << (k + 12)) |
| 14597 | + if (m << (k + 12) != 0) |
| 14598 | return 0; |
| 14599 | - return (m << (k + 11)) ? -1 : 1; |
| 14600 | + return (m << (k + 11) != 0) ? -1 : 1; |
| 14601 | } |
| 14602 | diff --git a/sysdeps/m68k/m680x0/m68020/atomic-machine.h b/sysdeps/m68k/m680x0/m68020/atomic-machine.h |
| 14603 | index 24bc5c5ef7..65965cca9e 100644 |
| 14604 | --- a/sysdeps/m68k/m680x0/m68020/atomic-machine.h |
| 14605 | +++ b/sysdeps/m68k/m680x0/m68020/atomic-machine.h |
| 14606 | @@ -73,7 +73,7 @@ typedef uintmax_t uatomic_max_t; |
| 14607 | __typeof (mem) __memp = (mem); \ |
| 14608 | __asm __volatile ("cas2%.l %0:%R0,%1:%R1,(%2):(%3)" \ |
| 14609 | : "=d" (__ret) \ |
| 14610 | - : "d" (newval), "r" (__memp), \ |
| 14611 | + : "d" ((__typeof (*(mem))) (newval)), "r" (__memp), \ |
| 14612 | "r" ((char *) __memp + 4), "0" (oldval) \ |
| 14613 | : "memory"); \ |
| 14614 | __ret; }) |
| 14615 | @@ -101,8 +101,9 @@ typedef uintmax_t uatomic_max_t; |
| 14616 | __asm __volatile ("1: cas2%.l %0:%R0,%1:%R1,(%2):(%3);" \ |
| 14617 | " jbne 1b" \ |
| 14618 | : "=d" (__result) \ |
| 14619 | - : "d" (newvalue), "r" (__memp), \ |
| 14620 | - "r" ((char *) __memp + 4), "0" (__result) \ |
| 14621 | + : "d" ((__typeof (*(mem))) (newvalue)), \ |
| 14622 | + "r" (__memp), "r" ((char *) __memp + 4), \ |
| 14623 | + "0" (__result) \ |
| 14624 | : "memory"); \ |
| 14625 | } \ |
| 14626 | __result; }) |
| 14627 | @@ -144,7 +145,7 @@ typedef uintmax_t uatomic_max_t; |
| 14628 | " cas2%.l %0:%R0,%1:%R1,(%3):(%4);" \ |
| 14629 | " jbne 1b" \ |
| 14630 | : "=d" (__result), "=&d" (__temp) \ |
| 14631 | - : "d" (value), "r" (__memp), \ |
| 14632 | + : "d" ((__typeof (*(mem))) (value)), "r" (__memp), \ |
| 14633 | "r" ((char *) __memp + 4), "0" (__result) \ |
| 14634 | : "memory"); \ |
| 14635 | } \ |
| 14636 | @@ -175,8 +176,9 @@ typedef uintmax_t uatomic_max_t; |
| 14637 | " cas2%.l %0:%R0,%1:%R1,(%3):(%4);" \ |
| 14638 | " jbne 1b" \ |
| 14639 | : "=d" (__oldval), "=&d" (__temp) \ |
| 14640 | - : "d" (value), "r" (__memp), \ |
| 14641 | - "r" ((char *) __memp + 4), "0" (__oldval) \ |
| 14642 | + : "d" ((__typeof (*(mem))) (value)), \ |
| 14643 | + "r" (__memp), "r" ((char *) __memp + 4), \ |
| 14644 | + "0" (__oldval) \ |
| 14645 | : "memory"); \ |
| 14646 | } \ |
| 14647 | }) |
| 14648 | diff --git a/sysdeps/m68k/nptl/tcb-offsets.sym b/sysdeps/m68k/nptl/tcb-offsets.sym |
| 14649 | index b1bba65868..241fb8b47c 100644 |
| 14650 | --- a/sysdeps/m68k/nptl/tcb-offsets.sym |
| 14651 | +++ b/sysdeps/m68k/nptl/tcb-offsets.sym |
| 14652 | @@ -7,5 +7,4 @@ |
| 14653 | #define thread_offsetof(mem) (long)(offsetof(struct pthread, mem) - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE) |
| 14654 | |
| 14655 | MULTIPLE_THREADS_OFFSET thread_offsetof (header.multiple_threads) |
| 14656 | -PID_OFFSET thread_offsetof (pid) |
| 14657 | TID_OFFSET thread_offsetof (tid) |
| 14658 | diff --git a/sysdeps/microblaze/nptl/tcb-offsets.sym b/sysdeps/microblaze/nptl/tcb-offsets.sym |
| 14659 | index 18afbee291..614f0dfed6 100644 |
| 14660 | --- a/sysdeps/microblaze/nptl/tcb-offsets.sym |
| 14661 | +++ b/sysdeps/microblaze/nptl/tcb-offsets.sym |
| 14662 | @@ -7,5 +7,4 @@ |
| 14663 | #define thread_offsetof(mem) (long)(offsetof (struct pthread, mem) - sizeof (struct pthread)) |
| 14664 | |
| 14665 | MULTIPLE_THREADS_OFFSET thread_offsetof (header.multiple_threads) |
| 14666 | -PID_OFFSET thread_offsetof (pid) |
| 14667 | TID_OFFSET thread_offsetof (tid) |
| 14668 | diff --git a/sysdeps/mips/Makefile b/sysdeps/mips/Makefile |
| 14669 | index 3d3552322b..7c1d77941e 100644 |
| 14670 | --- a/sysdeps/mips/Makefile |
| 14671 | +++ b/sysdeps/mips/Makefile |
| 14672 | @@ -9,6 +9,7 @@ endif |
| 14673 | |
| 14674 | ifeq ($(subdir),rt) |
| 14675 | librt-sysdep_routines += rt-sysdep |
| 14676 | +librt-shared-only-routines += rt-sysdep |
| 14677 | endif |
| 14678 | |
| 14679 | ifeq ($(subdir),debug) |
| 14680 | diff --git a/sysdeps/mips/mips32/crti.S b/sysdeps/mips/mips32/crti.S |
| 14681 | index 5c0ad7328a..dfbbdc4f8f 100644 |
| 14682 | --- a/sysdeps/mips/mips32/crti.S |
| 14683 | +++ b/sysdeps/mips/mips32/crti.S |
| 14684 | @@ -74,6 +74,7 @@ _init: |
| 14685 | .reloc 1f,R_MIPS_JALR,PREINIT_FUNCTION |
| 14686 | 1: jalr $25 |
| 14687 | .Lno_weak_fn: |
| 14688 | + .insn |
| 14689 | #else |
| 14690 | lw $25,%got(PREINIT_FUNCTION)($28) |
| 14691 | .reloc 1f,R_MIPS_JALR,PREINIT_FUNCTION |
| 14692 | diff --git a/sysdeps/mips/mips64/n32/crti.S b/sysdeps/mips/mips64/n32/crti.S |
| 14693 | index 00b89f3894..afe6d8edaa 100644 |
| 14694 | --- a/sysdeps/mips/mips64/n32/crti.S |
| 14695 | +++ b/sysdeps/mips/mips64/n32/crti.S |
| 14696 | @@ -74,6 +74,7 @@ _init: |
| 14697 | .reloc 1f,R_MIPS_JALR,PREINIT_FUNCTION |
| 14698 | 1: jalr $25 |
| 14699 | .Lno_weak_fn: |
| 14700 | + .insn |
| 14701 | #else |
| 14702 | lw $25,%got_disp(PREINIT_FUNCTION)($28) |
| 14703 | .reloc 1f,R_MIPS_JALR,PREINIT_FUNCTION |
| 14704 | diff --git a/sysdeps/mips/mips64/n64/crti.S b/sysdeps/mips/mips64/n64/crti.S |
| 14705 | index f59b20c631..4049d29290 100644 |
| 14706 | --- a/sysdeps/mips/mips64/n64/crti.S |
| 14707 | +++ b/sysdeps/mips/mips64/n64/crti.S |
| 14708 | @@ -74,6 +74,7 @@ _init: |
| 14709 | .reloc 1f,R_MIPS_JALR,PREINIT_FUNCTION |
| 14710 | 1: jalr $25 |
| 14711 | .Lno_weak_fn: |
| 14712 | + .insn |
| 14713 | #else |
| 14714 | ld $25,%got_disp(PREINIT_FUNCTION)($28) |
| 14715 | .reloc 1f,R_MIPS_JALR,PREINIT_FUNCTION |
| 14716 | diff --git a/sysdeps/mips/nptl/Makefile b/sysdeps/mips/nptl/Makefile |
| 14717 | index 117744ffe2..dda154d842 100644 |
| 14718 | --- a/sysdeps/mips/nptl/Makefile |
| 14719 | +++ b/sysdeps/mips/nptl/Makefile |
| 14720 | @@ -21,4 +21,5 @@ endif |
| 14721 | |
| 14722 | ifeq ($(subdir),nptl) |
| 14723 | libpthread-sysdep_routines += nptl-sysdep |
| 14724 | +libpthread-shared-only-routines += nptl-sysdep |
| 14725 | endif |
| 14726 | diff --git a/sysdeps/mips/nptl/tcb-offsets.sym b/sysdeps/mips/nptl/tcb-offsets.sym |
| 14727 | index e0e71dc430..9ea25b94a8 100644 |
| 14728 | --- a/sysdeps/mips/nptl/tcb-offsets.sym |
| 14729 | +++ b/sysdeps/mips/nptl/tcb-offsets.sym |
| 14730 | @@ -7,5 +7,4 @@ |
| 14731 | #define thread_offsetof(mem) (long)(offsetof(struct pthread, mem) - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE) |
| 14732 | |
| 14733 | MULTIPLE_THREADS_OFFSET thread_offsetof (header.multiple_threads) |
| 14734 | -PID_OFFSET thread_offsetof (pid) |
| 14735 | TID_OFFSET thread_offsetof (tid) |
| 14736 | diff --git a/sysdeps/nacl/clock.c b/sysdeps/nacl/clock.c |
| 14737 | index 664ad650c3..b6fbcfd2dd 100644 |
| 14738 | --- a/sysdeps/nacl/clock.c |
| 14739 | +++ b/sysdeps/nacl/clock.c |
| 14740 | @@ -24,6 +24,6 @@ |
| 14741 | clock_t |
| 14742 | clock (void) |
| 14743 | { |
| 14744 | - nacl_abi_clock_t result; |
| 14745 | + nacl_irt_clock_t result; |
| 14746 | return NACL_CALL (__nacl_irt_basic.clock (&result), result); |
| 14747 | } |
| 14748 | diff --git a/sysdeps/nacl/dup.c b/sysdeps/nacl/dup.c |
| 14749 | index 34a7cd46d4..cbce3f5a5a 100644 |
| 14750 | --- a/sysdeps/nacl/dup.c |
| 14751 | +++ b/sysdeps/nacl/dup.c |
| 14752 | @@ -27,4 +27,5 @@ __dup (int fd) |
| 14753 | int result; |
| 14754 | return NACL_CALL (__nacl_irt_fdio.dup (fd, &result), result); |
| 14755 | } |
| 14756 | +libc_hidden_def (__dup) |
| 14757 | weak_alias (__dup, dup) |
| 14758 | diff --git a/sysdeps/nios2/nptl/tcb-offsets.sym b/sysdeps/nios2/nptl/tcb-offsets.sym |
| 14759 | index d9ae952585..3cd8d984ac 100644 |
| 14760 | --- a/sysdeps/nios2/nptl/tcb-offsets.sym |
| 14761 | +++ b/sysdeps/nios2/nptl/tcb-offsets.sym |
| 14762 | @@ -9,6 +9,5 @@ |
| 14763 | # define thread_offsetof(mem) ((ptrdiff_t) THREAD_SELF + offsetof (struct pthread, mem)) |
| 14764 | |
| 14765 | MULTIPLE_THREADS_OFFSET thread_offsetof (header.multiple_threads) |
| 14766 | -PID_OFFSET thread_offsetof (pid) |
| 14767 | TID_OFFSET thread_offsetof (tid) |
| 14768 | POINTER_GUARD (offsetof (tcbhead_t, pointer_guard) - TLS_TCB_OFFSET - sizeof (tcbhead_t)) |
| 14769 | diff --git a/sysdeps/nptl/fork.c b/sysdeps/nptl/fork.c |
| 14770 | index 616d897a36..a5d1e86d71 100644 |
| 14771 | --- a/sysdeps/nptl/fork.c |
| 14772 | +++ b/sysdeps/nptl/fork.c |
| 14773 | @@ -131,16 +131,6 @@ __libc_fork (void) |
| 14774 | __malloc_fork_lock_parent (); |
| 14775 | } |
| 14776 | |
| 14777 | -#ifndef NDEBUG |
| 14778 | - pid_t ppid = THREAD_GETMEM (THREAD_SELF, tid); |
| 14779 | -#endif |
| 14780 | - |
| 14781 | - /* We need to prevent the getpid() code to update the PID field so |
| 14782 | - that, if a signal arrives in the child very early and the signal |
| 14783 | - handler uses getpid(), the value returned is correct. */ |
| 14784 | - pid_t parentpid = THREAD_GETMEM (THREAD_SELF, pid); |
| 14785 | - THREAD_SETMEM (THREAD_SELF, pid, -parentpid); |
| 14786 | - |
| 14787 | #ifdef ARCH_FORK |
| 14788 | pid = ARCH_FORK (); |
| 14789 | #else |
| 14790 | @@ -153,15 +143,10 @@ __libc_fork (void) |
| 14791 | { |
| 14792 | struct pthread *self = THREAD_SELF; |
| 14793 | |
| 14794 | - assert (THREAD_GETMEM (self, tid) != ppid); |
| 14795 | - |
| 14796 | /* See __pthread_once. */ |
| 14797 | if (__fork_generation_pointer != NULL) |
| 14798 | *__fork_generation_pointer += __PTHREAD_ONCE_FORK_GEN_INCR; |
| 14799 | |
| 14800 | - /* Adjust the PID field for the new process. */ |
| 14801 | - THREAD_SETMEM (self, pid, THREAD_GETMEM (self, tid)); |
| 14802 | - |
| 14803 | #if HP_TIMING_AVAIL |
| 14804 | /* The CPU clock of the thread and process have to be set to zero. */ |
| 14805 | hp_timing_t now; |
| 14806 | @@ -231,11 +216,6 @@ __libc_fork (void) |
| 14807 | } |
| 14808 | else |
| 14809 | { |
| 14810 | - assert (THREAD_GETMEM (THREAD_SELF, tid) == ppid); |
| 14811 | - |
| 14812 | - /* Restore the PID value. */ |
| 14813 | - THREAD_SETMEM (THREAD_SELF, pid, parentpid); |
| 14814 | - |
| 14815 | /* Release acquired locks in the multi-threaded case. */ |
| 14816 | if (multiple_threads) |
| 14817 | { |
| 14818 | diff --git a/sysdeps/posix/wait3.c b/sysdeps/posix/wait3.c |
| 14819 | index cf43d973a7..73722d2be6 100644 |
| 14820 | --- a/sysdeps/posix/wait3.c |
| 14821 | +++ b/sysdeps/posix/wait3.c |
| 14822 | @@ -33,7 +33,7 @@ __wait3 (int *stat_loc, int options, struct rusage *usage) |
| 14823 | __set_errno (ENOSYS); |
| 14824 | return (pid_t) -1; |
| 14825 | } |
| 14826 | - return __waitpid (WAIT_ANY, stat_loc.__iptr, options); |
| 14827 | + return __waitpid (WAIT_ANY, stat_loc, options); |
| 14828 | } |
| 14829 | |
| 14830 | weak_alias (__wait3, wait3) |
| 14831 | diff --git a/sysdeps/powerpc/fpu/libm-test-ulps b/sysdeps/powerpc/fpu/libm-test-ulps |
| 14832 | index 7f37c813d0..36b700c520 100644 |
| 14833 | --- a/sysdeps/powerpc/fpu/libm-test-ulps |
| 14834 | +++ b/sysdeps/powerpc/fpu/libm-test-ulps |
| 14835 | @@ -36,8 +36,8 @@ double: 2 |
| 14836 | float: 2 |
| 14837 | idouble: 2 |
| 14838 | ifloat: 2 |
| 14839 | -ildouble: 1 |
| 14840 | -ldouble: 1 |
| 14841 | +ildouble: 2 |
| 14842 | +ldouble: 2 |
| 14843 | |
| 14844 | Function: "acosh_downward": |
| 14845 | double: 1 |
| 14846 | @@ -52,8 +52,8 @@ double: 2 |
| 14847 | float: 2 |
| 14848 | idouble: 2 |
| 14849 | ifloat: 2 |
| 14850 | -ildouble: 3 |
| 14851 | -ldouble: 3 |
| 14852 | +ildouble: 4 |
| 14853 | +ldouble: 4 |
| 14854 | |
| 14855 | Function: "acosh_upward": |
| 14856 | double: 2 |
| 14857 | @@ -122,8 +122,8 @@ double: 3 |
| 14858 | float: 3 |
| 14859 | idouble: 3 |
| 14860 | ifloat: 3 |
| 14861 | -ildouble: 4 |
| 14862 | -ldouble: 4 |
| 14863 | +ildouble: 7 |
| 14864 | +ldouble: 7 |
| 14865 | |
| 14866 | Function: "atan": |
| 14867 | double: 1 |
| 14868 | @@ -216,8 +216,8 @@ double: 3 |
| 14869 | float: 3 |
| 14870 | idouble: 3 |
| 14871 | ifloat: 3 |
| 14872 | -ildouble: 3 |
| 14873 | -ldouble: 3 |
| 14874 | +ildouble: 4 |
| 14875 | +ldouble: 4 |
| 14876 | |
| 14877 | Function: "cabs": |
| 14878 | double: 1 |
| 14879 | @@ -272,8 +272,8 @@ double: 5 |
| 14880 | float: 3 |
| 14881 | idouble: 5 |
| 14882 | ifloat: 3 |
| 14883 | -ildouble: 5 |
| 14884 | -ldouble: 5 |
| 14885 | +ildouble: 8 |
| 14886 | +ldouble: 8 |
| 14887 | |
| 14888 | Function: Real part of "cacos_towardzero": |
| 14889 | double: 2 |
| 14890 | @@ -288,8 +288,8 @@ double: 5 |
| 14891 | float: 3 |
| 14892 | idouble: 5 |
| 14893 | ifloat: 3 |
| 14894 | -ildouble: 5 |
| 14895 | -ldouble: 5 |
| 14896 | +ildouble: 8 |
| 14897 | +ldouble: 8 |
| 14898 | |
| 14899 | Function: Real part of "cacos_upward": |
| 14900 | double: 2 |
| 14901 | @@ -328,8 +328,8 @@ double: 5 |
| 14902 | float: 3 |
| 14903 | idouble: 5 |
| 14904 | ifloat: 3 |
| 14905 | -ildouble: 5 |
| 14906 | -ldouble: 5 |
| 14907 | +ildouble: 8 |
| 14908 | +ldouble: 8 |
| 14909 | |
| 14910 | Function: Imaginary part of "cacosh_downward": |
| 14911 | double: 2 |
| 14912 | @@ -344,8 +344,8 @@ double: 5 |
| 14913 | float: 3 |
| 14914 | idouble: 5 |
| 14915 | ifloat: 3 |
| 14916 | -ildouble: 5 |
| 14917 | -ldouble: 5 |
| 14918 | +ildouble: 8 |
| 14919 | +ldouble: 8 |
| 14920 | |
| 14921 | Function: Imaginary part of "cacosh_towardzero": |
| 14922 | double: 2 |
| 14923 | @@ -432,8 +432,8 @@ double: 5 |
| 14924 | float: 3 |
| 14925 | idouble: 5 |
| 14926 | ifloat: 3 |
| 14927 | -ildouble: 5 |
| 14928 | -ldouble: 5 |
| 14929 | +ildouble: 8 |
| 14930 | +ldouble: 8 |
| 14931 | |
| 14932 | Function: Real part of "casin_towardzero": |
| 14933 | double: 3 |
| 14934 | @@ -448,8 +448,8 @@ double: 5 |
| 14935 | float: 3 |
| 14936 | idouble: 5 |
| 14937 | ifloat: 3 |
| 14938 | -ildouble: 5 |
| 14939 | -ldouble: 5 |
| 14940 | +ildouble: 8 |
| 14941 | +ldouble: 8 |
| 14942 | |
| 14943 | Function: Real part of "casin_upward": |
| 14944 | double: 2 |
| 14945 | @@ -488,8 +488,8 @@ double: 5 |
| 14946 | float: 3 |
| 14947 | idouble: 5 |
| 14948 | ifloat: 3 |
| 14949 | -ildouble: 5 |
| 14950 | -ldouble: 5 |
| 14951 | +ildouble: 8 |
| 14952 | +ldouble: 8 |
| 14953 | |
| 14954 | Function: Imaginary part of "casinh_downward": |
| 14955 | double: 3 |
| 14956 | @@ -504,8 +504,8 @@ double: 5 |
| 14957 | float: 3 |
| 14958 | idouble: 5 |
| 14959 | ifloat: 3 |
| 14960 | -ildouble: 5 |
| 14961 | -ldouble: 5 |
| 14962 | +ildouble: 8 |
| 14963 | +ldouble: 8 |
| 14964 | |
| 14965 | Function: Imaginary part of "casinh_towardzero": |
| 14966 | double: 3 |
| 14967 | @@ -696,8 +696,8 @@ double: 1 |
| 14968 | float: 1 |
| 14969 | idouble: 1 |
| 14970 | ifloat: 1 |
| 14971 | -ildouble: 1 |
| 14972 | -ldouble: 1 |
| 14973 | +ildouble: 2 |
| 14974 | +ldouble: 2 |
| 14975 | |
| 14976 | Function: Real part of "ccos_downward": |
| 14977 | double: 1 |
| 14978 | @@ -1132,8 +1132,8 @@ double: 1 |
| 14979 | float: 1 |
| 14980 | idouble: 1 |
| 14981 | ifloat: 1 |
| 14982 | -ildouble: 1 |
| 14983 | -ldouble: 1 |
| 14984 | +ildouble: 2 |
| 14985 | +ldouble: 2 |
| 14986 | |
| 14987 | Function: Imaginary part of "csin": |
| 14988 | ildouble: 1 |
| 14989 | @@ -1198,8 +1198,8 @@ double: 1 |
| 14990 | float: 1 |
| 14991 | idouble: 1 |
| 14992 | ifloat: 1 |
| 14993 | -ildouble: 1 |
| 14994 | -ldouble: 1 |
| 14995 | +ildouble: 2 |
| 14996 | +ldouble: 2 |
| 14997 | |
| 14998 | Function: Real part of "csinh_downward": |
| 14999 | double: 2 |
| 15000 | @@ -1318,8 +1318,8 @@ double: 1 |
| 15001 | float: 1 |
| 15002 | idouble: 1 |
| 15003 | ifloat: 1 |
| 15004 | -ildouble: 2 |
| 15005 | -ldouble: 2 |
| 15006 | +ildouble: 3 |
| 15007 | +ldouble: 3 |
| 15008 | |
| 15009 | Function: Imaginary part of "ctan": |
| 15010 | double: 2 |
| 15011 | @@ -1390,8 +1390,8 @@ double: 2 |
| 15012 | float: 1 |
| 15013 | idouble: 2 |
| 15014 | ifloat: 1 |
| 15015 | -ildouble: 2 |
| 15016 | -ldouble: 2 |
| 15017 | +ildouble: 3 |
| 15018 | +ldouble: 3 |
| 15019 | |
| 15020 | Function: Real part of "ctanh_downward": |
| 15021 | double: 4 |
| 15022 | @@ -1478,8 +1478,8 @@ double: 2 |
| 15023 | float: 2 |
| 15024 | idouble: 2 |
| 15025 | ifloat: 2 |
| 15026 | -ildouble: 2 |
| 15027 | -ldouble: 2 |
| 15028 | +ildouble: 3 |
| 15029 | +ldouble: 3 |
| 15030 | |
| 15031 | Function: "erfc_downward": |
| 15032 | double: 3 |
| 15033 | @@ -1564,8 +1564,8 @@ double: 1 |
| 15034 | float: 1 |
| 15035 | idouble: 1 |
| 15036 | ifloat: 1 |
| 15037 | -ildouble: 1 |
| 15038 | -ldouble: 1 |
| 15039 | +ildouble: 2 |
| 15040 | +ldouble: 2 |
| 15041 | |
| 15042 | Function: "exp2_upward": |
| 15043 | double: 1 |
| 15044 | @@ -1588,8 +1588,8 @@ ildouble: 2 |
| 15045 | ldouble: 2 |
| 15046 | |
| 15047 | Function: "exp_upward": |
| 15048 | -float: 1 |
| 15049 | double: 1 |
| 15050 | +float: 1 |
| 15051 | idouble: 1 |
| 15052 | ifloat: 1 |
| 15053 | ildouble: 1 |
| 15054 | @@ -1624,8 +1624,8 @@ double: 1 |
| 15055 | float: 1 |
| 15056 | idouble: 1 |
| 15057 | ifloat: 1 |
| 15058 | -ildouble: 4 |
| 15059 | -ldouble: 4 |
| 15060 | +ildouble: 6 |
| 15061 | +ldouble: 6 |
| 15062 | |
| 15063 | Function: "fma": |
| 15064 | ildouble: 1 |
| 15065 | @@ -1688,8 +1688,8 @@ double: 4 |
| 15066 | float: 5 |
| 15067 | idouble: 4 |
| 15068 | ifloat: 5 |
| 15069 | -ildouble: 10 |
| 15070 | -ldouble: 10 |
| 15071 | +ildouble: 11 |
| 15072 | +ldouble: 11 |
| 15073 | |
| 15074 | Function: "hypot": |
| 15075 | double: 1 |
| 15076 | @@ -1752,8 +1752,8 @@ double: 1 |
| 15077 | float: 2 |
| 15078 | idouble: 1 |
| 15079 | ifloat: 2 |
| 15080 | -ildouble: 1 |
| 15081 | -ldouble: 1 |
| 15082 | +ildouble: 2 |
| 15083 | +ldouble: 2 |
| 15084 | |
| 15085 | Function: "j1_downward": |
| 15086 | double: 3 |
| 15087 | @@ -1840,8 +1840,8 @@ double: 4 |
| 15088 | float: 5 |
| 15089 | idouble: 4 |
| 15090 | ifloat: 5 |
| 15091 | -ildouble: 10 |
| 15092 | -ldouble: 10 |
| 15093 | +ildouble: 11 |
| 15094 | +ldouble: 11 |
| 15095 | |
| 15096 | Function: "log": |
| 15097 | float: 1 |
| 15098 | @@ -1910,8 +1910,8 @@ double: 2 |
| 15099 | float: 2 |
| 15100 | idouble: 2 |
| 15101 | ifloat: 2 |
| 15102 | -ildouble: 2 |
| 15103 | -ldouble: 2 |
| 15104 | +ildouble: 3 |
| 15105 | +ldouble: 3 |
| 15106 | |
| 15107 | Function: "log2": |
| 15108 | double: 1 |
| 15109 | @@ -2184,16 +2184,16 @@ double: 3 |
| 15110 | float: 3 |
| 15111 | idouble: 3 |
| 15112 | ifloat: 3 |
| 15113 | -ildouble: 3 |
| 15114 | -ldouble: 3 |
| 15115 | +ildouble: 4 |
| 15116 | +ldouble: 4 |
| 15117 | |
| 15118 | Function: "tanh_towardzero": |
| 15119 | double: 2 |
| 15120 | float: 2 |
| 15121 | idouble: 2 |
| 15122 | ifloat: 2 |
| 15123 | -ildouble: 3 |
| 15124 | -ldouble: 3 |
| 15125 | +ildouble: 4 |
| 15126 | +ldouble: 4 |
| 15127 | |
| 15128 | Function: "tanh_upward": |
| 15129 | double: 3 |
| 15130 | diff --git a/sysdeps/powerpc/ifunc-sel.h b/sysdeps/powerpc/ifunc-sel.h |
| 15131 | index 526d8ed88b..ac589bd3c0 100644 |
| 15132 | --- a/sysdeps/powerpc/ifunc-sel.h |
| 15133 | +++ b/sysdeps/powerpc/ifunc-sel.h |
| 15134 | @@ -17,15 +17,17 @@ ifunc_sel (int (*f1) (void), int (*f2) (void), int (*f3) (void)) |
| 15135 | "addis %0,11,%2-1b@ha\n\t" |
| 15136 | "addi %0,%0,%2-1b@l\n\t" |
| 15137 | "cmpwi 12,1\n\t" |
| 15138 | - "beqlr\n\t" |
| 15139 | + "beq 2f\n\t" |
| 15140 | "addis %0,11,%3-1b@ha\n\t" |
| 15141 | "addi %0,%0,%3-1b@l\n\t" |
| 15142 | "cmpwi 12,-1\n\t" |
| 15143 | - "beqlr\n\t" |
| 15144 | + "beq 2f\n\t" |
| 15145 | "addis %0,11,%4-1b@ha\n\t" |
| 15146 | - "addi %0,%0,%4-1b@l" |
| 15147 | + "addi %0,%0,%4-1b@l\n\t" |
| 15148 | + "2:" |
| 15149 | : "=r" (ret) |
| 15150 | - : "X" (&global), "X" (f1), "X" (f2), "X" (f3)); |
| 15151 | + : "i" (&global), "i" (f1), "i" (f2), "i" (f3) |
| 15152 | + : "11", "12", "cr0"); |
| 15153 | return ret; |
| 15154 | } |
| 15155 | |
| 15156 | @@ -40,7 +42,8 @@ ifunc_one (int (*f1) (void)) |
| 15157 | "addis %0,%0,%1-1b@ha\n\t" |
| 15158 | "addi %0,%0,%1-1b@l" |
| 15159 | : "=r" (ret) |
| 15160 | - : "X" (f1)); |
| 15161 | + : "i" (f1) |
| 15162 | + : "12"); |
| 15163 | return ret; |
| 15164 | } |
| 15165 | #endif |
| 15166 | diff --git a/sysdeps/powerpc/nptl/tcb-offsets.sym b/sysdeps/powerpc/nptl/tcb-offsets.sym |
| 15167 | index f580e69555..7c9fd33562 100644 |
| 15168 | --- a/sysdeps/powerpc/nptl/tcb-offsets.sym |
| 15169 | +++ b/sysdeps/powerpc/nptl/tcb-offsets.sym |
| 15170 | @@ -13,7 +13,6 @@ |
| 15171 | #if TLS_MULTIPLE_THREADS_IN_TCB |
| 15172 | MULTIPLE_THREADS_OFFSET thread_offsetof (header.multiple_threads) |
| 15173 | #endif |
| 15174 | -PID thread_offsetof (pid) |
| 15175 | TID thread_offsetof (tid) |
| 15176 | POINTER_GUARD (offsetof (tcbhead_t, pointer_guard) - TLS_TCB_OFFSET - sizeof (tcbhead_t)) |
| 15177 | TAR_SAVE (offsetof (tcbhead_t, tar_save) - TLS_TCB_OFFSET - sizeof (tcbhead_t)) |
| 15178 | diff --git a/sysdeps/powerpc/powerpc32/power6/memset.S b/sysdeps/powerpc/powerpc32/power6/memset.S |
| 15179 | index b2a222edd2..d5dbe83af2 100644 |
| 15180 | --- a/sysdeps/powerpc/powerpc32/power6/memset.S |
| 15181 | +++ b/sysdeps/powerpc/powerpc32/power6/memset.S |
| 15182 | @@ -394,7 +394,7 @@ L(cacheAlignedx): |
| 15183 | /* A simple loop for the longer (>640 bytes) lengths. This form limits |
| 15184 | the branch miss-predicted to exactly 1 at loop exit.*/ |
| 15185 | L(cacheAligned512): |
| 15186 | - cmpli cr1,rLEN,128 |
| 15187 | + cmplwi cr1,rLEN,128 |
| 15188 | blt cr1,L(cacheAligned1) |
| 15189 | dcbz 0,rMEMP |
| 15190 | addi rLEN,rLEN,-128 |
| 15191 | diff --git a/sysdeps/powerpc/powerpc32/power9/multiarch/Implies b/sysdeps/powerpc/powerpc32/power9/multiarch/Implies |
| 15192 | index 4393b56872..1a46ef0035 100644 |
| 15193 | --- a/sysdeps/powerpc/powerpc32/power9/multiarch/Implies |
| 15194 | +++ b/sysdeps/powerpc/powerpc32/power9/multiarch/Implies |
| 15195 | @@ -1 +1 @@ |
| 15196 | -powerpc/powerpc32/power8/fpu/multiarch |
| 15197 | +powerpc/powerpc32/power8/multiarch |
| 15198 | diff --git a/sysdeps/powerpc/powerpc64/power6/memset.S b/sysdeps/powerpc/powerpc64/power6/memset.S |
| 15199 | index c2d1c4e600..d445b1e1ef 100644 |
| 15200 | --- a/sysdeps/powerpc/powerpc64/power6/memset.S |
| 15201 | +++ b/sysdeps/powerpc/powerpc64/power6/memset.S |
| 15202 | @@ -251,7 +251,7 @@ L(cacheAlignedx): |
| 15203 | /* A simple loop for the longer (>640 bytes) lengths. This form limits |
| 15204 | the branch miss-predicted to exactly 1 at loop exit.*/ |
| 15205 | L(cacheAligned512): |
| 15206 | - cmpli cr1,rLEN,128 |
| 15207 | + cmpldi cr1,rLEN,128 |
| 15208 | blt cr1,L(cacheAligned1) |
| 15209 | dcbz 0,rMEMP |
| 15210 | addi rLEN,rLEN,-128 |
| 15211 | diff --git a/sysdeps/powerpc/powerpc64/power9/fpu/Implies b/sysdeps/powerpc/powerpc64/power9/fpu/Implies |
| 15212 | index fad2505ab9..ae0dbaf857 100644 |
| 15213 | --- a/sysdeps/powerpc/powerpc64/power9/fpu/Implies |
| 15214 | +++ b/sysdeps/powerpc/powerpc64/power9/fpu/Implies |
| 15215 | @@ -1,2 +1 @@ |
| 15216 | powerpc/powerpc64/power8/fpu |
| 15217 | -powerpc/powerpc64/power8 |
| 15218 | diff --git a/sysdeps/s390/nptl/Makefile b/sysdeps/s390/nptl/Makefile |
| 15219 | index 5734b983b0..3a391c8217 100644 |
| 15220 | --- a/sysdeps/s390/nptl/Makefile |
| 15221 | +++ b/sysdeps/s390/nptl/Makefile |
| 15222 | @@ -21,4 +21,5 @@ endif |
| 15223 | |
| 15224 | ifeq ($(subdir),nptl) |
| 15225 | libpthread-routines += ptw-sysdep |
| 15226 | +libpthread-shared-only-routines += ptw-sysdep |
| 15227 | endif |
| 15228 | diff --git a/sysdeps/s390/nptl/tcb-offsets.sym b/sysdeps/s390/nptl/tcb-offsets.sym |
| 15229 | index 9cfae211e0..9c1c01f353 100644 |
| 15230 | --- a/sysdeps/s390/nptl/tcb-offsets.sym |
| 15231 | +++ b/sysdeps/s390/nptl/tcb-offsets.sym |
| 15232 | @@ -3,5 +3,4 @@ |
| 15233 | |
| 15234 | MULTIPLE_THREADS_OFFSET offsetof (tcbhead_t, multiple_threads) |
| 15235 | STACK_GUARD offsetof (tcbhead_t, stack_guard) |
| 15236 | -PID offsetof (struct pthread, pid) |
| 15237 | TID offsetof (struct pthread, tid) |
| 15238 | diff --git a/sysdeps/sh/nptl/tcb-offsets.sym b/sysdeps/sh/nptl/tcb-offsets.sym |
| 15239 | index ac63b5b93b..4963e1506f 100644 |
| 15240 | --- a/sysdeps/sh/nptl/tcb-offsets.sym |
| 15241 | +++ b/sysdeps/sh/nptl/tcb-offsets.sym |
| 15242 | @@ -4,7 +4,6 @@ |
| 15243 | |
| 15244 | RESULT offsetof (struct pthread, result) |
| 15245 | TID offsetof (struct pthread, tid) |
| 15246 | -PID offsetof (struct pthread, pid) |
| 15247 | CANCELHANDLING offsetof (struct pthread, cancelhandling) |
| 15248 | CLEANUP_JMP_BUF offsetof (struct pthread, cleanup_jmp_buf) |
| 15249 | MULTIPLE_THREADS_OFFSET offsetof (struct pthread, header.multiple_threads) |
| 15250 | diff --git a/sysdeps/sparc/nptl/tcb-offsets.sym b/sysdeps/sparc/nptl/tcb-offsets.sym |
| 15251 | index 923af8a5b7..f75d02065e 100644 |
| 15252 | --- a/sysdeps/sparc/nptl/tcb-offsets.sym |
| 15253 | +++ b/sysdeps/sparc/nptl/tcb-offsets.sym |
| 15254 | @@ -3,5 +3,4 @@ |
| 15255 | |
| 15256 | MULTIPLE_THREADS_OFFSET offsetof (tcbhead_t, multiple_threads) |
| 15257 | POINTER_GUARD offsetof (tcbhead_t, pointer_guard) |
| 15258 | -PID offsetof (struct pthread, pid) |
| 15259 | TID offsetof (struct pthread, tid) |
| 15260 | diff --git a/sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/Makefile b/sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/Makefile |
| 15261 | index ebbe28b07f..13d3c6db51 100644 |
| 15262 | --- a/sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/Makefile |
| 15263 | +++ b/sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/Makefile |
| 15264 | @@ -4,8 +4,8 @@ libm-sysdep_routines += m_copysignf-vis3 m_copysign-vis3 s_fabs-vis3 \ |
| 15265 | s_fabsf-vis3 s_llrintf-vis3 s_llrint-vis3 \ |
| 15266 | s_rintf-vis3 s_rint-vis3 w_sqrt-vis3 w_sqrtf-vis3 \ |
| 15267 | s_fminf-vis3 s_fmin-vis3 s_fmaxf-vis3 s_fmax-vis3 \ |
| 15268 | - s_fmaf-vis3 s_fma-vis3 s_fdimf-vis3 s_fdim-vis3 \ |
| 15269 | - s_nearbyint-vis3 s_nearbyintf-vis3 |
| 15270 | + s_fmaf-vis3 s_fma-vis3 s_nearbyint-vis3 \ |
| 15271 | + s_nearbyintf-vis3 |
| 15272 | sysdep_routines += s_copysignf-vis3 s_copysign-vis3 |
| 15273 | endif |
| 15274 | endif |
| 15275 | diff --git a/sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_fdim.S b/sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_fdim.S |
| 15276 | deleted file mode 100644 |
| 15277 | index 4b13408244..0000000000 |
| 15278 | --- a/sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_fdim.S |
| 15279 | +++ /dev/null |
| 15280 | @@ -1,19 +0,0 @@ |
| 15281 | -#include <sparc-ifunc.h> |
| 15282 | -#include <math_ldbl_opt.h> |
| 15283 | - |
| 15284 | -SPARC_ASM_VIS3_IFUNC(fdim) |
| 15285 | - |
| 15286 | -weak_alias (__fdim, fdim) |
| 15287 | - |
| 15288 | -#if LONG_DOUBLE_COMPAT(libm, GLIBC_2_1) |
| 15289 | -compat_symbol (libm, __fdim, fdiml, GLIBC_2_1); |
| 15290 | -#endif |
| 15291 | - |
| 15292 | -# undef weak_alias |
| 15293 | -# define weak_alias(a, b) |
| 15294 | -# undef compat_symbol |
| 15295 | -# define compat_symbol(a, b, c, d) |
| 15296 | - |
| 15297 | -#define __fdim __fdim_generic |
| 15298 | - |
| 15299 | -#include "../s_fdim.S" |
| 15300 | diff --git a/sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_fdimf.S b/sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_fdimf.S |
| 15301 | deleted file mode 100644 |
| 15302 | index 30381d6a59..0000000000 |
| 15303 | --- a/sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_fdimf.S |
| 15304 | +++ /dev/null |
| 15305 | @@ -1,12 +0,0 @@ |
| 15306 | -#include <sparc-ifunc.h> |
| 15307 | - |
| 15308 | -SPARC_ASM_VIS3_IFUNC(fdimf) |
| 15309 | - |
| 15310 | -weak_alias (__fdimf, fdimf) |
| 15311 | - |
| 15312 | -# undef weak_alias |
| 15313 | -# define weak_alias(a, b) |
| 15314 | - |
| 15315 | -#define __fdimf __fdimf_generic |
| 15316 | - |
| 15317 | -#include "../s_fdimf.S" |
| 15318 | diff --git a/sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_nearbyint-vis3.S b/sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_nearbyint-vis3.S |
| 15319 | index d9ff0cc288..ff81b0da83 100644 |
| 15320 | --- a/sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_nearbyint-vis3.S |
| 15321 | +++ b/sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_nearbyint-vis3.S |
| 15322 | @@ -36,15 +36,15 @@ |
| 15323 | #define SIGN_BIT %f12 /* -0.0 */ |
| 15324 | |
| 15325 | ENTRY (__nearbyint_vis3) |
| 15326 | + sllx %o0, 32, %o0 |
| 15327 | + or %o0, %o1, %o0 |
| 15328 | + movxtod %o0, %f0 |
| 15329 | fcmpd %fcc3, %f0, %f0 /* Check for sNaN */ |
| 15330 | st %fsr, [%sp + 88] |
| 15331 | sethi %hi(TWO_FIFTYTWO), %o2 |
| 15332 | sethi %hi(0xf8003e0), %o5 |
| 15333 | ld [%sp + 88], %o4 |
| 15334 | - sllx %o0, 32, %o0 |
| 15335 | or %o5, %lo(0xf8003e0), %o5 |
| 15336 | - or %o0, %o1, %o0 |
| 15337 | - movxtod %o0, %f0 |
| 15338 | andn %o4, %o5, %o4 |
| 15339 | fzero ZERO |
| 15340 | st %o4, [%sp + 80] |
| 15341 | diff --git a/sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_nearbyintf-vis3.S b/sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_nearbyintf-vis3.S |
| 15342 | index 5cd1eb02db..833a0dfc24 100644 |
| 15343 | --- a/sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_nearbyintf-vis3.S |
| 15344 | +++ b/sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_nearbyintf-vis3.S |
| 15345 | @@ -35,9 +35,9 @@ |
| 15346 | #define SIGN_BIT %f12 /* -0.0 */ |
| 15347 | |
| 15348 | ENTRY (__nearbyintf_vis3) |
| 15349 | + movwtos %o0, %f1 |
| 15350 | fcmps %fcc3, %f1, %f1 /* Check for sNaN */ |
| 15351 | st %fsr, [%sp + 88] |
| 15352 | - movwtos %o0, %f1 |
| 15353 | sethi %hi(TWO_TWENTYTHREE), %o2 |
| 15354 | sethi %hi(0xf8003e0), %o5 |
| 15355 | ld [%sp + 88], %o4 |
| 15356 | diff --git a/sysdeps/sparc/sparc32/sparcv9/fpu/s_nearbyint.S b/sysdeps/sparc/sparc32/sparcv9/fpu/s_nearbyint.S |
| 15357 | index 84a10971a4..198440a5bc 100644 |
| 15358 | --- a/sysdeps/sparc/sparc32/sparcv9/fpu/s_nearbyint.S |
| 15359 | +++ b/sysdeps/sparc/sparc32/sparcv9/fpu/s_nearbyint.S |
| 15360 | @@ -36,21 +36,21 @@ |
| 15361 | #define SIGN_BIT %f12 /* -0.0 */ |
| 15362 | |
| 15363 | ENTRY (__nearbyint) |
| 15364 | + sllx %o0, 32, %o0 |
| 15365 | + or %o0, %o1, %o0 |
| 15366 | + stx %o0, [%sp + 72] |
| 15367 | + ldd [%sp + 72], %f0 |
| 15368 | fcmpd %fcc3, %f0, %f0 /* Check for sNaN */ |
| 15369 | st %fsr, [%sp + 88] |
| 15370 | sethi %hi(TWO_FIFTYTWO), %o2 |
| 15371 | sethi %hi(0xf8003e0), %o5 |
| 15372 | ld [%sp + 88], %o4 |
| 15373 | - sllx %o0, 32, %o0 |
| 15374 | or %o5, %lo(0xf8003e0), %o5 |
| 15375 | - or %o0, %o1, %o0 |
| 15376 | andn %o4, %o5, %o4 |
| 15377 | fzero ZERO |
| 15378 | st %o4, [%sp + 80] |
| 15379 | - stx %o0, [%sp + 72] |
| 15380 | sllx %o2, 32, %o2 |
| 15381 | fnegd ZERO, SIGN_BIT |
| 15382 | - ldd [%sp + 72], %f0 |
| 15383 | ld [%sp + 80], %fsr |
| 15384 | stx %o2, [%sp + 72] |
| 15385 | fabsd %f0, %f14 |
| 15386 | diff --git a/sysdeps/sparc/sparc32/sparcv9/fpu/s_nearbyintf.S b/sysdeps/sparc/sparc32/sparcv9/fpu/s_nearbyintf.S |
| 15387 | index d5cf5ce815..9be41f6c22 100644 |
| 15388 | --- a/sysdeps/sparc/sparc32/sparcv9/fpu/s_nearbyintf.S |
| 15389 | +++ b/sysdeps/sparc/sparc32/sparcv9/fpu/s_nearbyintf.S |
| 15390 | @@ -35,9 +35,10 @@ |
| 15391 | #define SIGN_BIT %f12 /* -0.0 */ |
| 15392 | |
| 15393 | ENTRY (__nearbyintf) |
| 15394 | + st %o0, [%sp + 68] |
| 15395 | + ld [%sp + 68], %f1 |
| 15396 | fcmps %fcc3, %f1, %f1 /* Check for sNaN */ |
| 15397 | st %fsr, [%sp + 88] |
| 15398 | - st %o0, [%sp + 68] |
| 15399 | sethi %hi(TWO_TWENTYTHREE), %o2 |
| 15400 | sethi %hi(0xf8003e0), %o5 |
| 15401 | ld [%sp + 88], %o4 |
| 15402 | @@ -46,7 +47,6 @@ ENTRY (__nearbyintf) |
| 15403 | fnegs ZERO, SIGN_BIT |
| 15404 | andn %o4, %o5, %o4 |
| 15405 | st %o4, [%sp + 80] |
| 15406 | - ld [%sp + 68], %f1 |
| 15407 | ld [%sp + 80], %fsr |
| 15408 | st %o2, [%sp + 68] |
| 15409 | fabss %f1, %f14 |
| 15410 | diff --git a/sysdeps/tile/nptl/tcb-offsets.sym b/sysdeps/tile/nptl/tcb-offsets.sym |
| 15411 | index 6740bc976f..0147ffafb7 100644 |
| 15412 | --- a/sysdeps/tile/nptl/tcb-offsets.sym |
| 15413 | +++ b/sysdeps/tile/nptl/tcb-offsets.sym |
| 15414 | @@ -9,7 +9,6 @@ |
| 15415 | #define thread_offsetof(mem) (long)(offsetof(struct pthread, mem) - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE) |
| 15416 | |
| 15417 | MULTIPLE_THREADS_OFFSET thread_offsetof (header.multiple_threads) |
| 15418 | -PID_OFFSET thread_offsetof (pid) |
| 15419 | TID_OFFSET thread_offsetof (tid) |
| 15420 | POINTER_GUARD (offsetof (tcbhead_t, pointer_guard) - TLS_TCB_OFFSET - sizeof (tcbhead_t)) |
| 15421 | FEEDBACK_DATA_OFFSET (offsetof (tcbhead_t, feedback_data) - TLS_TCB_OFFSET - sizeof (tcbhead_t)) |
| 15422 | diff --git a/sysdeps/unix/alpha/Makefile b/sysdeps/unix/alpha/Makefile |
| 15423 | index 441aa02a83..0660847f15 100644 |
| 15424 | --- a/sysdeps/unix/alpha/Makefile |
| 15425 | +++ b/sysdeps/unix/alpha/Makefile |
| 15426 | @@ -1,3 +1,4 @@ |
| 15427 | ifeq ($(subdir),rt) |
| 15428 | librt-sysdep_routines += rt-sysdep |
| 15429 | +librt-shared-only-routines += rt-sysdep |
| 15430 | endif |
| 15431 | diff --git a/sysdeps/unix/sysdep.h b/sysdeps/unix/sysdep.h |
| 15432 | index 94a2ce0e37..38c2432002 100644 |
| 15433 | --- a/sysdeps/unix/sysdep.h |
| 15434 | +++ b/sysdeps/unix/sysdep.h |
| 15435 | @@ -24,42 +24,79 @@ |
| 15436 | #define SYSCALL__(name, args) PSEUDO (__##name, name, args) |
| 15437 | #define SYSCALL(name, args) PSEUDO (name, name, args) |
| 15438 | |
| 15439 | -#define __SYSCALL0(name) \ |
| 15440 | +#define __SYSCALL_CONCAT_X(a,b) a##b |
| 15441 | +#define __SYSCALL_CONCAT(a,b) __SYSCALL_CONCAT_X (a, b) |
| 15442 | + |
| 15443 | + |
| 15444 | +#define __INTERNAL_SYSCALL0(name, err) \ |
| 15445 | + INTERNAL_SYSCALL (name, err, 0) |
| 15446 | +#define __INTERNAL_SYSCALL1(name, err, a1) \ |
| 15447 | + INTERNAL_SYSCALL (name, err, 1, a1) |
| 15448 | +#define __INTERNAL_SYSCALL2(name, err, a1, a2) \ |
| 15449 | + INTERNAL_SYSCALL (name, err, 2, a1, a2) |
| 15450 | +#define __INTERNAL_SYSCALL3(name, err, a1, a2, a3) \ |
| 15451 | + INTERNAL_SYSCALL (name, err, 3, a1, a2, a3) |
| 15452 | +#define __INTERNAL_SYSCALL4(name, err, a1, a2, a3, a4) \ |
| 15453 | + INTERNAL_SYSCALL (name, err, 4, a1, a2, a3, a4) |
| 15454 | +#define __INTERNAL_SYSCALL5(name, err, a1, a2, a3, a4, a5) \ |
| 15455 | + INTERNAL_SYSCALL (name, err, 5, a1, a2, a3, a4, a5) |
| 15456 | +#define __INTERNAL_SYSCALL6(name, err, a1, a2, a3, a4, a5, a6) \ |
| 15457 | + INTERNAL_SYSCALL (name, err, 6, a1, a2, a3, a4, a5, a6) |
| 15458 | +#define __INTERNAL_SYSCALL7(name, err, a1, a2, a3, a4, a5, a6, a7) \ |
| 15459 | + INTERNAL_SYSCALL (name, err, 7, a1, a2, a3, a4, a5, a6, a7) |
| 15460 | + |
| 15461 | +#define __INTERNAL_SYSCALL_NARGS_X(a,b,c,d,e,f,g,h,n,o,...) o |
| 15462 | +#define __INTERNAL_SYSCALL_NARGS(...) \ |
| 15463 | + __INTERNAL_SYSCALL_NARGS_X (__VA_ARGS__,7,6,5,4,3,2,1,0,) |
| 15464 | +#define __INTERNAL_SYSCALL_DISP(b,...) \ |
| 15465 | + __SYSCALL_CONCAT (b,__INTERNAL_SYSCALL_NARGS(__VA_ARGS__))(__VA_ARGS__) |
| 15466 | + |
| 15467 | +/* Issue a syscall defined by syscall number plus any other argument required. |
| 15468 | + It is similar to INTERNAL_SYSCALL macro, but without the need to pass the |
| 15469 | + expected argument number as second parameter. */ |
| 15470 | +#define INTERNAL_SYSCALL_CALL(...) \ |
| 15471 | + __INTERNAL_SYSCALL_DISP (__INTERNAL_SYSCALL, __VA_ARGS__) |
| 15472 | + |
| 15473 | +#define __INLINE_SYSCALL0(name) \ |
| 15474 | INLINE_SYSCALL (name, 0) |
| 15475 | -#define __SYSCALL1(name, a1) \ |
| 15476 | +#define __INLINE_SYSCALL1(name, a1) \ |
| 15477 | INLINE_SYSCALL (name, 1, a1) |
| 15478 | -#define __SYSCALL2(name, a1, a2) \ |
| 15479 | +#define __INLINE_SYSCALL2(name, a1, a2) \ |
| 15480 | INLINE_SYSCALL (name, 2, a1, a2) |
| 15481 | -#define __SYSCALL3(name, a1, a2, a3) \ |
| 15482 | +#define __INLINE_SYSCALL3(name, a1, a2, a3) \ |
| 15483 | INLINE_SYSCALL (name, 3, a1, a2, a3) |
| 15484 | -#define __SYSCALL4(name, a1, a2, a3, a4) \ |
| 15485 | +#define __INLINE_SYSCALL4(name, a1, a2, a3, a4) \ |
| 15486 | INLINE_SYSCALL (name, 4, a1, a2, a3, a4) |
| 15487 | -#define __SYSCALL5(name, a1, a2, a3, a4, a5) \ |
| 15488 | +#define __INLINE_SYSCALL5(name, a1, a2, a3, a4, a5) \ |
| 15489 | INLINE_SYSCALL (name, 5, a1, a2, a3, a4, a5) |
| 15490 | -#define __SYSCALL6(name, a1, a2, a3, a4, a5, a6) \ |
| 15491 | +#define __INLINE_SYSCALL6(name, a1, a2, a3, a4, a5, a6) \ |
| 15492 | INLINE_SYSCALL (name, 6, a1, a2, a3, a4, a5, a6) |
| 15493 | -#define __SYSCALL7(name, a1, a2, a3, a4, a5, a6, a7) \ |
| 15494 | +#define __INLINE_SYSCALL7(name, a1, a2, a3, a4, a5, a6, a7) \ |
| 15495 | INLINE_SYSCALL (name, 7, a1, a2, a3, a4, a5, a6, a7) |
| 15496 | |
| 15497 | -#define __SYSCALL_NARGS_X(a,b,c,d,e,f,g,h,n,...) n |
| 15498 | -#define __SYSCALL_NARGS(...) \ |
| 15499 | - __SYSCALL_NARGS_X (__VA_ARGS__,7,6,5,4,3,2,1,0,) |
| 15500 | -#define __SYSCALL_CONCAT_X(a,b) a##b |
| 15501 | -#define __SYSCALL_CONCAT(a,b) __SYSCALL_CONCAT_X (a, b) |
| 15502 | -#define __SYSCALL_DISP(b,...) \ |
| 15503 | - __SYSCALL_CONCAT (b,__SYSCALL_NARGS(__VA_ARGS__))(__VA_ARGS__) |
| 15504 | +#define __INLINE_SYSCALL_NARGS_X(a,b,c,d,e,f,g,h,n,...) n |
| 15505 | +#define __INLINE_SYSCALL_NARGS(...) \ |
| 15506 | + __INLINE_SYSCALL_NARGS_X (__VA_ARGS__,7,6,5,4,3,2,1,0,) |
| 15507 | +#define __INLINE_SYSCALL_DISP(b,...) \ |
| 15508 | + __SYSCALL_CONCAT (b,__INLINE_SYSCALL_NARGS(__VA_ARGS__))(__VA_ARGS__) |
| 15509 | |
| 15510 | -#define __SYSCALL_CALL(...) __SYSCALL_DISP (__SYSCALL, __VA_ARGS__) |
| 15511 | +/* Issue a syscall defined by syscall number plus any other argument |
| 15512 | + required. Any error will be handled using arch defined macros and errno |
| 15513 | + will be set accordingly. |
| 15514 | + It is similar to INLINE_SYSCALL macro, but without the need to pass the |
| 15515 | + expected argument number as second parameter. */ |
| 15516 | +#define INLINE_SYSCALL_CALL(...) \ |
| 15517 | + __INLINE_SYSCALL_DISP (__INLINE_SYSCALL, __VA_ARGS__) |
| 15518 | |
| 15519 | #define SYSCALL_CANCEL(...) \ |
| 15520 | ({ \ |
| 15521 | long int sc_ret; \ |
| 15522 | if (SINGLE_THREAD_P) \ |
| 15523 | - sc_ret = __SYSCALL_CALL (__VA_ARGS__); \ |
| 15524 | + sc_ret = INLINE_SYSCALL_CALL (__VA_ARGS__); \ |
| 15525 | else \ |
| 15526 | { \ |
| 15527 | int sc_cancel_oldtype = LIBC_CANCEL_ASYNC (); \ |
| 15528 | - sc_ret = __SYSCALL_CALL (__VA_ARGS__); \ |
| 15529 | + sc_ret = INLINE_SYSCALL_CALL (__VA_ARGS__); \ |
| 15530 | LIBC_CANCEL_RESET (sc_cancel_oldtype); \ |
| 15531 | } \ |
| 15532 | sc_ret; \ |
| 15533 | diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile |
| 15534 | index 35e1ed48d2..32beaa67d0 100644 |
| 15535 | --- a/sysdeps/unix/sysv/linux/Makefile |
| 15536 | +++ b/sysdeps/unix/sysv/linux/Makefile |
| 15537 | @@ -140,7 +140,7 @@ endif |
| 15538 | ifeq ($(subdir),posix) |
| 15539 | sysdep_headers += bits/initspin.h |
| 15540 | |
| 15541 | -sysdep_routines += sched_getcpu |
| 15542 | +sysdep_routines += sched_getcpu oldglob |
| 15543 | |
| 15544 | tests += tst-affinity tst-affinity-pid |
| 15545 | |
| 15546 | diff --git a/sysdeps/unix/sysv/linux/aarch64/clone.S b/sysdeps/unix/sysv/linux/aarch64/clone.S |
| 15547 | index 76baa7a698..96482e53c0 100644 |
| 15548 | --- a/sysdeps/unix/sysv/linux/aarch64/clone.S |
| 15549 | +++ b/sysdeps/unix/sysv/linux/aarch64/clone.S |
| 15550 | @@ -72,16 +72,6 @@ thread_start: |
| 15551 | cfi_undefined (x30) |
| 15552 | mov x29, 0 |
| 15553 | |
| 15554 | - tbnz x11, #CLONE_VM_BIT, 1f |
| 15555 | - |
| 15556 | - mov x8, #SYS_ify(getpid) |
| 15557 | - svc 0x0 |
| 15558 | - mrs x1, tpidr_el0 |
| 15559 | - sub x1, x1, #PTHREAD_SIZEOF |
| 15560 | - str w0, [x1, #PTHREAD_PID_OFFSET] |
| 15561 | - str w0, [x1, #PTHREAD_TID_OFFSET] |
| 15562 | -1: |
| 15563 | - |
| 15564 | /* Pick the function arg and execute. */ |
| 15565 | mov x0, x12 |
| 15566 | blr x10 |
| 15567 | diff --git a/sysdeps/unix/sysv/linux/aarch64/vfork.S b/sysdeps/unix/sysv/linux/aarch64/vfork.S |
| 15568 | index 577895eeb2..aeed0b29ce 100644 |
| 15569 | --- a/sysdeps/unix/sysv/linux/aarch64/vfork.S |
| 15570 | +++ b/sysdeps/unix/sysv/linux/aarch64/vfork.S |
| 15571 | @@ -27,27 +27,10 @@ |
| 15572 | |
| 15573 | ENTRY (__vfork) |
| 15574 | |
| 15575 | - /* Save the TCB-cached PID away in w3, and then negate the TCB |
| 15576 | - field. But if it's zero, set it to 0x80000000 instead. See |
| 15577 | - raise.c for the logic that relies on this value. */ |
| 15578 | - mrs x2, tpidr_el0 |
| 15579 | - sub x2, x2, #PTHREAD_SIZEOF |
| 15580 | - ldr w3, [x2, #PTHREAD_PID_OFFSET] |
| 15581 | - mov w1, #0x80000000 |
| 15582 | - negs w0, w3 |
| 15583 | - csel w0, w1, w0, eq |
| 15584 | - str w0, [x2, #PTHREAD_PID_OFFSET] |
| 15585 | - |
| 15586 | mov x0, #0x4111 /* CLONE_VM | CLONE_VFORK | SIGCHLD */ |
| 15587 | mov x1, sp |
| 15588 | DO_CALL (clone, 2) |
| 15589 | |
| 15590 | - /* Restore the original value of the TCB cache of the PID, if we're |
| 15591 | - the parent. But in the child (syscall return value equals zero), |
| 15592 | - leave things as they are. */ |
| 15593 | - cbz x0, 1f |
| 15594 | - str w3, [x2, #PTHREAD_PID_OFFSET] |
| 15595 | -1: |
| 15596 | cmn x0, #4095 |
| 15597 | b.cs .Lsyscall_error |
| 15598 | RET |
| 15599 | diff --git a/sysdeps/unix/sysv/linux/alpha/Makefile b/sysdeps/unix/sysv/linux/alpha/Makefile |
| 15600 | index c089545e9b..3b523b70cf 100644 |
| 15601 | --- a/sysdeps/unix/sysv/linux/alpha/Makefile |
| 15602 | +++ b/sysdeps/unix/sysv/linux/alpha/Makefile |
| 15603 | @@ -40,4 +40,5 @@ endif # math |
| 15604 | ifeq ($(subdir),nptl) |
| 15605 | # pull in __syscall_error routine, __sigprocmask, __syscall_rt_sigaction |
| 15606 | libpthread-routines += ptw-sysdep ptw-sigprocmask ptw-rt_sigaction |
| 15607 | +libpthread-shared-only-routines += ptw-sysdep ptw-sigprocmask ptw-rt_sigaction |
| 15608 | endif |
| 15609 | diff --git a/sysdeps/unix/sysv/linux/alpha/clone.S b/sysdeps/unix/sysv/linux/alpha/clone.S |
| 15610 | index 6a3154f9a7..2757bf20c3 100644 |
| 15611 | --- a/sysdeps/unix/sysv/linux/alpha/clone.S |
| 15612 | +++ b/sysdeps/unix/sysv/linux/alpha/clone.S |
| 15613 | @@ -91,13 +91,6 @@ thread_start: |
| 15614 | cfi_def_cfa_register(fp) |
| 15615 | cfi_undefined(ra) |
| 15616 | |
| 15617 | - /* Check and see if we need to reset the PID. */ |
| 15618 | - ldq t0, 16(sp) |
| 15619 | - lda t1, CLONE_VM |
| 15620 | - and t0, t1, t2 |
| 15621 | - beq t2, 2f |
| 15622 | -1: |
| 15623 | - |
| 15624 | /* Load up the arguments. */ |
| 15625 | ldq pv, 0(sp) |
| 15626 | ldq a0, 8(sp) |
| 15627 | @@ -120,15 +113,6 @@ thread_start: |
| 15628 | halt |
| 15629 | |
| 15630 | .align 4 |
| 15631 | -2: |
| 15632 | - rduniq |
| 15633 | - mov v0, s0 |
| 15634 | - lda v0, __NR_getxpid |
| 15635 | - callsys |
| 15636 | -3: |
| 15637 | - stl v0, PID_OFFSET(s0) |
| 15638 | - stl v0, TID_OFFSET(s0) |
| 15639 | - br 1b |
| 15640 | cfi_endproc |
| 15641 | .end thread_start |
| 15642 | |
| 15643 | diff --git a/sysdeps/unix/sysv/linux/alpha/glob.c b/sysdeps/unix/sysv/linux/alpha/glob.c |
| 15644 | index c5dfb85468..19eb9b1c07 100644 |
| 15645 | --- a/sysdeps/unix/sysv/linux/alpha/glob.c |
| 15646 | +++ b/sysdeps/unix/sysv/linux/alpha/glob.c |
| 15647 | @@ -42,10 +42,6 @@ extern void __new_globfree (glob_t *__pglob); |
| 15648 | #undef globfree64 |
| 15649 | |
| 15650 | versioned_symbol (libc, __new_glob, glob, GLIBC_2_1); |
| 15651 | -versioned_symbol (libc, __new_globfree, globfree, GLIBC_2_1); |
| 15652 | libc_hidden_ver (__new_glob, glob) |
| 15653 | -libc_hidden_ver (__new_globfree, globfree) |
| 15654 | |
| 15655 | weak_alias (__new_glob, glob64) |
| 15656 | -weak_alias (__new_globfree, globfree64) |
| 15657 | -libc_hidden_ver (__new_globfree, globfree64) |
| 15658 | diff --git a/sysdeps/unix/sysv/linux/alpha/globfree.c b/sysdeps/unix/sysv/linux/alpha/globfree.c |
| 15659 | new file mode 100644 |
| 15660 | index 0000000000..98cf1c200b |
| 15661 | --- /dev/null |
| 15662 | +++ b/sysdeps/unix/sysv/linux/alpha/globfree.c |
| 15663 | @@ -0,0 +1,37 @@ |
| 15664 | +/* Compat globfree. Linux/alpha version. |
| 15665 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 15666 | + This file is part of the GNU C Library. |
| 15667 | + |
| 15668 | + The GNU C Library is free software; you can redistribute it and/or |
| 15669 | + modify it under the terms of the GNU Lesser General Public |
| 15670 | + License as published by the Free Software Foundation; either |
| 15671 | + version 2.1 of the License, or (at your option) any later version. |
| 15672 | + |
| 15673 | + The GNU C Library is distributed in the hope that it will be useful, |
| 15674 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15675 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15676 | + Lesser General Public License for more details. |
| 15677 | + |
| 15678 | + You should have received a copy of the GNU Lesser General Public |
| 15679 | + License along with the GNU C Library. If not, see |
| 15680 | + <http://www.gnu.org/licenses/>. */ |
| 15681 | + |
| 15682 | +#define globfree64 __no_globfree64_decl |
| 15683 | +#include <sys/types.h> |
| 15684 | +#include <glob.h> |
| 15685 | +#include <shlib-compat.h> |
| 15686 | + |
| 15687 | +#define globfree(pglob) \ |
| 15688 | + __new_globfree (pglob) |
| 15689 | + |
| 15690 | +extern void __new_globfree (glob_t *__pglob); |
| 15691 | + |
| 15692 | +#include <posix/globfree.c> |
| 15693 | + |
| 15694 | +#undef globfree64 |
| 15695 | + |
| 15696 | +versioned_symbol (libc, __new_globfree, globfree, GLIBC_2_1); |
| 15697 | +libc_hidden_ver (__new_globfree, globfree) |
| 15698 | + |
| 15699 | +weak_alias (__new_globfree, globfree64) |
| 15700 | +libc_hidden_ver (__new_globfree, globfree64) |
| 15701 | diff --git a/sysdeps/unix/sysv/linux/alpha/vfork.S b/sysdeps/unix/sysv/linux/alpha/vfork.S |
| 15702 | index 9fc199ac41..e5f7ed0661 100644 |
| 15703 | --- a/sysdeps/unix/sysv/linux/alpha/vfork.S |
| 15704 | +++ b/sysdeps/unix/sysv/linux/alpha/vfork.S |
| 15705 | @@ -25,24 +25,9 @@ ENTRY(__libc_vfork) |
| 15706 | rduniq |
| 15707 | mov v0, a1 |
| 15708 | |
| 15709 | - /* Save the TCB-cached PID away in A2, and then negate the TCB |
| 15710 | - field. But if it's zero, set it to 0x80000000 instead. See |
| 15711 | - raise.c for the logic that relies on this value. */ |
| 15712 | - ldl a2, PID_OFFSET(v0) |
| 15713 | - ldah t0, -0x8000 |
| 15714 | - negl a2, t1 |
| 15715 | - cmovne a2, t1, t0 |
| 15716 | - stl t0, PID_OFFSET(v0); |
| 15717 | - |
| 15718 | lda v0, SYS_ify(vfork) |
| 15719 | call_pal PAL_callsys |
| 15720 | |
| 15721 | - /* Restore the original value of the TCB cache of the PID, if we're |
| 15722 | - the parent. But in the child (syscall return value equals zero), |
| 15723 | - leave things as they are. */ |
| 15724 | - beq v0, 1f |
| 15725 | - stl a2, PID_OFFSET(a1) |
| 15726 | -1: |
| 15727 | /* Normal error check and return. */ |
| 15728 | bne a3, SYSCALL_ERROR_LABEL |
| 15729 | ret |
| 15730 | diff --git a/sysdeps/unix/sysv/linux/arm/clone.S b/sysdeps/unix/sysv/linux/arm/clone.S |
| 15731 | index 7ff681804b..4c6325d088 100644 |
| 15732 | --- a/sysdeps/unix/sysv/linux/arm/clone.S |
| 15733 | +++ b/sysdeps/unix/sysv/linux/arm/clone.S |
| 15734 | @@ -70,16 +70,6 @@ PSEUDO_END (__clone) |
| 15735 | 1: |
| 15736 | .fnstart |
| 15737 | .cantunwind |
| 15738 | - tst ip, #CLONE_VM |
| 15739 | - bne 2f |
| 15740 | - GET_TLS (lr) |
| 15741 | - mov r1, r0 |
| 15742 | - ldr r7, =SYS_ify(getpid) |
| 15743 | - swi 0x0 |
| 15744 | - NEGOFF_ADJ_BASE (r1, TID_OFFSET) |
| 15745 | - str r0, NEGOFF_OFF1 (r1, TID_OFFSET) |
| 15746 | - str r0, NEGOFF_OFF2 (r1, PID_OFFSET, TID_OFFSET) |
| 15747 | -2: |
| 15748 | @ pick the function arg and call address off the stack and execute |
| 15749 | ldr r0, [sp, #4] |
| 15750 | ldr ip, [sp], #8 |
| 15751 | diff --git a/sysdeps/unix/sysv/linux/arm/setcontext.S b/sysdeps/unix/sysv/linux/arm/setcontext.S |
| 15752 | index 603e508858..d1f168fece 100644 |
| 15753 | --- a/sysdeps/unix/sysv/linux/arm/setcontext.S |
| 15754 | +++ b/sysdeps/unix/sysv/linux/arm/setcontext.S |
| 15755 | @@ -86,12 +86,19 @@ weak_alias(__setcontext, setcontext) |
| 15756 | |
| 15757 | /* Called when a makecontext() context returns. Start the |
| 15758 | context in R4 or fall through to exit(). */ |
| 15759 | + /* Unwind descriptors are looked up based on PC - 2, so we have to |
| 15760 | + make sure to mark the instruction preceding the __startcontext |
| 15761 | + label as .cantunwind. */ |
| 15762 | + .fnstart |
| 15763 | + .cantunwind |
| 15764 | + nop |
| 15765 | ENTRY(__startcontext) |
| 15766 | movs r0, r4 |
| 15767 | bne PLTJMP(__setcontext) |
| 15768 | |
| 15769 | @ New context was 0 - exit |
| 15770 | b PLTJMP(HIDDEN_JUMPTARGET(exit)) |
| 15771 | + .fnend |
| 15772 | END(__startcontext) |
| 15773 | |
| 15774 | #ifdef PIC |
| 15775 | diff --git a/sysdeps/unix/sysv/linux/arm/vfork.S b/sysdeps/unix/sysv/linux/arm/vfork.S |
| 15776 | index 500f5ca4be..794372ee12 100644 |
| 15777 | --- a/sysdeps/unix/sysv/linux/arm/vfork.S |
| 15778 | +++ b/sysdeps/unix/sysv/linux/arm/vfork.S |
| 15779 | @@ -28,16 +28,6 @@ |
| 15780 | and the process ID of the new process to the old process. */ |
| 15781 | |
| 15782 | ENTRY (__vfork) |
| 15783 | - /* Save the PID value. */ |
| 15784 | - GET_TLS (r2) |
| 15785 | - NEGOFF_ADJ_BASE2 (r2, r0, PID_OFFSET) /* Save the TLS addr in r2. */ |
| 15786 | - ldr r3, NEGOFF_OFF1 (r2, PID_OFFSET) /* Load the saved PID. */ |
| 15787 | - rsbs r0, r3, #0 /* Negate it, and test for zero. */ |
| 15788 | - /* Use 0x80000000 if it was 0. See raise.c for how this is used. */ |
| 15789 | - it eq |
| 15790 | - moveq r0, #0x80000000 |
| 15791 | - str r0, NEGOFF_OFF1 (r2, PID_OFFSET) /* Store the temp PID. */ |
| 15792 | - |
| 15793 | /* The DO_CALL macro saves r7 on the stack, to enable generation |
| 15794 | of ARM unwind info. Since the stack is initially shared between |
| 15795 | parent and child of vfork, that saved value could be corrupted. |
| 15796 | @@ -57,11 +47,6 @@ ENTRY (__vfork) |
| 15797 | mov r7, ip |
| 15798 | cfi_restore (r7) |
| 15799 | |
| 15800 | - /* Restore the old PID value in the parent. */ |
| 15801 | - cmp r0, #0 /* If we are the parent... */ |
| 15802 | - it ne |
| 15803 | - strne r3, NEGOFF_OFF1 (r2, PID_OFFSET) /* restore the saved PID. */ |
| 15804 | - |
| 15805 | cmn a1, #4096 |
| 15806 | it cc |
| 15807 | RETINSTR(cc, lr) |
| 15808 | diff --git a/sysdeps/unix/sysv/linux/createthread.c b/sysdeps/unix/sysv/linux/createthread.c |
| 15809 | index 6d32cece48..ec86f50814 100644 |
| 15810 | --- a/sysdeps/unix/sysv/linux/createthread.c |
| 15811 | +++ b/sysdeps/unix/sysv/linux/createthread.c |
| 15812 | @@ -128,10 +128,10 @@ create_thread (struct pthread *pd, const struct pthread_attr *attr, |
| 15813 | /* The operation failed. We have to kill the thread. |
| 15814 | We let the normal cancellation mechanism do the work. */ |
| 15815 | |
| 15816 | + pid_t pid = __getpid (); |
| 15817 | INTERNAL_SYSCALL_DECL (err2); |
| 15818 | - (void) INTERNAL_SYSCALL (tgkill, err2, 3, |
| 15819 | - THREAD_GETMEM (THREAD_SELF, pid), |
| 15820 | - pd->tid, SIGCANCEL); |
| 15821 | + (void) INTERNAL_SYSCALL_CALL (tgkill, err2, pid, pd->tid, |
| 15822 | + SIGCANCEL); |
| 15823 | |
| 15824 | return INTERNAL_SYSCALL_ERRNO (res, err); |
| 15825 | } |
| 15826 | diff --git a/sysdeps/unix/sysv/linux/getcwd.c b/sysdeps/unix/sysv/linux/getcwd.c |
| 15827 | index 3f21ae743f..d0b2c38c17 100644 |
| 15828 | --- a/sysdeps/unix/sysv/linux/getcwd.c |
| 15829 | +++ b/sysdeps/unix/sysv/linux/getcwd.c |
| 15830 | @@ -76,7 +76,7 @@ __getcwd (char *buf, size_t size) |
| 15831 | int retval; |
| 15832 | |
| 15833 | retval = INLINE_SYSCALL (getcwd, 2, path, alloc_size); |
| 15834 | - if (retval >= 0) |
| 15835 | + if (retval > 0 && path[0] == '/') |
| 15836 | { |
| 15837 | #ifndef NO_ALLOCATION |
| 15838 | if (buf == NULL && size == 0) |
| 15839 | @@ -92,10 +92,10 @@ __getcwd (char *buf, size_t size) |
| 15840 | return buf; |
| 15841 | } |
| 15842 | |
| 15843 | - /* The system call cannot handle paths longer than a page. |
| 15844 | - Neither can the magic symlink in /proc/self. Just use the |
| 15845 | + /* The system call either cannot handle paths longer than a page |
| 15846 | + or can succeed without returning an absolute path. Just use the |
| 15847 | generic implementation right away. */ |
| 15848 | - if (errno == ENAMETOOLONG) |
| 15849 | + if (retval >= 0 || errno == ENAMETOOLONG) |
| 15850 | { |
| 15851 | #ifndef NO_ALLOCATION |
| 15852 | if (buf == NULL && size == 0) |
| 15853 | diff --git a/sysdeps/unix/sysv/linux/getpid.c b/sysdeps/unix/sysv/linux/getpid.c |
| 15854 | deleted file mode 100644 |
| 15855 | index 1124549326..0000000000 |
| 15856 | --- a/sysdeps/unix/sysv/linux/getpid.c |
| 15857 | +++ /dev/null |
| 15858 | @@ -1,64 +0,0 @@ |
| 15859 | -/* Copyright (C) 2003-2016 Free Software Foundation, Inc. |
| 15860 | - This file is part of the GNU C Library. |
| 15861 | - Contributed by Ulrich Drepper <drepper@redhat.com>, 2003. |
| 15862 | - |
| 15863 | - The GNU C Library is free software; you can redistribute it and/or |
| 15864 | - modify it under the terms of the GNU Lesser General Public |
| 15865 | - License as published by the Free Software Foundation; either |
| 15866 | - version 2.1 of the License, or (at your option) any later version. |
| 15867 | - |
| 15868 | - The GNU C Library is distributed in the hope that it will be useful, |
| 15869 | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15870 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15871 | - Lesser General Public License for more details. |
| 15872 | - |
| 15873 | - You should have received a copy of the GNU Lesser General Public |
| 15874 | - License along with the GNU C Library; if not, see |
| 15875 | - <http://www.gnu.org/licenses/>. */ |
| 15876 | - |
| 15877 | -#include <unistd.h> |
| 15878 | -#include <tls.h> |
| 15879 | -#include <sysdep.h> |
| 15880 | - |
| 15881 | - |
| 15882 | -#if IS_IN (libc) |
| 15883 | -static inline __attribute__((always_inline)) pid_t really_getpid (pid_t oldval); |
| 15884 | - |
| 15885 | -static inline __attribute__((always_inline)) pid_t |
| 15886 | -really_getpid (pid_t oldval) |
| 15887 | -{ |
| 15888 | - if (__glibc_likely (oldval == 0)) |
| 15889 | - { |
| 15890 | - pid_t selftid = THREAD_GETMEM (THREAD_SELF, tid); |
| 15891 | - if (__glibc_likely (selftid != 0)) |
| 15892 | - return selftid; |
| 15893 | - } |
| 15894 | - |
| 15895 | - INTERNAL_SYSCALL_DECL (err); |
| 15896 | - pid_t result = INTERNAL_SYSCALL (getpid, err, 0); |
| 15897 | - |
| 15898 | - /* We do not set the PID field in the TID here since we might be |
| 15899 | - called from a signal handler while the thread executes fork. */ |
| 15900 | - if (oldval == 0) |
| 15901 | - THREAD_SETMEM (THREAD_SELF, tid, result); |
| 15902 | - return result; |
| 15903 | -} |
| 15904 | -#endif |
| 15905 | - |
| 15906 | -pid_t |
| 15907 | -__getpid (void) |
| 15908 | -{ |
| 15909 | -#if !IS_IN (libc) |
| 15910 | - INTERNAL_SYSCALL_DECL (err); |
| 15911 | - pid_t result = INTERNAL_SYSCALL (getpid, err, 0); |
| 15912 | -#else |
| 15913 | - pid_t result = THREAD_GETMEM (THREAD_SELF, pid); |
| 15914 | - if (__glibc_unlikely (result <= 0)) |
| 15915 | - result = really_getpid (result); |
| 15916 | -#endif |
| 15917 | - return result; |
| 15918 | -} |
| 15919 | - |
| 15920 | -libc_hidden_def (__getpid) |
| 15921 | -weak_alias (__getpid, getpid) |
| 15922 | -libc_hidden_def (getpid) |
| 15923 | diff --git a/sysdeps/unix/sysv/linux/hppa/clone.S b/sysdeps/unix/sysv/linux/hppa/clone.S |
| 15924 | index 3d037f1430..25fcd497f7 100644 |
| 15925 | --- a/sysdeps/unix/sysv/linux/hppa/clone.S |
| 15926 | +++ b/sysdeps/unix/sysv/linux/hppa/clone.S |
| 15927 | @@ -132,18 +132,6 @@ ENTRY(__clone) |
| 15928 | ldwm -64(%sp), %r4 |
| 15929 | |
| 15930 | .LthreadStart: |
| 15931 | -# define CLONE_VM_BIT 23 /* 0x00000100 */ |
| 15932 | - /* Load original clone flags. |
| 15933 | - If CLONE_VM was passed, don't modify PID/TID. |
| 15934 | - Otherwise store the result of getpid to PID/TID. */ |
| 15935 | - ldw -56(%sp), %r26 |
| 15936 | - bb,<,n %r26, CLONE_VM_BIT, 1f |
| 15937 | - ble 0x100(%sr2, %r0) |
| 15938 | - ldi __NR_getpid, %r20 |
| 15939 | - mfctl %cr27, %r26 |
| 15940 | - stw %ret0, PID_THREAD_OFFSET(%r26) |
| 15941 | - stw %ret0, TID_THREAD_OFFSET(%r26) |
| 15942 | -1: |
| 15943 | /* Load up the arguments. */ |
| 15944 | ldw -60(%sp), %arg0 |
| 15945 | ldw -64(%sp), %r22 |
| 15946 | diff --git a/sysdeps/unix/sysv/linux/hppa/pt-vfork.S b/sysdeps/unix/sysv/linux/hppa/pt-vfork.S |
| 15947 | index df532362d2..4684048502 100644 |
| 15948 | --- a/sysdeps/unix/sysv/linux/hppa/pt-vfork.S |
| 15949 | +++ b/sysdeps/unix/sysv/linux/hppa/pt-vfork.S |
| 15950 | @@ -25,26 +25,6 @@ |
| 15951 | replaced by a call to `execve'. Return -1 for errors, 0 to the new process, |
| 15952 | and the process ID of the new process to the old process. */ |
| 15953 | |
| 15954 | -/* Load the thread register. |
| 15955 | - Load the saved PID value. |
| 15956 | - Negate the value. |
| 15957 | - Store the temporary PID. */ |
| 15958 | -#define SAVE_PID \ |
| 15959 | - mfctl %cr27, %r26 ASM_LINE_SEP \ |
| 15960 | - ldw PID_THREAD_OFFSET(%r26),%r1 ASM_LINE_SEP \ |
| 15961 | - sub %r0,%r1,%r1 ASM_LINE_SEP \ |
| 15962 | - stw %r1,PID_THREAD_OFFSET(%r26) ASM_LINE_SEP |
| 15963 | -/* If we are the parent... |
| 15964 | - Get the thread pointer. |
| 15965 | - Load the saved PID. |
| 15966 | - Negate the value (got back original) |
| 15967 | - Restore the PID. */ |
| 15968 | -#define RESTORE_PID \ |
| 15969 | - cmpb,=,n %r0,%ret0,.Lthread_start ASM_LINE_SEP \ |
| 15970 | - mfctl %cr27, %r26 ASM_LINE_SEP \ |
| 15971 | - ldw PID_THREAD_OFFSET(%r26),%r1 ASM_LINE_SEP \ |
| 15972 | - sub %r0,%r1,%r1 ASM_LINE_SEP \ |
| 15973 | - stw %r1,PID_THREAD_OFFSET(%r26) ASM_LINE_SEP \ |
| 15974 | .Lthread_start: ASM_LINE_SEP |
| 15975 | |
| 15976 | /* r26, r25, r24, r23 are free since vfork has no arguments */ |
| 15977 | @@ -58,16 +38,10 @@ ENTRY(__vfork) |
| 15978 | copy %r19, %r25 /* parent */ |
| 15979 | #endif |
| 15980 | |
| 15981 | - /* Save the process PID */ |
| 15982 | - SAVE_PID |
| 15983 | - |
| 15984 | /* Syscall saves and restores all register states */ |
| 15985 | ble 0x100(%sr2,%r0) |
| 15986 | ldi __NR_vfork,%r20 |
| 15987 | |
| 15988 | - /* Conditionally restore the PID */ |
| 15989 | - RESTORE_PID |
| 15990 | - |
| 15991 | /* Check for error */ |
| 15992 | ldi -4096,%r1 |
| 15993 | comclr,>>= %r1,%ret0,%r0 /* Note: unsigned compare. */ |
| 15994 | diff --git a/sysdeps/unix/sysv/linux/i386/Makefile b/sysdeps/unix/sysv/linux/i386/Makefile |
| 15995 | index 71ba61e9d7..6073a9fe04 100644 |
| 15996 | --- a/sysdeps/unix/sysv/linux/i386/Makefile |
| 15997 | +++ b/sysdeps/unix/sysv/linux/i386/Makefile |
| 15998 | @@ -31,6 +31,7 @@ endif |
| 15999 | # libpthread uses six-argument inline syscalls. |
| 16000 | ifeq ($(subdir),nptl) |
| 16001 | libpthread-sysdep_routines += libc-do-syscall |
| 16002 | +libpthread-shared-only-routines += libc-do-syscall |
| 16003 | endif |
| 16004 | |
| 16005 | ifeq ($(subdir),resource) |
| 16006 | @@ -48,9 +49,11 @@ endif |
| 16007 | ifeq ($(subdir),nptl) |
| 16008 | # pull in __syscall_error routine |
| 16009 | libpthread-routines += sysdep |
| 16010 | +libpthread-shared-only-routines += sysdep |
| 16011 | endif |
| 16012 | |
| 16013 | ifeq ($(subdir),rt) |
| 16014 | # pull in __syscall_error routine |
| 16015 | librt-routines += sysdep |
| 16016 | +librt-shared-only-routines += sysdep |
| 16017 | endif |
| 16018 | diff --git a/sysdeps/unix/sysv/linux/i386/clone.S b/sysdeps/unix/sysv/linux/i386/clone.S |
| 16019 | index 25f2a9c340..feae504ce6 100644 |
| 16020 | --- a/sysdeps/unix/sysv/linux/i386/clone.S |
| 16021 | +++ b/sysdeps/unix/sysv/linux/i386/clone.S |
| 16022 | @@ -107,9 +107,6 @@ L(thread_start): |
| 16023 | cfi_undefined (eip); |
| 16024 | /* Note: %esi is zero. */ |
| 16025 | movl %esi,%ebp /* terminate the stack frame */ |
| 16026 | - testl $CLONE_VM, %edi |
| 16027 | - je L(newpid) |
| 16028 | -L(haspid): |
| 16029 | call *%ebx |
| 16030 | #ifdef PIC |
| 16031 | call L(here) |
| 16032 | @@ -121,18 +118,6 @@ L(here): |
| 16033 | movl $SYS_ify(exit), %eax |
| 16034 | ENTER_KERNEL |
| 16035 | |
| 16036 | - .subsection 2 |
| 16037 | -L(newpid): |
| 16038 | - movl $SYS_ify(getpid), %eax |
| 16039 | - ENTER_KERNEL |
| 16040 | -L(nomoregetpid): |
| 16041 | - movl %eax, %gs:PID |
| 16042 | - movl %eax, %gs:TID |
| 16043 | - jmp L(haspid) |
| 16044 | - .previous |
| 16045 | - cfi_endproc; |
| 16046 | - |
| 16047 | - cfi_startproc |
| 16048 | PSEUDO_END (__clone) |
| 16049 | |
| 16050 | libc_hidden_def (__clone) |
| 16051 | diff --git a/sysdeps/unix/sysv/linux/i386/glob64.c b/sysdeps/unix/sysv/linux/i386/glob64.c |
| 16052 | index 802c957d6c..c2cc85741f 100644 |
| 16053 | --- a/sysdeps/unix/sysv/linux/i386/glob64.c |
| 16054 | +++ b/sysdeps/unix/sysv/linux/i386/glob64.c |
| 16055 | @@ -19,6 +19,7 @@ |
| 16056 | #include <dirent.h> |
| 16057 | #include <glob.h> |
| 16058 | #include <sys/stat.h> |
| 16059 | +#include <shlib-compat.h> |
| 16060 | |
| 16061 | #define dirent dirent64 |
| 16062 | #define __readdir(dirp) __readdir64 (dirp) |
| 16063 | @@ -33,44 +34,9 @@ |
| 16064 | #undef __stat |
| 16065 | #define __stat(file, buf) __xstat64 (_STAT_VER, file, buf) |
| 16066 | |
| 16067 | -#define NO_GLOB_PATTERN_P 1 |
| 16068 | - |
| 16069 | #define COMPILE_GLOB64 1 |
| 16070 | |
| 16071 | #include <posix/glob.c> |
| 16072 | |
| 16073 | -#include "shlib-compat.h" |
| 16074 | - |
| 16075 | -libc_hidden_def (globfree64) |
| 16076 | - |
| 16077 | versioned_symbol (libc, __glob64, glob64, GLIBC_2_2); |
| 16078 | libc_hidden_ver (__glob64, glob64) |
| 16079 | - |
| 16080 | -#if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2) |
| 16081 | - |
| 16082 | -#include <sysdeps/unix/sysv/linux/i386/olddirent.h> |
| 16083 | - |
| 16084 | -int __old_glob64 (const char *__pattern, int __flags, |
| 16085 | - int (*__errfunc) (const char *, int), |
| 16086 | - glob64_t *__pglob); |
| 16087 | - |
| 16088 | -#undef dirent |
| 16089 | -#define dirent __old_dirent64 |
| 16090 | -#undef GL_READDIR |
| 16091 | -# define GL_READDIR(pglob, stream) \ |
| 16092 | - ((struct __old_dirent64 *) (pglob)->gl_readdir (stream)) |
| 16093 | -#undef __readdir |
| 16094 | -#define __readdir(dirp) __old_readdir64 (dirp) |
| 16095 | -#undef glob |
| 16096 | -#define glob(pattern, flags, errfunc, pglob) \ |
| 16097 | - __old_glob64 (pattern, flags, errfunc, pglob) |
| 16098 | -#define convert_dirent __old_convert_dirent |
| 16099 | -#define glob_in_dir __old_glob_in_dir |
| 16100 | -#define GLOB_ATTRIBUTE attribute_compat_text_section |
| 16101 | - |
| 16102 | -#define GLOB_ONLY_P 1 |
| 16103 | - |
| 16104 | -#include <posix/glob.c> |
| 16105 | - |
| 16106 | -compat_symbol (libc, __old_glob64, glob64, GLIBC_2_1); |
| 16107 | -#endif |
| 16108 | diff --git a/sysdeps/unix/sysv/linux/i386/vfork.S b/sysdeps/unix/sysv/linux/i386/vfork.S |
| 16109 | index 7a1d3373bb..a865de2201 100644 |
| 16110 | --- a/sysdeps/unix/sysv/linux/i386/vfork.S |
| 16111 | +++ b/sysdeps/unix/sysv/linux/i386/vfork.S |
| 16112 | @@ -34,17 +34,6 @@ ENTRY (__vfork) |
| 16113 | cfi_adjust_cfa_offset (-4) |
| 16114 | cfi_register (%eip, %ecx) |
| 16115 | |
| 16116 | - /* Save the TCB-cached PID away in %edx, and then negate the TCB |
| 16117 | - field. But if it's zero, set it to 0x80000000 instead. See |
| 16118 | - raise.c for the logic that relies on this value. */ |
| 16119 | - movl %gs:PID, %edx |
| 16120 | - movl %edx, %eax |
| 16121 | - negl %eax |
| 16122 | - jne 1f |
| 16123 | - movl $0x80000000, %eax |
| 16124 | -1: movl %eax, %gs:PID |
| 16125 | - |
| 16126 | - |
| 16127 | /* Stuff the syscall number in EAX and enter into the kernel. */ |
| 16128 | movl $SYS_ify (vfork), %eax |
| 16129 | int $0x80 |
| 16130 | @@ -55,14 +44,6 @@ ENTRY (__vfork) |
| 16131 | pushl %ecx |
| 16132 | cfi_adjust_cfa_offset (4) |
| 16133 | |
| 16134 | - /* Restore the original value of the TCB cache of the PID, if we're |
| 16135 | - the parent. But in the child (syscall return value equals zero), |
| 16136 | - leave things as they are. */ |
| 16137 | - testl %eax, %eax |
| 16138 | - je 1f |
| 16139 | - movl %edx, %gs:PID |
| 16140 | -1: |
| 16141 | - |
| 16142 | cmpl $-4095, %eax |
| 16143 | /* Branch forward if it failed. */ |
| 16144 | jae SYSCALL_ERROR_LABEL |
| 16145 | diff --git a/sysdeps/unix/sysv/linux/ia64/Makefile b/sysdeps/unix/sysv/linux/ia64/Makefile |
| 16146 | index 1de62c528a..4d6766db5e 100644 |
| 16147 | --- a/sysdeps/unix/sysv/linux/ia64/Makefile |
| 16148 | +++ b/sysdeps/unix/sysv/linux/ia64/Makefile |
| 16149 | @@ -19,6 +19,7 @@ endif |
| 16150 | |
| 16151 | ifeq ($(subdir),rt) |
| 16152 | librt-routines += rt-sysdep |
| 16153 | +librt-shared-only-routines += rt-sysdep |
| 16154 | endif |
| 16155 | |
| 16156 | ifeq ($(subdir),nptl) |
| 16157 | diff --git a/sysdeps/unix/sysv/linux/ia64/clone2.S b/sysdeps/unix/sysv/linux/ia64/clone2.S |
| 16158 | index b4cfdfc959..e637b6d4a5 100644 |
| 16159 | --- a/sysdeps/unix/sysv/linux/ia64/clone2.S |
| 16160 | +++ b/sysdeps/unix/sysv/linux/ia64/clone2.S |
| 16161 | @@ -67,19 +67,7 @@ ENTRY(__clone2) |
| 16162 | (CHILD) mov loc0=gp |
| 16163 | (PARENT) ret |
| 16164 | ;; |
| 16165 | - tbit.nz p6,p0=in3,8 /* CLONE_VM */ |
| 16166 | -(p6) br.cond.dptk 1f |
| 16167 | - ;; |
| 16168 | - mov r15=SYS_ify (getpid) |
| 16169 | -(p7) break __BREAK_SYSCALL |
| 16170 | - ;; |
| 16171 | - add r9=PID,r13 |
| 16172 | - add r10=TID,r13 |
| 16173 | - ;; |
| 16174 | - st4 [r9]=r8 |
| 16175 | - st4 [r10]=r8 |
| 16176 | - ;; |
| 16177 | -1: ld8 out1=[in0],8 /* Retrieve code pointer. */ |
| 16178 | + ld8 out1=[in0],8 /* Retrieve code pointer. */ |
| 16179 | mov out0=in4 /* Pass proper argument to fn */ |
| 16180 | ;; |
| 16181 | ld8 gp=[in0] /* Load function gp. */ |
| 16182 | diff --git a/sysdeps/unix/sysv/linux/ia64/vfork.S b/sysdeps/unix/sysv/linux/ia64/vfork.S |
| 16183 | index 9154d7c0fd..84bfdd5d8a 100644 |
| 16184 | --- a/sysdeps/unix/sysv/linux/ia64/vfork.S |
| 16185 | +++ b/sysdeps/unix/sysv/linux/ia64/vfork.S |
| 16186 | @@ -33,32 +33,12 @@ ENTRY (__libc_vfork) |
| 16187 | .prologue // work around a GAS bug which triggers if |
| 16188 | .body // first .prologue is not at the beginning of proc. |
| 16189 | alloc r2=ar.pfs,0,0,2,0 |
| 16190 | - adds r14=PID,r13 |
| 16191 | - ;; |
| 16192 | - ld4 r16=[r14] |
| 16193 | - ;; |
| 16194 | - sub r15=0,r16 |
| 16195 | - cmp.eq p6,p0=0,r16 |
| 16196 | - ;; |
| 16197 | -(p6) movl r15=0x80000000 |
| 16198 | mov out0=CLONE_VM+CLONE_VFORK+SIGCHLD |
| 16199 | mov out1=0 /* Standard sp value. */ |
| 16200 | ;; |
| 16201 | - st4 [r14]=r15 |
| 16202 | DO_CALL (SYS_ify (clone)) |
| 16203 | cmp.eq p6,p0=0,r8 |
| 16204 | - adds r14=PID,r13 |
| 16205 | (p6) br.cond.dptk 1f |
| 16206 | - ;; |
| 16207 | - ld4 r15=[r14] |
| 16208 | - ;; |
| 16209 | - extr.u r16=r15,0,31 |
| 16210 | - ;; |
| 16211 | - cmp.eq p0,p6=0,r16 |
| 16212 | - ;; |
| 16213 | -(p6) sub r16=0,r15 |
| 16214 | - ;; |
| 16215 | - st4 [r14]=r16 |
| 16216 | 1: |
| 16217 | cmp.eq p6,p0=-1,r10 |
| 16218 | (p6) br.cond.spnt.few __syscall_error |
| 16219 | diff --git a/sysdeps/unix/sysv/linux/m68k/clone.S b/sysdeps/unix/sysv/linux/m68k/clone.S |
| 16220 | index 3a828443dc..630a29209d 100644 |
| 16221 | --- a/sysdeps/unix/sysv/linux/m68k/clone.S |
| 16222 | +++ b/sysdeps/unix/sysv/linux/m68k/clone.S |
| 16223 | @@ -98,19 +98,6 @@ ENTRY (__clone) |
| 16224 | cfi_startproc |
| 16225 | cfi_undefined (pc) /* Mark end of stack */ |
| 16226 | subl %fp, %fp /* terminate the stack frame */ |
| 16227 | - /* Check and see if we need to reset the PID. */ |
| 16228 | - andl #CLONE_VM, %d1 |
| 16229 | - jne 1f |
| 16230 | - movel #SYS_ify (getpid), %d0 |
| 16231 | - trap #0 |
| 16232 | - movel %a0, -(%sp) |
| 16233 | - movel %d0, -(%sp) |
| 16234 | - bsrl __m68k_read_tp@PLTPC |
| 16235 | - movel (%sp)+, %d0 |
| 16236 | - movel %d0, PID_OFFSET(%a0) |
| 16237 | - movel %d0, TID_OFFSET(%a0) |
| 16238 | - movel (%sp)+, %a0 |
| 16239 | -1: |
| 16240 | jsr (%a0) |
| 16241 | movel %d0, %d1 |
| 16242 | movel #SYS_ify (exit), %d0 |
| 16243 | diff --git a/sysdeps/unix/sysv/linux/m68k/vfork.S b/sysdeps/unix/sysv/linux/m68k/vfork.S |
| 16244 | index 1625a7b7a0..e27479361b 100644 |
| 16245 | --- a/sysdeps/unix/sysv/linux/m68k/vfork.S |
| 16246 | +++ b/sysdeps/unix/sysv/linux/m68k/vfork.S |
| 16247 | @@ -28,18 +28,6 @@ |
| 16248 | |
| 16249 | ENTRY (__vfork) |
| 16250 | |
| 16251 | - /* Save the TCB-cached PID away in %d1, and then negate the TCB |
| 16252 | - field. But if it's zero, set it to 0x80000000 instead. See |
| 16253 | - raise.c for the logic that relies on this value. */ |
| 16254 | - jbsr __m68k_read_tp@PLTPC |
| 16255 | - movel %a0, %a1 |
| 16256 | - movel PID_OFFSET(%a1), %d0 |
| 16257 | - movel %d0, %d1 |
| 16258 | - negl %d0 |
| 16259 | - jne 1f |
| 16260 | - movel #0x80000000, %d0 |
| 16261 | -1: movel %d0, PID_OFFSET(%a1) |
| 16262 | - |
| 16263 | /* Pop the return PC value into A0. */ |
| 16264 | movel %sp@+, %a0 |
| 16265 | cfi_adjust_cfa_offset (-4) |
| 16266 | @@ -49,14 +37,6 @@ ENTRY (__vfork) |
| 16267 | movel #SYS_ify (vfork), %d0 |
| 16268 | trap #0 |
| 16269 | |
| 16270 | - /* Restore the original value of the TCB cache of the PID, if we're |
| 16271 | - the parent. But in the child (syscall return value equals zero), |
| 16272 | - leave things as they are. */ |
| 16273 | - tstl %d0 |
| 16274 | - jeq 1f |
| 16275 | - movel %d1, PID_OFFSET(%a1) |
| 16276 | -1: |
| 16277 | - |
| 16278 | tstl %d0 |
| 16279 | jmi .Lerror /* Branch forward if it failed. */ |
| 16280 | |
| 16281 | diff --git a/sysdeps/unix/sysv/linux/microblaze/Makefile b/sysdeps/unix/sysv/linux/microblaze/Makefile |
| 16282 | index 44a838fa11..d178bc6f34 100644 |
| 16283 | --- a/sysdeps/unix/sysv/linux/microblaze/Makefile |
| 16284 | +++ b/sysdeps/unix/sysv/linux/microblaze/Makefile |
| 16285 | @@ -5,4 +5,5 @@ endif |
| 16286 | ifeq ($(subdir),nptl) |
| 16287 | # pull in __syscall_error routine |
| 16288 | libpthread-routines += sysdep |
| 16289 | -endif |
| 16290 | \ No newline at end of file |
| 16291 | +libpthread-shared-only-routines += sysdep |
| 16292 | +endif |
| 16293 | diff --git a/sysdeps/unix/sysv/linux/mips/clone.S b/sysdeps/unix/sysv/linux/mips/clone.S |
| 16294 | index 39634c5cf0..7ae65ef723 100644 |
| 16295 | --- a/sysdeps/unix/sysv/linux/mips/clone.S |
| 16296 | +++ b/sysdeps/unix/sysv/linux/mips/clone.S |
| 16297 | @@ -130,11 +130,6 @@ L(thread_start): |
| 16298 | SAVE_GP (GPOFF) |
| 16299 | /* The stackframe has been created on entry of clone(). */ |
| 16300 | |
| 16301 | - /* Check and see if we need to reset the PID. */ |
| 16302 | - and a1,a0,CLONE_VM |
| 16303 | - beqz a1,L(restore_pid) |
| 16304 | -L(donepid): |
| 16305 | - |
| 16306 | /* Restore the arg for user's function. */ |
| 16307 | PTR_L t9,0(sp) /* Function pointer. */ |
| 16308 | PTR_L a0,PTRSIZE(sp) /* Argument pointer. */ |
| 16309 | @@ -151,14 +146,6 @@ L(donepid): |
| 16310 | jal _exit |
| 16311 | #endif |
| 16312 | |
| 16313 | -L(restore_pid): |
| 16314 | - li v0,__NR_getpid |
| 16315 | - syscall |
| 16316 | - READ_THREAD_POINTER(v1) |
| 16317 | - INT_S v0,PID_OFFSET(v1) |
| 16318 | - INT_S v0,TID_OFFSET(v1) |
| 16319 | - b L(donepid) |
| 16320 | - |
| 16321 | END(__thread_start) |
| 16322 | |
| 16323 | libc_hidden_def (__clone) |
| 16324 | diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n64/globfree64.c b/sysdeps/unix/sysv/linux/mips/mips64/n64/globfree64.c |
| 16325 | new file mode 100644 |
| 16326 | index 0000000000..abc35fdd2b |
| 16327 | --- /dev/null |
| 16328 | +++ b/sysdeps/unix/sysv/linux/mips/mips64/n64/globfree64.c |
| 16329 | @@ -0,0 +1 @@ |
| 16330 | +/* glob64 is in globfree64.c */ |
| 16331 | diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n64/syscalls.list b/sysdeps/unix/sysv/linux/mips/mips64/n64/syscalls.list |
| 16332 | index 890a74494a..26ab6d0b75 100644 |
| 16333 | --- a/sysdeps/unix/sysv/linux/mips/mips64/n64/syscalls.list |
| 16334 | +++ b/sysdeps/unix/sysv/linux/mips/mips64/n64/syscalls.list |
| 16335 | @@ -4,6 +4,8 @@ mmap - mmap b:aniiii __mmap mmap __mmap64 mmap64 |
| 16336 | |
| 16337 | sync_file_range - sync_file_range Ci:iiii sync_file_range |
| 16338 | |
| 16339 | +readahead - readahead i:iii __readahead readahead |
| 16340 | + |
| 16341 | prlimit EXTRA prlimit64 i:iipp prlimit prlimit64 |
| 16342 | |
| 16343 | fanotify_mark EXTRA fanotify_mark i:iiiis fanotify_mark |
| 16344 | diff --git a/sysdeps/unix/sysv/linux/mips/vfork.S b/sysdeps/unix/sysv/linux/mips/vfork.S |
| 16345 | index 1867c8626e..0b9244b7f8 100644 |
| 16346 | --- a/sysdeps/unix/sysv/linux/mips/vfork.S |
| 16347 | +++ b/sysdeps/unix/sysv/linux/mips/vfork.S |
| 16348 | @@ -60,14 +60,6 @@ NESTED(__libc_vfork,FRAMESZ,sp) |
| 16349 | PTR_ADDU sp, FRAMESZ |
| 16350 | cfi_adjust_cfa_offset (-FRAMESZ) |
| 16351 | |
| 16352 | - /* Save the PID value. */ |
| 16353 | - READ_THREAD_POINTER(v1) /* Get the thread pointer. */ |
| 16354 | - lw a2, PID_OFFSET(v1) /* Load the saved PID. */ |
| 16355 | - subu a2, $0, a2 /* Negate it. */ |
| 16356 | - bnez a2, 1f /* If it was zero... */ |
| 16357 | - lui a2, 0x8000 /* use 0x80000000 instead. */ |
| 16358 | -1: sw a2, PID_OFFSET(v1) /* Store the temporary PID. */ |
| 16359 | - |
| 16360 | li a0, 0x4112 /* CLONE_VM | CLONE_VFORK | SIGCHLD */ |
| 16361 | move a1, sp |
| 16362 | |
| 16363 | @@ -75,17 +67,6 @@ NESTED(__libc_vfork,FRAMESZ,sp) |
| 16364 | li v0,__NR_clone |
| 16365 | syscall |
| 16366 | |
| 16367 | - /* Restore the old PID value in the parent. */ |
| 16368 | - beqz v0, 1f /* If we are the parent... */ |
| 16369 | - READ_THREAD_POINTER(v1) /* Get the thread pointer. */ |
| 16370 | - lw a2, PID_OFFSET(v1) /* Load the saved PID. */ |
| 16371 | - subu a2, $0, a2 /* Re-negate it. */ |
| 16372 | - lui a0, 0x8000 /* Load 0x80000000... */ |
| 16373 | - bne a2, a0, 2f /* ... compare against it... */ |
| 16374 | - li a2, 0 /* ... use 0 instead. */ |
| 16375 | -2: sw a2, PID_OFFSET(v1) /* Restore the PID. */ |
| 16376 | -1: |
| 16377 | - |
| 16378 | cfi_remember_state |
| 16379 | bnez a3,L(error) |
| 16380 | |
| 16381 | diff --git a/sysdeps/unix/sysv/linux/nios2/clone.S b/sysdeps/unix/sysv/linux/nios2/clone.S |
| 16382 | index 30b6e4a6c8..c9fa00f94c 100644 |
| 16383 | --- a/sysdeps/unix/sysv/linux/nios2/clone.S |
| 16384 | +++ b/sysdeps/unix/sysv/linux/nios2/clone.S |
| 16385 | @@ -68,14 +68,6 @@ thread_start: |
| 16386 | cfi_startproc |
| 16387 | cfi_undefined (ra) |
| 16388 | |
| 16389 | - /* We expect the argument registers to be preserved across system |
| 16390 | - calls and across task cloning, so flags should be in r4 here. */ |
| 16391 | - andi r2, r4, CLONE_VM |
| 16392 | - bne r2, zero, 2f |
| 16393 | - DO_CALL (getpid, 0) |
| 16394 | - stw r2, PID_OFFSET(r23) |
| 16395 | - stw r2, TID_OFFSET(r23) |
| 16396 | -2: |
| 16397 | ldw r5, 4(sp) /* Function pointer. */ |
| 16398 | ldw r4, 0(sp) /* Argument pointer. */ |
| 16399 | addi sp, sp, 8 |
| 16400 | diff --git a/sysdeps/unix/sysv/linux/nios2/vfork.S b/sysdeps/unix/sysv/linux/nios2/vfork.S |
| 16401 | index c1bb9c7134..8997269199 100644 |
| 16402 | --- a/sysdeps/unix/sysv/linux/nios2/vfork.S |
| 16403 | +++ b/sysdeps/unix/sysv/linux/nios2/vfork.S |
| 16404 | @@ -21,20 +21,10 @@ |
| 16405 | |
| 16406 | ENTRY(__vfork) |
| 16407 | |
| 16408 | - ldw r6, PID_OFFSET(r23) |
| 16409 | - sub r7, zero, r6 |
| 16410 | - bne r7, zero, 2f |
| 16411 | - movhi r7, %hi(0x80000000) |
| 16412 | -2: |
| 16413 | - stw r7, PID_OFFSET(r23) |
| 16414 | - |
| 16415 | movi r4, 0x4111 /* (CLONE_VM | CLONE_VFORK | SIGCHLD) */ |
| 16416 | mov r5, zero |
| 16417 | DO_CALL (clone, 2) |
| 16418 | |
| 16419 | - beq r2, zero, 1f |
| 16420 | - stw r6, PID_OFFSET(r23) |
| 16421 | -1: |
| 16422 | bne r7, zero, SYSCALL_ERROR_LABEL |
| 16423 | ret |
| 16424 | |
| 16425 | diff --git a/sysdeps/unix/sysv/linux/oldglob.c b/sysdeps/unix/sysv/linux/oldglob.c |
| 16426 | new file mode 100644 |
| 16427 | index 0000000000..8233e57ce9 |
| 16428 | --- /dev/null |
| 16429 | +++ b/sysdeps/unix/sysv/linux/oldglob.c |
| 16430 | @@ -0,0 +1,42 @@ |
| 16431 | +#include <shlib-compat.h> |
| 16432 | + |
| 16433 | +#if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2) |
| 16434 | + |
| 16435 | +#include <dirent.h> |
| 16436 | +#include <glob.h> |
| 16437 | +#include <sys/stat.h> |
| 16438 | + |
| 16439 | +#include <sysdeps/unix/sysv/linux/i386/olddirent.h> |
| 16440 | + |
| 16441 | +int __old_glob64 (const char *__pattern, int __flags, |
| 16442 | + int (*__errfunc) (const char *, int), |
| 16443 | + glob64_t *__pglob); |
| 16444 | +libc_hidden_proto (__old_glob64); |
| 16445 | + |
| 16446 | +#define dirent __old_dirent64 |
| 16447 | +#define GL_READDIR(pglob, stream) \ |
| 16448 | + ((struct __old_dirent64 *) (pglob)->gl_readdir (stream)) |
| 16449 | +#undef __readdir |
| 16450 | +#define __readdir(dirp) __old_readdir64 (dirp) |
| 16451 | + |
| 16452 | +#define glob_t glob64_t |
| 16453 | +#define glob(pattern, flags, errfunc, pglob) \ |
| 16454 | + __old_glob64 (pattern, flags, errfunc, pglob) |
| 16455 | +#define globfree(pglob) globfree64(pglob) |
| 16456 | + |
| 16457 | +#define convert_dirent __old_convert_dirent |
| 16458 | +#define glob_in_dir __old_glob_in_dir |
| 16459 | + |
| 16460 | +#undef stat |
| 16461 | +#define stat stat64 |
| 16462 | +#undef __stat |
| 16463 | +#define __stat(file, buf) __xstat64 (_STAT_VER, file, buf) |
| 16464 | + |
| 16465 | +#define GLOB_ATTRIBUTE attribute_compat_text_section |
| 16466 | + |
| 16467 | +#include <posix/glob.c> |
| 16468 | + |
| 16469 | +libc_hidden_def (__old_glob64); |
| 16470 | + |
| 16471 | +compat_symbol (libc, __old_glob64, glob64, GLIBC_2_1); |
| 16472 | +#endif |
| 16473 | diff --git a/sysdeps/unix/sysv/linux/powerpc/Makefile b/sysdeps/unix/sysv/linux/powerpc/Makefile |
| 16474 | index c89ed9ec7d..2cfb46eca3 100644 |
| 16475 | --- a/sysdeps/unix/sysv/linux/powerpc/Makefile |
| 16476 | +++ b/sysdeps/unix/sysv/linux/powerpc/Makefile |
| 16477 | @@ -8,6 +8,7 @@ abi-64-v2-condition := __WORDSIZE == 64 && _CALL_ELF == 2 |
| 16478 | |
| 16479 | ifeq ($(subdir),rt) |
| 16480 | librt-routines += rt-sysdep |
| 16481 | +librt-shared-only-routines += rt-sysdep |
| 16482 | endif |
| 16483 | |
| 16484 | ifeq ($(subdir),stdlib) |
| 16485 | @@ -34,4 +35,5 @@ ifeq ($(subdir),nptl) |
| 16486 | libpthread-routines += sysdep |
| 16487 | libpthread-sysdep_routines += elision-lock elision-unlock elision-timed \ |
| 16488 | elision-trylock |
| 16489 | +libpthread-shared-only-routines += sysdep |
| 16490 | endif |
| 16491 | diff --git a/sysdeps/unix/sysv/linux/powerpc/elision-lock.c b/sysdeps/unix/sysv/linux/powerpc/elision-lock.c |
| 16492 | index dd1e4c3b17..7dd3d835b6 100644 |
| 16493 | --- a/sysdeps/unix/sysv/linux/powerpc/elision-lock.c |
| 16494 | +++ b/sysdeps/unix/sysv/linux/powerpc/elision-lock.c |
| 16495 | @@ -45,7 +45,9 @@ |
| 16496 | int |
| 16497 | __lll_lock_elision (int *lock, short *adapt_count, EXTRAARG int pshared) |
| 16498 | { |
| 16499 | - if (*adapt_count > 0) |
| 16500 | + /* adapt_count is accessed concurrently but is just a hint. Thus, |
| 16501 | + use atomic accesses but relaxed MO is sufficient. */ |
| 16502 | + if (atomic_load_relaxed (adapt_count) > 0) |
| 16503 | { |
| 16504 | goto use_lock; |
| 16505 | } |
| 16506 | @@ -67,7 +69,8 @@ __lll_lock_elision (int *lock, short *adapt_count, EXTRAARG int pshared) |
| 16507 | if (_TEXASRU_FAILURE_PERSISTENT (__builtin_get_texasru ())) |
| 16508 | { |
| 16509 | if (aconf.skip_lock_internal_abort > 0) |
| 16510 | - *adapt_count = aconf.skip_lock_internal_abort; |
| 16511 | + atomic_store_relaxed (adapt_count, |
| 16512 | + aconf.skip_lock_internal_abort); |
| 16513 | goto use_lock; |
| 16514 | } |
| 16515 | } |
| 16516 | @@ -75,7 +78,8 @@ __lll_lock_elision (int *lock, short *adapt_count, EXTRAARG int pshared) |
| 16517 | |
| 16518 | /* Fall back to locks for a bit if retries have been exhausted */ |
| 16519 | if (aconf.try_tbegin > 0 && aconf.skip_lock_out_of_tbegin_retries > 0) |
| 16520 | - *adapt_count = aconf.skip_lock_out_of_tbegin_retries; |
| 16521 | + atomic_store_relaxed (adapt_count, |
| 16522 | + aconf.skip_lock_out_of_tbegin_retries); |
| 16523 | |
| 16524 | use_lock: |
| 16525 | return LLL_LOCK ((*lock), pshared); |
| 16526 | diff --git a/sysdeps/unix/sysv/linux/powerpc/elision-trylock.c b/sysdeps/unix/sysv/linux/powerpc/elision-trylock.c |
| 16527 | index 0807a6a432..606185670d 100644 |
| 16528 | --- a/sysdeps/unix/sysv/linux/powerpc/elision-trylock.c |
| 16529 | +++ b/sysdeps/unix/sysv/linux/powerpc/elision-trylock.c |
| 16530 | @@ -34,7 +34,7 @@ __lll_trylock_elision (int *futex, short *adapt_count) |
| 16531 | __libc_tabort (_ABORT_NESTED_TRYLOCK); |
| 16532 | |
| 16533 | /* Only try a transaction if it's worth it. */ |
| 16534 | - if (*adapt_count > 0) |
| 16535 | + if (atomic_load_relaxed (adapt_count) > 0) |
| 16536 | { |
| 16537 | goto use_lock; |
| 16538 | } |
| 16539 | @@ -49,7 +49,7 @@ __lll_trylock_elision (int *futex, short *adapt_count) |
| 16540 | __libc_tend (0); |
| 16541 | |
| 16542 | if (aconf.skip_lock_busy > 0) |
| 16543 | - *adapt_count = aconf.skip_lock_busy; |
| 16544 | + atomic_store_relaxed (adapt_count, aconf.skip_lock_busy); |
| 16545 | } |
| 16546 | else |
| 16547 | { |
| 16548 | @@ -59,7 +59,8 @@ __lll_trylock_elision (int *futex, short *adapt_count) |
| 16549 | result in another failure. Use normal locking now and |
| 16550 | for the next couple of calls. */ |
| 16551 | if (aconf.skip_trylock_internal_abort > 0) |
| 16552 | - *adapt_count = aconf.skip_trylock_internal_abort; |
| 16553 | + atomic_store_relaxed (adapt_count, |
| 16554 | + aconf.skip_trylock_internal_abort); |
| 16555 | } |
| 16556 | } |
| 16557 | |
| 16558 | diff --git a/sysdeps/unix/sysv/linux/powerpc/elision-unlock.c b/sysdeps/unix/sysv/linux/powerpc/elision-unlock.c |
| 16559 | index 43c5a67df2..51d7018e4c 100644 |
| 16560 | --- a/sysdeps/unix/sysv/linux/powerpc/elision-unlock.c |
| 16561 | +++ b/sysdeps/unix/sysv/linux/powerpc/elision-unlock.c |
| 16562 | @@ -28,13 +28,16 @@ __lll_unlock_elision (int *lock, short *adapt_count, int pshared) |
| 16563 | __libc_tend (0); |
| 16564 | else |
| 16565 | { |
| 16566 | - lll_unlock ((*lock), pshared); |
| 16567 | + /* Update adapt_count in the critical section to prevent a |
| 16568 | + write-after-destroy error as mentioned in BZ 20822. The |
| 16569 | + following update of adapt_count has to be contained within |
| 16570 | + the critical region of the fall-back lock in order to not violate |
| 16571 | + the mutex destruction requirements. */ |
| 16572 | + short __tmp = atomic_load_relaxed (adapt_count); |
| 16573 | + if (__tmp > 0) |
| 16574 | + atomic_store_relaxed (adapt_count, __tmp - 1); |
| 16575 | |
| 16576 | - /* Update the adapt count AFTER completing the critical section. |
| 16577 | - Doing this here prevents unneeded stalling when entering |
| 16578 | - a critical section. Saving about 8% runtime on P8. */ |
| 16579 | - if (*adapt_count > 0) |
| 16580 | - (*adapt_count)--; |
| 16581 | + lll_unlock ((*lock), pshared); |
| 16582 | } |
| 16583 | return 0; |
| 16584 | } |
| 16585 | diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/clone.S b/sysdeps/unix/sysv/linux/powerpc/powerpc32/clone.S |
| 16586 | index bebadbfbb9..49fe01ecde 100644 |
| 16587 | --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/clone.S |
| 16588 | +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/clone.S |
| 16589 | @@ -76,15 +76,6 @@ ENTRY (__clone) |
| 16590 | crandc cr1*4+eq,cr1*4+eq,cr0*4+so |
| 16591 | bne- cr1,L(parent) /* The '-' is to minimise the race. */ |
| 16592 | |
| 16593 | - /* If CLONE_VM is set do not update the pid/tid field. */ |
| 16594 | - andi. r0,r28,CLONE_VM |
| 16595 | - bne+ cr0,L(oldpid) |
| 16596 | - |
| 16597 | - DO_CALL(SYS_ify(getpid)) |
| 16598 | - stw r3,TID(r2) |
| 16599 | - stw r3,PID(r2) |
| 16600 | -L(oldpid): |
| 16601 | - |
| 16602 | /* Call procedure. */ |
| 16603 | mtctr r30 |
| 16604 | mr r3,r31 |
| 16605 | diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/vfork.S b/sysdeps/unix/sysv/linux/powerpc/powerpc32/vfork.S |
| 16606 | index edbc7de1e6..0a724953a4 100644 |
| 16607 | --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/vfork.S |
| 16608 | +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/vfork.S |
| 16609 | @@ -27,34 +27,8 @@ |
| 16610 | |
| 16611 | ENTRY (__vfork) |
| 16612 | |
| 16613 | - /* Load the TCB-cached PID value and negates it. If It it is zero |
| 16614 | - sets it to 0x800000. And then sets its value again on TCB field. |
| 16615 | - See raise.c for the logic that relies on this value. */ |
| 16616 | - |
| 16617 | - lwz r0,PID(r2) |
| 16618 | - cmpwi cr0,r0,0 |
| 16619 | - neg r0,r0 |
| 16620 | - bne- cr0,1f |
| 16621 | - lis r0,0x8000 |
| 16622 | -1: stw r0,PID(r2) |
| 16623 | - |
| 16624 | DO_CALL (SYS_ify (vfork)) |
| 16625 | |
| 16626 | - cmpwi cr1,r3,0 |
| 16627 | - beqlr- 1 |
| 16628 | - |
| 16629 | - /* Restore the original value of the TCB cache of the PID, if we're |
| 16630 | - the parent. But in the child (syscall return value equals zero), |
| 16631 | - leave things as they are. */ |
| 16632 | - lwz r0,PID(r2) |
| 16633 | - /* Cannot use clrlwi. here, because cr0 needs to be preserved |
| 16634 | - until PSEUDO_RET. */ |
| 16635 | - clrlwi r4,r0,1 |
| 16636 | - cmpwi cr1,r4,0 |
| 16637 | - beq- cr1,1f |
| 16638 | - neg r4,r0 |
| 16639 | -1: stw r4,PID(r2) |
| 16640 | - |
| 16641 | PSEUDO_RET |
| 16642 | |
| 16643 | PSEUDO_END (__vfork) |
| 16644 | diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S b/sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S |
| 16645 | index 7c59b9b4e9..d8604f6731 100644 |
| 16646 | --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S |
| 16647 | +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S |
| 16648 | @@ -78,15 +78,6 @@ ENTRY (__clone) |
| 16649 | crandc cr1*4+eq,cr1*4+eq,cr0*4+so |
| 16650 | bne- cr1,L(parent) /* The '-' is to minimise the race. */ |
| 16651 | |
| 16652 | - /* If CLONE_VM is set do not update the pid/tid field. */ |
| 16653 | - rldicl. r0,r29,56,63 /* flags & CLONE_VM. */ |
| 16654 | - bne+ cr0,L(oldpid) |
| 16655 | - |
| 16656 | - DO_CALL(SYS_ify(getpid)) |
| 16657 | - stw r3,TID(r13) |
| 16658 | - stw r3,PID(r13) |
| 16659 | -L(oldpid): |
| 16660 | - |
| 16661 | std r2,FRAME_TOC_SAVE(r1) |
| 16662 | /* Call procedure. */ |
| 16663 | PPC64_LOAD_FUNCPTR r30 |
| 16664 | diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/vfork.S b/sysdeps/unix/sysv/linux/powerpc/powerpc64/vfork.S |
| 16665 | index 3083ab7b3c..6b4cf432c1 100644 |
| 16666 | --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/vfork.S |
| 16667 | +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/vfork.S |
| 16668 | @@ -28,31 +28,8 @@ |
| 16669 | ENTRY (__vfork) |
| 16670 | CALL_MCOUNT 0 |
| 16671 | |
| 16672 | - /* Load the TCB-cached PID value and negates it. If It it is zero |
| 16673 | - sets it to 0x800000. And then sets its value again on TCB field. |
| 16674 | - See raise.c for the logic that relies on this value. */ |
| 16675 | - lwz r0,PID(r13) |
| 16676 | - cmpwi cr0,r0,0 |
| 16677 | - neg r0,r0 |
| 16678 | - bne- cr0,1f |
| 16679 | - lis r0,0x8000 |
| 16680 | -1: stw r0,PID(r13) |
| 16681 | - |
| 16682 | DO_CALL (SYS_ify (vfork)) |
| 16683 | |
| 16684 | - cmpwi cr1,r3,0 |
| 16685 | - beqlr- 1 |
| 16686 | - |
| 16687 | - /* Restore the original value of the TCB cache of the PID, if we're |
| 16688 | - the parent. But in the child (syscall return value equals zero), |
| 16689 | - leave things as they are. */ |
| 16690 | - lwz r0,PID(r13) |
| 16691 | - clrlwi r4,r0,1 |
| 16692 | - cmpwi cr1,r4,0 |
| 16693 | - beq- cr1,1f |
| 16694 | - neg r4,r0 |
| 16695 | -1: stw r4,PID(r13) |
| 16696 | - |
| 16697 | PSEUDO_RET |
| 16698 | |
| 16699 | PSEUDO_END (__vfork) |
| 16700 | diff --git a/sysdeps/unix/sysv/linux/pread.c b/sysdeps/unix/sysv/linux/pread.c |
| 16701 | index 1bcff64781..46d974d952 100644 |
| 16702 | --- a/sysdeps/unix/sysv/linux/pread.c |
| 16703 | +++ b/sysdeps/unix/sysv/linux/pread.c |
| 16704 | @@ -28,8 +28,7 @@ |
| 16705 | ssize_t |
| 16706 | __libc_pread (int fd, void *buf, size_t count, off_t offset) |
| 16707 | { |
| 16708 | - return SYSCALL_CANCEL (pread, fd, buf, count, |
| 16709 | - __ALIGNMENT_ARG SYSCALL_LL (offset)); |
| 16710 | + return SYSCALL_CANCEL (pread, fd, buf, count, SYSCALL_LL_PRW (offset)); |
| 16711 | } |
| 16712 | |
| 16713 | strong_alias (__libc_pread, __pread) |
| 16714 | diff --git a/sysdeps/unix/sysv/linux/pread64.c b/sysdeps/unix/sysv/linux/pread64.c |
| 16715 | index 58c6aeb541..f51beae77a 100644 |
| 16716 | --- a/sysdeps/unix/sysv/linux/pread64.c |
| 16717 | +++ b/sysdeps/unix/sysv/linux/pread64.c |
| 16718 | @@ -26,8 +26,7 @@ |
| 16719 | ssize_t |
| 16720 | __libc_pread64 (int fd, void *buf, size_t count, off64_t offset) |
| 16721 | { |
| 16722 | - return SYSCALL_CANCEL (pread64, fd, buf, count, |
| 16723 | - __ALIGNMENT_ARG SYSCALL_LL64 (offset)); |
| 16724 | + return SYSCALL_CANCEL (pread64, fd, buf, count, SYSCALL_LL64_PRW (offset)); |
| 16725 | } |
| 16726 | |
| 16727 | weak_alias (__libc_pread64, __pread64) |
| 16728 | diff --git a/sysdeps/unix/sysv/linux/pthread-pids.h b/sysdeps/unix/sysv/linux/pthread-pids.h |
| 16729 | index d42bba03cf..618a5b1b9f 100644 |
| 16730 | --- a/sysdeps/unix/sysv/linux/pthread-pids.h |
| 16731 | +++ b/sysdeps/unix/sysv/linux/pthread-pids.h |
| 16732 | @@ -26,5 +26,5 @@ static inline void |
| 16733 | __pthread_initialize_pids (struct pthread *pd) |
| 16734 | { |
| 16735 | INTERNAL_SYSCALL_DECL (err); |
| 16736 | - pd->pid = pd->tid = INTERNAL_SYSCALL (set_tid_address, err, 1, &pd->tid); |
| 16737 | + pd->tid = INTERNAL_SYSCALL_CALL (set_tid_address, err, &pd->tid); |
| 16738 | } |
| 16739 | diff --git a/sysdeps/unix/sysv/linux/pthread_kill.c b/sysdeps/unix/sysv/linux/pthread_kill.c |
| 16740 | index bcb3009675..cc109973cc 100644 |
| 16741 | --- a/sysdeps/unix/sysv/linux/pthread_kill.c |
| 16742 | +++ b/sysdeps/unix/sysv/linux/pthread_kill.c |
| 16743 | @@ -21,6 +21,7 @@ |
| 16744 | #include <pthreadP.h> |
| 16745 | #include <tls.h> |
| 16746 | #include <sysdep.h> |
| 16747 | +#include <unistd.h> |
| 16748 | |
| 16749 | |
| 16750 | int |
| 16751 | @@ -49,15 +50,9 @@ __pthread_kill (pthread_t threadid, int signo) |
| 16752 | /* We have a special syscall to do the work. */ |
| 16753 | INTERNAL_SYSCALL_DECL (err); |
| 16754 | |
| 16755 | - /* One comment: The PID field in the TCB can temporarily be changed |
| 16756 | - (in fork). But this must not affect this code here. Since this |
| 16757 | - function would have to be called while the thread is executing |
| 16758 | - fork, it would have to happen in a signal handler. But this is |
| 16759 | - no allowed, pthread_kill is not guaranteed to be async-safe. */ |
| 16760 | - int val; |
| 16761 | - val = INTERNAL_SYSCALL (tgkill, err, 3, THREAD_GETMEM (THREAD_SELF, pid), |
| 16762 | - tid, signo); |
| 16763 | + pid_t pid = __getpid (); |
| 16764 | |
| 16765 | + int val = INTERNAL_SYSCALL_CALL (tgkill, err, pid, tid, signo); |
| 16766 | return (INTERNAL_SYSCALL_ERROR_P (val, err) |
| 16767 | ? INTERNAL_SYSCALL_ERRNO (val, err) : 0); |
| 16768 | } |
| 16769 | diff --git a/sysdeps/unix/sysv/linux/pthread_sigqueue.c b/sysdeps/unix/sysv/linux/pthread_sigqueue.c |
| 16770 | index 7694d5467c..e393e0bd73 100644 |
| 16771 | --- a/sysdeps/unix/sysv/linux/pthread_sigqueue.c |
| 16772 | +++ b/sysdeps/unix/sysv/linux/pthread_sigqueue.c |
| 16773 | @@ -49,27 +49,22 @@ pthread_sigqueue (pthread_t threadid, int signo, const union sigval value) |
| 16774 | if (signo == SIGCANCEL || signo == SIGTIMER || signo == SIGSETXID) |
| 16775 | return EINVAL; |
| 16776 | |
| 16777 | + pid_t pid = getpid (); |
| 16778 | + |
| 16779 | /* Set up the siginfo_t structure. */ |
| 16780 | siginfo_t info; |
| 16781 | memset (&info, '\0', sizeof (siginfo_t)); |
| 16782 | info.si_signo = signo; |
| 16783 | info.si_code = SI_QUEUE; |
| 16784 | - info.si_pid = THREAD_GETMEM (THREAD_SELF, pid); |
| 16785 | + info.si_pid = pid; |
| 16786 | info.si_uid = getuid (); |
| 16787 | info.si_value = value; |
| 16788 | |
| 16789 | /* We have a special syscall to do the work. */ |
| 16790 | INTERNAL_SYSCALL_DECL (err); |
| 16791 | |
| 16792 | - /* One comment: The PID field in the TCB can temporarily be changed |
| 16793 | - (in fork). But this must not affect this code here. Since this |
| 16794 | - function would have to be called while the thread is executing |
| 16795 | - fork, it would have to happen in a signal handler. But this is |
| 16796 | - no allowed, pthread_sigqueue is not guaranteed to be async-safe. */ |
| 16797 | - int val = INTERNAL_SYSCALL (rt_tgsigqueueinfo, err, 4, |
| 16798 | - THREAD_GETMEM (THREAD_SELF, pid), |
| 16799 | - tid, signo, &info); |
| 16800 | - |
| 16801 | + int val = INTERNAL_SYSCALL_CALL (rt_tgsigqueueinfo, err, pid, tid, signo, |
| 16802 | + &info); |
| 16803 | return (INTERNAL_SYSCALL_ERROR_P (val, err) |
| 16804 | ? INTERNAL_SYSCALL_ERRNO (val, err) : 0); |
| 16805 | #else |
| 16806 | diff --git a/sysdeps/unix/sysv/linux/pwrite.c b/sysdeps/unix/sysv/linux/pwrite.c |
| 16807 | index 9c502beac1..1371df8a60 100644 |
| 16808 | --- a/sysdeps/unix/sysv/linux/pwrite.c |
| 16809 | +++ b/sysdeps/unix/sysv/linux/pwrite.c |
| 16810 | @@ -28,8 +28,7 @@ |
| 16811 | ssize_t |
| 16812 | __libc_pwrite (int fd, const void *buf, size_t count, off_t offset) |
| 16813 | { |
| 16814 | - return SYSCALL_CANCEL (pwrite, fd, buf, count, |
| 16815 | - __ALIGNMENT_ARG SYSCALL_LL (offset)); |
| 16816 | + return SYSCALL_CANCEL (pwrite, fd, buf, count, SYSCALL_LL_PRW (offset)); |
| 16817 | } |
| 16818 | |
| 16819 | strong_alias (__libc_pwrite, __pwrite) |
| 16820 | diff --git a/sysdeps/unix/sysv/linux/pwrite64.c b/sysdeps/unix/sysv/linux/pwrite64.c |
| 16821 | index b49e6bc286..22f1f05a44 100644 |
| 16822 | --- a/sysdeps/unix/sysv/linux/pwrite64.c |
| 16823 | +++ b/sysdeps/unix/sysv/linux/pwrite64.c |
| 16824 | @@ -26,8 +26,7 @@ |
| 16825 | ssize_t |
| 16826 | __libc_pwrite64 (int fd, const void *buf, size_t count, off64_t offset) |
| 16827 | { |
| 16828 | - return SYSCALL_CANCEL (pwrite64, fd, buf, count, |
| 16829 | - __ALIGNMENT_ARG SYSCALL_LL64 (offset)); |
| 16830 | + return SYSCALL_CANCEL (pwrite64, fd, buf, count, SYSCALL_LL64_PRW (offset)); |
| 16831 | } |
| 16832 | weak_alias (__libc_pwrite64, __pwrite64) |
| 16833 | libc_hidden_weak (__pwrite64) |
| 16834 | diff --git a/sysdeps/unix/sysv/linux/raise.c b/sysdeps/unix/sysv/linux/raise.c |
| 16835 | index 470033e83d..49bb7cb0d4 100644 |
| 16836 | --- a/sysdeps/unix/sysv/linux/raise.c |
| 16837 | +++ b/sysdeps/unix/sysv/linux/raise.c |
| 16838 | @@ -26,13 +26,6 @@ |
| 16839 | int |
| 16840 | raise (int sig) |
| 16841 | { |
| 16842 | - /* raise is an async-safe function so it could be called while the |
| 16843 | - fork/vfork function temporarily invalidated the PID field. To avoid |
| 16844 | - relying on cached value we block all user-defined signal handler |
| 16845 | - (which might call fork/vfork) and issue the getpid and gettid |
| 16846 | - syscalls directly. */ |
| 16847 | - |
| 16848 | - |
| 16849 | /* rt_sigprocmask may fail if: |
| 16850 | |
| 16851 | 1. sigsetsize != sizeof (sigset_t) (EINVAL) |
| 16852 | diff --git a/sysdeps/unix/sysv/linux/s390/Makefile b/sysdeps/unix/sysv/linux/s390/Makefile |
| 16853 | index 497ffd566c..f8ed013e9e 100644 |
| 16854 | --- a/sysdeps/unix/sysv/linux/s390/Makefile |
| 16855 | +++ b/sysdeps/unix/sysv/linux/s390/Makefile |
| 16856 | @@ -6,6 +6,7 @@ abi-64-condition := __WORDSIZE == 64 |
| 16857 | |
| 16858 | ifeq ($(subdir),rt) |
| 16859 | librt-routines += rt-sysdep |
| 16860 | +librt-shared-only-routines += rt-sysdep |
| 16861 | endif |
| 16862 | |
| 16863 | ifeq ($(subdir),stdlib) |
| 16864 | diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/clone.S b/sysdeps/unix/sysv/linux/s390/s390-32/clone.S |
| 16865 | index 2f8fa0b840..b1de1480d1 100644 |
| 16866 | --- a/sysdeps/unix/sysv/linux/s390/s390-32/clone.S |
| 16867 | +++ b/sysdeps/unix/sysv/linux/s390/s390-32/clone.S |
| 16868 | @@ -54,13 +54,6 @@ error: |
| 16869 | PSEUDO_END (__clone) |
| 16870 | |
| 16871 | thread_start: |
| 16872 | - tml %r3,256 /* CLONE_VM == 0x00000100 */ |
| 16873 | - jne 1f |
| 16874 | - svc SYS_ify(getpid) |
| 16875 | - ear %r3,%a0 |
| 16876 | - st %r2,PID(%r3) |
| 16877 | - st %r2,TID(%r3) |
| 16878 | -1: |
| 16879 | /* fn is in gpr 1, arg in gpr 0 */ |
| 16880 | lr %r2,%r0 /* set first parameter to void *arg */ |
| 16881 | ahi %r15,-96 /* make room on the stack for the save area */ |
| 16882 | diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/vfork.S b/sysdeps/unix/sysv/linux/s390/s390-32/vfork.S |
| 16883 | index b7588ebd7c..cc60e139ba 100644 |
| 16884 | --- a/sysdeps/unix/sysv/linux/s390/s390-32/vfork.S |
| 16885 | +++ b/sysdeps/unix/sysv/linux/s390/s390-32/vfork.S |
| 16886 | @@ -28,21 +28,9 @@ |
| 16887 | and the process ID of the new process to the old process. */ |
| 16888 | |
| 16889 | ENTRY (__libc_vfork) |
| 16890 | - ear %r4,%a0 |
| 16891 | - lhi %r1,1 |
| 16892 | - icm %r3,15,PID(%r4) |
| 16893 | - sll %r1,31 |
| 16894 | - je 1f |
| 16895 | - lcr %r1,%r3 |
| 16896 | -1: st %r1,PID(%r4) |
| 16897 | - |
| 16898 | /* Do vfork system call. */ |
| 16899 | svc SYS_ify (vfork) |
| 16900 | |
| 16901 | - ltr %r2,%r2 |
| 16902 | - je 1f |
| 16903 | - st %r3,PID(%r4) |
| 16904 | -1: |
| 16905 | /* Check for error. */ |
| 16906 | lhi %r4,-4095 |
| 16907 | clr %r2,%r4 |
| 16908 | diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/clone.S b/sysdeps/unix/sysv/linux/s390/s390-64/clone.S |
| 16909 | index fb816922ca..29606acf03 100644 |
| 16910 | --- a/sysdeps/unix/sysv/linux/s390/s390-64/clone.S |
| 16911 | +++ b/sysdeps/unix/sysv/linux/s390/s390-64/clone.S |
| 16912 | @@ -55,15 +55,6 @@ error: |
| 16913 | PSEUDO_END (__clone) |
| 16914 | |
| 16915 | thread_start: |
| 16916 | - tmll %r3,256 /* CLONE_VM == 0x00000100 */ |
| 16917 | - jne 1f |
| 16918 | - svc SYS_ify(getpid) |
| 16919 | - ear %r3,%a0 |
| 16920 | - sllg %r3,%r3,32 |
| 16921 | - ear %r3,%a1 |
| 16922 | - st %r2,PID(%r3) |
| 16923 | - st %r2,TID(%r3) |
| 16924 | -1: |
| 16925 | /* fn is in gpr 1, arg in gpr 0 */ |
| 16926 | lgr %r2,%r0 /* set first parameter to void *arg */ |
| 16927 | aghi %r15,-160 /* make room on the stack for the save area */ |
| 16928 | diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/vfork.S b/sysdeps/unix/sysv/linux/s390/s390-64/vfork.S |
| 16929 | index 0bd2161381..b9a813f2cc 100644 |
| 16930 | --- a/sysdeps/unix/sysv/linux/s390/s390-64/vfork.S |
| 16931 | +++ b/sysdeps/unix/sysv/linux/s390/s390-64/vfork.S |
| 16932 | @@ -28,22 +28,9 @@ |
| 16933 | and the process ID of the new process to the old process. */ |
| 16934 | |
| 16935 | ENTRY (__libc_vfork) |
| 16936 | - ear %r4,%a0 |
| 16937 | - sllg %r4,%r4,32 |
| 16938 | - ear %r4,%a1 |
| 16939 | - icm %r3,15,PID(%r4) |
| 16940 | - llilh %r1,32768 |
| 16941 | - je 1f |
| 16942 | - lcr %r1,%r3 |
| 16943 | -1: st %r1,PID(%r4) |
| 16944 | - |
| 16945 | /* Do vfork system call. */ |
| 16946 | svc SYS_ify (vfork) |
| 16947 | |
| 16948 | - ltgr %r2,%r2 |
| 16949 | - je 1f |
| 16950 | - st %r3,PID(%r4) |
| 16951 | -1: |
| 16952 | /* Check for error. */ |
| 16953 | lghi %r4,-4095 |
| 16954 | clgr %r2,%r4 |
| 16955 | diff --git a/sysdeps/unix/sysv/linux/sh/clone.S b/sysdeps/unix/sysv/linux/sh/clone.S |
| 16956 | index 4cd7df117c..ce7cddcb19 100644 |
| 16957 | --- a/sysdeps/unix/sysv/linux/sh/clone.S |
| 16958 | +++ b/sysdeps/unix/sysv/linux/sh/clone.S |
| 16959 | @@ -66,23 +66,7 @@ ENTRY(__clone) |
| 16960 | 2: |
| 16961 | /* terminate the stack frame */ |
| 16962 | mov #0, r14 |
| 16963 | - mov r4, r0 |
| 16964 | - shlr8 r0 |
| 16965 | - tst #1, r0 // CLONE_VM = (1 << 8) |
| 16966 | - bf/s 4f |
| 16967 | - mov r4, r0 |
| 16968 | - /* new pid */ |
| 16969 | - mov #+SYS_ify(getpid), r3 |
| 16970 | - trapa #0x15 |
| 16971 | -3: |
| 16972 | - stc gbr, r1 |
| 16973 | - mov.w .Lpidoff, r2 |
| 16974 | - add r1, r2 |
| 16975 | - mov.l r0, @r2 |
| 16976 | - mov.w .Ltidoff, r2 |
| 16977 | - add r1, r2 |
| 16978 | - mov.l r0, @r2 |
| 16979 | -4: |
| 16980 | + |
| 16981 | /* thread starts */ |
| 16982 | mov.l @r15, r1 |
| 16983 | jsr @r1 |
| 16984 | @@ -113,10 +97,6 @@ ENTRY(__clone) |
| 16985 | .long _GLOBAL_OFFSET_TABLE_ |
| 16986 | .L3: |
| 16987 | .long PLTJMP(C_SYMBOL_NAME(_exit)) |
| 16988 | -.Lpidoff: |
| 16989 | - .word PID - TLS_PRE_TCB_SIZE |
| 16990 | -.Ltidoff: |
| 16991 | - .word TID - TLS_PRE_TCB_SIZE |
| 16992 | PSEUDO_END (__clone) |
| 16993 | |
| 16994 | libc_hidden_def (__clone) |
| 16995 | diff --git a/sysdeps/unix/sysv/linux/sh/kernel-features.h b/sysdeps/unix/sysv/linux/sh/kernel-features.h |
| 16996 | index ad05fc39e1..c5240fafbd 100644 |
| 16997 | --- a/sysdeps/unix/sysv/linux/sh/kernel-features.h |
| 16998 | +++ b/sysdeps/unix/sysv/linux/sh/kernel-features.h |
| 16999 | @@ -44,3 +44,8 @@ |
| 17000 | |
| 17001 | /* SH does not have a 64-bit inode field. */ |
| 17002 | #undef __ASSUME_ST_INO_64_BIT |
| 17003 | + |
| 17004 | +/* SH4 ABI does not really require argument alignment for 64-bits, but |
| 17005 | + the kernel interface for p{read,write}64 adds a dummy long argument |
| 17006 | + before the offset. */ |
| 17007 | +#define __ASSUME_PRW_DUMMY_ARG 1 |
| 17008 | diff --git a/sysdeps/unix/sysv/linux/sh/pwrite.c b/sysdeps/unix/sysv/linux/sh/pwrite.c |
| 17009 | deleted file mode 100644 |
| 17010 | index 391ed5e17b..0000000000 |
| 17011 | --- a/sysdeps/unix/sysv/linux/sh/pwrite.c |
| 17012 | +++ /dev/null |
| 17013 | @@ -1,23 +0,0 @@ |
| 17014 | -/* Copyright (C) 1997-2016 Free Software Foundation, Inc. |
| 17015 | - This file is part of the GNU C Library. |
| 17016 | - Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. |
| 17017 | - |
| 17018 | - The GNU C Library is free software; you can redistribute it and/or |
| 17019 | - modify it under the terms of the GNU Lesser General Public |
| 17020 | - License as published by the Free Software Foundation; either |
| 17021 | - version 2.1 of the License, or (at your option) any later version. |
| 17022 | - |
| 17023 | - The GNU C Library is distributed in the hope that it will be useful, |
| 17024 | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17025 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17026 | - Lesser General Public License for more details. |
| 17027 | - |
| 17028 | - You should have received a copy of the GNU Lesser General Public |
| 17029 | - License along with the GNU C Library; if not, see |
| 17030 | - <http://www.gnu.org/licenses/>. */ |
| 17031 | - |
| 17032 | -/* SH4 ABI does not really require argument alignment for 64-bits, but |
| 17033 | - the kernel interface for pwrite adds a dummy long argument before the |
| 17034 | - offset. */ |
| 17035 | -#define __ALIGNMENT_ARG |
| 17036 | -#include <sysdeps/unix/sysv/linux/pwrite.c> |
| 17037 | diff --git a/sysdeps/unix/sysv/linux/sh/sh3/ucontext_i.sym b/sysdeps/unix/sysv/linux/sh/sh3/ucontext_i.sym |
| 17038 | index 17397c5511..25f914a93b 100644 |
| 17039 | --- a/sysdeps/unix/sysv/linux/sh/sh3/ucontext_i.sym |
| 17040 | +++ b/sysdeps/unix/sysv/linux/sh/sh3/ucontext_i.sym |
| 17041 | @@ -13,22 +13,22 @@ SIG_SETMASK |
| 17042 | oLINK ucontext (uc_link) |
| 17043 | oSS_SP ucontext (uc_stack.ss_sp) |
| 17044 | oSS_SIZE ucontext (uc_stack.ss_size) |
| 17045 | -oR0 mcontext (gregs[R0]) |
| 17046 | -oR1 mcontext (gregs[R1]) |
| 17047 | -oR2 mcontext (gregs[R2]) |
| 17048 | -oR3 mcontext (gregs[R3]) |
| 17049 | -oR4 mcontext (gregs[R4]) |
| 17050 | -oR5 mcontext (gregs[R5]) |
| 17051 | -oR6 mcontext (gregs[R6]) |
| 17052 | -oR7 mcontext (gregs[R7]) |
| 17053 | -oR8 mcontext (gregs[R8]) |
| 17054 | -oR9 mcontext (gregs[R9]) |
| 17055 | -oR10 mcontext (gregs[R10]) |
| 17056 | -oR11 mcontext (gregs[R11]) |
| 17057 | -oR12 mcontext (gregs[R12]) |
| 17058 | -oR13 mcontext (gregs[R13]) |
| 17059 | -oR14 mcontext (gregs[R14]) |
| 17060 | -oR15 mcontext (gregs[R15]) |
| 17061 | +oR0 mcontext (gregs[REG_R0]) |
| 17062 | +oR1 mcontext (gregs[REG_R1]) |
| 17063 | +oR2 mcontext (gregs[REG_R2]) |
| 17064 | +oR3 mcontext (gregs[REG_R3]) |
| 17065 | +oR4 mcontext (gregs[REG_R4]) |
| 17066 | +oR5 mcontext (gregs[REG_R5]) |
| 17067 | +oR6 mcontext (gregs[REG_R6]) |
| 17068 | +oR7 mcontext (gregs[REG_R7]) |
| 17069 | +oR8 mcontext (gregs[REG_R8]) |
| 17070 | +oR9 mcontext (gregs[REG_R9]) |
| 17071 | +oR10 mcontext (gregs[REG_R10]) |
| 17072 | +oR11 mcontext (gregs[REG_R11]) |
| 17073 | +oR12 mcontext (gregs[REG_R12]) |
| 17074 | +oR13 mcontext (gregs[REG_R13]) |
| 17075 | +oR14 mcontext (gregs[REG_R14]) |
| 17076 | +oR15 mcontext (gregs[REG_R15]) |
| 17077 | oPC mcontext (pc) |
| 17078 | oPR mcontext (pr) |
| 17079 | oSR mcontext (sr) |
| 17080 | diff --git a/sysdeps/unix/sysv/linux/sh/sh4/ucontext_i.sym b/sysdeps/unix/sysv/linux/sh/sh4/ucontext_i.sym |
| 17081 | index 65633fbcf4..130f60cd96 100644 |
| 17082 | --- a/sysdeps/unix/sysv/linux/sh/sh4/ucontext_i.sym |
| 17083 | +++ b/sysdeps/unix/sysv/linux/sh/sh4/ucontext_i.sym |
| 17084 | @@ -13,22 +13,22 @@ SIG_SETMASK |
| 17085 | oLINK ucontext (uc_link) |
| 17086 | oSS_SP ucontext (uc_stack.ss_sp) |
| 17087 | oSS_SIZE ucontext (uc_stack.ss_size) |
| 17088 | -oR0 mcontext (gregs[R0]) |
| 17089 | -oR1 mcontext (gregs[R1]) |
| 17090 | -oR2 mcontext (gregs[R2]) |
| 17091 | -oR3 mcontext (gregs[R3]) |
| 17092 | -oR4 mcontext (gregs[R4]) |
| 17093 | -oR5 mcontext (gregs[R5]) |
| 17094 | -oR6 mcontext (gregs[R6]) |
| 17095 | -oR7 mcontext (gregs[R7]) |
| 17096 | -oR8 mcontext (gregs[R8]) |
| 17097 | -oR9 mcontext (gregs[R9]) |
| 17098 | -oR10 mcontext (gregs[R10]) |
| 17099 | -oR11 mcontext (gregs[R11]) |
| 17100 | -oR12 mcontext (gregs[R12]) |
| 17101 | -oR13 mcontext (gregs[R13]) |
| 17102 | -oR14 mcontext (gregs[R14]) |
| 17103 | -oR15 mcontext (gregs[R15]) |
| 17104 | +oR0 mcontext (gregs[REG_R0]) |
| 17105 | +oR1 mcontext (gregs[REG_R1]) |
| 17106 | +oR2 mcontext (gregs[REG_R2]) |
| 17107 | +oR3 mcontext (gregs[REG_R3]) |
| 17108 | +oR4 mcontext (gregs[REG_R4]) |
| 17109 | +oR5 mcontext (gregs[REG_R5]) |
| 17110 | +oR6 mcontext (gregs[REG_R6]) |
| 17111 | +oR7 mcontext (gregs[REG_R7]) |
| 17112 | +oR8 mcontext (gregs[REG_R8]) |
| 17113 | +oR9 mcontext (gregs[REG_R9]) |
| 17114 | +oR10 mcontext (gregs[REG_R10]) |
| 17115 | +oR11 mcontext (gregs[REG_R11]) |
| 17116 | +oR12 mcontext (gregs[REG_R12]) |
| 17117 | +oR13 mcontext (gregs[REG_R13]) |
| 17118 | +oR14 mcontext (gregs[REG_R14]) |
| 17119 | +oR15 mcontext (gregs[REG_R15]) |
| 17120 | oPC mcontext (pc) |
| 17121 | oPR mcontext (pr) |
| 17122 | oSR mcontext (sr) |
| 17123 | diff --git a/sysdeps/unix/sysv/linux/sh/sys/ucontext.h b/sysdeps/unix/sysv/linux/sh/sys/ucontext.h |
| 17124 | index ab9a7e66bf..037fbb73e8 100644 |
| 17125 | --- a/sysdeps/unix/sysv/linux/sh/sys/ucontext.h |
| 17126 | +++ b/sysdeps/unix/sysv/linux/sh/sys/ucontext.h |
| 17127 | @@ -31,49 +31,47 @@ |
| 17128 | typedef int greg_t; |
| 17129 | |
| 17130 | /* Number of general registers. */ |
| 17131 | -#define NGPREG 16 |
| 17132 | +#define NGREG 16 |
| 17133 | |
| 17134 | /* Container for all general registers. */ |
| 17135 | -typedef greg_t gregset_t[NGPREG]; |
| 17136 | +typedef greg_t gregset_t[NGREG]; |
| 17137 | |
| 17138 | -#ifdef __USE_GNU |
| 17139 | /* Number of each register is the `gregset_t' array. */ |
| 17140 | enum |
| 17141 | { |
| 17142 | - R0 = 0, |
| 17143 | -#define R0 R0 |
| 17144 | - R1 = 1, |
| 17145 | -#define R1 R1 |
| 17146 | - R2 = 2, |
| 17147 | -#define R2 R2 |
| 17148 | - R3 = 3, |
| 17149 | -#define R3 R3 |
| 17150 | - R4 = 4, |
| 17151 | -#define R4 R4 |
| 17152 | - R5 = 5, |
| 17153 | -#define R5 R5 |
| 17154 | - R6 = 6, |
| 17155 | -#define R6 R6 |
| 17156 | - R7 = 7, |
| 17157 | -#define R7 R7 |
| 17158 | - R8 = 8, |
| 17159 | -#define R8 R8 |
| 17160 | - R9 = 9, |
| 17161 | -#define R9 R9 |
| 17162 | - R10 = 10, |
| 17163 | -#define R10 R10 |
| 17164 | - R11 = 11, |
| 17165 | -#define R11 R11 |
| 17166 | - R12 = 12, |
| 17167 | -#define R12 R12 |
| 17168 | - R13 = 13, |
| 17169 | -#define R13 R13 |
| 17170 | - R14 = 14, |
| 17171 | -#define R14 R14 |
| 17172 | - R15 = 15, |
| 17173 | -#define R15 R15 |
| 17174 | + REG_R0 = 0, |
| 17175 | +#define REG_R0 REG_R0 |
| 17176 | + REG_R1 = 1, |
| 17177 | +#define REG_R1 REG_R1 |
| 17178 | + REG_R2 = 2, |
| 17179 | +#define REG_R2 REG_R2 |
| 17180 | + REG_R3 = 3, |
| 17181 | +#define REG_R3 REG_R3 |
| 17182 | + REG_R4 = 4, |
| 17183 | +#define REG_R4 REG_R4 |
| 17184 | + REG_R5 = 5, |
| 17185 | +#define REG_R5 REG_R5 |
| 17186 | + REG_R6 = 6, |
| 17187 | +#define REG_R6 REG_R6 |
| 17188 | + REG_R7 = 7, |
| 17189 | +#define REG_R7 REG_R7 |
| 17190 | + REG_R8 = 8, |
| 17191 | +#define REG_R8 REG_R8 |
| 17192 | + REG_R9 = 9, |
| 17193 | +#define REG_R9 REG_R9 |
| 17194 | + REG_R10 = 10, |
| 17195 | +#define REG_R10 REG_R10 |
| 17196 | + REG_R11 = 11, |
| 17197 | +#define REG_R11 REG_R11 |
| 17198 | + REG_R12 = 12, |
| 17199 | +#define REG_R12 REG_R12 |
| 17200 | + REG_R13 = 13, |
| 17201 | +#define REG_R13 REG_R13 |
| 17202 | + REG_R14 = 14, |
| 17203 | +#define REG_R14 REG_R14 |
| 17204 | + REG_R15 = 15, |
| 17205 | +#define REG_R15 REG_R15 |
| 17206 | }; |
| 17207 | -#endif |
| 17208 | |
| 17209 | #if (defined(__SH4__) || defined(__SH4A__)) |
| 17210 | typedef int freg_t; |
| 17211 | diff --git a/sysdeps/unix/sysv/linux/sh/vfork.S b/sysdeps/unix/sysv/linux/sh/vfork.S |
| 17212 | index 6895bc5491..df559cb439 100644 |
| 17213 | --- a/sysdeps/unix/sysv/linux/sh/vfork.S |
| 17214 | +++ b/sysdeps/unix/sysv/linux/sh/vfork.S |
| 17215 | @@ -26,30 +26,11 @@ |
| 17216 | and the process ID of the new process to the old process. */ |
| 17217 | |
| 17218 | ENTRY (__libc_vfork) |
| 17219 | - /* Save the PID value. */ |
| 17220 | - stc gbr, r2 |
| 17221 | - mov.w .L2, r0 |
| 17222 | - mov.l @(r0,r2), r4 |
| 17223 | - neg r4, r1 |
| 17224 | - tst r1, r1 |
| 17225 | - bf 1f |
| 17226 | - mov #1, r1 |
| 17227 | - rotr r1 |
| 17228 | -1: |
| 17229 | - mov.l r1, @(r0,r2) |
| 17230 | |
| 17231 | mov.w .L1, r3 |
| 17232 | trapa #0x10 |
| 17233 | mov r0, r1 |
| 17234 | |
| 17235 | - /* Restore the old PID value in the parent. */ |
| 17236 | - tst r0, r0 |
| 17237 | - bt.s 2f |
| 17238 | - stc gbr, r2 |
| 17239 | - mov.w .L2, r0 |
| 17240 | - mov.l r4, @(r0,r2) |
| 17241 | - mov r1, r0 |
| 17242 | -2: |
| 17243 | mov #-12, r2 |
| 17244 | shad r2, r1 |
| 17245 | not r1, r1 // r1=0 means r0 = -1 to -4095 |
| 17246 | @@ -61,8 +42,6 @@ ENTRY (__libc_vfork) |
| 17247 | nop |
| 17248 | .L1: |
| 17249 | .word __NR_vfork |
| 17250 | -.L2: |
| 17251 | - .word PID - TLS_PRE_TCB_SIZE |
| 17252 | .align 2 |
| 17253 | PSEUDO_END (__libc_vfork) |
| 17254 | |
| 17255 | diff --git a/sysdeps/unix/sysv/linux/sparc/Makefile b/sysdeps/unix/sysv/linux/sparc/Makefile |
| 17256 | index e67aecf8f0..a67d199eb5 100644 |
| 17257 | --- a/sysdeps/unix/sysv/linux/sparc/Makefile |
| 17258 | +++ b/sysdeps/unix/sysv/linux/sparc/Makefile |
| 17259 | @@ -6,6 +6,7 @@ abi-64-condition := __WORDSIZE == 64 |
| 17260 | |
| 17261 | ifeq ($(subdir),rt) |
| 17262 | librt-routines += rt-sysdep |
| 17263 | +librt-shared-only-routines += rt-sysdep |
| 17264 | endif |
| 17265 | |
| 17266 | ifeq ($(subdir),sysvipc) |
| 17267 | @@ -15,4 +16,5 @@ endif |
| 17268 | ifeq ($(subdir),nptl) |
| 17269 | # pull in __syscall_error routine |
| 17270 | libpthread-routines += sysdep |
| 17271 | +libpthread-shared-only-routines += sysdep |
| 17272 | endif |
| 17273 | diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/clone.S b/sysdeps/unix/sysv/linux/sparc/sparc32/clone.S |
| 17274 | index d6c92f6133..0456a0d16e 100644 |
| 17275 | --- a/sysdeps/unix/sysv/linux/sparc/sparc32/clone.S |
| 17276 | +++ b/sysdeps/unix/sysv/linux/sparc/sparc32/clone.S |
| 17277 | @@ -79,13 +79,6 @@ END(__clone) |
| 17278 | |
| 17279 | .type __thread_start,@function |
| 17280 | __thread_start: |
| 17281 | - andcc %g4, CLONE_VM, %g0 |
| 17282 | - bne 1f |
| 17283 | - set __NR_getpid,%g1 |
| 17284 | - ta 0x10 |
| 17285 | - st %o0,[%g7 + PID] |
| 17286 | - st %o0,[%g7 + TID] |
| 17287 | -1: |
| 17288 | mov %g0, %fp /* terminate backtrace */ |
| 17289 | call %g2 |
| 17290 | mov %g3,%o0 |
| 17291 | diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/vfork.S b/sysdeps/unix/sysv/linux/sparc/sparc32/vfork.S |
| 17292 | index 0d0a3b5298..6d985034f0 100644 |
| 17293 | --- a/sysdeps/unix/sysv/linux/sparc/sparc32/vfork.S |
| 17294 | +++ b/sysdeps/unix/sysv/linux/sparc/sparc32/vfork.S |
| 17295 | @@ -22,24 +22,14 @@ |
| 17296 | .text |
| 17297 | .globl __syscall_error |
| 17298 | ENTRY(__libc_vfork) |
| 17299 | - ld [%g7 + PID], %o5 |
| 17300 | - cmp %o5, 0 |
| 17301 | - bne 1f |
| 17302 | - sub %g0, %o5, %o4 |
| 17303 | - sethi %hi(0x80000000), %o4 |
| 17304 | -1: st %o4, [%g7 + PID] |
| 17305 | - |
| 17306 | LOADSYSCALL(vfork) |
| 17307 | ta 0x10 |
| 17308 | bcc 2f |
| 17309 | mov %o7, %g1 |
| 17310 | - st %o5, [%g7 + PID] |
| 17311 | call __syscall_error |
| 17312 | mov %g1, %o7 |
| 17313 | 2: sub %o1, 1, %o1 |
| 17314 | andcc %o0, %o1, %o0 |
| 17315 | - bne,a 1f |
| 17316 | - st %o5, [%g7 + PID] |
| 17317 | 1: retl |
| 17318 | nop |
| 17319 | END(__libc_vfork) |
| 17320 | diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/clone.S b/sysdeps/unix/sysv/linux/sparc/sparc64/clone.S |
| 17321 | index b0f62660a7..6ffead88e2 100644 |
| 17322 | --- a/sysdeps/unix/sysv/linux/sparc/sparc64/clone.S |
| 17323 | +++ b/sysdeps/unix/sysv/linux/sparc/sparc64/clone.S |
| 17324 | @@ -76,13 +76,6 @@ END(__clone) |
| 17325 | |
| 17326 | .type __thread_start,@function |
| 17327 | __thread_start: |
| 17328 | - andcc %g4, CLONE_VM, %g0 |
| 17329 | - bne,pt %icc, 1f |
| 17330 | - set __NR_getpid,%g1 |
| 17331 | - ta 0x6d |
| 17332 | - st %o0,[%g7 + PID] |
| 17333 | - st %o0,[%g7 + TID] |
| 17334 | -1: |
| 17335 | mov %g0, %fp /* terminate backtrace */ |
| 17336 | call %g2 |
| 17337 | mov %g3,%o0 |
| 17338 | diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/vfork.S b/sysdeps/unix/sysv/linux/sparc/sparc64/vfork.S |
| 17339 | index 0818eba02e..298dd197a9 100644 |
| 17340 | --- a/sysdeps/unix/sysv/linux/sparc/sparc64/vfork.S |
| 17341 | +++ b/sysdeps/unix/sysv/linux/sparc/sparc64/vfork.S |
| 17342 | @@ -22,24 +22,14 @@ |
| 17343 | .text |
| 17344 | .globl __syscall_error |
| 17345 | ENTRY(__libc_vfork) |
| 17346 | - ld [%g7 + PID], %o5 |
| 17347 | - sethi %hi(0x80000000), %o3 |
| 17348 | - cmp %o5, 0 |
| 17349 | - sub %g0, %o5, %o4 |
| 17350 | - move %icc, %o3, %o4 |
| 17351 | - st %o4, [%g7 + PID] |
| 17352 | - |
| 17353 | LOADSYSCALL(vfork) |
| 17354 | ta 0x6d |
| 17355 | bcc,pt %xcc, 2f |
| 17356 | mov %o7, %g1 |
| 17357 | - st %o5, [%g7 + PID] |
| 17358 | call __syscall_error |
| 17359 | mov %g1, %o7 |
| 17360 | 2: sub %o1, 1, %o1 |
| 17361 | andcc %o0, %o1, %o0 |
| 17362 | - bne,a,pt %icc, 1f |
| 17363 | - st %o5, [%g7 + PID] |
| 17364 | 1: retl |
| 17365 | nop |
| 17366 | END(__libc_vfork) |
| 17367 | diff --git a/sysdeps/unix/sysv/linux/spawni.c b/sysdeps/unix/sysv/linux/spawni.c |
| 17368 | index bb3eecfde1..b5f20a710b 100644 |
| 17369 | --- a/sysdeps/unix/sysv/linux/spawni.c |
| 17370 | +++ b/sysdeps/unix/sysv/linux/spawni.c |
| 17371 | @@ -58,22 +58,19 @@ |
| 17372 | normal program exit with the exit code 127. */ |
| 17373 | #define SPAWN_ERROR 127 |
| 17374 | |
| 17375 | -/* We need to block both SIGCANCEL and SIGSETXID. */ |
| 17376 | -#define SIGALL_SET \ |
| 17377 | - ((__sigset_t) { .__val = {[0 ... _SIGSET_NWORDS-1 ] = -1 } }) |
| 17378 | - |
| 17379 | #ifdef __ia64__ |
| 17380 | -# define CLONE(__fn, __stack, __stacksize, __flags, __args) \ |
| 17381 | - __clone2 (__fn, __stack, __stacksize, __flags, __args, 0, 0, 0) |
| 17382 | +# define CLONE(__fn, __stackbase, __stacksize, __flags, __args) \ |
| 17383 | + __clone2 (__fn, __stackbase, __stacksize, __flags, __args, 0, 0, 0) |
| 17384 | #else |
| 17385 | # define CLONE(__fn, __stack, __stacksize, __flags, __args) \ |
| 17386 | __clone (__fn, __stack, __flags, __args) |
| 17387 | #endif |
| 17388 | |
| 17389 | -#if _STACK_GROWS_DOWN |
| 17390 | -# define STACK(__stack, __stack_size) (__stack + __stack_size) |
| 17391 | -#elif _STACK_GROWS_UP |
| 17392 | +/* Since ia64 wants the stackbase w/clone2, re-use the grows-up macro. */ |
| 17393 | +#if _STACK_GROWS_UP || defined (__ia64__) |
| 17394 | # define STACK(__stack, __stack_size) (__stack) |
| 17395 | +#elif _STACK_GROWS_DOWN |
| 17396 | +# define STACK(__stack, __stack_size) (__stack + __stack_size) |
| 17397 | #endif |
| 17398 | |
| 17399 | |
| 17400 | @@ -329,6 +326,11 @@ __spawnix (pid_t * pid, const char *file, |
| 17401 | |
| 17402 | /* Add a slack area for child's stack. */ |
| 17403 | size_t argv_size = (argc * sizeof (void *)) + 512; |
| 17404 | + /* We need at least a few pages in case the compiler's stack checking is |
| 17405 | + enabled. In some configs, it is known to use at least 24KiB. We use |
| 17406 | + 32KiB to be "safe" from anything the compiler might do. Besides, the |
| 17407 | + extra pages won't actually be allocated unless they get used. */ |
| 17408 | + argv_size += (32 * 1024); |
| 17409 | size_t stack_size = ALIGN_UP (argv_size, GLRO(dl_pagesize)); |
| 17410 | void *stack = __mmap (NULL, stack_size, prot, |
| 17411 | MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0); |
| 17412 | @@ -340,7 +342,9 @@ __spawnix (pid_t * pid, const char *file, |
| 17413 | } |
| 17414 | |
| 17415 | /* Disable asynchronous cancellation. */ |
| 17416 | - int cs = LIBC_CANCEL_ASYNC (); |
| 17417 | + int state; |
| 17418 | + __libc_ptf_call (__pthread_setcancelstate, |
| 17419 | + (PTHREAD_CANCEL_DISABLE, &state), 0); |
| 17420 | |
| 17421 | args.file = file; |
| 17422 | args.exec = exec; |
| 17423 | @@ -351,7 +355,7 @@ __spawnix (pid_t * pid, const char *file, |
| 17424 | args.envp = envp; |
| 17425 | args.xflags = xflags; |
| 17426 | |
| 17427 | - __sigprocmask (SIG_BLOCK, &SIGALL_SET, &args.oldmask); |
| 17428 | + __libc_signal_block_all (&args.oldmask); |
| 17429 | |
| 17430 | /* The clone flags used will create a new child that will run in the same |
| 17431 | memory space (CLONE_VM) and the execution of calling thread will be |
| 17432 | @@ -384,9 +388,9 @@ __spawnix (pid_t * pid, const char *file, |
| 17433 | if ((ec == 0) && (pid != NULL)) |
| 17434 | *pid = new_pid; |
| 17435 | |
| 17436 | - __sigprocmask (SIG_SETMASK, &args.oldmask, 0); |
| 17437 | + __libc_signal_restore_set (&args.oldmask); |
| 17438 | |
| 17439 | - LIBC_CANCEL_RESET (cs); |
| 17440 | + __libc_ptf_call (__pthread_setcancelstate, (state, NULL), 0); |
| 17441 | |
| 17442 | return ec; |
| 17443 | } |
| 17444 | diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list |
| 17445 | index 7ae2541f8f..248641b830 100644 |
| 17446 | --- a/sysdeps/unix/sysv/linux/syscalls.list |
| 17447 | +++ b/sysdeps/unix/sysv/linux/syscalls.list |
| 17448 | @@ -18,6 +18,7 @@ execve - execve i:spp __execve execve |
| 17449 | fdatasync - fdatasync Ci:i fdatasync |
| 17450 | flock - flock i:ii __flock flock |
| 17451 | get_kernel_syms EXTRA get_kernel_syms i:p __compat_get_kernel_syms get_kernel_syms@GLIBC_2.0:GLIBC_2.23 |
| 17452 | +getpid - getpid Ei: __getpid getpid |
| 17453 | getegid - getegid Ei: __getegid getegid |
| 17454 | geteuid - geteuid Ei: __geteuid geteuid |
| 17455 | getpgid - getpgid i:i __getpgid getpgid |
| 17456 | diff --git a/sysdeps/unix/sysv/linux/sysdep.h b/sysdeps/unix/sysv/linux/sysdep.h |
| 17457 | index a469f57121..e3ecd5638e 100644 |
| 17458 | --- a/sysdeps/unix/sysv/linux/sysdep.h |
| 17459 | +++ b/sysdeps/unix/sysv/linux/sysdep.h |
| 17460 | @@ -48,6 +48,16 @@ |
| 17461 | __LONG_LONG_PAIR ((long) ((val) >> 32), (long) ((val) & 0xffffffff)) |
| 17462 | #endif |
| 17463 | |
| 17464 | +/* Provide a common macro to pass 64-bit value on pread and pwrite |
| 17465 | + syscalls. */ |
| 17466 | +#ifdef __ASSUME_PRW_DUMMY_ARG |
| 17467 | +# define SYSCALL_LL_PRW(val) 0, SYSCALL_LL (val) |
| 17468 | +# define SYSCALL_LL64_PRW(val) 0, SYSCALL_LL64 (val) |
| 17469 | +#else |
| 17470 | +# define SYSCALL_LL_PRW(val) __ALIGNMENT_ARG SYSCALL_LL (val) |
| 17471 | +# define SYSCALL_LL64_PRW(val) __ALIGNMENT_ARG SYSCALL_LL64 (val) |
| 17472 | +#endif |
| 17473 | + |
| 17474 | /* Provide a macro to pass the off{64}_t argument on p{readv,writev}{64}. */ |
| 17475 | #define LO_HI_LONG(val) \ |
| 17476 | (long) (val), \ |
| 17477 | diff --git a/sysdeps/unix/sysv/linux/tile/Makefile b/sysdeps/unix/sysv/linux/tile/Makefile |
| 17478 | index 1c1cfff280..43acea3633 100644 |
| 17479 | --- a/sysdeps/unix/sysv/linux/tile/Makefile |
| 17480 | +++ b/sysdeps/unix/sysv/linux/tile/Makefile |
| 17481 | @@ -25,4 +25,5 @@ endif |
| 17482 | ifeq ($(subdir),nptl) |
| 17483 | # pull in __syscall_error routine |
| 17484 | libpthread-routines += sysdep |
| 17485 | +libpthread-shared-only-routines += sysdep |
| 17486 | endif |
| 17487 | diff --git a/sysdeps/unix/sysv/linux/tile/clone.S b/sysdeps/unix/sysv/linux/tile/clone.S |
| 17488 | index d1d36462e7..3f9e3d56c4 100644 |
| 17489 | --- a/sysdeps/unix/sysv/linux/tile/clone.S |
| 17490 | +++ b/sysdeps/unix/sysv/linux/tile/clone.S |
| 17491 | @@ -163,22 +163,6 @@ ENTRY (__clone) |
| 17492 | .Lthread_start: |
| 17493 | cfi_def_cfa_offset (FRAME_SIZE) |
| 17494 | cfi_undefined (lr) |
| 17495 | - /* Check and see if we need to reset the PID, which we do if |
| 17496 | - CLONE_VM isn't set, i.e. it's a fork-like clone with a new |
| 17497 | - address space. In that case we update the cached values |
| 17498 | - from the true system pid (retrieved via __NR_getpid syscall). */ |
| 17499 | - moveli r0, CLONE_VM |
| 17500 | - and r0, r30, r0 |
| 17501 | - BNEZ r0, .Lno_reset_pid /* CLONE_VM is set */ |
| 17502 | - moveli TREG_SYSCALL_NR_NAME, __NR_getpid |
| 17503 | - swint1 |
| 17504 | - ADDLI_PTR r2, tp, PID_OFFSET |
| 17505 | - { |
| 17506 | - ST4 r2, r0 |
| 17507 | - ADDLI_PTR r2, tp, TID_OFFSET |
| 17508 | - } |
| 17509 | - ST4 r2, r0 |
| 17510 | -.Lno_reset_pid: |
| 17511 | { |
| 17512 | /* Invoke user function with specified argument. */ |
| 17513 | move r0, r31 |
| 17514 | diff --git a/sysdeps/unix/sysv/linux/tile/vfork.S b/sysdeps/unix/sysv/linux/tile/vfork.S |
| 17515 | index d8c5ce3e24..2272777187 100644 |
| 17516 | --- a/sysdeps/unix/sysv/linux/tile/vfork.S |
| 17517 | +++ b/sysdeps/unix/sysv/linux/tile/vfork.S |
| 17518 | @@ -29,18 +29,6 @@ |
| 17519 | |
| 17520 | .text |
| 17521 | ENTRY (__vfork) |
| 17522 | - { |
| 17523 | - addli r11, tp, PID_OFFSET /* Point at PID. */ |
| 17524 | - movei r13, 1 |
| 17525 | - } |
| 17526 | - { |
| 17527 | - LD4U r12, r11 /* Load the saved PID. */ |
| 17528 | - shli r13, r13, 31 /* Build 0x80000000. */ |
| 17529 | - } |
| 17530 | - sub r12, zero, r12 /* Negate it. */ |
| 17531 | - CMOVEQZ r12, r12, r13 /* Replace zero pids. */ |
| 17532 | - ST4 r11, r12 /* Store the temporary PID. */ |
| 17533 | - |
| 17534 | { |
| 17535 | moveli r0, CLONE_VFORK | CLONE_VM | SIGCHLD |
| 17536 | move r1, zero |
| 17537 | @@ -52,22 +40,6 @@ ENTRY (__vfork) |
| 17538 | moveli TREG_SYSCALL_NR_NAME, __NR_clone |
| 17539 | swint1 |
| 17540 | |
| 17541 | - BEQZ r0, 1f /* If we are the parent... */ |
| 17542 | - { |
| 17543 | - addli r11, tp, PID_OFFSET /* Point at PID. */ |
| 17544 | - movei r13, 1 |
| 17545 | - } |
| 17546 | - { |
| 17547 | - LD4U r12, r11 /* Load the saved PID. */ |
| 17548 | - shli r13, r13, 31 /* Build 0x80000000. */ |
| 17549 | - } |
| 17550 | - { |
| 17551 | - CMPEQ r13, r12, r12 /* Test for that value. */ |
| 17552 | - sub r12, zero, r12 /* Re-negate it. */ |
| 17553 | - } |
| 17554 | - CMOVNEZ r12, r13, zero /* Replace zero pids. */ |
| 17555 | - ST4 r11, r12 /* Restore the PID. */ |
| 17556 | -1: |
| 17557 | BNEZ r1, 0f |
| 17558 | jrp lr |
| 17559 | PSEUDO_END (__vfork) |
| 17560 | diff --git a/sysdeps/unix/sysv/linux/tst-clone2.c b/sysdeps/unix/sysv/linux/tst-clone2.c |
| 17561 | index 68a7e6d6e2..1472311947 100644 |
| 17562 | --- a/sysdeps/unix/sysv/linux/tst-clone2.c |
| 17563 | +++ b/sysdeps/unix/sysv/linux/tst-clone2.c |
| 17564 | @@ -28,8 +28,11 @@ |
| 17565 | #include <stdlib.h> |
| 17566 | #include <sys/types.h> |
| 17567 | #include <sys/wait.h> |
| 17568 | +#include <sys/syscall.h> |
| 17569 | |
| 17570 | -#include <tls.h> /* for THREAD_* macros. */ |
| 17571 | +#include <stackinfo.h> /* For _STACK_GROWS_{UP,DOWN}. */ |
| 17572 | + |
| 17573 | +#include <support/check.h> |
| 17574 | |
| 17575 | static int sig; |
| 17576 | static int pipefd[2]; |
| 17577 | @@ -39,39 +42,35 @@ f (void *a) |
| 17578 | { |
| 17579 | close (pipefd[0]); |
| 17580 | |
| 17581 | - pid_t pid = THREAD_GETMEM (THREAD_SELF, pid); |
| 17582 | - pid_t tid = THREAD_GETMEM (THREAD_SELF, tid); |
| 17583 | + pid_t ppid = getppid (); |
| 17584 | + pid_t pid = getpid (); |
| 17585 | + pid_t tid = syscall (__NR_gettid); |
| 17586 | |
| 17587 | - while (write (pipefd[1], &pid, sizeof pid) < 0) |
| 17588 | - continue; |
| 17589 | - while (write (pipefd[1], &tid, sizeof tid) < 0) |
| 17590 | - continue; |
| 17591 | + if (write (pipefd[1], &ppid, sizeof ppid) != sizeof (ppid)) |
| 17592 | + FAIL_EXIT1 ("write ppid failed\n"); |
| 17593 | + if (write (pipefd[1], &pid, sizeof pid) != sizeof (pid)) |
| 17594 | + FAIL_EXIT1 ("write pid failed\n"); |
| 17595 | + if (write (pipefd[1], &tid, sizeof tid) != sizeof (tid)) |
| 17596 | + FAIL_EXIT1 ("write tid failed\n"); |
| 17597 | |
| 17598 | return 0; |
| 17599 | } |
| 17600 | |
| 17601 | |
| 17602 | static int |
| 17603 | -clone_test (int clone_flags) |
| 17604 | +do_test (void) |
| 17605 | { |
| 17606 | sig = SIGRTMIN; |
| 17607 | sigset_t ss; |
| 17608 | sigemptyset (&ss); |
| 17609 | sigaddset (&ss, sig); |
| 17610 | if (sigprocmask (SIG_BLOCK, &ss, NULL) != 0) |
| 17611 | - { |
| 17612 | - printf ("sigprocmask failed: %m\n"); |
| 17613 | - return 1; |
| 17614 | - } |
| 17615 | + FAIL_EXIT1 ("sigprocmask failed: %m"); |
| 17616 | |
| 17617 | if (pipe2 (pipefd, O_CLOEXEC)) |
| 17618 | - { |
| 17619 | - printf ("sigprocmask failed: %m\n"); |
| 17620 | - return 1; |
| 17621 | - } |
| 17622 | - |
| 17623 | - pid_t ppid = getpid (); |
| 17624 | + FAIL_EXIT1 ("pipe failed: %m"); |
| 17625 | |
| 17626 | + int clone_flags = 0; |
| 17627 | #ifdef __ia64__ |
| 17628 | extern int __clone2 (int (*__fn) (void *__arg), void *__child_stack_base, |
| 17629 | size_t __child_stack_size, int __flags, |
| 17630 | @@ -88,61 +87,47 @@ clone_test (int clone_flags) |
| 17631 | #error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP" |
| 17632 | #endif |
| 17633 | #endif |
| 17634 | + |
| 17635 | close (pipefd[1]); |
| 17636 | |
| 17637 | if (p == -1) |
| 17638 | + FAIL_EXIT1("clone failed: %m"); |
| 17639 | + |
| 17640 | + pid_t ppid, pid, tid; |
| 17641 | + if (read (pipefd[0], &ppid, sizeof pid) != sizeof pid) |
| 17642 | { |
| 17643 | - printf ("clone failed: %m\n"); |
| 17644 | - return 1; |
| 17645 | + kill (p, SIGKILL); |
| 17646 | + FAIL_EXIT1 ("read ppid failed: %m"); |
| 17647 | } |
| 17648 | - |
| 17649 | - pid_t pid, tid; |
| 17650 | if (read (pipefd[0], &pid, sizeof pid) != sizeof pid) |
| 17651 | { |
| 17652 | - printf ("read pid failed: %m\n"); |
| 17653 | kill (p, SIGKILL); |
| 17654 | - return 1; |
| 17655 | + FAIL_EXIT1 ("read pid failed: %m"); |
| 17656 | } |
| 17657 | if (read (pipefd[0], &tid, sizeof tid) != sizeof tid) |
| 17658 | { |
| 17659 | - printf ("read pid failed: %m\n"); |
| 17660 | kill (p, SIGKILL); |
| 17661 | - return 1; |
| 17662 | + FAIL_EXIT1 ("read tid failed: %m"); |
| 17663 | } |
| 17664 | |
| 17665 | close (pipefd[0]); |
| 17666 | |
| 17667 | int ret = 0; |
| 17668 | |
| 17669 | - /* For CLONE_VM glibc clone implementation does not change the pthread |
| 17670 | - pid/tid field. */ |
| 17671 | - if ((clone_flags & CLONE_VM) == CLONE_VM) |
| 17672 | - { |
| 17673 | - if ((ppid != pid) || (ppid != tid)) |
| 17674 | - { |
| 17675 | - printf ("parent pid (%i) != received pid/tid (%i/%i)\n", |
| 17676 | - (int)ppid, (int)pid, (int)tid); |
| 17677 | - ret = 1; |
| 17678 | - } |
| 17679 | - } |
| 17680 | - /* For any other flag clone updates the new pthread pid and tid with |
| 17681 | - the clone return value. */ |
| 17682 | - else |
| 17683 | - { |
| 17684 | - if ((p != pid) || (p != tid)) |
| 17685 | - { |
| 17686 | - printf ("child pid (%i) != received pid/tid (%i/%i)\n", |
| 17687 | - (int)p, (int)pid, (int)tid); |
| 17688 | - ret = 1; |
| 17689 | - } |
| 17690 | - } |
| 17691 | + pid_t own_pid = getpid (); |
| 17692 | + pid_t own_tid = syscall (__NR_gettid); |
| 17693 | + |
| 17694 | + /* Some sanity checks for clone syscall: returned ppid should be current |
| 17695 | + pid and both returned tid/pid should be different from current one. */ |
| 17696 | + if ((ppid != own_pid) || (pid == own_pid) || (tid == own_tid)) |
| 17697 | + FAIL_RET ("ppid=%i pid=%i tid=%i | own_pid=%i own_tid=%i", |
| 17698 | + (int)ppid, (int)pid, (int)tid, (int)own_pid, (int)own_tid); |
| 17699 | |
| 17700 | int e; |
| 17701 | if (waitpid (p, &e, __WCLONE) != p) |
| 17702 | { |
| 17703 | - puts ("waitpid failed"); |
| 17704 | kill (p, SIGKILL); |
| 17705 | - return 1; |
| 17706 | + FAIL_EXIT1 ("waitpid failed"); |
| 17707 | } |
| 17708 | if (!WIFEXITED (e)) |
| 17709 | { |
| 17710 | @@ -150,29 +135,12 @@ clone_test (int clone_flags) |
| 17711 | printf ("died from signal %s\n", strsignal (WTERMSIG (e))); |
| 17712 | else |
| 17713 | puts ("did not terminate correctly"); |
| 17714 | - return 1; |
| 17715 | + exit (EXIT_FAILURE); |
| 17716 | } |
| 17717 | if (WEXITSTATUS (e) != 0) |
| 17718 | - { |
| 17719 | - printf ("exit code %d\n", WEXITSTATUS (e)); |
| 17720 | - return 1; |
| 17721 | - } |
| 17722 | + FAIL_EXIT1 ("exit code %d", WEXITSTATUS (e)); |
| 17723 | |
| 17724 | return ret; |
| 17725 | } |
| 17726 | |
| 17727 | -int |
| 17728 | -do_test (void) |
| 17729 | -{ |
| 17730 | - /* First, check that the clone implementation, without any flag, updates |
| 17731 | - the struct pthread to contain the new PID and TID. */ |
| 17732 | - int ret = clone_test (0); |
| 17733 | - /* Second, check that with CLONE_VM the struct pthread PID and TID fields |
| 17734 | - remain unmodified after the clone. Any modifications would cause problem |
| 17735 | - for the parent as described in bug 19957. */ |
| 17736 | - ret += clone_test (CLONE_VM); |
| 17737 | - return ret; |
| 17738 | -} |
| 17739 | - |
| 17740 | -#define TEST_FUNCTION do_test () |
| 17741 | -#include "../test-skeleton.c" |
| 17742 | +#include <support/test-driver.c> |
| 17743 | diff --git a/sysdeps/unix/sysv/linux/wordsize-64/globfree64.c b/sysdeps/unix/sysv/linux/wordsize-64/globfree64.c |
| 17744 | new file mode 100644 |
| 17745 | index 0000000000..af035e1514 |
| 17746 | --- /dev/null |
| 17747 | +++ b/sysdeps/unix/sysv/linux/wordsize-64/globfree64.c |
| 17748 | @@ -0,0 +1,2 @@ |
| 17749 | +/* This file is here so sysdeps/gnu/glob64.c doesn't take precedence. */ |
| 17750 | +#include <sysdeps/wordsize-64/globfree64.c> |
| 17751 | diff --git a/sysdeps/unix/sysv/linux/x86_64/clone.S b/sysdeps/unix/sysv/linux/x86_64/clone.S |
| 17752 | index 66f4b11490..5629aed395 100644 |
| 17753 | --- a/sysdeps/unix/sysv/linux/x86_64/clone.S |
| 17754 | +++ b/sysdeps/unix/sysv/linux/x86_64/clone.S |
| 17755 | @@ -91,14 +91,6 @@ L(thread_start): |
| 17756 | the outermost frame obviously. */ |
| 17757 | xorl %ebp, %ebp |
| 17758 | |
| 17759 | - andq $CLONE_VM, %rdi |
| 17760 | - jne 1f |
| 17761 | - movl $SYS_ify(getpid), %eax |
| 17762 | - syscall |
| 17763 | - movl %eax, %fs:PID |
| 17764 | - movl %eax, %fs:TID |
| 17765 | -1: |
| 17766 | - |
| 17767 | /* Set up arguments for the function call. */ |
| 17768 | popq %rax /* Function to call. */ |
| 17769 | popq %rdi /* Argument. */ |
| 17770 | diff --git a/sysdeps/unix/sysv/linux/x86_64/vfork.S b/sysdeps/unix/sysv/linux/x86_64/vfork.S |
| 17771 | index 8332ade9fb..cdd2dea32a 100644 |
| 17772 | --- a/sysdeps/unix/sysv/linux/x86_64/vfork.S |
| 17773 | +++ b/sysdeps/unix/sysv/linux/x86_64/vfork.S |
| 17774 | @@ -34,16 +34,6 @@ ENTRY (__vfork) |
| 17775 | cfi_adjust_cfa_offset(-8) |
| 17776 | cfi_register(%rip, %rdi) |
| 17777 | |
| 17778 | - /* Save the TCB-cached PID away in %esi, and then negate the TCB |
| 17779 | - field. But if it's zero, set it to 0x80000000 instead. See |
| 17780 | - raise.c for the logic that relies on this value. */ |
| 17781 | - movl %fs:PID, %esi |
| 17782 | - movl $0x80000000, %ecx |
| 17783 | - movl %esi, %edx |
| 17784 | - negl %edx |
| 17785 | - cmove %ecx, %edx |
| 17786 | - movl %edx, %fs:PID |
| 17787 | - |
| 17788 | /* Stuff the syscall number in RAX and enter into the kernel. */ |
| 17789 | movl $SYS_ify (vfork), %eax |
| 17790 | syscall |
| 17791 | @@ -52,14 +42,6 @@ ENTRY (__vfork) |
| 17792 | pushq %rdi |
| 17793 | cfi_adjust_cfa_offset(8) |
| 17794 | |
| 17795 | - /* Restore the original value of the TCB cache of the PID, if we're |
| 17796 | - the parent. But in the child (syscall return value equals zero), |
| 17797 | - leave things as they are. */ |
| 17798 | - testq %rax, %rax |
| 17799 | - je 1f |
| 17800 | - movl %esi, %fs:PID |
| 17801 | -1: |
| 17802 | - |
| 17803 | cmpl $-4095, %eax |
| 17804 | jae SYSCALL_ERROR_LABEL /* Branch forward if it failed. */ |
| 17805 | |
| 17806 | diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/globfree.c b/sysdeps/unix/sysv/linux/x86_64/x32/globfree.c |
| 17807 | new file mode 100644 |
| 17808 | index 0000000000..b76a761c17 |
| 17809 | --- /dev/null |
| 17810 | +++ b/sysdeps/unix/sysv/linux/x86_64/x32/globfree.c |
| 17811 | @@ -0,0 +1 @@ |
| 17812 | +#include <sysdeps/wordsize-64/globfree.c> |
| 17813 | diff --git a/sysdeps/wordsize-64/glob.c b/sysdeps/wordsize-64/glob.c |
| 17814 | index 082faf1c70..954e8d37e2 100644 |
| 17815 | --- a/sysdeps/wordsize-64/glob.c |
| 17816 | +++ b/sysdeps/wordsize-64/glob.c |
| 17817 | @@ -4,5 +4,3 @@ |
| 17818 | #undef glob64 |
| 17819 | #undef globfree64 |
| 17820 | weak_alias (glob, glob64) |
| 17821 | -weak_alias (globfree, globfree64) |
| 17822 | -libc_hidden_ver (globfree, globfree64) |
| 17823 | diff --git a/sysdeps/wordsize-64/globfree.c b/sysdeps/wordsize-64/globfree.c |
| 17824 | new file mode 100644 |
| 17825 | index 0000000000..ec8c35b489 |
| 17826 | --- /dev/null |
| 17827 | +++ b/sysdeps/wordsize-64/globfree.c |
| 17828 | @@ -0,0 +1,5 @@ |
| 17829 | +#define globfree64 __no_globfree64_decl |
| 17830 | +#include <posix/globfree.c> |
| 17831 | +#undef globfree64 |
| 17832 | +weak_alias (globfree, globfree64) |
| 17833 | +libc_hidden_ver (globfree, globfree64) |
| 17834 | diff --git a/sysdeps/wordsize-64/globfree64.c b/sysdeps/wordsize-64/globfree64.c |
| 17835 | new file mode 100644 |
| 17836 | index 0000000000..a0f57ff4b3 |
| 17837 | --- /dev/null |
| 17838 | +++ b/sysdeps/wordsize-64/globfree64.c |
| 17839 | @@ -0,0 +1 @@ |
| 17840 | +/* globfree64 is in globfree.c */ |
| 17841 | diff --git a/sysdeps/x86/cpu-features-offsets.sym b/sysdeps/x86/cpu-features-offsets.sym |
| 17842 | index f6739fae81..33dd094e37 100644 |
| 17843 | --- a/sysdeps/x86/cpu-features-offsets.sym |
| 17844 | +++ b/sysdeps/x86/cpu-features-offsets.sym |
| 17845 | @@ -15,6 +15,7 @@ CPUID_ECX_OFFSET offsetof (struct cpuid_registers, ecx) |
| 17846 | CPUID_EDX_OFFSET offsetof (struct cpuid_registers, edx) |
| 17847 | FAMILY_OFFSET offsetof (struct cpu_features, family) |
| 17848 | MODEL_OFFSET offsetof (struct cpu_features, model) |
| 17849 | +XSAVE_STATE_SIZE_OFFSET offsetof (struct cpu_features, xsave_state_size) |
| 17850 | FEATURE_OFFSET offsetof (struct cpu_features, feature) |
| 17851 | FEATURE_SIZE sizeof (unsigned int) |
| 17852 | |
| 17853 | diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c |
| 17854 | index 9ce4b495a5..9eca98817d 100644 |
| 17855 | --- a/sysdeps/x86/cpu-features.c |
| 17856 | +++ b/sysdeps/x86/cpu-features.c |
| 17857 | @@ -18,6 +18,7 @@ |
| 17858 | |
| 17859 | #include <cpuid.h> |
| 17860 | #include <cpu-features.h> |
| 17861 | +#include <libc-internal.h> |
| 17862 | |
| 17863 | static void |
| 17864 | get_common_indeces (struct cpu_features *cpu_features, |
| 17865 | @@ -88,6 +89,71 @@ get_common_indeces (struct cpu_features *cpu_features, |
| 17866 | cpu_features->feature[index_arch_FMA_Usable] |
| 17867 | |= bit_arch_FMA_Usable; |
| 17868 | } |
| 17869 | + |
| 17870 | + /* For _dl_runtime_resolve, set xsave_state_size to xsave area |
| 17871 | + size + integer register save size and align it to 64 bytes. */ |
| 17872 | + if (cpu_features->max_cpuid >= 0xd) |
| 17873 | + { |
| 17874 | + unsigned int eax, ebx, ecx, edx; |
| 17875 | + |
| 17876 | + __cpuid_count (0xd, 0, eax, ebx, ecx, edx); |
| 17877 | + if (ebx != 0) |
| 17878 | + { |
| 17879 | + cpu_features->xsave_state_size |
| 17880 | + = ALIGN_UP (ebx + STATE_SAVE_OFFSET, 64); |
| 17881 | + |
| 17882 | + __cpuid_count (0xd, 1, eax, ebx, ecx, edx); |
| 17883 | + |
| 17884 | + /* Check if XSAVEC is available. */ |
| 17885 | + if ((eax & (1 << 1)) != 0) |
| 17886 | + { |
| 17887 | + unsigned int xstate_comp_offsets[32]; |
| 17888 | + unsigned int xstate_comp_sizes[32]; |
| 17889 | + unsigned int i; |
| 17890 | + |
| 17891 | + xstate_comp_offsets[0] = 0; |
| 17892 | + xstate_comp_offsets[1] = 160; |
| 17893 | + xstate_comp_offsets[2] = 576; |
| 17894 | + xstate_comp_sizes[0] = 160; |
| 17895 | + xstate_comp_sizes[1] = 256; |
| 17896 | + |
| 17897 | + for (i = 2; i < 32; i++) |
| 17898 | + { |
| 17899 | + if ((STATE_SAVE_MASK & (1 << i)) != 0) |
| 17900 | + { |
| 17901 | + __cpuid_count (0xd, i, eax, ebx, ecx, edx); |
| 17902 | + xstate_comp_sizes[i] = eax; |
| 17903 | + } |
| 17904 | + else |
| 17905 | + { |
| 17906 | + ecx = 0; |
| 17907 | + xstate_comp_sizes[i] = 0; |
| 17908 | + } |
| 17909 | + |
| 17910 | + if (i > 2) |
| 17911 | + { |
| 17912 | + xstate_comp_offsets[i] |
| 17913 | + = (xstate_comp_offsets[i - 1] |
| 17914 | + + xstate_comp_sizes[i -1]); |
| 17915 | + if ((ecx & (1 << 1)) != 0) |
| 17916 | + xstate_comp_offsets[i] |
| 17917 | + = ALIGN_UP (xstate_comp_offsets[i], 64); |
| 17918 | + } |
| 17919 | + } |
| 17920 | + |
| 17921 | + /* Use XSAVEC. */ |
| 17922 | + unsigned int size |
| 17923 | + = xstate_comp_offsets[31] + xstate_comp_sizes[31]; |
| 17924 | + if (size) |
| 17925 | + { |
| 17926 | + cpu_features->xsave_state_size |
| 17927 | + = ALIGN_UP (size + STATE_SAVE_OFFSET, 64); |
| 17928 | + cpu_features->feature[index_arch_XSAVEC_Usable] |
| 17929 | + |= bit_arch_XSAVEC_Usable; |
| 17930 | + } |
| 17931 | + } |
| 17932 | + } |
| 17933 | + } |
| 17934 | } |
| 17935 | } |
| 17936 | |
| 17937 | @@ -133,8 +199,6 @@ init_cpu_features (struct cpu_features *cpu_features) |
| 17938 | |
| 17939 | case 0x57: |
| 17940 | /* Knights Landing. Enable Silvermont optimizations. */ |
| 17941 | - cpu_features->feature[index_arch_Prefer_No_VZEROUPPER] |
| 17942 | - |= bit_arch_Prefer_No_VZEROUPPER; |
| 17943 | |
| 17944 | case 0x5c: |
| 17945 | case 0x5f: |
| 17946 | @@ -205,6 +269,16 @@ init_cpu_features (struct cpu_features *cpu_features) |
| 17947 | if (CPU_FEATURES_ARCH_P (cpu_features, AVX2_Usable)) |
| 17948 | cpu_features->feature[index_arch_AVX_Fast_Unaligned_Load] |
| 17949 | |= bit_arch_AVX_Fast_Unaligned_Load; |
| 17950 | + |
| 17951 | + /* Since AVX512ER is unique to Xeon Phi, set Prefer_No_VZEROUPPER |
| 17952 | + if AVX512ER is available. Don't use AVX512 to avoid lower CPU |
| 17953 | + frequency if AVX512ER isn't available. */ |
| 17954 | + if (CPU_FEATURES_CPU_P (cpu_features, AVX512ER)) |
| 17955 | + cpu_features->feature[index_arch_Prefer_No_VZEROUPPER] |
| 17956 | + |= bit_arch_Prefer_No_VZEROUPPER; |
| 17957 | + else |
| 17958 | + cpu_features->feature[index_arch_Prefer_No_AVX512] |
| 17959 | + |= bit_arch_Prefer_No_AVX512; |
| 17960 | } |
| 17961 | /* This spells out "AuthenticAMD". */ |
| 17962 | else if (ebx == 0x68747541 && ecx == 0x444d4163 && edx == 0x69746e65) |
| 17963 | diff --git a/sysdeps/x86/cpu-features.h b/sysdeps/x86/cpu-features.h |
| 17964 | index 97ffe765f4..507a141414 100644 |
| 17965 | --- a/sysdeps/x86/cpu-features.h |
| 17966 | +++ b/sysdeps/x86/cpu-features.h |
| 17967 | @@ -37,6 +37,8 @@ |
| 17968 | #define bit_arch_Prefer_No_VZEROUPPER (1 << 17) |
| 17969 | #define bit_arch_Fast_Unaligned_Copy (1 << 18) |
| 17970 | #define bit_arch_Prefer_ERMS (1 << 19) |
| 17971 | +#define bit_arch_Prefer_No_AVX512 (1 << 20) |
| 17972 | +#define bit_arch_XSAVEC_Usable (1 << 21) |
| 17973 | |
| 17974 | /* CPUID Feature flags. */ |
| 17975 | |
| 17976 | @@ -60,6 +62,11 @@ |
| 17977 | #define bit_cpu_AVX2 (1 << 5) |
| 17978 | #define bit_cpu_AVX512F (1 << 16) |
| 17979 | #define bit_cpu_AVX512DQ (1 << 17) |
| 17980 | +#define bit_cpu_AVX512PF (1 << 26) |
| 17981 | +#define bit_cpu_AVX512ER (1 << 27) |
| 17982 | +#define bit_cpu_AVX512CD (1 << 28) |
| 17983 | +#define bit_cpu_AVX512BW (1 << 30) |
| 17984 | +#define bit_cpu_AVX512VL (1u << 31) |
| 17985 | |
| 17986 | /* XCR0 Feature flags. */ |
| 17987 | #define bit_XMM_state (1 << 1) |
| 17988 | @@ -74,6 +81,15 @@ |
| 17989 | /* The current maximum size of the feature integer bit array. */ |
| 17990 | #define FEATURE_INDEX_MAX 1 |
| 17991 | |
| 17992 | +/* Offset for fxsave/xsave area used by _dl_runtime_resolve. Also need |
| 17993 | + space to preserve RCX, RDX, RSI, RDI, R8, R9 and RAX. It must be |
| 17994 | + aligned to 16 bytes for fxsave and 64 bytes for xsave. */ |
| 17995 | +#define STATE_SAVE_OFFSET (8 * 7 + 8) |
| 17996 | + |
| 17997 | +/* Save SSE, AVX, AVX512, mask and bound registers. */ |
| 17998 | +#define STATE_SAVE_MASK \ |
| 17999 | + ((1 << 1) | (1 << 2) | (1 << 3) | (1 << 5) | (1 << 6) | (1 << 7)) |
| 18000 | + |
| 18001 | #ifdef __ASSEMBLER__ |
| 18002 | |
| 18003 | # include <cpu-features-offsets.h> |
| 18004 | @@ -107,6 +123,9 @@ |
| 18005 | # define index_arch_Prefer_No_VZEROUPPER FEATURE_INDEX_1*FEATURE_SIZE |
| 18006 | # define index_arch_Fast_Unaligned_Copy FEATURE_INDEX_1*FEATURE_SIZE |
| 18007 | # define index_arch_Prefer_ERMS FEATURE_INDEX_1*FEATURE_SIZE |
| 18008 | +# define index_arch_Use_dl_runtime_resolve_opt FEATURE_INDEX_1*FEATURE_SIZE |
| 18009 | +# define index_arch_Use_dl_runtime_resolve_slow FEATURE_INDEX_1*FEATURE_SIZE |
| 18010 | +# define index_arch_Prefer_No_AVX512 FEATURE_INDEX_1*FEATURE_SIZE |
| 18011 | |
| 18012 | |
| 18013 | # if defined (_LIBC) && !IS_IN (nonlib) |
| 18014 | @@ -195,6 +214,12 @@ struct cpu_features |
| 18015 | } cpuid[COMMON_CPUID_INDEX_MAX]; |
| 18016 | unsigned int family; |
| 18017 | unsigned int model; |
| 18018 | + /* The type must be unsigned long int so that we use |
| 18019 | + |
| 18020 | + sub xsave_state_size_offset(%rip) %RSP_LP |
| 18021 | + |
| 18022 | + in _dl_runtime_resolve. */ |
| 18023 | + unsigned long int xsave_state_size; |
| 18024 | unsigned int feature[FEATURE_INDEX_MAX]; |
| 18025 | }; |
| 18026 | |
| 18027 | @@ -232,6 +257,11 @@ extern const struct cpu_features *__get_cpu_features (void) |
| 18028 | # define index_cpu_AVX2 COMMON_CPUID_INDEX_7 |
| 18029 | # define index_cpu_AVX512F COMMON_CPUID_INDEX_7 |
| 18030 | # define index_cpu_AVX512DQ COMMON_CPUID_INDEX_7 |
| 18031 | +# define index_cpu_AVX512PF COMMON_CPUID_INDEX_7 |
| 18032 | +# define index_cpu_AVX512ER COMMON_CPUID_INDEX_7 |
| 18033 | +# define index_cpu_AVX512CD COMMON_CPUID_INDEX_7 |
| 18034 | +# define index_cpu_AVX512BW COMMON_CPUID_INDEX_7 |
| 18035 | +# define index_cpu_AVX512VL COMMON_CPUID_INDEX_7 |
| 18036 | # define index_cpu_ERMS COMMON_CPUID_INDEX_7 |
| 18037 | # define index_cpu_RTM COMMON_CPUID_INDEX_7 |
| 18038 | # define index_cpu_FMA COMMON_CPUID_INDEX_1 |
| 18039 | @@ -250,6 +280,11 @@ extern const struct cpu_features *__get_cpu_features (void) |
| 18040 | # define reg_AVX2 ebx |
| 18041 | # define reg_AVX512F ebx |
| 18042 | # define reg_AVX512DQ ebx |
| 18043 | +# define reg_AVX512PF ebx |
| 18044 | +# define reg_AVX512ER ebx |
| 18045 | +# define reg_AVX512CD ebx |
| 18046 | +# define reg_AVX512BW ebx |
| 18047 | +# define reg_AVX512VL ebx |
| 18048 | # define reg_ERMS ebx |
| 18049 | # define reg_RTM ebx |
| 18050 | # define reg_FMA ecx |
| 18051 | @@ -277,6 +312,8 @@ extern const struct cpu_features *__get_cpu_features (void) |
| 18052 | # define index_arch_Prefer_No_VZEROUPPER FEATURE_INDEX_1 |
| 18053 | # define index_arch_Fast_Unaligned_Copy FEATURE_INDEX_1 |
| 18054 | # define index_arch_Prefer_ERMS FEATURE_INDEX_1 |
| 18055 | +# define index_arch_Prefer_No_AVX512 FEATURE_INDEX_1 |
| 18056 | +# define index_arch_XSAVEC_Usable FEATURE_INDEX_1 |
| 18057 | |
| 18058 | #endif /* !__ASSEMBLER__ */ |
| 18059 | |
| 18060 | diff --git a/sysdeps/x86_64/Makefile b/sysdeps/x86_64/Makefile |
| 18061 | index 6d99284cd0..cc990a9685 100644 |
| 18062 | --- a/sysdeps/x86_64/Makefile |
| 18063 | +++ b/sysdeps/x86_64/Makefile |
| 18064 | @@ -27,7 +27,7 @@ ifeq ($(subdir),elf) |
| 18065 | CFLAGS-.os += $(if $(filter $(@F),$(patsubst %,%.os,$(all-rtld-routines))),\ |
| 18066 | -mno-mmx) |
| 18067 | |
| 18068 | -sysdep-dl-routines += tlsdesc dl-tlsdesc |
| 18069 | +sysdep-dl-routines += tlsdesc dl-tlsdesc tls_get_addr |
| 18070 | |
| 18071 | tests += ifuncmain8 |
| 18072 | modules-names += ifuncmod8 |
| 18073 | @@ -49,9 +49,12 @@ extra-test-objs += tst-quadmod1pie.o tst-quadmod2pie.o |
| 18074 | $(objpfx)tst-quad1pie: $(objpfx)tst-quadmod1pie.o |
| 18075 | $(objpfx)tst-quad2pie: $(objpfx)tst-quadmod2pie.o |
| 18076 | |
| 18077 | -tests += tst-audit3 tst-audit4 tst-audit5 tst-audit6 tst-audit7 tst-audit10 |
| 18078 | -test-extras += tst-audit4-aux tst-audit10-aux |
| 18079 | -extra-test-objs += tst-audit4-aux.o tst-audit10-aux.o |
| 18080 | +tests += tst-audit3 tst-audit4 tst-audit5 tst-audit6 tst-audit7 \ |
| 18081 | + tst-audit10 tst-sse tst-avx tst-avx512 |
| 18082 | +test-extras += tst-audit4-aux tst-audit10-aux \ |
| 18083 | + tst-avx-aux tst-avx512-aux |
| 18084 | +extra-test-objs += tst-audit4-aux.o tst-audit10-aux.o \ |
| 18085 | + tst-avx-aux.o tst-avx512-aux.o |
| 18086 | |
| 18087 | tests += tst-split-dynreloc |
| 18088 | LDFLAGS-tst-split-dynreloc = -Wl,-T,$(..)sysdeps/x86_64/tst-split-dynreloc.lds |
| 18089 | @@ -62,7 +65,8 @@ modules-names += tst-auditmod3a tst-auditmod3b \ |
| 18090 | tst-auditmod5a tst-auditmod5b \ |
| 18091 | tst-auditmod6a tst-auditmod6b tst-auditmod6c \ |
| 18092 | tst-auditmod7a tst-auditmod7b \ |
| 18093 | - tst-auditmod10a tst-auditmod10b |
| 18094 | + tst-auditmod10a tst-auditmod10b \ |
| 18095 | + tst-ssemod tst-avxmod tst-avx512mod |
| 18096 | |
| 18097 | $(objpfx)tst-audit3: $(objpfx)tst-auditmod3a.so |
| 18098 | $(objpfx)tst-audit3.out: $(objpfx)tst-auditmod3b.so |
| 18099 | @@ -89,6 +93,10 @@ $(objpfx)tst-audit10: $(objpfx)tst-audit10-aux.o $(objpfx)tst-auditmod10a.so |
| 18100 | $(objpfx)tst-audit10.out: $(objpfx)tst-auditmod10b.so |
| 18101 | tst-audit10-ENV = LD_AUDIT=$(objpfx)tst-auditmod10b.so |
| 18102 | |
| 18103 | +$(objpfx)tst-sse: $(objpfx)tst-ssemod.so |
| 18104 | +$(objpfx)tst-avx: $(objpfx)tst-avx-aux.o $(objpfx)tst-avxmod.so |
| 18105 | +$(objpfx)tst-avx512: $(objpfx)tst-avx512-aux.o $(objpfx)tst-avx512mod.so |
| 18106 | + |
| 18107 | AVX-CFLAGS=-mavx -mno-vzeroupper |
| 18108 | CFLAGS-tst-audit4-aux.c += $(AVX-CFLAGS) |
| 18109 | CFLAGS-tst-auditmod4a.c += $(AVX-CFLAGS) |
| 18110 | @@ -96,14 +104,18 @@ CFLAGS-tst-auditmod4b.c += $(AVX-CFLAGS) |
| 18111 | CFLAGS-tst-auditmod6b.c += $(AVX-CFLAGS) |
| 18112 | CFLAGS-tst-auditmod6c.c += $(AVX-CFLAGS) |
| 18113 | CFLAGS-tst-auditmod7b.c += $(AVX-CFLAGS) |
| 18114 | +CFLAGS-tst-avx-aux.c += $(AVX-CFLAGS) |
| 18115 | +CFLAGS-tst-avxmod.c += $(AVX-CFLAGS) |
| 18116 | ifeq (yes,$(config-cflags-avx512)) |
| 18117 | AVX512-CFLAGS = -mavx512f |
| 18118 | CFLAGS-tst-audit10-aux.c += $(AVX512-CFLAGS) |
| 18119 | CFLAGS-tst-auditmod10a.c += $(AVX512-CFLAGS) |
| 18120 | CFLAGS-tst-auditmod10b.c += $(AVX512-CFLAGS) |
| 18121 | +CFLAGS-tst-avx512-aux.c += $(AVX512-CFLAGS) |
| 18122 | +CFLAGS-tst-avx512mod.c += $(AVX512-CFLAGS) |
| 18123 | endif |
| 18124 | endif |
| 18125 | |
| 18126 | ifeq ($(subdir),csu) |
| 18127 | -gen-as-const-headers += tlsdesc.sym |
| 18128 | +gen-as-const-headers += tlsdesc.sym rtld-offsets.sym |
| 18129 | endif |
| 18130 | diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h |
| 18131 | index ed0c1a8efd..8355432dfc 100644 |
| 18132 | --- a/sysdeps/x86_64/dl-machine.h |
| 18133 | +++ b/sysdeps/x86_64/dl-machine.h |
| 18134 | @@ -66,9 +66,9 @@ static inline int __attribute__ ((unused, always_inline)) |
| 18135 | elf_machine_runtime_setup (struct link_map *l, int lazy, int profile) |
| 18136 | { |
| 18137 | Elf64_Addr *got; |
| 18138 | - extern void _dl_runtime_resolve_sse (ElfW(Word)) attribute_hidden; |
| 18139 | - extern void _dl_runtime_resolve_avx (ElfW(Word)) attribute_hidden; |
| 18140 | - extern void _dl_runtime_resolve_avx512 (ElfW(Word)) attribute_hidden; |
| 18141 | + extern void _dl_runtime_resolve_fxsave (ElfW(Word)) attribute_hidden; |
| 18142 | + extern void _dl_runtime_resolve_xsave (ElfW(Word)) attribute_hidden; |
| 18143 | + extern void _dl_runtime_resolve_xsavec (ElfW(Word)) attribute_hidden; |
| 18144 | extern void _dl_runtime_profile_sse (ElfW(Word)) attribute_hidden; |
| 18145 | extern void _dl_runtime_profile_avx (ElfW(Word)) attribute_hidden; |
| 18146 | extern void _dl_runtime_profile_avx512 (ElfW(Word)) attribute_hidden; |
| 18147 | @@ -117,12 +117,14 @@ elf_machine_runtime_setup (struct link_map *l, int lazy, int profile) |
| 18148 | /* This function will get called to fix up the GOT entry |
| 18149 | indicated by the offset on the stack, and then jump to |
| 18150 | the resolved address. */ |
| 18151 | - if (HAS_ARCH_FEATURE (AVX512F_Usable)) |
| 18152 | - *(ElfW(Addr) *) (got + 2) = (ElfW(Addr)) &_dl_runtime_resolve_avx512; |
| 18153 | - else if (HAS_ARCH_FEATURE (AVX_Usable)) |
| 18154 | - *(ElfW(Addr) *) (got + 2) = (ElfW(Addr)) &_dl_runtime_resolve_avx; |
| 18155 | + if (GLRO(dl_x86_cpu_features).xsave_state_size != 0) |
| 18156 | + *(ElfW(Addr) *) (got + 2) |
| 18157 | + = (HAS_ARCH_FEATURE (XSAVEC_Usable) |
| 18158 | + ? (ElfW(Addr)) &_dl_runtime_resolve_xsavec |
| 18159 | + : (ElfW(Addr)) &_dl_runtime_resolve_xsave); |
| 18160 | else |
| 18161 | - *(ElfW(Addr) *) (got + 2) = (ElfW(Addr)) &_dl_runtime_resolve_sse; |
| 18162 | + *(ElfW(Addr) *) (got + 2) |
| 18163 | + = (ElfW(Addr)) &_dl_runtime_resolve_fxsave; |
| 18164 | } |
| 18165 | } |
| 18166 | |
| 18167 | diff --git a/sysdeps/x86_64/dl-tls.c b/sysdeps/x86_64/dl-tls.c |
| 18168 | new file mode 100644 |
| 18169 | index 0000000000..3584805c8e |
| 18170 | --- /dev/null |
| 18171 | +++ b/sysdeps/x86_64/dl-tls.c |
| 18172 | @@ -0,0 +1,53 @@ |
| 18173 | +/* Thread-local storage handling in the ELF dynamic linker. x86-64 version. |
| 18174 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 18175 | + This file is part of the GNU C Library. |
| 18176 | + |
| 18177 | + The GNU C Library is free software; you can redistribute it and/or |
| 18178 | + modify it under the terms of the GNU Lesser General Public |
| 18179 | + License as published by the Free Software Foundation; either |
| 18180 | + version 2.1 of the License, or (at your option) any later version. |
| 18181 | + |
| 18182 | + The GNU C Library is distributed in the hope that it will be useful, |
| 18183 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18184 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18185 | + Lesser General Public License for more details. |
| 18186 | + |
| 18187 | + You should have received a copy of the GNU Lesser General Public |
| 18188 | + License along with the GNU C Library; if not, see |
| 18189 | + <http://www.gnu.org/licenses/>. */ |
| 18190 | + |
| 18191 | +#ifdef SHARED |
| 18192 | +/* Work around GCC PR58066, due to which __tls_get_addr may be called |
| 18193 | + with an unaligned stack. The compat implementation is in |
| 18194 | + tls_get_addr-compat.S. */ |
| 18195 | + |
| 18196 | +# include <dl-tls.h> |
| 18197 | + |
| 18198 | +/* Define __tls_get_addr within elf/dl-tls.c under a different |
| 18199 | + name. */ |
| 18200 | +extern __typeof__ (__tls_get_addr) ___tls_get_addr; |
| 18201 | + |
| 18202 | +# define __tls_get_addr ___tls_get_addr |
| 18203 | +# include <elf/dl-tls.c> |
| 18204 | +# undef __tls_get_addr |
| 18205 | + |
| 18206 | +hidden_ver (___tls_get_addr, __tls_get_addr) |
| 18207 | + |
| 18208 | +/* Only handle slow paths for __tls_get_addr. */ |
| 18209 | +attribute_hidden |
| 18210 | +void * |
| 18211 | +__tls_get_addr_slow (GET_ADDR_ARGS) |
| 18212 | +{ |
| 18213 | + dtv_t *dtv = THREAD_DTV (); |
| 18214 | + |
| 18215 | + if (__glibc_unlikely (dtv[0].counter != GL(dl_tls_generation))) |
| 18216 | + return update_get_addr (GET_ADDR_PARAM); |
| 18217 | + |
| 18218 | + return tls_get_addr_tail (GET_ADDR_PARAM, dtv, NULL); |
| 18219 | +} |
| 18220 | +#else |
| 18221 | + |
| 18222 | +/* No compatibility symbol needed. */ |
| 18223 | +# include <elf/dl-tls.c> |
| 18224 | + |
| 18225 | +#endif |
| 18226 | diff --git a/sysdeps/x86_64/dl-tls.h b/sysdeps/x86_64/dl-tls.h |
| 18227 | index cf6c107f54..fa5bf6cd93 100644 |
| 18228 | --- a/sysdeps/x86_64/dl-tls.h |
| 18229 | +++ b/sysdeps/x86_64/dl-tls.h |
| 18230 | @@ -16,6 +16,9 @@ |
| 18231 | License along with the GNU C Library; if not, see |
| 18232 | <http://www.gnu.org/licenses/>. */ |
| 18233 | |
| 18234 | +#ifndef _X86_64_DL_TLS_H |
| 18235 | +#define _X86_64_DL_TLS_H |
| 18236 | + |
| 18237 | #include <stdint.h> |
| 18238 | |
| 18239 | /* Type used for the representation of TLS information in the GOT. */ |
| 18240 | @@ -27,3 +30,5 @@ typedef struct dl_tls_index |
| 18241 | |
| 18242 | |
| 18243 | extern void *__tls_get_addr (tls_index *ti); |
| 18244 | + |
| 18245 | +#endif /* _X86_64_DL_TLS_H */ |
| 18246 | diff --git a/sysdeps/x86_64/dl-trampoline.S b/sysdeps/x86_64/dl-trampoline.S |
| 18247 | index 12f1a5cf84..b4cda0f535 100644 |
| 18248 | --- a/sysdeps/x86_64/dl-trampoline.S |
| 18249 | +++ b/sysdeps/x86_64/dl-trampoline.S |
| 18250 | @@ -18,6 +18,7 @@ |
| 18251 | |
| 18252 | #include <config.h> |
| 18253 | #include <sysdep.h> |
| 18254 | +#include <cpu-features.h> |
| 18255 | #include <link-defines.h> |
| 18256 | |
| 18257 | #ifndef DL_STACK_ALIGNMENT |
| 18258 | @@ -33,41 +34,24 @@ |
| 18259 | # define DL_STACK_ALIGNMENT 8 |
| 18260 | #endif |
| 18261 | |
| 18262 | -#ifndef DL_RUNTIME_UNALIGNED_VEC_SIZE |
| 18263 | -/* The maximum size in bytes of unaligned vector load and store in the |
| 18264 | - dynamic linker. Since SSE optimized memory/string functions with |
| 18265 | - aligned SSE register load and store are used in the dynamic linker, |
| 18266 | - we must set this to 8 so that _dl_runtime_resolve_sse will align the |
| 18267 | - stack before calling _dl_fixup. */ |
| 18268 | -# define DL_RUNTIME_UNALIGNED_VEC_SIZE 8 |
| 18269 | -#endif |
| 18270 | - |
| 18271 | -/* True if _dl_runtime_resolve should align stack to VEC_SIZE bytes. */ |
| 18272 | +/* True if _dl_runtime_resolve should align stack for STATE_SAVE or align |
| 18273 | + stack to 16 bytes before calling _dl_fixup. */ |
| 18274 | #define DL_RUNTIME_RESOLVE_REALIGN_STACK \ |
| 18275 | - (VEC_SIZE > DL_STACK_ALIGNMENT \ |
| 18276 | - && VEC_SIZE > DL_RUNTIME_UNALIGNED_VEC_SIZE) |
| 18277 | - |
| 18278 | -/* Align vector register save area to 16 bytes. */ |
| 18279 | -#define REGISTER_SAVE_VEC_OFF 0 |
| 18280 | + (STATE_SAVE_ALIGNMENT > DL_STACK_ALIGNMENT \ |
| 18281 | + || 16 > DL_STACK_ALIGNMENT) |
| 18282 | |
| 18283 | /* Area on stack to save and restore registers used for parameter |
| 18284 | passing when calling _dl_fixup. */ |
| 18285 | #ifdef __ILP32__ |
| 18286 | -# define REGISTER_SAVE_RAX (REGISTER_SAVE_VEC_OFF + VEC_SIZE * 8) |
| 18287 | # define PRESERVE_BND_REGS_PREFIX |
| 18288 | #else |
| 18289 | -/* Align bound register save area to 16 bytes. */ |
| 18290 | -# define REGISTER_SAVE_BND0 (REGISTER_SAVE_VEC_OFF + VEC_SIZE * 8) |
| 18291 | -# define REGISTER_SAVE_BND1 (REGISTER_SAVE_BND0 + 16) |
| 18292 | -# define REGISTER_SAVE_BND2 (REGISTER_SAVE_BND1 + 16) |
| 18293 | -# define REGISTER_SAVE_BND3 (REGISTER_SAVE_BND2 + 16) |
| 18294 | -# define REGISTER_SAVE_RAX (REGISTER_SAVE_BND3 + 16) |
| 18295 | # ifdef HAVE_MPX_SUPPORT |
| 18296 | # define PRESERVE_BND_REGS_PREFIX bnd |
| 18297 | # else |
| 18298 | # define PRESERVE_BND_REGS_PREFIX .byte 0xf2 |
| 18299 | # endif |
| 18300 | #endif |
| 18301 | +#define REGISTER_SAVE_RAX 0 |
| 18302 | #define REGISTER_SAVE_RCX (REGISTER_SAVE_RAX + 8) |
| 18303 | #define REGISTER_SAVE_RDX (REGISTER_SAVE_RCX + 8) |
| 18304 | #define REGISTER_SAVE_RSI (REGISTER_SAVE_RDX + 8) |
| 18305 | @@ -79,50 +63,56 @@ |
| 18306 | |
| 18307 | #define VEC_SIZE 64 |
| 18308 | #define VMOVA vmovdqa64 |
| 18309 | -#if DL_RUNTIME_RESOLVE_REALIGN_STACK || VEC_SIZE <= DL_STACK_ALIGNMENT |
| 18310 | -# define VMOV vmovdqa64 |
| 18311 | -#else |
| 18312 | -# define VMOV vmovdqu64 |
| 18313 | -#endif |
| 18314 | #define VEC(i) zmm##i |
| 18315 | -#define _dl_runtime_resolve _dl_runtime_resolve_avx512 |
| 18316 | #define _dl_runtime_profile _dl_runtime_profile_avx512 |
| 18317 | #include "dl-trampoline.h" |
| 18318 | -#undef _dl_runtime_resolve |
| 18319 | #undef _dl_runtime_profile |
| 18320 | #undef VEC |
| 18321 | -#undef VMOV |
| 18322 | #undef VMOVA |
| 18323 | #undef VEC_SIZE |
| 18324 | |
| 18325 | #define VEC_SIZE 32 |
| 18326 | #define VMOVA vmovdqa |
| 18327 | -#if DL_RUNTIME_RESOLVE_REALIGN_STACK || VEC_SIZE <= DL_STACK_ALIGNMENT |
| 18328 | -# define VMOV vmovdqa |
| 18329 | -#else |
| 18330 | -# define VMOV vmovdqu |
| 18331 | -#endif |
| 18332 | #define VEC(i) ymm##i |
| 18333 | -#define _dl_runtime_resolve _dl_runtime_resolve_avx |
| 18334 | #define _dl_runtime_profile _dl_runtime_profile_avx |
| 18335 | #include "dl-trampoline.h" |
| 18336 | -#undef _dl_runtime_resolve |
| 18337 | #undef _dl_runtime_profile |
| 18338 | #undef VEC |
| 18339 | -#undef VMOV |
| 18340 | #undef VMOVA |
| 18341 | #undef VEC_SIZE |
| 18342 | |
| 18343 | /* movaps/movups is 1-byte shorter. */ |
| 18344 | #define VEC_SIZE 16 |
| 18345 | #define VMOVA movaps |
| 18346 | -#if DL_RUNTIME_RESOLVE_REALIGN_STACK || VEC_SIZE <= DL_STACK_ALIGNMENT |
| 18347 | -# define VMOV movaps |
| 18348 | -#else |
| 18349 | -# define VMOV movups |
| 18350 | -#endif |
| 18351 | #define VEC(i) xmm##i |
| 18352 | -#define _dl_runtime_resolve _dl_runtime_resolve_sse |
| 18353 | #define _dl_runtime_profile _dl_runtime_profile_sse |
| 18354 | #undef RESTORE_AVX |
| 18355 | #include "dl-trampoline.h" |
| 18356 | +#undef _dl_runtime_profile |
| 18357 | +#undef VEC |
| 18358 | +#undef VMOVA |
| 18359 | +#undef VEC_SIZE |
| 18360 | + |
| 18361 | +#define USE_FXSAVE |
| 18362 | +#define STATE_SAVE_ALIGNMENT 16 |
| 18363 | +#define _dl_runtime_resolve _dl_runtime_resolve_fxsave |
| 18364 | +#include "dl-trampoline.h" |
| 18365 | +#undef _dl_runtime_resolve |
| 18366 | +#undef USE_FXSAVE |
| 18367 | +#undef STATE_SAVE_ALIGNMENT |
| 18368 | + |
| 18369 | +#define USE_XSAVE |
| 18370 | +#define STATE_SAVE_ALIGNMENT 64 |
| 18371 | +#define _dl_runtime_resolve _dl_runtime_resolve_xsave |
| 18372 | +#include "dl-trampoline.h" |
| 18373 | +#undef _dl_runtime_resolve |
| 18374 | +#undef USE_XSAVE |
| 18375 | +#undef STATE_SAVE_ALIGNMENT |
| 18376 | + |
| 18377 | +#define USE_XSAVEC |
| 18378 | +#define STATE_SAVE_ALIGNMENT 64 |
| 18379 | +#define _dl_runtime_resolve _dl_runtime_resolve_xsavec |
| 18380 | +#include "dl-trampoline.h" |
| 18381 | +#undef _dl_runtime_resolve |
| 18382 | +#undef USE_XSAVEC |
| 18383 | +#undef STATE_SAVE_ALIGNMENT |
| 18384 | diff --git a/sysdeps/x86_64/dl-trampoline.h b/sysdeps/x86_64/dl-trampoline.h |
| 18385 | index b90836ab13..b9c2f1796f 100644 |
| 18386 | --- a/sysdeps/x86_64/dl-trampoline.h |
| 18387 | +++ b/sysdeps/x86_64/dl-trampoline.h |
| 18388 | @@ -16,40 +16,47 @@ |
| 18389 | License along with the GNU C Library; if not, see |
| 18390 | <http://www.gnu.org/licenses/>. */ |
| 18391 | |
| 18392 | -#undef REGISTER_SAVE_AREA_RAW |
| 18393 | -#ifdef __ILP32__ |
| 18394 | -/* X32 saves RCX, RDX, RSI, RDI, R8 and R9 plus RAX as well as VEC0 to |
| 18395 | - VEC7. */ |
| 18396 | -# define REGISTER_SAVE_AREA_RAW (8 * 7 + VEC_SIZE * 8) |
| 18397 | -#else |
| 18398 | -/* X86-64 saves RCX, RDX, RSI, RDI, R8 and R9 plus RAX as well as |
| 18399 | - BND0, BND1, BND2, BND3 and VEC0 to VEC7. */ |
| 18400 | -# define REGISTER_SAVE_AREA_RAW (8 * 7 + 16 * 4 + VEC_SIZE * 8) |
| 18401 | -#endif |
| 18402 | + .text |
| 18403 | +#ifdef _dl_runtime_resolve |
| 18404 | |
| 18405 | -#undef REGISTER_SAVE_AREA |
| 18406 | -#undef LOCAL_STORAGE_AREA |
| 18407 | -#undef BASE |
| 18408 | -#if DL_RUNTIME_RESOLVE_REALIGN_STACK |
| 18409 | -# define REGISTER_SAVE_AREA (REGISTER_SAVE_AREA_RAW + 8) |
| 18410 | -/* Local stack area before jumping to function address: RBX. */ |
| 18411 | -# define LOCAL_STORAGE_AREA 8 |
| 18412 | -# define BASE rbx |
| 18413 | -# if (REGISTER_SAVE_AREA % VEC_SIZE) != 0 |
| 18414 | -# error REGISTER_SAVE_AREA must be multples of VEC_SIZE |
| 18415 | +# undef REGISTER_SAVE_AREA |
| 18416 | +# undef LOCAL_STORAGE_AREA |
| 18417 | +# undef BASE |
| 18418 | + |
| 18419 | +# if (STATE_SAVE_ALIGNMENT % 16) != 0 |
| 18420 | +# error STATE_SAVE_ALIGNMENT must be multples of 16 |
| 18421 | # endif |
| 18422 | -#else |
| 18423 | -# define REGISTER_SAVE_AREA REGISTER_SAVE_AREA_RAW |
| 18424 | + |
| 18425 | +# if (STATE_SAVE_OFFSET % STATE_SAVE_ALIGNMENT) != 0 |
| 18426 | +# error STATE_SAVE_OFFSET must be multples of STATE_SAVE_ALIGNMENT |
| 18427 | +# endif |
| 18428 | + |
| 18429 | +# if DL_RUNTIME_RESOLVE_REALIGN_STACK |
| 18430 | +/* Local stack area before jumping to function address: RBX. */ |
| 18431 | +# define LOCAL_STORAGE_AREA 8 |
| 18432 | +# define BASE rbx |
| 18433 | +# ifdef USE_FXSAVE |
| 18434 | +/* Use fxsave to save XMM registers. */ |
| 18435 | +# define REGISTER_SAVE_AREA (512 + STATE_SAVE_OFFSET) |
| 18436 | +# if (REGISTER_SAVE_AREA % 16) != 0 |
| 18437 | +# error REGISTER_SAVE_AREA must be multples of 16 |
| 18438 | +# endif |
| 18439 | +# endif |
| 18440 | +# else |
| 18441 | +# ifndef USE_FXSAVE |
| 18442 | +# error USE_FXSAVE must be defined |
| 18443 | +# endif |
| 18444 | +/* Use fxsave to save XMM registers. */ |
| 18445 | +# define REGISTER_SAVE_AREA (512 + STATE_SAVE_OFFSET + 8) |
| 18446 | /* Local stack area before jumping to function address: All saved |
| 18447 | registers. */ |
| 18448 | -# define LOCAL_STORAGE_AREA REGISTER_SAVE_AREA |
| 18449 | -# define BASE rsp |
| 18450 | -# if (REGISTER_SAVE_AREA % 16) != 8 |
| 18451 | -# error REGISTER_SAVE_AREA must be odd multples of 8 |
| 18452 | +# define LOCAL_STORAGE_AREA REGISTER_SAVE_AREA |
| 18453 | +# define BASE rsp |
| 18454 | +# if (REGISTER_SAVE_AREA % 16) != 8 |
| 18455 | +# error REGISTER_SAVE_AREA must be odd multples of 8 |
| 18456 | +# endif |
| 18457 | # endif |
| 18458 | -#endif |
| 18459 | |
| 18460 | - .text |
| 18461 | .globl _dl_runtime_resolve |
| 18462 | .hidden _dl_runtime_resolve |
| 18463 | .type _dl_runtime_resolve, @function |
| 18464 | @@ -57,19 +64,30 @@ |
| 18465 | cfi_startproc |
| 18466 | _dl_runtime_resolve: |
| 18467 | cfi_adjust_cfa_offset(16) # Incorporate PLT |
| 18468 | -#if DL_RUNTIME_RESOLVE_REALIGN_STACK |
| 18469 | -# if LOCAL_STORAGE_AREA != 8 |
| 18470 | -# error LOCAL_STORAGE_AREA must be 8 |
| 18471 | -# endif |
| 18472 | +# if DL_RUNTIME_RESOLVE_REALIGN_STACK |
| 18473 | +# if LOCAL_STORAGE_AREA != 8 |
| 18474 | +# error LOCAL_STORAGE_AREA must be 8 |
| 18475 | +# endif |
| 18476 | pushq %rbx # push subtracts stack by 8. |
| 18477 | cfi_adjust_cfa_offset(8) |
| 18478 | cfi_rel_offset(%rbx, 0) |
| 18479 | mov %RSP_LP, %RBX_LP |
| 18480 | cfi_def_cfa_register(%rbx) |
| 18481 | - and $-VEC_SIZE, %RSP_LP |
| 18482 | -#endif |
| 18483 | + and $-STATE_SAVE_ALIGNMENT, %RSP_LP |
| 18484 | +# endif |
| 18485 | +# ifdef REGISTER_SAVE_AREA |
| 18486 | sub $REGISTER_SAVE_AREA, %RSP_LP |
| 18487 | +# if !DL_RUNTIME_RESOLVE_REALIGN_STACK |
| 18488 | cfi_adjust_cfa_offset(REGISTER_SAVE_AREA) |
| 18489 | +# endif |
| 18490 | +# else |
| 18491 | + # Allocate stack space of the required size to save the state. |
| 18492 | +# if IS_IN (rtld) |
| 18493 | + sub _rtld_local_ro+RTLD_GLOBAL_RO_DL_X86_CPU_FEATURES_OFFSET+XSAVE_STATE_SIZE_OFFSET(%rip), %RSP_LP |
| 18494 | +# else |
| 18495 | + sub _dl_x86_cpu_features+XSAVE_STATE_SIZE_OFFSET(%rip), %RSP_LP |
| 18496 | +# endif |
| 18497 | +# endif |
| 18498 | # Preserve registers otherwise clobbered. |
| 18499 | movq %rax, REGISTER_SAVE_RAX(%rsp) |
| 18500 | movq %rcx, REGISTER_SAVE_RCX(%rsp) |
| 18501 | @@ -78,59 +96,42 @@ _dl_runtime_resolve: |
| 18502 | movq %rdi, REGISTER_SAVE_RDI(%rsp) |
| 18503 | movq %r8, REGISTER_SAVE_R8(%rsp) |
| 18504 | movq %r9, REGISTER_SAVE_R9(%rsp) |
| 18505 | - VMOV %VEC(0), (REGISTER_SAVE_VEC_OFF)(%rsp) |
| 18506 | - VMOV %VEC(1), (REGISTER_SAVE_VEC_OFF + VEC_SIZE)(%rsp) |
| 18507 | - VMOV %VEC(2), (REGISTER_SAVE_VEC_OFF + VEC_SIZE * 2)(%rsp) |
| 18508 | - VMOV %VEC(3), (REGISTER_SAVE_VEC_OFF + VEC_SIZE * 3)(%rsp) |
| 18509 | - VMOV %VEC(4), (REGISTER_SAVE_VEC_OFF + VEC_SIZE * 4)(%rsp) |
| 18510 | - VMOV %VEC(5), (REGISTER_SAVE_VEC_OFF + VEC_SIZE * 5)(%rsp) |
| 18511 | - VMOV %VEC(6), (REGISTER_SAVE_VEC_OFF + VEC_SIZE * 6)(%rsp) |
| 18512 | - VMOV %VEC(7), (REGISTER_SAVE_VEC_OFF + VEC_SIZE * 7)(%rsp) |
| 18513 | -#ifndef __ILP32__ |
| 18514 | - # We also have to preserve bound registers. These are nops if |
| 18515 | - # Intel MPX isn't available or disabled. |
| 18516 | -# ifdef HAVE_MPX_SUPPORT |
| 18517 | - bndmov %bnd0, REGISTER_SAVE_BND0(%rsp) |
| 18518 | - bndmov %bnd1, REGISTER_SAVE_BND1(%rsp) |
| 18519 | - bndmov %bnd2, REGISTER_SAVE_BND2(%rsp) |
| 18520 | - bndmov %bnd3, REGISTER_SAVE_BND3(%rsp) |
| 18521 | +# ifdef USE_FXSAVE |
| 18522 | + fxsave STATE_SAVE_OFFSET(%rsp) |
| 18523 | # else |
| 18524 | -# if REGISTER_SAVE_BND0 == 0 |
| 18525 | - .byte 0x66,0x0f,0x1b,0x04,0x24 |
| 18526 | + movl $STATE_SAVE_MASK, %eax |
| 18527 | + xorl %edx, %edx |
| 18528 | + # Clear the XSAVE Header. |
| 18529 | +# ifdef USE_XSAVE |
| 18530 | + movq %rdx, (STATE_SAVE_OFFSET + 512)(%rsp) |
| 18531 | + movq %rdx, (STATE_SAVE_OFFSET + 512 + 8)(%rsp) |
| 18532 | +# endif |
| 18533 | + movq %rdx, (STATE_SAVE_OFFSET + 512 + 8 * 2)(%rsp) |
| 18534 | + movq %rdx, (STATE_SAVE_OFFSET + 512 + 8 * 3)(%rsp) |
| 18535 | + movq %rdx, (STATE_SAVE_OFFSET + 512 + 8 * 4)(%rsp) |
| 18536 | + movq %rdx, (STATE_SAVE_OFFSET + 512 + 8 * 5)(%rsp) |
| 18537 | + movq %rdx, (STATE_SAVE_OFFSET + 512 + 8 * 6)(%rsp) |
| 18538 | + movq %rdx, (STATE_SAVE_OFFSET + 512 + 8 * 7)(%rsp) |
| 18539 | +# ifdef USE_XSAVE |
| 18540 | + xsave STATE_SAVE_OFFSET(%rsp) |
| 18541 | # else |
| 18542 | - .byte 0x66,0x0f,0x1b,0x44,0x24,REGISTER_SAVE_BND0 |
| 18543 | + xsavec STATE_SAVE_OFFSET(%rsp) |
| 18544 | # endif |
| 18545 | - .byte 0x66,0x0f,0x1b,0x4c,0x24,REGISTER_SAVE_BND1 |
| 18546 | - .byte 0x66,0x0f,0x1b,0x54,0x24,REGISTER_SAVE_BND2 |
| 18547 | - .byte 0x66,0x0f,0x1b,0x5c,0x24,REGISTER_SAVE_BND3 |
| 18548 | # endif |
| 18549 | -#endif |
| 18550 | # Copy args pushed by PLT in register. |
| 18551 | # %rdi: link_map, %rsi: reloc_index |
| 18552 | mov (LOCAL_STORAGE_AREA + 8)(%BASE), %RSI_LP |
| 18553 | mov LOCAL_STORAGE_AREA(%BASE), %RDI_LP |
| 18554 | call _dl_fixup # Call resolver. |
| 18555 | mov %RAX_LP, %R11_LP # Save return value |
| 18556 | -#ifndef __ILP32__ |
| 18557 | - # Restore bound registers. These are nops if Intel MPX isn't |
| 18558 | - # avaiable or disabled. |
| 18559 | -# ifdef HAVE_MPX_SUPPORT |
| 18560 | - bndmov REGISTER_SAVE_BND3(%rsp), %bnd3 |
| 18561 | - bndmov REGISTER_SAVE_BND2(%rsp), %bnd2 |
| 18562 | - bndmov REGISTER_SAVE_BND1(%rsp), %bnd1 |
| 18563 | - bndmov REGISTER_SAVE_BND0(%rsp), %bnd0 |
| 18564 | + # Get register content back. |
| 18565 | +# ifdef USE_FXSAVE |
| 18566 | + fxrstor STATE_SAVE_OFFSET(%rsp) |
| 18567 | # else |
| 18568 | - .byte 0x66,0x0f,0x1a,0x5c,0x24,REGISTER_SAVE_BND3 |
| 18569 | - .byte 0x66,0x0f,0x1a,0x54,0x24,REGISTER_SAVE_BND2 |
| 18570 | - .byte 0x66,0x0f,0x1a,0x4c,0x24,REGISTER_SAVE_BND1 |
| 18571 | -# if REGISTER_SAVE_BND0 == 0 |
| 18572 | - .byte 0x66,0x0f,0x1a,0x04,0x24 |
| 18573 | -# else |
| 18574 | - .byte 0x66,0x0f,0x1a,0x44,0x24,REGISTER_SAVE_BND0 |
| 18575 | -# endif |
| 18576 | + movl $STATE_SAVE_MASK, %eax |
| 18577 | + xorl %edx, %edx |
| 18578 | + xrstor STATE_SAVE_OFFSET(%rsp) |
| 18579 | # endif |
| 18580 | -#endif |
| 18581 | - # Get register content back. |
| 18582 | movq REGISTER_SAVE_R9(%rsp), %r9 |
| 18583 | movq REGISTER_SAVE_R8(%rsp), %r8 |
| 18584 | movq REGISTER_SAVE_RDI(%rsp), %rdi |
| 18585 | @@ -138,20 +139,12 @@ _dl_runtime_resolve: |
| 18586 | movq REGISTER_SAVE_RDX(%rsp), %rdx |
| 18587 | movq REGISTER_SAVE_RCX(%rsp), %rcx |
| 18588 | movq REGISTER_SAVE_RAX(%rsp), %rax |
| 18589 | - VMOV (REGISTER_SAVE_VEC_OFF)(%rsp), %VEC(0) |
| 18590 | - VMOV (REGISTER_SAVE_VEC_OFF + VEC_SIZE)(%rsp), %VEC(1) |
| 18591 | - VMOV (REGISTER_SAVE_VEC_OFF + VEC_SIZE * 2)(%rsp), %VEC(2) |
| 18592 | - VMOV (REGISTER_SAVE_VEC_OFF + VEC_SIZE * 3)(%rsp), %VEC(3) |
| 18593 | - VMOV (REGISTER_SAVE_VEC_OFF + VEC_SIZE * 4)(%rsp), %VEC(4) |
| 18594 | - VMOV (REGISTER_SAVE_VEC_OFF + VEC_SIZE * 5)(%rsp), %VEC(5) |
| 18595 | - VMOV (REGISTER_SAVE_VEC_OFF + VEC_SIZE * 6)(%rsp), %VEC(6) |
| 18596 | - VMOV (REGISTER_SAVE_VEC_OFF + VEC_SIZE * 7)(%rsp), %VEC(7) |
| 18597 | -#if DL_RUNTIME_RESOLVE_REALIGN_STACK |
| 18598 | +# if DL_RUNTIME_RESOLVE_REALIGN_STACK |
| 18599 | mov %RBX_LP, %RSP_LP |
| 18600 | cfi_def_cfa_register(%rsp) |
| 18601 | movq (%rsp), %rbx |
| 18602 | cfi_restore(%rbx) |
| 18603 | -#endif |
| 18604 | +# endif |
| 18605 | # Adjust stack(PLT did 2 pushes) |
| 18606 | add $(LOCAL_STORAGE_AREA + 16), %RSP_LP |
| 18607 | cfi_adjust_cfa_offset(-(LOCAL_STORAGE_AREA + 16)) |
| 18608 | @@ -160,9 +153,10 @@ _dl_runtime_resolve: |
| 18609 | jmp *%r11 # Jump to function address. |
| 18610 | cfi_endproc |
| 18611 | .size _dl_runtime_resolve, .-_dl_runtime_resolve |
| 18612 | +#endif |
| 18613 | |
| 18614 | |
| 18615 | -#ifndef PROF |
| 18616 | +#if !defined PROF && defined _dl_runtime_profile |
| 18617 | # if (LR_VECTOR_OFFSET % VEC_SIZE) != 0 |
| 18618 | # error LR_VECTOR_OFFSET must be multples of VEC_SIZE |
| 18619 | # endif |
| 18620 | diff --git a/sysdeps/x86_64/memcpy_chk.S b/sysdeps/x86_64/memcpy_chk.S |
| 18621 | index 2296b55119..a95b3ad3cf 100644 |
| 18622 | --- a/sysdeps/x86_64/memcpy_chk.S |
| 18623 | +++ b/sysdeps/x86_64/memcpy_chk.S |
| 18624 | @@ -19,7 +19,7 @@ |
| 18625 | #include <sysdep.h> |
| 18626 | #include "asm-syntax.h" |
| 18627 | |
| 18628 | -#ifndef PIC |
| 18629 | +#ifndef SHARED |
| 18630 | /* For libc.so this is defined in memcpy.S. |
| 18631 | For libc.a, this is a separate source to avoid |
| 18632 | memcpy bringing in __chk_fail and all routines |
| 18633 | diff --git a/sysdeps/x86_64/multiarch/memcpy.S b/sysdeps/x86_64/multiarch/memcpy.S |
| 18634 | index b8677596f9..ea4ec70d1a 100644 |
| 18635 | --- a/sysdeps/x86_64/multiarch/memcpy.S |
| 18636 | +++ b/sysdeps/x86_64/multiarch/memcpy.S |
| 18637 | @@ -32,6 +32,8 @@ ENTRY(__new_memcpy) |
| 18638 | lea __memcpy_erms(%rip), %RAX_LP |
| 18639 | HAS_ARCH_FEATURE (Prefer_ERMS) |
| 18640 | jnz 2f |
| 18641 | + HAS_ARCH_FEATURE (Prefer_No_AVX512) |
| 18642 | + jnz 1f |
| 18643 | HAS_ARCH_FEATURE (AVX512F_Usable) |
| 18644 | jz 1f |
| 18645 | lea __memcpy_avx512_no_vzeroupper(%rip), %RAX_LP |
| 18646 | diff --git a/sysdeps/x86_64/multiarch/memcpy_chk.S b/sysdeps/x86_64/multiarch/memcpy_chk.S |
| 18647 | index 9d92c8a7e3..26b49de6f6 100644 |
| 18648 | --- a/sysdeps/x86_64/multiarch/memcpy_chk.S |
| 18649 | +++ b/sysdeps/x86_64/multiarch/memcpy_chk.S |
| 18650 | @@ -30,6 +30,8 @@ |
| 18651 | ENTRY(__memcpy_chk) |
| 18652 | .type __memcpy_chk, @gnu_indirect_function |
| 18653 | LOAD_RTLD_GLOBAL_RO_RDX |
| 18654 | + HAS_ARCH_FEATURE (Prefer_No_AVX512) |
| 18655 | + jnz 1f |
| 18656 | HAS_ARCH_FEATURE (AVX512F_Usable) |
| 18657 | jz 1f |
| 18658 | lea __memcpy_chk_avx512_no_vzeroupper(%rip), %RAX_LP |
| 18659 | diff --git a/sysdeps/x86_64/multiarch/memmove.S b/sysdeps/x86_64/multiarch/memmove.S |
| 18660 | index ff5e041420..ef92afde5a 100644 |
| 18661 | --- a/sysdeps/x86_64/multiarch/memmove.S |
| 18662 | +++ b/sysdeps/x86_64/multiarch/memmove.S |
| 18663 | @@ -30,6 +30,8 @@ ENTRY(__libc_memmove) |
| 18664 | lea __memmove_erms(%rip), %RAX_LP |
| 18665 | HAS_ARCH_FEATURE (Prefer_ERMS) |
| 18666 | jnz 2f |
| 18667 | + HAS_ARCH_FEATURE (Prefer_No_AVX512) |
| 18668 | + jnz 1f |
| 18669 | HAS_ARCH_FEATURE (AVX512F_Usable) |
| 18670 | jz 1f |
| 18671 | lea __memmove_avx512_no_vzeroupper(%rip), %RAX_LP |
| 18672 | diff --git a/sysdeps/x86_64/multiarch/memmove_chk.S b/sysdeps/x86_64/multiarch/memmove_chk.S |
| 18673 | index 7f861206df..a9129c460a 100644 |
| 18674 | --- a/sysdeps/x86_64/multiarch/memmove_chk.S |
| 18675 | +++ b/sysdeps/x86_64/multiarch/memmove_chk.S |
| 18676 | @@ -29,6 +29,8 @@ |
| 18677 | ENTRY(__memmove_chk) |
| 18678 | .type __memmove_chk, @gnu_indirect_function |
| 18679 | LOAD_RTLD_GLOBAL_RO_RDX |
| 18680 | + HAS_ARCH_FEATURE (Prefer_No_AVX512) |
| 18681 | + jnz 1f |
| 18682 | HAS_ARCH_FEATURE (AVX512F_Usable) |
| 18683 | jz 1f |
| 18684 | lea __memmove_chk_avx512_no_vzeroupper(%rip), %RAX_LP |
| 18685 | diff --git a/sysdeps/x86_64/multiarch/mempcpy.S b/sysdeps/x86_64/multiarch/mempcpy.S |
| 18686 | index 51970687cf..87c8299fea 100644 |
| 18687 | --- a/sysdeps/x86_64/multiarch/mempcpy.S |
| 18688 | +++ b/sysdeps/x86_64/multiarch/mempcpy.S |
| 18689 | @@ -32,6 +32,8 @@ ENTRY(__mempcpy) |
| 18690 | lea __mempcpy_erms(%rip), %RAX_LP |
| 18691 | HAS_ARCH_FEATURE (Prefer_ERMS) |
| 18692 | jnz 2f |
| 18693 | + HAS_ARCH_FEATURE (Prefer_No_AVX512) |
| 18694 | + jnz 1f |
| 18695 | HAS_ARCH_FEATURE (AVX512F_Usable) |
| 18696 | jz 1f |
| 18697 | lea __mempcpy_avx512_no_vzeroupper(%rip), %RAX_LP |
| 18698 | diff --git a/sysdeps/x86_64/multiarch/mempcpy_chk.S b/sysdeps/x86_64/multiarch/mempcpy_chk.S |
| 18699 | index 9e49f6f26e..642c67973b 100644 |
| 18700 | --- a/sysdeps/x86_64/multiarch/mempcpy_chk.S |
| 18701 | +++ b/sysdeps/x86_64/multiarch/mempcpy_chk.S |
| 18702 | @@ -30,6 +30,8 @@ |
| 18703 | ENTRY(__mempcpy_chk) |
| 18704 | .type __mempcpy_chk, @gnu_indirect_function |
| 18705 | LOAD_RTLD_GLOBAL_RO_RDX |
| 18706 | + HAS_ARCH_FEATURE (Prefer_No_AVX512) |
| 18707 | + jnz 1f |
| 18708 | HAS_ARCH_FEATURE (AVX512F_Usable) |
| 18709 | jz 1f |
| 18710 | lea __mempcpy_chk_avx512_no_vzeroupper(%rip), %RAX_LP |
| 18711 | diff --git a/sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S b/sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S |
| 18712 | index 28e71fd576..acf448c9a6 100644 |
| 18713 | --- a/sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S |
| 18714 | +++ b/sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S |
| 18715 | @@ -110,6 +110,8 @@ ENTRY (__memset_erms) |
| 18716 | ENTRY (MEMSET_SYMBOL (__memset, erms)) |
| 18717 | # endif |
| 18718 | L(stosb): |
| 18719 | + /* Issue vzeroupper before rep stosb. */ |
| 18720 | + VZEROUPPER |
| 18721 | movq %rdx, %rcx |
| 18722 | movzbl %sil, %eax |
| 18723 | movq %rdi, %rdx |
| 18724 | diff --git a/sysdeps/x86_64/multiarch/memset.S b/sysdeps/x86_64/multiarch/memset.S |
| 18725 | index 96e99341aa..eae39e2ecd 100644 |
| 18726 | --- a/sysdeps/x86_64/multiarch/memset.S |
| 18727 | +++ b/sysdeps/x86_64/multiarch/memset.S |
| 18728 | @@ -41,6 +41,8 @@ ENTRY(memset) |
| 18729 | jnz L(AVX512F) |
| 18730 | lea __memset_avx2_unaligned(%rip), %RAX_LP |
| 18731 | L(AVX512F): |
| 18732 | + HAS_ARCH_FEATURE (Prefer_No_AVX512) |
| 18733 | + jnz 2f |
| 18734 | HAS_ARCH_FEATURE (AVX512F_Usable) |
| 18735 | jz 2f |
| 18736 | lea __memset_avx512_no_vzeroupper(%rip), %RAX_LP |
| 18737 | diff --git a/sysdeps/x86_64/multiarch/memset_chk.S b/sysdeps/x86_64/multiarch/memset_chk.S |
| 18738 | index 2efe6ed909..38d7bef6df 100644 |
| 18739 | --- a/sysdeps/x86_64/multiarch/memset_chk.S |
| 18740 | +++ b/sysdeps/x86_64/multiarch/memset_chk.S |
| 18741 | @@ -38,6 +38,8 @@ ENTRY(__memset_chk) |
| 18742 | jnz L(AVX512F) |
| 18743 | lea __memset_chk_avx2_unaligned(%rip), %RAX_LP |
| 18744 | L(AVX512F): |
| 18745 | + HAS_ARCH_FEATURE (Prefer_No_AVX512) |
| 18746 | + jnz 2f |
| 18747 | HAS_ARCH_FEATURE (AVX512F_Usable) |
| 18748 | jz 2f |
| 18749 | lea __memset_chk_avx512_no_vzeroupper(%rip), %RAX_LP |
| 18750 | diff --git a/sysdeps/x86_64/nptl/tcb-offsets.sym b/sysdeps/x86_64/nptl/tcb-offsets.sym |
| 18751 | index aeb752673a..8a25c482cb 100644 |
| 18752 | --- a/sysdeps/x86_64/nptl/tcb-offsets.sym |
| 18753 | +++ b/sysdeps/x86_64/nptl/tcb-offsets.sym |
| 18754 | @@ -4,7 +4,6 @@ |
| 18755 | |
| 18756 | RESULT offsetof (struct pthread, result) |
| 18757 | TID offsetof (struct pthread, tid) |
| 18758 | -PID offsetof (struct pthread, pid) |
| 18759 | CANCELHANDLING offsetof (struct pthread, cancelhandling) |
| 18760 | CLEANUP_JMP_BUF offsetof (struct pthread, cleanup_jmp_buf) |
| 18761 | CLEANUP offsetof (struct pthread, cleanup) |
| 18762 | diff --git a/sysdeps/x86_64/rtld-offsets.sym b/sysdeps/x86_64/rtld-offsets.sym |
| 18763 | new file mode 100644 |
| 18764 | index 0000000000..fd41b51521 |
| 18765 | --- /dev/null |
| 18766 | +++ b/sysdeps/x86_64/rtld-offsets.sym |
| 18767 | @@ -0,0 +1,6 @@ |
| 18768 | +#define SHARED |
| 18769 | +#include <ldsodefs.h> |
| 18770 | + |
| 18771 | +-- |
| 18772 | + |
| 18773 | +GL_TLS_GENERATION_OFFSET offsetof (struct rtld_global, _dl_tls_generation) |
| 18774 | diff --git a/sysdeps/x86_64/sysdep.h b/sysdeps/x86_64/sysdep.h |
| 18775 | index 75ac747be8..4b67fa80c1 100644 |
| 18776 | --- a/sysdeps/x86_64/sysdep.h |
| 18777 | +++ b/sysdeps/x86_64/sysdep.h |
| 18778 | @@ -89,13 +89,14 @@ lose: \ |
| 18779 | END (name) |
| 18780 | |
| 18781 | #undef JUMPTARGET |
| 18782 | -#ifdef PIC |
| 18783 | +#ifdef SHARED |
| 18784 | # ifdef BIND_NOW |
| 18785 | # define JUMPTARGET(name) *name##@GOTPCREL(%rip) |
| 18786 | # else |
| 18787 | # define JUMPTARGET(name) name##@PLT |
| 18788 | # endif |
| 18789 | #else |
| 18790 | +/* For static archives, branch to target directly. */ |
| 18791 | # define JUMPTARGET(name) name |
| 18792 | #endif |
| 18793 | |
| 18794 | diff --git a/sysdeps/x86_64/tls_get_addr.S b/sysdeps/x86_64/tls_get_addr.S |
| 18795 | new file mode 100644 |
| 18796 | index 0000000000..9d38fb3be5 |
| 18797 | --- /dev/null |
| 18798 | +++ b/sysdeps/x86_64/tls_get_addr.S |
| 18799 | @@ -0,0 +1,61 @@ |
| 18800 | +/* Stack-aligning implementation of __tls_get_addr. x86-64 version. |
| 18801 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 18802 | + This file is part of the GNU C Library. |
| 18803 | + |
| 18804 | + The GNU C Library is free software; you can redistribute it and/or |
| 18805 | + modify it under the terms of the GNU Lesser General Public |
| 18806 | + License as published by the Free Software Foundation; either |
| 18807 | + version 2.1 of the License, or (at your option) any later version. |
| 18808 | + |
| 18809 | + The GNU C Library is distributed in the hope that it will be useful, |
| 18810 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18811 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18812 | + Lesser General Public License for more details. |
| 18813 | + |
| 18814 | + You should have received a copy of the GNU Lesser General Public |
| 18815 | + License along with the GNU C Library; if not, see |
| 18816 | + <http://www.gnu.org/licenses/>. */ |
| 18817 | + |
| 18818 | +#ifdef SHARED |
| 18819 | + |
| 18820 | +# include <sysdep.h> |
| 18821 | +# include "tlsdesc.h" |
| 18822 | +# include "rtld-offsets.h" |
| 18823 | + |
| 18824 | +/* See __tls_get_addr and __tls_get_addr_slow in dl-tls.c. This function |
| 18825 | + call __tls_get_addr_slow on both slow paths. It realigns the stack |
| 18826 | + before the call to work around GCC PR58066. */ |
| 18827 | + |
| 18828 | +ENTRY (__tls_get_addr) |
| 18829 | + mov %fs:DTV_OFFSET, %RDX_LP |
| 18830 | + mov GL_TLS_GENERATION_OFFSET+_rtld_local(%rip), %RAX_LP |
| 18831 | + /* GL(dl_tls_generation) == dtv[0].counter */ |
| 18832 | + cmp %RAX_LP, (%rdx) |
| 18833 | + jne 1f |
| 18834 | + mov TI_MODULE_OFFSET(%rdi), %RAX_LP |
| 18835 | + /* dtv[ti->ti_module] */ |
| 18836 | +# ifdef __LP64__ |
| 18837 | + salq $4, %rax |
| 18838 | + movq (%rdx,%rax), %rax |
| 18839 | +# else |
| 18840 | + movl (%rdx,%rax, 8), %eax |
| 18841 | +# endif |
| 18842 | + cmp $-1, %RAX_LP |
| 18843 | + je 1f |
| 18844 | + add TI_OFFSET_OFFSET(%rdi), %RAX_LP |
| 18845 | + ret |
| 18846 | +1: |
| 18847 | + /* On the slow path, align the stack. */ |
| 18848 | + pushq %rbp |
| 18849 | + cfi_def_cfa_offset (16) |
| 18850 | + cfi_offset (%rbp, -16) |
| 18851 | + mov %RSP_LP, %RBP_LP |
| 18852 | + cfi_def_cfa_register (%rbp) |
| 18853 | + and $-16, %RSP_LP |
| 18854 | + call __tls_get_addr_slow |
| 18855 | + mov %RBP_LP, %RSP_LP |
| 18856 | + popq %rbp |
| 18857 | + cfi_def_cfa (%rsp, 8) |
| 18858 | + ret |
| 18859 | +END (__tls_get_addr) |
| 18860 | +#endif /* SHARED */ |
| 18861 | diff --git a/sysdeps/x86_64/tlsdesc.sym b/sysdeps/x86_64/tlsdesc.sym |
| 18862 | index 33854975d0..fc897ab4b5 100644 |
| 18863 | --- a/sysdeps/x86_64/tlsdesc.sym |
| 18864 | +++ b/sysdeps/x86_64/tlsdesc.sym |
| 18865 | @@ -15,3 +15,6 @@ TLSDESC_ARG offsetof(struct tlsdesc, arg) |
| 18866 | TLSDESC_GEN_COUNT offsetof(struct tlsdesc_dynamic_arg, gen_count) |
| 18867 | TLSDESC_MODID offsetof(struct tlsdesc_dynamic_arg, tlsinfo.ti_module) |
| 18868 | TLSDESC_MODOFF offsetof(struct tlsdesc_dynamic_arg, tlsinfo.ti_offset) |
| 18869 | + |
| 18870 | +TI_MODULE_OFFSET offsetof(tls_index, ti_module) |
| 18871 | +TI_OFFSET_OFFSET offsetof(tls_index, ti_offset) |
| 18872 | diff --git a/sysdeps/x86_64/tst-avx-aux.c b/sysdeps/x86_64/tst-avx-aux.c |
| 18873 | new file mode 100644 |
| 18874 | index 0000000000..e3807de7bb |
| 18875 | --- /dev/null |
| 18876 | +++ b/sysdeps/x86_64/tst-avx-aux.c |
| 18877 | @@ -0,0 +1,47 @@ |
| 18878 | +/* Test case for preserved AVX registers in dynamic linker, -mavx part. |
| 18879 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 18880 | + This file is part of the GNU C Library. |
| 18881 | + |
| 18882 | + The GNU C Library is free software; you can redistribute it and/or |
| 18883 | + modify it under the terms of the GNU Lesser General Public |
| 18884 | + License as published by the Free Software Foundation; either |
| 18885 | + version 2.1 of the License, or (at your option) any later version. |
| 18886 | + |
| 18887 | + The GNU C Library is distributed in the hope that it will be useful, |
| 18888 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18889 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18890 | + Lesser General Public License for more details. |
| 18891 | + |
| 18892 | + You should have received a copy of the GNU Lesser General Public |
| 18893 | + License along with the GNU C Library; if not, see |
| 18894 | + <http://www.gnu.org/licenses/>. */ |
| 18895 | + |
| 18896 | +#include <immintrin.h> |
| 18897 | +#include <stdlib.h> |
| 18898 | +#include <string.h> |
| 18899 | + |
| 18900 | +int |
| 18901 | +tst_avx_aux (void) |
| 18902 | +{ |
| 18903 | +#ifdef __AVX__ |
| 18904 | + extern __m256i avx_test (__m256i, __m256i, __m256i, __m256i, |
| 18905 | + __m256i, __m256i, __m256i, __m256i); |
| 18906 | + |
| 18907 | + __m256i ymm0 = _mm256_set1_epi32 (0); |
| 18908 | + __m256i ymm1 = _mm256_set1_epi32 (1); |
| 18909 | + __m256i ymm2 = _mm256_set1_epi32 (2); |
| 18910 | + __m256i ymm3 = _mm256_set1_epi32 (3); |
| 18911 | + __m256i ymm4 = _mm256_set1_epi32 (4); |
| 18912 | + __m256i ymm5 = _mm256_set1_epi32 (5); |
| 18913 | + __m256i ymm6 = _mm256_set1_epi32 (6); |
| 18914 | + __m256i ymm7 = _mm256_set1_epi32 (7); |
| 18915 | + __m256i ret = avx_test (ymm0, ymm1, ymm2, ymm3, |
| 18916 | + ymm4, ymm5, ymm6, ymm7); |
| 18917 | + ymm0 = _mm256_set1_epi32 (0x12349876); |
| 18918 | + if (memcmp (&ymm0, &ret, sizeof (ret))) |
| 18919 | + abort (); |
| 18920 | + return 0; |
| 18921 | +#else /* __AVX__ */ |
| 18922 | + return 77; |
| 18923 | +#endif /* __AVX__ */ |
| 18924 | +} |
| 18925 | diff --git a/sysdeps/x86_64/tst-avx.c b/sysdeps/x86_64/tst-avx.c |
| 18926 | new file mode 100644 |
| 18927 | index 0000000000..ec2e3a79ff |
| 18928 | --- /dev/null |
| 18929 | +++ b/sysdeps/x86_64/tst-avx.c |
| 18930 | @@ -0,0 +1,49 @@ |
| 18931 | +/* Test case for preserved AVX registers in dynamic linker. |
| 18932 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 18933 | + This file is part of the GNU C Library. |
| 18934 | + |
| 18935 | + The GNU C Library is free software; you can redistribute it and/or |
| 18936 | + modify it under the terms of the GNU Lesser General Public |
| 18937 | + License as published by the Free Software Foundation; either |
| 18938 | + version 2.1 of the License, or (at your option) any later version. |
| 18939 | + |
| 18940 | + The GNU C Library is distributed in the hope that it will be useful, |
| 18941 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18942 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18943 | + Lesser General Public License for more details. |
| 18944 | + |
| 18945 | + You should have received a copy of the GNU Lesser General Public |
| 18946 | + License along with the GNU C Library; if not, see |
| 18947 | + <http://www.gnu.org/licenses/>. */ |
| 18948 | + |
| 18949 | +#include <cpuid.h> |
| 18950 | + |
| 18951 | +int tst_avx_aux (void); |
| 18952 | + |
| 18953 | +static int |
| 18954 | +avx_enabled (void) |
| 18955 | +{ |
| 18956 | + unsigned int eax, ebx, ecx, edx; |
| 18957 | + |
| 18958 | + if (__get_cpuid (1, &eax, &ebx, &ecx, &edx) == 0 |
| 18959 | + || (ecx & (bit_AVX | bit_OSXSAVE)) != (bit_AVX | bit_OSXSAVE)) |
| 18960 | + return 0; |
| 18961 | + |
| 18962 | + /* Check the OS has AVX and SSE saving enabled. */ |
| 18963 | + asm ("xgetbv" : "=a" (eax), "=d" (edx) : "c" (0)); |
| 18964 | + |
| 18965 | + return (eax & 6) == 6; |
| 18966 | +} |
| 18967 | + |
| 18968 | +static int |
| 18969 | +do_test (void) |
| 18970 | +{ |
| 18971 | + /* Run AVX test only if AVX is supported. */ |
| 18972 | + if (avx_enabled ()) |
| 18973 | + return tst_avx_aux (); |
| 18974 | + else |
| 18975 | + return 77; |
| 18976 | +} |
| 18977 | + |
| 18978 | +#define TEST_FUNCTION do_test () |
| 18979 | +#include "../../test-skeleton.c" |
| 18980 | diff --git a/sysdeps/x86_64/tst-avx512-aux.c b/sysdeps/x86_64/tst-avx512-aux.c |
| 18981 | new file mode 100644 |
| 18982 | index 0000000000..6cebc523f2 |
| 18983 | --- /dev/null |
| 18984 | +++ b/sysdeps/x86_64/tst-avx512-aux.c |
| 18985 | @@ -0,0 +1,48 @@ |
| 18986 | +/* Test case for preserved AVX512 registers in dynamic linker, |
| 18987 | + -mavx512 part. |
| 18988 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 18989 | + This file is part of the GNU C Library. |
| 18990 | + |
| 18991 | + The GNU C Library is free software; you can redistribute it and/or |
| 18992 | + modify it under the terms of the GNU Lesser General Public |
| 18993 | + License as published by the Free Software Foundation; either |
| 18994 | + version 2.1 of the License, or (at your option) any later version. |
| 18995 | + |
| 18996 | + The GNU C Library is distributed in the hope that it will be useful, |
| 18997 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18998 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18999 | + Lesser General Public License for more details. |
| 19000 | + |
| 19001 | + You should have received a copy of the GNU Lesser General Public |
| 19002 | + License along with the GNU C Library; if not, see |
| 19003 | + <http://www.gnu.org/licenses/>. */ |
| 19004 | + |
| 19005 | +#include <immintrin.h> |
| 19006 | +#include <stdlib.h> |
| 19007 | +#include <string.h> |
| 19008 | + |
| 19009 | +int |
| 19010 | +tst_avx512_aux (void) |
| 19011 | +{ |
| 19012 | +#ifdef __AVX512F__ |
| 19013 | + extern __m512i avx512_test (__m512i, __m512i, __m512i, __m512i, |
| 19014 | + __m512i, __m512i, __m512i, __m512i); |
| 19015 | + |
| 19016 | + __m512i zmm0 = _mm512_set1_epi32 (0); |
| 19017 | + __m512i zmm1 = _mm512_set1_epi32 (1); |
| 19018 | + __m512i zmm2 = _mm512_set1_epi32 (2); |
| 19019 | + __m512i zmm3 = _mm512_set1_epi32 (3); |
| 19020 | + __m512i zmm4 = _mm512_set1_epi32 (4); |
| 19021 | + __m512i zmm5 = _mm512_set1_epi32 (5); |
| 19022 | + __m512i zmm6 = _mm512_set1_epi32 (6); |
| 19023 | + __m512i zmm7 = _mm512_set1_epi32 (7); |
| 19024 | + __m512i ret = avx512_test (zmm0, zmm1, zmm2, zmm3, |
| 19025 | + zmm4, zmm5, zmm6, zmm7); |
| 19026 | + zmm0 = _mm512_set1_epi32 (0x12349876); |
| 19027 | + if (memcmp (&zmm0, &ret, sizeof (ret))) |
| 19028 | + abort (); |
| 19029 | + return 0; |
| 19030 | +#else /* __AVX512F__ */ |
| 19031 | + return 77; |
| 19032 | +#endif /* __AVX512F__ */ |
| 19033 | +} |
| 19034 | diff --git a/sysdeps/x86_64/tst-avx512.c b/sysdeps/x86_64/tst-avx512.c |
| 19035 | new file mode 100644 |
| 19036 | index 0000000000..a8e42ef553 |
| 19037 | --- /dev/null |
| 19038 | +++ b/sysdeps/x86_64/tst-avx512.c |
| 19039 | @@ -0,0 +1,57 @@ |
| 19040 | +/* Test case for preserved AVX512 registers in dynamic linker. |
| 19041 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 19042 | + This file is part of the GNU C Library. |
| 19043 | + |
| 19044 | + The GNU C Library is free software; you can redistribute it and/or |
| 19045 | + modify it under the terms of the GNU Lesser General Public |
| 19046 | + License as published by the Free Software Foundation; either |
| 19047 | + version 2.1 of the License, or (at your option) any later version. |
| 19048 | + |
| 19049 | + The GNU C Library is distributed in the hope that it will be useful, |
| 19050 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19051 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19052 | + Lesser General Public License for more details. |
| 19053 | + |
| 19054 | + You should have received a copy of the GNU Lesser General Public |
| 19055 | + License along with the GNU C Library; if not, see |
| 19056 | + <http://www.gnu.org/licenses/>. */ |
| 19057 | + |
| 19058 | +#include <cpuid.h> |
| 19059 | + |
| 19060 | +int tst_avx512_aux (void); |
| 19061 | + |
| 19062 | +static int |
| 19063 | +avx512_enabled (void) |
| 19064 | +{ |
| 19065 | +#ifdef bit_AVX512F |
| 19066 | + unsigned int eax, ebx, ecx, edx; |
| 19067 | + |
| 19068 | + if (__get_cpuid (1, &eax, &ebx, &ecx, &edx) == 0 |
| 19069 | + || (ecx & (bit_AVX | bit_OSXSAVE)) != (bit_AVX | bit_OSXSAVE)) |
| 19070 | + return 0; |
| 19071 | + |
| 19072 | + __cpuid_count (7, 0, eax, ebx, ecx, edx); |
| 19073 | + if (!(ebx & bit_AVX512F)) |
| 19074 | + return 0; |
| 19075 | + |
| 19076 | + asm ("xgetbv" : "=a" (eax), "=d" (edx) : "c" (0)); |
| 19077 | + |
| 19078 | + /* Verify that ZMM, YMM and XMM states are enabled. */ |
| 19079 | + return (eax & 0xe6) == 0xe6; |
| 19080 | +#else |
| 19081 | + return 0; |
| 19082 | +#endif |
| 19083 | +} |
| 19084 | + |
| 19085 | +static int |
| 19086 | +do_test (void) |
| 19087 | +{ |
| 19088 | + /* Run AVX512 test only if AVX512 is supported. */ |
| 19089 | + if (avx512_enabled ()) |
| 19090 | + return tst_avx512_aux (); |
| 19091 | + else |
| 19092 | + return 77; |
| 19093 | +} |
| 19094 | + |
| 19095 | +#define TEST_FUNCTION do_test () |
| 19096 | +#include "../../test-skeleton.c" |
| 19097 | diff --git a/sysdeps/x86_64/tst-avx512mod.c b/sysdeps/x86_64/tst-avx512mod.c |
| 19098 | new file mode 100644 |
| 19099 | index 0000000000..4cfb3a2c3d |
| 19100 | --- /dev/null |
| 19101 | +++ b/sysdeps/x86_64/tst-avx512mod.c |
| 19102 | @@ -0,0 +1,48 @@ |
| 19103 | +/* Test case for x86-64 preserved AVX512 registers in dynamic linker. */ |
| 19104 | + |
| 19105 | +#ifdef __AVX512F__ |
| 19106 | +#include <stdlib.h> |
| 19107 | +#include <string.h> |
| 19108 | +#include <immintrin.h> |
| 19109 | + |
| 19110 | +__m512i |
| 19111 | +avx512_test (__m512i x0, __m512i x1, __m512i x2, __m512i x3, |
| 19112 | + __m512i x4, __m512i x5, __m512i x6, __m512i x7) |
| 19113 | +{ |
| 19114 | + __m512i zmm; |
| 19115 | + |
| 19116 | + zmm = _mm512_set1_epi32 (0); |
| 19117 | + if (memcmp (&zmm, &x0, sizeof (zmm))) |
| 19118 | + abort (); |
| 19119 | + |
| 19120 | + zmm = _mm512_set1_epi32 (1); |
| 19121 | + if (memcmp (&zmm, &x1, sizeof (zmm))) |
| 19122 | + abort (); |
| 19123 | + |
| 19124 | + zmm = _mm512_set1_epi32 (2); |
| 19125 | + if (memcmp (&zmm, &x2, sizeof (zmm))) |
| 19126 | + abort (); |
| 19127 | + |
| 19128 | + zmm = _mm512_set1_epi32 (3); |
| 19129 | + if (memcmp (&zmm, &x3, sizeof (zmm))) |
| 19130 | + abort (); |
| 19131 | + |
| 19132 | + zmm = _mm512_set1_epi32 (4); |
| 19133 | + if (memcmp (&zmm, &x4, sizeof (zmm))) |
| 19134 | + abort (); |
| 19135 | + |
| 19136 | + zmm = _mm512_set1_epi32 (5); |
| 19137 | + if (memcmp (&zmm, &x5, sizeof (zmm))) |
| 19138 | + abort (); |
| 19139 | + |
| 19140 | + zmm = _mm512_set1_epi32 (6); |
| 19141 | + if (memcmp (&zmm, &x6, sizeof (zmm))) |
| 19142 | + abort (); |
| 19143 | + |
| 19144 | + zmm = _mm512_set1_epi32 (7); |
| 19145 | + if (memcmp (&zmm, &x7, sizeof (zmm))) |
| 19146 | + abort (); |
| 19147 | + |
| 19148 | + return _mm512_set1_epi32 (0x12349876); |
| 19149 | +} |
| 19150 | +#endif |
| 19151 | diff --git a/sysdeps/x86_64/tst-avxmod.c b/sysdeps/x86_64/tst-avxmod.c |
| 19152 | new file mode 100644 |
| 19153 | index 0000000000..6e5b154997 |
| 19154 | --- /dev/null |
| 19155 | +++ b/sysdeps/x86_64/tst-avxmod.c |
| 19156 | @@ -0,0 +1,48 @@ |
| 19157 | +/* Test case for x86-64 preserved AVX registers in dynamic linker. */ |
| 19158 | + |
| 19159 | +#ifdef __AVX__ |
| 19160 | +#include <stdlib.h> |
| 19161 | +#include <string.h> |
| 19162 | +#include <immintrin.h> |
| 19163 | + |
| 19164 | +__m256i |
| 19165 | +avx_test (__m256i x0, __m256i x1, __m256i x2, __m256i x3, |
| 19166 | + __m256i x4, __m256i x5, __m256i x6, __m256i x7) |
| 19167 | +{ |
| 19168 | + __m256i ymm; |
| 19169 | + |
| 19170 | + ymm = _mm256_set1_epi32 (0); |
| 19171 | + if (memcmp (&ymm, &x0, sizeof (ymm))) |
| 19172 | + abort (); |
| 19173 | + |
| 19174 | + ymm = _mm256_set1_epi32 (1); |
| 19175 | + if (memcmp (&ymm, &x1, sizeof (ymm))) |
| 19176 | + abort (); |
| 19177 | + |
| 19178 | + ymm = _mm256_set1_epi32 (2); |
| 19179 | + if (memcmp (&ymm, &x2, sizeof (ymm))) |
| 19180 | + abort (); |
| 19181 | + |
| 19182 | + ymm = _mm256_set1_epi32 (3); |
| 19183 | + if (memcmp (&ymm, &x3, sizeof (ymm))) |
| 19184 | + abort (); |
| 19185 | + |
| 19186 | + ymm = _mm256_set1_epi32 (4); |
| 19187 | + if (memcmp (&ymm, &x4, sizeof (ymm))) |
| 19188 | + abort (); |
| 19189 | + |
| 19190 | + ymm = _mm256_set1_epi32 (5); |
| 19191 | + if (memcmp (&ymm, &x5, sizeof (ymm))) |
| 19192 | + abort (); |
| 19193 | + |
| 19194 | + ymm = _mm256_set1_epi32 (6); |
| 19195 | + if (memcmp (&ymm, &x6, sizeof (ymm))) |
| 19196 | + abort (); |
| 19197 | + |
| 19198 | + ymm = _mm256_set1_epi32 (7); |
| 19199 | + if (memcmp (&ymm, &x7, sizeof (ymm))) |
| 19200 | + abort (); |
| 19201 | + |
| 19202 | + return _mm256_set1_epi32 (0x12349876); |
| 19203 | +} |
| 19204 | +#endif |
| 19205 | diff --git a/sysdeps/x86_64/tst-sse.c b/sysdeps/x86_64/tst-sse.c |
| 19206 | new file mode 100644 |
| 19207 | index 0000000000..dd1537cf27 |
| 19208 | --- /dev/null |
| 19209 | +++ b/sysdeps/x86_64/tst-sse.c |
| 19210 | @@ -0,0 +1,46 @@ |
| 19211 | +/* Test case for preserved SSE registers in dynamic linker. |
| 19212 | + Copyright (C) 2017 Free Software Foundation, Inc. |
| 19213 | + This file is part of the GNU C Library. |
| 19214 | + |
| 19215 | + The GNU C Library is free software; you can redistribute it and/or |
| 19216 | + modify it under the terms of the GNU Lesser General Public |
| 19217 | + License as published by the Free Software Foundation; either |
| 19218 | + version 2.1 of the License, or (at your option) any later version. |
| 19219 | + |
| 19220 | + The GNU C Library is distributed in the hope that it will be useful, |
| 19221 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19222 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19223 | + Lesser General Public License for more details. |
| 19224 | + |
| 19225 | + You should have received a copy of the GNU Lesser General Public |
| 19226 | + License along with the GNU C Library; if not, see |
| 19227 | + <http://www.gnu.org/licenses/>. */ |
| 19228 | + |
| 19229 | +#include <immintrin.h> |
| 19230 | +#include <stdlib.h> |
| 19231 | +#include <string.h> |
| 19232 | + |
| 19233 | +extern __m128i sse_test (__m128i, __m128i, __m128i, __m128i, |
| 19234 | + __m128i, __m128i, __m128i, __m128i); |
| 19235 | + |
| 19236 | +static int |
| 19237 | +do_test (void) |
| 19238 | +{ |
| 19239 | + __m128i xmm0 = _mm_set1_epi32 (0); |
| 19240 | + __m128i xmm1 = _mm_set1_epi32 (1); |
| 19241 | + __m128i xmm2 = _mm_set1_epi32 (2); |
| 19242 | + __m128i xmm3 = _mm_set1_epi32 (3); |
| 19243 | + __m128i xmm4 = _mm_set1_epi32 (4); |
| 19244 | + __m128i xmm5 = _mm_set1_epi32 (5); |
| 19245 | + __m128i xmm6 = _mm_set1_epi32 (6); |
| 19246 | + __m128i xmm7 = _mm_set1_epi32 (7); |
| 19247 | + __m128i ret = sse_test (xmm0, xmm1, xmm2, xmm3, |
| 19248 | + xmm4, xmm5, xmm6, xmm7); |
| 19249 | + xmm0 = _mm_set1_epi32 (0x12349876); |
| 19250 | + if (memcmp (&xmm0, &ret, sizeof (ret))) |
| 19251 | + abort (); |
| 19252 | + return 0; |
| 19253 | +} |
| 19254 | + |
| 19255 | +#define TEST_FUNCTION do_test () |
| 19256 | +#include "../../test-skeleton.c" |
| 19257 | diff --git a/sysdeps/x86_64/tst-ssemod.c b/sysdeps/x86_64/tst-ssemod.c |
| 19258 | new file mode 100644 |
| 19259 | index 0000000000..907a64c69e |
| 19260 | --- /dev/null |
| 19261 | +++ b/sysdeps/x86_64/tst-ssemod.c |
| 19262 | @@ -0,0 +1,46 @@ |
| 19263 | +/* Test case for x86-64 preserved SSE registers in dynamic linker. */ |
| 19264 | + |
| 19265 | +#include <stdlib.h> |
| 19266 | +#include <string.h> |
| 19267 | +#include <immintrin.h> |
| 19268 | + |
| 19269 | +__m128i |
| 19270 | +sse_test (__m128i x0, __m128i x1, __m128i x2, __m128i x3, |
| 19271 | + __m128i x4, __m128i x5, __m128i x6, __m128i x7) |
| 19272 | +{ |
| 19273 | + __m128i xmm; |
| 19274 | + |
| 19275 | + xmm = _mm_set1_epi32 (0); |
| 19276 | + if (memcmp (&xmm, &x0, sizeof (xmm))) |
| 19277 | + abort (); |
| 19278 | + |
| 19279 | + xmm = _mm_set1_epi32 (1); |
| 19280 | + if (memcmp (&xmm, &x1, sizeof (xmm))) |
| 19281 | + abort (); |
| 19282 | + |
| 19283 | + xmm = _mm_set1_epi32 (2); |
| 19284 | + if (memcmp (&xmm, &x2, sizeof (xmm))) |
| 19285 | + abort (); |
| 19286 | + |
| 19287 | + xmm = _mm_set1_epi32 (3); |
| 19288 | + if (memcmp (&xmm, &x3, sizeof (xmm))) |
| 19289 | + abort (); |
| 19290 | + |
| 19291 | + xmm = _mm_set1_epi32 (4); |
| 19292 | + if (memcmp (&xmm, &x4, sizeof (xmm))) |
| 19293 | + abort (); |
| 19294 | + |
| 19295 | + xmm = _mm_set1_epi32 (5); |
| 19296 | + if (memcmp (&xmm, &x5, sizeof (xmm))) |
| 19297 | + abort (); |
| 19298 | + |
| 19299 | + xmm = _mm_set1_epi32 (6); |
| 19300 | + if (memcmp (&xmm, &x6, sizeof (xmm))) |
| 19301 | + abort (); |
| 19302 | + |
| 19303 | + xmm = _mm_set1_epi32 (7); |
| 19304 | + if (memcmp (&xmm, &x7, sizeof (xmm))) |
| 19305 | + abort (); |
| 19306 | + |
| 19307 | + return _mm_set1_epi32 (0x12349876); |
| 19308 | +} |