2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University
28 * All Rights Reserved.
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.
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.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
53 * File: memory_object.h
54 * Author: Michael Wayne Young
56 * External memory management interface definition.
59 #ifndef _MACH_MEMORY_OBJECT_TYPES_H_
60 #define _MACH_MEMORY_OBJECT_TYPES_H_
63 * User-visible types used in the external memory
64 * management interface:
67 #include <mach/port.h>
68 #include <mach/vm_types.h>
69 #include <mach/machine/vm_types.h>
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
77 typedef mach_port_t memory_object_default_t
;
79 typedef mach_port_t memory_object_t
;
80 /* A memory object ... */
81 /* Used by the kernel to retrieve */
84 typedef mach_port_t memory_object_control_t
;
85 /* Provided to a memory manager; ... */
86 /* used to control a memory object */
88 typedef mach_port_t memory_object_name_t
;
89 /* Used to describe the memory ... */
90 /* object in vm_regions() calls */
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 */
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.
107 #define MEMORY_OBJECT_COPY_TEMPORARY 3
108 /* ... Memory manager doesn't
109 * change data externally, and
110 * doesn't need to see changes.
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
120 * Not yet safe for non-kernel use.
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
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. */
145 #define MEMORY_OBJECT_NULL MACH_PORT_NULL
148 * Data lock request flags
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
158 * Types for the memory object flavor interfaces
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
];
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
174 struct old_memory_object_behave_info
{
175 memory_object_copy_strategy_t copy_strategy
;
177 boolean_t invalidate
;
180 struct memory_object_perf_info
{
181 vm_size_t cluster_size
;
185 struct old_memory_object_attr_info
{ /* old attr list */
186 boolean_t object_ready
;
188 memory_object_copy_strategy_t copy_strategy
;
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
;
198 struct memory_object_behave_info
{
199 memory_object_copy_strategy_t copy_strategy
;
201 boolean_t invalidate
;
202 boolean_t silent_overwrite
;
203 boolean_t advisory_pageout
;
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
;
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
;
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
;
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
;
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
;
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))
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)
242 * Even before we have components, we do not want to export upl internal
243 * structure to non mach components.
245 #ifndef MACH_KERNEL_PRIVATE
246 #ifdef KERNEL_PRIVATE
251 typedef mach_port_t upl_t
;
252 #endif /* KERNEL_PRIVATE */
255 #define MAX_UPL_TRANSFER 64
257 struct upl_page_info
{
258 vm_offset_t phys_addr
;
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 */
268 typedef struct upl_page_info upl_page_info_t
;
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
;
277 /* upl invocation flags */
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
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
294 /* upl pages check flags */
295 #define UPL_CHECK_DIRTY 0x1
297 /* upl pagein/pageout flags */
298 #define UPL_IOSYNC 0x1
299 #define UPL_NOCOMMIT 0x2
300 #define UPL_NORDAHEAD 0x4
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
308 /* flags for return of state from vm_map_get_upl, vm_upl address space */
310 #define UPL_DEV_MEMORY 0x1
311 #define UPL_PHYS_CONTIG 0x2
314 /* access macros for upl_t */
316 #define UPL_DEVICE_PAGE(upl) \
317 (((upl)[(index)].phys_addr != 0) ? (!((upl)[0].device)) : FALSE)
319 #define UPL_PAGE_PRESENT(upl, index) \
320 ((upl)[(index)].phys_addr != 0)
322 #define UPL_PHYS_PAGE(upl, index) \
323 (((upl)[(index)].phys_addr != 0) ? \
324 ((upl)[(index)].phys_addr) : (vm_offset_t)NULL)
326 #define UPL_DIRTY_PAGE(upl, index) \
327 (((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].dirty) : FALSE)
329 #define UPL_PRECIOUS_PAGE(upl, index) \
330 (((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].precious) : FALSE)
332 #define UPL_VALID_PAGE(upl, index) \
333 (((upl)[(index)].phys_addr != 0) ? (!((upl)[(index)].absent)) : FALSE)
335 #define UPL_SET_PAGE_FREE_ON_COMMIT(upl, index) \
336 if ((upl)[(index)].phys_addr != 0) \
337 ((upl)[(index)].pageout) = TRUE
339 #define UPL_CLR_PAGE_FREE_ON_COMMIT(upl, index) \
340 if ((upl)[(index)].phys_addr != 0) \
341 ((upl)[(index)].pageout) = FALSE
344 #ifdef KERNEL_PRIVATE
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.
351 #if !defined(IOKIT) || defined(MACH_KERNEL)
352 #include <mach/error.h>
354 /* The call prototyped below is used strictly by UPL_GET_INTERNAL_PAGE_LIST */
356 extern vm_size_t upl_offset_to_pagelist
;
357 extern vm_size_t
upl_get_internal_pagelist_offset();
359 /* UPL_GET_INTERNAL_PAGE_LIST is only valid on internal objects where the */
360 /* list request was made with the UPL_INTERNAL flag */
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))
367 extern kern_return_t
vm_fault_list_request(
369 vm_object_offset_t offset
,
372 upl_page_info_t
**user_page_list
,
376 extern kern_return_t
upl_system_list_request(
378 vm_object_offset_t offset
,
380 vm_size_t super_size
,
382 upl_page_info_t
**user_page_list
,
386 extern kern_return_t
upl_map(
389 vm_offset_t
*dst_addr
);
391 extern kern_return_t
upl_un_map(
395 extern kern_return_t
upl_commit_range(
399 boolean_t free_on_empty
,
400 upl_page_info_t
*page_list
);
402 extern kern_return_t
upl_commit(
404 upl_page_info_t
*page_list
);
406 extern upl_t
upl_create(
409 extern void upl_destroy(
412 extern kern_return_t
upl_abort(
416 extern kern_return_t
upl_abort_range(
422 extern void upl_set_dirty(
425 extern void upl_clear_dirty(
430 extern kern_return_t
memory_object_page_op(
432 vm_object_offset_t offset
,
434 vm_offset_t
*phys_entry
,
437 extern kern_return_t
memory_object_release_name(
441 extern kern_return_t
vm_map_get_upl(
446 upl_page_info_t
**page_list
,
449 int force_data_sync
);
451 extern kern_return_t
vm_region_clone(
452 ipc_port_t src_region
,
453 ipc_port_t dst_region
);
455 extern kern_return_t
vm_map_region_replace(
457 ipc_port_t old_region
,
458 ipc_port_t new_region
,
465 #ifndef MACH_KERNEL_PRIVATE
467 /* address space shared region descriptor */
469 typedef void *shared_region_mapping_t
;
470 typedef void *vm_named_entry_t
;
472 extern kern_return_t
memory_object_destroy_named(
474 kern_return_t reason
);
476 extern kern_return_t
memory_object_lock_request_named(
478 vm_object_offset_t offset
,
479 memory_object_size_t size
,
480 memory_object_return_t should_return
,
483 ipc_port_t reply_to
);
485 extern kern_return_t
memory_object_change_attributes_named(
487 memory_object_flavor_t flavor
,
488 memory_object_info_t attributes
,
493 extern kern_return_t
memory_object_create_named(
496 vm_object_t
*object_ptr
);
499 extern kern_return_t vm_get_shared_region(
501 shared_region_mapping_t *shared_region);
503 extern kern_return_t vm_set_shared_region(
505 shared_region_mapping_t shared_region);
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
,
519 shared_region_mapping_t
*next
);
521 extern kern_return_t
shared_region_mapping_create(
522 ipc_port_t text_region
,
524 ipc_port_t data_region
,
526 vm_offset_t region_mappings
,
527 vm_offset_t client_base
,
528 shared_region_mapping_t
*shared_region
);
530 extern kern_return_t
shared_region_mapping_ref(
531 shared_region_mapping_t shared_region
);
533 extern kern_return_t
shared_region_mapping_dealloc(
534 shared_region_mapping_t shared_region
);
537 shared_region_object_chain_attach(
538 shared_region_mapping_t target_region
,
539 shared_region_mapping_t object_chain
);
542 #endif MACH_KERNEL_PRIVATE
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.
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
557 #define UPL_POP_DUMP 0x20000000
558 #define UPL_POP_SET 0x40000000
559 #define UPL_POP_CLR 0x80000000
562 * Used to support options on memory_object_release_name call
565 #define MEMORY_OBJECT_TERMINATE_IDLE 0x1
566 #define MEMORY_OBJECT_RESPECT_CACHE 0x2
567 #define MEMORY_OBJECT_RELEASE_NO_OP 0x4
570 #endif /* !defined(IOKIT) || defined(MACH_KERNEL) */
571 #endif /* KERNEL_PRIVATE */
575 #endif /* _MACH_MEMORY_OBJECT_TYPES_H_ */