Forward to the list as it is a perfect answer! -------- Message original -------- Sujet: Re: [Materm-devel] Small question about segfaults Date: Mon, 20 Oct 2008 16:40:14 +0200 De: Frederik Deweerdt <[EMAIL PROTECTED]> Pour :: jehan <[EMAIL PROTECTED]> Références: <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
[replying to you in private, I can't post to the list right now] On Mon, Oct 20, 2008 at 04:35:06PM +0200, jehan wrote: > Frederik Deweerdt writes: > > > From the program's point of view, all memory space is his, some > > addresses are allocated, some not. But all the memory (eg. from 0 to > > 0xffffffff on a 32bits arch) is potentially his. > > Ok, so what I understand here is that you confirm that the program won't > segfault as long as I am not accessing another program's allocated memory, > even if I get out my own allocated memory. Is that so? Nope, if you get out your own allocated memory, you will segfault. ...but sometimes you won't :-) The trick is as illustrated by this sample program: int main() { char *p; int i; p = malloc(128); /* suppose that the libc allocated 4K for performance purposes here */ for (i=0; i < 256; i++) { p[i] = '0'; } return 0; } This could segfault or not, depending on what the call to malloc did behind the scenes. Luckily a tool like valgrind would catch this for you. Another point to clarify. From a program's point of view, he's alone running in his address space (0-0xffffffff). The kernel set the memory up in such a way. So there's no way you could access another program's memory (except for shared memory, like the one shmget provides) Regards, Frederik ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Materm-devel mailing list Materm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/materm-devel mrxvt home page: http://materm.sourceforge.net