-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
oomify.h
66 lines (59 loc) · 2.3 KB
/
oomify.h
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
/****************************************************************************
* bfs *
* Copyright (C) 2020 Tavian Barnes <[email protected]> *
* *
* Permission to use, copy, modify, and/or distribute this software for any *
* purpose with or without fee is hereby granted. *
* *
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES *
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF *
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR *
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES *
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN *
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF *
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *
****************************************************************************/
#ifndef OOMIFY_H
#define OOMIFY_H
#include <stdatomic.h>
#include <stdbool.h>
#include <stddef.h>
#define OOMCTL_FILENO 3
/**
* OOMify configuration.
*/
struct oomctl {
/** The allocation at which to inject a failure. */
size_t inject_at;
/** Whether to fail subsequent allocations as well. */
bool inject_after;
/** Whether to raise SIGSTOP on the first failure. */
bool stop;
};
#define OOMSTAT_FILENO 4
/**
* OOMify statistics.
*/
struct oomstat {
/** The total number of allocations that occured. */
atomic_size_t total;
/** The number of malloc() calls. */
atomic_size_t malloc;
/** The number of calloc() calls. */
atomic_size_t calloc;
/** The number of realloc(ptr, size) calls. */
atomic_size_t realloc_ptr;
/** The number of realloc(NULL, size) calls. */
atomic_size_t realloc_null;
/** The number of aligned_alloc() calls. */
atomic_size_t aligned_alloc;
/** The number of posix_memalign() calls. */
atomic_size_t posix_memalign;
/** The number of memalign() calls. */
atomic_size_t memalign;
/** The number of free(ptr) calls. */
atomic_size_t free_ptr;
/** The number of free(NULL) calls. */
atomic_size_t free_null;
};
#endif // OOMIFY_H