• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Copyright (c) 2021 SUSE LLC  */
3 
4 #ifndef LAPI_CLOSE_RANGE__
5 # define LAPI_CLOSE_RANGE__
6 
7 # include "lapi/syscalls.h"
8 
9 # ifdef HAVE_LINUX_CLOSE_RANGE_H
10 #  include <linux/close_range.h>
11 # endif
12 
13 # ifndef CLOSE_RANGE_UNSHARE
14 #  define CLOSE_RANGE_UNSHARE	(1U << 1)
15 # endif
16 
17 # ifndef CLOSE_RANGE_CLOEXEC
18 #  define CLOSE_RANGE_CLOEXEC	(1U << 2)
19 # endif
20 
21 # ifndef HAVE_CLOSE_RANGE
close_range(unsigned int fd,unsigned int max_fd,unsigned int flags)22 static inline int close_range(unsigned int fd, unsigned int max_fd,
23 			      unsigned int flags)
24 {
25 	return tst_syscall(__NR_close_range, fd, max_fd, flags);
26 }
27 # endif
28 
close_range_supported_by_kernel(void)29 static inline void close_range_supported_by_kernel(void)
30 {
31 	long ret;
32 
33 	if ((tst_kvercmp(5, 9, 0)) < 0) {
34 		/* Check if the syscall is backported on an older kernel */
35 		ret = syscall(__NR_close_range, 1, 0, 0);
36 		if (ret == -1 && errno == ENOSYS)
37 			tst_brk(TCONF, "Test not supported on kernel version < v5.9");
38 	}
39 }
40 
41 #endif	/* LAPI_CLOSE_RANGE_H__ */
42