7
7
#include "fs/aio.h"
8
8
#include "fs/fd.h"
9
9
10
- // Guest memory offsets for the IOCB structure.
11
- // Calculated by a test program compiled and ran in iSH itself.
12
10
struct _guest_iocb {
13
11
uint64_t data ;
14
12
uint32_t key ;
@@ -24,6 +22,8 @@ struct _guest_iocb {
24
22
uint32_t resfd ;
25
23
};
26
24
25
+ // Guest memory offsets for the IOCB structure.
26
+ // Calculated by a test program compiled and ran in iSH itself.
27
27
static_assert (offsetof(struct _guest_iocb , data ) == 0 , "IOCB order" );
28
28
static_assert (offsetof(struct _guest_iocb , key ) == 8 , "IOCB order" );
29
29
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");
37
37
static_assert (offsetof(struct _guest_iocb , flags ) == 56 , "IOCB order" );
38
38
static_assert (offsetof(struct _guest_iocb , resfd ) == 60 , "IOCB order" );
39
39
40
+ struct _guest_ioevent {
41
+ uint64_t data ;
42
+ uint64_t obj ;
43
+ int64_t res ;
44
+ int64_t res2 ;
45
+ };
46
+
40
47
// Guest memory offsets for the IO_EVENT structure.
41
48
// 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" ) ;
47
54
48
55
dword_t sys_io_setup (dword_t nr_events , addr_t ctx_idp ) {
49
56
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
110
117
if (err < 0 ) return err ;
111
118
continue ;
112
119
}
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 ];
113
126
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 ;
120
128
121
- events += AIO_IO_EVENT_SIZEOF ;
129
+ events += sizeof ( _guest_ioevent ) ;
122
130
}
123
131
124
132
return i ;
0 commit comments