]> git.ipfire.org Git - people/ms/suricata.git/blob - src/util-pages.c
core: Remove unneeded consts
[people/ms/suricata.git] / src / util-pages.c
1 /* Copyright (C) 2016 Open Information Security Foundation
2 *
3 * You can copy, redistribute or modify this Program under the terms of
4 * the GNU General Public License version 2 as published by the Free
5 * Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * version 2 along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
16 */
17
18 /**
19 * \file
20 *
21 * \author Victor Julien <victor@inliniac.net>
22 *
23 * Page util functions
24 */
25
26 #include "suricata-common.h"
27 #include "util-pages.h"
28
29 #ifndef HAVE_PAGESUPPORTSRWX_AS_MACRO
30
31 /** \brief check if OS allows for RWX pages
32 *
33 * Some OS' disallow RWX pages for security reasons. This function mmaps
34 * some memory RW and then tries to turn it into RWX. If this fails we
35 * assume that the OS doesn't allow for this.
36 *
37 * Thanks to Shawn Webb from HardenedBSD for the suggestion.
38 *
39 * \retval 1 RWX supported
40 * \retval 0 not supported
41 */
42 int PageSupportsRWX(void)
43 {
44 int retval = 1;
45 void *ptr;
46 ptr = mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0);
47 if (ptr != MAP_FAILED) {
48 if (mprotect(ptr, getpagesize(), PROT_READ|PROT_WRITE|PROT_EXEC) == -1) {
49 SCLogConfig("RWX pages denied by OS");
50 retval = 0;
51 }
52 munmap(ptr, getpagesize());
53 }
54 return retval;
55 }
56 #endif /* HAVE_PAGESUPPORTSRWX_AS_MACRO */
57