> It smells a bit like a kernel bug: the program below gives a bus
> error...
>
> #define _GNU_SOURCE 1
> #include <unistd.h>
> #include <sys/mman.h>
> #include <stdio.h>
>
> int main(void)
> {
> char *p = mmap(0, 4096, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
> p[0] = '1';
> printf("p = %p, p[0] = %c\n", p, p[0]);
> p = mremap(p, 4096, 8192, MREMAP_MAYMOVE);
> printf("after mremap p = %p, p[0] = %c\n", p, p[0]);
> p[4096] = '2';
> return 0;
> }
to followup, no it's not a bug.
replacing with
int fd = open("/tmp/foo", O_RDWR);
char *p = mmap(0, 4096, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, fd, 0);
also crashes.
For shared anon mappings mmap creates a 4096 bytes sized virtual file. For
a real file you'd have to ftruncate it to the new size first. But here we
don't have a fd to call ftruncate. We would only be able to use
ftruncate+mremap with explicit /dev/zero mappings or shm_open (best
would be to use a different fd for each memory type), but of course that
would be more involving.
Bart
-
To unsubscribe from this list: send the line "unsubscribe linux-msdos" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at http://vger.kernel.org/majordomo-info.html