C program calling assembly - results in segmentation fault
I'm trying some examples from a book and I just keep getting seg faults.
Below is the smallest possible program that still exhibits this behaviour. The full program is written as a means to 'inject' assembly code into a running program and would, among other things, malloc enough memory, read the 'code' from a file ,then point the function pointer fptr to it and call it.
The hardcoded bytes in this example are the equivalent of the following assembly lines:
which basically translates to exit() in C.
This is the program:
int main(int argc,char **argv)
And this is the output:
I'm doing this on a Fedora 8 (2.6.23) box
The Last thing i did was
/sbin/sysctl -w kernel.exec-shield=0
/sbin/sysctl -w kernel.randomize_va_space=0
echo 0 > /proc/sys/kernel/randomize_va_space
echo 0 > /proc/sys/kernel/exec-shield
echo 0 > /proc/sys/kernel/exec-shield-randomize
(same segmentation fault...)
Last edited by Filipe; 10-31-2008 at 11:42 AM.