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 */
15
16
17 #include <sys/types.h>
18 #include <sys/thread.h>
19 #include <sys/proc.h>
20 #include <sys/mman.h>
21 #include <sys/vmsystm.h>
22 #include <vm/as.h>
23 #include <vm/seg_umap.h>
24
25 #if !defined(__xpv)
26 #include <sys/comm_page.h>
27 #endif /* !defined(__xpv) */
28
29 /*
30 * Map in the comm page.
31 *
32 * The contents of the comm page are only defined on non-xpv x86 at this time.
33 * Furthermore, the data is only valid in userspace (32-bit or 64-bit) when
34 * mapped from a 64-bit kernel.
35 * See: "uts/i86pc/sys/comm_page.h"
36 */
37 caddr_t
comm_page_mapin()38 comm_page_mapin()
39 {
40 #if !defined(__xpv)
41 proc_t *p = curproc;
42 caddr_t addr = NULL;
43 size_t len = COMM_PAGE_SIZE;
44 uint_t prot = PROT_USER | PROT_READ;
45 segumap_crargs_t suarg;
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 suarg.kaddr = (caddr_t)&comm_page;
54 suarg.prot = suarg.maxprot = prot;
55 if (as_map(p->p_as, addr, len, segumap_create, &suarg) != 0) {
56 return (NULL);
57 }
58 return (addr);
59 #else /* !defined(__xpv) */
60 return (NULL);
61 #endif /* !defined(__xpv) */
62 }
63