* [[wp>select (Unix)|select]]
* [[http://www.cppfans.org/1417.html|浅析epoll-为何多路复用I/O要使用epoll]]
* [[http://www.cppfans.org/1418.html|浅析epoll – epoll函数深入讲解]]
====== 訊號 ======
#include
#include
#include
// /usr/include/sys/ucontext.h
void segv_handler(int sig, siginfo_t *si, void *context)
{
printf("Got SIGSEGV at address: 0x%lx\n", (long) si->si_addr);
abort();
}
int main() {
struct sigaction act;
/* The SA_SIGINFO flag tells sigaction() to use the sa_sigaction field, not sa_handler. */
act.sa_flags = SA_SIGINFO;
/* Use the sa_sigaction field because the handles has two additional parameters */
act.sa_sigaction = segv_handler;
sigemptyset(&act.sa_mask);
/* Register our signal handler. */
sigaction(SIGSEGV, &act, NULL);
/* Trigger segfault */
*(char *) 0 = 0;
}
* [[http://tinymicros.com/wiki/Linux_Overflow_Signal_Handler_Example|Linux Overflow Signal Handler Example]]
* ''arch/x86/include/asm/sigcontext.h''
* ''/usr/include/sys/ucontext.h''。
/* Context to describe whole processor state. */
typedef struct
{
gregset_t gregs;
/* Note that fpregs is a pointer. */
fpregset_t fpregs;
unsigned long __reserved1 [8];
} mcontext_t;
/* Userlevel context. */
typedef struct ucontext
{
unsigned long int uc_flags;
struct ucontext *uc_link;
stack_t uc_stack;
mcontext_t uc_mcontext;
__sigset_t uc_sigmask;
struct _libc_fpstate __fpregs_mem;
} ucontext_t;
* [[http://stackoverflow.com/questions/12349169/where-is-uc-mcontext-definition|Where is uc_mcontext definition?]]
* [[wp>SIGSEGV]]
* [[http://www.daniweb.com/hardware-and-software/linux-and-unix/threads/267950/linux-signal-handling|Linux Signal Handling]]
* [[http://stackoverflow.com/questions/2663456/write-a-signal-handler-to-catch-sigsegv|Write a signal handler to catch SIGSEGV]]
* [[http://stackoverflow.com/questions/10202941/segmentation-fault-handling|Segmentation fault handling]]
* [[http://stackoverflow.com/questions/122877/why-does-strcpy-trigger-a-segmentation-fault-with-global-variables|Why does strcpy trigger a segmentation fault with global variables?]]
#include
#include
#include
#include
#include
void segv_handler(int sig, siginfo_t *si, void *context)
{
fprintf(stderr, "Got SIGSEGV at address: 0x%lx\n", (long) si->si_addr);
if (si->si_code == SEGV_MAPERR)
fprintf(stderr, "Address not mapped to object\n");
else if (si->si_code == SEGV_ACCERR)
fprintf(stderr, "Invalid permissions for mapped object\n");
else
fprintf(stderr, "No such code\n");
exit(1);
}
static void map_readonly(void *addr, long size)
{
unsigned long start, end, page_size;
page_size = getpagesize();
start = (unsigned long)addr;
start &= ~(page_size - 1);
end = (unsigned long)addr + size;
end += page_size - 1;
end &= ~(page_size - 1);
mprotect((void *)start, end - start,
PROT_READ);
}
int main()
{
sigset_t set;
struct sigaction sigact;
char *vaddr = 0;
memset(&sigact, 0, sizeof(sigact));
sigact.sa_flags = SA_SIGINFO;
sigact.sa_sigaction = segv_handler;
sigaction(SIGSEGV, &sigact, NULL);
sigemptyset(&set);
sigaddset(&set, SIGSEGV);
//*vaddr = 'a'; // SEGV_MAPERR
char *vaddr2 = (char *)malloc(4);
map_readonly(vaddr2, 4);
*vaddr2 = 'a'; // SEGV_ACCERR
}
* [[http://stackoverflow.com/questions/1687415/malloc-results-in-segmentation-fault-after-mprotect|malloc results in segmentation fault after mprotect]]
* [[http://fanqiang.chinaunix.net/a4/b2/20010508/113528_b.html|Linux下C語言編程--信號處理函數]]
====== 其它 ======
* [[http://blog.roodo.com/rocksaying/archives/2333878.html|How to use the select(), an I/O Multiplexer]]
* [[http://www.jollen.org/blog/2007/02/dynamic_loader_1_dlopen.html|研究 Dynamic Loader, #1: dlopen]]
* [[http://blog.linux.org.tw/~jserv/archives/001561.html|dlopen 的 _init 與 _fini]]
* [[http://stackoverflow.com/questions/4803152/mmap-fails-when-length-is-larger-the-4g|mmap fails when length is larger the 4G]]
====== 外部連結 ======
* [[http://www.linuxprogrammingblog.com/|Linux Programming Blog]]
* [[http://www.tldp.org/LDP/lpg/|The Linux Programmer's Guide]]
* [[http://programminggroundup.blogspot.tw/|PROGRAMMING FROM THE GROUND UP]]
* [[http://www.makelinux.net/ldd3/|Linux Device Drivers, 3rd Edition]]