CORE(5)

NAME
core - memory image file format

SYNOPSIS
#include <sys/param.h>
#include <sys/core.h>

DESCRIPTION
A small number of signals which cause abnormal termination of a process also cause a record of the process's in-core state to be written to disk for later examination by one of the available debuggers (see sigaction(2)). This memory image is written to a file named programname.core in the working directory, provided the terminated process had write permission in the directory, and provided the abnormality did not cause a system crash. (In this event, the decision to save the core file is arbitrary, see savecore(8).)

The maximum size of a programname.core file is limited by setrlimit(2). Files which would be larger than the limit are not created.

The programname.core file consists of the u-area, whose size (in pages) is defined by the UPAGES manifest in the <machine/param.h> file. The u-area starts with a user structure as given in <sys/user.h>. The remainder of the programname.core file consists of the data pages followed by the stack pages of the process image. The amount of data space image in the programname.core file is given (in pages) by the variable u_dsize in the u-area. The amount of stack image in the core file is given (in pages) by the variable u_ssize in the u-area. The size of a “page” is given by the constant PAGE_SIZE, defined in <machine/param.h>. The user structure is defined as:

    struct	user {
    	struct	pcb u_pcb;
    	struct	pstats u_stats;
    	/*
    	 * Remaining fields only for core dump and/or ptrace--
    	 * not valid at other times!
    	 */
    	struct	kinfo_proc u_kproc;
    	struct	md_coredump u_md;
    };

md_coredump is defined in the header file <machine/pcb.h>.

The on-disk core file consists of a header followed by a number of segments. Each segment is preceded by a coreseg structure giving the segment's type, the virtual address where the bits resided in process address space and the size of the segment.

The core header specifies the lengths of the core header itself and each of the following core segment headers to allow for any machine dependent alignment requirements.

    struct coreseg {
    	u_int32_t c_midmag;		/* magic, id, flags */
    	u_long	c_addr;		/* Virtual address of segment */
    	u_long	c_size;		/* Size of this segment */
    };

    struct core {
    	u_int32_t c_midmag;		/* magic, id, flags */
    	u_int16_t c_hdrsize;   /* Size of this header (machdep algn) */
    	u_int16_t c_seghdrsize;	/* Size of a segment header */
    	u_int32_t c_nseg;		/* # of core segments */
    	char	c_name[MAXCOMLEN+1];	/* Copy of p->p_comm */
    	u_int32_t c_signo;		/* Killing signal */
    	u_long	c_ucode;		/* Hmm ? */
    	u_long	c_cpusize;	/* Size of machine dependent segment */
    	u_long	c_tsize;		/* Size of traditional text segment */
    	u_long	c_dsize;		/* Size of traditional data segment */
    	u_long	c_ssize;		/* Size of traditional stack segment */
    };

The core structure's c_midmag field is an a.out-style midmag number with a COREMAGIC magic number. and flags from the following list:

    #define CORE_CPU	1
    #define CORE_DATA	2
    #define CORE_STACK	4

SEE ALSO
gdb(1), setrlimit(2), sigaction(2), sysctl(3)

HISTORY
A core file format appeared in AT&T UNIX.

CAVEATS
Programs which are started with either the set-user-ID or set-group-ID bits set, or which change their UID or GID after starting, will normally not dump core. This is to prevent sensitive information from inadvertently ending up on disk. This behaviour can be changed (for debugging purposes) by changing the kern.nosuidcoredump sysctl(3) variable to the right settings.