nuttx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-nuttx] patacongo opened a new issue #959: Issues with variadic ioctil()
Date Sun, 03 May 2020 16:43:33 GMT

patacongo opened a new issue #959:
URL: https://github.com/apache/incubator-nuttx/issues/959


   ## History
   
   For many years, ioctl() was non-standard function not described in any POSIX documents.
 The typical prototype was:
   
       int ioctl(int fd, int cmd, unsigned long arg);
   
   This has numerous limitations:  There could only be on problem and it assume that all types
of interest could fit into an unsigned long.  In particular, things like pointers to structures.
   
   Linux implemented the variadic ioctl command a few years back:
   
       int ioctl(int fd, int cmd, ...);
   
   For Linux compatibility, a very limited version of this variadic ioctl was implement. 
It was limited because it still expected a signal argument of type unsigned long.  This was
_not_ a significant issue, however, because the fixed, single argument version was the default.
   
   However, Opengroup.org has recently specified the ioctl command as the variadic form: 
https://pubs.opengroup.org/onlinepubs/009604599/functions/ioctl.html (although it technically
only applies to a special class of STREAM devices).  In order comply with this Opengroup.org
requirement, the default was changed so that the variadic ioctl() is now the default form
(commit c3b0848284cfb99f2254dfbcaee66c277d7d27e1).
   
   ## Problems
   
   The problem with the use of the variadic ioctl() is that now the arguments provided to
the ioctl must be explicitly cast to (unsigned long) or, if they differ in width, the extraction
of the single unsigned long argument will fail.  In the past, no explicit cast was required;
the provided argument would be automatically cast to unsigned long, if possible.
   
   This is further complicated by newer 64-bit architectures.  sizeof(void *) make not be
equal to sizeof(unsigned long).
   
   ## Solution
   
   There is only on proper solution:
   
   1. Remove the legacy, fixed argument ioctl() interface altogether; remove CONFIG_LIBC_IOCTL_VARIADIC
   2. Do not extract the single unsigned int argument; do not call file_ioctl().  Instead,
create a new os interface vioctl() which is also a system call:
   
       int vioctl(int fd, int cmd, va_list arg);
   
   3. Replace all implementations of ioctl() in all drivers with the variadic argument list.
   4. For each ioctl command, call va_start() to get the argument.  Remove all current casts
of the unsigned long arg.
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



Mime
View raw message