1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
6 *
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
10 */
11
12 /*
13 * Copyright 2016 Joyent, Inc.
14 * Copyright 2025 Oxide Computer Company
15 */
16
17
18 #include <sys/types.h>
19 #include <sys/thread.h>
20 #include <sys/proc.h>
21 #include <sys/mman.h>
22 #include <sys/vmsystm.h>
23 #include <vm/as.h>
24 #include <vm/seg_umap.h>
25
26 #if !defined(__xpv)
27 #include <sys/comm_page.h>
28 #endif /* !defined(__xpv) */
29
30 /*
31 * Map in the comm page.
32 *
33 * The contents of the comm page are only defined on non-xpv x86 at this time.
34 * Furthermore, the data is only valid in userspace (32-bit or 64-bit) when
35 * mapped from a 64-bit kernel.
36 * See: "uts/i86pc/sys/comm_page.h"
37 */
38 caddr_t
comm_page_mapin()39 comm_page_mapin()
40 {
41 #if !defined(__xpv)
42 proc_t *p = curproc;
43 caddr_t addr = NULL;
44 const size_t len = sizeof (comm_page_t);
45 const uint_t prot = PROT_USER | PROT_READ;
46
47 map_addr(&addr, len, (offset_t)0, 1, 0);
48 if (addr == NULL || valid_usr_range(addr, len, prot, p->p_as,
49 p->p_as->a_userlimit) != RANGE_OKAY) {
50 return (NULL);
51 }
52
53 segumap_crargs_t suarg = {
54 .kaddr = (caddr_t)&comm_page,
55 .prot = prot,
56 .maxprot = prot,
57 };
58 if (as_map(p->p_as, addr, len, segumap_create, &suarg) != 0) {
59 return (NULL);
60 }
61 return (addr);
62 #else /* !defined(__xpv) */
63 return (NULL);
64 #endif /* !defined(__xpv) */
65 }
66