https://sourceware.org/bugzilla/show_bug.cgi?id=29292

--- Comment #2 from Rainer Orth <ro at CeBiTec dot Uni-Bielefeld.DE> ---
> --- Comment #1 from Rainer Orth <ro at gcc dot gnu.org> ---
> I'll try to create a minimal testcase (just tmpfile, mmap, fill buffer, msync,
> munmap, fread) to see if the problem reproduces there.

Here's what I've got:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>

#define headersz 72

int
main (void)
{
  FILE *f = tmpfile ();
  int fd = fileno (f);
  lseek (fd, headersz - 1, SEEK_SET);
  char dummy = 0;
  write (fd, &dummy, 1);
  void *hdr = mmap (NULL, headersz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  memset (hdr, 'a', headersz - 1);
  msync (hdr, headersz, MS_ASYNC);
  munmap (hdr, headersz);
  fseek (f, 0, SEEK_END);
  long fsize = ftell (f);
  fseek (f, 0, SEEK_SET);
  unsigned char *buf = malloc (fsize);
  fread (buf, fsize, 1, f);
  printf ("%s\n", buf);
  return 0;
}

It works (printing 71 x 'a') on all of Linux/x86_64, Mac OS X 10.7,
Solaris 10 and Solaris 11.3.  Only on Solaris 11.4 do I get an empty
buffer, matching what I see with gld.

> However, I very much wonder what's the advantage of this complicated
> mmap/msync/munmap
> dance instead of just writing the header to the tmp file and be done with it.

Despite the fact that obviously Solaris 11.4 is wrong here, this
question remains valid.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Reply via email to