9
9
10
10
// Guest memory offsets for the IOCB structure.
11
11
// Calculated by a test program compiled and ran in iSH itself.
12
- const size_t AIO_IOCB_DATA = 0 ;
13
- const size_t AIO_IOCB_KEY = 8 ;
14
- const size_t AIO_IOCB_RW_FLAGS = 12 ;
15
- const size_t AIO_IOCB_LIO_OPCODE = 16 ;
16
- const size_t AIO_IOCB_REQPRIO = 18 ;
17
- const size_t AIO_IOCB_FILDES = 20 ;
18
- const size_t AIO_IOCB_BUF = 24 ;
19
- const size_t AIO_IOCB_NBYTES = 32 ;
20
- const size_t AIO_IOCB_OFFSET = 40 ;
21
- const size_t AIO_IOCB_RESERVED2 = 48 ;
22
- const size_t AIO_IOCB_FLAGS = 56 ;
23
- const size_t AIO_IOCB_RESFD = 60 ;
12
+ struct _guest_iocb {
13
+ uint64_t data ;
14
+ uint32_t key ;
15
+ uint32_t rw_flags ;
16
+ uint16_t lio_opcode ;
17
+ int16_t reqprio ;
18
+ uint32_t fildes ;
19
+ uint64_t buf ;
20
+ uint64_t nbytes ;
21
+ int64_t offset ;
22
+ uint64_t reserved2 ;
23
+ uint32_t flags ;
24
+ uint32_t resfd ;
25
+ };
26
+
27
+ static_assert (offsetof(struct _guest_iocb , data ) == 0 , "IOCB order" );
28
+ static_assert (offsetof(struct _guest_iocb , key ) == 8 , "IOCB order" );
29
+ static_assert (offsetof(struct _guest_iocb , rw_flags ) == 12 , "IOCB order" );
30
+ static_assert (offsetof(struct _guest_iocb , lio_opcode ) == 16 , "IOCB order" );
31
+ static_assert (offsetof(struct _guest_iocb , reqprio ) == 18 , "IOCB order" );
32
+ static_assert (offsetof(struct _guest_iocb , fildes ) == 20 , "IOCB order" );
33
+ static_assert (offsetof(struct _guest_iocb , buf ) == 24 , "IOCB order" );
34
+ static_assert (offsetof(struct _guest_iocb , nbytes ) == 32 , "IOCB order" );
35
+ static_assert (offsetof(struct _guest_iocb , offset ) == 40 , "IOCB order" );
36
+ static_assert (offsetof(struct _guest_iocb , reserved2 ) == 48 , "IOCB order" );
37
+ static_assert (offsetof(struct _guest_iocb , flags ) == 56 , "IOCB order" );
38
+ static_assert (offsetof(struct _guest_iocb , resfd ) == 60 , "IOCB order" );
24
39
25
40
// Guest memory offsets for the IO_EVENT structure.
26
41
// Also confirmed by test program.
@@ -124,19 +139,16 @@ dword_t sys_io_submit(dword_t ctx_id, dword_t u_nr, addr_t iocbpp) {
124
139
addr_t iocbp = 0 ;
125
140
if (user_get (iocbpp + i * sizeof (addr_t ), iocbp )) goto fault ;
126
141
127
- uint64_t user_data = 0 ;
128
- if (user_get (iocbp + AIO_IOCB_DATA , user_data )) goto fault ;
142
+ struct _guest_iocb giocb = { 0 } ;
143
+ if (user_get (iocbp , giocb )) goto fault ;
129
144
130
145
struct aioctx_event_pending host_iocb ;
131
- uint16_t op = 0 ;
132
146
133
- if (user_get (iocbp + AIO_IOCB_LIO_OPCODE , op )) goto fault ;
134
- host_iocb .op = (enum aioctx_op )op ;
135
-
136
- if (user_get (iocbp + AIO_IOCB_FILDES , host_iocb .fd )) goto fault ;
137
- if (user_get (iocbp + AIO_IOCB_BUF , host_iocb .buf )) goto fault ;
138
- if (user_get (iocbp + AIO_IOCB_NBYTES , host_iocb .nbytes )) goto fault ;
139
- if (user_get (iocbp + AIO_IOCB_OFFSET , host_iocb .offset )) goto fault ;
147
+ host_iocb .op = (enum aioctx_op )giocb .data ;
148
+ host_iocb .fd = giocb .fildes ;
149
+ host_iocb .buf = giocb .buf ;
150
+ host_iocb .nbytes = giocb .nbytes ;
151
+ host_iocb .offset = giocb .offset ;
140
152
141
153
lock (& current -> files -> lock );
142
154
@@ -152,7 +164,7 @@ dword_t sys_io_submit(dword_t ctx_id, dword_t u_nr, addr_t iocbpp) {
152
164
break ;
153
165
}
154
166
155
- err = aioctx_submit_pending_event (ctx , user_data , iocbp , host_iocb );
167
+ err = aioctx_submit_pending_event (ctx , giocb . data , iocbp , host_iocb );
156
168
if (err < 0 ) {
157
169
// TODO: This assumes the usual pattern of "first IOCB errors, all
158
170
// others stop processing without erroring"
0 commit comments