Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/ioctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

typedef struct {
unsigned long request;
unsigned long size;
char data[];
} ioctl_in_t;

Expand Down
74 changes: 31 additions & 43 deletions posix/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1643,22 +1643,15 @@
#define IOCPARM_MASK 0x1fffUL
#define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK)

#define IOC_OUT 0x40000000UL
#define IOC_IN 0x80000000UL
#define IOC_INOUT (IOC_IN | IOC_OUT)
#define _IOC(inout, group, num, len) ((unsigned long)((inout) | (((len) & IOCPARM_MASK) << 16) | (((unsigned int)(group)) << 8) | (num)))
#define IOC_VOID 0x20000000
#define IOC_OUT 0x40000000
#define IOC_IN 0x80000000
#define IOC_INOUT (IOC_IN | IOC_OUT)

#define SIOCGIFCONF _IOC(IOC_INOUT, 'S', 0x12U, sizeof(struct ifconf))
#define SIOCADDRT _IOC(IOC_IN, 'S', 0x44U, sizeof(struct rtentry))
#define SIOCDELRT _IOC(IOC_IN, 'S', 0x45U, sizeof(struct rtentry))


static void ioctl_pack(msg_t *msg, unsigned long request, void *data, oid_t *oid)
static void ioctl_pack(msg_t *msg, unsigned long request, void *data, size_t size, oid_t *oid)
{
size_t size = IOCPARM_LEN(request);
ioctl_in_t *ioctl = (ioctl_in_t *)msg->i.raw;
struct ifconf *ifc;
struct rtentry *rt;

hal_memcpy(&msg->oid, oid, sizeof(*oid));
msg->type = mtDevCtl;
Expand All @@ -1668,6 +1661,7 @@
msg->o.size = 0;

ioctl->request = request;
ioctl->size = size;

if ((request & IOC_INOUT) != 0U) {
if ((request & IOC_IN) != 0U) {
Expand All @@ -1690,47 +1684,19 @@
size = min(size, sizeof(void *));
hal_memcpy(ioctl->data, &data, size);
}
else {
/* No action required */
}


/* ioctl special case: arg is structure with pointer - has to be custom-packed into message */
if (request == SIOCGIFCONF) {
ifc = (struct ifconf *)data;
msg->o.data = ifc->ifc_buf;
msg->o.size = ifc->ifc_len;
}
else if ((request == SIOCADDRT) || (request == SIOCDELRT)) {
rt = (struct rtentry *)data;
if (rt->rt_dev != NULL) {
msg->o.data = rt->rt_dev;
msg->o.size = hal_strlen(rt->rt_dev) + 1U;
}
}
else {
/* No action required */
}
}


static int ioctl_processResponse(const msg_t *msg, unsigned long request, void *data)
int ioctl_processResponse(const msg_t *msg, unsigned long request, void *data, size_t size)
{
size_t size = IOCPARM_LEN(request);
int err;
struct ifconf *ifc;

err = msg->o.err;

if (((request & IOC_OUT) != 0U) && (size <= sizeof(msg->o.raw))) {
hal_memcpy(data, msg->o.raw, size);
}

if (request == SIOCGIFCONF) { /* restore overridden userspace pointer */
ifc = (struct ifconf *)data;
ifc->ifc_buf = msg->o.data;
}

return err;
}

Expand All @@ -1743,19 +1709,41 @@
int err;
msg_t msg;
void *data = NULL;
size_t size = IOCPARM_LEN(request);

err = posix_getOpenFile(fildes, &f);
if (err == 0) {
/* TODO: handle POSIX defined requests with `switch (request)` */
if (((request & IOC_INOUT) != 0U) || (IOCPARM_LEN(request) > 0U)) {
/* TODO: handle POSIX defined requests */
if (((request & IOC_INOUT) != 0) || (size > 0)) {
GETFROMSTACK(ustack, void *, data, 2);
/* the actual size of the pointed-to structure: >= IOCPARM_LEN(request) */
GETFROMSTACK(ustack, size_t, size, 3);

if ((request & IOC_VOID) == 0) {
if (data == NULL) {
err = -EFAULT;
break;

Check failure on line 1725 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (sparcv8leon-gr712rc-board)

break statement not within loop or switch

Check failure on line 1725 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt106x-evk)

break statement not within loop or switch

Check failure on line 1725 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-pc)

break statement not within loop or switch

Check failure on line 1725 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-qemu)

break statement not within loop or switch

Check failure on line 1725 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (riscv64-generic-qemu)

break statement not within loop or switch

Check failure on line 1725 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (sparcv8leon-gr716-mimas)

break statement not within loop or switch

Check failure on line 1725 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv8r52-mps3an536-qemu)

break statement not within loop or switch

Check failure on line 1725 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (sparcv8leon-gr740-mini)

break statement not within loop or switch

Check failure on line 1725 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (sparcv8leon-gr716-mini)

break statement not within loop or switch

Check failure on line 1725 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt117x-evk)

break statement not within loop or switch

Check failure on line 1725 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7r5f-zynqmp-qemu)

break statement not within loop or switch

Check failure on line 1725 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a7-imx6ull-evk)

break statement not within loop or switch

Check failure on line 1725 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (aarch64a53-zynqmp-qemu)

break statement not within loop or switch
}

if (vm_mapBelongs(proc_current()->process, data, size) < 0) {
err = -EFAULT;
break;

Check failure on line 1730 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (sparcv8leon-gr712rc-board)

break statement not within loop or switch

Check failure on line 1730 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt106x-evk)

break statement not within loop or switch

Check failure on line 1730 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-pc)

break statement not within loop or switch

Check failure on line 1730 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-qemu)

break statement not within loop or switch

Check failure on line 1730 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (riscv64-generic-qemu)

break statement not within loop or switch

Check failure on line 1730 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (sparcv8leon-gr716-mimas)

break statement not within loop or switch

Check failure on line 1730 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv8r52-mps3an536-qemu)

break statement not within loop or switch

Check failure on line 1730 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (sparcv8leon-gr740-mini)

break statement not within loop or switch

Check failure on line 1730 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (sparcv8leon-gr716-mini)

break statement not within loop or switch

Check failure on line 1730 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt117x-evk)

break statement not within loop or switch

Check failure on line 1730 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7r5f-zynqmp-qemu)

break statement not within loop or switch

Check failure on line 1730 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a7-imx6ull-evk)

break statement not within loop or switch

Check failure on line 1730 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (aarch64a53-zynqmp-qemu)

break statement not within loop or switch
}
}
}

ioctl_pack(&msg, request, data, size, &f->oid);

err = proc_send(f->oid.port, &msg);
if (err == EOK) {
err = ioctl_processResponse(&msg, request, data, size);
}

ioctl_pack(&msg, request, data, &f->oid);

Check failure on line 1742 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (sparcv8leon-gr712rc-board)

too few arguments to function 'ioctl_pack'

Check failure on line 1742 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (sparcv8leon-gr712rc-board)

passing argument 4 of 'ioctl_pack' makes integer from pointer without a cast [-Wint-conversion]

Check failure on line 1742 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt106x-evk)

too few arguments to function 'ioctl_pack'

Check failure on line 1742 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt106x-evk)

passing argument 4 of 'ioctl_pack' makes integer from pointer without a cast [-Wint-conversion]

Check failure on line 1742 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-pc)

too few arguments to function 'ioctl_pack'

Check failure on line 1742 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-pc)

passing argument 4 of 'ioctl_pack' makes integer from pointer without a cast [-Wint-conversion]

Check failure on line 1742 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-qemu)

too few arguments to function 'ioctl_pack'

Check failure on line 1742 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-qemu)

passing argument 4 of 'ioctl_pack' makes integer from pointer without a cast [-Wint-conversion]

Check failure on line 1742 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (riscv64-generic-qemu)

too few arguments to function 'ioctl_pack'

Check failure on line 1742 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (riscv64-generic-qemu)

passing argument 4 of 'ioctl_pack' makes integer from pointer without a cast [-Wint-conversion]

Check failure on line 1742 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (sparcv8leon-gr716-mimas)

too few arguments to function 'ioctl_pack'

Check failure on line 1742 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (sparcv8leon-gr716-mimas)

passing argument 4 of 'ioctl_pack' makes integer from pointer without a cast [-Wint-conversion]

Check failure on line 1742 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv8r52-mps3an536-qemu)

too few arguments to function 'ioctl_pack'

Check failure on line 1742 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv8r52-mps3an536-qemu)

passing argument 4 of 'ioctl_pack' makes integer from pointer without a cast [-Wint-conversion]

Check failure on line 1742 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (sparcv8leon-gr740-mini)

too few arguments to function 'ioctl_pack'

Check failure on line 1742 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (sparcv8leon-gr740-mini)

passing argument 4 of 'ioctl_pack' makes integer from pointer without a cast [-Wint-conversion]

Check failure on line 1742 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (sparcv8leon-gr716-mini)

too few arguments to function 'ioctl_pack'

Check failure on line 1742 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (sparcv8leon-gr716-mini)

passing argument 4 of 'ioctl_pack' makes integer from pointer without a cast [-Wint-conversion]

Check failure on line 1742 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt117x-evk)

too few arguments to function 'ioctl_pack'

Check failure on line 1742 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt117x-evk)

passing argument 4 of 'ioctl_pack' makes integer from pointer without a cast [-Wint-conversion]

Check failure on line 1742 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7r5f-zynqmp-qemu)

too few arguments to function 'ioctl_pack'

Check failure on line 1742 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7r5f-zynqmp-qemu)

passing argument 4 of 'ioctl_pack' makes integer from pointer without a cast [-Wint-conversion]

Check failure on line 1742 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a7-imx6ull-evk)

too few arguments to function 'ioctl_pack'

Check failure on line 1742 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a7-imx6ull-evk)

passing argument 4 of 'ioctl_pack' makes integer from pointer without a cast [-Wint-conversion]

Check failure on line 1742 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (aarch64a53-zynqmp-qemu)

too few arguments to function 'ioctl_pack'

Check failure on line 1742 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (aarch64a53-zynqmp-qemu)

passing argument 4 of 'ioctl_pack' makes integer from pointer without a cast [-Wint-conversion]

err = proc_send(f->oid.port, &msg);
if (err == EOK) {
err = ioctl_processResponse(&msg, request, data);

Check failure on line 1746 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (sparcv8leon-gr712rc-board)

too few arguments to function 'ioctl_processResponse'

Check failure on line 1746 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt106x-evk)

too few arguments to function 'ioctl_processResponse'

Check failure on line 1746 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-pc)

too few arguments to function 'ioctl_processResponse'

Check failure on line 1746 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-qemu)

too few arguments to function 'ioctl_processResponse'

Check failure on line 1746 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (riscv64-generic-qemu)

too few arguments to function 'ioctl_processResponse'

Check failure on line 1746 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (sparcv8leon-gr716-mimas)

too few arguments to function 'ioctl_processResponse'

Check failure on line 1746 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv8r52-mps3an536-qemu)

too few arguments to function 'ioctl_processResponse'

Check failure on line 1746 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (sparcv8leon-gr740-mini)

too few arguments to function 'ioctl_processResponse'

Check failure on line 1746 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (sparcv8leon-gr716-mini)

too few arguments to function 'ioctl_processResponse'

Check failure on line 1746 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt117x-evk)

too few arguments to function 'ioctl_processResponse'

Check failure on line 1746 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7r5f-zynqmp-qemu)

too few arguments to function 'ioctl_processResponse'

Check failure on line 1746 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a7-imx6ull-evk)

too few arguments to function 'ioctl_processResponse'

Check failure on line 1746 in posix/posix.c

View workflow job for this annotation

GitHub Actions / call-ci / build (aarch64a53-zynqmp-qemu)

too few arguments to function 'ioctl_processResponse'
}

(void)posix_fileDeref(f);
Expand Down
20 changes: 0 additions & 20 deletions posix/posix_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,26 +123,6 @@ typedef struct _process_info_t {
} process_info_t;


/* SIOCGIFCONF ioctl special case: arg is structure with pointer */
struct ifconf {
unsigned int ifc_len; /* size of buffer */
char *ifc_buf; /* buffer address */
};

/* SIOADDRT and SIOCDELRT ioctls special case: arg is structure with pointer */
struct rtentry {
struct sockaddr rt_dst;
struct sockaddr rt_gateway;
struct sockaddr rt_genmask;
short rt_flags;
short rt_metric;
char *rt_dev;
unsigned long rt_mss;
unsigned long rt_window;
unsigned short rt_irtt;
};


int posix_fileDeref(open_file_t *f);


Expand Down
1 change: 1 addition & 0 deletions syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1714,6 +1714,7 @@ int syscalls_sys_ioctl(u8 *ustack)
GETFROMSTACK(ustack, int, fildes, 0);
GETFROMSTACK(ustack, unsigned long, request, 1);

/* vm_mapBelongs on optional data pointer checked in posix_ioctl */
return posix_ioctl(fildes, request, ustack);
}

Expand Down
Loading