File: error.h

package info (click to toggle)
libpulp 0.3.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,976 kB
  • sloc: ansic: 11,792; python: 1,216; sh: 881; makefile: 871; cpp: 582; asm: 387
file content (126 lines) | stat: -rw-r--r-- 4,620 bytes parent folder | download
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
 *  libpulp - User-space Livepatching Library
 *
 *  Copyright (C) 2021 SUSE Software Solutions GmbH
 *
 *  This file is part of libpulp.
 *
 *  libpulp 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.
 *
 *  libpulp 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 General Public License
 *  along with libpulp.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef ERROR_H
#define ERROR_H

#include "error_common.h"
#include <stdbool.h>

/* Error checking routines.  */

void exit(int);

/** @brief Get libpulp error state.
 *
 * If a fatal error has occured, libpulp cannot continue livepatching processes
 * because it may be into an unexpected state.  This function queries if
 * libpulp is in an error state.
 **/
ulp_error_t get_libpulp_error_state(void);


/** @brief Set libpulp error state.
 *
 * If a fatal error has occured, libpulp cannot continue livepatching processes
 * because it may be into an unexpected state.  This function sets its state
 * so livepatching can be marked as disabled for any reason.
 **/
void set_libpulp_error_state(ulp_error_t);
void set_libpulp_error_state_with_reason_func(const char *file, const char *func,
                                              int line, ulp_error_t state,
                                              const char *fmt, ...);

/** @brief Macro which passes the current file, function and line number for
 * logging for the `set_libpulp_error_state_with_reason_func`.
 */
#define set_libpulp_error_state_with_reason(...) \
  set_libpulp_error_state_with_reason_func(__FILE__, __func__, __LINE__, __VA_ARGS__)

/** @brief Check if libpulp is in an fatal error state.
 *
 * If a fatal error has occured, libpulp cannot continue livepatching processes
 * because it may be into an unexpected state.
 *
 * @return true if in error state, false if not.
 **/
bool libpulp_is_in_error_state(void);

/** @brief Assert that the following expression is true.  */
void libpulp_assert_func(const char *file, const char *func, int line,
                         unsigned long expression);

/** @brief Macro which passes the current file, function and line number for
 * logging.  */
#define libpulp_assert(expr) \
  libpulp_assert_func(__FILE__, __func__, __LINE__, (unsigned long)(expr))

/** @brief Libpulp's version of `errx`
 *
 *  This function works like libc's `errx`, however instead of quiting the
 *  process it put libpulp into a state that livepatches are blocked.
 * */
void libpulp_errx_func(const char *file, const char *func, int line, int eval,
                       const char *fmt, ...);

/** @brief Macro which passes the current file, function and line number for
 * logging.  */
#ifndef libpulp_errx
#define libpulp_errx(...) \
  libpulp_errx_func(__FILE__, __func__, __LINE__, __VA_ARGS__)
#endif

/** @brief Libpulp's version of `exit`
 *
 *  This function works like libc's `exit`, however instead of quiting the
 *  process it put libpulp into a state that livepatches are blocked.
 * */
void libpulp_exit_func(const char *file, const char *func, int line, int val);

#define libpulp_exit(val) libpulp_exit_func(__FILE__, __func__, __LINE__, val)

/** @brief This function will indeed crash the process with an error message.
 *
 * Should be used with care. This should be used when the library is
 * initializing and something really bad happened (e.g. dlsym not found, which
 * means malloc can't be called in the original process. That certainly will
 * turns into a disaster so it is better to crash in the beginning rather than
 * trying to continue the user's process.
 **/
void __attribute__((noreturn)) libpulp_crash(const char *fmt, ...);

/** @brief Assert that the following expression is true.  Crash the program if
 * not.  */
void libpulp_crash_assert_func(const char *file, const char *func, int line,
                               unsigned long expression);

#define libpulp_crash_assert(expr) \
  libpulp_crash_assert_func(__FILE__, __func__, __LINE__, (unsigned long)(expr))

/** Poison any function that makes the process to abort.  */
#ifndef DISABLE_ERR_POISON
#ifdef assert
#undef assert
#endif
#pragma GCC poison errx exit assert abort
#endif

#endif /* ERROR_H  */