# Copyright 2018 syzkaller project authors. All rights reserved.
# Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.

include <uapi/linux/aio_abi.h>

resource io_ctx[intptr]

io_setup(n int32, ctx ptr[out, io_ctx])
io_destroy(ctx io_ctx)
io_getevents(ctx io_ctx, min_nr intptr, nr len[events], events ptr[out, array[io_event]], timeout ptr[in, timespec, opt])
io_pgetevents(ctx io_ctx, min_nr intptr, nr len[events], events ptr[out, array[io_event]], timeout ptr[in, timespec, opt], usig ptr[in, sigset_size, opt])
# TODO: kernel identifies requets by address, so pointers passed to io_submit
# need to be forwarded to io_cancel somehow.
io_submit(ctx io_ctx, nr len[iocbpp], iocbpp ptr[in, array[ptr[in, iocb]]])
io_cancel(ctx io_ctx, iocb ptr[in, iocb], res ptr[out, io_event])

lio_opcode = IOCB_CMD_PREAD, IOCB_CMD_PWRITE, IOCB_CMD_FSYNC, IOCB_CMD_FDSYNC, IOCB_CMD_NOOP, IOCB_CMD_PREADV, IOCB_CMD_PWRITEV
iocb_flags = 0, IOCB_FLAG_RESFD

io_event {
	data	int64
	obj	int64
	res	int64
	res2	int64
}

iocb {
	aio_data	const[0, int64]
	aio_key		const[0, int32]
	aio_rw_flags	const[0, int32]
	aio_lio_opcode	flags[lio_opcode, int16]
	aio_reqprio	int16
	aio_fildes	fd
	aio_buf		ptr64[inout, array[int8]]
	aio_nbytes	len[aio_buf, int64]
	aio_offset	int64
	aio_reserved2	const[0, int64]
	aio_flags	flags[iocb_flags, int32]
	aio_resfd	fd_event
}