]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/amd64/amd64/db_interface.c
amd64: Protect the kernel text, data, and BSS by setting the RW/NX bits
[FreeBSD/FreeBSD.git] / sys / amd64 / amd64 / db_interface.c
1 /*-
2  * Mach Operating System
3  * Copyright (c) 1991,1990 Carnegie Mellon University
4  * All Rights Reserved.
5  *
6  * Permission to use, copy, modify and distribute this software and its
7  * documentation is hereby granted, provided that both the copyright
8  * notice and this permission notice appear in all copies of the
9  * software, derivative works or modified versions, and any portions
10  * thereof, and that both notices appear in supporting documentation.
11  *
12  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
13  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15  *
16  * Carnegie Mellon requests users of this software to return to
17  *
18  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
19  *  School of Computer Science
20  *  Carnegie Mellon University
21  *  Pittsburgh PA 15213-3890
22  *
23  * any improvements or extensions that they make and grant Carnegie the
24  * rights to redistribute these changes.
25  */
26
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29
30 /*
31  * Interface to new debugger.
32  */
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kdb.h>
37 #include <sys/pcpu.h>
38
39 #include <machine/cpufunc.h>
40 #include <machine/specialreg.h>
41
42 #include <ddb/ddb.h>
43
44 /*
45  * Read bytes from kernel address space for debugger.
46  */
47 int
48 db_read_bytes(vm_offset_t addr, size_t size, char *data)
49 {
50         jmp_buf jb;
51         void *prev_jb;
52         char *src;
53         int ret;
54
55         prev_jb = kdb_jmpbuf(jb);
56         ret = setjmp(jb);
57         if (ret == 0) {
58                 src = (char *)addr;
59                 while (size-- > 0)
60                         *data++ = *src++;
61         }
62         (void)kdb_jmpbuf(prev_jb);
63         return (ret);
64 }
65
66 /*
67  * Write bytes to kernel address space for debugger.
68  * We need to disable write protection temporarily so we can write
69  * things (such as break points) that might be in write-protected
70  * memory.
71  */
72 int
73 db_write_bytes(vm_offset_t addr, size_t size, char *data)
74 {
75         jmp_buf jb;
76         void *prev_jb;
77         char *dst;
78         u_long cr0save;
79         int ret;
80
81         cr0save = rcr0();
82         prev_jb = kdb_jmpbuf(jb);
83         ret = setjmp(jb);
84         if (ret == 0) {
85                 load_cr0(cr0save & ~CR0_WP);
86                 dst = (char *)addr;
87                 while (size-- > 0)
88                         *dst++ = *data++;
89         }
90         load_cr0(cr0save);
91         (void)kdb_jmpbuf(prev_jb);
92         return (ret);
93 }
94
95 void
96 db_show_mdpcpu(struct pcpu *pc)
97 {
98
99         db_printf("curpmap      = %p\n", pc->pc_curpmap);
100         db_printf("tssp         = %p\n", pc->pc_tssp);
101         db_printf("commontssp   = %p\n", pc->pc_commontssp);
102         db_printf("rsp0         = 0x%lx\n", pc->pc_rsp0);
103         db_printf("gs32p        = %p\n", pc->pc_gs32p);
104         db_printf("ldt          = %p\n", pc->pc_ldt);
105         db_printf("tss          = %p\n", pc->pc_tss);
106 }