15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 /* Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T */
28 /* All Rights Reserved */
29 /* */
30 /* Copyright (c) 1987, 1988 Microsoft Corporation */
31 /* All Rights Reserved */
32 /* */
33
34 /*
35 * Copyright 2012 Joyent, Inc. All rights reserved.
36 */
37
38 #include <sys/types.h>
39 #include <sys/sysmacros.h>
40 #include <sys/param.h>
41 #include <sys/signal.h>
42 #include <sys/systm.h>
43 #include <sys/user.h>
44 #include <sys/proc.h>
45 #include <sys/disp.h>
46 #include <sys/class.h>
47 #include <sys/core.h>
48 #include <sys/syscall.h>
49 #include <sys/cpuvar.h>
50 #include <sys/vm.h>
51 #include <sys/sysinfo.h>
52 #include <sys/fault.h>
53 #include <sys/stack.h>
54 #include <sys/psw.h>
55 #include <sys/regset.h>
84 #include <sys/tnf.h>
85 #include <sys/tnf_probe.h>
86 #include <sys/cred.h>
87 #include <sys/mman.h>
88 #include <sys/x86_archext.h>
89 #include <sys/copyops.h>
90 #include <c2/audit.h>
91 #include <sys/ftrace.h>
92 #include <sys/panic.h>
93 #include <sys/traptrace.h>
94 #include <sys/ontrap.h>
95 #include <sys/cpc_impl.h>
96 #include <sys/bootconf.h>
97 #include <sys/bootinfo.h>
98 #include <sys/promif.h>
99 #include <sys/mach_mmu.h>
100 #if defined(__xpv)
101 #include <sys/hypervisor.h>
102 #endif
103 #include <sys/contract/process_impl.h>
104
105 #define USER 0x10000 /* user-mode flag added to trap type */
106
107 static const char *trap_type_mnemonic[] = {
108 "de", "db", "2", "bp",
109 "of", "br", "ud", "nm",
110 "df", "9", "ts", "np",
111 "ss", "gp", "pf", "15",
112 "mf", "ac", "mc", "xf"
113 };
114
115 static const char *trap_type[] = {
116 "Divide error", /* trap id 0 */
117 "Debug", /* trap id 1 */
118 "NMI interrupt", /* trap id 2 */
119 "Breakpoint", /* trap id 3 */
120 "Overflow", /* trap id 4 */
121 "BOUND range exceeded", /* trap id 5 */
122 "Invalid opcode", /* trap id 6 */
123 "Device not available", /* trap id 7 */
845 watchcode, rp->r_pc);
846 fault_type = F_INVAL;
847 } else {
848 bzero(&siginfo, sizeof (siginfo));
849 siginfo.si_signo = SIGTRAP;
850 siginfo.si_code = watchcode;
851 siginfo.si_addr = vaddr;
852 siginfo.si_trapafter = 0;
853 siginfo.si_pc = (caddr_t)rp->r_pc;
854 fault = FLTWATCH;
855 break;
856 }
857 } else {
858 /* XXX pr_watch_emul() never succeeds (for now) */
859 if (rw != S_EXEC && pr_watch_emul(rp, vaddr, rw))
860 goto out;
861 do_watch_step(vaddr, sz, rw, 0, 0);
862 fault_type = F_INVAL;
863 }
864
865 res = pagefault(addr, fault_type, rw, 0);
866
867 /*
868 * If pagefault() succeeded, ok.
869 * Otherwise attempt to grow the stack.
870 */
871 if (res == 0 ||
872 (res == FC_NOMAP &&
873 addr < p->p_usrstack &&
874 grow(addr))) {
875 lwp->lwp_lastfault = FLTPAGE;
876 lwp->lwp_lastfaddr = addr;
877 if (prismember(&p->p_fltmask, FLTPAGE)) {
878 bzero(&siginfo, sizeof (siginfo));
879 siginfo.si_addr = addr;
880 (void) stop_on_fault(FLTPAGE, &siginfo);
881 }
882 goto out;
883 } else if (res == FC_PROT && addr < p->p_usrstack &&
884 (mmu.pt_nx != 0 && (errcode & PF_ERR_EXEC))) {
|
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 /* Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T */
28 /* All Rights Reserved */
29 /* */
30 /* Copyright (c) 1987, 1988 Microsoft Corporation */
31 /* All Rights Reserved */
32 /* */
33
34 /*
35 * Copyright 2015 Joyent, Inc.
36 */
37
38 #include <sys/types.h>
39 #include <sys/sysmacros.h>
40 #include <sys/param.h>
41 #include <sys/signal.h>
42 #include <sys/systm.h>
43 #include <sys/user.h>
44 #include <sys/proc.h>
45 #include <sys/disp.h>
46 #include <sys/class.h>
47 #include <sys/core.h>
48 #include <sys/syscall.h>
49 #include <sys/cpuvar.h>
50 #include <sys/vm.h>
51 #include <sys/sysinfo.h>
52 #include <sys/fault.h>
53 #include <sys/stack.h>
54 #include <sys/psw.h>
55 #include <sys/regset.h>
84 #include <sys/tnf.h>
85 #include <sys/tnf_probe.h>
86 #include <sys/cred.h>
87 #include <sys/mman.h>
88 #include <sys/x86_archext.h>
89 #include <sys/copyops.h>
90 #include <c2/audit.h>
91 #include <sys/ftrace.h>
92 #include <sys/panic.h>
93 #include <sys/traptrace.h>
94 #include <sys/ontrap.h>
95 #include <sys/cpc_impl.h>
96 #include <sys/bootconf.h>
97 #include <sys/bootinfo.h>
98 #include <sys/promif.h>
99 #include <sys/mach_mmu.h>
100 #if defined(__xpv)
101 #include <sys/hypervisor.h>
102 #endif
103 #include <sys/contract/process_impl.h>
104 #include <sys/brand.h>
105
106 #define USER 0x10000 /* user-mode flag added to trap type */
107
108 static const char *trap_type_mnemonic[] = {
109 "de", "db", "2", "bp",
110 "of", "br", "ud", "nm",
111 "df", "9", "ts", "np",
112 "ss", "gp", "pf", "15",
113 "mf", "ac", "mc", "xf"
114 };
115
116 static const char *trap_type[] = {
117 "Divide error", /* trap id 0 */
118 "Debug", /* trap id 1 */
119 "NMI interrupt", /* trap id 2 */
120 "Breakpoint", /* trap id 3 */
121 "Overflow", /* trap id 4 */
122 "BOUND range exceeded", /* trap id 5 */
123 "Invalid opcode", /* trap id 6 */
124 "Device not available", /* trap id 7 */
846 watchcode, rp->r_pc);
847 fault_type = F_INVAL;
848 } else {
849 bzero(&siginfo, sizeof (siginfo));
850 siginfo.si_signo = SIGTRAP;
851 siginfo.si_code = watchcode;
852 siginfo.si_addr = vaddr;
853 siginfo.si_trapafter = 0;
854 siginfo.si_pc = (caddr_t)rp->r_pc;
855 fault = FLTWATCH;
856 break;
857 }
858 } else {
859 /* XXX pr_watch_emul() never succeeds (for now) */
860 if (rw != S_EXEC && pr_watch_emul(rp, vaddr, rw))
861 goto out;
862 do_watch_step(vaddr, sz, rw, 0, 0);
863 fault_type = F_INVAL;
864 }
865
866 /*
867 * Allow the brand to interpose on invalid memory accesses
868 * prior to running the native pagefault handler. If this
869 * brand hook returns zero, it was able to handle the fault
870 * completely. Otherwise, drive on and call pagefault().
871 */
872 if (PROC_IS_BRANDED(p) && BROP(p)->b_pagefault != NULL &&
873 BROP(p)->b_pagefault(p, lwp, addr, fault_type, rw) == 0) {
874 goto out;
875 }
876
877 res = pagefault(addr, fault_type, rw, 0);
878
879 /*
880 * If pagefault() succeeded, ok.
881 * Otherwise attempt to grow the stack.
882 */
883 if (res == 0 ||
884 (res == FC_NOMAP &&
885 addr < p->p_usrstack &&
886 grow(addr))) {
887 lwp->lwp_lastfault = FLTPAGE;
888 lwp->lwp_lastfaddr = addr;
889 if (prismember(&p->p_fltmask, FLTPAGE)) {
890 bzero(&siginfo, sizeof (siginfo));
891 siginfo.si_addr = addr;
892 (void) stop_on_fault(FLTPAGE, &siginfo);
893 }
894 goto out;
895 } else if (res == FC_PROT && addr < p->p_usrstack &&
896 (mmu.pt_nx != 0 && (errcode & PF_ERR_EXEC))) {
|