fortify_source and syscall wrapping

Jan Leupold leupold at
Thu Sep 10 12:37:16 CEST 2020

Hi all,

I just had a long debugging session and wanted to comment the result here
on the list.

When using -D_FORTIFY_SOURCE=2 the first ioctl() after open() suddenly
failed. This is due to an inline function "open()" (in bits/fcntl2.h),
that will analyse the call arguments and forward the function call
accordingly. When the second argument is not a compile-time constant,
then the call is forwarded to "__open_2()" instead of "__open_alias()".

So when you write:

open("/dev/rtdm/rtser0", O_RDWR);

then __cobalt_open() will be called. But when you use a function like

int my_function(int mode) {
    return open("/dev/rtdm/rtser0", mode);

then __open_2() will be called. The consequence is that the following
ioctl(RTSER_RTIOC_SET_CONFIG) fails, as the file descriptor was not
opened by __cobalt_open().

This is a nasty little difference. My solution was to write:

int my_function(int mode) {
    return __WRAP(open("/dev/rtdm/rtser0", mode));

Maybe this is just ancient history for you, but I had some "fun" to find


Mit freundlichen Grüßen

*Jan Leupold*
R-S-I Logo <>

R-S-I Elektrotechnik GmbH & Co. KG
Woelkestraße 11
D-85301 Schweitenkirchen <>

Tel: +49 8444 9204-32
Fax: +49 8444 9204-50
leupold at <mailto:leupold at>

Amtsgericht Ingolstadt - GmbH: HRB 191328 - KG: HRA 170363
Geschäftsführer: Dr.-Ing. Michael Sorg, Dipl.-Ing. Franz Sorg
USt-IdNr.: DE 128592548

More information about the Xenomai mailing list