From: Dmitry V. Levin Date: Wed, 13 Jan 2016 22:06:18 +0000 (+0000) Subject: aio.test: check memory access by aio decoders X-Git-Tag: v4.12~639 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=68f7a66dc9bab17c678d3454d8b41ef88c5a2bff;p=strace aio.test: check memory access by aio decoders * tests/aio.c (main): Place all objects passed to io_* syscalls at the end of memory pages followed by inaccessible pages. --- diff --git a/tests/aio.c b/tests/aio.c index 93ec6feb..29d2191d 100644 --- a/tests/aio.c +++ b/tests/aio.c @@ -47,94 +47,109 @@ int main(void) { - static char data0[4096]; - static char data1[8192]; + const unsigned int sizeof_data0 = 4096; + const unsigned int sizeof_data1 = 8192; + void *data0 = tail_alloc(sizeof_data0); + void *data1 = tail_alloc(sizeof_data1); - const struct iocb cb[] = { + const struct iocb proto_cb[] = { { .aio_data = 0xfeedface11111111, .aio_reqprio = 11, .aio_buf = (unsigned long) data0, .aio_offset = 0xdeface1facefeed, - .aio_nbytes = sizeof(data0) + .aio_nbytes = sizeof_data0 }, { .aio_data = 0xfeedface22222222, .aio_reqprio = 22, .aio_buf = (unsigned long) data1, .aio_offset = 0xdeface2cafef00d, - .aio_nbytes = sizeof(data1) + .aio_nbytes = sizeof_data1 } }; - const struct iovec iov0[] = { + const struct iocb *cb = tail_memdup(proto_cb, sizeof(proto_cb)); + + const struct iovec proto_iov0[] = { { .iov_base = data0, - .iov_len = sizeof(data0) / 4 + .iov_len = sizeof_data0 / 4 }, { - .iov_base = data0 + sizeof(data0) / 4, - .iov_len = sizeof(data0) / 4 * 3 + .iov_base = data0 + sizeof_data0 / 4, + .iov_len = sizeof_data0 / 4 * 3 }, }; - const struct iovec iov1[] = { + const struct iovec *iov0 = tail_memdup(proto_iov0, sizeof(proto_iov0)); + + const struct iovec proto_iov1[] = { { .iov_base = data1, - .iov_len = sizeof(data1) / 4 + .iov_len = sizeof_data1 / 4 }, { - .iov_base = data1 + sizeof(data1) / 4, - .iov_len = sizeof(data1) / 4 * 3 + .iov_base = data1 + sizeof_data1 / 4, + .iov_len = sizeof_data1 / 4 * 3 }, }; - const struct iocb cbv[] = { + const struct iovec *iov1 = tail_memdup(proto_iov1, sizeof(proto_iov1)); + + const struct iocb proto_cbv[] = { { .aio_data = 0xfeed11111111face, .aio_lio_opcode = 7, .aio_reqprio = 111, - .aio_buf = (unsigned long) &iov0, + .aio_buf = (unsigned long) iov0, .aio_offset = 0xdeface1facefeed, - .aio_nbytes = ARRAY_SIZE(iov0) + .aio_nbytes = ARRAY_SIZE(proto_iov0) }, { .aio_data = 0xfeed22222222face, .aio_lio_opcode = 7, .aio_reqprio = 222, - .aio_buf = (unsigned long) &iov1, + .aio_buf = (unsigned long) iov1, .aio_offset = 0xdeface2cafef00d, - .aio_nbytes = ARRAY_SIZE(iov1) + .aio_nbytes = ARRAY_SIZE(proto_iov1) } }; - struct iocb cbc = { + const struct iocb *cbv = tail_memdup(proto_cbv, sizeof(proto_cbv)); + + const struct iocb proto_cbc = { .aio_data = 0xdeadbeefbadc0ded, .aio_reqprio = 99, .aio_fildes = -42 }; + const struct iocb *cbc = tail_memdup(&proto_cbc, sizeof(proto_cbc)); - const long cbs[ARRAY_SIZE(cb) + 2] = { - (long) &cb[0], (long) &cb[1], - 0xdeadbeef, 0xbadc0ded + const long proto_cbs[] = { + (long) &cb[0], (long) &cb[1] }; - const long cbvs[ARRAY_SIZE(cb) + 2] = { + const long *cbs = tail_memdup(proto_cbs, sizeof(proto_cbs)); + + const long proto_cbvs[] = { (long) &cbv[0], (long) &cbv[1], - 0xdeadbeef, 0xbadc0ded }; + const long *cbvs = tail_memdup(proto_cbvs, sizeof(proto_cbvs)); + + unsigned long *ctx = tail_alloc(sizeof(unsigned long)); + *ctx = 0; - unsigned long ctx = 0; - const unsigned int nr = ARRAY_SIZE(cb); + const unsigned int nr = ARRAY_SIZE(proto_cb); const unsigned long lnr = (unsigned long) (0xdeadbeef00000000ULL | nr); - struct io_event ev[nr]; - const struct timespec ts = { .tv_nsec = 123456789 }; + const struct io_event *ev = tail_alloc(nr * sizeof(struct io_event)); + const struct timespec proto_ts = { .tv_nsec = 123456789 }; + const struct timespec *ts = tail_memdup(&proto_ts, sizeof(proto_ts)); (void) close(0); if (open("/dev/zero", O_RDONLY)) perror_msg_and_skip("open: %s", "/dev/zero"); - if (syscall(__NR_io_setup, lnr, &ctx)) + if (syscall(__NR_io_setup, lnr, ctx)) perror_msg_and_skip("io_setup"); - printf("io_setup(%u, [%lu]) = 0\n", nr, ctx); + printf("io_setup(%u, [%lu]) = 0\n", nr, *ctx); - if (syscall(__NR_io_submit, ctx, nr, cbs) != (long) nr) + if (syscall(__NR_io_submit, *ctx, nr, cbs) != (long) nr) perror_msg_and_skip("io_submit"); printf("io_submit(%lu, %u, [" "{data=%#llx, pread, reqprio=11, fildes=0, " @@ -142,31 +157,29 @@ main(void) "{data=%#llx, pread, reqprio=22, fildes=0, " "buf=%p, nbytes=%u, offset=%lld}" "]) = %u\n", - ctx, nr, + *ctx, nr, (unsigned long long) cb[0].aio_data, data0, - (unsigned int) sizeof(data0), (long long) cb[0].aio_offset, + sizeof_data0, (long long) cb[0].aio_offset, (unsigned long long) cb[1].aio_data, data1, - (unsigned int) sizeof(data1), (long long) cb[1].aio_offset, + sizeof_data1, (long long) cb[1].aio_offset, nr); - assert(syscall(__NR_io_getevents, ctx, nr, nr + 1, ev, &ts) == (long) nr); + assert(syscall(__NR_io_getevents, *ctx, nr, nr + 1, ev, ts) == (long) nr); printf("io_getevents(%lu, %u, %u, [" "{data=%#llx, obj=%p, res=%u, res2=0}, " "{data=%#llx, obj=%p, res=%u, res2=0}" "], {0, 123456789}) = %u\n", - ctx, nr, nr + 1, - (unsigned long long) cb[0].aio_data, &cb[0], - (unsigned int) sizeof(data0), - (unsigned long long) cb[1].aio_data, &cb[1], - (unsigned int) sizeof(data1), + *ctx, nr, nr + 1, + (unsigned long long) cb[0].aio_data, &cb[0], sizeof_data0, + (unsigned long long) cb[1].aio_data, &cb[1], sizeof_data1, nr); - assert(syscall(__NR_io_cancel, ctx, &cbc, ev) == -1 && EINVAL == errno); + assert(syscall(__NR_io_cancel, *ctx, cbc, ev) == -1 && EINVAL == errno); printf("io_cancel(%lu, {data=%#llx, pread, reqprio=99, fildes=-42}, %p) " "= -1 EINVAL (%m)\n", - ctx, (unsigned long long) cbc.aio_data, ev); + *ctx, (unsigned long long) cbc->aio_data, ev); - if (syscall(__NR_io_submit, ctx, nr, cbvs) != (long) nr) + if (syscall(__NR_io_submit, *ctx, nr, cbvs) != (long) nr) perror_msg_and_skip("io_submit"); printf("io_submit(%lu, %u, [" "{data=%#llx, preadv, reqprio=%hd, fildes=0, " @@ -174,7 +187,7 @@ main(void) "{data=%#llx, preadv, reqprio=%hd, fildes=0, " "iovec=[{%p, %u}, {%p, %u}], offset=%lld}" "]) = %u\n", - ctx, nr, + *ctx, nr, (unsigned long long) cbv[0].aio_data, cbv[0].aio_reqprio, iov0[0].iov_base, (unsigned int) iov0[0].iov_len, iov0[1].iov_base, (unsigned int) iov0[1].iov_len, @@ -185,8 +198,8 @@ main(void) (long long) cbv[1].aio_offset, nr); - assert(syscall(__NR_io_destroy, ctx) == 0); - printf("io_destroy(%lu) = 0\n", ctx); + assert(syscall(__NR_io_destroy, *ctx) == 0); + printf("io_destroy(%lu) = 0\n", *ctx); puts("+++ exited with 0 +++"); return 0;