system-calls

How to write a signal handler to catch SIGSEGV?

筅森魡賤 提交于 2019-11-25 23:40:26
问题 I want to write a signal handler to catch SIGSEGV. I protect a block of memory for read or write using char *buffer; char *p; char a; int pagesize = 4096; mprotect(buffer,pagesize,PROT_NONE) This protects pagesize bytes of memory starting at buffer against any reads or writes. Second, I try to read the memory: p = buffer; a = *p This will generate a SIGSEGV, and my handler will be called. So far so good. My problem is that, once the handler is called, I want to change the access write of the

What happens if you use the 32-bit int 0x80 Linux ABI in 64-bit code?

喜你入骨 提交于 2019-11-25 21:39:37
问题 int 0x80 on Linux always invokes the 32-bit ABI, regardless of what mode it\'s called from: args in ebx , ecx , ... and syscall numbers from /usr/include/asm/unistd_32.h . (Or crashes on 64-bit kernels compiled without CONFIG_IA32_EMULATION ). 64-bit code should use syscall , with call numbers from /usr/include/asm/unistd_64.h , and args in rdi , rsi , etc. See What are the calling conventions for UNIX & Linux system calls on i386 and x86-64. If your question was marked a duplicate of this,