1 /* Simple little program that just generates a core dump from inside some
2 nested function calls. */
14 #define MAPSIZE (8 * 1024)
16 /* Don't make these automatic vars or we will have to walk back up the
17 stack to access them. */
22 int coremaker_data
= 1; /* In Data section */
23 int coremaker_bss
; /* In BSS section */
25 const int coremaker_ro
= 201; /* In Read-Only Data section */
27 /* Note that if the mapping fails for any reason, we set buf2
28 to -1 and the testsuite notices this and reports it as
29 a failure due to a mapping error. This way we don't have
30 to test for specific errors when running the core maker. */
36 extern void *malloc ();
38 /* Allocate and initialize a buffer that will be used to write
39 the file that is later mapped in. */
41 buf1
= (char *) malloc (MAPSIZE
);
42 for (j
= 0; j
< MAPSIZE
; ++j
)
47 /* Write the file to map in */
49 fd
= open ("coremmap.data", O_CREAT
| O_RDWR
, 0666);
52 perror ("coremmap.data open failed");
56 write (fd
, buf1
, MAPSIZE
);
58 /* Now map the file into our address space as buf2 */
60 buf2
= (char *) mmap (0, MAPSIZE
, PROT_READ
| PROT_WRITE
, MAP_PRIVATE
, fd
, 0);
61 if (buf2
== (char *) -1)
63 perror ("mmap failed");
67 /* Verify that the original data and the mapped data are identical.
68 If not, we'd rather fail now than when trying to access the mapped
69 data from the core file. */
71 for (j
= 0; j
< MAPSIZE
; ++j
)
73 if (buf1
[j
] != buf2
[j
])
75 fprintf (stderr
, "mapped data is incorrect");
85 int coremaker_local
[5];
89 /* Force a corefile that includes the data section for AIX. */
93 sigaction (SIGABRT
, (struct sigaction
*)0, &sa
);
94 sa
.sa_flags
|= SA_FULLDUMP
;
95 sigaction (SIGABRT
, &sa
, (struct sigaction
*)0);
99 /* Make sure that coremaker_local doesn't get optimized away. */
100 for (i
= 0; i
< 5; i
++)
101 coremaker_local
[i
] = i
;
103 for (i
= 0; i
< 5; i
++)
104 coremaker_bss
+= coremaker_local
[i
];
105 coremaker_data
= coremaker_ro
+ 1;
This page took 0.033005 seconds and 5 git commands to generate.