--- /dev/null
+/* Tests for ioctl wrappers.
+ More complicated ones than just trivial ones in scalar_ioctl. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <strings.h>
+#include <unistd.h>
+#include <net/if.h>
+#include <sys/socket.h>
+#include <sys/sockio.h>
+
+/* sockio */
+__attribute__((noinline))
+static int test_SIOCGIFCONF(void)
+{
+ int fd = socket(AF_INET, SOCK_DGRAM, 0);
+ if (fd < 0)
+ perror("socket");
+
+ int n_ifs;
+ if (ioctl(fd, SIOCGIFNUM, &n_ifs) < 0)
+ perror("ioctl(SIOCGIFNUM)");
+
+ struct ifconf ifc;
+ ifc.ifc_len = (n_ifs + 1) * sizeof(struct ifreq);
+ ifc.ifc_buf = malloc((n_ifs + 1) * sizeof(struct ifreq));
+ if (ifc.ifc_buf == NULL)
+ perror("malloc");
+
+ if (ioctl(fd, SIOCGIFCONF, &ifc) < 0)
+ perror("ioctl(SIOCGIFCONF)");
+
+ /* Check definedness of ifc attributes ... */
+ int x = 0;
+ if (ifc.ifc_len != 0) x = -1; else x = -2;
+ if (ifc.ifc_req != NULL) x = -3; else x = -4;
+ if (strcmp(ifc.ifc_req[0].ifr_name, "") != 0) x = -5; else x = -6;
+ /* ... and now one which is not defined. */
+ if (strcmp(ifc.ifc_req[n_ifs].ifr_name, "") != 0) x = -7; else x = -8;
+
+ free(ifc.ifc_buf);
+ close(fd);
+ return x;
+}
+
+__attribute__((noinline))
+static int test_SIOCGLIFCONF(void)
+{
+ int fd = socket(AF_INET, SOCK_DGRAM, 0);
+ if (fd < 0)
+ perror("socket");
+
+ struct lifnum lifn;
+ lifn.lifn_family = AF_INET;
+ lifn.lifn_flags = 0;
+ if (ioctl(fd, SIOCGLIFNUM, &lifn) < 0)
+ perror("ioctl(SIOCGLIFNUM)");
+
+ struct lifconf lifc;
+ lifc.lifc_family = AF_INET;
+ lifc.lifc_flags = 0;
+ lifc.lifc_len = (lifn.lifn_count + 1) * sizeof(struct lifreq);
+ lifc.lifc_buf = malloc((lifn.lifn_count + 1) * sizeof(struct lifreq));
+ if (lifc.lifc_buf == NULL)
+ perror("malloc");
+
+ if (ioctl(fd, SIOCGLIFCONF, &lifc) < 0)
+ perror("ioctl(SIOCGLIFCONF)");
+
+ /* Check definedness of lifc attributes ... */
+ int x = 0;
+ if (lifc.lifc_len != 0) x = -1; else x = -2;
+ if (lifc.lifc_req != NULL) x = -3; else x = -4;
+ if (strcmp(lifc.lifc_req[0].lifr_name, "") != 0) x = -5; else x = -6;
+ /* ... and now one which is not defined. */
+ if (strcmp(lifc.lifc_req[lifn.lifn_count].lifr_name, "") != 0)
+ x = -7; else x = -8;
+
+ free(lifc.lifc_buf);
+ close(fd);
+ return x;
+}
+
+int main(void)
+{
+ /* sockio */
+ test_SIOCGIFCONF();
+ test_SIOCGLIFCONF();
+
+ return 0;
+}
-/* Basic ioctl test. */
+/* Basic ioctl scalar tests. */
#define __EXTENSIONS__ 1
#include "scalar.h"
-#include <unistd.h>
#include <net/if.h>
#include <sys/crypto/ioctl.h>
#include <sys/dtrace.h>
static void sys_ioctl_SIOCGIFCONF_2(void)
{
struct ifconf ifc;
- char buf[5];
+ char buf[] = "";
- ifc.ifc_len = x0 + 5;
+ ifc.ifc_len = x0 + 1;
ifc.ifc_buf = (void *) (x0 + buf);
GO(SYS_ioctl, "(SIOCGIFCONF), 5s 0m");
SY(SYS_ioctl, x0 - 1, x0 + SIOCGIFCONF, &ifc + x0); FAIL;
}
-__attribute__((noinline))
-static int sys_ioctl_SIOCGIFCONF_3(void)
-{
- int fd = socket(AF_INET, SOCK_DGRAM, 0);
- if (fd < 0)
- perror("socket");
-
- int n_ifs;
- if (ioctl(fd, SIOCGIFNUM, &n_ifs) < 0)
- perror("ioctl(SIOCGIFNUM)");
-
- struct ifconf ifc;
- ifc.ifc_len = (n_ifs + 1) * sizeof(struct ifreq);
- ifc.ifc_buf = malloc((n_ifs + 1) * sizeof(struct ifreq));
- if (ifc.ifc_buf == NULL)
- perror("malloc");
-
- GO(SYS_ioctl, "(SIOCGIFCONF), 1s 0m");
- if (ioctl(fd, SIOCGIFCONF, &ifc) < 0)
- perror("ioctl(SIOCGIFCONF)");
-
- /* Check definedness of ifc attributes ... */
- int x = 0;
- if (ifc.ifc_len != 0) x = -1; else x = -2;
- if (ifc.ifc_req != NULL) x = -3; else x = -4;
- if (strcmp(ifc.ifc_req[0].ifr_name, "") != 0) x = -5; else x = -6;
- /* ... and now one which is not defined. */
- if (strcmp(ifc.ifc_req[n_ifs].ifr_name, "") != 0) x = -7; else x = -8;
-
- free(ifc.ifc_buf);
- close(fd);
- return x;
-}
-
__attribute__((noinline))
static void sys_ioctl_SIOCGIFFLAGS(void)
{
static void sys_ioctl_SIOCGLIFCONF_2(void)
{
struct lifconf lifc;
- char buf[5];
+ char buf[] = "";
- lifc.lifc_len = x0 + 5;
+ lifc.lifc_len = x0 + 1;
lifc.lifc_buf = (void *) (x0 + buf);
lifc.lifc_family = x0 + 1;
lifc.lifc_flags = x0 + 0;
SY(SYS_ioctl, x0 - 1, x0 + SIOCGLIFCONF, &lifc + x0); FAIL;
}
-__attribute__((noinline))
-static int sys_ioctl_SIOCGLIFCONF_3(void)
-{
- int fd = socket(AF_INET, SOCK_DGRAM, 0);
- if (fd < 0)
- perror("socket");
-
- struct lifnum lifn;
- lifn.lifn_family = AF_INET;
- lifn.lifn_flags = 0;
- if (ioctl(fd, SIOCGLIFNUM, &lifn) < 0)
- perror("ioctl(SIOCGLIFNUM)");
-
- struct lifconf lifc;
- lifc.lifc_family = AF_INET;
- lifc.lifc_flags = 0;
- lifc.lifc_len = (lifn.lifn_count + 1) * sizeof(struct lifreq);
- lifc.lifc_buf = malloc((lifn.lifn_count + 1) * sizeof(struct lifreq));
- if (lifc.lifc_buf == NULL)
- perror("malloc");
-
- GO(SYS_ioctl, "(SIOCGLIFCONF), 1s 0m");
- if (ioctl(fd, SIOCGLIFCONF, &lifc) < 0)
- perror("ioctl(SIOCGLIFCONF)");
-
- /* Check definedness of lifc attributes ... */
- int x = 0;
- if (lifc.lifc_len != 0) x = -1; else x = -2;
- if (lifc.lifc_req != NULL) x = -3; else x = -4;
- if (strcmp(lifc.lifc_req[0].lifr_name, "") != 0) x = -5; else x = -6;
- /* ... and now one which is not defined. */
- if (strcmp(lifc.lifc_req[lifn.lifn_count].lifr_name, "") != 0)
- x = -7; else x = -8;
-
- free(lifc.lifc_buf);
- close(fd);
- return x;
-}
-
__attribute__((noinline))
static void sys_ioctl_SIOCGLIFFLAGS(void)
{
/* sockio */
sys_ioctl_SIOCGIFCONF();
sys_ioctl_SIOCGIFCONF_2();
- sys_ioctl_SIOCGIFCONF_3();
sys_ioctl_SIOCGIFFLAGS();
sys_ioctl_SIOCGIFFLAGS_2();
sys_ioctl_SIOCGIFNETMASK();
sys_ioctl_SIOCGLIFBRDADDR_2();
sys_ioctl_SIOCGLIFCONF();
sys_ioctl_SIOCGLIFCONF_2();
- sys_ioctl_SIOCGLIFCONF_3();
sys_ioctl_SIOCGLIFFLAGS();
sys_ioctl_SIOCGLIFFLAGS_2();
sys_ioctl_SIOCGLIFNETMASK();
...
Address 0x........ is on thread 1's stack
----------------------------------------------------------
- 54: SYS_ioctl (SIOCGIFCONF), 1s 0m
----------------------------------------------------------
-Conditional jump or move depends on uninitialised value(s)
- ...
-
---------------------------------------------------------
54: SYS_ioctl (SIOCGIFFLAGS) 3s 2m
---------------------------------------------------------
...
Address 0x........ is on thread 1's stack
----------------------------------------------------------
- 54: SYS_ioctl (SIOCGLIFCONF), 1s 0m
----------------------------------------------------------
-Conditional jump or move depends on uninitialised value(s)
- ...
-
---------------------------------------------------------
54: SYS_ioctl (SIOCGLIFFLAGS) 3s 2m
---------------------------------------------------------