9c11d02e9b853bae014ed9afa246541f04a45193
[lttng-modules.git] / include / wrapper / fdtable.h
1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
2 *
3 * wrapper/fdtable.h
4 *
5 * Copyright (C) 2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 */
7
8 #ifndef _LTTNG_WRAPPER_FDTABLE_H
9 #define _LTTNG_WRAPPER_FDTABLE_H
10
11 #include <lttng/kernel-version.h>
12 #include <linux/fdtable.h>
13 #include <linux/sched.h>
14
15 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(6,7,0))
16 static inline
17 struct file *lttng_lookup_fdget_rcu(unsigned int fd)
18 {
19 return lookup_fdget_rcu(fd);
20 }
21
22 #elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,11,0))
23 static inline
24 struct file *lttng_lookup_fdget_rcu(unsigned int fd)
25 {
26 struct file* file = lookup_fd_rcu(fd);
27
28 if (unlikely(!file || !get_file_rcu(file)))
29 return NULL;
30 return file;
31 }
32 #else
33 static inline
34 struct file *lttng_lookup_fdget_rcu(unsigned int fd)
35 {
36 struct file* file = fcheck(fd);
37
38 if (unlikely(!file || !get_file_rcu(file)))
39 return NULL;
40 return file;
41 }
42 #endif
43
44 #if (LTTNG_LINUX_VERSION_CODE < LTTNG_KERNEL_VERSION(3,7,0))
45
46 int lttng_iterate_fd(struct files_struct *files,
47 unsigned int first,
48 int (*cb)(const void *, struct file *, unsigned int),
49 const void *ctx);
50
51 #else
52
53 /*
54 * iterate_fd() appeared at commit
55 * c3c073f808b22dfae15ef8412b6f7b998644139a in the Linux kernel (first
56 * released kernel: v3.7).
57 */
58 #define lttng_iterate_fd iterate_fd
59
60 #endif
61
62 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,4,0))
63
64 static inline bool lttng_close_on_exec(int fd, const struct fdtable *fdt)
65 {
66 return close_on_exec(fd, fdt);
67 }
68
69 #else
70
71 static inline bool lttng_close_on_exec(int fd, const struct fdtable *fdt)
72 {
73 return FD_ISSET(fd, fdt->close_on_exec);
74 }
75
76 #endif
77
78 #endif /* _LTTNG_WRAPPER_FDTABLE_H */
This page took 0.030422 seconds and 4 git commands to generate.