glibc/sysdeps/unix/sysv/linux/x86_64
Adhemerval Zanella 7a887dd537 posix: Fix -Warray-bounds instances building timer_create [BZ #26687]
GCC 11 -Warray-bounds triggers invalid warnings when building
Linux timer_create.c:

../sysdeps/unix/sysv/linux/timer_create.c: In function '__timer_create_new':
../sysdeps/unix/sysv/linux/timer_create.c:83:17: warning: array subscript 'struct timer[0]' is partly outside array bounds of 'unsigned char[8]' [-Warray-bounds]
   83 |             newp->sigev_notify = (evp != NULL
      |                 ^~
../sysdeps/unix/sysv/linux/timer_create.c:59:47: note: referencing an object of size 8 allocated by 'malloc'
   59 |         struct timer *newp = (struct timer *) malloc (offsetof (struct timer,
      |                                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   60 |                                                                 thrfunc));
      |                                                                 ~~~~~~~~~

The struct allocated for !SIGEV_THREAD timers only requires two 'int'
fields (sigev_notify and ktimerid) and the offsetof trick tries minimize
the memory usage by only allocation the required size.  However,
although the resulting size is suffice for !SIGEV_THREAD time, accessing
the partially allocated object is error-prone and UB.

This patch fixes both issues by embedding the information whether
the timer if a SIGEV_THREAD in the returned 'timer_t'.  For
!SIGEV_THREAD, the resulting 'timer_t' is the returned kernel timer
identifer (kernel_timer_t), while for SIGEV_THREAD it uses the fact
malloc returns at least _Alignof (max_align_t) pointers plus that
valid kernel_timer_t are always positive to set MSB bit of the returned
'timer_t' to indicate the timer handles a SIGEV_THREAD.

It allows to remove the memory allocation for !SIGEV_THREAD and also
remove the 'sigev_notify' field from 'struct timer'.

Checked on x86_64-linux-gnu and i686-linux-gnu.
2020-10-06 15:29:35 -03:00
..
64 Update mallinfo2 ABI, and test 2020-09-17 18:49:30 -04:00
x32 Update mallinfo2 ABI, and test 2020-09-17 18:49:30 -04:00
____longjmp_chk.S Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
__start_context.S Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
brk.c Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
clone.S Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
compat-timer.h Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
configure
configure.ac
dl-cache.h Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
dl-procinfo.c Add _dl_x86_cpu_features to rtld_global 2015-08-13 03:41:22 -07:00
dl-procinfo.h x86: Set dl_platform and dl_hwcap from CPU features [BZ #21391] 2017-05-03 13:44:35 -07:00
getcontext.S Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
Implies
kernel_stat.h linux: Define STAT64_IS_KERNEL_STAT64 2020-09-11 14:35:11 -03:00
kernel-features.h Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
ldconfig.h Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
ldd-rewrite.sed
libmvec.abilist Ignore absolute symbols in ABI tests. 2018-05-04 15:46:32 +00:00
makecontext.c Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
Makefile
readelflib.c
register-dump.h Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
setcontext.S Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
sigaction.c Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
sigaltstack-offsets.sym
sigcontextinfo.h Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
swapcontext.S Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
syscall.S Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
syscalls.list Remove p{read,write}{v} and fallocate from x86 auto-generation list 2017-08-22 17:27:18 -03:00
sysdep.h Add SYSCALL_ULONG_ARG_[12] to pass long to syscall [BZ #25810] 2020-04-29 05:35:34 -07:00
sysdep.S Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
timer_create.c Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
timer_delete.c Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
timer_getoverr.c Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
timer_gettime.c posix: Fix -Warray-bounds instances building timer_create [BZ #26687] 2020-10-06 15:29:35 -03:00
timer_settime.c posix: Fix -Warray-bounds instances building timer_create [BZ #26687] 2020-10-06 15:29:35 -03:00
ucontext_i.sym x86-64/CET: Extend ucontext_t to save shadow stack 2018-07-25 06:37:31 -07:00
Versions Revert {send,sendm,recv,recvm}msg conformance changes 2016-06-10 11:58:16 -03:00
vfork.S Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00