Skip to content

Commit db0c0aa

Browse files
committed
Also rip out the AIO_IO_EVENT constants for another host-compiled structure and static asserts.
1 parent 1174ec7 commit db0c0aa

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

kernel/aio.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
#include "fs/aio.h"
88
#include "fs/fd.h"
99

10-
// Guest memory offsets for the IOCB structure.
11-
// Calculated by a test program compiled and ran in iSH itself.
1210
struct _guest_iocb {
1311
uint64_t data;
1412
uint32_t key;
@@ -24,6 +22,8 @@ struct _guest_iocb {
2422
uint32_t resfd;
2523
};
2624

25+
// Guest memory offsets for the IOCB structure.
26+
// Calculated by a test program compiled and ran in iSH itself.
2727
static_assert(offsetof(struct _guest_iocb, data) == 0, "IOCB order");
2828
static_assert(offsetof(struct _guest_iocb, key) == 8, "IOCB order");
2929
static_assert(offsetof(struct _guest_iocb, rw_flags) == 12, "IOCB order");
@@ -37,13 +37,20 @@ static_assert(offsetof(struct _guest_iocb, reserved2) == 48, "IOCB order");
3737
static_assert(offsetof(struct _guest_iocb, flags) == 56, "IOCB order");
3838
static_assert(offsetof(struct _guest_iocb, resfd) == 60, "IOCB order");
3939

40+
struct _guest_ioevent {
41+
uint64_t data;
42+
uint64_t obj;
43+
int64_t res;
44+
int64_t res2;
45+
};
46+
4047
// Guest memory offsets for the IO_EVENT structure.
4148
// Also confirmed by test program.
42-
const size_t AIO_IO_EVENT_DATA = 0;
43-
const size_t AIO_IO_EVENT_OBJ = 8;
44-
const size_t AIO_IO_EVENT_RES = 16;
45-
const size_t AIO_IO_EVENT_RES2 = 24;
46-
const size_t AIO_IO_EVENT_SIZEOF = 32;
49+
static_assert(offsetof(struct _guest_ioevent, data) == 0, "IOEVENT order");
50+
static_assert(offsetof(struct _guest_ioevent, obj) == 8, "IOEVENT order");
51+
static_assert(offsetof(struct _guest_ioevent, res) == 16, "IOEVENT order");
52+
static_assert(offsetof(struct _guest_ioevent, res2) == 24, "IOEVENT order");
53+
static_assert(sizeof(struct _guest_ioevent) == 32, "IOEVENT size");
4754

4855
dword_t sys_io_setup(dword_t nr_events, addr_t ctx_idp) {
4956
STRACE("io_setup(%d, 0x%x)", nr_events, ctx_idp);
@@ -110,15 +117,16 @@ dword_t sys_io_getevents(dword_t ctx_id, dword_t min_nr, dword_t nr, addr_t even
110117
if (err < 0) return err;
111118
continue;
112119
}
120+
121+
struct _guest_ioevent gevent = {0};
122+
gevent.data = user_data;
123+
gevent.obj = (uint64_t)iocbp;
124+
gevent.res = cdata.result[0];
125+
gevent.res2 = cdata.result[1];
113126

114-
uint64_t obj = (uint64_t)iocbp;
115-
116-
if (user_put(events + AIO_IO_EVENT_DATA, user_data)) return _EFAULT;
117-
if (user_put(events + AIO_IO_EVENT_OBJ, obj)) return _EFAULT;
118-
if (user_put(events + AIO_IO_EVENT_RES, cdata.result[0])) return _EFAULT;
119-
if (user_put(events + AIO_IO_EVENT_RES2, cdata.result[1])) return _EFAULT;
127+
if (user_put(events, user_data)) return _EFAULT;
120128

121-
events += AIO_IO_EVENT_SIZEOF;
129+
events += sizeof(struct _guest_ioevent);
122130
}
123131

124132
return i;

0 commit comments

Comments
 (0)