Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2005-04

fpMMap and FreeBSD

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Xromov Kirill

Hello fpc-pascal,

I try to use fpMMap function to access file data under FreeBSD 5.3-RELEASE with fpc-1.9.8. But code from examle
(http://www.freepascal.org/docs-html/rtl/baseunix/fpmmap.html) not working.

  P:=Pchar(fpmmap(nil,len+1 ,PROT_READ or PROT_WRITE,MAP_PRIVATE,fd,0));
  If longint(P)=-1 then Halt(4);
  // At this P is normal pointer like (0x291ad000).
  Writeln('Read in memory  :',P);
  and at this point: Program received signal SIGBUS, Bus error.

And strange moment. Another example in C work OK.
---
if ((src = mmap (0, statbuf.st_size, PROT_READ, MAP_SHARED, fdin, 0)) == (caddr_t) -1)

    perror ("mmap error for input");
  /* mmap the output file */
  if ((dst = mmap (0, statbuf.st_size, PROT_READ | PROT_WRITE,
                   MAP_SHARED, fdout, 0)) == (caddr_t) -1)
    perror ("mmap error for output");

/* this copies the input file to the output file */

  memcpy (dst, src, statbuf.st_size);

---

Best regards, Xromov
Marco van de Voort
to Xromov Kirill: I try to use fpMMap function to access file data under FreeBSD 5.3-RELEASE with…
I try to use fpMMap function to access file data under FreeBSD 5.3-RELEASE with fpc-1.9.8. But code from examle (http://www.freepascal.org/docs-html/rtl/baseunix/fpmmap.html) not working.

Fixed in CVS.

Turned out mmap called via __syscall needs an extra parameter that must be 0 (?), due to stack layout the filedescriptor got passed in this space, which is ok for memory mapping of memory, but not for this example.

There is not much one can easily do in 1.9.8 to get it to work easily, since the 9 param do_syscall call doesn't exist either.

If you can't/won't use CVS, I could see if I can make a quick mock unit with a working mmap in it for 1.9.8.