0002-libsanitizer-uclibc-sigaction-layout.patch 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. libsanitizer: add SANITIZER_UCLIBC branch for struct sigaction layout
  2. uClibc-ng's struct sigaction has fields in the kernel order
  3. (sa_handler, sa_flags, sa_restorer, sa_mask) so that the sigaction()
  4. syscall wrapper can pass the struct to rt_sigaction without
  5. translation -- see uClibc-ng's bits/sigaction.h.
  6. libsanitizer's __sanitizer_sigaction assumed glibc's userspace order
  7. (sa_handler, sa_mask, sa_flags, sa_restorer) which does not match,
  8. causing CHECK_STRUCT_SIZE_AND_OFFSET(sigaction, sa_mask/sa_flags/
  9. sa_restorer) to fire with comparisons reducing to '(4 == 12)',
  10. '(132 == 4)' and '(136 == 8)'.
  11. Add a dedicated SANITIZER_UCLIBC branch that mirrors the kernel layout.
  12. This is consistent with the existing per-libc/per-arch variants
  13. (Android 32-bit, MIPS, FreeBSD, s390x, sparc) already in the same
  14. struct. No effect on glibc or musl builds.
  15. Signed-off-by: Ramin Moussavi <ramin.moussavi@yacoub.de>
  16. ---
  17. --- a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h
  18. +++ b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h
  19. @@ -642,6 +642,20 @@
  20. uptr sa_flags;
  21. void (*sa_restorer)();
  22. };
  23. +#elif SANITIZER_UCLIBC
  24. +// uClibc-ng's struct sigaction mirrors the Linux kernel's layout
  25. +// (sa_flags / sa_restorer before sa_mask) so that the sigaction()
  26. +// syscall wrapper passes the struct to the kernel without translation.
  27. +// See uClibc-ng's libc/sysdeps/linux/common/bits/sigaction.h.
  28. +struct __sanitizer_sigaction {
  29. + union {
  30. + __sanitizer_sigactionhandler_ptr sigaction;
  31. + __sanitizer_sighandler_ptr handler;
  32. + };
  33. + unsigned long sa_flags;
  34. + void (*sa_restorer)(void);
  35. + __sanitizer_sigset_t sa_mask;
  36. +};
  37. #else // !SANITIZER_ANDROID
  38. struct __sanitizer_sigaction {
  39. #if defined(__mips__) && !SANITIZER_FREEBSD