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