From ec9c929ff00c07df0e667b68bec285e1b02d8445 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 29 Nov 2014 17:39:40 -0600 Subject: Updated comments --- nuttx/fs/vfs/fs_ioctl.c | 2 +- nuttx/include/nuttx/fs/fs.h | 2 +- nuttx/include/sys/ioctl.h | 2 +- nuttx/libc/Kconfig | 15 ++++++++++++++- nuttx/libc/misc/lib_ioctl.c | 20 ++++++++++++++++---- 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/nuttx/fs/vfs/fs_ioctl.c b/nuttx/fs/vfs/fs_ioctl.c index d96d95889..eb48d5c34 100644 --- a/nuttx/fs/vfs/fs_ioctl.c +++ b/nuttx/fs/vfs/fs_ioctl.c @@ -69,7 +69,7 @@ * * Return: * >=0 on success (positive non-zero values are cmd-specific) - * -1 on failure withi errno set properly: + * -1 on failure with errno set properly: * * EBADF * 'fd' is not a valid descriptor. diff --git a/nuttx/include/nuttx/fs/fs.h b/nuttx/include/nuttx/fs/fs.h index 1baa91cee..ad05da5d7 100644 --- a/nuttx/include/nuttx/fs/fs.h +++ b/nuttx/include/nuttx/fs/fs.h @@ -638,7 +638,7 @@ int close_blockdriver(FAR struct inode *inode); * * Return: * >=0 on success (positive non-zero values are cmd-specific) - * -1 on failure withi errno set properly: + * -1 on failure with errno set properly: * * EBADF * 'fd' is not a valid descriptor. diff --git a/nuttx/include/sys/ioctl.h b/nuttx/include/sys/ioctl.h index 60dfa5cea..01987d58f 100644 --- a/nuttx/include/sys/ioctl.h +++ b/nuttx/include/sys/ioctl.h @@ -84,7 +84,7 @@ extern "C" * * Return: * >=0 on success (positive non-zero values are cmd-specific) - * -1 on failure withi errno set properly: + * -1 on failure with errno set properly: * * EBADF * 'fd' is not a valid descriptor. diff --git a/nuttx/libc/Kconfig b/nuttx/libc/Kconfig index b49b92e31..5ea546aa9 100644 --- a/nuttx/libc/Kconfig +++ b/nuttx/libc/Kconfig @@ -76,7 +76,20 @@ config LIBC_IOCTL_VARIADIC WARNING: Use of this option could cause subtle system errors is the third argument is omitted or if the sizeof the thread argument - is anything other than sizeof (unsigned long). + is anything other than sizeof (unsigned long). Most small integers + will be promoted to 'int'. The following assertion appears in ioctl(): + + DEBUGASSERT(sizeof(int) == sizeof(unsigned long) && + sizeof(FAR void *) == sizeof(unsigned long)); + + Do not enable this option if the above is not true. 32-bit ARM + should pass this test with all three types having sizeof(type) == 4 + bytes. 'float' should also be tested. But 'long long' and 'double' + are out of the question! Don't event try to pass them. + + And what will happen if no third argument is passed? In most cases, + this should just result in a garbage value for arg. But you may + discover cases where something worse happens! config LIB_RAND_ORDER int "Order of the random number generate" diff --git a/nuttx/libc/misc/lib_ioctl.c b/nuttx/libc/misc/lib_ioctl.c index a2838790c..fa0d90804 100644 --- a/nuttx/libc/misc/lib_ioctl.c +++ b/nuttx/libc/misc/lib_ioctl.c @@ -42,6 +42,7 @@ #include #include #include +#include #include @@ -66,7 +67,7 @@ * * Return: * >=0 on success (positive non-zero values are cmd-specific) - * -1 on failure withi errno set properly: + * -1 on failure with errno set properly: * * EBADF * 'fd' is not a valid descriptor. @@ -84,15 +85,26 @@ int ioctl(int fd, int req, ...) { - va_list ap; unsigned long arg; + va_list ap; /* Get the unsigned long argument. * - * REVISIT: This could cause of the crash down the road if the actual size - * of the argument is anything other than sizeof(unsigned long); + * REVISIT: This could be the cause of the crash down the road if the + * actual size of the argument is anything other than sizeof(unsigned long). + * Most small integers will be promoted to 'int'. ARM should pass the + * following test with all three types having sizeof(type) == 4 bytes. + * 'float' should also be tested. But 'long long' and 'double' are out of + * the question! Don't try to pass them. + * + * And what will happen if no third argument is passed? In most cases, + * this should just result in a garbage value for arg. But you may + * discover cases where something worse happens! */ + DEBUGASSERT(sizeof(int) == sizeof(unsigned long) && + sizeof(FAR void *) == sizeof(unsigned long)); + va_start(ap, req); arg = va_arg(ap, unsigned long); va_end(ap); -- cgit v1.2.3