File: syscall-clamp.c

package info (click to toggle)
libgpg-error 1.35-1~bpo9+1
  • links: PTS, VCS
  • area: main
  • in suites: stretch-backports
  • size: 5,848 kB
  • sloc: ansic: 22,324; sh: 13,156; makefile: 488; awk: 333; lisp: 138; sed: 16
file content (80 lines) | stat: -rw-r--r-- 2,223 bytes parent folder | download | duplicates (10)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* syscall-clamp.c - Syscall clamp related stuff
 * Copyright (C) 2016, 2017 g10 Code GmbH
 *
 * This file is part of Libgpg-error.
 *
 * Libgpg-error is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * Libgpg-error is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, see <https://www.gnu.org/licenses/>.
 * SPDX-License-Identifier: LGPL-2.1+
 */

#include <config.h>

#include "gpgrt-int.h"

/*
 * Functions called before and after blocking syscalls.
 * gpgrt_set_syscall_clamp is used to set them.
 */
static void (*pre_syscall_func)(void);
static void (*post_syscall_func)(void);


/*
 * Register the syscall clamp.  These two functions are called
 * immediately before and after a possible blocking system call.  This
 * should be used before any I/O happens.  The function is commonly
 * used with the nPth library:
 *
 *    gpgrt_set_syscall_clamp (npth_unprotect, npth_protect);
 *
 * These functions may not modify ERRNO.
 *
 * Setting the clamp is not thread-safe and should thus be done as
 * early as possible.
 */
void
_gpgrt_set_syscall_clamp (void (*pre)(void), void (*post)(void))
{
  pre_syscall_func = pre;
  post_syscall_func = post;
}

/*
 * Return the current sycall clamp functions.  This can be used by
 * other libraries which have blocking functions.
 */
void
_gpgrt_get_syscall_clamp (void (**r_pre)(void), void (**r_post)(void))
{
  *r_pre  = pre_syscall_func;
  *r_post = post_syscall_func;
}


/* Call this function before a blocking system or libc call.  */
void
_gpgrt_pre_syscall (void)
{
  if (pre_syscall_func)
    pre_syscall_func ();
}


/* Call this function after a blocking system or libc call.  */
void
_gpgrt_post_syscall (void)
{
  if (post_syscall_func)
    post_syscall_func ();
}