aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/liburing/test/no-mmap-inval.c
blob: 1d31688b272569044039eb72d6dfff04df376d36 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "../config-host.h"
/* SPDX-License-Identifier: MIT */
/*
 * Description: test that using SETUP_NO_MMAP with an invalid SQ ring
 *		address fails.
 *
 */
#include <stdlib.h>
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>

#include "liburing.h"
#include "helpers.h"

int main(int argc, char *argv[])
{
	struct io_uring_params p = {
		.sq_entries	= 2,
		.cq_entries	= 4,
		.flags		= IORING_SETUP_NO_MMAP,
	};
	struct io_uring ring;
	void *addr;
	int ret;

	if (argc > 1)
		return T_EXIT_SKIP;

	t_posix_memalign(&addr, sysconf(_SC_PAGESIZE), 8192);
	p.cq_off.user_addr = (unsigned long long) (uintptr_t) addr;

	ret = io_uring_queue_init_params(2, &ring, &p);
	if (ret == -EINVAL) {
		/*  kernel doesn't support SETUP_NO_MMAP */
		free(addr);
		return T_EXIT_SKIP;
	} else if (ret && (ret != -EFAULT && ret != -ENOMEM)) {
		fprintf(stderr, "Got %d, wanted -EFAULT\n", ret);
		return T_EXIT_FAIL;
	}

	free(addr);
	return T_EXIT_PASS;
}