Segmentation fault when trying to call a function locating in .data section

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm trying the following code on Linux

------code start------
#include <stdio.h>
#include <stdlib.h>

static unsigned char _func1[0x200] = {
	0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
	0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
	0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
	0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
	0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
	0x90, 0x90, 0x90, 0xc3, 0x90, 0x90, 0x90, 0x90,
};


int main()
{
	((void (*)(void)) _func1)();
	printf("okay\n");
	return 0;
}
------code end------

gcc a.c
./a.out
Segmentation fault

I am confused. In x86 architecture, the physical memory pages have either Read or Write attributes. But they don't have eXecutable attributes. Since the code stored in _func1 is valid instructions, how segmentation fault arise when CPU run
to _func1?


Thanks,
PRC


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux