Newsgroups: comp.lang.perl Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.jpl.nasa.gov (Larry Wall) Subject: Re: anyone gotten mmap to work w/ perl? Message-ID: <1991Apr9.051702.22978@jpl-devvax.jpl.nasa.gov> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA References: <535@appserv.Eng.Sun.COM> Date: Tue, 9 Apr 1991 05:17:02 GMT In article <535@appserv.Eng.Sun.COM> lm@sun.UUCP (Larry McVoy) writes: : : The subject line says it all, I want to use mmap(2) from perl. I know I : can do: : : sub mmap() { : local($fh, $len, $prot) = @_; : : return (syscall(SYS_mmap(0, len, $prot, MAP_SHARED, fileno($fh), 0)); : } : : The problem is the return address. I need to fake out perl into : believing that the address is a string that is $len bytes long but : should not be freed. Is there an easy way of doing this short of : wacking on perl itself? Mmm. Not that I can think of, though there might be some way of bootstrapping an inplace modification of *name into a generalized poke routine. There might also be something you can do with the 'p' pack/unpack specifier--I haven't thought about that much. Apart from that, you could use the usub hooks to link mmap into uperl.o as a subroutine. However, there's no way to guarantee that perl won't realloc a variable unless you're careful about the operations you apply to it. Assigning to a substr() of the same length is always safe. Some substitutions are safe and some aren't. (The safe ones are the ones with a constant RHS that is known to be shorter than the LHS.) read() and sysread() are safe as long as you don't ask for more than the length of the string. Most other operations are safe as long as the final length of the string is less that what it thinks is currently allocated. What you'd really kinda like is a way to mmap a particular variable, and let Perl worry about it when it gets reallocated... Larry