1 /*-
2 * Copyright (c) 2002 Poul-Henning Kamp
3 * Copyright (c) 2002 Networks Associates Technology, Inc.
4 * All rights reserved.
5 *
6 * This software was developed for the FreeBSD Project by Poul-Henning Kamp
7 * and NAI Labs, the Security Research Division of Network Associates, Inc.
8 * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
9 * DARPA CHATS research program.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. The names of the authors may not be used to endorse or promote
20 * products derived from this software without specific prior written
21 * permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * $FreeBSD: releng/5.1/sys/amd64/amd64/dump_machdep.c 114349 2003-05-01 01:05:25Z peter $
36 */
37
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/conf.h>
41 #include <sys/cons.h>
42 #include <sys/kernel.h>
43 #include <sys/kerneldump.h>
44 #include <vm/vm.h>
45 #include <vm/pmap.h>
46 #include <machine/md_var.h>
47
48 CTASSERT(sizeof(struct kerneldumpheader) == 512);
49
50 static struct kerneldumpheader kdh;
51
52 void
53 dumpsys(struct dumperinfo *di)
54 {
55 off_t dumplo;
56 vm_offset_t a, addr;
57 u_int count, left, u;
58 void *va;
59 int i, mb;
60 int c;
61
62 printf("Dumping %ld MB\n", Maxmem / (1024*1024 / PAGE_SIZE));
63
64 /* Fill in the kernel dump header */
65 strcpy(kdh.magic, KERNELDUMPMAGIC);
66 strcpy(kdh.architecture, "amd64");
67 kdh.version = htod32(KERNELDUMPVERSION);
68 kdh.architectureversion = htod32(KERNELDUMP_I386_VERSION);
69 kdh.dumplength = htod64(Maxmem * (off_t)PAGE_SIZE);
70 kdh.dumptime = htod64(time_second);
71 kdh.blocksize = htod32(di->blocksize);
72 strncpy(kdh.hostname, hostname, sizeof kdh.hostname);
73 strncpy(kdh.versionstring, version, sizeof kdh.versionstring);
74 if (panicstr != NULL)
75 strncpy(kdh.panicstring, panicstr, sizeof kdh.panicstring);
76 kdh.parity = kerneldump_parity(&kdh);
77
78 /*
79 * Check if we will have enough room to save the coredump.
80 * The partition size needed is the sum of:
81 * Memory to save + header + trailer + Room to leave untouched
82 * at partition head. (an arbitrary amount).
83 */
84 if (di->mediasize <
85 Maxmem * (off_t)PAGE_SIZE + sizeof kdh * 2 + 64*1024) {
86 printf("\nDump failed. Partition too small.\n");
87 return;
88 }
89 dumplo = di->mediaoffset + di->mediasize - Maxmem * (off_t)PAGE_SIZE;
90 dumplo -= sizeof kdh * 2;
91 i = di->dumper(di->priv, &kdh, 0, dumplo, sizeof kdh);
92 if (i)
93 printf("\nDump failed writing header (%d)\n", i);
94 dumplo += sizeof kdh;
95 i = 0;
96 addr = 0;
97 va = 0;
98 mb = 0;
99 for (count = 0; count < Maxmem;) {
100 left = Maxmem - count;
101 if (left > MAXDUMPPGS)
102 left = MAXDUMPPGS;
103 for (u = 0; u < left; u++) {
104 a = addr + u * PAGE_SIZE;
105 if (!is_physical_memory(a))
106 a = 0;
107 va = pmap_kenter_temporary(trunc_page(a), u);
108 }
109 i = count / (16*1024*1024 / PAGE_SIZE);
110 if (i != mb) {
111 printf(" %d", count / (1024 * 1024 / PAGE_SIZE));
112 mb = i;
113 }
114 i = di->dumper(di->priv, va, 0, dumplo, left * PAGE_SIZE);
115 if (i)
116 break;
117 count += left;
118 dumplo += left * PAGE_SIZE;
119 addr += left * PAGE_SIZE;
120 if ((c = cncheckc()) == 0x03) {
121 printf("\nDump aborted.\n");
122 return;
123 } else if (c != -1)
124 printf("[CTRL-C to abort] ");
125 }
126 if (i)
127 printf("\nDump failed writing data (%d)\n", i);
128 i = di->dumper(di->priv, &kdh, 0, dumplo, sizeof kdh);
129 if (i)
130 printf("\nDump failed writing trailer (%d)\n", i);
131 di->dumper(di->priv, NULL, 0, 0, 0); /* tell them we are done */
132 printf("\nDump complete\n");
133 return;
134 }
Cache object: 6619d4f4324eaf9cd671d84cda7da2a1
|