no-mmap-inval.c 975 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "../config-host.h"
  2. /* SPDX-License-Identifier: MIT */
  3. /*
  4. * Description: test that using SETUP_NO_MMAP with an invalid SQ ring
  5. * address fails.
  6. *
  7. */
  8. #include <stdlib.h>
  9. #include <sys/types.h>
  10. #include <stdio.h>
  11. #include <unistd.h>
  12. #include "liburing.h"
  13. #include "helpers.h"
  14. int main(int argc, char *argv[])
  15. {
  16. struct io_uring_params p = {
  17. .sq_entries = 2,
  18. .cq_entries = 4,
  19. .flags = IORING_SETUP_NO_MMAP,
  20. };
  21. struct io_uring ring;
  22. void *addr;
  23. int ret;
  24. if (argc > 1)
  25. return T_EXIT_SKIP;
  26. t_posix_memalign(&addr, sysconf(_SC_PAGESIZE), 8192);
  27. p.cq_off.user_addr = (unsigned long long) (uintptr_t) addr;
  28. ret = io_uring_queue_init_params(2, &ring, &p);
  29. if (ret == -EINVAL || ret == -ENOENT) {
  30. /* kernel doesn't support SETUP_NO_MMAP */
  31. free(addr);
  32. return T_EXIT_SKIP;
  33. } else if (ret && (ret != -EFAULT && ret != -ENOMEM)) {
  34. fprintf(stderr, "Got %d, wanted -EFAULT\n", ret);
  35. return T_EXIT_FAIL;
  36. }
  37. free(addr);
  38. return T_EXIT_PASS;
  39. }