From owner-freebsd-hackers Thu Aug 23 11: 7:43 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from srv1.cosmo-project.de (srv1.cosmo-project.de [213.83.6.106]) by hub.freebsd.org (Postfix) with ESMTP id C7D5137B40C for ; Thu, 23 Aug 2001 11:07:29 -0700 (PDT) (envelope-from ticso@mail.cicely.de) Received: from mail.cicely.de (cicely20 [10.1.1.22]) by srv1.cosmo-project.de (8.11.0/8.11.0) with ESMTP id f7NI7QA36861; Thu, 23 Aug 2001 20:07:27 +0200 (CEST) Received: (from ticso@localhost) by mail.cicely.de (8.11.0/8.11.0) id f7NI7W227531; Thu, 23 Aug 2001 20:07:32 +0200 (CEST) Date: Thu, 23 Aug 2001 20:07:31 +0200 From: Bernd Walter To: Julian Elischer Cc: Alfred Perlstein , Bernd Walter , freebsd-hackers@freebsd.org Subject: Re: mmap MAP_INHERIT question. Message-ID: <20010823200731.A27427@cicely20.cicely.de> References: <20010823083711.Z81307@elvis.mu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="9jxsPFA5p3P2qPhR" Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: ; from julian@elischer.org on Thu, Aug 23, 2001 at 10:13:01AM -0700 X-Operating-System: NetBSD cicely20.cicely.de 1.5 sparc Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG --9jxsPFA5p3P2qPhR Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Aug 23, 2001 at 10:13:01AM -0700, Julian Elischer wrote: > exec gives you an new vm space.. > inherrit only applies to forks Then the manpage is absolutely wrong: MAP_INHERIT Permit regions to be inherited across execve(2) system calls. I asumed MAP_SHARED alone is suffient for fork!? > On Thu, 23 Aug 2001, Alfred Perlstein wrote: > > > * Bernd Walter [010823 06:16] wrote: > > > I do the following: > > > buf = (char*)mmap(NULL, BUFSIZE, PROT_READ | PROT_WRITE, > > > MAP_ANON | MAP_INHERIT | MAP_SHARED, -1, 0); > > > > > > Now I vfork/execve a child. > > > But the child can't access the mmaped memory. > > > It was my understanding that MAP_INHERIT | MAP_SHARED keep the memory > > > over the execve. > > > > Without sample code this is impossible to explain. It's attached. Start prog1 and prog2 should see the mmaped memory. In the complex case I found it the second program wasn't able to read. In this simple case it is able to read some different value and crashed my i386-current (4.7.2001) when prog1 finishes. I can't say if it's also a problem on recent current and the system did not wrote a crashdump... -- B.Walter COSMO-Project http://www.cosmo-project.de ticso@cicely.de Usergroup info@cosmo-project.de --9jxsPFA5p3P2qPhR Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="prog1.c" #include #include #include #include #include #include void ncox(int fd) { int val; int res; val = fcntl(fd, F_GETFD, 0); res = fcntl(fd, F_SETFD, val & ~FD_CLOEXEC); } void cox(int fd) { int val; int res; val = fcntl(fd, F_GETFD, 0); res = fcntl(fd, F_SETFD, val | FD_CLOEXEC); } int main(int argc, char *argv[]) { char *buf; pid_t pid; int sv[2]; int val; char arg0[] = "prog2"; char* arg[] = {arg0, 0}; buf = (char*)mmap(NULL, 8192, PROT_READ | PROT_WRITE, MAP_ANON | MAP_INHERIT | MAP_SHARED, -1, 0); buf[0] = 'a'; buf[1] = '\0'; printf("Buffer Prog1 = %p(%s)\n", buf, buf); socketpair(AF_UNIX, SOCK_STREAM, 0, sv); printf("socketpair returned %i,%i\n", sv[0], sv[1]); sv[0]; cox(sv[0]); cox(sv[1]); val = fcntl(sv[0], F_GETFL, 0); fcntl(sv[0], F_SETFL, val | O_NONBLOCK); pid = vfork(); if (pid == 0) { dup2(sv[1], 3); ncox(3); execve("./prog2", arg, 0); } close(sv[1]); write(sv[0], &buf, sizeof(buf)); sleep(100); return 0; } --9jxsPFA5p3P2qPhR Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="prog2.c" #include #include int main(int argc, char *argv[]) { char *buf; read(3, &buf, sizeof(buf)); printf("Buffer Prog2 = %p", buf); printf("(%s)\n", buf); sleep(100); } --9jxsPFA5p3P2qPhR-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message