On Tue, 26 Oct 2004 15:07:39 +0300, Momchil Velikov <velco@xxxxxxxxx> wrote:
Simone Vellei wrote:
Hi, there is an user space method to intercept memory access, or this can be done only in kernel space (through mmap hacking)? I need to implement a mechanism for handling different address spaces for a distributed shared memory. I need to intercept remote address space access (locally invalid!) and handling this with a remote operation.
You can do it in userspace, with mmap and sigaction+SA_SIGINFO+siginfo_t
That's going to be painfully slow and unpleasant.
Could you please, clarify such bald and implicitly offensive
statetments ? What is slow ? DSM or something else ? Compared to what (I recon you have some alternative suggestion) ?
Tace, here's an example program:
#include <sys/mman.h> #include <sys/time.h> #include <time.h> #include <signal.h> #include <stdio.h> #include <errno.h> #include <string.h>
char *page;
void handler (int sig, siginfo_t *info, void *p) { if ((char *) info->si_addr >= page || (char *) info->si_addr < page + 4096) { mprotect (page, 4096, PROT_READ|PROT_WRITE); memset (page, 0xa5, 4096); } else abort (); }
int main () { struct timeval stv, etv; struct sigaction sa; page = mmap (0, 4096, PROT_NONE, MAP_SHARED | MAP_ANONYMOUS, 0, 0);
if (page == MAP_FAILED) { perror ("mm"); return -1; }
sa.sa_sigaction = handler; sigemptyset (&sa.sa_mask); sa.sa_flags = SA_SIGINFO; sigaction (SIGSEGV, &sa, 0);
gettimeofday (&stv, 0); #if 0 printf ("0x%0x\n", ((unsigned int *) page) [10]); #else ((volatile unsigned int *) page) [10]; #endif gettimeofday (&etv, 0);
printf ("%lf\n", ((etv.tv_sec - stv.tv_sec) * 1e6 + (etv.tv_usec - stv.tv_usec))); return 0; }
-- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/