1 /* Hook for making file descriptor functions close(), ioctl() extensible.
2 Copyright (C) 2009-2022 Free Software Foundation, Inc.
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
9 This file is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
26 /* Currently, this entire code is only needed for the handling of sockets
27 on native Windows platforms. */
31 /* Type of function that closes FD. */
32 typedef int (*gl_close_fn
) (int fd
);
34 /* Type of function that applies a control request to FD. */
35 typedef int (*gl_ioctl_fn
) (int fd
, int request
, void *arg
);
37 /* An element of the list of file descriptor hooks.
38 In CLOS (Common Lisp Object System) speak, it consists of an "around"
39 method for the close() function and an "around" method for the ioctl()
41 The fields of this structure are considered private. */
44 /* Doubly linked list. */
45 struct fd_hook
*private_next
;
46 struct fd_hook
*private_prev
;
47 /* Function that treats the types of FD that it knows about and calls
48 execute_close_hooks (REMAINING_LIST, PRIMARY, FD) as a fallback. */
49 int (*private_close_fn
) (const struct fd_hook
*remaining_list
,
52 /* Function that treats the types of FD that it knows about and calls
53 execute_ioctl_hooks (REMAINING_LIST, PRIMARY, FD, REQUEST, ARG) as a
55 int (*private_ioctl_fn
) (const struct fd_hook
*remaining_list
,
57 int fd
, int request
, void *arg
);
60 /* This type of function closes FD, applying special knowledge for the FD
61 types it knows about, and calls
62 execute_close_hooks (REMAINING_LIST, PRIMARY, FD)
63 for the other FD types.
64 In CLOS speak, REMAINING_LIST is the remaining list of "around" methods,
65 and PRIMARY is the "primary" method for close(). */
66 typedef int (*close_hook_fn
) (const struct fd_hook
*remaining_list
,
70 /* Execute the close hooks in REMAINING_LIST, with PRIMARY as "primary" method.
71 Return 0 or -1, like close() would do. */
72 extern int execute_close_hooks (const struct fd_hook
*remaining_list
,
76 /* Execute all close hooks, with PRIMARY as "primary" method.
77 Return 0 or -1, like close() would do. */
78 extern int execute_all_close_hooks (gl_close_fn primary
, int fd
);
80 /* This type of function applies a control request to FD, applying special
81 knowledge for the FD types it knows about, and calls
82 execute_ioctl_hooks (REMAINING_LIST, PRIMARY, FD, REQUEST, ARG)
83 for the other FD types.
84 In CLOS speak, REMAINING_LIST is the remaining list of "around" methods,
85 and PRIMARY is the "primary" method for ioctl(). */
86 typedef int (*ioctl_hook_fn
) (const struct fd_hook
*remaining_list
,
88 int fd
, int request
, void *arg
);
90 /* Execute the ioctl hooks in REMAINING_LIST, with PRIMARY as "primary" method.
91 Return 0 or -1, like ioctl() would do. */
92 extern int execute_ioctl_hooks (const struct fd_hook
*remaining_list
,
94 int fd
, int request
, void *arg
);
96 /* Execute all ioctl hooks, with PRIMARY as "primary" method.
97 Return 0 or -1, like ioctl() would do. */
98 extern int execute_all_ioctl_hooks (gl_ioctl_fn primary
,
99 int fd
, int request
, void *arg
);
101 /* Add a function pair to the list of file descriptor hooks.
102 CLOSE_HOOK and IOCTL_HOOK may be NULL, indicating no change.
103 The LINK variable points to a piece of memory which is guaranteed to be
104 accessible until the corresponding call to unregister_fd_hook. */
105 extern void register_fd_hook (close_hook_fn close_hook
, ioctl_hook_fn ioctl_hook
,
106 struct fd_hook
*link
);
108 /* Removes a hook from the list of file descriptor hooks. */
109 extern void unregister_fd_hook (struct fd_hook
*link
);
119 #endif /* FD_HOOK_H */