정상적으로 컴파일되고 충돌하지 않는이 프로그램은 어떻습니까?
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/mman.h>
extern char __executable_start;
extern char __etext;
int
main (int argc, char **argv)
{
int pagesize = sysconf (_SC_PAGE_SIZE);
char *start =
(char *) (((uintptr_t) & __executable_start) & ~(pagesize - 1));
char *end =
(char *) (((uintptr_t) & __etext + pagesize - 1) & ~(pagesize - 1));
mprotect (start, end - start, PROT_READ | PROT_WRITE | PROT_EXEC);
printf ("Hello world\n");
void *m = main;
*((char *) m) = 0;
exit (0);
}
내가 __executable_start
및 __etext
사용했지만, 당신은 적어도 맨 페이지에 설명되어있는 이러한 작업을 얻을 수 있다면 당신이보고 더 좋을 수 있습니다
NAME
`etext`, `edata`, `end` - end of program segments
개요
extern etext;
extern edata;
extern end;
설명
The addresses of these symbols indicate the end of various program segments:
`etext` This is the first address past the end of the text segment (the program
code).
`edata` This is the first address past the end of the initialized data segment.
`end` This is the first address past the end of the uninitialized data
segment (also known as the BSS segment).
Although these symbols have long been provided on most UNIX systems, they are
not standardized; use with caution.
에 부합