#include <stdio.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#ifndef __STDC__
#define const
#endif
#define MAPSIZE (8 * 1024)
char *buf1;
char *buf2;
int coremaker_data = 1;
int coremaker_bss;
const int coremaker_ro = 201;
void
mmapdata ()
{
int j, fd;
buf1 = (char *) malloc (MAPSIZE);
for (j = 0; j < MAPSIZE; ++j)
{
buf1[j] = j;
}
fd = open ("coremmap.data", O_CREAT | O_RDWR, 0666);
if (fd == -1)
{
perror ("coremmap.data open failed");
buf2 = (char *) -1;
return;
}
write (fd, buf1, MAPSIZE);
buf2 = (char *) mmap (0, MAPSIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
if (buf2 == (char *) -1)
{
perror ("mmap failed");
return;
}
for (j = 0; j < MAPSIZE; ++j)
{
if (buf1[j] != buf2[j])
{
fprintf (stderr, "mapped data is incorrect");
buf2 = (char *) -1;
return;
}
}
}
void
func2 ()
{
int coremaker_local[5];
int i;
#ifdef SA_FULLDUMP
{
struct sigaction sa;
sigaction (SIGABRT, (struct sigaction *)0, &sa);
sa.sa_flags |= SA_FULLDUMP;
sigaction (SIGABRT, &sa, (struct sigaction *)0);
}
#endif
for (i = 0; i < 5; i++)
coremaker_local[i] = i;
coremaker_bss = 0;
for (i = 0; i < 5; i++)
coremaker_bss += coremaker_local[i];
coremaker_data = coremaker_ro + 1;
abort ();
}
void
func1 ()
{
func2 ();
}
int main ()
{
fprintf (stdout, "%d\n", getpid());
fflush (stdout);
mmapdata ();
func1 ();
return 0;
}