View Issue Details

IDProjectCategoryView StatusLast Update
00019441003.1(2024)/Issue8System Interfacespublic2025-09-10 23:48
Reporterjoelsherrill Assigned To 
PrioritynormalSeverityCommentTypeClarification Requested
Status NewResolutionOpen 
NameJoel Sherrill
OrganizationRTEMS Project
User Reference
SectionC243.pdf
Page Numberp. 1553
Line Number52176
Interp Status
Final Accepted Text
Summary0001944: posix_devctl() uses int for command where some ioctl() implementations use larger type
DescriptionThe posix_devctl() function is intended to provide a type safe alternative to ioctl(). Unfortunately, it uses int for dcmd which is not necessarily large enough to contain the "op/dcmd" value. Per the Linux man page https://man7.org/linux/man-pages/man2/ioctl.2.html, ioctl() commonly has one of two signatures:

       int ioctl(int fd, unsigned long op, ...); /* glibc, BSD */
       int ioctl(int fd, int op, ...); /* musl, other UNIX */

FreeBSD assumes the "op" is at least 32 bits in size and that the most significant bit can be set. The macros generating "op" values end up generating 32-bit signed numbers which causes compiler warnings when using those computed values with posix_devctl().

Per the Linux ioct.h man page cited above, the "op" is constructed similarly and can explicitly set the most significant bit in the 32-bit int. This is the same problem.

The rationale provided with the posix_devctl() discusses why direction was not explicitly mentioned in the "dcmd" encoding. However, it misses that the existing practices needed an unsigned value.

Note: The BSD and Linux op encoding schemes do not work at all on targets where int is 16 bits.
Desired ActionThere are two possible alternative resolutions. One is to switch to unsigned long per glib and BSD. The other is to go to a special type which the implementer can define such as ioctl_command_t.

Historically 32-bits have been enough but using a new type for "dcmd" allows an implementation to use a width that does not correspond to int or long type if that provides value.
TagsNo tags attached.

Activities

There are no notes attached to this issue.

Issue History

Date Modified Username Field Change
2025-09-10 23:48 joelsherrill New Issue