summaryrefslogtreecommitdiff
path: root/nuttx
diff options
context:
space:
mode:
Diffstat (limited to 'nuttx')
-rw-r--r--nuttx/fs/vfs/fs_ioctl.c2
-rw-r--r--nuttx/include/nuttx/fs/fs.h2
-rw-r--r--nuttx/include/sys/ioctl.h2
-rw-r--r--nuttx/libc/Kconfig15
-rw-r--r--nuttx/libc/misc/lib_ioctl.c20
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 <sys/ioctl.h>
#include <stdarg.h>
#include <errno.h>
+#include <assert.h>
#include <nuttx/fs/fs.h>
@@ -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);