File: | obj-scan-build/mach-defpager/../../mach-defpager/wiring.c |
Location: | line 120, column 7 |
Description: | Value stored to 'kr' is never read |
1 | /* |
2 | * Mach Operating System |
3 | * Copyright (c) 1991 Carnegie Mellon University |
4 | * All Rights Reserved. |
5 | * |
6 | * Permission to use, copy, modify and distribute this software and its |
7 | * documentation is hereby granted, provided that both the copyright |
8 | * notice and this permission notice appear in all copies of the |
9 | * software, derivative works or modified versions, and any portions |
10 | * thereof, and that both notices appear in supporting documentation. |
11 | * |
12 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" |
13 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR |
14 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. |
15 | * |
16 | * Carnegie Mellon requests users of this software to return to |
17 | * |
18 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU |
19 | * School of Computer Science |
20 | * Carnegie Mellon University |
21 | * Pittsburgh PA 15213-3890 |
22 | * |
23 | * any improvements or extensions that they make and grant Carnegie Mellon |
24 | * the rights to redistribute these changes. |
25 | */ |
26 | /* |
27 | * Package to wire current task's memory. |
28 | */ |
29 | #include <mach.h> |
30 | #include <mach_init.h> |
31 | #include <mach/machine/vm_param.h> |
32 | #include "default_pager.h" |
33 | |
34 | mach_port_t this_task; /* our task */ |
35 | mach_port_t priv_host_port = MACH_PORT_NULL((mach_port_t) 0); |
36 | /* the privileged host port */ |
37 | |
38 | void |
39 | wire_setup(host_priv) |
40 | mach_port_t host_priv; |
41 | { |
42 | priv_host_port = host_priv; |
43 | this_task = mach_task_self()((__mach_task_self_ + 0)); |
44 | } |
45 | |
46 | void |
47 | wire_memory(start, size, prot) |
48 | vm_address_t start; |
49 | vm_size_t size; |
50 | vm_prot_t prot; |
51 | { |
52 | kern_return_t kr; |
53 | |
54 | if (priv_host_port == MACH_PORT_NULL((mach_port_t) 0)) |
55 | return; |
56 | |
57 | kr = vm_wire(priv_host_port, |
58 | this_task, |
59 | start, size, prot); |
60 | if (kr != KERN_SUCCESS0) |
61 | panic("mem_wire: %d", kr); |
62 | } |
63 | |
64 | void |
65 | wire_thread() |
66 | { |
67 | kern_return_t kr; |
68 | |
69 | if (priv_host_port == MACH_PORT_NULL((mach_port_t) 0)) |
70 | return; |
71 | |
72 | kr = thread_wire(priv_host_port, |
73 | mach_thread_self(), |
74 | TRUE((boolean_t) 1)); |
75 | if (kr != KERN_SUCCESS0) |
76 | panic("wire_thread: %d", kr); |
77 | } |
78 | |
79 | void |
80 | wire_all_memory() |
81 | { |
82 | register kern_return_t kr; |
83 | vm_offset_t address; |
84 | vm_size_t size; |
85 | vm_prot_t protection; |
86 | vm_prot_t max_protection; |
87 | vm_inherit_t inheritance; |
88 | boolean_t is_shared; |
89 | memory_object_name_t object; |
90 | vm_offset_t offset; |
91 | |
92 | if (priv_host_port == MACH_PORT_NULL((mach_port_t) 0)) |
93 | return; |
94 | |
95 | /* iterate thru all regions, wiring */ |
96 | address = 0; |
97 | while ( |
98 | (kr = vm_region(this_task, &address, |
99 | &size, |
100 | &protection, |
101 | &max_protection, |
102 | &inheritance, |
103 | &is_shared, |
104 | &object, |
105 | &offset)) |
106 | == KERN_SUCCESS0) |
107 | { |
108 | if (MACH_PORT_VALID(object)(((object) != ((mach_port_t) 0)) && ((object) != ((mach_port_t ) ~0)))) |
109 | (void) mach_port_deallocate(this_task, object); |
110 | if (protection != VM_PROT_NONE((vm_prot_t) 0x00)) |
111 | { |
112 | /* The VM system cannot cope with a COW fault on another |
113 | unrelated virtual copy happening later when we have |
114 | wired down the original page. So we must touch all our |
115 | pages before wiring to make sure that only we will ever |
116 | use them. */ |
117 | void *page; |
118 | if (!(protection & VM_PROT_WRITE((vm_prot_t) 0x02))) |
119 | { |
120 | kr = vm_protect(this_task, address, size, |
Value stored to 'kr' is never read | |
121 | 0, max_protection); |
122 | } |
123 | for (page = (void *) address; |
124 | page < (void *) (address + size); |
125 | page += vm_page_size) |
126 | *(volatile int *) page = *(int *) page; |
127 | |
128 | wire_memory(address, size, protection); |
129 | |
130 | if (!(protection & VM_PROT_WRITE((vm_prot_t) 0x02))) |
131 | { |
132 | kr = vm_protect(this_task, address, size, |
133 | 0, protection); |
134 | } |
135 | } |
136 | address += size; |
137 | } |
138 | } |
139 | |
140 | /* |
141 | * Alias for vm_allocate to return wired memory. |
142 | */ |
143 | kern_return_t |
144 | vm_allocate(task, address, size, anywhere) |
145 | task_t task; |
146 | vm_address_t *address; |
147 | vm_size_t size; |
148 | boolean_t anywhere; |
149 | { |
150 | kern_return_t kr; |
151 | |
152 | if (anywhere) |
153 | *address = VM_MIN_ADDRESS(0); |
154 | kr = vm_map(task, |
155 | address, size, (vm_offset_t) 0, anywhere, |
156 | MEMORY_OBJECT_NULL((mach_port_t) 0), (vm_offset_t)0, FALSE((boolean_t) 0), |
157 | VM_PROT_DEFAULT(((vm_prot_t) 0x01)|((vm_prot_t) 0x02)), VM_PROT_ALL(((vm_prot_t) 0x01)|((vm_prot_t) 0x02)|((vm_prot_t) 0x04)), VM_INHERIT_DEFAULT((vm_inherit_t) 1)); |
158 | if (kr != KERN_SUCCESS0) |
159 | return kr; |
160 | |
161 | if (task == this_task) |
162 | (void) vm_wire(priv_host_port, task, *address, size, |
163 | VM_PROT_DEFAULT(((vm_prot_t) 0x01)|((vm_prot_t) 0x02))); |
164 | return KERN_SUCCESS0; |
165 | } |
166 | |
167 | /* Other versions of this function in libc... */ |
168 | kern_return_t |
169 | __vm_allocate (task, address, size, anywhere) |
170 | task_t task; |
171 | vm_address_t *address; |
172 | vm_size_t size; |
173 | boolean_t anywhere; |
174 | { |
175 | return vm_allocate (task, address, size, anywhere); |
176 | } |