glibc/sysdeps
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
..
aarch64 aarch64: enforce >=64K guard size [BZ #26691] 2020-10-02 09:57:44 +01:00
alpha aarch64: enforce >=64K guard size [BZ #26691] 2020-10-02 09:57:44 +01:00
arc aarch64: enforce >=64K guard size [BZ #26691] 2020-10-02 09:57:44 +01:00
arm aarch64: enforce >=64K guard size [BZ #26691] 2020-10-02 09:57:44 +01:00
csky aarch64: enforce >=64K guard size [BZ #26691] 2020-10-02 09:57:44 +01:00
generic Linux: Remove rseq support 2020-07-16 17:55:35 +02:00
gnu string: Fix strerrorname_np return value [BZ #26555] 2020-09-29 13:56:06 -03:00
hppa aarch64: enforce >=64K guard size [BZ #26691] 2020-10-02 09:57:44 +01:00
htl htl: Move cleanup handling to non-private libc-lock 2020-06-28 00:13:57 +00:00
hurd hurd: Fix build-many-glibcs.py 2020-07-13 14:25:03 -03:00
i386 aarch64: enforce >=64K guard size [BZ #26691] 2020-10-02 09:57:44 +01:00
ia64 aarch64: enforce >=64K guard size [BZ #26691] 2020-10-02 09:57:44 +01:00
ieee754 math: Fix inaccuracy of j0f for x >= 2^127 when sin(x)+cos(x) is tiny 2020-08-07 16:33:13 -03:00
m68k aarch64: enforce >=64K guard size [BZ #26691] 2020-10-02 09:57:44 +01:00
mach hurd: add ST_RELATIME 2020-09-27 18:23:27 +02:00
microblaze aarch64: enforce >=64K guard size [BZ #26691] 2020-10-02 09:57:44 +01:00
mips aarch64: enforce >=64K guard size [BZ #26691] 2020-10-02 09:57:44 +01:00
nios2 aarch64: enforce >=64K guard size [BZ #26691] 2020-10-02 09:57:44 +01:00
nptl Fix GCC 11 -Warray-parameter warning for __sigsetjmp (bug 26647) 2020-10-05 16:46:46 +00:00
posix Remove internal usage of extensible stat functions 2020-09-11 14:35:32 -03:00
powerpc aarch64: enforce >=64K guard size [BZ #26691] 2020-10-02 09:57:44 +01:00
pthread C11 threads: Fix inaccuracies in testsuite 2020-09-07 11:42:52 +02:00
riscv aarch64: enforce >=64K guard size [BZ #26691] 2020-10-02 09:57:44 +01:00
s390 aarch64: enforce >=64K guard size [BZ #26691] 2020-10-02 09:57:44 +01:00
sh aarch64: enforce >=64K guard size [BZ #26691] 2020-10-02 09:57:44 +01:00
sparc aarch64: enforce >=64K guard size [BZ #26691] 2020-10-02 09:57:44 +01:00
unix posix: Fix -Warray-bounds instances building timer_create [BZ #26687] 2020-10-06 15:29:35 -03:00
wordsize-32 Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
wordsize-64 Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
x86 Reversing calculation of __x86_shared_non_temporal_threshold 2020-09-28 22:10:39 +00:00
x86_64 aarch64: enforce >=64K guard size [BZ #26691] 2020-10-02 09:57:44 +01:00