]> git.saurik.com Git - apple/xnu.git/blob - osfmk/mach/memory_object_types.h
21f84e39cdcca368f4c977605f613b8fe6453a02
[apple/xnu.git] / osfmk / mach / memory_object_types.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * @OSF_COPYRIGHT@
24 */
25 /*
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University
28 * All Rights Reserved.
29 *
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
35 *
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
39 *
40 * Carnegie Mellon requests users of this software to return to
41 *
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
46 *
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
49 */
50 /*
51 */
52 /*
53 * File: memory_object.h
54 * Author: Michael Wayne Young
55 *
56 * External memory management interface definition.
57 */
58
59 #ifndef _MACH_MEMORY_OBJECT_TYPES_H_
60 #define _MACH_MEMORY_OBJECT_TYPES_H_
61
62 /*
63 * User-visible types used in the external memory
64 * management interface:
65 */
66
67 #include <mach/port.h>
68 #include <mach/vm_types.h>
69 #include <mach/machine/vm_types.h>
70
71 #define VM_64_BIT_DATA_OBJECTS
72 #define SHARED_LIBRARY_SERVER_SUPPORTED
73 #define GLOBAL_SHARED_TEXT_SEGMENT 0x70000000
74 #define GLOBAL_SHARED_DATA_SEGMENT 0x80000000
75 #define GLOBAL_SHARED_SEGMENT_MASK 0xF0000000
76
77 typedef mach_port_t memory_object_default_t;
78
79 typedef mach_port_t memory_object_t;
80 /* A memory object ... */
81 /* Used by the kernel to retrieve */
82 /* or store data */
83
84 typedef mach_port_t memory_object_control_t;
85 /* Provided to a memory manager; ... */
86 /* used to control a memory object */
87
88 typedef mach_port_t memory_object_name_t;
89 /* Used to describe the memory ... */
90 /* object in vm_regions() calls */
91
92 typedef mach_port_t memory_object_rep_t;
93 /* Per-client handle for mem object */
94 /* Used by user programs to specify */
95 /* the object to map */
96
97 typedef int memory_object_copy_strategy_t;
98 /* How memory manager handles copy: */
99 #define MEMORY_OBJECT_COPY_NONE 0
100 /* ... No special support */
101 #define MEMORY_OBJECT_COPY_CALL 1
102 /* ... Make call on memory manager */
103 #define MEMORY_OBJECT_COPY_DELAY 2
104 /* ... Memory manager doesn't
105 * change data externally.
106 */
107 #define MEMORY_OBJECT_COPY_TEMPORARY 3
108 /* ... Memory manager doesn't
109 * change data externally, and
110 * doesn't need to see changes.
111 */
112 #define MEMORY_OBJECT_COPY_SYMMETRIC 4
113 /* ... Memory manager doesn't
114 * change data externally,
115 * doesn't need to see changes,
116 * and object will not be
117 * multiply mapped.
118 *
119 * XXX
120 * Not yet safe for non-kernel use.
121 */
122
123 #define MEMORY_OBJECT_COPY_INVALID 5
124 /* ... An invalid copy strategy,
125 * for external objects which
126 * have not been initialized.
127 * Allows copy_strategy to be
128 * examined without also
129 * examining pager_ready and
130 * internal.
131 */
132
133 typedef int memory_object_return_t;
134 /* Which pages to return to manager
135 this time (lock_request) */
136 #define MEMORY_OBJECT_RETURN_NONE 0
137 /* ... don't return any. */
138 #define MEMORY_OBJECT_RETURN_DIRTY 1
139 /* ... only dirty pages. */
140 #define MEMORY_OBJECT_RETURN_ALL 2
141 /* ... dirty and precious pages. */
142 #define MEMORY_OBJECT_RETURN_ANYTHING 3
143 /* ... any resident page. */
144
145 #define MEMORY_OBJECT_NULL MACH_PORT_NULL
146
147 /*
148 * Data lock request flags
149 */
150
151 #define MEMORY_OBJECT_DATA_FLUSH 0x1
152 #define MEMORY_OBJECT_DATA_NO_CHANGE 0x2
153 #define MEMORY_OBJECT_DATA_PURGE 0x4
154 #define MEMORY_OBJECT_COPY_SYNC 0x8
155 #define MEMORY_OBJECT_DATA_SYNC 0x10
156
157 /*
158 * Types for the memory object flavor interfaces
159 */
160
161 #define MEMORY_OBJECT_INFO_MAX (1024)
162 typedef int *memory_object_info_t;
163 typedef int memory_object_flavor_t;
164 typedef int memory_object_info_data_t[MEMORY_OBJECT_INFO_MAX];
165
166
167 #define OLD_MEMORY_OBJECT_BEHAVIOR_INFO 10
168 #define MEMORY_OBJECT_PERFORMANCE_INFO 11
169 #define OLD_MEMORY_OBJECT_ATTRIBUTE_INFO 12
170 #define MEMORY_OBJECT_ATTRIBUTE_INFO 14
171 #define MEMORY_OBJECT_BEHAVIOR_INFO 15
172
173
174 struct old_memory_object_behave_info {
175 memory_object_copy_strategy_t copy_strategy;
176 boolean_t temporary;
177 boolean_t invalidate;
178 };
179
180 struct memory_object_perf_info {
181 vm_size_t cluster_size;
182 boolean_t may_cache;
183 };
184
185 struct old_memory_object_attr_info { /* old attr list */
186 boolean_t object_ready;
187 boolean_t may_cache;
188 memory_object_copy_strategy_t copy_strategy;
189 };
190
191 struct memory_object_attr_info {
192 memory_object_copy_strategy_t copy_strategy;
193 vm_offset_t cluster_size;
194 boolean_t may_cache_object;
195 boolean_t temporary;
196 };
197
198 struct memory_object_behave_info {
199 memory_object_copy_strategy_t copy_strategy;
200 boolean_t temporary;
201 boolean_t invalidate;
202 boolean_t silent_overwrite;
203 boolean_t advisory_pageout;
204 };
205
206 typedef struct old_memory_object_behave_info *old_memory_object_behave_info_t;
207 typedef struct old_memory_object_behave_info old_memory_object_behave_info_data_t;
208
209 typedef struct memory_object_behave_info *memory_object_behave_info_t;
210 typedef struct memory_object_behave_info memory_object_behave_info_data_t;
211
212 typedef struct memory_object_perf_info *memory_object_perf_info_t;
213 typedef struct memory_object_perf_info memory_object_perf_info_data_t;
214
215 typedef struct old_memory_object_attr_info *old_memory_object_attr_info_t;
216 typedef struct old_memory_object_attr_info old_memory_object_attr_info_data_t;
217
218 typedef struct memory_object_attr_info *memory_object_attr_info_t;
219 typedef struct memory_object_attr_info memory_object_attr_info_data_t;
220
221 #define OLD_MEMORY_OBJECT_BEHAVE_INFO_COUNT \
222 (sizeof(old_memory_object_behave_info_data_t)/sizeof(int))
223 #define MEMORY_OBJECT_BEHAVE_INFO_COUNT \
224 (sizeof(memory_object_behave_info_data_t)/sizeof(int))
225 #define MEMORY_OBJECT_PERF_INFO_COUNT \
226 (sizeof(memory_object_perf_info_data_t)/sizeof(int))
227 #define OLD_MEMORY_OBJECT_ATTR_INFO_COUNT \
228 (sizeof(old_memory_object_attr_info_data_t)/sizeof(int))
229 #define MEMORY_OBJECT_ATTR_INFO_COUNT \
230 (sizeof(memory_object_attr_info_data_t)/sizeof(int))
231
232 #define invalid_memory_object_flavor(f) \
233 (f != MEMORY_OBJECT_ATTRIBUTE_INFO && \
234 f != MEMORY_OBJECT_PERFORMANCE_INFO && \
235 f != OLD_MEMORY_OBJECT_BEHAVIOR_INFO && \
236 f != MEMORY_OBJECT_BEHAVIOR_INFO && \
237 f != OLD_MEMORY_OBJECT_ATTRIBUTE_INFO)
238
239
240
241 /*
242 * Even before we have components, we do not want to export upl internal
243 * structure to non mach components.
244 */
245 #ifndef MACH_KERNEL_PRIVATE
246 #ifdef KERNEL_PRIVATE
247 typedef struct {
248 unsigned int opaque;
249 } * upl_t;
250 #else
251 typedef mach_port_t upl_t;
252 #endif /* KERNEL_PRIVATE */
253 #endif
254
255 #define MAX_UPL_TRANSFER 64
256
257 struct upl_page_info {
258 vm_offset_t phys_addr;
259 unsigned int
260 pageout:1, /* page is to be removed on commit */
261 absent:1, /* No valid data in this page */
262 dirty:1, /* Page must be cleaned (O) */
263 precious:1, /* must be cleaned, we have only copy */
264 device:1, /* no page data, mapped dev memory */
265 :0; /* force to long boundary */
266 };
267
268 typedef struct upl_page_info upl_page_info_t;
269
270 typedef unsigned long long memory_object_offset_t;
271 typedef unsigned long long memory_object_size_t;
272 typedef upl_page_info_t *upl_page_list_ptr_t;
273 typedef mach_port_t upl_object_t;
274
275
276
277 /* upl invocation flags */
278
279 #define UPL_COPYOUT_FROM 0x1
280 #define UPL_PRECIOUS 0x2
281 #define UPL_NO_SYNC 0x4
282 #define UPL_CLEAN_IN_PLACE 0x8
283 #define UPL_NOBLOCK 0x10
284 #define UPL_RET_ONLY_DIRTY 0x20
285 #define UPL_SET_INTERNAL 0x40
286
287 /* upl abort error flags */
288 #define UPL_ABORT_RESTART 0x1
289 #define UPL_ABORT_UNAVAILABLE 0x2
290 #define UPL_ABORT_ERROR 0x4
291 #define UPL_ABORT_FREE_ON_EMPTY 0x8
292 #define UPL_ABORT_DUMP_PAGES 0x10
293
294 /* upl pages check flags */
295 #define UPL_CHECK_DIRTY 0x1
296
297 /* upl pagein/pageout flags */
298 #define UPL_IOSYNC 0x1
299 #define UPL_NOCOMMIT 0x2
300 #define UPL_NORDAHEAD 0x4
301
302 /* upl commit flags */
303 #define UPL_COMMIT_FREE_ON_EMPTY 0x1
304 #define UPL_COMMIT_CLEAR_DIRTY 0x2
305 #define UPL_COMMIT_SET_DIRTY 0x4
306 #define UPL_COMMIT_INACTIVATE 0x8
307
308 /* flags for return of state from vm_map_get_upl, vm_upl address space */
309 /* based call */
310 #define UPL_DEV_MEMORY 0x1
311 #define UPL_PHYS_CONTIG 0x2
312
313
314 /* access macros for upl_t */
315
316 #define UPL_DEVICE_PAGE(upl) \
317 (((upl)[(index)].phys_addr != 0) ? (!((upl)[0].device)) : FALSE)
318
319 #define UPL_PAGE_PRESENT(upl, index) \
320 ((upl)[(index)].phys_addr != 0)
321
322 #define UPL_PHYS_PAGE(upl, index) \
323 (((upl)[(index)].phys_addr != 0) ? \
324 ((upl)[(index)].phys_addr) : (vm_offset_t)NULL)
325
326 #define UPL_DIRTY_PAGE(upl, index) \
327 (((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].dirty) : FALSE)
328
329 #define UPL_PRECIOUS_PAGE(upl, index) \
330 (((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].precious) : FALSE)
331
332 #define UPL_VALID_PAGE(upl, index) \
333 (((upl)[(index)].phys_addr != 0) ? (!((upl)[(index)].absent)) : FALSE)
334
335 #define UPL_SET_PAGE_FREE_ON_COMMIT(upl, index) \
336 if ((upl)[(index)].phys_addr != 0) \
337 ((upl)[(index)].pageout) = TRUE
338
339 #define UPL_CLR_PAGE_FREE_ON_COMMIT(upl, index) \
340 if ((upl)[(index)].phys_addr != 0) \
341 ((upl)[(index)].pageout) = FALSE
342
343
344 #ifdef KERNEL_PRIVATE
345 /*
346 * iokit code doesn't include prerequisite header files, thus the
347 * !defined(IOKIT). But osfmk code defines IOKIT! Thus the
348 * defined(MACH_KERNEL). To clean this gorp up "just" fix all
349 * iokit & driver code to include the prereqs.
350 */
351 #if !defined(IOKIT) || defined(MACH_KERNEL)
352 #include <mach/error.h>
353
354 /* The call prototyped below is used strictly by UPL_GET_INTERNAL_PAGE_LIST */
355
356 extern vm_size_t upl_offset_to_pagelist;
357 extern vm_size_t upl_get_internal_pagelist_offset();
358
359 /* UPL_GET_INTERNAL_PAGE_LIST is only valid on internal objects where the */
360 /* list request was made with the UPL_INTERNAL flag */
361
362 #define UPL_GET_INTERNAL_PAGE_LIST(upl) \
363 ((upl_page_info_t *)((upl_offset_to_pagelist == 0) ? \
364 (unsigned int)upl + (unsigned int)(upl_offset_to_pagelist = upl_get_internal_pagelist_offset()): \
365 (unsigned int)upl + (unsigned int)upl_offset_to_pagelist))
366
367 extern kern_return_t vm_fault_list_request(
368 vm_object_t object,
369 vm_object_offset_t offset,
370 vm_size_t size,
371 upl_t *upl,
372 upl_page_info_t **user_page_list,
373 int page_list_count,
374 int cntrol_flags);
375
376 extern kern_return_t upl_system_list_request(
377 vm_object_t object,
378 vm_object_offset_t offset,
379 vm_size_t size,
380 vm_size_t super_size,
381 upl_t *upl,
382 upl_page_info_t **user_page_list,
383 int page_list_count,
384 int cntrol_flags);
385
386 extern kern_return_t upl_map(
387 vm_map_t map,
388 upl_t upl,
389 vm_offset_t *dst_addr);
390
391 extern kern_return_t upl_un_map(
392 vm_map_t map,
393 upl_t upl);
394
395 extern kern_return_t upl_commit_range(
396 upl_t upl,
397 vm_offset_t offset,
398 vm_size_t size,
399 boolean_t free_on_empty,
400 upl_page_info_t *page_list);
401
402 extern kern_return_t upl_commit(
403 upl_t upl,
404 upl_page_info_t *page_list);
405
406 extern upl_t upl_create(
407 boolean_t internal);
408
409 extern void upl_destroy(
410 upl_t page_list);
411
412 extern kern_return_t upl_abort(
413 upl_t page_list,
414 int error);
415
416 extern kern_return_t upl_abort_range(
417 upl_t page_list,
418 vm_offset_t offset,
419 vm_size_t size,
420 int error);
421
422 extern void upl_set_dirty(
423 upl_t upl);
424
425 extern void upl_clear_dirty(
426 upl_t upl);
427
428
429
430 extern kern_return_t memory_object_page_op(
431 vm_object_t object,
432 vm_object_offset_t offset,
433 int ops,
434 vm_offset_t *phys_entry,
435 int *flags);
436
437 extern kern_return_t memory_object_release_name(
438 vm_object_t object,
439 int flags);
440
441 extern kern_return_t vm_map_get_upl(
442 vm_map_t map,
443 vm_offset_t offset,
444 vm_size_t *upl_size,
445 upl_t *upl,
446 upl_page_info_t **page_list,
447 int *count,
448 int *flags,
449 int force_data_sync);
450
451 extern kern_return_t vm_region_clone(
452 ipc_port_t src_region,
453 ipc_port_t dst_region);
454
455 extern kern_return_t vm_map_region_replace(
456 vm_map_t target_map,
457 ipc_port_t old_region,
458 ipc_port_t new_region,
459 vm_offset_t start,
460 vm_offset_t end);
461
462
463
464
465 #ifndef MACH_KERNEL_PRIVATE
466
467 /* address space shared region descriptor */
468
469 typedef void *shared_region_mapping_t;
470 typedef void *vm_named_entry_t;
471
472 extern kern_return_t memory_object_destroy_named(
473 vm_object_t object,
474 kern_return_t reason);
475
476 extern kern_return_t memory_object_lock_request_named(
477 vm_object_t object,
478 vm_object_offset_t offset,
479 memory_object_size_t size,
480 memory_object_return_t should_return,
481 int flags,
482 int prot,
483 ipc_port_t reply_to);
484
485 extern kern_return_t memory_object_change_attributes_named(
486 vm_object_t object,
487 memory_object_flavor_t flavor,
488 memory_object_info_t attributes,
489 int count,
490 int reply_to,
491 int reply_to_type);
492
493 extern kern_return_t memory_object_create_named(
494 ipc_port_t port,
495 vm_size_t size,
496 vm_object_t *object_ptr);
497
498 /*
499 extern kern_return_t vm_get_shared_region(
500 task_t task,
501 shared_region_mapping_t *shared_region);
502
503 extern kern_return_t vm_set_shared_region(
504 task_t task,
505 shared_region_mapping_t shared_region);
506 */
507
508 extern kern_return_t shared_region_mapping_info(
509 shared_region_mapping_t shared_region,
510 ipc_port_t *text_region,
511 vm_size_t *text_size,
512 ipc_port_t *data_region,
513 vm_size_t *data_size,
514 vm_offset_t *region_mappings,
515 vm_offset_t *client_base,
516 vm_offset_t *alternate_base,
517 vm_offset_t *alternate_next,
518 int *flags,
519 shared_region_mapping_t *next);
520
521 extern kern_return_t shared_region_mapping_create(
522 ipc_port_t text_region,
523 vm_size_t text_size,
524 ipc_port_t data_region,
525 vm_size_t data_size,
526 vm_offset_t region_mappings,
527 vm_offset_t client_base,
528 shared_region_mapping_t *shared_region);
529
530 extern kern_return_t shared_region_mapping_ref(
531 shared_region_mapping_t shared_region);
532
533 extern kern_return_t shared_region_mapping_dealloc(
534 shared_region_mapping_t shared_region);
535
536 extern kern_return_t
537 shared_region_object_chain_attach(
538 shared_region_mapping_t target_region,
539 shared_region_mapping_t object_chain);
540
541
542 #endif MACH_KERNEL_PRIVATE
543
544
545 /*
546 * Flags for the UPL page ops routine. This routine is not exported
547 * out of the kernel at the moment and so the defs live here.
548 */
549
550
551 #define UPL_POP_DIRTY 0x1
552 #define UPL_POP_PAGEOUT 0x2
553 #define UPL_POP_PRECIOUS 0x4
554 #define UPL_POP_ABSENT 0x8
555 #define UPL_POP_BUSY 0x10
556
557 #define UPL_POP_DUMP 0x20000000
558 #define UPL_POP_SET 0x40000000
559 #define UPL_POP_CLR 0x80000000
560
561 /*
562 * Used to support options on memory_object_release_name call
563 */
564
565 #define MEMORY_OBJECT_TERMINATE_IDLE 0x1
566 #define MEMORY_OBJECT_RESPECT_CACHE 0x2
567 #define MEMORY_OBJECT_RELEASE_NO_OP 0x4
568
569
570 #endif /* !defined(IOKIT) || defined(MACH_KERNEL) */
571 #endif /* KERNEL_PRIVATE */
572
573
574
575 #endif /* _MACH_MEMORY_OBJECT_TYPES_H_ */