2 * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
3 * Copyright (c) 2016-2018 The strace developers.
6 * SPDX-License-Identifier: GPL-2.0-or-later
14 print_mincore(const unsigned int pages, void *const addr,
15 const size_t size, unsigned char *const vec)
19 if (mincore(addr, size, vec))
20 perror_msg_and_skip("mincore");
22 printf("mincore(%p, %zu, [", addr, size);
23 for (i = 0; i < pages; ++i) {
26 if (i >= DEFAULT_STRLEN) {
30 printf("%u", vec[i] & 1);
36 test_mincore(const unsigned int pages)
38 const size_t page_size = get_page_size();
39 const size_t size = pages * page_size;
40 void *const addr = tail_alloc(size);
41 unsigned char *const vec = tail_alloc(pages);
43 mincore(addr, size, NULL);
44 printf("mincore(%p, %zu, NULL) = -1 %s (%m)\n",
45 addr, size, errno2name());
47 print_mincore(pages, addr, size, vec);
49 print_mincore(pages, addr, size - page_size + 1, vec);
56 test_mincore(DEFAULT_STRLEN);
57 test_mincore(DEFAULT_STRLEN + 1);
59 puts("+++ exited with 0 +++");