forked from ColinIanKing/stress-ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore-resources.h
155 lines (142 loc) · 3.41 KB
/
core-resources.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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* Copyright (C) 2022-2023 Colin Ian King.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef CORE_RESOURCES_H
#define CORE_RESOURCES_H
#if defined(__NR_userfaultfd)
#define HAVE_USERFAULTFD
#endif
#if defined(HAVE_SYS_EVENTFD_H)
#include <sys/eventfd.h>
#endif
#if defined(HAVE_SYS_INOTIFY_H)
#include <sys/inotify.h>
#endif
#if defined(HAVE_SYS_IPC_H)
#include <sys/ipc.h>
#endif
#if defined(HAVE_SYS_MSG_H)
#include <sys/msg.h>
#endif
#if defined(HAVE_SEM_SYSV)
#include <sys/sem.h>
#endif
#if defined(HAVE_SYS_TIMERFD_H)
#include <sys/timerfd.h>
#endif
#if defined(HAVE_MQUEUE_H)
#include <mqueue.h>
#endif
#if defined(HAVE_SEMAPHORE_H)
#include <semaphore.h>
#endif
typedef struct {
void *m_malloc;
void *m_sbrk;
void *m_mmap;
size_t m_mmap_size;
int fd_pipe[2];
int pipe_ret;
int fd_open;
int fd_sock;
int fd_socketpair[2];
pid_t pid;
#if defined(HAVE_EVENTFD)
int fd_ev;
#endif
#if defined(HAVE_MEMFD_CREATE)
int fd_memfd;
void *ptr_memfd;
#endif
#if defined(__NR_memfd_secret)
int fd_memfd_secret;
int padding1;
void *ptr_memfd_secret;
#endif
#if defined(HAVE_USERFAULTFD)
int fd_uf;
#endif
#if defined(O_TMPFILE)
int fd_tmp;
#endif
#if defined(HAVE_LIB_PTHREAD)
pthread_t pthread;
int pthread_ret;
#if defined(HAVE_PTHREAD_MUTEX_T) && \
defined(HAVE_PTHREAD_MUTEX_INIT) && \
defined(HAVE_PTHREAD_MUTEX_DESTROY)
int mutex_ret;
pthread_mutex_t mutex;
#endif
#endif
#if defined(HAVE_SYS_INOTIFY_H)
int fd_inotify;
int wd_inotify;
#endif
#if defined(HAVE_PTSNAME)
int pty_mtx;
int pty;
#endif
#if defined(HAVE_LIB_RT) && \
defined(HAVE_TIMER_CREATE) && \
defined(HAVE_TIMER_DELETE) && \
defined(SIGUNUSED)
bool timerok;
timer_t timerid;
#endif
#if defined(HAVE_SYS_TIMERFD_H) && \
defined(HAVE_TIMERFD_CREATE) && \
defined(HAVE_TIMERFD_GETTIME) && \
defined(HAVE_TIMERFD_SETTIME) && \
defined(CLOCK_REALTIME)
int timer_fd;
#endif
#if defined(HAVE_LIB_PTHREAD) && \
defined(HAVE_SEM_POSIX)
bool semok;
uint8_t padding[3];
sem_t sem;
#endif
#if defined(HAVE_SEM_SYSV)
int sem_id;
#endif
#if defined(HAVE_MQ_SYSV) && \
defined(HAVE_SYS_IPC_H) && \
defined(HAVE_SYS_MSG_H)
int msgq_id;
#endif
#if defined(HAVE_LIB_RT) && \
defined(HAVE_MQ_POSIX) && \
defined(HAVE_MQUEUE_H)
mqd_t mq;
char mq_name[64];
#endif
#if defined(HAVE_PKEY_ALLOC) && \
defined(HAVE_PKEY_FREE)
int pkey;
#endif
#if defined(HAVE_PIDFD_OPEN)
int pid_fd;
#endif
} stress_resources_t;
size_t stress_resources_allocate(const stress_args_t *args, stress_resources_t *resources,
const size_t num_resources, const size_t pipe_size, const size_t min_mem_free,
const bool do_fork);
void stress_resources_free(const stress_args_t *args, stress_resources_t *resources,
const size_t num_resources);
#endif