summaryrefslogtreecommitdiffstats
path: root/man2/mprotect.2
diff options
context:
space:
mode:
Diffstat (limited to 'man2/mprotect.2')
-rw-r--r--man2/mprotect.226
1 files changed, 13 insertions, 13 deletions
diff --git a/man2/mprotect.2 b/man2/mprotect.2
index 5a829dafe..1fe3e6a13 100644
--- a/man2/mprotect.2
+++ b/man2/mprotect.2
@@ -301,12 +301,12 @@ Got SIGSEGV at address: 0x804e000
#include <stdlib.h>
#include <sys/mman.h>
#include <unistd.h>
-
+\&
#define handle_error(msg) \e
do { perror(msg); exit(EXIT_FAILURE); } while (0)
-
+\&
static char *buffer;
-
+\&
static void
handler(int sig, siginfo_t *si, void *unused)
{
@@ -315,43 +315,43 @@ handler(int sig, siginfo_t *si, void *unused)
printf() is not async\-signal\-safe; see signal\-safety(7).
Nevertheless, we use printf() here as a simple way of
showing that the handler was called. */
-
+\&
printf("Got SIGSEGV at address: %p\en", si\->si_addr);
exit(EXIT_FAILURE);
}
-
+\&
int
main(void)
{
int pagesize;
struct sigaction sa;
-
+\&
sa.sa_flags = SA_SIGINFO;
sigemptyset(&sa.sa_mask);
sa.sa_sigaction = handler;
if (sigaction(SIGSEGV, &sa, NULL) == \-1)
handle_error("sigaction");
-
+\&
pagesize = sysconf(_SC_PAGE_SIZE);
if (pagesize == \-1)
handle_error("sysconf");
-
+\&
/* Allocate a buffer aligned on a page boundary;
initial protection is PROT_READ | PROT_WRITE. */
-
+\&
buffer = memalign(pagesize, 4 * pagesize);
if (buffer == NULL)
handle_error("memalign");
-
+\&
printf("Start of region: %p\en", buffer);
-
+\&
if (mprotect(buffer + pagesize * 2, pagesize,
PROT_READ) == \-1)
handle_error("mprotect");
-
+\&
for (char *p = buffer ; ; )
*(p++) = \[aq]a\[aq];
-
+\&
printf("Loop completed\en"); /* Should never happen */
exit(EXIT_SUCCESS);
}