; safe2.asm for testing protections within sections ; Assemble: nasm -f elf -l safe2.lst safe2.asm ; Link: gcc -o safe2 safe2.o ; Run: safe2 ; Output: ; it should stop with a system caught error global main ; the standard gcc entry point extern printf ; the C function, to be called section .rodata ; read only data section, variables a: dd 5 ; int a=5; fmt: db "still running",10,0 ; The printf format, "\n",'0' section .text ; Code section. not writeable main: ; the program label for the entry point push ebp ; set up stack frame mov ebp,esp jmp a ; should be error, data not executable push dword fmt ; address of ctrl string call printf ; Call C function add esp,4 ; pop stack, 1 push times 4 bytes mov esp, ebp ; take down stack frame pop ebp ; same as "leave" op mov eax,0 ; normal, no error, return value ret ; return