Contiki 3.x
swseg-prot-domains.h
1 /*
2  * Copyright (C) 2015, Intel Corporation. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  *
13  * 3. Neither the name of the copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived
15  * from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28  * OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef CPU_X86_MM_SWSEG_PROT_DOMAINS_H_
32 #define CPU_X86_MM_SWSEG_PROT_DOMAINS_H_
33 
34 #include <stdint.h>
35 #include <stdlib.h>
36 #include <stdbool.h>
37 #include "ldt-layout.h"
38 #include "paging.h"
39 #include "segmentation.h"
40 #include "syscalls-int.h"
41 
42 struct dom_kern_data {
43  /** Local Descriptor Table with per-domain descriptors */
44  segment_desc_t ldt[LDT_NUM_DESC];
45  /** Flags are defined with the prefix PROT_DOMAINS_FLAG in prot-domains.h */
46  uint32_t flags;
47  /**
48  * Original return address from call stack when this protection domain
49  * invoked some other protection domain. This serves to control the return
50  * entrypoint. The callee is not permitted to modify this value (unless the
51  * callee is the kernel protection domain).
52  */
53  uintptr_t orig_ret_addr;
54 
55  /* This structure is precisely 32 bytes in length, a power of 2. If its size
56  * changes, add an alignment attribute to keep it aligned at a power of 2 so
57  * that dereferencing arrays of these structures uses shift instructions
58  * instead of multiplication. Shifting is faster than multiplication.
59  */
60 };
61 
62 /* relies on dom_kern_data: */
63 #include "multi-segment.h"
64 
65 #define PROT_DOMAINS_ENTER_ISR(exc) \
66  MULTI_SEGMENT_ENTER_ISR(exc) \
67  PROT_DOMAINS_ENTER_ISR_COMMON(exc)
68 #define PROT_DOMAINS_LEAVE_ISR(exc) \
69  PROT_DOMAINS_LEAVE_ISR_COMMON(exc) \
70  MULTI_SEGMENT_LEAVE_ISR(exc)
71 
72 #define prot_domains_impl_init syscalls_int_init
73 
74 #define prot_domains_set_wp(en)
75 
76 /* Allocate one additional GDT entry for each protection domain. Note that
77  * the particular storage allocated by this statement may actually be used for
78  * some other protection domain, depending on how the linker happens to arrange
79  * all of the GDT storage. The GDT_IDX_LDT macro in gdt-layout.h determine
80  * which storage is used for each protection domain. Thus, this storage should
81  * not be referenced directly by its variable name.
82  */
83 #define PROT_DOMAINS_ALLOC_IMPL(nm) \
84  static segment_desc_t ATTR_BSS_GDT_MID _gdt_storage_##nm
85 
86 #endif /* CPU_X86_MM_SWSEG_PROT_DOMAINS_H_ */
Segment descriptor.
Definition: segmentation.h:89