lkml.org 
[lkml]   [1997]   [Jan]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: mmap(MAP_SHARED | MAP_ANON) broke!
On 11 Jan 1997, Eric W. Biederman wrote:

> There is also another solution (That's a real hack).
> x = mmap(..., MAP_ANON |MAP_PRIVATE, ...);
> fd = open("/proc/self/mem");
> y = mmap(...., MAP_SHARED, ..., fd, x);
> munmap(x);

This didn't work for me... I also tried forking and then mmap-ing() the
space out of the other processes /proc/.../mem--

Any idea what's going on (code attached).


Thanks


Sujal

-- Cut --
#include <stdio.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <fcntl.h>

extern int errno;

main()
{
char *a;
char *b;
int f;

a = mmap(0, 8192, PROT_READ | PROT_WRITE, MAP_ANONYMOUS |
MAP_PRIVATE, -1, 0);

f = open("/proc/self/mem", O_RDWR);

printf ("%d\n", f); // Prints 3

b = mmap(0, 8192, PROT_READ | PROT_WRITE, MAP_SHARED, f, a);

munmap(a, 8192);

printf ("%d %d\n", b, errno); // Prints -1 22

if (fork()) {
*b = 100;
} else {
sleep (1);
printf ("%d\n", *b);
}
}



\
 
 \ /
  Last update: 2005-03-22 13:38    [W:0.196 / U:0.032 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site