|
|
1.1 root 1: \input texinfo @c -*- Texinfo -*-
2: @setfilename mach.info
3: @settitle The GNU Mach Reference Manual
4: @setchapternewpage odd
5:
6: @comment Tell install-info what to do.
7: @dircategory Kernel
8: @direntry
9: * GNUMach: (mach). Using and programming the GNU Mach microkernel.
10: @end direntry
11:
12: @c Should have a glossary.
13: @c Unify some of our indices.
14: @syncodeindex pg cp
15: @syncodeindex vr fn
16: @syncodeindex tp fn
17:
18: @c Get the Mach version we are documenting.
19: @include version.texi
20: @set EDITION 0.4
21: @c @set ISBN X-XXXXXX-XX-X
22:
1.1.1.2 root 23: @copying
1.1 root 24: This file documents the GNU Mach microkernel.
25:
1.1.1.2 root 26: This is edition @value{EDITION}, last updated on @value{UPDATED}, of @cite{The
27: GNU Mach Reference Manual}, for version @value{VERSION}.
1.1 root 28:
1.1.1.2 root 29: Copyright @copyright{} 2001, 2002, 2006, 2007, 2008 Free Software
30: Foundation, Inc.
1.1 root 31:
1.1.1.2 root 32: @c @sp 2
33: @c Published by the Free Software Foundation @*
34: @c 59 Temple Place -- Suite 330, @*
35: @c Boston, MA 02111-1307 USA @*
36: @c ISBN @value{ISBN} @*
37:
38: @quotation
1.1 root 39: Permission is granted to copy, distribute and/or modify this document
1.1.1.2 root 40: under the terms of the GNU Free Documentation License, Version 1.2 or
41: any later version published by the Free Software Foundation; with no
42: Invariant Section, with no Front-Cover Texts, and with no Back-Cover
43: Texts. A copy of the license is included in the section entitled
44: ``GNU Free Documentation License''.
1.1 root 45:
46: This work is based on manual pages under the following copyright and license:
47:
48: @noindent
49: Mach Operating System@*
50: Copyright @copyright{} 1991,1990 Carnegie Mellon University@*
51: All Rights Reserved.
52:
53: Permission to use, copy, modify and distribute this software and its
54: documentation is hereby granted, provided that both the copyright
55: notice and this permission notice appear in all copies of the
56: software, derivative works or modified versions, and any portions
57: thereof, and that both notices appear in supporting documentation.
58:
59: CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
60: CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
61: ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
1.1.1.2 root 62: @end quotation
63: @end copying
1.1 root 64:
65: @iftex
66: @shorttitlepage The GNU Mach Reference Manual
67: @end iftex
68: @titlepage
69: @center @titlefont{The GNU Mach}
70: @sp 1
71: @center @titlefont{Reference Manual}
72: @sp 2
73: @center Marcus Brinkmann
74: @center with
75: @center Gordon Matzigkeit, Gibran Hasnaoui,
76: @center Robert V. Baron, Richard P. Draves, Mary R. Thompson, Joseph S. Barrera
77: @sp 3
78: @center Edition @value{EDITION}
79: @sp 1
80: @center last updated @value{UPDATED}
81: @sp 1
82: @center for version @value{VERSION}
83: @page
84: @vskip 0pt plus 1filll
1.1.1.2 root 85: @insertcopying
1.1 root 86: @end titlepage
87: @c @titlepage
88: @c @finalout
89: @c @title The GNU Mach Reference Manual
90: @c @author Marcus Brinkmann
91: @c @author Gordon Matzigkeit
92: @c @author Gibran Hasnaoui
93:
94: @c @author Robert V. Baron @c (rvb)
95: @c @author Richard P. Draves @c (rpd)
96: @c @author Mary R. Thompson @c (mrt)
97: @c @author Joseph S. Barrera @c (jsb)
1.1.1.2 root 98: @c @c The following occur rarely in the rcs commit logs of the man pages:
1.1 root 99: @c @c Dan Stodolsky, (danner)
100: @c @c David B. Golub, (dbg)
101: @c @c Terri Watson, (elf)
102: @c @c Lori Iannamico, (lli) [distribution coordinator]
103: @c @c Further authors of kernel_interfaces.ps:
104: @c @c David Black [OSF]
105: @c @c William Bolosky
106: @c @c Jonathan Chew
107: @c @c Alessandro Forin
108: @c @c Richard F. Rashid
109: @c @c Avadis Tevanian Jr.
110: @c @c Michael W. Young
111: @c @c See also
112: @c @c http://www.cs.cmu.edu/afs/cs/project/mach/public/www/people-former.html
113: @page
114:
115: @ifnottex
116: @node Top
117: @top Main Menu
1.1.1.2 root 118:
119: @insertcopying
1.1 root 120: @end ifnottex
121:
122: @menu
123: * Introduction:: How to use this manual.
124: * Installing:: Setting up GNU Mach on your computer.
125: * Bootstrap:: Running GNU Mach on your machine.
126: * Inter Process Communication:: Communication between process.
127: * Virtual Memory Interface:: Allocating and deallocating virtual memory.
128: * External Memory Management:: Handling memory pages in user space.
129: * Threads and Tasks:: Handling of threads and tasks.
130: * Host Interface:: Interface to a Mach host.
131: * Processors and Processor Sets:: Handling processors and sets of processors.
1.1.1.2 root 132: * Device Interface:: Accessing kernel devices.
1.1 root 133: * Kernel Debugger:: How to use the built-in kernel debugger.
134:
135: Appendices
136:
137: * Copying:: The GNU General Public License says how you
138: can copy and share the GNU Mach microkernel.
139: * Documentation License:: This manual is under the GNU Free
140: Documentation License.
141:
142: Indices
143:
144: * Concept Index:: Index of concepts and programs.
145: * Function and Data Index:: Index of functions, variables and data types.
146:
147:
148: @detailmenu
149: --- The Detailed Node Listing ---
150:
151: Introduction
152:
153: * Audience:: The people for whom this manual is written.
154: * Features:: Reasons to install and use GNU Mach.
155: * Overview:: Basic architecture of the Mach microkernel.
156: * History:: The story about Mach.
157:
158: Installing
159:
160: * Binary Distributions:: Obtaining ready-to-run GNU distributions.
161: * Compilation:: Building GNU Mach from its source code.
162: * Configuration:: Configuration options at compilation time.
163: * Cross-Compilation:: Building GNU Mach from another system.
164:
165: Bootstrap
166:
167: * Bootloader:: Starting the microkernel, or other OSes.
168: * Modules:: Starting the first task of the OS.
169:
170: Inter Process Communication
171:
172: * Major Concepts:: The concepts behind the Mach IPC system.
173: * Messaging Interface:: Composing, sending and receiving messages.
174: * Port Manipulation Interface:: Manipulating ports, port rights, port sets.
175:
176: Messaging Interface
177:
178: * Mach Message Call:: Sending and receiving messages.
179: * Message Format:: The format of Mach messages.
180: * Exchanging Port Rights:: Sending and receiving port rights.
181: * Memory:: Passing memory regions in messages.
182: * Message Send:: Sending messages.
183: * Message Receive:: Receiving messages.
184: * Atomicity:: Atomicity of port rights.
185:
186: Port Manipulation Interface
187:
188: * Port Creation:: How to create new ports and port sets.
189: * Port Destruction:: How to destroy ports and port sets.
190: * Port Names:: How to query and manipulate port names.
191: * Port Rights:: How to work with port rights.
192: * Ports and other Tasks:: How to move rights between tasks.
193: * Receive Rights:: How to work with receive rights.
194: * Port Sets:: How to work with port sets.
195: * Request Notifications:: How to request notifications for events.
1.1.1.3 root 196: * Inherited Ports:: How to work with the inherited system ports.
1.1 root 197:
198: Virtual Memory Interface
199:
200: * Memory Allocation:: Allocation of new virtual memory.
201: * Memory Deallocation:: Freeing unused virtual memory.
202: * Data Transfer:: Reading, writing and copying memory.
203: * Memory Attributes:: Tweaking memory regions.
204: * Mapping Memory Objects:: How to map memory objects.
205: * Memory Statistics:: How to get statistics about memory usage.
206:
207: External Memory Management
208:
209: * Memory Object Server:: The basics of external memory management.
210: * Memory Object Creation:: How new memory objects are created.
211: * Memory Object Termination:: How memory objects are terminated.
212: * Memory Objects and Data:: Data transfer to and from memory objects.
213: * Memory Object Locking:: How memory objects are locked.
214: * Memory Object Attributes:: Manipulating attributes of memory objects.
215: * Default Memory Manager:: Setting and using the default memory manager.
216:
217: Threads and Tasks
218:
219: * Thread Interface:: Manipulating threads.
220: * Task Interface:: Manipulating tasks.
221: * Profiling:: Profiling threads and tasks.
222:
223: Thread Interface
224:
225: * Thread Creation:: Creating threads.
226: * Thread Termination:: Terminating threads.
227: * Thread Information:: How to get informations on threads.
228: * Thread Settings:: How to set threads related informations.
229: * Thread Execution:: How to control the thread's machine state.
230: * Scheduling:: Operations on thread scheduling.
231: * Thread Special Ports:: How to handle the thread's special ports.
232: * Exceptions:: Managing exceptions.
233:
234: Scheduling
235:
236: * Thread Priority:: Changing the priority of a thread.
237: * Hand-Off Scheduling:: Switch to a new thread.
238: * Scheduling Policy:: Setting the scheduling policy.
239:
240: Task Interface
241:
242: * Task Creation:: Creating tasks.
243: * Task Termination:: Terminating tasks.
244: * Task Information:: Informations on tasks.
245: * Task Execution:: Thread scheduling in a task.
246: * Task Special Ports:: How to get and set the task's special ports.
247: * Syscall Emulation:: How to emulate system calls.
248:
249: Host Interface
250:
251: * Host Ports:: Ports representing a host.
252: * Host Information:: Query information about a host.
253: * Host Time:: Functions to query manipulate the host time.
254: * Host Reboot:: Rebooting the system.
255:
256: Processors and Processor Sets
257:
258: * Processor Set Interface:: How to work with processor sets.
259: * Processor Interface:: How to work with individual processors.
260:
261: Processor Set Interface
262:
263: * Processor Set Ports:: Ports representing a processor set.
264: * Processor Set Access:: How the processor sets are accessed.
265: * Processor Set Creation:: How new processor sets are created.
266: * Processor Set Destruction:: How processor sets are destroyed.
267: * Tasks and Threads on Sets:: Assigning tasks or threads to processor sets.
268: * Processor Set Priority:: Specifying the priority of a processor set.
269: * Processor Set Policy:: Changing the processor set policies.
270: * Processor Set Info:: Obtaining information about a processor set.
271:
272: Processor Interface
273:
274: * Hosted Processors:: Getting a list of all processors on a host.
275: * Processor Control:: Starting, stopping, controlling processors.
276: * Processors and Sets:: Combining processors into processor sets.
277: * Processor Info:: Obtaining information on processors.
278:
279: Device Interface
280:
281: * Device Open:: Opening hardware devices.
282: * Device Close:: Closing hardware devices.
283: * Device Read:: Reading data from the device.
284: * Device Write:: Writing data to the device.
285: * Device Map:: Mapping devices into virtual memory.
286: * Device Status:: Querying and manipulating a device.
287: * Device Filter:: Filtering packets arriving on a device.
288:
289: Kernel Debugger
290:
291: * Operation:: Basic architecture of the kernel debugger.
292: * Commands:: Available commands in the kernel debugger.
293: * Variables:: Access of variables from the kernel debugger.
294: * Expressions:: Usage of expressions in the kernel debugger.
295:
296: Documentation License
297:
1.1.1.2 root 298: * GNU Free Documentation License:: The GNU Free Documentation License.
1.1 root 299: * CMU License:: The CMU license applies to the original Mach
300: kernel and its documentation.
301:
302: @end detailmenu
303: @end menu
304:
305:
306: @node Introduction
307: @chapter Introduction
308:
309: GNU Mach is the microkernel of the GNU Project. It is the base of the
310: operating system, and provides its functionality to the Hurd servers,
311: the GNU C Library and all user applications. The microkernel itself
312: does not provide much functionality of the system, just enough to make
313: it possible for the Hurd servers and the C library to implement the missing
314: features you would expect from a POSIX compatible operating system.
315:
316: @menu
317: * Audience:: The people for whom this manual is written.
318: * Features:: Reasons to install and use GNU Mach.
319: * Overview:: Basic architecture of the Mach microkernel.
320: * History:: The story about Mach.
321: @end menu
322:
323:
324: @node Audience
325: @section Audience
326:
327: This manual is designed to be useful to everybody who is interested in
328: using, administering, or programming the Mach microkernel.
329:
330: If you are an end-user and you are looking for help on running the Mach
331: kernel, the first few chapters of this manual describe the essential
332: parts of installing and using the kernel in the GNU operating system.
333:
334: The rest of this manual is a technical discussion of the Mach
335: programming interface and its implementation, and would not be helpful
336: until you want to learn how to extend the system or modify the kernel.
337:
338: This manual is organized according to the subsystems of Mach, and each
339: chapter begins with descriptions of conceptual ideas that are related to
340: that subsystem. If you are a programmer and want to learn more about,
341: say, the Mach IPC subsystem, you can skip to the IPC chapter
342: (@pxref{Inter Process Communication}), and read about the related
343: concepts and interface definitions.
344:
345:
346: @node Features
347: @section Features
348:
349: GNU Mach is not the most advanced microkernel known to the planet,
350: nor is it the fastest or smallest, but it has a rich set of interfaces and
351: some features which make it useful as the base of the Hurd system.
352:
353: @table @asis
354: @item it's free software
355: Anybody can use, modify, and redistribute it under the terms of the GNU
356: General Public License (@pxref{Copying}). GNU Mach is part of the GNU
357: system, which is a complete operating system licensed under the GPL.
358:
359: @item it's built to survive
360: As a microkernel, GNU Mach doesn't implement a lot of the features
361: commonly found in an operating system, but only the bare minimum
362: that is required to implement a full operating system on top of it.
363: This means that a lot of the operating system code is maintained outside
364: of GNU Mach, and while this code may go through a complete redesign, the
365: code of the microkernel can remain comparatively stable.
366:
367: @item it's scalable
368: Mach is particularly well suited for SMP and network cluster techniques.
369: Thread support is provided at the kernel level, and the kernel itself
370: takes advantage of that. Network transparency at the IPC level makes
371: resources of the system available across machine boundaries (with NORMA
372: IPC, currently not available in GNU Mach).
373:
374: @item it exists
375: The Mach microkernel is real software that works Right Now.
376: It is not a research or a proposal. You don't have to wait at all
377: before you can start using and developing it. Mach has been used in
378: many operating systems in the past, usually as the base for a single
379: UNIX server. In the GNU system, Mach is the base of a functional
380: multi-server operating system, the Hurd.
381: @end table
382:
383:
384: @node Overview
385: @section Overview
386:
387: @c This paragraph by Gordon Matzigkeit from the Hurd manual.
388: An operating system kernel provides a framework for programs to share a
389: computer's hardware resources securely and efficiently. This requires
1.1.1.2 root 390: that the programs are separated and protected from each other. To make
1.1 root 391: running multiple programs in parallel useful, there also needs to be a
392: facility for programs to exchange information by communication.
393:
394: The Mach microkernel provides abstractions of the underlying hardware
395: resources like devices and memory. It organizes the running programs
396: into tasks and threads (points of execution in the tasks). In addition,
397: Mach provides a rich interface for inter-process communication.
398:
399: What Mach does not provide is a POSIX compatible programming interface.
400: In fact, it has no understanding of file systems, POSIX process semantics,
401: network protocols and many more. All this is implemented in tasks
402: running on top of the microkernel. In the GNU operating system, the Hurd
403: servers and the C library share the responsibility to implement the POSIX
404: interface, and the additional interfaces which are specific to the GNU
405: system.
406:
407:
408: @node History
409: @section History
410:
411: XXX A few lines about the history of Mach here.
412:
413:
414: @node Installing
415: @chapter Installing
416:
417: Before you can use the Mach microkernel in your system you'll need to install
418: it and all components you want to use with it, e.g. the rest of the operating
419: system. You also need a bootloader to load the kernel from the storage
420: medium and run it when the computer is started.
421:
422: GNU Mach is only available for Intel i386-compatible architectures
423: (such as the Pentium) currently. If you have a different architecture
424: and want to run the GNU Mach microkernel, you will need to port the
425: kernel and all other software of the system to your machine's architecture.
426: Porting is an involved process which requires considerable programming skills,
427: and it is not recommended for the faint-of-heart.
428: If you have the talent and desire to do a port, contact
429: @email{bug-hurd@@gnu.org} in order to coordinate the effort.
430:
431: @menu
432: * Binary Distributions:: Obtaining ready-to-run GNU distributions.
433: * Compilation:: Building GNU Mach from its source code.
434: * Configuration:: Configuration options at compile time.
435: * Cross-Compilation:: Building GNU Mach from another system.
436: @end menu
437:
438:
439: @node Binary Distributions
440: @section Binary Distributions
441:
442: By far the easiest and best way to install GNU Mach and the operating
443: system is to obtain a GNU binary distribution. The GNU operating
444: system consists of GNU Mach, the Hurd, the C library and many applications.
445: Without the GNU operating system, you will only have a microkernel, which
446: is not very useful by itself, without the other programs.
447:
448: Building the whole operating system takes a huge effort, and you are well
449: advised to not do it yourself, but to get a binary distribution of the
450: GNU operating system. The distribution also includes a binary of the
451: GNU Mach microkernel.
452:
453: Information on how to obtain the GNU system can be found in the Hurd
454: info manual.
455:
456:
457: @node Compilation
458: @section Compilation
459:
460: If you already have a running GNU system, and only want to recompile
461: the kernel, for example to select a different set of included hardware
462: drivers, you can easily do this. You need the GNU C compiler and
1.1.1.2 root 463: MIG, the Mach interface generator, which both come in their own
1.1 root 464: packages.
465:
466: Building and installing the kernel is as easy as with any other GNU
467: software package. The configure script is used to configure the source
468: and set the compile time options. The compilation is done by running:
469:
470: @example
471: make
472: @end example
473:
474: To install the kernel and its header files, just enter the command:
475:
476: @example
477: make install
478: @end example
479:
1.1.1.2 root 480: This will install the kernel as @file{EXEC_PREFIX/boot/gnumach}, the header
481: files into @file{PREFIX/include/}, the list of message ids as
482: @file{PREFIX/share/msgids/gnumach.msgids} and the documentation into
483: @file{PREFIX/share/info/}.
484:
485: Note that there is also a way to only install the header and documentation
486: files without having to actually build the whole package: run @command{make
487: install-data} after having ran @command{configure} to do so. (This is needed
488: for bootstrapping a cross compiler and similar procedures.)
1.1 root 489:
490: @node Configuration
491: @section Configuration
492:
1.1.1.2 root 493: See the following tables for the options can be passed to the
494: @command{configure} script as command line arguments to control what components
495: are built into the kernel, how certain things are configured and so on.
496:
497: See the top-level @file{INSTALL} file for information about generic
498: @command{configure} options, like under which paths to install the package's
499: components. It also describes how to control the process by setting
500: environment variables.
501:
502: The file @file{i386/README-Drivers} has some i386-specific information for
503: device drivers. You should only need to consult this file in case a device
504: driver is not working for you.
1.1 root 505:
1.1.1.2 root 506: @subsection Table of configure switches not related to device drivers
1.1 root 507:
508: @table @code
509: @item --enable-kdb
1.1.1.2 root 510: In-kernel debugger. This is only useful if you actually anticipate debugging
511: the kernel. It is not enabled by default because it adds considerably to the
512: unpageable memory footprint of the kernel. @xref{Kernel Debugger}.
513: @end table
514:
515: @table @code
516: @item --enable-pae
517: @acronym{PAE, Physical Address Extension} feature (@samp{ix86}-only),
518: which is available on modern @samp{ix86} processors; on @samp{ix86-at} disabled
519: by default, on @samp{ix86-xen} enabled by default.
520: @end table
521:
522: @subsection Turning device drivers on or off
1.1 root 523:
1.1.1.2 root 524: Each device driver has an associated configure switch. The following table
525: indicates whether a device driver is enabled by default or not. It also gives
526: --- if possible at all --- the configure switches to use for disabling or
527: enabling device drivers, in case you're not satisfied with the default choices.
528: You can specify @samp{--enable-device-drivers=WHICH} (where WHICH on
529: @samp{ix86-at} must be one of @samp{default}, @samp{qemu}, @samp{none}) to
530: preset a certain subset of all available device drivers.
531: @samp{--enable-device-drivers} is sugar for
532: @samp{--enable-device-drivers=default} (and is the implicit default
533: nevertheless) and @samp{--disable-device-drivers} is short for
534: @samp{--enable-device-drivers=none}. @samp{qemu} will include only the set of
535: device drivers that is useful when using the resulting kernel binary to drive a
536: Hurd system in the @acronym{QEMU} system emulator. This is only useful for
537: reducing the kernel build time and the kernel image size.
538:
539: @subsection What the configure switches do
540:
541: Each configure switch has two effects. First, it defines a @acronym{CPP}
542: symbol that turns on or off the hooks that autoconfigure the device and add it
543: to the list of available devices. Second, it adds the source code for the
544: driver to a make variable so that the code for the driver is compiled and
545: linked into the kernel. Also follow this route to find the file(s) which are
546: implementing a certain device driver.
547:
548: @subsection Table of configure switches related to device drivers
549:
550: (@samp{%d} in the following denotes a unit number, starting with @samp{0}.)
551:
552: @table @code
553: @item --disable-kmsg
554: Kernel message device @samp{kmsg}.
1.1 root 555:
556: @item --enable-lpr
1.1.1.2 root 557: Parallel port device driver for the @samp{lpr%d} devices. On @samp{ix86-at}
558: enabled by @samp{default}.
1.1 root 559:
560: @item --enable-floppy
1.1.1.2 root 561: PC floppy disk controller device driver for the @samp{fd%d} devices. On
562: @samp{ix86-at} enabled by @samp{default} and for @samp{qemu}.
1.1 root 563:
564: @item --enable-ide
1.1.1.2 root 565: IDE controller device driver for the @samp{hd%d} and @samp{hd%ds%d} (disks and
566: their partitions) devices. On @samp{ix86-at} enabled by @samp{default} and for
567: @samp{qemu}.
1.1 root 568: @end table
569:
1.1.1.2 root 570: The following options control drivers for various SCSI controller. SCSI
571: devices are named @samp{sd%d} and @samp{sd%ds$d} (disks and their partitions)
572: or @samp{cd%d} (CD ROMs).
1.1 root 573:
574: @table @code
575: @item --enable-advansys
1.1.1.2 root 576: AdvanSys SCSI controller device driver. On @samp{ix86-at} enabled by
577: @samp{default}.
1.1 root 578:
579: @item --enable-buslogic
1.1.1.2 root 580: BusLogic SCSI controller device driver. On @samp{ix86-at} enabled by
581: @samp{default}.
1.1 root 582:
1.1.1.2 root 583: @item --enable-flashpoint
584: Only meaningful in conjunction with the above BusLogic SCSI controller device
585: driver. Enable the FlashPoint support.
586:
587: @item --enable-u14-34f
588: UltraStor 14F/34F SCSI controller device driver. On @samp{ix86-at} enabled by
589: @samp{default}.
1.1 root 590:
591: @item --enable-ultrastor
1.1.1.2 root 592: UltraStor SCSI controller device driver. On @samp{ix86-at} enabled by
593: @samp{default}.
1.1 root 594:
595: @item --enable-aha152x
1.1.1.2 root 596: Adaptec AHA-152x/2825 SCSI controller device driver. On @samp{ix86-at} enabled
597: by @samp{default}.
1.1 root 598:
599: @item --enable-aha1542
1.1.1.2 root 600: Adaptec AHA-1542 SCSI controller device driver. On @samp{ix86-at} enabled by
601: @samp{default}.
1.1 root 602:
603: @item --enable-aha1740
1.1.1.2 root 604: Adaptec AHA-1740 SCSI controller device driver. On @samp{ix86-at} enabled by
605: @samp{default}.
1.1 root 606:
607: @item --enable-aic7xxx
1.1.1.2 root 608: Adaptec AIC7xxx SCSI controller device driver. On @samp{ix86-at} enabled by
609: @samp{default}.
1.1 root 610:
1.1.1.2 root 611: @item --enable-fdomain
612: Future Domain 16xx SCSI controller device driver. On @samp{ix86-at} enabled by
613: @samp{default}.
1.1 root 614:
615: @item --enable-in2000
1.1.1.2 root 616: Always IN 2000 SCSI controller device driver. On @samp{ix86-at} enabled by
617: @samp{default}.
1.1 root 618:
1.1.1.2 root 619: @item --enable-g_NCR5380
620: Generic NCR5380/53c400 SCSI controller device driver.
1.1 root 621:
1.1.1.2 root 622: @item --enable-NCR53c406a
623: NCR53c406a SCSI controller device driver.
1.1 root 624:
625: @item --enable-pas16
1.1.1.2 root 626: PAS16 SCSI controller device driver. On @samp{ix86-at} enabled by
627: @samp{default}.
1.1 root 628:
629: @item --enable-seagate
1.1.1.2 root 630: Seagate ST02 and Future Domain TMC-8xx SCSI controller device driver. On
631: @samp{ix86-at} enabled by @samp{default}.
1.1 root 632:
633: @item --enable-t128
1.1.1.2 root 634: Trantor T128/T128F/T228 SCSI controller device driver. On @samp{ix86-at}
635: enabled by @samp{default}.
636:
637: @item --enable-53c78xx
638: NCR53C7,8xx SCSI controller device driver. On @samp{ix86-at} enabled by
639: @samp{default}.
640:
641: @item --enable-eata_dma
642: EATA-DMA (DPT, NEC, AT&T, SNI, AST, Olivetti, Alphatronix) SCSI controller
643: device driver.
644:
645: @item --enable-eata_pio
646: EATA-PIO (old DPT PM2001, PM2012A) SCSI controller device driver. On
647: @samp{ix86-at} enabled by @samp{default}.
1.1 root 648:
649: @item --enable-wd7000
1.1.1.2 root 650: WD 7000 SCSI controller device driver. On @samp{ix86-at} enabled by
651: @samp{default}.
1.1 root 652:
653: @item --enable-eata
1.1.1.2 root 654: EATA ISA/EISA/PCI (DPT and generic EATA/DMA-compliant boards) SCSI controller
655: device driver. On @samp{ix86-at} enabled by @samp{default}.
1.1 root 656:
657: @item --enable-am53c974
1.1.1.2 root 658: AM53/79C974 SCSI controller device driver. On @samp{ix86-at} enabled by
659: @samp{default}.
1.1 root 660:
1.1.1.2 root 661: @item --enable-dtc
662: DTC3180/3280 SCSI controller device driver. On @samp{ix86-at} enabled by
663: @samp{default}.
1.1 root 664:
665: @item --enable-ncr53c8xx
1.1.1.2 root 666: NCR53C8XX, dc390w, dc390u, dc390f SCSI controller device driver. On
667: @samp{ix86-at} enabled by @samp{default}.
668:
669: @item --enable-tmscsim
670: Tekram DC-390(T) SCSI controller device driver. On @samp{ix86-at} enabled by
671: @samp{default}.
1.1 root 672:
673: @item --enable-ppa
1.1.1.2 root 674: IOMEGA Parallel Port ZIP drive device driver. On @samp{ix86-at} enabled by
675: @samp{default}.
1.1 root 676:
677: @item --enable-qlogicfas
1.1.1.2 root 678: Qlogic FAS SCSI controller device driver. On @samp{ix86-at} enabled by
679: @samp{default}.
1.1 root 680:
681: @item --enable-qlogicisp
1.1.1.2 root 682: Qlogic ISP SCSI controller device driver. On @samp{ix86-at} enabled by
683: @samp{default}.
1.1 root 684:
685: @item --enable-gdth
1.1.1.2 root 686: GDT SCSI Disk Array controller device driver. On @samp{ix86-at} enabled by
687: @samp{default}.
1.1 root 688: @end table
689:
1.1.1.2 root 690: The following options enable drivers for various ethernet cards. NIC devices
691: are usually named @samp{eth%d}, except for the pocket adaptors.
1.1 root 692:
1.1.1.2 root 693: @c GNU Mach does only autodetect one ethernet card. To enable any further
694: @c cards, the source code has to be edited.
1.1 root 695: @c XXX Reference to the source code.
696:
697: @table @code
1.1.1.2 root 698: @item --enable-ne
699: NE2000/NE1000 ISA network card device driver. On @samp{ix86-at} enabled by
700: @samp{default} and for @samp{qemu}.
1.1 root 701:
702: @item --enable-3c503
1.1.1.2 root 703: 3Com 503 (Etherlink II) network card device driver. On @samp{ix86-at} enabled
704: by @samp{default}.
1.1 root 705:
706: @item --enable-3c509
1.1.1.2 root 707: 3Com 509/579 (Etherlink III) network card device driver. On @samp{ix86-at}
708: enabled by @samp{default}.
1.1 root 709:
1.1.1.2 root 710: @item --enable-wd
711: WD80X3 network card device driver. On @samp{ix86-at} enabled by
712: @samp{default}.
1.1 root 713:
714: @item --enable-3c501
1.1.1.2 root 715: 3COM 501/Etherlink I network card device driver. On @samp{ix86-at} enabled by
716: @samp{default}.
1.1 root 717:
1.1.1.2 root 718: @item --enable-smc-ultra
719: SMC Ultra network card device driver. On @samp{ix86-at} enabled by
720: @samp{default}.
721:
722: @item --enable-smc-ultra32
723: SMC Ultra 32 network card device driver. On @samp{ix86-at} enabled by
724: @samp{default}.
725:
726: @item --enable-hp-plus
727: HP PCLAN+ (27247B and 27252A) network card device driver. On @samp{ix86-at}
728: enabled by @samp{default}.
729:
730: @item --enable-hp
731: HP PCLAN (27245 and other 27xxx series) network card device driver. On
732: @samp{ix86-at} enabled by @samp{default}.
1.1 root 733:
734: @item --enable-3c59x
1.1.1.2 root 735: 3Com 590/900 series (592/595/597/900/905) "Vortex/Boomerang" network card
736: device driver. On @samp{ix86-at} enabled by @samp{default}.
1.1 root 737:
738: @item --enable-seeq8005
1.1.1.2 root 739: Seeq8005 network card device driver. On @samp{ix86-at} enabled by
740: @samp{default}.
1.1 root 741:
742: @item --enable-hp100
1.1.1.2 root 743: HP 10/100VG PCLAN (ISA, EISA, PCI) network card device driver. On
744: @samp{ix86-at} enabled by @samp{default}.
1.1 root 745:
746: @item --enable-ac3200
1.1.1.2 root 747: Ansel Communications EISA 3200 network card device driver. On @samp{ix86-at}
748: enabled by @samp{default}.
1.1 root 749:
750: @item --enable-e2100
1.1.1.2 root 751: Cabletron E21xx network card device driver. On @samp{ix86-at} enabled by
752: @samp{default}.
1.1 root 753:
754: @item --enable-at1700
1.1.1.2 root 755: AT1700 (Fujitsu 86965) network card device driver. On @samp{ix86-at} enabled
756: by @samp{default}.
1.1 root 757:
758: @item --enable-eth16i
1.1.1.2 root 759: ICL EtherTeam 16i/32 network card device driver. On @samp{ix86-at} enabled by
760: @samp{default}.
1.1 root 761:
762: @item --enable-znet
1.1.1.2 root 763: Zenith Z-Note network card device driver. On @samp{ix86-at} enabled by
764: @samp{default}.
1.1 root 765:
766: @item --enable-eexpress
1.1.1.2 root 767: EtherExpress 16 network card device driver. On @samp{ix86-at} enabled by
768: @samp{default}.
1.1 root 769:
1.1.1.2 root 770: @item --enable-eepro
771: EtherExpressPro network card device driver. On @samp{ix86-at} enabled by
772: @samp{default}.
773:
774: @item --enable-eepro100
775: Intel EtherExpressPro PCI 10+/100B/100+ network card device driver. On
776: @samp{ix86-at} enabled by @samp{default}.
1.1 root 777:
778: @item --enable-depca
1.1.1.2 root 779: DEPCA, DE10x, DE200, DE201, DE202, DE210, DE422 network card device driver. On
780: @samp{ix86-at} enabled by @samp{default}.
1.1 root 781:
782: @item --enable-ewrk3
1.1.1.2 root 783: EtherWORKS 3 (DE203, DE204, DE205) network card device driver. On
784: @samp{ix86-at} enabled by @samp{default}.
1.1 root 785:
786: @item --enable-de4x5
1.1.1.2 root 787: DE425, DE434, DE435, DE450, DE500 network card device driver. On
788: @samp{ix86-at} enabled by @samp{default}.
1.1 root 789:
790: @item --enable-apricot
1.1.1.2 root 791: Apricot XEN-II on board ethernet network card device driver. On @samp{ix86-at}
792: enabled by @samp{default}.
1.1 root 793:
794: @item --enable-wavelan
1.1.1.2 root 795: AT&T WaveLAN & DEC RoamAbout DS network card device driver.
1.1 root 796:
797: @item --enable-3c507
1.1.1.2 root 798: 3Com 507 network card device driver. On @samp{ix86-at} enabled by
799: @samp{default}.
1.1 root 800:
801: @item --enable-3c505
1.1.1.2 root 802: 3Com 505/Etherlink II network card device driver. On @samp{ix86-at} enabled by
803: @samp{default}.
1.1 root 804:
805: @item --enable-de600
1.1.1.2 root 806: D-Link DE-600 network card device driver. On @samp{ix86-at} enabled by
807: @samp{default}.
1.1 root 808:
809: @item --enable-de620
1.1.1.2 root 810: D-Link DE-620 network card device driver. On @samp{ix86-at} enabled by
811: @samp{default}.
1.1 root 812:
1.1.1.2 root 813: @item --enable-sk_g16
814: Schneider & Koch G16 network card device driver. On @samp{ix86-at} enabled by
815: @samp{default}.
1.1 root 816:
817: @item --enable-ni52
1.1.1.2 root 818: NI5210 network card device driver. On @samp{ix86-at} enabled by
819: @samp{default}.
1.1 root 820:
821: @item --enable-ni65
1.1.1.2 root 822: NI6510 network card device driver. On @samp{ix86-at} enabled by
823: @samp{default}.
1.1 root 824:
825: @item --enable-atp
1.1.1.2 root 826: AT-LAN-TEC/RealTek pocket adaptor network card device driver for the
827: @samp{atp%d} devices.
1.1 root 828:
829: @item --enable-lance
1.1.1.2 root 830: AMD LANCE and PCnet (AT1500 and NE2100) network card device driver. On
831: @samp{ix86-at} enabled by @samp{default}.
832:
833: @item --enable-tulip
834: DECchip Tulip (dc21x4x) PCI network card device driver. On @samp{ix86-at}
835: enabled by @samp{default}.
1.1 root 836:
837: @item --enable-fmv18x
1.1.1.2 root 838: FMV-181/182/183/184 network card device driver. On @samp{ix86-at} enabled by
839: @samp{default}.
1.1 root 840:
841: @item --enable-3c515
1.1.1.2 root 842: 3Com 515 ISA Fast EtherLink network card device driver. On @samp{ix86-at}
843: enabled by @samp{default}.
1.1 root 844:
845: @item --enable-pcnet32
1.1.1.2 root 846: AMD PCI PCnet32 (PCI bus NE2100 cards) network card device driver. On
847: @samp{ix86-at} enabled by @samp{default}.
1.1 root 848:
1.1.1.2 root 849: @item --enable-ne2k-pci
850: PCI NE2000 network card device driver. On @samp{ix86-at} enabled by
851: @samp{default}.
1.1 root 852:
853: @item --enable-yellowfin
1.1.1.2 root 854: Packet Engines Yellowfin Gigabit-NIC network card device driver. On
855: @samp{ix86-at} enabled by @samp{default}.
1.1 root 856:
857: @item --enable-rtl8139
1.1.1.2 root 858: RealTek 8129/8139 (not 8019/8029!) network card device driver. On
859: @samp{ix86-at} enabled by @samp{default}.
860:
861: @item --enable-epic100
862: SMC 83c170/175 EPIC/100 (EtherPower II) network card device driver. On
863: @samp{ix86-at} enabled by @samp{default}.
1.1 root 864:
865: @item --enable-tlan
1.1.1.2 root 866: TI ThunderLAN network card device driver. On @samp{ix86-at} enabled by
867: @samp{default}.
868:
869: @item --enable-via-rhine
870: VIA Rhine network card device driver. On @samp{ix86-at} enabled by
871: @samp{default}.
872:
873: @item --enable-hamachi
874: Packet Engines "Hamachi" GNIC-2 Gigabit Ethernet device driver. On
875: @samp{ix86-at} enabled by @samp{default}.
876:
877: @item --enable-intel-gige
878: Intel PCI Gigabit Ethernet device driver. On @samp{ix86-at} enabled by
879: @samp{default}.
880:
881: @item --enable-myson803
882: Myson MTD803 Ethernet adapter series device driver. On @samp{ix86-at} enabled
883: by @samp{default}.
884:
885: @item --enable-natsemi
886: National Semiconductor DP8381x series PCI Ethernet device driver. On
887: @samp{ix86-at} enabled by @samp{default}.
1.1 root 888:
1.1.1.2 root 889: @item --enable-ns820
890: National Semiconductor DP8382x series PCI Ethernet device driver. On
891: @samp{ix86-at} enabled by @samp{default}.
892:
893: @item --enable-starfire
894: Adaptec Starfire network adapter device driver. On @samp{ix86-at} enabled by
895: @samp{default}.
896:
897: @item --enable-sundance
898: Sundance ST201 "Alta" PCI Ethernet device driver. On @samp{ix86-at} enabled by
899: @samp{default}.
900:
901: @item --enable-winbond-840
902: Winbond W89c840 PCI Ethernet device driver. On @samp{ix86-at} enabled by
903: @samp{default}.
904: @end table
905:
906: The following options either control device drivers for supported PCMCIA
907: bridges or control the overall behaviour of the GNU Mach PCMCIA core. To make
908: use of GNU Mach PCMCIA support you need to have the corresponding userland
909: applications (GNU Mach Card Services) installed.
910:
911: @table @code
912: @item --enable-i82365
913: Device driver for the Intel 82365 and compatible PC Card controllers, and
914: Yenta-compatible PCI-to-CardBus controllers. On @samp{ix86-at} enabled by
915: @samp{default}.
916:
917: @item --enable-pcmcia-isa
918: ISA bus related bits in the GNU Mach PCMCIA core. Keeping it enabled is
919: generally a good idea, since it does not only have effect if your PC Card
920: bridge is attached to the ISA bus, but provides more (ISA) interrupts to the
921: Card Services for it to assign to the cards in turn. On @samp{ix86-at} enabled
922: by @samp{default}.
923: @end table
924:
925: The following options control device drivers for supported PCMCIA Ethernet
926: controllers. NIC devices are usually named @samp{eth%d}.
927:
928: @table @code
929: @item --enable-3c574_cs
930: PCMCIA ethernet driver for the 3Com 3c574 ``RoadRunner''. On @samp{ix86-at}
931: enabled by @samp{default}.
932:
933: @item --enable-3c589_cs
934: Driver for the 3Com 3c589 PCMCIA card. On @samp{ix86-at} enabled by
935: @samp{default}.
936:
937: @item --enable-axnet_cs
938: Driver for the Asix AX88190-based PCMCIA cards. On @samp{ix86-at} enabled by
939: @samp{default}.
940:
941: @item --enable-fmvj18x_cs
942: Driver for PCMCIA cards with the fmvj18x chipset. On @samp{ix86-at} enabled by
943: @samp{default}.
944:
945: @item --enable-nmclan_cs
946: Driver for the New Media Ethernet LAN PCMCIA cards. On @samp{ix86-at} enabled
947: by @samp{default}.
948:
949: @item --enable-pcnet_cs
950: Driver for NS8390-based PCMCIA cards. This driver supports the D-Link DE-650
951: and Linksys EthernetCard cards, the newer D-Link and Linksys combo cards,
952: Accton EN2212 cards, the RPTI EP400, and the PreMax PE-200 in non-shared-memory
953: mode, and the IBM Credit Card Adapter, the NE4100, the Thomas Conrad ethernet
954: card, and the Kingston KNE-PCM/x in shared-memory mode. It will also handle
955: the Socket EA card in either mode. On @samp{ix86-at} enabled by
956: @samp{default}.
957:
958: @item --enable-smc91c92_cs
959: Driver for SMC91c92-based PCMCIA cards. On @samp{ix86-at} enabled by
960: @samp{default}.
961:
962: @item --enable-xirc2ps_cs
963: Driver for Xircom CreditCard and Realport PCMCIA ethernet adapters. On
964: @samp{ix86-at} enabled by @samp{default}.
965: @end table
966:
967: The following options control device drivers for supported PCMCIA Wireless LAN
968: network controllers. NIC devices are usually named @samp{eth%d}.
969:
970: Please mind, that you need to have some userland applications (the GNU Mach
971: Wireless Tools) installed, in order to make use of these devices.
972:
973: @table @code
974: @item --enable-orinoco_cs
975: Driver for the Hermes or Prism 2 chipset based PCMCIA wireless adapters, with
976: Lucent/Agere, Intersil or Symbol firmware. This driver is suitable for PCMCIA
977: wireless adapters, such as the Lucent WavelanIEEE/Orinoco cards and their OEM
978: (Cabletron/EnteraSys RoamAbout 802.11, ELSA Airlancer, Melco Buffalo and
979: others). It should also be usable on various Prism II based cards such as the
980: Linksys, D-Link and Farallon Skyline. It should also work on Symbol cards such
981: as the 3Com AirConnect and Ericsson WLAN. On @samp{ix86-at} enabled by
982: @samp{default}.
1.1 root 983: @end table
984:
985:
986: @node Cross-Compilation
987: @section Cross-Compilation
988:
989: Another way to install the kernel is to use an existing operating system
990: in order to compile the kernel binary.
991: This is called @dfn{cross-compiling}, because it is done between two
992: different platforms. If the pre-built kernels are not working for
993: you, and you can't ask someone to compile a custom kernel for your
994: machine, this is your last chance to get a kernel that boots on your
995: hardware.
996:
997: Luckily, the kernel does have light dependencies. You don't even
998: need a cross compiler if your build machine has a compiler and is
999: the same architecture as the system you want to run GNU Mach on.
1000:
1001: You need a cross-mig, though.
1002:
1003: XXX More info needed.
1004:
1005:
1006: @node Bootstrap
1007: @chapter Bootstrap
1008:
1009: Bootstrapping@footnote{The term @dfn{bootstrapping} refers to a Dutch
1010: legend about a boy who was able to fly by pulling himself up by his
1011: bootstraps. In computers, this term refers to any process where a
1012: simple system activates a more complicated system.} is the procedure by
1013: which your machine loads the microkernel and transfers control to the
1014: operating system.
1015:
1016:
1017: @menu
1018: * Bootloader:: Starting the microkernel, or other OSes.
1019: * Modules:: Starting the first task of the OS.
1020: @end menu
1021:
1022: @node Bootloader
1023: @section Bootloader
1024:
1025: The @dfn{bootloader} is the first software that runs on your machine.
1026: Many hardware architectures have a very simple startup routine which
1027: reads a very simple bootloader from the beginning of the internal hard
1028: disk, then transfers control to it. Other architectures have startup
1029: routines which are able to understand more of the contents of the hard
1030: disk, and directly start a more advanced bootloader.
1031:
1032: @cindex GRUB
1033: @cindex GRand Unified Bootloader
1.1.1.2 root 1034: @dfn{GRUB}@footnote{The GRand Unified Bootloader, available
1035: from @uref{http://gnu.org/software/grub/}.} is the GNU bootloader.
1.1 root 1036: GRUB provides advanced functionality, and is capable of loading several
1037: different kernels (such as Mach, Linux, DOS, and the *BSD family).
1038: @xref{Top, , Introduction, grub, GRUB Manual}.
1039:
1040: GNU Mach conforms to the Multiboot specification which defines an
1041: interface between the bootloader and the components that run very early
1042: at startup. GNU Mach can be started by any bootloader which supports
1043: the multiboot standard. After the bootloader loaded the kernel image to
1044: a designated address in the system memory, it jumps into the startup
1045: code of the kernel. This code initializes the kernel and detects the
1046: available hardware devices. Afterwards, the first system task is
1047: started. @xref{Top, , Overview, multiboot, Multiboot Specification}.
1048:
1049:
1050: @node Modules
1051: @section Modules
1052: @pindex serverboot
1053:
1.1.1.2 root 1054: This is outdated.
1055:
1.1 root 1056: Because the microkernel does not provide filesystem support and other
1057: features necessary to load the first system task from a storage medium,
1058: the first task is loaded by the bootloader as a module to a specified
1059: address. In the GNU system, this first program is the @code{serverboot}
1060: executable. GNU Mach inserts the host control port and the device
1061: master port into this task and appends the port numbers to the command
1062: line before executing it.
1063:
1064: The @code{serverboot} program is responsible for loading and executing
1065: the rest of the Hurd servers. Rather than containing specific
1066: instructions for starting the Hurd, it follows general steps given in a
1067: user-supplied boot script.
1068:
1069: XXX More about boot scripts.
1070:
1071:
1072: @node Inter Process Communication
1073: @chapter Inter Process Communication
1074:
1075: This chapter describes the details of the Mach IPC system. First the
1076: actual calls concerned with sending and receiving messages are
1077: discussed, then the details of the port system are described in detail.
1078:
1079: @menu
1080: * Major Concepts:: The concepts behind the Mach IPC system.
1081: * Messaging Interface:: Composing, sending and receiving messages.
1082: * Port Manipulation Interface:: Manipulating ports, port rights, port sets.
1083: @end menu
1084:
1085:
1086: @node Major Concepts
1087: @section Major Concepts
1088: @cindex interprocess communication (IPC)
1089: @cindex IPC (interprocess communication)
1090: @cindex communication between tasks
1091: @cindex remote procedure calls (RPC)
1092: @cindex RPC (remote procedure calls)
1093: @cindex messages
1094:
1095: The Mach kernel provides message-oriented, capability-based interprocess
1096: communication. The interprocess communication (IPC) primitives
1097: efficiently support many different styles of interaction, including
1098: remote procedure calls (RPC), object-oriented distributed programming,
1099: streaming of data, and sending very large amounts of data.
1100:
1101: The IPC primitives operate on three abstractions: messages, ports, and
1102: port sets. User tasks access all other kernel services and abstractions
1103: via the IPC primitives.
1104:
1105: The message primitives let tasks send and receive messages. Tasks send
1106: messages to ports. Messages sent to a port are delivered reliably
1107: (messages may not be lost) and are received in the order in which they
1108: were sent. Messages contain a fixed-size header and a variable amount
1109: of typed data following the header. The header describes the
1110: destination and size of the message.
1111:
1112: The IPC implementation makes use of the VM system to efficiently
1113: transfer large amounts of data. The message body can contain the
1114: address of a region in the sender's address space which should be
1115: transferred as part of the message. When a task receives a message
1116: containing an out-of-line region of data, the data appears in an unused
1117: portion of the receiver's address space. This transmission of
1118: out-of-line data is optimized so that sender and receiver share the
1119: physical pages of data copy-on-write, and no actual data copy occurs
1120: unless the pages are written. Regions of memory up to the size of a
1121: full address space may be sent in this manner.
1122:
1123: Ports hold a queue of messages. Tasks operate on a port to send and
1124: receive messages by exercising capabilities for the port. Multiple
1125: tasks can hold send capabilities, or rights, for a port. Tasks can also
1126: hold send-once rights, which grant the ability to send a single message.
1127: Only one task can hold the receive capability, or receive right, for a
1128: port. Port rights can be transferred between tasks via messages. The
1129: sender of a message can specify in the message body that the message
1130: contains a port right. If a message contains a receive right for a
1131: port, then the receive right is removed from the sender of the message
1132: and the right is transferred to the receiver of the message. While the
1133: receive right is in transit, tasks holding send rights can still send
1134: messages to the port, and they are queued until a task acquires the
1135: receive right and uses it to receive the messages.
1136:
1137: Tasks can receive messages from ports and port sets. The port set
1138: abstraction allows a single thread to wait for a message from any of
1139: several ports. Tasks manipulate port sets with a capability, or
1140: port-set right, which is taken from the same space as the port
1141: capabilities. The port-set right may not be transferred in a message.
1142: A port set holds receive rights, and a receive operation on a port set
1143: blocks waiting for a message sent to any of the constituent ports. A
1144: port may not belong to more than one port set, and if a port is a member
1145: of a port set, the holder of the receive right can't receive directly
1146: from the port.
1147:
1148: Port rights are a secure, location-independent way of naming ports. The
1149: port queue is a protected data structure, only accessible via the
1150: kernel's exported message primitives. Rights are also protected by the
1151: kernel; there is no way for a malicious user task to guess a port name
1152: and send a message to a port to which it shouldn't have access. Port
1153: rights do not carry any location information. When a receive right for
1154: a port moves from task to task, and even between tasks on different
1155: machines, the send rights for the port remain unchanged and continue to
1156: function.
1157:
1158: @node Messaging Interface
1159: @section Messaging Interface
1160:
1161: This section describes how messages are composed, sent and received
1162: within the Mach IPC system.
1163:
1164: @menu
1165: * Mach Message Call:: Sending and receiving messages.
1166: * Message Format:: The format of Mach messages.
1167: * Exchanging Port Rights:: Sending and receiving port rights.
1168: * Memory:: Passing memory regions in messages.
1169: * Message Send:: Sending messages.
1170: * Message Receive:: Receiving messages.
1171: * Atomicity:: Atomicity of port rights.
1172: @end menu
1173:
1174:
1175: @node Mach Message Call
1176: @subsection Mach Message Call
1177:
1178: To use the @code{mach_msg} call, you can include the header files
1179: @file{mach/port.h} and @file{mach/message.h}.
1180:
1181: @deftypefun mach_msg_return_t mach_msg (@w{mach_msg_header_t *@var{msg}}, @w{mach_msg_option_t @var{option}}, @w{mach_msg_size_t @var{send_size}}, @w{mach_msg_size_t @var{rcv_size}}, @w{mach_port_t @var{rcv_name}}, @w{mach_msg_timeout_t @var{timeout}}, @w{mach_port_t @var{notify}})
1182: The @code{mach_msg} function is used to send and receive messages. Mach
1183: messages contain typed data, which can include port rights and
1184: references to large regions of memory.
1185:
1186: @var{msg} is the address of a buffer in the caller's address space.
1187: Message buffers should be aligned on long-word boundaries. The message
1188: options @var{option} are bit values, combined with bitwise-or. One or
1189: both of @code{MACH_SEND_MSG} and @code{MACH_RCV_MSG} should be used.
1190: Other options act as modifiers. When sending a message, @var{send_size}
1191: specifies the size of the message buffer. Otherwise zero should be
1192: supplied. When receiving a message, @var{rcv_size} specifies the size
1193: of the message buffer. Otherwise zero should be supplied. When
1194: receiving a message, @var{rcv_name} specifies the port or port set.
1195: Otherwise @code{MACH_PORT_NULL} should be supplied. When using the
1196: @code{MACH_SEND_TIMEOUT} and @code{MACH_RCV_TIMEOUT} options,
1197: @var{timeout} specifies the time in milliseconds to wait before giving
1198: up. Otherwise @code{MACH_MSG_TIMEOUT_NONE} should be supplied. When
1199: using the @code{MACH_SEND_NOTIFY}, @code{MACH_SEND_CANCEL}, and
1200: @code{MACH_RCV_NOTIFY} options, @var{notify} specifies the port used for
1201: the notification. Otherwise @code{MACH_PORT_NULL} should be supplied.
1202:
1203: If the option argument is @code{MACH_SEND_MSG}, it sends a message. The
1204: @var{send_size} argument specifies the size of the message to send. The
1205: @code{msgh_remote_port} field of the message header specifies the
1206: destination of the message.
1207:
1208: If the option argument is @code{MACH_RCV_MSG}, it receives a message.
1209: The @var{rcv_size} argument specifies the size of the message buffer
1210: that will receive the message; messages larger than @var{rcv_size} are
1211: not received. The @var{rcv_name} argument specifies the port or port
1212: set from which to receive.
1213:
1214: If the option argument is @code{MACH_SEND_MSG|MACH_RCV_MSG}, then
1215: @code{mach_msg} does both send and receive operations. If the send
1216: operation encounters an error (any return code other than
1217: @code{MACH_MSG_SUCCESS}), then the call returns immediately without
1218: attempting the receive operation. Semantically the combined call is
1219: equivalent to separate send and receive calls, but it saves a system
1220: call and enables other internal optimizations.
1221:
1222: If the option argument specifies neither @code{MACH_SEND_MSG} nor
1223: @code{MACH_RCV_MSG}, then @code{mach_msg} does nothing.
1224:
1225: Some options, like @code{MACH_SEND_TIMEOUT} and @code{MACH_RCV_TIMEOUT},
1226: share a supporting argument. If these options are used together, they
1227: make independent use of the supporting argument's value.
1228: @end deftypefun
1229:
1230: @deftp {Data type} mach_msg_timeout_t
1231: This is a @code{natural_t} used by the timeout mechanism. The units are
1232: milliseconds. The value to be used when there is no timeout is
1233: @code{MACH_MSG_TIMEOUT_NONE}.
1234: @end deftp
1235:
1236:
1237: @node Message Format
1238: @subsection Message Format
1239: @cindex message format
1240: @cindex format of a message
1241: @cindex composing messages
1242: @cindex message composition
1243:
1244: A Mach message consists of a fixed size message header, a
1245: @code{mach_msg_header_t}, followed by zero or more data items. Data
1246: items are typed. Each item has a type descriptor followed by the actual
1247: data (or the address of the data, for out-of-line memory regions).
1248:
1249: The following data types are related to Mach ports:
1250:
1251: @deftp {Data type} mach_port_t
1252: The @code{mach_port_t} data type is an unsigned integer type which
1253: represents a port name in the task's port name space. In GNU Mach, this
1254: is an @code{unsigned int}.
1255: @end deftp
1256:
1257: @c This is defined elsewhere.
1258: @c @deftp {Data type} mach_port_seqno_t
1259: @c The @code{mach_port_seqno_t} data type is an unsigned integer type which
1260: @c represents a sequence number of a message. In GNU Mach, this is an
1261: @c @code{unsigned int}.
1262: @c @end deftp
1263:
1264: The following data types are related to Mach messages:
1265:
1266: @deftp {Data type} mach_msg_bits_t
1267: The @code{mach_msg_bits_t} data type is an @code{unsigned int} used to
1268: store various flags for a message.
1269: @end deftp
1270:
1271: @deftp {Data type} mach_msg_size_t
1272: The @code{mach_msg_size_t} data type is an @code{unsigned int} used to
1273: store the size of a message.
1274: @end deftp
1275:
1276: @deftp {Data type} mach_msg_id_t
1277: The @code{mach_msg_id_t} data type is an @code{integer_t} typically used to
1278: convey a function or operation id for the receiver.
1279: @end deftp
1280:
1281: @deftp {Data type} mach_msg_header_t
1282: This structure is the start of every message in the Mach IPC system. It
1283: has the following members:
1284:
1285: @table @code
1286: @item mach_msg_bits_t msgh_bits
1287: The @code{msgh_bits} field has the following bits defined, all other
1288: bits should be zero:
1289:
1290: @table @code
1291: @item MACH_MSGH_BITS_REMOTE_MASK
1292: @itemx MACH_MSGH_BITS_LOCAL_MASK
1293: The remote and local bits encode @code{mach_msg_type_name_t} values that
1294: specify the port rights in the @code{msgh_remote_port} and
1295: @code{msgh_local_port} fields. The remote value must specify a send or
1296: send-once right for the destination of the message. If the local value
1297: doesn't specify a send or send-once right for the message's reply port,
1298: it must be zero and msgh_local_port must be @code{MACH_PORT_NULL}.
1299:
1300: @item MACH_MSGH_BITS_COMPLEX
1301: The complex bit must be specified if the message body contains port
1302: rights or out-of-line memory regions. If it is not specified, then the
1303: message body carries no port rights or memory, no matter what the type
1304: descriptors may seem to indicate.
1305: @end table
1306:
1307: @code{MACH_MSGH_BITS_REMOTE} and @code{MACH_MSGH_BITS_LOCAL} macros
1308: return the appropriate @code{mach_msg_type_name_t} values, given a
1309: @code{msgh_bits} value. The @code{MACH_MSGH_BITS} macro constructs a
1310: value for @code{msgh_bits}, given two @code{mach_msg_type_name_t}
1311: values.
1312:
1313: @item mach_msg_size_t msgh_size
1314: The @code{msgh_size} field in the header of a received message contains
1315: the message's size. The message size, a byte quantity, includes the
1316: message header, type descriptors, and in-line data. For out-of-line
1317: memory regions, the message size includes the size of the in-line
1318: address, not the size of the actual memory region. There are no
1319: arbitrary limits on the size of a Mach message, the number of data items
1320: in a message, or the size of the data items.
1321:
1322: @item mach_port_t msgh_remote_port
1323: The @code{msgh_remote_port} field specifies the destination port of the
1324: message. The field must carry a legitimate send or send-once right for
1325: a port.
1326:
1327: @item mach_port_t msgh_local_port
1328: The @code{msgh_local_port} field specifies an auxiliary port right,
1329: which is conventionally used as a reply port by the recipient of the
1330: message. The field must carry a send right, a send-once right,
1331: @code{MACH_PORT_NULL}, or @code{MACH_PORT_DEAD}.
1332:
1.1.1.3 root 1333: @item unsigned long msgh_protected_payload
1334: The @code{msgh_protected_payload} field carries a payload that is set
1335: by the kernel during message delivery. The payload is an opaque
1336: identifier that can be used by the receiver to lookup the associated
1337: data structure.
1338:
1339: It is only valid in received messages. See @ref{Message Receive} for
1340: further information.
1341:
1.1 root 1342: @item mach_port_seqno_t msgh_seqno
1343: The @code{msgh_seqno} field provides a sequence number for the message.
1344: It is only valid in received messages; its value in sent messages is
1345: overwritten.
1346: @c XXX The "MESSAGE RECEIVE" section discusses message sequence numbers.
1347:
1348: @item mach_msg_id_t msgh_id
1349: The @code{mach_msg} call doesn't use the @code{msgh_id} field, but it
1350: conventionally conveys an operation or function id.
1351: @end table
1352: @end deftp
1353:
1354: @deftypefn Macro mach_msg_bits_t MACH_MSGH_BITS (@w{mach_msg_type_name_t @var{remote}}, @w{mach_msg_type_name_t @var{local}})
1355: This macro composes two @code{mach_msg_type_name_t} values that specify
1356: the port rights in the @code{msgh_remote_port} and
1357: @code{msgh_local_port} fields of a @code{mach_msg} call into an
1358: appropriate @code{mach_msg_bits_t} value.
1359: @end deftypefn
1360:
1361: @deftypefn Macro mach_msg_type_name_t MACH_MSGH_BITS_REMOTE (@w{mach_msg_bits_t @var{bits}})
1362: This macro extracts the @code{mach_msg_type_name_t} value for the remote
1363: port right in a @code{mach_msg_bits_t} value.
1364: @end deftypefn
1365:
1366: @deftypefn Macro mach_msg_type_name_t MACH_MSGH_BITS_LOCAL (@w{mach_msg_bits_t @var{bits}})
1367: This macro extracts the @code{mach_msg_type_name_t} value for the local
1368: port right in a @code{mach_msg_bits_t} value.
1369: @end deftypefn
1370:
1371: @deftypefn Macro mach_msg_bits_t MACH_MSGH_BITS_PORTS (@w{mach_msg_bits_t @var{bits}})
1372: This macro extracts the @code{mach_msg_bits_t} component consisting of
1373: the @code{mach_msg_type_name_t} values for the remote and local port
1374: right in a @code{mach_msg_bits_t} value.
1375: @end deftypefn
1376:
1377: @deftypefn Macro mach_msg_bits_t MACH_MSGH_BITS_OTHER (@w{mach_msg_bits_t @var{bits}})
1378: This macro extracts the @code{mach_msg_bits_t} component consisting of
1379: everything except the @code{mach_msg_type_name_t} values for the remote
1380: and local port right in a @code{mach_msg_bits_t} value.
1381: @end deftypefn
1382:
1383: Each data item has a type descriptor, a @code{mach_msg_type_t} or a
1384: @code{mach_msg_type_long_t}. The @code{mach_msg_type_long_t} type
1385: descriptor allows larger values for some fields. The
1386: @code{msgtl_header} field in the long descriptor is only used for its
1387: inline, longform, and deallocate bits.
1388:
1389: @deftp {Data type} mach_msg_type_name_t
1390: This is an @code{unsigned int} and can be used to hold the
1391: @code{msgt_name} component of the @code{mach_msg_type_t} and
1392: @code{mach_msg_type_long_t} structure.
1393: @end deftp
1394:
1395: @deftp {Data type} mach_msg_type_size_t
1396: This is an @code{unsigned int} and can be used to hold the
1397: @code{msgt_size} component of the @code{mach_msg_type_t} and
1398: @code{mach_msg_type_long_t} structure.
1399: @end deftp
1400:
1401: @deftp {Data type} mach_msg_type_number_t
1402: This is an @code{natural_t} and can be used to hold the
1403: @code{msgt_number} component of the @code{mach_msg_type_t} and
1404: @code{mach_msg_type_long_t} structure.
1405: @c XXX This is used for the size of arrays, too. Mmh?
1406: @end deftp
1407:
1408: @deftp {Data type} mach_msg_type_t
1409: This structure has the following members:
1410:
1411: @table @code
1412: @item unsigned int msgt_name : 8
1413: The @code{msgt_name} field specifies the data's type. The following
1414: types are predefined:
1415:
1416: @table @code
1417: @item MACH_MSG_TYPE_UNSTRUCTURED
1418: @item MACH_MSG_TYPE_BIT
1419: @item MACH_MSG_TYPE_BOOLEAN
1420: @item MACH_MSG_TYPE_INTEGER_16
1421: @item MACH_MSG_TYPE_INTEGER_32
1422: @item MACH_MSG_TYPE_CHAR
1423: @item MACH_MSG_TYPE_BYTE
1424: @item MACH_MSG_TYPE_INTEGER_8
1425: @item MACH_MSG_TYPE_REAL
1426: @item MACH_MSG_TYPE_STRING
1427: @item MACH_MSG_TYPE_STRING_C
1428: @item MACH_MSG_TYPE_PORT_NAME
1.1.1.3 root 1429: @item MACH_MSG_TYPE_PROTECTED_PAYLOAD
1.1 root 1430: @end table
1431:
1432: The following predefined types specify port rights, and receive special
1433: treatment. The next section discusses these types in detail. The type
1434: @c XXX cross ref
1435: @code{MACH_MSG_TYPE_PORT_NAME} describes port right names, when no
1436: rights are being transferred, but just names. For this purpose, it
1437: should be used in preference to @code{MACH_MSG_TYPE_INTEGER_32}.
1438:
1439: @table @code
1440: @item MACH_MSG_TYPE_MOVE_RECEIVE
1441: @item MACH_MSG_TYPE_MOVE_SEND
1442: @item MACH_MSG_TYPE_MOVE_SEND_ONCE
1443: @item MACH_MSG_TYPE_COPY_SEND
1444: @item MACH_MSG_TYPE_MAKE_SEND
1445: @item MACH_MSG_TYPE_MAKE_SEND_ONCE
1446: @end table
1447:
1.1.1.3 root 1448: The type @code{MACH_MSG_TYPE_PROTECTED_PAYLOAD} is used by the kernel
1449: to indicate that a delivered message carries a payload in the
1450: @code{msgh_protected_payload} field. See @ref{Message Receive} for
1451: more information.
1452:
1.1 root 1453: @item msgt_size : 8
1454: The @code{msgt_size} field specifies the size of each datum, in bits. For
1455: example, the msgt_size of @code{MACH_MSG_TYPE_INTEGER_32} data is 32.
1456:
1457: @item msgt_number : 12
1458: The @code{msgt_number} field specifies how many data elements comprise
1459: the data item. Zero is a legitimate number.
1460:
1461: The total length specified by a type descriptor is @w{@code{(msgt_size *
1462: msgt_number)}}, rounded up to an integral number of bytes. In-line data
1463: is then padded to an integral number of long-words. This ensures that
1464: type descriptors always start on long-word boundaries. It implies that
1465: message sizes are always an integral multiple of a long-word's size.
1466:
1467: @item msgt_inline : 1
1468: The @code{msgt_inline} bit specifies, when @code{FALSE}, that the data
1469: actually resides in an out-of-line region. The address of the memory
1470: region (a @code{vm_offset_t} or @code{vm_address_t}) follows the type
1471: descriptor in the message body. The @code{msgt_name}, @code{msgt_size},
1472: and @code{msgt_number} fields describe the memory region, not the
1473: address.
1474:
1475: @item msgt_longform : 1
1476: The @code{msgt_longform} bit specifies, when @code{TRUE}, that this type
1477: descriptor is a @code{mach_msg_type_long_t} instead of a
1478: @code{mach_msg_type_t}. The @code{msgt_name}, @code{msgt_size}, and
1479: @code{msgt_number} fields should be zero. Instead, @code{mach_msg} uses
1480: the following @code{msgtl_name}, @code{msgtl_size}, and
1481: @code{msgtl_number} fields.
1482:
1483: @item msgt_deallocate : 1
1484: The @code{msgt_deallocate} bit is used with out-of-line regions. When
1485: @code{TRUE}, it specifies that the memory region should be deallocated
1486: from the sender's address space (as if with @code{vm_deallocate}) when
1487: the message is sent.
1488:
1489: @item msgt_unused : 1
1490: The @code{msgt_unused} bit should be zero.
1491: @end table
1492: @end deftp
1493:
1494: @deftypefn Macro boolean_t MACH_MSG_TYPE_PORT_ANY (mach_msg_type_name_t type)
1495: This macro returns @code{TRUE} if the given type name specifies a port
1496: type, otherwise it returns @code{FALSE}.
1497: @end deftypefn
1498:
1499: @deftypefn Macro boolean_t MACH_MSG_TYPE_PORT_ANY_SEND (mach_msg_type_name_t type)
1500: This macro returns @code{TRUE} if the given type name specifies a port
1501: type with a send or send-once right, otherwise it returns @code{FALSE}.
1502: @end deftypefn
1503:
1504: @deftypefn Macro boolean_t MACH_MSG_TYPE_PORT_ANY_RIGHT (mach_msg_type_name_t type)
1505: This macro returns @code{TRUE} if the given type name specifies a port
1506: right type which is moved, otherwise it returns @code{FALSE}.
1507: @end deftypefn
1508:
1509: @deftp {Data type} mach_msg_type_long_t
1510: This structure has the following members:
1511:
1512: @table @code
1513: @item mach_msg_type_t msgtl_header
1514: Same meaning as @code{msgt_header}.
1515: @c XXX cross ref
1516:
1517: @item unsigned short msgtl_name
1518: Same meaning as @code{msgt_name}.
1519:
1520: @item unsigned short msgtl_size
1521: Same meaning as @code{msgt_size}.
1522:
1523: @item unsigned int msgtl_number
1524: Same meaning as @code{msgt_number}.
1525: @end table
1526: @end deftp
1527:
1528:
1529: @node Exchanging Port Rights
1530: @subsection Exchanging Port Rights
1531: @cindex sending port rights
1532: @cindex receiving port rights
1533: @cindex moving port rights
1534:
1535: Each task has its own space of port rights. Port rights are named with
1536: positive integers. Except for the reserved values
1537: @w{@code{MACH_PORT_NULL (0)}@footnote{In the Hurd system, we don't make
1538: the assumption that @code{MACH_PORT_NULL} is zero and evaluates to
1539: false, but rather compare port names to @code{MACH_PORT_NULL}
1.1.1.2 root 1540: explicitly}} and @w{@code{MACH_PORT_DEAD (~0)}}, this is a full 32-bit
1.1 root 1541: name space. When the kernel chooses a name for a new right, it is free
1542: to pick any unused name (one which denotes no right) in the space.
1543:
1544: There are five basic kinds of rights: receive rights, send rights,
1545: send-once rights, port-set rights, and dead names. Dead names are not
1546: capabilities. They act as place-holders to prevent a name from being
1547: otherwise used.
1548:
1549: A port is destroyed, or dies, when its receive right is deallocated.
1550: When a port dies, send and send-once rights for the port turn into dead
1551: names. Any messages queued at the port are destroyed, which deallocates
1552: the port rights and out-of-line memory in the messages.
1553:
1554: Tasks may hold multiple user-references for send rights and dead names.
1555: When a task receives a send right which it already holds, the kernel
1556: increments the right's user-reference count. When a task deallocates a
1557: send right, the kernel decrements its user-reference count, and the task
1558: only loses the send right when the count goes to zero.
1559:
1560: Send-once rights always have a user-reference count of one, although a
1561: port can have multiple send-once rights, because each send-once right
1562: held by a task has a different name. In contrast, when a task holds
1563: send rights or a receive right for a port, the rights share a single
1564: name.
1565:
1566: A message body can carry port rights; the @code{msgt_name}
1567: (@code{msgtl_name}) field in a type descriptor specifies the type of
1568: port right and how the port right is to be extracted from the caller.
1569: The values @code{MACH_PORT_NULL} and @code{MACH_PORT_DEAD} are always
1570: valid in place of a port right in a message body. In a sent message,
1571: the following @code{msgt_name} values denote port rights:
1572:
1573: @table @code
1574: @item MACH_MSG_TYPE_MAKE_SEND
1575: The message will carry a send right, but the caller must supply a
1576: receive right. The send right is created from the receive right, and
1577: the receive right's make-send count is incremented.
1578:
1579: @item MACH_MSG_TYPE_COPY_SEND
1580: The message will carry a send right, and the caller should supply a send
1581: right. The user reference count for the supplied send right is not
1582: changed. The caller may also supply a dead name and the receiving task
1583: will get @code{MACH_PORT_DEAD}.
1584:
1585: @item MACH_MSG_TYPE_MOVE_SEND
1586: The message will carry a send right, and the caller should supply a send
1587: right. The user reference count for the supplied send right is
1588: decremented, and the right is destroyed if the count becomes zero.
1589: Unless a receive right remains, the name becomes available for
1590: recycling. The caller may also supply a dead name, which loses a user
1591: reference, and the receiving task will get @code{MACH_PORT_DEAD}.
1592:
1593: @item MACH_MSG_TYPE_MAKE_SEND_ONCE
1594: The message will carry a send-once right, but the caller must supply a
1595: receive right. The send-once right is created from the receive right.
1596:
1597: @item MACH_MSG_TYPE_MOVE_SEND_ONCE
1598: The message will carry a send-once right, and the caller should supply a
1599: send-once right. The caller loses the supplied send-once right. The
1600: caller may also supply a dead name, which loses a user reference, and
1601: the receiving task will get @code{MACH_PORT_DEAD}.
1602:
1603: @item MACH_MSG_TYPE_MOVE_RECEIVE
1604: The message will carry a receive right, and the caller should supply a
1605: receive right. The caller loses the supplied receive right, but retains
1606: any send rights with the same name.
1607: @end table
1608:
1609: If a message carries a send or send-once right, and the port dies while
1610: the message is in transit, then the receiving task will get
1611: @code{MACH_PORT_DEAD} instead of a right. The following
1612: @code{msgt_name} values in a received message indicate that it carries
1613: port rights:
1614:
1615: @table @code
1616: @item MACH_MSG_TYPE_PORT_SEND
1617: This name is an alias for @code{MACH_MSG_TYPE_MOVE_SEND}. The message
1618: carried a send right. If the receiving task already has send and/or
1619: receive rights for the port, then that name for the port will be reused.
1620: Otherwise, the new right will have a new name. If the task already has
1621: send rights, it gains a user reference for the right (unless this would
1622: cause the user-reference count to overflow). Otherwise, it acquires the
1623: send right, with a user-reference count of one.
1624:
1625: @item MACH_MSG_TYPE_PORT_SEND_ONCE
1626: This name is an alias for @code{MACH_MSG_TYPE_MOVE_SEND_ONCE}. The
1627: message carried a send-once right. The right will have a new name.
1628:
1629: @item MACH_MSG_TYPE_PORT_RECEIVE
1630: This name is an alias for @code{MACH_MSG_TYPE_MOVE_RECEIVE}. The
1631: message carried a receive right. If the receiving task already has send
1632: rights for the port, then that name for the port will be reused.
1633: Otherwise, the right will have a new name. The make-send count of the
1634: receive right is reset to zero, but the port retains other attributes
1635: like queued messages, extant send and send-once rights, and requests for
1636: port-destroyed and no-senders notifications.
1637: @end table
1638:
1639: When the kernel chooses a new name for a port right, it can choose any
1640: name, other than @code{MACH_PORT_NULL} and @code{MACH_PORT_DEAD}, which
1641: is not currently being used for a port right or dead name. It might
1642: choose a name which at some previous time denoted a port right, but is
1643: currently unused.
1644:
1645:
1646: @node Memory
1647: @subsection Memory
1648: @cindex sending memory
1649: @cindex receiving memory
1650:
1651: A message body can contain the address of a region in the sender's
1652: address space which should be transferred as part of the message. The
1653: message carries a logical copy of the memory, but the kernel uses VM
1654: techniques to defer any actual page copies. Unless the sender or the
1655: receiver modifies the data, the physical pages remain shared.
1656:
1657: An out-of-line transfer occurs when the data's type descriptor specifies
1658: @code{msgt_inline} as @code{FALSE}. The address of the memory region (a
1659: @code{vm_offset_t} or @code{vm_address_t}) should follow the type
1660: descriptor in the message body. The type descriptor and the address
1661: contribute to the message's size (@code{send_size}, @code{msgh_size}).
1662: The out-of-line data does not contribute to the message's size.
1663:
1664: The name, size, and number fields in the type descriptor describe the
1665: type and length of the out-of-line data, not the in-line address.
1666: Out-of-line memory frequently requires long type descriptors
1667: (@code{mach_msg_type_long_t}), because the @code{msgt_number} field is
1668: too small to describe a page of 4K bytes.
1669:
1670: Out-of-line memory arrives somewhere in the receiver's address space as
1671: new memory. It has the same inheritance and protection attributes as
1672: newly @code{vm_allocate}'d memory. The receiver has the responsibility
1673: of deallocating (with @code{vm_deallocate}) the memory when it is no
1674: longer needed. Security-conscious receivers should exercise caution
1675: when using out-of-line memory from untrustworthy sources, because the
1676: memory may be backed by an unreliable memory manager.
1677:
1678: Null out-of-line memory is legal. If the out-of-line region size is
1679: zero (for example, because @code{msgtl_number} is zero), then the
1680: region's specified address is ignored. A received null out-of-line
1681: memory region always has a zero address.
1682:
1683: Unaligned addresses and region sizes that are not page multiples are
1684: legal. A received message can also contain memory with unaligned
1685: addresses and funny sizes. In the general case, the first and last
1686: pages in the new memory region in the receiver do not contain only data
1687: from the sender, but are partly zero.@footnote{Sending out-of-line
1688: memory with a non-page-aligned address, or a size which is not a page
1689: multiple, works but with a caveat. The extra bytes in the first and
1690: last page of the received memory are not zeroed, so the receiver can
1691: peek at more data than the sender intended to transfer. This might be a
1692: security problem for the sender.} The received address points to the
1693: start of the data in the first page. This possibility doesn't
1694: complicate deallocation, because @code{vm_deallocate} does the right
1695: thing, rounding the start address down and the end address up to
1696: deallocate all arrived pages.
1697:
1698: Out-of-line memory has a deallocate option, controlled by the
1699: @code{msgt_deallocate} bit. If it is @code{TRUE} and the out-of-line
1700: memory region is not null, then the region is implicitly deallocated
1701: from the sender, as if by @code{vm_deallocate}. In particular, the
1702: start and end addresses are rounded so that every page overlapped by the
1703: memory region is deallocated. The use of @code{msgt_deallocate}
1704: effectively changes the memory copy into a memory movement. In a
1705: received message, @code{msgt_deallocate} is @code{TRUE} in type
1706: descriptors for out-of-line memory.
1707:
1708: Out-of-line memory can carry port rights.
1709:
1710:
1711: @node Message Send
1712: @subsection Message Send
1713: @cindex sending messages
1714:
1715: The send operation queues a message to a port. The message carries a
1716: copy of the caller's data. After the send, the caller can freely modify
1717: the message buffer or the out-of-line memory regions and the message
1718: contents will remain unchanged.
1719:
1720: Message delivery is reliable and sequenced. Messages are not lost, and
1721: messages sent to a port, from a single thread, are received in the order
1722: in which they were sent.
1723:
1724: If the destination port's queue is full, then several things can happen.
1725: If the message is sent to a send-once right (@code{msgh_remote_port}
1726: carries a send-once right), then the kernel ignores the queue limit and
1727: delivers the message. Otherwise the caller blocks until there is room
1728: in the queue, unless the @code{MACH_SEND_TIMEOUT} or
1729: @code{MACH_SEND_NOTIFY} options are used. If a port has several blocked
1730: senders, then any of them may queue the next message when space in the
1731: queue becomes available, with the proviso that a blocked sender will not
1732: be indefinitely starved.
1733:
1734: These options modify @code{MACH_SEND_MSG}. If @code{MACH_SEND_MSG} is
1735: not also specified, they are ignored.
1736:
1737: @table @code
1738: @item MACH_SEND_TIMEOUT
1739: The timeout argument should specify a maximum time (in milliseconds) for
1740: the call to block before giving up.@footnote{If MACH_SEND_TIMEOUT is
1741: used without MACH_SEND_INTERRUPT, then the timeout duration might not be
1742: accurate. When the call is interrupted and automatically retried, the
1743: original timeout is used. If interrupts occur frequently enough, the
1744: timeout interval might never expire.} If the message can't be queued
1745: before the timeout interval elapses, then the call returns
1746: @code{MACH_SEND_TIMED_OUT}. A zero timeout is legitimate.
1747:
1748: @item MACH_SEND_NOTIFY
1749: The notify argument should specify a receive right for a notify port.
1750: If the send were to block, then instead the message is queued,
1751: @code{MACH_SEND_WILL_NOTIFY} is returned, and a msg-accepted
1752: notification is requested. If @code{MACH_SEND_TIMEOUT} is also
1753: specified, then @code{MACH_SEND_NOTIFY} doesn't take effect until the
1754: timeout interval elapses.
1755:
1756: With @code{MACH_SEND_NOTIFY}, a task can forcibly queue to a send right
1.1.1.2 root 1757: one message at a time. A msg-accepted notification is sent to the
1.1 root 1758: notify port when another message can be forcibly queued. If an attempt
1759: is made to use @code{MACH_SEND_NOTIFY} before then, the call returns a
1760: @code{MACH_SEND_NOTIFY_IN_PROGRESS} error.
1761:
1762: The msg-accepted notification carries the name of the send right. If
1763: the send right is deallocated before the msg-accepted notification is
1764: generated, then the msg-accepted notification carries the value
1765: @code{MACH_PORT_NULL}. If the destination port is destroyed before the
1766: notification is generated, then a send-once notification is generated
1767: instead.
1768:
1769: @item MACH_SEND_INTERRUPT
1770: If specified, the @code{mach_msg} call will return
1771: @code{MACH_SEND_INTERRUPTED} if a software interrupt aborts the call.
1772: Otherwise, the send operation will be retried.
1773:
1774: @item MACH_SEND_CANCEL
1775: The notify argument should specify a receive right for a notify port.
1776: If the send operation removes the destination port right from the
1777: caller, and the removed right had a dead-name request registered for it,
1778: and notify is the notify port for the dead-name request, then the
1779: dead-name request may be silently canceled (instead of resulting in a
1780: port-deleted notification).
1781:
1782: This option is typically used to cancel a dead-name request made with
1783: the @code{MACH_RCV_NOTIFY} option. It should only be used as an optimization.
1784: @end table
1785:
1786: The send operation can generate the following return codes. These
1787: return codes imply that the call did nothing:
1788:
1789: @table @code
1790: @item MACH_SEND_MSG_TOO_SMALL
1791: The specified send_size was smaller than the minimum size for a message.
1792:
1793: @item MACH_SEND_NO_BUFFER
1794: A resource shortage prevented the kernel from allocating a message
1795: buffer.
1796:
1797: @item MACH_SEND_INVALID_DATA
1798: The supplied message buffer was not readable.
1799:
1800: @item MACH_SEND_INVALID_HEADER
1801: The @code{msgh_bits} value was invalid.
1802:
1803: @item MACH_SEND_INVALID_DEST
1804: The @code{msgh_remote_port} value was invalid.
1805:
1806: @item MACH_SEND_INVALID_REPLY
1807: The @code{msgh_local_port} value was invalid.
1808:
1809: @item MACH_SEND_INVALID_NOTIFY
1810: When using @code{MACH_SEND_CANCEL}, the notify argument did not denote a
1811: valid receive right.
1812: @end table
1813:
1814: These return codes imply that some or all of the message was destroyed:
1815:
1816: @table @code
1817: @item MACH_SEND_INVALID_MEMORY
1818: The message body specified out-of-line data that was not readable.
1819:
1820: @item MACH_SEND_INVALID_RIGHT
1821: The message body specified a port right which the caller didn't possess.
1822:
1823: @item MACH_SEND_INVALID_TYPE
1824: A type descriptor was invalid.
1825:
1826: @item MACH_SEND_MSG_TOO_SMALL
1827: The last data item in the message ran over the end of the message.
1828: @end table
1829:
1830: These return codes imply that the message was returned to the caller
1831: with a pseudo-receive operation:
1832:
1833: @table @code
1834: @item MACH_SEND_TIMED_OUT
1835: The timeout interval expired.
1836:
1837: @item MACH_SEND_INTERRUPTED
1838: A software interrupt occurred.
1839:
1840: @item MACH_SEND_INVALID_NOTIFY
1841: When using @code{MACH_SEND_NOTIFY}, the notify argument did not denote a
1842: valid receive right.
1843:
1844: @item MACH_SEND_NO_NOTIFY
1845: A resource shortage prevented the kernel from setting up a msg-accepted
1846: notification.
1847:
1848: @item MACH_SEND_NOTIFY_IN_PROGRESS
1849: A msg-accepted notification was already requested, and hasn't yet been
1850: generated.
1851: @end table
1852:
1853: These return codes imply that the message was queued:
1854:
1855: @table @code
1856: @item MACH_SEND_WILL_NOTIFY
1857: The message was forcibly queued, and a msg-accepted notification was
1858: requested.
1859:
1860: @item MACH_MSG_SUCCESS
1861: The message was queued.
1862: @end table
1863:
1864: Some return codes, like @code{MACH_SEND_TIMED_OUT}, imply that the
1865: message was almost sent, but could not be queued. In these situations,
1866: the kernel tries to return the message contents to the caller with a
1867: pseudo-receive operation. This prevents the loss of port rights or
1868: memory which only exist in the message. For example, a receive right
1869: which was moved into the message, or out-of-line memory sent with the
1870: deallocate bit.
1871:
1872: The pseudo-receive operation is very similar to a normal receive
1873: operation. The pseudo-receive handles the port rights in the message
1874: header as if they were in the message body. They are not reversed.
1875: After the pseudo-receive, the message is ready to be resent. If the
1876: message is not resent, note that out-of-line memory regions may have
1877: moved and some port rights may have changed names.
1878:
1879: The pseudo-receive operation may encounter resource shortages. This is
1880: similar to a @code{MACH_RCV_BODY_ERROR} return code from a receive
1881: operation. When this happens, the normal send return codes are
1882: augmented with the @code{MACH_MSG_IPC_SPACE}, @code{MACH_MSG_VM_SPACE},
1883: @code{MACH_MSG_IPC_KERNEL}, and @code{MACH_MSG_VM_KERNEL} bits to
1884: indicate the nature of the resource shortage.
1885:
1886: The queueing of a message carrying receive rights may create a circular
1887: loop of receive rights and messages, which can never be received. For
1888: example, a message carrying a receive right can be sent to that receive
1889: right. This situation is not an error, but the kernel will
1890: garbage-collect such loops, destroying the messages and ports involved.
1891:
1892:
1893: @node Message Receive
1894: @subsection Message Receive
1895:
1896: The receive operation dequeues a message from a port. The receiving
1897: task acquires the port rights and out-of-line memory regions carried in
1898: the message.
1899:
1900: The @code{rcv_name} argument specifies a port or port set from which to
1901: receive. If a port is specified, the caller must possess the receive
1902: right for the port and the port must not be a member of a port set. If
1903: no message is present, then the call blocks, subject to the
1904: @code{MACH_RCV_TIMEOUT} option.
1905:
1906: If a port set is specified, the call will receive a message sent to any
1907: of the member ports. It is permissible for the port set to have no
1908: member ports, and ports may be added and removed while a receive from
1909: the port set is in progress. The received message can come from any of
1910: the member ports which have messages, with the proviso that a member
1911: port with messages will not be indefinitely starved. The
1912: @code{msgh_local_port} field in the received message header specifies
1913: from which port in the port set the message came.
1914:
1915: The @code{rcv_size} argument specifies the size of the caller's message
1916: buffer. The @code{mach_msg} call will not receive a message larger than
1917: @code{rcv_size}. Messages that are too large are destroyed, unless the
1918: @code{MACH_RCV_LARGE} option is used.
1919:
1920: The destination and reply ports are reversed in a received message
1921: header. The @code{msgh_local_port} field names the destination port,
1922: from which the message was received, and the @code{msgh_remote_port}
1923: field names the reply port right. The bits in @code{msgh_bits} are also
1924: reversed. The @code{MACH_MSGH_BITS_LOCAL} bits have the value
1925: @code{MACH_MSG_TYPE_PORT_SEND} if the message was sent to a send right,
1926: and the value @code{MACH_MSG_TYPE_PORT_SEND_ONCE} if was sent to a
1927: send-once right. The @code{MACH_MSGH_BITS_REMOTE} bits describe the
1928: reply port right.
1929:
1930: A received message can contain port rights and out-of-line memory. The
1931: @code{msgh_local_port} field does not receive a port right; the act of
1932: receiving the message destroys the send or send-once right for the
1933: destination port. The msgh_remote_port field does name a received port
1934: right, the reply port right, and the message body can carry port rights
1935: and memory if @code{MACH_MSGH_BITS_COMPLEX} is present in msgh_bits.
1936: Received port rights and memory should be consumed or deallocated in
1937: some fashion.
1938:
1939: In almost all cases, @code{msgh_local_port} will specify the name of a
1940: receive right, either @code{rcv_name} or if @code{rcv_name} is a port
1941: set, a member of @code{rcv_name}. If other threads are concurrently
1942: manipulating the receive right, the situation is more complicated. If
1943: the receive right is renamed during the call, then
1944: @code{msgh_local_port} specifies the right's new name. If the caller
1945: loses the receive right after the message was dequeued from it, then
1946: @code{mach_msg} will proceed instead of returning
1947: @code{MACH_RCV_PORT_DIED}. If the receive right was destroyed, then
1948: @code{msgh_local_port} specifies @code{MACH_PORT_DEAD}. If the receive
1949: right still exists, but isn't held by the caller, then
1950: @code{msgh_local_port} specifies @code{MACH_PORT_NULL}.
1951:
1.1.1.3 root 1952: Servers usually associate some state with a receive right. To that
1953: end, they might use a hash table to look up the state for the port a
1954: message was sent to. To optimize this, a task may associate an opaque
1955: @var{payload} with a receive right using the
1956: @code{mach_port_set_protected_payload} function. Once this is done,
1957: the kernel will set the @code{msgh_protected_payload} field to
1958: @var{payload} when delivering a message to this right and indicate
1959: this by setting the local part of @code{msgh_bits} to
1960: @code{MACH_MSG_TYPE_PROTECTED_PAYLOAD}.
1961:
1962: The support for protected payloads was added to GNU Mach. To preserve
1963: binary compatibility, the @code{msgh_local_port} and
1964: @code{msgh_local_port} share the same location. This makes it
1965: possible to add the payload information without increasing the size of
1966: @code{mach_msg_header_t}. This is an implementation detail. Which
1967: field is valid is determined by the local part of the
1968: @code{msgh_bits}. Existing software is not affected. When a receive
1969: right is transferred to another task, its payload is cleared.
1970:
1.1 root 1971: Received messages are stamped with a sequence number, taken from the
1972: port from which the message was received. (Messages received from a
1973: port set are stamped with a sequence number from the appropriate member
1974: port.) Newly created ports start with a zero sequence number, and the
1975: sequence number is reset to zero whenever the port's receive right moves
1976: between tasks. When a message is dequeued from the port, it is stamped
1977: with the port's sequence number and the port's sequence number is then
1978: incremented. The dequeue and increment operations are atomic, so that
1979: multiple threads receiving messages from a port can use the
1980: @code{msgh_seqno} field to reconstruct the original order of the
1981: messages.
1982:
1983: These options modify @code{MACH_RCV_MSG}. If @code{MACH_RCV_MSG} is not
1984: also specified, they are ignored.
1985:
1986: @table @code
1987: @item MACH_RCV_TIMEOUT
1988: The timeout argument should specify a maximum time (in milliseconds) for
1989: the call to block before giving up.@footnote{If MACH_RCV_TIMEOUT is used
1990: without MACH_RCV_INTERRUPT, then the timeout duration might not be
1991: accurate. When the call is interrupted and automatically retried, the
1992: original timeout is used. If interrupts occur frequently enough, the
1993: timeout interval might never expire.} If no message arrives before the
1994: timeout interval elapses, then the call returns
1995: @code{MACH_RCV_TIMED_OUT}. A zero timeout is legitimate.
1996:
1997: @item MACH_RCV_NOTIFY
1998: The notify argument should specify a receive right for a notify port.
1999: If receiving the reply port creates a new port right in the caller, then
2000: the notify port is used to request a dead-name notification for the new
2001: port right.
2002:
2003: @item MACH_RCV_INTERRUPT
2004: If specified, the @code{mach_msg} call will return
2005: @code{MACH_RCV_INTERRUPTED} if a software interrupt aborts the call.
2006: Otherwise, the receive operation will be retried.
2007:
2008: @item MACH_RCV_LARGE
2009: If the message is larger than @code{rcv_size}, then the message remains
2010: queued instead of being destroyed. The call returns
2011: @code{MACH_RCV_TOO_LARGE} and the actual size of the message is returned
2012: in the @code{msgh_size} field of the message header.
2013: @end table
2014:
2015: The receive operation can generate the following return codes. These
2016: return codes imply that the call did not dequeue a message:
2017:
2018: @table @code
2019: @item MACH_RCV_INVALID_NAME
2020: The specified @code{rcv_name} was invalid.
2021:
2022: @item MACH_RCV_IN_SET
2023: The specified port was a member of a port set.
2024:
2025: @item MACH_RCV_TIMED_OUT
2026: The timeout interval expired.
2027:
2028: @item MACH_RCV_INTERRUPTED
2029: A software interrupt occurred.
2030:
2031: @item MACH_RCV_PORT_DIED
2032: The caller lost the rights specified by @code{rcv_name}.
2033:
2034: @item MACH_RCV_PORT_CHANGED
2035: @code{rcv_name} specified a receive right which was moved into a port
2036: set during the call.
2037:
2038: @item MACH_RCV_TOO_LARGE
2039: When using @code{MACH_RCV_LARGE}, and the message was larger than
2040: @code{rcv_size}. The message is left queued, and its actual size is
2041: returned in the @code{msgh_size} field of the message buffer.
2042: @end table
2043:
2044: These return codes imply that a message was dequeued and destroyed:
2045:
2046: @table @code
2047: @item MACH_RCV_HEADER_ERROR
2048: A resource shortage prevented the reception of the port rights in the
2049: message header.
2050:
2051: @item MACH_RCV_INVALID_NOTIFY
2052: When using @code{MACH_RCV_NOTIFY}, the notify argument did not denote a
2053: valid receive right.
2054:
2055: @item MACH_RCV_TOO_LARGE
2056: When not using @code{MACH_RCV_LARGE}, a message larger than
2057: @code{rcv_size} was dequeued and destroyed.
2058: @end table
2059:
2060: In these situations, when a message is dequeued and then destroyed, the
2061: reply port and all port rights and memory in the message body are
2062: destroyed. However, the caller receives the message's header, with all
2063: fields correct, including the destination port but excepting the reply
2064: port, which is @code{MACH_PORT_NULL}.
2065:
2066: These return codes imply that a message was received:
2067:
2068: @table @code
2069: @item MACH_RCV_BODY_ERROR
2070: A resource shortage prevented the reception of a port right or
2071: out-of-line memory region in the message body. The message header,
2072: including the reply port, is correct. The kernel attempts to transfer
2073: all port rights and memory regions in the body, and only destroys those
2074: that can't be transferred.
2075:
2076: @item MACH_RCV_INVALID_DATA
2077: The specified message buffer was not writable. The calling task did
2078: successfully receive the port rights and out-of-line memory regions in
2079: the message.
2080:
2081: @item MACH_MSG_SUCCESS
2082: A message was received.
2083: @end table
2084:
2085: Resource shortages can occur after a message is dequeued, while
2086: transferring port rights and out-of-line memory regions to the receiving
2087: task. The @code{mach_msg} call returns @code{MACH_RCV_HEADER_ERROR} or
2088: @code{MACH_RCV_BODY_ERROR} in this situation. These return codes always
2089: carry extra bits (bitwise-ored) that indicate the nature of the resource
2090: shortage:
2091:
2092: @table @code
2093: @item MACH_MSG_IPC_SPACE
2094: There was no room in the task's IPC name space for another port name.
2095:
2096: @item MACH_MSG_VM_SPACE
2097: There was no room in the task's VM address space for an out-of-line
2098: memory region.
2099:
2100: @item MACH_MSG_IPC_KERNEL
2101: A kernel resource shortage prevented the reception of a port right.
2102:
2103: @item MACH_MSG_VM_KERNEL
2104: A kernel resource shortage prevented the reception of an out-of-line
2105: memory region.
2106: @end table
2107:
2108: If a resource shortage prevents the reception of a port right, the port
2109: right is destroyed and the caller sees the name @code{MACH_PORT_NULL}.
2110: If a resource shortage prevents the reception of an out-of-line memory
2111: region, the region is destroyed and the caller receives a zero address.
2112: In addition, the @code{msgt_size} (@code{msgtl_size}) field in the
2113: data's type descriptor is changed to zero. If a resource shortage
2114: prevents the reception of out-of-line memory carrying port rights, then
2115: the port rights are always destroyed if the memory region can not be
2116: received. A task never receives port rights or memory regions that it
2117: isn't told about.
2118:
2119:
2120: @node Atomicity
2121: @subsection Atomicity
2122:
2123: The @code{mach_msg} call handles port rights in a message header
2124: atomically. Port rights and out-of-line memory in a message body do not
2125: enjoy this atomicity guarantee. The message body may be processed
2126: front-to-back, back-to-front, first out-of-line memory then port rights,
2127: in some random order, or even atomically.
2128:
2129: For example, consider sending a message with the destination port
2130: specified as @code{MACH_MSG_TYPE_MOVE_SEND} and the reply port specified
2131: as @code{MACH_MSG_TYPE_COPY_SEND}. The same send right, with one
2132: user-reference, is supplied for both the @code{msgh_remote_port} and
2133: @code{msgh_local_port} fields. Because @code{mach_msg} processes the
2134: message header atomically, this succeeds. If @code{msgh_remote_port}
2135: were processed before @code{msgh_local_port}, then @code{mach_msg} would
2136: return @code{MACH_SEND_INVALID_REPLY} in this situation.
2137:
2138: On the other hand, suppose the destination and reply port are both
2139: specified as @code{MACH_MSG_TYPE_MOVE_SEND}, and again the same send
2140: right with one user-reference is supplied for both. Now the send
2141: operation fails, but because it processes the header atomically,
2142: mach_msg can return either @code{MACH_SEND_INVALID_DEST} or
2143: @code{MACH_SEND_INVALID_REPLY}.
2144:
2145: For example, consider receiving a message at the same time another
2146: thread is deallocating the destination receive right. Suppose the reply
2147: port field carries a send right for the destination port. If the
2148: deallocation happens before the dequeuing, then the receiver gets
2149: @code{MACH_RCV_PORT_DIED}. If the deallocation happens after the
2150: receive, then the @code{msgh_local_port} and the @code{msgh_remote_port}
2151: fields both specify the same right, which becomes a dead name when the
2152: receive right is deallocated. If the deallocation happens between the
2153: dequeue and the receive, then the @code{msgh_local_port} and
2154: @code{msgh_remote_port} fields both specify @code{MACH_PORT_DEAD}.
2155: Because the header is processed atomically, it is not possible for just
2156: one of the two fields to hold @code{MACH_PORT_DEAD}.
2157:
2158: The @code{MACH_RCV_NOTIFY} option provides a more likely example.
2159: Suppose a message carrying a send-once right reply port is received with
2160: @code{MACH_RCV_NOTIFY} at the same time the reply port is destroyed. If
2161: the reply port is destroyed first, then @code{msgh_remote_port}
2162: specifies @code{MACH_PORT_DEAD} and the kernel does not generate a
2163: dead-name notification. If the reply port is destroyed after it is
2164: received, then @code{msgh_remote_port} specifies a dead name for which
2165: the kernel generates a dead-name notification. It is not possible to
2166: receive the reply port right and have it turn into a dead name before
2167: the dead-name notification is requested; as part of the message header
2168: the reply port is received atomically.
2169:
2170:
2171: @node Port Manipulation Interface
2172: @section Port Manipulation Interface
2173:
2174: This section describes the interface to create, destroy and manipulate
2175: ports, port rights and port sets.
2176:
2177: @cindex IPC space port
2178: @cindex port representing an IPC space
2179: @deftp {Data type} ipc_space_t
2180: This is a @code{task_t} (and as such a @code{mach_port_t}), which holds
2181: a port name associated with a port that represents an IPC space in the
2182: kernel. An IPC space is used by the kernel to manage the port names and
2183: rights available to a task. The IPC space doesn't get a port name of
2184: its own. Instead the port name of the task containing the IPC space is
2185: used to name the IPC space of the task (as is indicated by the fact that
2186: the type of @code{ipc_space_t} is actually @code{task_t}).
2187:
2188: The IPC spaces of tasks are the only ones accessible outside of
2189: the kernel.
2190: @end deftp
2191:
2192: @menu
2193: * Port Creation:: How to create new ports and port sets.
2194: * Port Destruction:: How to destroy ports and port sets.
2195: * Port Names:: How to query and manipulate port names.
2196: * Port Rights:: How to work with port rights.
2197: * Ports and other Tasks:: How to move rights between tasks.
2198: * Receive Rights:: How to work with receive rights.
2199: * Port Sets:: How to work with port sets.
2200: * Request Notifications:: How to request notifications for events.
1.1.1.3 root 2201: * Inherited Ports:: How to work with the inherited system ports.
1.1 root 2202: @end menu
2203:
2204:
2205: @node Port Creation
2206: @subsection Port Creation
2207:
2208: @deftypefun kern_return_t mach_port_allocate (@w{ipc_space_t @var{task}}, @w{mach_port_right_t @var{right}}, @w{mach_port_t *@var{name}})
2209: The @code{mach_port_allocate} function creates a new right in the
2210: specified task. The new right's name is returned in @var{name}, which
2211: may be any name that wasn't in use.
2212:
2213: The @var{right} argument takes the following values:
2214:
2215: @table @code
2216: @item MACH_PORT_RIGHT_RECEIVE
2217: @code{mach_port_allocate} creates a port. The new port is not a member
2218: of any port set. It doesn't have any extant send or send-once rights.
2219: Its make-send count is zero, its sequence number is zero, its queue
2220: limit is @code{MACH_PORT_QLIMIT_DEFAULT}, and it has no queued messages.
2221: @var{name} denotes the receive right for the new port.
2222:
2223: @var{task} does not hold send rights for the new port, only the receive
2224: right. @code{mach_port_insert_right} and @code{mach_port_extract_right}
2225: can be used to convert the receive right into a combined send/receive
2226: right.
2227:
2228: @item MACH_PORT_RIGHT_PORT_SET
2229: @code{mach_port_allocate} creates a port set. The new port set has no
2230: members.
2231:
2232: @item MACH_PORT_RIGHT_DEAD_NAME
2233: @code{mach_port_allocate} creates a dead name. The new dead name has
2234: one user reference.
2235: @end table
2236:
2237: The function returns @code{KERN_SUCCESS} if the call succeeded,
2238: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2239: @code{KERN_INVALID_VALUE} if @var{right} was invalid, @code{KERN_NO_SPACE} if
2240: there was no room in @var{task}'s IPC name space for another right and
2241: @code{KERN_RESOURCE_SHORTAGE} if the kernel ran out of memory.
2242:
2243: The @code{mach_port_allocate} call is actually an RPC to @var{task},
2244: normally a send right for a task port, but potentially any send right.
2245: In addition to the normal diagnostic return codes from the call's server
2246: (normally the kernel), the call may return @code{mach_msg} return codes.
2247: @end deftypefun
2248:
2249: @deftypefun mach_port_t mach_reply_port ()
2250: The @code{mach_reply_port} system call creates a reply port in the
2251: calling task.
2252:
2253: @code{mach_reply_port} creates a port, giving the calling task the
2254: receive right for the port. The call returns the name of the new
2255: receive right.
2256:
2257: This is very much like creating a receive right with the
2258: @code{mach_port_allocate} call, with two differences. First,
2259: @code{mach_reply_port} is a system call and not an RPC (which requires a
2260: reply port). Second, the port created by @code{mach_reply_port} may be
2261: optimized for use as a reply port.
2262:
2263: The function returns @code{MACH_PORT_NULL} if a resource shortage
2264: prevented the creation of the receive right.
2265: @end deftypefun
2266:
2267: @deftypefun kern_return_t mach_port_allocate_name (@w{ipc_space_t @var{task}}, @w{mach_port_right_t @var{right}}, @w{mach_port_t @var{name}})
2268: The function @code{mach_port_allocate_name} creates a new right in the
2269: specified task, with a specified name for the new right. @var{name}
2270: must not already be in use for some right, and it can't be the reserved
2271: values @code{MACH_PORT_NULL} and @code{MACH_PORT_DEAD}.
2272:
2273: The @var{right} argument takes the following values:
2274:
2275: @table @code
2276: @item MACH_PORT_RIGHT_RECEIVE
2277: @code{mach_port_allocate_name} creates a port. The new port is not a
2278: member of any port set. It doesn't have any extant send or send-once
2279: rights. Its make-send count is zero, its sequence number is zero, its
2280: queue limit is @code{MACH_PORT_QLIMIT_DEFAULT}, and it has no queued
2281: messages. @var{name} denotes the receive right for the new port.
2282:
2283: @var{task} does not hold send rights for the new port, only the receive
2284: right. @code{mach_port_insert_right} and @code{mach_port_extract_right}
2285: can be used to convert the receive right into a combined send/receive
2286: right.
2287:
2288: @item MACH_PORT_RIGHT_PORT_SET
2289: @code{mach_port_allocate_name} creates a port set. The new port set has
2290: no members.
2291:
2292: @item MACH_PORT_RIGHT_DEAD_NAME
2293: @code{mach_port_allocate_name} creates a new dead name. The new dead
2294: name has one user reference.
2295: @end table
2296:
2297: The function returns @code{KERN_SUCCESS} if the call succeeded,
2298: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2299: @code{KERN_INVALID_VALUE} if @var{right} was invalid or @var{name} was
2300: @code{MACH_PORT_NULL} or @code{MACH_PORT_DEAD}, @code{KERN_NAME_EXISTS}
2301: if @var{name} was already in use for a port right and
2302: @code{KERN_RESOURCE_SHORTAGE} if the kernel ran out of memory.
2303:
2304: The @code{mach_port_allocate_name} call is actually an RPC to
2305: @var{task}, normally a send right for a task port, but potentially any
2306: send right. In addition to the normal diagnostic return codes from the
2307: call's server (normally the kernel), the call may return @code{mach_msg}
2308: return codes.
2309: @end deftypefun
2310:
2311:
2312: @node Port Destruction
2313: @subsection Port Destruction
2314:
2315: @deftypefun kern_return_t mach_port_deallocate (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}})
2316: The function @code{mach_port_deallocate} releases a user reference for a
2317: right in @var{task}'s IPC name space. It allows a task to release a
2318: user reference for a send or send-once right without failing if the port
2319: has died and the right is now actually a dead name.
2320:
2321: If @var{name} denotes a dead name, send right, or send-once right, then
2322: the right loses one user reference. If it only had one user reference,
2323: then the right is destroyed.
2324:
2325: The function returns @code{KERN_SUCCESS} if the call succeeded,
2326: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2327: @code{KERN_INVALID_NAME} if @var{name} did not denote a right and
2328: @code{KERN_INVALID_RIGHT} if @var{name} denoted an invalid right.
2329:
2330: The @code{mach_port_deallocate} call is actually an RPC to
2331: @var{task}, normally a send right for a task port, but potentially any
2332: send right. In addition to the normal diagnostic return codes from the
2333: call's server (normally the kernel), the call may return @code{mach_msg}
2334: return codes.
2335: @end deftypefun
2336:
2337: @deftypefun kern_return_t mach_port_destroy (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}})
2338: The function @code{mach_port_destroy} deallocates all rights denoted by
2339: a name. The name becomes immediately available for reuse.
2340:
2341: For most purposes, @code{mach_port_mod_refs} and
2342: @code{mach_port_deallocate} are preferable.
2343:
2344: If @var{name} denotes a port set, then all members of the port set are
2345: implicitly removed from the port set.
2346:
2347: If @var{name} denotes a receive right that is a member of a port set,
2348: the receive right is implicitly removed from the port set. If there is
2349: a port-destroyed request registered for the port, then the receive right
2350: is not actually destroyed, but instead is sent in a port-destroyed
2351: notification to the backup port. If there is no registered
2352: port-destroyed request, remaining messages queued to the port are
2353: destroyed and extant send and send-once rights turn into dead names. If
2354: those send and send-once rights have dead-name requests registered, then
2355: dead-name notifications are generated for them.
2356:
2357: If @var{name} denotes a send-once right, then the send-once right is
2358: used to produce a send-once notification for the port.
2359:
2360: If @var{name} denotes a send-once, send, and/or receive right, and it
2361: has a dead-name request registered, then the registered send-once right
2362: is used to produce a port-deleted notification for the name.
2363:
2364: The function returns @code{KERN_SUCCESS} if the call succeeded,
2365: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2366: @code{KERN_INVALID_NAME} if @var{name} did not denote a right.
2367:
2368: The @code{mach_port_destroy} call is actually an RPC to
2369: @var{task}, normally a send right for a task port, but potentially any
2370: send right. In addition to the normal diagnostic return codes from the
2371: call's server (normally the kernel), the call may return @code{mach_msg}
2372: return codes.
2373: @end deftypefun
2374:
2375:
2376: @node Port Names
2377: @subsection Port Names
2378:
2379: @deftypefun kern_return_t mach_port_names (@w{ipc_space_t @var{task}}, @w{mach_port_array_t *@var{names}}, @w{mach_msg_type_number_t *@var{ncount}}, @w{mach_port_type_array_t *@var{types}}, @w{mach_msg_type_number_t *@var{tcount}})
2380: The function @code{mach_port_names} returns information about
2381: @var{task}'s port name space. For each name, it also returns what type
2382: of rights @var{task} holds. (The same information returned by
2383: @code{mach_port_type}.) @var{names} and @var{types} are arrays that are
2384: automatically allocated when the reply message is received. The user
2385: should @code{vm_deallocate} them when the data is no longer needed.
2386:
2387: @code{mach_port_names} will return in @var{names} the names of the
2388: ports, port sets, and dead names in the task's port name space, in no
2389: particular order and in @var{ncount} the number of names returned. It
2390: will return in @var{types} the type of each corresponding name, which
2391: indicates what kind of rights the task holds with that name.
2392: @var{tcount} should be the same as @var{ncount}.
2393:
2394: The function returns @code{KERN_SUCCESS} if the call succeeded,
2395: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2396: @code{KERN_RESOURCE_SHORTAGE} if the kernel ran out of memory.
2397:
2398: The @code{mach_port_names} call is actually an RPC to @var{task},
2399: normally a send right for a task port, but potentially any send right.
2400: In addition to the normal diagnostic return codes from the call's server
2401: (normally the kernel), the call may return @code{mach_msg} return codes.
2402: @end deftypefun
2403:
2404: @deftypefun kern_return_t mach_port_type (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}}, @w{mach_port_type_t *@var{ptype}})
2405: The function @code{mach_port_type} returns information about
2406: @var{task}'s rights for a specific name in its port name space. The
2407: returned @var{ptype} is a bitmask indicating what rights @var{task}
2408: holds for the port, port set or dead name. The bitmask is composed of
2409: the following bits:
2410:
2411: @table @code
2412: @item MACH_PORT_TYPE_SEND
2413: The name denotes a send right.
2414:
2415: @item MACH_PORT_TYPE_RECEIVE
2416: The name denotes a receive right.
2417:
2418: @item MACH_PORT_TYPE_SEND_ONCE
2419: The name denotes a send-once right.
2420:
2421: @item MACH_PORT_TYPE_PORT_SET
2422: The name denotes a port set.
2423:
2424: @item MACH_PORT_TYPE_DEAD_NAME
2425: The name is a dead name.
2426:
2427: @item MACH_PORT_TYPE_DNREQUEST
2428: A dead-name request has been registered for the right.
2429:
2430: @item MACH_PORT_TYPE_MAREQUEST
2431: A msg-accepted request for the right is pending.
2432:
2433: @item MACH_PORT_TYPE_COMPAT
2434: The port right was created in the compatibility mode.
2435: @end table
2436:
2437: The function returns @code{KERN_SUCCESS} if the call succeeded,
2438: @code{KERN_INVALID_TASK} if @var{task} was invalid and
2439: @code{KERN_INVALID_NAME} if @var{name} did not denote a right.
2440:
2441: The @code{mach_port_type} call is actually an RPC to @var{task},
2442: normally a send right for a task port, but potentially any send right.
2443: In addition to the normal diagnostic return codes from the call's server
2444: (normally the kernel), the call may return @code{mach_msg} return codes.
2445: @end deftypefun
2446:
2447: @deftypefun kern_return_t mach_port_rename (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{old_name}}, @w{mach_port_t @var{new_name}})
2448: The function @code{mach_port_rename} changes the name by which a port,
2449: port set, or dead name is known to @var{task}. @var{old_name} is the
2450: original name and @var{new_name} the new name for the port right.
2451: @var{new_name} must not already be in use, and it can't be the
2452: distinguished values @code{MACH_PORT_NULL} and @code{MACH_PORT_DEAD}.
2453:
2454: The function returns @code{KERN_SUCCESS} if the call succeeded,
2455: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2456: @code{KERN_INVALID_NAME} if @var{old_name} did not denote a right,
2457: @code{KERN_INVALID_VALUE} if @var{new_name} was @code{MACH_PORT_NULL} or
2458: @code{MACH_PORT_DEAD}, @code{KERN_NAME_EXISTS} if @code{new_name}
2459: already denoted a right and @code{KERN_RESOURCE_SHORTAGE} if the kernel
2460: ran out of memory.
2461:
2462: The @code{mach_port_rename} call is actually an RPC to @var{task},
2463: normally a send right for a task port, but potentially any send right.
2464: In addition to the normal diagnostic return codes from the call's server
2465: (normally the kernel), the call may return @code{mach_msg} return codes.
2466: @end deftypefun
2467:
2468:
2469: @node Port Rights
2470: @subsection Port Rights
2471:
2472: @deftypefun kern_return_t mach_port_get_refs (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}}, @w{mach_port_right_t @var{right}}, @w{mach_port_urefs_t *@var{refs}})
2473: The function @code{mach_port_get_refs} returns the number of user
2474: references a task has for a right.
2475:
2476: The @var{right} argument takes the following values:
2477: @itemize @bullet
2478: @item @code{MACH_PORT_RIGHT_SEND}
2479: @item @code{MACH_PORT_RIGHT_RECEIVE}
2480: @item @code{MACH_PORT_RIGHT_SEND_ONCE}
2481: @item @code{MACH_PORT_RIGHT_PORT_SET}
2482: @item @code{MACH_PORT_RIGHT_DEAD_NAME}
2483: @end itemize
2484:
2485: If @var{name} denotes a right, but not the type of right specified, then
2486: zero is returned. Otherwise a positive number of user references is
2487: returned. Note that a name may simultaneously denote send and receive
2488: rights.
2489:
2490: The function returns @code{KERN_SUCCESS} if the call succeeded,
2491: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2492: @code{KERN_INVALID_VALUE} if @var{right} was invalid and
2493: @code{KERN_INVALID_NAME} if @var{name} did not denote a right.
2494:
2495: The @code{mach_port_get_refs} call is actually an RPC to @var{task},
2496: normally a send right for a task port, but potentially any send right.
2497: In addition to the normal diagnostic return codes from the call's server
2498: (normally the kernel), the call may return @code{mach_msg} return codes.
2499: @end deftypefun
2500:
2501: @deftypefun kern_return_t mach_port_mod_refs (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}}, @w{mach_port_right_t @var{right}}, @w{mach_port_delta_t @var{delta}})
2502: The function @code{mach_port_mod_refs} requests that the number of user
2503: references a task has for a right be changed. This results in the right
2504: being destroyed, if the number of user references is changed to zero.
2505: The task holding the right is @var{task}, @var{name} should denote the
2506: specified right. @var{right} denotes the type of right being modified.
2507: @var{delta} is the signed change to the number of user references.
2508:
2509: The @var{right} argument takes the following values:
2510: @itemize @bullet
2511: @item @code{MACH_PORT_RIGHT_SEND}
2512: @item @code{MACH_PORT_RIGHT_RECEIVE}
2513: @item @code{MACH_PORT_RIGHT_SEND_ONCE}
2514: @item @code{MACH_PORT_RIGHT_PORT_SET}
2515: @item @code{MACH_PORT_RIGHT_DEAD_NAME}
2516: @end itemize
2517:
2518: The number of user references for the right is changed by the amount
2519: @var{delta}, subject to the following restrictions: port sets, receive
2520: rights, and send-once rights may only have one user reference. The
2521: resulting number of user references can't be negative. If the resulting
2522: number of user references is zero, the effect is to deallocate the
2523: right. For dead names and send rights, there is an
2524: implementation-defined maximum number of user references.
2525:
2526: If the call destroys the right, then the effect is as described for
2527: @code{mach_port_destroy}, with the exception that
2528: @code{mach_port_destroy} simultaneously destroys all the rights denoted
2529: by a name, while @code{mach_port_mod_refs} can only destroy one right.
2530: The name will be available for reuse if it only denoted the one right.
2531:
2532: The function returns @code{KERN_SUCCESS} if the call succeeded,
2533: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2534: @code{KERN_INVALID_VALUE} if @var{right} was invalid or the
2535: user-reference count would become negative, @code{KERN_INVALID_NAME} if
2536: @var{name} did not denote a right, @code{KERN_INVALID_RIGHT} if
2537: @var{name} denoted a right, but not the specified right and
2538: @code{KERN_UREFS_OVERFLOW} if the user-reference count would overflow.
2539:
2540: The @code{mach_port_mod_refs} call is actually an RPC to @var{task},
2541: normally a send right for a task port, but potentially any send right.
2542: In addition to the normal diagnostic return codes from the call's server
2543: (normally the kernel), the call may return @code{mach_msg} return codes.
2544: @end deftypefun
2545:
2546:
2547: @node Ports and other Tasks
2548: @subsection Ports and other Tasks
2549:
2550: @deftypefun kern_return_t mach_port_insert_right (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}}, @w{mach_port_t @var{right}}, @w{mach_msg_type_name_t @var{right_type}})
2551: The function @var{mach_port_insert_right} inserts into @var{task} the
2552: caller's right for a port, using a specified name for the right in the
2553: target task.
2554:
2555: The specified @var{name} can't be one of the reserved values
2556: @code{MACH_PORT_NULL} or @code{MACH_PORT_DEAD}. The @var{right} can't
2557: be @code{MACH_PORT_NULL} or @code{MACH_PORT_DEAD}.
2558:
2559: The argument @var{right_type} specifies a right to be inserted and how
2560: that right should be extracted from the caller. It should be a value
2561: appropriate for @var{msgt_name}; see @code{mach_msg}. @c XXX cross ref
2562:
2563: If @var{right_type} is @code{MACH_MSG_TYPE_MAKE_SEND},
2564: @code{MACH_MSG_TYPE_MOVE_SEND}, or @code{MACH_MSG_TYPE_COPY_SEND}, then
2565: a send right is inserted. If the target already holds send or receive
2566: rights for the port, then @var{name} should denote those rights in the
2567: target. Otherwise, @var{name} should be unused in the target. If the
2568: target already has send rights, then those send rights gain an
2569: additional user reference. Otherwise, the target gains a send right,
2570: with a user reference count of one.
2571:
2572: If @var{right_type} is @code{MACH_MSG_TYPE_MAKE_SEND_ONCE} or
2573: @code{MACH_MSG_TYPE_MOVE_SEND_ONCE}, then a send-once right is inserted.
2574: The name should be unused in the target. The target gains a send-once
2575: right.
2576:
2577: If @var{right_type} is @code{MACH_MSG_TYPE_MOVE_RECEIVE}, then a receive
2578: right is inserted. If the target already holds send rights for the
2579: port, then name should denote those rights in the target. Otherwise,
2580: name should be unused in the target. The receive right is moved into
2581: the target task.
2582:
2583: The function returns @code{KERN_SUCCESS} if the call succeeded,
2584: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2585: @code{KERN_INVALID_VALUE} if @var{right} was not a port right or
2586: @var{name} was @code{MACH_PORT_NULL} or @code{MACH_PORT_DEAD},
2587: @code{KERN_NAME_EXISTS} if @var{name} already denoted a right,
2588: @code{KERN_INVALID_CAPABILITY} if @var{right} was @code{MACH_PORT_NULL}
2589: or @code{MACH_PORT_DEAD} @code{KERN_RIGHT_EXISTS} if @var{task} already
2590: had rights for the port, with a different name,
2591: @code{KERN_UREFS_OVERFLOW} if the user-reference count would overflow
2592: and @code{KERN_RESOURCE_SHORTAGE} if the kernel ran out of memory.
2593:
2594: The @code{mach_port_insert_right} call is actually an RPC to @var{task},
2595: normally a send right for a task port, but potentially any send right.
2596: In addition to the normal diagnostic return codes from the call's server
2597: (normally the kernel), the call may return @code{mach_msg} return codes.
2598: @end deftypefun
2599:
2600: @deftypefun kern_return_t mach_port_extract_right (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}}, @w{mach_msg_type_name_t @var{desired_type}}, @w{mach_port_t *@var{right}}, @w{mach_msg_type_name_t *@var{acquired_type}})
2601: The function @var{mach_port_extract_right} extracts a port right from
2602: the target @var{task} and returns it to the caller as if the task sent
2603: the right voluntarily, using @var{desired_type} as the value of
2604: @var{msgt_name}. @xref{Mach Message Call}.
2605:
2606: The returned value of @var{acquired_type} will be
2607: @code{MACH_MSG_TYPE_PORT_SEND} if a send right is extracted,
2608: @code{MACH_MSG_TYPE_PORT_RECEIVE} if a receive right is extracted, and
2609: @code{MACH_MSG_TYPE_PORT_SEND_ONCE} if a send-once right is extracted.
2610:
2611: The function returns @code{KERN_SUCCESS} if the call succeeded,
2612: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2613: @code{KERN_INVALID_NAME} if @var{name} did not denote a right,
2614: @code{KERN_INVALID_RIGHT} if @var{name} denoted a right, but an invalid one,
2615: @code{KERN_INVALID_VALUE} if @var{desired_type} was invalid.
2616:
2617: The @code{mach_port_extract_right} call is actually an RPC to
2618: @var{task}, normally a send right for a task port, but potentially any
2619: send right. In addition to the normal diagnostic return codes from the
2620: call's server (normally the kernel), the call may return @code{mach_msg}
2621: return codes.
2622: @end deftypefun
2623:
2624:
2625: @node Receive Rights
2626: @subsection Receive Rights
2627:
2628: @deftp {Data type} mach_port_seqno_t
2629: The @code{mach_port_seqno_t} data type is an @code{unsigned int} which
2630: contains the sequence number of a port.
2631: @end deftp
2632:
2633: @deftp {Data type} mach_port_mscount_t
2634: The @code{mach_port_mscount_t} data type is an @code{unsigned int} which
2635: contains the make-send count for a port.
2636: @end deftp
2637:
2638: @deftp {Data type} mach_port_msgcount_t
2639: The @code{mach_port_msgcount_t} data type is an @code{unsigned int} which
2640: contains a number of messages.
2641: @end deftp
2642:
2643: @deftp {Data type} mach_port_rights_t
2644: The @code{mach_port_rights_t} data type is an @code{unsigned int} which
2645: contains a number of rights for a port.
2646: @end deftp
2647:
2648: @deftp {Data type} mach_port_status_t
2649: This structure contains some status information about a port, which can
2650: be queried with @code{mach_port_get_receive_status}. It has the following
2651: members:
2652:
2653: @table @code
2654: @item mach_port_t mps_pset
2655: The containing port set.
2656:
2657: @item mach_port_seqno_t mps_seqno
2658: The sequence number.
2659:
2660: @item mach_port_mscount_t mps_mscount
2661: The make-send count.
2662:
2663: @item mach_port_msgcount_t mps_qlimit
2664: The maximum number of messages in the queue.
2665:
2666: @item mach_port_msgcount_t mps_msgcount
2667: The current number of messages in the queue.
2668:
2669: @item mach_port_rights_t mps_sorights
2670: The number of send-once rights that exist.
2671:
2672: @item boolean_t mps_srights
2673: @code{TRUE} if send rights exist.
2674:
2675: @item boolean_t mps_pdrequest
2676: @code{TRUE} if port-deleted notification is requested.
2677:
2678: @item boolean_t mps_nsrequest
2679: @code{TRUE} if no-senders notification is requested.
2680: @end table
2681: @end deftp
2682:
2683: @deftypefun kern_return_t mach_port_get_receive_status (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}}, @w{mach_port_status_t *@var{status}})
2684: The function @code{mach_port_get_receive_status} returns the current
2685: status of the specified receive right.
2686:
2687: The function returns @code{KERN_SUCCESS} if the call succeeded,
2688: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2689: @code{KERN_INVALID_NAME} if @var{name} did not denote a right and
2690: @code{KERN_INVALID_RIGHT} if @var{name} denoted a right, but not a
2691: receive right.
2692:
2693: The @code{mach_port_get_receive_status} call is actually an RPC to @var{task},
2694: normally a send right for a task port, but potentially any send right.
2695: In addition to the normal diagnostic return codes from the call's server
2696: (normally the kernel), the call may return @code{mach_msg} return codes.
2697: @end deftypefun
2698:
2699: @deftypefun kern_return_t mach_port_set_mscount (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}}, @w{mach_port_mscount_t @var{mscount}})
2700: The function @code{mach_port_set_mscount} changes the make-send count of
2701: @var{task}'s receive right named @var{name} to @var{mscount}. All
2702: values for @var{mscount} are valid.
2703:
2704: The function returns @code{KERN_SUCCESS} if the call succeeded,
2705: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2706: @code{KERN_INVALID_NAME} if @var{name} did not denote a right and
2707: @code{KERN_INVALID_RIGHT} if @var{name} denoted a right, but not a
2708: receive right.
2709:
2710: The @code{mach_port_set_mscount} call is actually an RPC to @var{task},
2711: normally a send right for a task port, but potentially any send right.
2712: In addition to the normal diagnostic return codes from the call's server
2713: (normally the kernel), the call may return @code{mach_msg} return codes.
2714: @end deftypefun
2715:
2716: @deftypefun kern_return_t mach_port_set_qlimit (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}}, @w{mach_port_msgcount_t @var{qlimit}})
2717: The function @code{mach_port_set_qlimit} changes the queue limit
2718: @var{task}'s receive right named @var{name} to @var{qlimit}. Valid
2719: values for @var{qlimit} are between zero and
2720: @code{MACH_PORT_QLIMIT_MAX}, inclusive.
2721:
2722: The function returns @code{KERN_SUCCESS} if the call succeeded,
2723: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2724: @code{KERN_INVALID_NAME} if @var{name} did not denote a right,
2725: @code{KERN_INVALID_RIGHT} if @var{name} denoted a right, but not a
2726: receive right and @code{KERN_INVALID_VALUE} if @var{qlimit} was invalid.
2727:
2728: The @code{mach_port_set_qlimit} call is actually an RPC to @var{task},
2729: normally a send right for a task port, but potentially any send right.
2730: In addition to the normal diagnostic return codes from the call's server
2731: (normally the kernel), the call may return @code{mach_msg} return codes.
2732: @end deftypefun
2733:
2734: @deftypefun kern_return_t mach_port_set_seqno (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}}, @w{mach_port_seqno_t @var{seqno}})
2735: The function @code{mach_port_set_seqno} changes the sequence number
2736: @var{task}'s receive right named @var{name} to @var{seqno}. All
2737: sequence number values are valid. The next message received from the
2738: port will be stamped with the specified sequence number.
2739:
2740: The function returns @code{KERN_SUCCESS} if the call succeeded,
2741: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2742: @code{KERN_INVALID_NAME} if @var{name} did not denote a right and
2743: @code{KERN_INVALID_RIGHT} if @var{name} denoted a right, but not a
2744: receive right.
2745:
2746: The @code{mach_port_set_seqno} call is actually an RPC to @var{task},
2747: normally a send right for a task port, but potentially any send right.
2748: In addition to the normal diagnostic return codes from the call's server
2749: (normally the kernel), the call may return @code{mach_msg} return codes.
2750: @end deftypefun
2751:
1.1.1.3 root 2752: @deftypefun kern_return_t mach_port_set_protected_payload (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}}, @w{unsigned long @var{payload}})
2753: The function @code{mach_port_set_protected_payload} sets the protected
2754: payload associated with the right @var{name} to @var{payload}.
2755: Section @ref{Message Receive} describes how setting a protected
2756: payload affects the messages delivered to @var{name}.
2757:
2758: The function returns @code{KERN_SUCCESS} if the call succeeded,
2759: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2760: @code{KERN_INVALID_NAME} if @var{name} did not denote a right and
2761: @code{KERN_INVALID_RIGHT} if @var{name} denoted a right, but not a
2762: receive right.
2763:
2764: The @code{mach_port_set_protected_payload} call is actually an RPC to
2765: @var{task}, normally a send right for a task port, but potentially any
2766: send right. In addition to the normal diagnostic return codes from
2767: the call's server (normally the kernel), the call may return
2768: @code{mach_msg} return codes.
2769: @end deftypefun
2770:
2771: @deftypefun kern_return_t mach_port_clear_protected_payload (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}}, @w{unsigned long @var{payload}})
2772: The function @code{mach_port_clear_protected_payload} clears the
2773: protected payload associated with the right @var{name}.
2774:
2775: The function returns @code{KERN_SUCCESS} if the call succeeded,
2776: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2777: @code{KERN_INVALID_NAME} if @var{name} did not denote a right and
2778: @code{KERN_INVALID_RIGHT} if @var{name} denoted a right, but not a
2779: receive right.
2780:
2781: The @code{mach_port_clear_protected_payload} call is actually an RPC
2782: to @var{task}, normally a send right for a task port, but potentially
2783: any send right. In addition to the normal diagnostic return codes
2784: from the call's server (normally the kernel), the call may return
2785: @code{mach_msg} return codes.
2786: @end deftypefun
1.1 root 2787:
2788: @node Port Sets
2789: @subsection Port Sets
2790:
2791: @deftypefun kern_return_t mach_port_get_set_status (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}}, @w{mach_port_array_t *@var{members}}, @w{mach_msg_type_number_t *@var{count}})
2792: The function @code{mach_port_get_set_status} returns the members of a
2793: port set. @var{members} is an array that is automatically allocated
2794: when the reply message is received. The user should
2795: @code{vm_deallocate} it when the data is no longer needed.
2796:
2797: The function returns @code{KERN_SUCCESS} if the call succeeded,
2798: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2799: @code{KERN_INVALID_NAME} if @var{name} did not denote a right,
2800: @code{KERN_INVALID_RIGHT} if @var{name} denoted a right, but not a
2801: receive right and @code{KERN_RESOURCE_SHORTAGE} if the kernel ran out of
2802: memory.
2803:
2804: The @code{mach_port_get_set_status} call is actually an RPC to
2805: @var{task}, normally a send right for a task port, but potentially any
2806: send right. In addition to the normal diagnostic return codes from the
2807: call's server (normally the kernel), the call may return @code{mach_msg}
2808: return codes.
2809: @end deftypefun
2810:
2811: @deftypefun kern_return_t mach_port_move_member (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{member}}, @w{mach_port_t @var{after}})
2812: The function @var{mach_port_move_member} moves the receive right
2813: @var{member} into the port set @var{after}. If the receive right is
2814: already a member of another port set, it is removed from that set first
2815: (the whole operation is atomic). If the port set is
2816: @code{MACH_PORT_NULL}, then the receive right is not put into a port
2817: set, but removed from its current port set.
2818:
2819: The function returns @code{KERN_SUCCESS} if the call succeeded,
2820: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2821: @code{KERN_INVALID_NAME} if @var{member} or @var{after} did not denote a
2822: right, @code{KERN_INVALID_RIGHT} if @var{member} denoted a right, but
2823: not a receive right or @var{after} denoted a right, but not a port set,
2824: and @code{KERN_NOT_IN_SET} if @var{after} was @code{MACH_PORT_NULL}, but
2825: @code{member} wasn't currently in a port set.
2826:
2827: The @code{mach_port_move_member} call is actually an RPC to @var{task},
2828: normally a send right for a task port, but potentially any send right.
2829: In addition to the normal diagnostic return codes from the call's server
2830: (normally the kernel), the call may return @code{mach_msg} return codes.
2831: @end deftypefun
2832:
2833:
2834: @node Request Notifications
2835: @subsection Request Notifications
2836:
2837: @deftypefun kern_return_t mach_port_request_notification (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}}, @w{mach_msg_id_t @var{variant}}, @w{mach_port_mscount_t @var{sync}}, @w{mach_port_t @var{notify}}, @w{mach_msg_type_name_t @var{notify_type}}, @w{mach_port_t *@var{previous}})
2838: The function @code{mach_port_request_notification} registers a request
2839: for a notification and supplies the send-once right @var{notify} to
2840: which the notification will be sent. The @var{notify_type} denotes the
2841: IPC type for the send-once right, which can be
2842: @code{MACH_MSG_TYPE_MAKE_SEND_ONCE} or
2843: @code{MACH_MSG_TYPE_MOVE_SEND_ONCE}. It is an atomic swap, returning
2844: the previously registered send-once right (or @code{MACH_PORT_NULL} for
2845: none) in @var{previous}. A previous notification request may be
2846: cancelled by providing @code{MACH_PORT_NULL} for @var{notify}.
2847:
2848: The @var{variant} argument takes the following values:
2849:
2850: @table @code
2851: @item MACH_NOTIFY_PORT_DESTROYED
2852: @var{sync} must be zero. The @var{name} must specify a receive right,
2853: and the call requests a port-destroyed notification for the receive
2854: right. If the receive right were to have been destroyed, say by
2855: @code{mach_port_destroy}, then instead the receive right will be sent in
2856: a port-destroyed notification to the registered send-once right.
2857:
2858: @item MACH_NOTIFY_DEAD_NAME
2859: The call requests a dead-name notification. @var{name} specifies send,
2860: receive, or send-once rights for a port. If the port is destroyed (and
2861: the right remains, becoming a dead name), then a dead-name notification
2862: which carries the name of the right will be sent to the registered
2863: send-once right. If @var{notify} is not null and sync is non-zero, the
2864: name may specify a dead name, and a dead-name notification is
2865: immediately generated.
2866:
2867: Whenever a dead-name notification is generated, the user reference count
2868: of the dead name is incremented. For example, a send right with two
2869: user refs has a registered dead-name request. If the port is destroyed,
2870: the send right turns into a dead name with three user refs (instead of
2871: two), and a dead-name notification is generated.
2872:
2873: If the name is made available for reuse, perhaps because of
2874: @code{mach_port_destroy} or @code{mach_port_mod_refs}, or the name
2875: denotes a send-once right which has a message sent to it, then the
2876: registered send-once right is used to generate a port-deleted
2877: notification.
2878:
2879: @item MACH_NOTIFY_NO_SENDERS
2880: The call requests a no-senders notification. @var{name} must specify a
2881: receive right. If @var{notify} is not null, and the receive right's
2882: make-send count is greater than or equal to the sync value, and it has
2883: no extant send rights, than an immediate no-senders notification is
2884: generated. Otherwise the notification is generated when the receive
2885: right next loses its last extant send right. In either case, any
2886: previously registered send-once right is returned.
2887:
2888: The no-senders notification carries the value the port's make-send count
2889: had when it was generated. The make-send count is incremented whenever
2890: @code{MACH_MSG_TYPE_MAKE_SEND} is used to create a new send right from
2891: the receive right. The make-send count is reset to zero when the
2892: receive right is carried in a message.
2893: @end table
2894:
2895: The function returns @code{KERN_SUCCESS} if the call succeeded,
2896: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2897: @code{KERN_INVALID_VALUE} if @var{variant} was invalid,
2898: @code{KERN_INVALID_NAME} if @var{name} did not denote a right,
2899: @code{KERN_INVALID_RIGHT} if @var{name} denoted an invalid right and
2900: @code{KERN_INVALID_CAPABILITY} if @var{notify} was invalid.
2901:
2902: When using @code{MACH_NOTIFY_PORT_DESTROYED}, the function returns
2903: @code{KERN_INVALID_VALUE} if @var{sync} wasn't zero.
2904:
2905: When using @code{MACH_NOTIFY_DEAD_NAME}, the function returns
2906: @code{KERN_RESOURCE_SHORTAGE} if the kernel ran out of memory,
2907: @code{KERN_INVALID_ARGUMENT} if @var{name} denotes a dead name, but
2908: @var{sync} is zero or @var{notify} is @code{MACH_PORT_NULL}, and
2909: @code{KERN_UREFS_OVERFLOW} if @var{name} denotes a dead name, but
2910: generating an immediate dead-name notification would overflow the name's
2911: user-reference count.
2912:
2913: The @code{mach_port_request_notification} call is actually an RPC to
2914: @var{task}, normally a send right for a task port, but potentially any
2915: send right. In addition to the normal diagnostic return codes from the
2916: call's server (normally the kernel), the call may return @code{mach_msg}
2917: return codes.
2918: @end deftypefun
2919:
1.1.1.3 root 2920: @node Inherited Ports
2921: @subsection Inherited Ports
1.1 root 2922:
1.1.1.3 root 2923: The inherited ports concept is not used in the Hurd, and so the _SLOT
2924: macros are not defined in GNU Mach.
1.1 root 2925:
1.1.1.3 root 2926: The following section documents how @code{mach_ports_register} and
2927: @code{mach_ports_lookup} were originally intended to be used.
2928:
2929: @deftypefun kern_return_t mach_ports_register (@w{task_t @var{target_task}}, @w{port_array_t @var{init_port_set}}, @w{int @var{init_port_array_count}})
2930: @deftypefunx kern_return_t mach_ports_lookup (@w{task_t @var{target_task}}, @w{port_array_t *@var{init_port_set}}, @w{int *@var{init_port_array_count}})
2931: @code{mach_ports_register} manipulates the inherited ports array,
2932: @code{mach_ports_lookup} is used to acquire specific parent ports.
2933: @var{target_task} is the task to be affected. @var{init_port_set} is an
2934: array of system ports to be registered, or returned. Although the array
2935: size is given as variable, the kernel will only accept a limited number
2936: of ports. @var{init_port_array_count} is the number of ports returned
2937: in @var{init_port_set}.
2938:
2939: @code{mach_ports_register} registers an array of well-known system ports
2940: with the kernel on behalf of a specific task. Currently the ports to be
2941: registered are: the port to the Network Name Server, the port to the
2942: Environment Manager, and a port to the Service server. These port
2943: values must be placed in specific slots in the init_port_set. The slot
2944: numbers are given by the global constants defined in @file{mach_init.h}:
2945: @code{NAME_SERVER_SLOT}, @code{ENVIRONMENT_SLOT}, and
2946: @code{SERVICE_SLOT}. These ports may later be retrieved with
2947: @code{mach_ports_lookup}.
2948:
2949: When a new task is created (see @code{task_create}), the child task will
2950: be given access to these ports. Only port send rights may be
2951: registered. Furthermore, the number of ports which may be registered is
2952: fixed and given by the global constant @code{MACH_PORT_SLOTS_USED}
2953: Attempts to register too many ports will fail.
2954:
2955: It is intended that this mechanism be used only for task initialization,
2956: and then only by runtime support modules. A parent task has three
2957: choices in passing these system ports to a child task. Most commonly it
2958: can do nothing and its child will inherit access to the same
2959: @var{init_port_set} that the parent has; or a parent task may register a
2960: set of ports it wishes to have passed to all of its children by calling
2961: @code{mach_ports_register} using its task port; or it may make necessary
2962: modifications to the set of ports it wishes its child to see, and then
2963: register those ports using the child's task port prior to starting the
2964: child's thread(s). The @code{mach_ports_lookup} call which is done by
2965: @code{mach_init} in the child task will acquire these initial ports for
2966: the child.
2967:
2968: Tasks other than the Network Name Server and the Environment Manager
2969: should not need access to the Service port. The Network Name Server port
2970: is the same for all tasks on a given machine. The Environment port is
2971: the only port likely to have different values for different tasks.
2972:
2973: Since the number of ports which may be registered is limited, ports
2974: other than those used by the runtime system to initialize a task should
2975: be passed to children either through an initial message, or through the
2976: Network Name Server for public ports, or the Environment Manager for
2977: private ports.
2978:
2979: The function returns @code{KERN_SUCCESS} if the memory was allocated,
2980: and @code{KERN_INVALID_ARGUMENT} if an attempt was made to register more
2981: ports than the current kernel implementation allows.
2982: @end deftypefun
1.1 root 2983:
2984:
2985: @node Virtual Memory Interface
2986: @chapter Virtual Memory Interface
2987:
2988: @cindex virtual memory map port
2989: @cindex port representing a virtual memory map
2990: @deftp {Data type} vm_task_t
2991: This is a @code{task_t} (and as such a @code{mach_port_t}), which holds
2992: a port name associated with a port that represents a virtual memory map
2993: in the kernel. An virtual memory map is used by the kernel to manage
2994: the address space of a task. The virtual memory map doesn't get a port
2995: name of its own. Instead the port name of the task provided with the
2996: virtual memory is used to name the virtual memory map of the task (as is
2997: indicated by the fact that the type of @code{vm_task_t} is actually
2998: @code{task_t}).
2999:
3000: The virtual memory maps of tasks are the only ones accessible outside of
3001: the kernel.
3002: @end deftp
3003:
3004: @menu
3005: * Memory Allocation:: Allocation of new virtual memory.
3006: * Memory Deallocation:: Freeing unused virtual memory.
3007: * Data Transfer:: Reading, writing and copying memory.
3008: * Memory Attributes:: Tweaking memory regions.
3009: * Mapping Memory Objects:: How to map memory objects.
3010: * Memory Statistics:: How to get statistics about memory usage.
3011: @end menu
3012:
3013: @node Memory Allocation
3014: @section Memory Allocation
3015:
3016: @deftypefun kern_return_t vm_allocate (@w{vm_task_t @var{target_task}}, @w{vm_address_t *@var{address}}, @w{vm_size_t @var{size}}, @w{boolean_t @var{anywhere}})
3017: The function @code{vm_allocate} allocates a region of virtual memory,
3018: placing it in the specified @var{task}'s address space.
3019:
3020: The starting address is @var{address}. If the @var{anywhere} option is
3021: false, an attempt is made to allocate virtual memory starting at this
3022: virtual address. If this address is not at the beginning of a virtual
3023: page, it will be rounded down to one. If there is not enough space at
3024: this address, no memory will be allocated. If the @var{anywhere} option
3025: is true, the input value of this address will be ignored, and the space
3026: will be allocated wherever it is available. In either case, the address
3027: at which memory was actually allocated will be returned in
3028: @var{address}.
3029:
3030: @var{size} is the number of bytes to allocate (rounded by the system in
3031: a machine dependent way to an integral number of virtual pages).
3032:
3033: If @var{anywhere} is true, the kernel should find and allocate any
3034: region of the specified size, and return the address of the resulting
3035: region in address address, rounded to a virtual page boundary if there
3036: is sufficient space.
3037:
3038: The physical memory is not actually allocated until the new virtual
3039: memory is referenced. By default, the kernel rounds all addresses down
3040: to the nearest page boundary and all memory sizes up to the nearest page
3041: size. The global variable @code{vm_page_size} contains the page size.
3042: @code{mach_task_self} returns the value of the current task port which
3043: should be used as the @var{target_task} argument in order to allocate
3044: memory in the caller's address space. For languages other than C, these
3045: values can be obtained by the calls @code{vm_statistics} and
3046: @code{mach_task_self}. Initially, the pages of allocated memory will be
3047: protected to allow all forms of access, and will be inherited in child
3048: tasks as a copy. Subsequent calls to @code{vm_protect} and
3049: @code{vm_inherit} may be used to change these properties. The allocated
3050: region is always zero-filled.
3051:
3052: The function returns @code{KERN_SUCCESS} if the memory was successfully
3053: allocated, @code{KERN_INVALID_ADDRESS} if an invalid address was
3054: specified and @code{KERN_NO_SPACE} if there was not enough space left to
3055: satisfy the request.
3056: @end deftypefun
3057:
3058:
3059: @node Memory Deallocation
3060: @section Memory Deallocation
3061:
3062: @deftypefun kern_return_t vm_deallocate (@w{vm_task_t @var{target_task}}, @w{vm_address_t @var{address}}, @w{vm_size_t @var{size}})
3063: @code{vm_deallocate} relinquishes access to a region of a @var{task}'s
3064: address space, causing further access to that memory to fail. This
3065: address range will be available for reallocation. @var{address} is the
3066: starting address, which will be rounded down to a page boundary.
3067: @var{size} is the number of bytes to deallocate, which will be rounded
3068: up to give a page boundary. Note, that because of the rounding to
3069: virtual page boundaries, more than @var{size} bytes may be deallocated.
3070: Use @code{vm_page_size} or @code{vm_statistics} to find out the current
3071: virtual page size.
3072:
1.1.1.2 root 3073: This call may be used to deallocate memory that was passed to a task in a
1.1 root 3074: message (via out of line data). In that case, the rounding should cause
3075: no trouble, since the region of memory was allocated as a set of pages.
3076:
3077: The @code{vm_deallocate} call affects only the task specified by the
3078: @var{target_task}. Other tasks which may have access to this memory may
3079: continue to reference it.
3080:
3081: The function returns @code{KERN_SUCCESS} if the memory was successfully
3082: deallocated and @code{KERN_INVALID_ADDRESS} if an invalid or
3083: non-allocated address was specified.
3084: @end deftypefun
3085:
3086:
3087: @node Data Transfer
3088: @section Data Transfer
3089:
3090: @deftypefun kern_return_t vm_read (@w{vm_task_t @var{target_task}}, @w{vm_address_t @var{address}}, @w{vm_size_t @var{size}}, @w{vm_offset_t *@var{data}}, @w{mach_msg_type_number_t *@var{data_count}})
3091: The function @code{vm_read} allows one task's virtual memory to be read
3092: by another task. The @var{target_task} is the task whose memory is to
3093: be read. @var{address} is the first address to be read and must be on a
3094: page boundary. @var{size} is the number of bytes of data to be read and
3095: must be an integral number of pages. @var{data} is the array of data
3096: copied from the given task, and @var{data_count} is the size of the data
3097: array in bytes (will be an integral number of pages).
3098:
3099: Note that the data array is returned in a newly allocated region; the
3100: task reading the data should @code{vm_deallocate} this region when it is
3101: done with the data.
3102:
3103: The function returns @code{KERN_SUCCESS} if the memory was successfully
3104: read, @code{KERN_INVALID_ADDRESS} if an invalid or non-allocated address
3105: was specified or there was not @var{size} bytes of data following the
3106: address, @code{KERN_INVALID_ARGUMENT} if the address does not start on a
3107: page boundary or the size is not an integral number of pages,
3108: @code{KERN_PROTECTION_FAILURE} if the address region in the target task
3109: is protected against reading and @code{KERN_NO_SPACE} if there was not
3110: enough room in the callers virtual memory to allocate space for the data
3111: to be returned.
3112: @end deftypefun
3113:
3114: @deftypefun kern_return_t vm_write (@w{vm_task_t @var{target_task}}, @w{vm_address_t @var{address}}, @w{vm_offset_t @var{data}}, @w{mach_msg_type_number_t @var{data_count}})
1.1.1.2 root 3115: The function @code{vm_write} allows a task to write to the virtual memory
1.1 root 3116: of @var{target_task}. @var{address} is the starting address in task to
3117: be affected. @var{data} is an array of bytes to be written, and
3118: @var{data_count} the size of the @var{data} array.
3119:
3120: The current implementation requires that @var{address}, @var{data} and
3121: @var{data_count} all be page-aligned. Otherwise,
3122: @code{KERN_INVALID_ARGUMENT} is returned.
3123:
3124: The function returns @code{KERN_SUCCESS} if the memory was successfully
3125: written, @code{KERN_INVALID_ADDRESS} if an invalid or non-allocated
3126: address was specified or there was not @var{data_count} bytes of
3127: allocated memory starting at @var{address} and
3128: @code{KERN_PROTECTION_FAILURE} if the address region in the target task
3129: is protected against writing.
3130: @end deftypefun
3131:
3132: @deftypefun kern_return_t vm_copy (@w{vm_task_t @var{target_task}}, @w{vm_address_t @var{source_address}}, @w{vm_size_t @var{count}}, @w{vm_offset_t @var{dest_address}})
3133: The function @code{vm_copy} causes the source memory range to be copied
3134: to the destination address. The source and destination memory ranges
3135: may overlap. The destination address range must already be allocated
3136: and writable; the source range must be readable.
3137:
3138: @code{vm_copy} is equivalent to @code{vm_read} followed by
3139: @code{vm_write}.
3140:
3141: The current implementation requires that @var{address}, @var{data} and
3142: @var{data_count} all be page-aligned. Otherwise,
3143: @code{KERN_INVALID_ARGUMENT} is returned.
3144:
3145: The function returns @code{KERN_SUCCESS} if the memory was successfully
3146: written, @code{KERN_INVALID_ADDRESS} if an invalid or non-allocated
3147: address was specified or there was insufficient memory allocated at one
3148: of the addresses and @code{KERN_PROTECTION_FAILURE} if the destination
3149: region was not writable or the source region was not readable.
3150: @end deftypefun
3151:
3152:
3153: @node Memory Attributes
3154: @section Memory Attributes
3155:
3156: @deftypefun kern_return_t vm_region (@w{vm_task_t @var{target_task}}, @w{vm_address_t *@var{address}}, @w{vm_size_t *@var{size}}, @w{vm_prot_t *@var{protection}}, @w{vm_prot_t *@var{max_protection}}, @w{vm_inherit_t *@var{inheritance}}, @w{boolean_t *@var{shared}}, @w{memory_object_name_t *@var{object_name}}, @w{vm_offset_t *@var{offset}})
3157: The function @code{vm_region} returns a description of the specified
3158: region of @var{target_task}'s virtual address space. @code{vm_region}
3159: begins at @var{address} and looks forward through memory until it comes
3160: to an allocated region. If address is within a region, then that region
3161: is used. Various bits of information about the region are returned. If
3162: @var{address} was not within a region, then @var{address} is set to the
3163: start of the first region which follows the incoming value. In this way
3164: an entire address space can be scanned.
3165:
3166: The @var{size} returned is the size of the located region in bytes.
3167: @var{protection} is the current protection of the region,
3168: @var{max_protection} is the maximum allowable protection for this
3169: region. @var{inheritance} is the inheritance attribute for this region.
3170: @var{shared} tells if the region is shared or not. The port
3171: @var{object_name} identifies the memory object associated with this
3172: region, and @var{offset} is the offset into the pager object that this
3173: region begins at.
3174: @c XXX cross ref pager_init
3175:
3176: The function returns @code{KERN_SUCCESS} if the memory region was
3177: successfully located and the information returned and @code{KERN_NO_SPACE} if
3178: there is no region at or above @var{address} in the specified task.
3179: @end deftypefun
3180:
3181: @deftypefun kern_return_t vm_protect (@w{vm_task_t @var{target_task}}, @w{vm_address_t @var{address}}, @w{vm_size_t @var{size}}, @w{boolean_t @var{set_maximum}}, @w{vm_prot_t @var{new_protection}})
3182: The function @code{vm_protect} sets the virtual memory access privileges
3183: for a range of allocated addresses in @var{target_task}'s virtual
3184: address space. The protection argument describes a combination of read,
3185: write, and execute accesses that should be @emph{permitted}.
3186:
3187: @var{address} is the starting address, which will be rounded down to a
3188: page boundary. @var{size} is the size in bytes of the region for which
3189: protection is to change, and will be rounded up to give a page boundary.
3190: If @var{set_maximum} is set, make the protection change apply to the
3191: maximum protection associated with this address range; otherwise, the
3192: current protection on this range is changed. If the maximum protection
3193: is reduced below the current protection, both will be changed to reflect
3194: the new maximum. @var{new_protection} is the new protection value for
3195: this region; a set of: @code{VM_PROT_READ}, @code{VM_PROT_WRITE},
3196: @code{VM_PROT_EXECUTE}.
3197:
3198: The enforcement of virtual memory protection is machine-dependent.
3199: Nominally read access requires @code{VM_PROT_READ} permission, write
3200: access requires @code{VM_PROT_WRITE} permission, and execute access
3201: requires @code{VM_PROT_EXECUTE} permission. However, some combinations
3202: of access rights may not be supported. In particular, the kernel
3203: interface allows write access to require @code{VM_PROT_READ} and
3204: @code{VM_PROT_WRITE} permission and execute access to require
3205: @code{VM_PROT_READ} permission.
3206:
3207: The function returns @code{KERN_SUCCESS} if the memory was successfully
3208: protected, @code{KERN_INVALID_ADDRESS} if an invalid or non-allocated
3209: address was specified and @code{KERN_PROTECTION_FAILURE} if an attempt
3210: was made to increase the current or maximum protection beyond the
3211: existing maximum protection value.
3212: @end deftypefun
3213:
3214: @deftypefun kern_return_t vm_inherit (@w{vm_task_t @var{target_task}}, @w{vm_address_t @var{address}}, @w{vm_size_t @var{size}}, @w{vm_inherit_t @var{new_inheritance}})
3215: The function @code{vm_inherit} specifies how a region of
3216: @var{target_task}'s address space is to be passed to child tasks at the
3217: time of task creation. Inheritance is an attribute of virtual pages, so
3218: @var{address} to start from will be rounded down to a page boundary and
1.1.1.2 root 3219: @var{size}, the size in bytes of the region for which inheritance is to
1.1 root 3220: change, will be rounded up to give a page boundary. How this memory is
3221: to be inherited in child tasks is specified by @var{new_inheritance}.
3222: Inheritance is specified by using one of these following three values:
3223:
3224: @table @code
3225: @item VM_INHERIT_SHARE
3226: Child tasks will share this memory with this task.
3227:
3228: @item VM_INHERIT_COPY
3229: Child tasks will receive a copy of this region.
3230:
3231: @item VM_INHERIT_NONE
3232: This region will be absent from child tasks.
3233: @end table
3234:
3235: Setting @code{vm_inherit} to @code{VM_INHERIT_SHARE} and forking a child
3236: task is the only way two Mach tasks can share physical memory. Remember
1.1.1.2 root 3237: that all the threads of a given task share all the same memory.
1.1 root 3238:
3239: The function returns @code{KERN_SUCCESS} if the memory inheritance was
3240: successfully set and @code{KERN_INVALID_ADDRESS} if an invalid or
3241: non-allocated address was specified.
3242: @end deftypefun
3243:
1.1.1.4 root 3244: @deftypefun kern_return_t vm_wire (@w{host_t @var{host}}, @w{vm_task_t @var{target_task}}, @w{vm_address_t @var{address}}, @w{vm_size_t @var{size}}, @w{vm_prot_t @var{access}})
3245: The function @code{vm_wire} allows applications to control
3246: memory pageability. @var{host} is the host port for the
1.1 root 3247: host on which @var{target_task} resides. @var{address} is the starting
3248: address, which will be rounded down to a page boundary. @var{size} is
3249: the size in bytes of the region for which protection is to change, and
3250: will be rounded up to give a page boundary. @var{access} specifies the
1.1.1.4 root 3251: types of accesses that must not cause page faults. If the host port is
3252: not privileged, the amount of memory is limited per task.
1.1 root 3253:
3254: The semantics of a successful @code{vm_wire} operation are that memory
3255: in the specified range will not cause page faults for any accesses
3256: included in access. Data memory can be made non-pageable (wired) with a
3257: access argument of @code{VM_PROT_READ | VM_PROT_WRITE}. A special case
3258: is that @code{VM_PROT_NONE} makes the memory pageable.
3259:
3260: The function returns @code{KERN_SUCCESS} if the call succeeded,
1.1.1.4 root 3261: @code{KERN_INVALID_HOST} if @var{host} was not a valid host
1.1 root 3262: port, @code{KERN_INVALID_TASK} if @var{task} was not a valid task,
3263: @code{KERN_INVALID_VALUE} if @var{access} specified an invalid access
3264: mode, @code{KERN_FAILURE} if some memory in the specified range is not
3265: present or has an inappropriate protection value, and
3266: @code{KERN_INVALID_ARGUMENT} if unwiring (@var{access} is
3267: @code{VM_PROT_NONE}) and the memory is not already wired.
3268:
1.1.1.4 root 3269: The @code{vm_wire} call is actually an RPC to @var{host}, normally
1.1 root 3270: a send right for a privileged host port, but potentially any send right.
3271: In addition to the normal diagnostic return codes from the call's server
3272: (normally the kernel), the call may return @code{mach_msg} return codes.
3273: @end deftypefun
3274:
3275: @deftypefun kern_return_t vm_machine_attribute (@w{vm_task_t @var{task}}, @w{vm_address_t @var{address}}, @w{vm_size_t @var{size}}, @w{vm_prot_t @var{access}}, @w{vm_machine_attribute_t @var{attribute}}, @w{vm_machine_attribute_val_t @var{value}})
3276: The function @code{vm_machine_attribute} specifies machine-specific
3277: attributes for a VM mapping, such as cachability, migrability,
3278: replicability. This is used on machines that allow the user control
3279: over the cache (this is the case for MIPS architectures) or placement of
3280: memory pages as in NUMA architectures (Non-Uniform Memory Access time)
3281: such as the IBM ACE multiprocessor.
3282:
3283: Machine-specific attributes can be consider additions to the
3284: machine-independent ones such as protection and inheritance, but they
3285: are not guaranteed to be supported by any given machine. Moreover,
3286: implementations of Mach on new architectures might find the need for new
3287: attribute types and or values besides the ones defined in the initial
3288: implementation.
3289:
3290: The types currently defined are
3291: @table @code
3292: @item MATTR_CACHE
3293: Controls caching of memory pages
3294:
3295: @item MATTR_MIGRATE
3296: Controls migrability of memory pages
3297:
3298: @item MATTR_REPLICATE
3299: Controls replication of memory pages
3300: @end table
3301:
3302: Corresponding values, and meaning of a specific call to
3303: @code{vm_machine_attribute}
3304: @table @code
3305: @item MATTR_VAL_ON
3306: Enables the attribute. Being enabled is the default value for any
3307: applicable attribute.
3308:
3309: @item MATTR_VAL_OFF
3310: Disables the attribute, making memory non-cached, or non-migratable, or
3311: non-replicatable.
3312:
3313: @item MATTR_VAL_GET
3314: Returns the current value of the attribute for the memory segment. If
3315: the attribute does not apply uniformly to the given range the value
3316: returned applies to the initial portion of the segment only.
3317:
3318: @item MATTR_VAL_CACHE_FLUSH
3319: Flush the memory pages from the Cache. The size value in this case
3320: might be meaningful even if not a multiple of the page size, depending
3321: on the implementation.
3322:
3323: @item MATTR_VAL_ICACHE_FLUSH
3324: Same as above, applied to the Instruction Cache alone.
3325:
3326: @item MATTR_VAL_DCACHE_FLUSH
3327: Same as above, applied to the Data Cache alone.
3328: @end table
3329:
3330: The function returns @code{KERN_SUCCESS} if call succeeded, and
3331: @code{KERN_INVALID_ARGUMENT} if @var{task} is not a task, or
3332: @var{address} and @var{size} do not define a valid address range in
3333: task, or @var{attribute} is not a valid attribute type, or it is not
3334: implemented, or @var{value} is not a permissible value for attribute.
3335: @end deftypefun
3336:
3337:
3338: @node Mapping Memory Objects
3339: @section Mapping Memory Objects
3340:
3341: @deftypefun kern_return_t vm_map (@w{vm_task_t @var{target_task}}, @w{vm_address_t *@var{address}}, @w{vm_size_t @var{size}}, @w{vm_address_t @var{mask}}, @w{boolean_t @var{anywhere}}, @w{memory_object_t @var{memory_object}}, @w{vm_offset_t @var{offset}}, @w{boolean_t @var{copy}}, @w{vm_prot_t @var{cur_protection}}, @w{vm_prot_t @var{max_protection}}, @w{vm_inherit_t @var{inheritance}})
3342: The function @code{vm_map} maps a region of virtual memory at the
3343: specified address, for which data is to be supplied by the given memory
3344: object, starting at the given offset within that object. In addition to
3345: the arguments used in @code{vm_allocate}, the @code{vm_map} call allows
3346: the specification of an address alignment parameter, and of the initial
3347: protection and inheritance values.
3348: @c XXX See the descriptions of vm_allocate, vm_protect , and vm_inherit
3349:
3350: If the memory object in question is not currently in use, the kernel
3351: will perform a @code{memory_object_init} call at this time. If the copy
3352: parameter is asserted, the specified region of the memory object will be
3353: copied to this address space; changes made to this object by other tasks
3354: will not be visible in this mapping, and changes made in this mapping
3355: will not be visible to others (or returned to the memory object).
3356:
3357: The @code{vm_map} call returns once the mapping is established.
3358: Completion of the call does not require any action on the part of the
3359: memory manager.
3360:
3361: Warning: Only memory objects that are provided by bona fide memory
3362: managers should be used in the @code{vm_map} call. A memory manager
3363: must implement the memory object interface described elsewhere in this
3364: manual. If other ports are used, a thread that accesses the mapped
3365: virtual memory may become permanently hung or may receive a memory
3366: exception.
3367:
3368: @var{target_task} is the task to be affected. The starting address is
3369: @var{address}. If the @var{anywhere} option is used, this address is
1.1.1.3 root 3370: used as a starting hint. The address actually allocated will be returned in
1.1 root 3371: @var{address}. @var{size} is the number of bytes to allocate (rounded by
3372: the system in a machine dependent way). The alignment restriction is
3373: specified by @var{mask}. Bits asserted in this mask must not be
3374: asserted in the address returned. If @var{anywhere} is set, the kernel
3375: should find and allocate any region of the specified size, and return
3376: the address of the resulting region in @var{address}.
3377:
3378: @var{memory_object} is the port that represents the memory object: used
3379: by user tasks in @code{vm_map}; used by the make requests for data or
3380: other management actions. If this port is @code{MEMORY_OBJECT_NULL},
3381: then zero-filled memory is allocated instead. Within a memory object,
1.1.1.2 root 3382: @var{offset} specifies an offset in bytes. This must be page aligned.
1.1 root 3383: If @var{copy} is set, the range of the memory object should be copied to
3384: the target task, rather than mapped read-write.
3385:
3386: The function returns @code{KERN_SUCCESS} if the object is mapped,
3387: @code{KERN_NO_SPACE} if no unused region of the task's virtual address
3388: space that meets the address, size, and alignment criteria could be
3389: found, and @code{KERN_INVALID_ARGUMENT} if an invalid argument was provided.
3390: @end deftypefun
3391:
3392:
3393: @node Memory Statistics
3394: @section Memory Statistics
3395:
3396: @deftp {Data type} vm_statistics_data_t
3397: This structure is returned in @var{vm_stats} by the @code{vm_statistics}
3398: function and provides virtual memory statistics for the system. It has
3399: the following members:
3400:
3401: @table @code
3402: @item long pagesize
3403: The page size in bytes.
3404:
3405: @item long free_count
3406: The number of free pages.
3407:
3408: @item long active_count
3409: The umber of active pages.
3410:
3411: @item long inactive_count
3412: The number of inactive pages.
3413:
3414: @item long wire_count
3415: The number of pages wired down.
3416:
3417: @item long zero_fill_count
3418: The number of zero filled pages.
3419:
3420: @item long reactivations
3421: The number of reactivated pages.
3422:
3423: @item long pageins
3424: The number of pageins.
3425:
3426: @item long pageouts
3427: The number of pageouts.
3428:
3429: @item long faults
3430: The number of faults.
3431:
3432: @item long cow_faults
3433: The number of copy-on-writes.
3434:
3435: @item long lookups
3436: The number of object cache lookups.
3437:
3438: @item long hits
3439: The number of object cache hits.
3440: @end table
3441: @end deftp
3442:
3443: @deftypefun kern_return_t vm_statistics (@w{vm_task_t @var{target_task}}, @w{vm_statistics_data_t *@var{vm_stats}})
3444: The function @code{vm_statistics} returns the statistics about the
3445: kernel's use of virtual memory since the kernel was booted.
3446: @code{pagesize} can also be found as a global variable
3447: @code{vm_page_size} which is set at task initialization and remains
3448: constant for the life of the task.
3449: @end deftypefun
3450:
3451:
3452: @node External Memory Management
3453: @chapter External Memory Management
3454:
3455: @menu
3456: * Memory Object Server:: The basics of external memory management.
3457: * Memory Object Creation:: How new memory objects are created.
3458: * Memory Object Termination:: How memory objects are terminated.
3459: * Memory Objects and Data:: Data transfer to and from memory objects.
3460: * Memory Object Locking:: How memory objects are locked.
3461: * Memory Object Attributes:: Manipulating attributes of memory objects.
3462: * Default Memory Manager:: Setting and using the default memory manager.
3463: @end menu
3464:
3465:
3466: @node Memory Object Server
3467: @section Memory Object Server
3468:
3469: @deftypefun boolean_t memory_object_server (@w{msg_header_t *@var{in_msg}}, @w{msg_header_t *@var{out_msg}})
3470: @deftypefunx boolean_t memory_object_default_server (@w{msg_header_t *@var{in_msg}}, @w{msg_header_t *@var{out_msg}})
3471: @deftypefunx boolean_t seqnos_memory_object_server (@w{msg_header_t *@var{in_msg}}, @w{msg_header_t *@var{out_msg}})
3472: @deftypefunx boolean_t seqnos_memory_object_default_server (@w{msg_header_t *@var{in_msg}}, @w{msg_header_t *@var{out_msg}})
3473: A memory manager is a server task that responds to specific messages
3474: from the kernel in order to handle memory management functions for the
3475: kernel.
3476:
3477: In order to isolate the memory manager from the specifics of message
3478: formatting, the remote procedure call generator produces a procedure,
3479: @code{memory_object_server}, to handle a received message. This
3480: function does all necessary argument handling, and actually calls one of
3481: the following functions: @code{memory_object_init},
3482: @code{memory_object_data_write}, @code{memory_object_data_return},
3483: @code{memory_object_data_request}, @code{memory_object_data_unlock},
3484: @code{memory_object_lock_completed}, @code{memory_object_copy},
3485: @code{memory_object_terminate}. The @strong{default memory manager} may
3486: get two additional requests from the kernel: @code{memory_object_create}
3487: and @code{memory_object_data_initialize}. The remote procedure call
3488: generator produces a procedure @code{memory_object_default_server} to
3489: handle those functions specific to the default memory manager.
3490:
3491: The @code{seqnos_memory_object_server} and
3492: @code{seqnos_memory_object_default_server} differ from
3493: @code{memory_object_server} and @code{memory_object_default_server} in
3494: that they supply message sequence numbers to the server interfaces.
3495: They call the @code{seqnos_memory_object_*} functions, which complement
3496: the @code{memory_object_*} set of functions.
3497:
3498: The return value from the @code{memory_object_server} function indicates
3499: that the message was appropriate to the memory management interface
3500: (returning @code{TRUE}), or that it could not handle this message
3501: (returning @code{FALSE}).
3502:
3503: The @var{in_msg} argument is the message that has been received from the
3504: kernel. The @var{out_msg} is a reply message, but this is not used for
3505: this server.
3506:
3507: The function returns @code{TRUE} to indicate that the message in
3508: question was applicable to this interface, and that the appropriate
3509: routine was called to interpret the message. It returns @code{FALSE} to
3510: indicate that the message did not apply to this interface, and that no
3511: other action was taken.
3512: @end deftypefun
3513:
3514:
3515: @node Memory Object Creation
3516: @section Memory Object Creation
3517:
3518: @deftypefun kern_return_t memory_object_init (@w{memory_object_t @var{memory_object}}, @w{memory_object_control_t @var{memory_control}}, @w{memory_object_name_t @var{memory_object_name}}, @w{vm_size_t @var{memory_object_page_size}})
3519: @deftypefunx kern_return_t seqnos_memory_object_init (@w{memory_object_t @var{memory_object}}, @w{mach_port_seqno_t @var{seqno}}, @w{memory_object_control_t @var{memory_control}}, @w{memory_object_name_t @var{memory_object_name}}, @w{vm_size_t @var{memory_object_page_size}})
3520: The function @code{memory_object_init} serves as a notification that the
3521: kernel has been asked to map the given memory object into a task's
3522: virtual address space. Additionally, it provides a port on which the
3523: memory manager may issue cache management requests, and a port which the
3524: kernel will use to name this data region. In the event that different
3525: each will perform a @code{memory_object_init} call with new request and
3526: name ports. The virtual page size that is used by the calling kernel is
3527: included for planning purposes.
3528:
1.1.1.5 ! root 3529: When the memory manager is prepared to accept requests for data for
! 3530: this object, it must call @code{memory_object_ready}, or set the ready
! 3531: flag using @code{memory_object_set_attributes}.
1.1 root 3532: Otherwise the kernel will not process requests on this object. To
3533: reject all mappings of this object, the memory manager may use
3534: @code{memory_object_destroy}.
3535:
3536: The argument @var{memory_object} is the port that represents the memory
3537: object data, as supplied to the kernel in a @code{vm_map} call.
3538: @var{memory_control} is the request port to which a response is
3539: requested. (In the event that a memory object has been supplied to more
3540: than one the kernel that has made the request.)
3541: @var{memory_object_name} is a port used by the kernel to refer to the
1.1.1.2 root 3542: memory object data in response to @code{vm_region} calls.
1.1 root 3543: @code{memory_object_page_size} is the page size to be used by this
3544: kernel. All data sizes in calls involving this kernel must be an
3545: integral multiple of the page size. Note that different kernels,
3546: indicated by a different @code{memory_control}, may have different page
3547: sizes.
3548:
3549: The function should return @code{KERN_SUCCESS}, but since this routine
3550: is called by the kernel, which does not wait for a reply message, this
3551: value is ignored.
3552: @end deftypefun
3553:
3554: @deftypefun kern_return_t memory_object_ready (@w{memory_object_control_t @var{memory_control}}, @w{boolean_t @var{may_cache_object}}, @w{memory_object_copy_strategy_t @var{copy_strategy}})
3555: The function @code{memory_object_ready} informs the kernel that the
3556: memory manager is ready to receive data or unlock requests on behalf of
3557: the clients. The argument @var{memory_control} is the port, provided by
3558: the kernel in a @code{memory_object_init} call, to which cache
3559: management requests may be issued. If @var{may_cache_object} is set,
3560: the kernel may keep data associated with this memory object, even after
3561: virtual memory references to it are gone.
3562:
3563: @var{copy_strategy} tells how the kernel should copy regions of the
3564: associated memory object. There are three possible caching strategies:
3565: @code{MEMORY_OBJECT_COPY_NONE} which specifies that nothing special
3566: should be done when data in the object is copied;
3567: @code{MEMORY_OBJECT_COPY_CALL} which specifies that the memory manager
3568: should be notified via a @code{memory_object_copy} call before any part
3569: of the object is copied; and @code{MEMORY_OBJECT_COPY_DELAY} which
3570: guarantees that the memory manager does not externally modify the data
3571: so that the kernel can use its normal copy-on-write algorithms.
3572: @code{MEMORY_OBJECT_COPY_DELAY} is the strategy most commonly used.
3573:
3574: This routine does not receive a reply message (and consequently has no
3575: return value), so only message transmission errors apply.
3576: @end deftypefun
3577:
3578:
3579: @node Memory Object Termination
3580: @section Memory Object Termination
3581:
3582: @deftypefun kern_return_t memory_object_terminate (@w{memory_object_t @var{memory_object}}, @w{memory_object_control_t @var{memory_control}}, @w{memory_object_name_t @var{memory_object_name}})
3583: @deftypefunx kern_return_t seqnos_memory_object_terminate (@w{memory_object_t @var{memory_object}}, @w{mach_port_seqno_t @var{seqno}}, @w{memory_object_control_t @var{memory_control}}, @w{memory_object_name_t @var{memory_object_name}})
3584: The function @code{memory_object_terminate} indicates that the kernel
3585: has completed its use of the given memory object. All rights to the
3586: memory object control and name ports are included, so that the memory
3587: manager can destroy them (using @code{mach_port_deallocate}) after doing
3588: appropriate bookkeeping. The kernel will terminate a memory object only
3589: after all address space mappings of that memory object have been
3590: deallocated, or upon explicit request by the memory manager.
3591:
3592: The argument @var{memory_object} is the port that represents the memory
3593: object data, as supplied to the kernel in a @code{vm_map} call.
3594: @var{memory_control} is the request port to which a response is
3595: requested. (In the event that a memory object has been supplied to more
3596: than one the kernel that has made the request.)
3597: @var{memory_object_name} is a port used by the kernel to refer to the
1.1.1.2 root 3598: memory object data in response to @code{vm_region} calls.
1.1 root 3599:
3600: The function should return @code{KERN_SUCCESS}, but since this routine
3601: is called by the kernel, which does not wait for a reply message, this
3602: value is ignored.
3603: @end deftypefun
3604:
3605: @deftypefun kern_return_t memory_object_destroy (@w{memory_object_control_t @var{memory_control}}, @w{kern_return_t @var{reason}})
3606: The function @code{memory_object_destroy} tells the kernel to shut down
3607: the memory object. As a result of this call the kernel will no longer
3608: support paging activity or any @code{memory_object} calls on this
3609: object, and all rights to the memory object port, the memory control
3610: port and the memory name port will be returned to the memory manager in
3611: a memory_object_terminate call. If the memory manager is concerned that
3612: any modified cached data be returned to it before the object is
3613: terminated, it should call @code{memory_object_lock_request} with
3614: @var{should_flush} set and a lock value of @code{VM_PROT_WRITE} before
3615: making this call.
3616:
3617: The argument @var{memory_control} is the port, provided by the kernel in
3618: a @code{memory_object_init} call, to which cache management requests may
3619: be issued. @var{reason} is an error code indicating why the object
3620: must be destroyed.
1.1.1.2 root 3621: @c The error code is currently ignored.
1.1 root 3622:
3623: This routine does not receive a reply message (and consequently has no
3624: return value), so only message transmission errors apply.
3625: @end deftypefun
3626:
3627:
3628: @node Memory Objects and Data
3629: @section Memory Objects and Data
3630:
3631: @deftypefun kern_return_t memory_object_data_return (@w{memory_object_t @var{memory_object}}, @w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_offset_t @var{data}}, @w{vm_size_t @var{data_count}}, @w{boolean_t @var{dirty}}, @w{boolean_t @var{kernel_copy}})
3632: @deftypefunx kern_return_t seqnos_memory_object_data_return (@w{memory_object_t @var{memory_object}}, @w{mach_port_seqno_t @var{seqno}}, @w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_offset_t @var{data}}, @w{vm_size_t @var{data_count}}, @w{boolean_t @var{dirty}}, @w{boolean_t @var{kernel_copy}})
3633: The function @code{memory_object_data_return} provides the memory
3634: manager with data that has been modified while cached in physical
3635: memory. Once the memory manager no longer needs this data (e.g., it has
3636: been written to another storage medium), it should be deallocated using
3637: @code{vm_deallocate}.
3638:
3639: The argument @var{memory_object} is the port that represents the memory
3640: object data, as supplied to the kernel in a @code{vm_map} call.
3641: @var{memory_control} is the request port to which a response is
3642: requested. (In the event that a memory object has been supplied to more
3643: than one the kernel that has made the request.) @var{offset} is the
3644: offset within a memory object to which this call refers. This will be
3645: page aligned. @var{data} is the data which has been modified while
3646: cached in physical memory. @var{data_count} is the amount of data to be
3647: written, in bytes. This will be an integral number of memory object
3648: pages.
3649:
3650: The kernel will also use this call to return precious pages. If an
3651: unmodified precious age is returned, @var{dirty} is set to @code{FALSE},
3652: otherwise it is @code{TRUE}. If @var{kernel_copy} is @code{TRUE}, the
3653: kernel kept a copy of the page. Precious data remains precious if the
3654: kernel keeps a copy. The indication that the kernel kept a copy is only
3655: a hint if the data is not precious; the cleaned copy may be discarded
3656: without further notifying the manager.
3657:
3658: The function should return @code{KERN_SUCCESS}, but since this routine
3659: is called by the kernel, which does not wait for a reply message, this
3660: value is ignored.
3661: @end deftypefun
3662:
3663: @deftypefun kern_return_t memory_object_data_request (@w{memory_object_t @var{memory_object}}, @w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_offset_t @var{length}}, @w{vm_prot_t @var{desired_access}})
3664: @deftypefunx kern_return_t seqnos_memory_object_data_request (@w{memory_object_t @var{memory_object}}, @w{mach_port_seqno_t @var{seqno}}, @w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_offset_t @var{length}}, @w{vm_prot_t @var{desired_access}})
3665: The function @code{memory_object_data_request} is a request for data
3666: from the specified memory object, for at least the access specified.
3667: The memory manager is expected to return at least the specified data,
3668: with as much access as it can allow, using
3669: @code{memory_object_data_supply}. If the memory manager is unable to
3670: provide the data (for example, because of a hardware error), it may use
3671: the @code{memory_object_data_error} call. The
3672: @code{memory_object_data_unavailable} call may be used to tell the
3673: kernel to supply zero-filled memory for this region.
3674:
3675: The argument @var{memory_object} is the port that represents the memory
3676: object data, as supplied to the kernel in a @code{vm_map} call.
3677: @var{memory_control} is the request port to which a response is
3678: requested. (In the event that a memory object has been supplied to more
3679: than one the kernel that has made the request.) @var{offset} is the
3680: offset within a memory object to which this call refers. This will be
3681: page aligned. @var{length} is the number of bytes of data, starting at
3682: @var{offset}, to which this call refers. This will be an integral
3683: number of memory object pages. @var{desired_access} is a protection
3684: value describing the memory access modes which must be permitted on the
3685: specified cached data. One or more of: @code{VM_PROT_READ},
3686: @code{VM_PROT_WRITE} or @code{VM_PROT_EXECUTE}.
3687:
3688: The function should return @code{KERN_SUCCESS}, but since this routine
3689: is called by the kernel, which does not wait for a reply message, this
3690: value is ignored.
3691: @end deftypefun
3692:
3693: @deftypefun kern_return_t memory_object_data_supply (@w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_offset_t @var{data}}, @w{vm_size_t @var{data_count}}, @w{vm_prot_t @var{lock_value}}, @w{boolean_t @var{precious}}, @w{mach_port_t @var{reply}})
3694: The function @code{memory_object_data_supply} supplies the kernel with
3695: data for the specified memory object. Ordinarily, memory managers
1.1.1.2 root 3696: should only provide data in response to @code{memory_object_data_request}
1.1 root 3697: calls from the kernel (but they may provide data in advance as desired).
3698: When data already held by this kernel is provided again, the new data is
3699: ignored. The kernel may not provide any data (or protection)
3700: consistency among pages with different virtual page alignments within
3701: the same object.
3702:
3703: The argument @var{memory_control} is the port, provided by the kernel in
3704: a @code{memory_object_init} call, to which cache management requests may
3705: be issued. @var{offset} is an offset within a memory object in bytes.
3706: This must be page aligned. @var{data} is the data that is being
3707: provided to the kernel. This is a pointer to the data.
3708: @var{data_count} is the amount of data to be provided. Only whole
3709: virtual pages of data can be accepted; partial pages will be discarded.
3710:
3711: @var{lock_value} is a protection value indicating those forms of access
3712: that should @strong{not} be permitted to the specified cached data. The
3713: lock values must be one or more of the set: @code{VM_PROT_NONE},
3714: @code{VM_PROT_READ}, @code{VM_PROT_WRITE}, @code{VM_PROT_EXECUTE} and
3715: @code{VM_PROT_ALL} as defined in @file{mach/vm_prot.h}.
3716:
3717: If @var{precious} is @code{FALSE}, the kernel treats the data as a
3718: temporary and may throw it away if it hasn't been changed. If the
3719: @var{precious} value is @code{TRUE}, the kernel treats its copy as a
3720: data repository and promises to return it to the manager; the manager
3721: may tell the kernel to throw it away instead by flushing and not
3722: cleaning the data (see @code{memory_object_lock_request}).
3723:
3724: If @var{reply_to} is not @code{MACH_PORT_NULL}, the kernel will send a
3725: completion message to the provided port (see
3726: @code{memory_object_supply_completed}).
3727:
3728: This routine does not receive a reply message (and consequently has no
3729: return value), so only message transmission errors apply.
3730: @end deftypefun
3731:
3732: @deftypefun kern_return_t memory_object_supply_completed (@w{memory_object_t @var{memory_object}}, @w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_size_t @var{length}}, @w{kern_return_t @var{result}}, @w{vm_offset_t @var{error_offset}})
3733: @deftypefunx kern_return_t seqnos_memory_object_supply_completed (@w{memory_object_t @var{memory_object}}, @w{mach_port_seqno_t @var{seqno}}, @w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_size_t @var{length}}, @w{kern_return_t @var{result}}, @w{vm_offset_t @var{error_offset}})
3734: The function @code{memory_object_supply_completed} indicates that a
3735: previous @code{memory_object_data_supply} has been completed. Note that
3736: this call is made on whatever port was specified in the
3737: @code{memory_object_data_supply} call; that port need not be the memory
3738: object port itself. No reply is expected after this call.
3739:
3740: The argument @var{memory_object} is the port that represents the memory
3741: object data, as supplied to the kernel in a @code{vm_map} call.
3742: @var{memory_control} is the request port to which a response is
3743: requested. (In the event that a memory object has been supplied to more
3744: than one the kernel that has made the request.) @var{offset} is the
3745: offset within a memory object to which this call refers. @var{length}
3746: is the length of the data covered by the lock request. The @var{result}
3747: parameter indicates what happened during the supply. If it is not
3748: @code{KERN_SUCCESS}, then @var{error_offset} identifies the first offset
3749: at which a problem occurred. The pagein operation stopped at this
3750: point. Note that the only failures reported by this mechanism are
3751: @code{KERN_MEMORY_PRESENT}. All other failures (invalid argument, error
3752: on pagein of supplied data in manager's address space) cause the entire
3753: operation to fail.
3754:
3755:
3756: @end deftypefun
3757:
3758: @deftypefun kern_return_t memory_object_data_error (@w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_size_t @var{size}}, @w{kern_return_t @var{reason}})
3759: The function @code{memory_object_data_error} indicates that the memory
3760: manager cannot return the data requested for the given region,
3761: specifying a reason for the error. This is typically used when a
3762: hardware error is encountered.
3763:
3764: The argument @var{memory_control} is the port, provided by the kernel in
3765: a @code{memory_object_init} call, to which cache management requests may
3766: be issued. @var{offset} is an offset within a memory object in bytes.
3767: This must be page aligned. @var{data} is the data that is being
3768: provided to the kernel. This is a pointer to the data. @var{size} is
3769: the amount of cached data (starting at @var{offset}) to be handled.
3770: This must be an integral number of the memory object page size.
1.1.1.2 root 3771: @var{reason} is an error code indicating what type of error occurred.
3772: @c The error code is currently ignored.
1.1 root 3773:
3774: This routine does not receive a reply message (and consequently has no
3775: return value), so only message transmission errors apply.
3776: @end deftypefun
3777:
3778: @deftypefun kern_return_t memory_object_data_unavailable (@w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_size_t @var{size}}, @w{kern_return_t @var{reason}})
3779: The function @code{memory_object_data_unavailable} indicates that the
3780: memory object does not have data for the given region and that the
3781: kernel should provide the data for this range. The memory manager may
3782: use this call in three different situations.
3783:
3784: @enumerate
3785: @item
3786: The object was created by @code{memory_object_create} and the kernel has
3787: not yet provided data for this range (either via a
3788: @code{memory_object_data_initialize}, @code{memory_object_data_write} or
3789: a @code{memory_object_data_return} for the object.
3790:
3791: @item
3792: The object was created by an @code{memory_object_data_copy} and the
3793: kernel should copy this region from the original memory object.
3794:
3795: @item
3796: The object is a normal user-created memory object and the kernel should
3797: supply unlocked zero-filled pages for the range.
3798: @end enumerate
3799:
3800: The argument @var{memory_control} is the port, provided by the kernel in
3801: a @code{memory_object_init} call, to which cache management requests may
3802: be issued. @var{offset} is an offset within a memory object, in bytes.
3803: This must be page aligned. @var{size} is the amount of cached data
3804: (starting at @var{offset}) to be handled. This must be an integral
3805: number of the memory object page size.
3806:
3807: This routine does not receive a reply message (and consequently has no
3808: return value), so only message transmission errors apply.
3809: @end deftypefun
3810:
3811: @deftypefun kern_return_t memory_object_copy (@w{memory_object_t @var{old_memory_object}}, @w{memory_object_control_t @var{old_memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_size_t @var{length}}, @w{memory_object_t @var{new_memory_object}})
3812: @deftypefunx kern_return_t seqnos_memory_object_copy (@w{memory_object_t @var{old_memory_object}}, @w{mach_port_seqno_t @var{seqno}}, @w{memory_object_control_t @var{old_memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_size_t @var{length}}, @w{memory_object_t @var{new_memory_object}})
3813: The function @code{memory_object_copy} indicates that a copy has been
3814: made of the specified range of the given original memory object. This
3815: call includes only the new memory object itself; a
3816: @code{memory_object_init} call will be made on the new memory object
3817: after the currently cached pages of the original object are prepared.
3818: After the memory manager receives the init call, it must reply with the
3819: @code{memory_object_ready} call to assert the "ready" attribute. The
3820: kernel will use the new memory object, control and name ports to refer
3821: to the new copy.
3822:
3823: This call is made when the original memory object had the caching
3824: parameter set to @code{MEMORY_OBJECT_COPY_CALL} and a user of the object
3825: has asked the kernel to copy it.
3826:
3827: Cached pages from the original memory object at the time of the copy
3828: operation are handled as follows: Readable pages may be silently copied
3829: to the new memory object (with all access permissions). Pages not
3830: copied are locked to prevent write access.
3831:
3832: The new memory object is @strong{temporary}, meaning that the memory
3833: manager should not change its contents or allow the memory object to be
3834: mapped in another client. The memory manager may use the
3835: @code{memory_object_data_unavailable} call to indicate that the
3836: appropriate pages of the original memory object may be used to fulfill
3837: the data request.
3838:
3839: The argument @var{old_memory_object} is the port that represents the old
3840: memory object data. @var{old_memory_control} is the kernel port for the
3841: old object. @var{offset} is the offset within a memory object to which
3842: this call refers. This will be page aligned. @var{length} is the
3843: number of bytes of data, starting at @var{offset}, to which this call
3844: refers. This will be an integral number of memory object pages.
3845: @var{new_memory_object} is a new memory object created by the kernel;
3846: see synopsis for further description. Note that all port rights
3847: (including receive rights) are included for the new memory object.
3848:
3849: The function should return @code{KERN_SUCCESS}, but since this routine
3850: is called by the kernel, which does not wait for a reply message, this
3851: value is ignored.
3852: @end deftypefun
3853:
1.1.1.2 root 3854: The remaining interfaces in this section are obsolete.
1.1 root 3855:
3856: @deftypefun kern_return_t memory_object_data_write (@w{memory_object_t @var{memory_object}}, @w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_offset_t @var{data}}, @w{vm_size_t @var{data_count}})
3857: @deftypefunx kern_return_t seqnos_memory_object_data_write (@w{memory_object_t @var{memory_object}}, @w{mach_port_seqno_t @var{seqno}}, @w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_offset_t @var{data}}, @w{vm_size_t @var{data_count}})
3858: The function @code{memory_object_data_write} provides the memory manager
3859: with data that has been modified while cached in physical memory. It is the old form of @code{memory_object_data_return}. Once
3860: the memory manager no longer needs this data (e.g., it has been written
3861: to another storage medium), it should be deallocated using
3862: @code{vm_deallocate}.
3863:
3864: The argument @var{memory_object} is the port that represents the memory
3865: object data, as supplied to the kernel in a @code{vm_map} call.
3866: @var{memory_control} is the request port to which a response is
3867: requested. (In the event that a memory object has been supplied to more
3868: than one the kernel that has made the request.) @var{offset} is the
3869: offset within a memory object to which this call refers. This will be
3870: page aligned. @var{data} is the data which has been modified while
3871: cached in physical memory. @var{data_count} is the amount of data to be
3872: written, in bytes. This will be an integral number of memory object
3873: pages.
3874:
3875: The function should return @code{KERN_SUCCESS}, but since this routine
3876: is called by the kernel, which does not wait for a reply message, this
3877: value is ignored.
3878: @end deftypefun
3879:
3880: @deftypefun kern_return_t memory_object_data_provided (@w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_offset_t @var{data}}, @w{vm_size_t @var{data_count}}, @w{vm_prot_t @var{lock_value}})
3881: The function @code{memory_object_data_provided} supplies the kernel with
3882: data for the specified memory object. It is the old form of
3883: @code{memory_object_data_supply}. Ordinarily, memory managers should
1.1.1.2 root 3884: only provide data in response to @code{memory_object_data_request} calls
1.1 root 3885: from the kernel. The @var{lock_value} specifies what type of access
3886: will not be allowed to the data range. The lock values must be one or
3887: more of the set: @code{VM_PROT_NONE}, @code{VM_PROT_READ},
3888: @code{VM_PROT_WRITE}, @code{VM_PROT_EXECUTE} and @code{VM_PROT_ALL} as
3889: defined in @file{mach/vm_prot.h}.
3890:
3891: The argument @var{memory_control} is the port, provided by the kernel in
3892: a @code{memory_object_init} call, to which cache management requests may
3893: be issued. @var{offset} is an offset within a memory object in bytes.
3894: This must be page aligned. @var{data} is the data that is being
3895: provided to the kernel. This is a pointer to the data.
3896: @var{data_count} is the amount of data to be provided. This must be an
3897: integral number of memory object pages. @var{lock_value} is a
3898: protection value indicating those forms of access that should
3899: @strong{not} be permitted to the specified cached data.
3900:
3901: This routine does not receive a reply message (and consequently has no
3902: return value), so only message transmission errors apply.
3903: @end deftypefun
3904:
3905:
3906: @node Memory Object Locking
3907: @section Memory Object Locking
3908:
3909: @deftypefun kern_return_t memory_object_lock_request (@w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_size_t @var{size}}, @w{memory_object_return_t @var{should_clean}}, @w{boolean_t @var{should_flush}}, @w{vm_prot_t @var{lock_value}}, @w{mach_port_t @var{reply_to}})
3910: The function @code{memory_object_lock_request} allows a memory manager
3911: to make cache management requests. As specified in arguments to the
3912: call, the kernel will:
3913: @itemize
3914: @item
3915: clean (i.e., write back using @code{memory_object_data_supply} or
3916: @code{memory_object_data_write}) any cached data which has been modified
3917: since the last time it was written
3918:
3919: @item
3920: flush (i.e., remove any uses of) that data from memory
3921:
3922: @item
3923: lock (i.e., prohibit the specified uses of) the cached data
3924: @end itemize
3925:
3926: Locks applied to cached data are not cumulative; new lock values
3927: override previous ones. Thus, data may also be unlocked using this
3928: primitive. The lock values must be one or more of the following values:
3929: @code{VM_PROT_NONE}, @code{VM_PROT_READ}, @code{VM_PROT_WRITE},
3930: @code{VM_PROT_EXECUTE} and @code{VM_PROT_ALL} as defined in
3931: @file{mach/vm_prot.h}.
3932:
3933: Only data which is cached at the time of this call is affected. When a
3934: running thread requires a prohibited access to cached data, the kernel
3935: will issue a @code{memory_object_data_unlock} call specifying the forms
3936: of access required.
3937:
3938: Once all of the actions requested by this call have been completed, the
3939: kernel issues a @code{memory_object_lock_completed} call on the
3940: specified reply port.
3941:
3942: The argument @var{memory_control} is the port, provided by the kernel in
3943: a @code{memory_object_init} call, to which cache management requests may
3944: be issued. @var{offset} is an offset within a memory object, in bytes.
3945: This must be page aligned. @var{size} is the amount of cached data
3946: (starting at @var{offset}) to be handled. This must be an integral
3947: number of the memory object page size. If @var{should_clean} is set,
3948: modified data should be written back to the memory manager. If
3949: @var{should_flush} is set, the specified cached data should be
3950: invalidated, and all uses of that data should be revoked.
3951: @var{lock_value} is a protection value indicating those forms of access
3952: that should @strong{not} be permitted to the specified cached data.
1.1.1.2 root 3953: @var{reply_to} is a port on which a @code{memory_object_lock_completed}
1.1 root 3954: call should be issued, or @code{MACH_PORT_NULL} if no acknowledgement is
3955: desired.
3956:
3957: This routine does not receive a reply message (and consequently has no
3958: return value), so only message transmission errors apply.
3959: @end deftypefun
3960:
3961: @deftypefun kern_return_t memory_object_lock_completed (@w{memory_object_t @var{memory_object}}, @w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_size_t @var{length}})
3962: @deftypefunx kern_return_t seqnos_memory_object_lock_completed (@w{memory_object_t @var{memory_object}}, @w{mach_port_seqno_t @var{seqno}}, @w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_size_t @var{length}})
3963: The function @code{memory_object_lock_completed} indicates that a
3964: previous @code{memory_object_lock_request} has been completed. Note
3965: that this call is made on whatever port was specified in the
3966: @code{memory_object_lock_request} call; that port need not be the memory
3967: object port itself. No reply is expected after this call.
3968:
3969: The argument @var{memory_object} is the port that represents the memory
3970: object data, as supplied to the kernel in a @code{vm_map} call.
3971: @var{memory_control} is the request port to which a response is
3972: requested. (In the event that a memory object has been supplied to more
3973: than one the kernel that has made the request.) @var{offset} is the
3974: offset within a memory object to which this call refers. @var{length}
3975: is the length of the data covered by the lock request.
3976:
3977: The function should return @code{KERN_SUCCESS}, but since this routine
3978: is called by the kernel, which does not wait for a reply message, this
3979: value is ignored.
3980: @end deftypefun
3981:
3982: @deftypefun kern_return_t memory_object_data_unlock (@w{memory_object_t @var{memory_object}}, @w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_size_t @var{length}}, @w{vm_prot_t @var{desired_access}})
3983: @deftypefunx kern_return_t seqnos_memory_object_data_unlock (@w{memory_object_t @var{memory_object}}, @w{mach_port_seqno_t @var{seqno}}, @w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_size_t @var{length}}, @w{vm_prot_t @var{desired_access}})
3984: The function @code{memory_object_data_unlock} is a request that the
3985: memory manager permit at least the desired access to the specified data
3986: cached by the kernel. A call to @code{memory_object_lock_request} is
3987: expected in response.
3988:
3989: The argument @var{memory_object} is the port that represents the memory
3990: object data, as supplied to the kernel in a @code{vm_map} call.
3991: @var{memory_control} is the request port to which a response is
3992: requested. (In the event that a memory object has been supplied to more
3993: than one the kernel that has made the request.) @var{offset} is the
3994: offset within a memory object to which this call refers. This will be
3995: page aligned. @var{length} is the number of bytes of data, starting at
3996: @var{offset}, to which this call refers. This will be an integral
3997: number of memory object pages. @var{desired_access} a protection value
3998: describing the memory access modes which must be permitted on the
3999: specified cached data. One or more of: @code{VM_PROT_READ},
4000: @code{VM_PROT_WRITE} or @code{VM_PROT_EXECUTE}.
4001:
4002: The function should return @code{KERN_SUCCESS}, but since this routine
4003: is called by the kernel, which does not wait for a reply message, this
4004: value is ignored.
4005: @end deftypefun
4006:
4007:
4008: @node Memory Object Attributes
4009: @section Memory Object Attributes
4010:
4011: @deftypefun kern_return_t memory_object_get_attributes (@w{memory_object_control_t @var{memory_control}}, @w{boolean_t *@var{object_ready}}, @w{boolean_t *@var{may_cache_object}}, @w{memory_object_copy_strategy_t *@var{copy_strategy}})
4012: The function @code{memory_object_get_attribute} retrieves the current
4013: attributes associated with the memory object.
4014:
4015: The argument @var{memory_control} is the port, provided by the kernel in
4016: a @code{memory_object_init} call, to which cache management requests may
4017: be issued. If @var{object_ready} is set, the kernel may issue new data
4018: and unlock requests on the associated memory object. If
4019: @var{may_cache_object} is set, the kernel may keep data associated with
4020: this memory object, even after virtual memory references to it are gone.
4021: @var{copy_strategy} tells how the kernel should copy regions of the
4022: associated memory object.
4023:
4024: This routine does not receive a reply message (and consequently has no
4025: return value), so only message transmission errors apply.
4026: @end deftypefun
4027:
4028: @deftypefun kern_return_t memory_object_change_attributes (@w{memory_object_control_t @var{memory_control}}, @w{boolean_t @var{may_cache_object}}, @w{memory_object_copy_strategy_t @var{copy_strategy}}, @w{mach_port_t @var{reply_to}})
4029: The function @code{memory_object_change_attribute} sets
4030: performance-related attributes for the specified memory object. If the
4031: caching attribute is asserted, the kernel is permitted (and encouraged)
4032: to maintain cached data for this memory object even after no virtual
4033: address space contains this data.
4034:
4035: There are three possible caching strategies:
4036: @code{MEMORY_OBJECT_COPY_NONE} which specifies that nothing special
4037: should be done when data in the object is copied;
4038: @code{MEMORY_OBJECT_COPY_CALL} which specifies that the memory manager
4039: should be notified via a @code{memory_object_copy} call before any part
4040: of the object is copied; and @code{MEMORY_OBJECT_COPY_DELAY} which
4041: guarantees that the memory manager does not externally modify the data
4042: so that the kernel can use its normal copy-on-write algorithms.
4043: @code{MEMORY_OBJECT_COPY_DELAY} is the strategy most commonly used.
4044:
4045: The argument @var{memory_control} is the port, provided by the kernel in
4046: a @code{memory_object_init} call, to which cache management requests may
4047: be issued. If @var{may_cache_object} is set, the kernel may keep data
4048: associated with this memory object, even after virtual memory references
4049: to it are gone. @var{copy_strategy} tells how the kernel should copy
4050: regions of the associated memory object. @var{reply_to} is a port on
1.1.1.2 root 4051: which a @code{memory_object_change_completed} call will be issued upon
1.1 root 4052: completion of the attribute change, or @code{MACH_PORT_NULL} if no
4053: acknowledgement is desired.
4054:
4055: This routine does not receive a reply message (and consequently has no
4056: return value), so only message transmission errors apply.
4057: @end deftypefun
4058:
4059: @deftypefun kern_return_t memory_object_change_completed (@w{memory_object_t @var{memory_object}}, @w{boolean_t @var{may_cache_object}}, @w{memory_object_copy_strategy_t @var{copy_strategy}})
4060: @deftypefunx kern_return_t seqnos_memory_object_change_completed (@w{memory_object_t @var{memory_object}}, @w{mach_port_seqno_t @var{seqno}}, @w{boolean_t @var{may_cache_object}}, @w{memory_object_copy_strategy_t @var{copy_strategy}})
4061: The function @code{memory_object_change_completed} indicates the
4062: completion of an attribute change call.
4063:
4064: @c Warning: This routine does NOT contain a memory_object_control_t because
4065: @c the memory_object_change_attributes call may cause memory object
4066: @c termination (by uncaching the object). This would yield an invalid
4067: @c port.
4068: @end deftypefun
4069:
4070: The following interface is obsoleted by @code{memory_object_ready} and
4071: @code{memory_object_change_attributes}. If the old form
4072: @code{memory_object_set_attributes} is used to make a memory object
4073: ready, the kernel will write back data using the old
4074: @code{memory_object_data_write} interface rather than
4075: @code{memory_object_data_return}..
4076:
4077: @deftypefun kern_return_t memory_object_set_attributes (@w{memory_object_control_t @var{memory_control}}, @w{boolean @var{object_ready}}, @w{boolean_t @var{may_cache_object}}, @w{memory_object_copy_strategy_t @var{copy_strategy}})
1.1.1.2 root 4078: The function @code{memory_object_set_attribute} controls how the
1.1 root 4079: memory object. The kernel will only make data or unlock requests when
4080: the ready attribute is asserted. If the caching attribute is asserted,
4081: the kernel is permitted (and encouraged) to maintain cached data for
4082: this memory object even after no virtual address space contains this
4083: data.
4084:
4085: There are three possible caching strategies:
4086: @code{MEMORY_OBJECT_COPY_NONE} which specifies that nothing special
4087: should be done when data in the object is copied;
4088: @code{MEMORY_OBJECT_COPY_CALL} which specifies that the memory manager
4089: should be notified via a @code{memory_object_copy} call before any part
4090: of the object is copied; and @code{MEMORY_OBJECT_COPY_DELAY} which
4091: guarantees that the memory manager does not externally modify the data
4092: so that the kernel can use its normal copy-on-write algorithms.
4093: @code{MEMORY_OBJECT_COPY_DELAY} is the strategy most commonly used.
4094:
4095: The argument @var{memory_control} is the port, provided by the kernel in
4096: a @code{memory_object_init} call, to which cache management requests may
4097: be issued. If @var{object_ready} is set, the kernel may issue new data
4098: and unlock requests on the associated memory object. If
4099: @var{may_cache_object} is set, the kernel may keep data associated with
4100: this memory object, even after virtual memory references to it are gone.
4101: @var{copy_strategy} tells how the kernel should copy regions of the
4102: associated memory object.
4103:
4104: This routine does not receive a reply message (and consequently has no
4105: return value), so only message transmission errors apply.
4106: @end deftypefun
4107:
4108:
4109: @node Default Memory Manager
4110: @section Default Memory Manager
4111:
4112: @deftypefun kern_return_t vm_set_default_memory_manager (@w{host_t @var{host}}, @w{mach_port_t *@var{default_manager}})
4113: The function @code{vm_set_default_memory_manager} sets the kernel's
4114: default memory manager. It sets the port to which newly-created
4115: temporary memory objects are delivered by @code{memory_object_create} to
4116: the host. The old memory manager port is returned. If
4117: @var{default_manager} is @code{MACH_PORT_NULL} then this routine just returns
4118: the current default manager port without changing it.
4119:
4120: The argument @var{host} is a task port to the kernel whose default
4121: memory manager is to be changed. @var{default_manager} is an in/out
4122: parameter. As input, @var{default_manager} is the port that the new
4123: memory manager is listening on for @code{memory_object_create} calls.
4124: As output, it is the old default memory manager's port.
4125:
4126: The function returns @code{KERN_SUCCESS} if the new memory manager is
4127: installed, and @code{KERN_INVALID_ARGUMENT} if this task does not have
4128: the privileges required for this call.
4129: @end deftypefun
4130:
4131: @deftypefun kern_return_t memory_object_create (@w{memory_object_t @var{old_memory_object}}, @w{memory_object_t @var{new_memory_object}}, @w{vm_size_t @var{new_object_size}}, @w{memory_object_control_t @var{new_control}}, @w{memory_object_name_t @var{new_name}}, @w{vm_size_t @var{new_page_size}})
4132: @deftypefunx kern_return_t seqnos_memory_object_create (@w{memory_object_t @var{old_memory_object}}, @w{mach_port_seqno_t @var{seqno}}, @w{memory_object_t @var{new_memory_object}}, @w{vm_size_t @var{new_object_size}}, @w{memory_object_control_t @var{new_control}}, @w{memory_object_name_t @var{new_name}}, @w{vm_size_t @var{new_page_size}})
4133: The function @code{memory_object_create} is a request that the given
4134: memory manager accept responsibility for the given memory object created
4135: by the kernel. This call will only be made to the system
4136: @strong{default memory manager}. The memory object in question
4137: initially consists of zero-filled memory; only memory pages that are
4138: actually written will ever be provided to
4139: @code{memory_object_data_request} calls, the default memory manager must
4140: use @code{memory_object_data_unavailable} for any pages that have not
4141: previously been written.
4142:
4143: No reply is expected after this call. Since this call is directed to
4144: the default memory manager, the kernel assumes that it will be ready to
4145: handle data requests to this object and does not need the confirmation
4146: of a @code{memory_object_set_attributes} call.
4147:
4148: The argument @var{old_memory_object} is a memory object provided by the
4149: default memory manager on which the kernel can make
4150: @code{memory_object_create} calls. @var{new_memory_object} is a new
4151: memory object created by the kernel; see synopsis for further
4152: description. Note that all port rights (including receive rights) are
4153: included for the new memory object. @var{new_object_size} is the
4154: maximum size of the new object. @var{new_control} is a port, created by
4155: the kernel, on which a memory manager may issue cache management
4156: requests for the new object. @var{new_name} a port used by the kernel
4157: to refer to the new memory object data in response to @code{vm_region}
4158: calls. @var{new_page_size} is the page size to be used by this kernel.
4159: All data sizes in calls involving this kernel must be an integral
4160: multiple of the page size. Note that different kernels, indicated by
4161: different a @code{memory_control}, may have different page sizes.
4162:
4163: The function should return @code{KERN_SUCCESS}, but since this routine
4164: is called by the kernel, which does not wait for a reply message, this
4165: value is ignored.
4166: @end deftypefun
4167:
4168: @deftypefun kern_return_t memory_object_data_initialize (@w{memory_object_t @var{memory_object}}, @w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_offset_t @var{data}}, @w{vm_size_t @var{data_count}})
4169: @deftypefunx kern_return_t seqnos_memory_object_data_initialize (@w{memory_object_t @var{memory_object}}, @w{mach_port_seqno_t @var{seqno}}, @w{memory_object_control_t @var{memory_control}}, @w{vm_offset_t @var{offset}}, @w{vm_offset_t @var{data}}, @w{vm_size_t @var{data_count}})
4170: The function @code{memory_object_data_initialize} provides the memory
4171: manager with initial data for a kernel-created memory object. If the
4172: memory manager already has been supplied data (by a previous
4173: @code{memory_object_data_initialize}, @code{memory_object_data_write} or
4174: @code{memory_object_data_return}), then this data should be ignored.
4175: Otherwise, this call behaves exactly as does
4176: @code{memory_object_data_return} on memory objects created by the kernel
4177: via @code{memory_object_create} and thus will only be made to default
4178: memory managers. This call will not be made on objects created via
4179: @code{memory_object_copy}.
4180:
4181: The argument @var{memory_object} the port that represents the memory
4182: object data, as supplied by the kernel in a @code{memory_object_create}
4183: call. @var{memory_control} is the request port to which a response is
4184: requested. (In the event that a memory object has been supplied to more
4185: than one the kernel that has made the request.) @var{offset} is the
4186: offset within a memory object to which this call refers. This will be
1.1.1.2 root 4187: page aligned. @var{data} is the data which has been modified while
1.1 root 4188: cached in physical memory. @var{data_count} is the amount of data to be
4189: written, in bytes. This will be an integral number of memory object
4190: pages.
4191:
4192: The function should return @code{KERN_SUCCESS}, but since this routine
4193: is called by the kernel, which does not wait for a reply message, this
4194: value is ignored.
4195: @end deftypefun
4196:
4197:
4198: @node Threads and Tasks
4199: @chapter Threads and Tasks
4200:
4201: @menu
4202: * Thread Interface:: Manipulating threads.
4203: * Task Interface:: Manipulating tasks.
4204: * Profiling:: Profiling threads and tasks.
4205: @end menu
4206:
4207:
4208: @node Thread Interface
4209: @section Thread Interface
4210:
4211: @cindex thread port
4212: @cindex port representing a thread
4213: @deftp {Data type} thread_t
4214: This is a @code{mach_port_t} and used to hold the port name of a
4215: thread port that represents the thread. Manipulations of the thread are
4216: implemented as remote procedure calls to the thread port. A thread can
4217: get a port to itself with the @code{mach_thread_self} system call.
4218: @end deftp
4219:
4220: @menu
4221: * Thread Creation:: Creating new threads.
4222: * Thread Termination:: Terminating existing threads.
4223: * Thread Information:: How to get informations on threads.
4224: * Thread Settings:: How to set threads related informations.
4225: * Thread Execution:: How to control the thread's machine state.
4226: * Scheduling:: Operations on thread scheduling.
4227: * Thread Special Ports:: How to handle the thread's special ports.
4228: * Exceptions:: Managing exceptions.
4229: @end menu
4230:
4231:
4232: @node Thread Creation
4233: @subsection Thread Creation
4234:
4235: @deftypefun kern_return_t thread_create (@w{task_t @var{parent_task}}, @w{thread_t *@var{child_thread}})
4236: The function @code{thread_create} creates a new thread within the task
4237: specified by @var{parent_task}. The new thread has no processor state,
4238: and has a suspend count of 1. To get a new thread to run, first
4239: @code{thread_create} is called to get the new thread's identifier,
4240: (@var{child_thread}). Then @code{thread_set_state} is called to set a
4241: processor state, and finally @code{thread_resume} is called to get the
4242: thread scheduled to execute.
4243:
4244: When the thread is created send rights to its thread kernel port are
4245: given to it and returned to the caller in @var{child_thread}. The new
4246: thread's exception port is set to @code{MACH_PORT_NULL}.
4247:
4248: The function returns @code{KERN_SUCCESS} if a new thread has been
4249: created, @code{KERN_INVALID_ARGUMENT} if @var{parent_task} is not a
4250: valid task and @code{KERN_RESOURCE_SHORTAGE} if some critical kernel
4251: resource is not available.
4252: @end deftypefun
4253:
4254:
4255: @node Thread Termination
4256: @subsection Thread Termination
4257:
4258: @deftypefun kern_return_t thread_terminate (@w{thread_t @var{target_thread}})
4259: The function @code{thread_terminate} destroys the thread specified by
4260: @var{target_thread}.
4261:
4262: The function returns @code{KERN_SUCCESS} if the thread has been killed
4263: and @code{KERN_INVALID_ARGUMENT} if @var{target_thread} is not a thread.
4264: @end deftypefun
4265:
4266:
4267: @node Thread Information
4268: @subsection Thread Information
4269:
4270: @deftypefun thread_t mach_thread_self ()
4271: The @code{mach_thread_self} system call returns the calling thread's
4272: thread port.
4273:
4274: @code{mach_thread_self} has an effect equivalent to receiving a send
4275: right for the thread port. @code{mach_thread_self} returns the name of
4276: the send right. In particular, successive calls will increase the
4277: calling task's user-reference count for the send right.
4278:
4279: @c author{marcus}
4280: As a special exception, the kernel will overrun the user reference count
4281: of the thread name port, so that this function can not fail for that
4282: reason. Because of this, the user should not deallocate the port right
4283: if an overrun might have happened. Otherwise the reference count could
4284: drop to zero and the send right be destroyed while the user still
4285: expects to be able to use it. As the kernel does not make use of the
4286: number of extant send rights anyway, this is safe to do (the thread port
4287: itself is not destroyed, even when there are no send rights anymore).
4288:
4289: The function returns @code{MACH_PORT_NULL} if a resource shortage
4290: prevented the reception of the send right or if the thread port is
4291: currently null and @code{MACH_PORT_DEAD} if the thread port is currently
4292: dead.
4293: @end deftypefun
4294:
4295: @deftypefun kern_return_t thread_info (@w{thread_t @var{target_thread}}, @w{int @var{flavor}}, @w{thread_info_t @var{thread_info}}, @w{mach_msg_type_number_t *@var{thread_infoCnt}})
4296: The function @code{thread_info} returns the selected information array
4297: for a thread, as specified by @var{flavor}.
4298:
4299: @var{thread_info} is an array of integers that is supplied by the caller
4300: and returned filled with specified information. @var{thread_infoCnt} is
4301: supplied as the maximum number of integers in @var{thread_info}. On
4302: return, it contains the actual number of integers in @var{thread_info}.
4303: The maximum number of integers returned by any flavor is
4304: @code{THREAD_INFO_MAX}.
4305:
4306: The type of information returned is defined by @var{flavor}, which can
4307: be one of the following:
4308:
4309: @table @code
4310: @item THREAD_BASIC_INFO
4311: The function returns basic information about the thread, as defined by
4312: @code{thread_basic_info_t}. This includes the user and system time, the
4313: run state, and scheduling priority. The number of integers returned is
4314: @code{THREAD_BASIC_INFO_COUNT}.
4315:
4316: @item THREAD_SCHED_INFO
1.1.1.2 root 4317: The function returns information about the scheduling policy for the
1.1 root 4318: thread as defined by @code{thread_sched_info_t}. The number of integers
4319: returned is @code{THREAD_SCHED_INFO_COUNT}.
4320: @end table
4321:
4322: The function returns @code{KERN_SUCCESS} if the call succeeded and
4323: @code{KERN_INVALID_ARGUMENT} if @var{target_thread} is not a thread or
4324: @var{flavor} is not recognized. The function returns
4325: @code{MIG_ARRAY_TOO_LARGE} if the returned info array is too large for
4326: @var{thread_info}. In this case, @var{thread_info} is filled as much as
4327: possible and @var{thread_infoCnt} is set to the number of elements that
4328: would have been returned if there were enough room.
4329: @end deftypefun
4330:
4331: @deftp {Data type} {struct thread_basic_info}
4332: This structure is returned in @var{thread_info} by the
4333: @code{thread_info} function and provides basic information about the
4334: thread. You can cast a variable of type @code{thread_info_t} to a
4335: pointer of this type if you provided it as the @var{thread_info}
4336: parameter for the @code{THREAD_BASIC_INFO} flavor of @code{thread_info}.
4337: It has the following members:
4338:
4339: @table @code
4340: @item time_value_t user_time
4341: user run time
4342:
4343: @item time_value_t system_time
4344: system run time
4345: @item int cpu_usage
4346: Scaled cpu usage percentage. The scale factor is @code{TH_USAGE_SCALE}.
4347:
4348: @item int base_priority
4349: The base scheduling priority of the thread.
4350:
4351: @item int cur_priority
4352: The current scheduling priority of the thread.
4353:
4354: @item integer_t run_state
1.1.1.2 root 4355: The run state of the thread. The possible values of this field are:
1.1 root 4356: @table @code
4357: @item TH_STATE_RUNNING
4358: The thread is running normally.
4359:
4360: @item TH_STATE_STOPPED
4361: The thread is suspended.
4362:
4363: @item TH_STATE_WAITING
4364: The thread is waiting normally.
4365:
4366: @item TH_STATE_UNINTERRUPTIBLE
4367: The thread is in an uninterruptible wait.
4368:
4369: @item TH_STATE_HALTED
4370: The thread is halted at a clean point.
4371: @end table
4372:
4373: @item flags
4374: Various flags. The possible values of this field are:
4375: @table @code
4376: @item TH_FLAGS_SWAPPED
4377: The thread is swapped out.
4378:
4379: @item TH_FLAGS_IDLE
4380: The thread is an idle thread.
4381: @end table
4382:
4383: @item int suspend_count
4384: The suspend count for the thread.
4385:
4386: @item int sleep_time
4387: The number of seconds that the thread has been sleeping.
4388:
4389: @item time_value_t creation_time
4390: The time stamp of creation.
4391: @end table
4392: @end deftp
4393:
4394: @deftp {Data type} thread_basic_info_t
4395: This is a pointer to a @code{struct thread_basic_info}.
4396: @end deftp
4397:
4398: @deftp {Data type} {struct thread_sched_info}
4399: This structure is returned in @var{thread_info} by the
4400: @code{thread_info} function and provides schedule information about the
4401: thread. You can cast a variable of type @code{thread_info_t} to a
4402: pointer of this type if you provided it as the @var{thread_info}
4403: parameter for the @code{THREAD_SCHED_INFO} flavor of @code{thread_info}.
4404: It has the following members:
4405:
4406: @table @code
4407: @item int policy
4408: The scheduling policy of the thread, @ref{Scheduling Policy}.
4409:
4410: @item integer_t data
4411: Policy-dependent scheduling information, @ref{Scheduling Policy}.
4412:
4413: @item int base_priority
4414: The base scheduling priority of the thread.
4415:
4416: @item int max_priority
4417: The maximum scheduling priority of the thread.
4418:
4419: @item int cur_priority
4420: The current scheduling priority of the thread.
4421:
4422: @item int depressed
4423: @code{TRUE} if the thread is depressed.
4424:
4425: @item int depress_priority
4426: The priority the thread was depressed from.
4427: @end table
4428: @end deftp
4429:
4430: @deftp {Data type} thread_sched_info_t
4431: This is a pointer to a @code{struct thread_sched_info}.
4432: @end deftp
4433:
4434:
4435: @node Thread Settings
4436: @subsection Thread Settings
4437:
4438: @deftypefun kern_return_t thread_wire (@w{host_priv_t @var{host_priv}}, @w{thread_t @var{thread}}, @w{boolean_t @var{wired}})
4439: The function @code{thread_wire} controls the VM privilege level of the
4440: thread @var{thread}. A VM-privileged thread never waits inside the
4441: kernel for memory allocation from the kernel's free list of pages or for
4442: allocation of a kernel stack.
4443:
4444: Threads that are part of the default pageout path should be
4445: VM-privileged, to prevent system deadlocks. Threads that are not part
4446: of the default pageout path should not be VM-privileged, to prevent the
4447: kernel's free list of pages from being exhausted.
4448:
4449: The functions returns @code{KERN_SUCCESS} if the call succeeded,
4450: @code{KERN_INVALID_ARGUMENT} if @var{host_priv} or @var{thread} was
4451: invalid.
4452:
4453: The @code{thread_wire} call is actually an RPC to @var{host_priv},
4454: normally a send right for a privileged host port, but potentially any
4455: send right. In addition to the normal diagnostic return codes from the
4456: call's server (normally the kernel), the call may return @code{mach_msg}
4457: return codes.
4458: @c See also: vm_wire(2), vm_set_default_memory_manager(2).
4459: @end deftypefun
4460:
4461:
4462: @node Thread Execution
4463: @subsection Thread Execution
4464:
4465: @deftypefun kern_return_t thread_suspend (@w{thread_t @var{target_thread}})
4466: Increments the thread's suspend count and prevents the thread from
4467: executing any more user level instructions. In this context a user
4468: level instruction is either a machine instruction executed in user mode
4469: or a system trap instruction including page faults. Thus if a thread is
4470: currently executing within a system trap the kernel code may continue to
1.1.1.2 root 4471: execute until it reaches the system return code or it may suspend within
1.1 root 4472: the kernel code. In either case, when the thread is resumed the system
1.1.1.2 root 4473: trap will return. This could cause unpredictable results if the user
1.1 root 4474: did a suspend and then altered the user state of the thread in order to
4475: change its direction upon a resume. The call @code{thread_abort} is
4476: provided to allow the user to abort any system call that is in progress
4477: in a predictable way.
4478:
4479: The suspend count may become greater than one with the effect that it
4480: will take more than one resume call to restart the thread.
4481:
4482: The function returns @code{KERN_SUCCESS} if the thread has been
4483: suspended and @code{KERN_INVALID_ARGUMENT} if @var{target_thread} is not
4484: a thread.
4485: @end deftypefun
4486:
4487: @deftypefun kern_return_t thread_resume (@w{thread_t @var{target_thread}})
1.1.1.2 root 4488: Decrements the thread's suspend count. If the count becomes zero the
1.1 root 4489: thread is resumed. If it is still positive, the thread is left
4490: suspended. The suspend count may not become negative.
4491:
4492: The function returns @code{KERN_SUCCESS} if the thread has been resumed,
4493: @code{KERN_FAILURE} if the suspend count is already zero and
4494: @code{KERN_INVALID_ARGUMENT} if @var{target_thread} is not a thread.
4495: @end deftypefun
4496:
4497: @deftypefun kern_return_t thread_abort (@w{thread_t @var{target_thread}})
4498: The function @code{thread_abort} aborts the kernel primitives:
4499: @code{mach_msg}, @code{msg_send}, @code{msg_receive} and @code{msg_rpc}
4500: and page-faults, making the call return a code indicating that it was
4501: interrupted. The call is interrupted whether or not the thread (or task
1.1.1.2 root 4502: containing it) is currently suspended. If it is suspended, the thread
4503: receives the interrupt when it is resumed.
1.1 root 4504:
4505: A thread will retry an aborted page-fault if its state is not modified
4506: before it is resumed. @code{msg_send} returns @code{SEND_INTERRUPTED};
4507: @code{msg_receive} returns @code{RCV_INTERRUPTED}; @code{msg_rpc}
4508: returns either @code{SEND_INTERRUPTED} or @code{RCV_INTERRUPTED},
4509: depending on which half of the RPC was interrupted.
4510:
4511: The main reason for this primitive is to allow one thread to cleanly
4512: stop another thread in a manner that will allow the future execution of
4513: the target thread to be controlled in a predictable way.
4514: @code{thread_suspend} keeps the target thread from executing any further
4515: instructions at the user level, including the return from a system call.
4516: @code{thread_get_state}/@code{thread_set_state} allows the examination
4517: or modification of the user state of a target thread. However, if a
4518: suspended thread was executing within a system call, it also has
4519: associated with it a kernel state. This kernel state can not be
4520: modified by @code{thread_set_state} with the result that when the thread
4521: is resumed the system call may return changing the user state and
4522: possibly user memory. @code{thread_abort} aborts the kernel call from
4523: the target thread's point of view by resetting the kernel state so that
4524: the thread will resume execution at the system call return with the
4525: return code value set to one of the interrupted codes. The system call
4526: itself will either be entirely completed or entirely aborted, depending
4527: on the precise moment at which the abort was received. Thus if the
4528: thread's user state has been changed by @code{thread_set_state}, it will
4529: not be modified by any unexpected system call side effects.
4530:
4531: For example to simulate a Unix signal, the following sequence of calls
4532: may be used:
4533:
4534: @enumerate
4535: @item
4536: @code{thread_suspend}: Stops the thread.
4537:
4538: @item
4539: @code{thread_abort}: Interrupts any system call in progress, setting the
4540: return value to `interrupted'. Since the thread is stopped, it will not
4541: return to user code.
4542:
4543: @item
4544: @code{thread_set_state}: Alters thread's state to simulate a procedure
4545: call to the signal handler
4546:
4547: @item
4548: @code{thread_resume}: Resumes execution at the signal handler. If the
4549: thread's stack has been correctly set up, the thread may return to the
4550: interrupted system call. (Of course, the code to push an extra stack
4551: frame and change the registers is VERY machine-dependent.)
4552: @end enumerate
4553:
4554: Calling @code{thread_abort} on a non-suspended thread is pretty risky,
4555: since it is very difficult to know exactly what system trap, if any, the
4556: thread might be executing and whether an interrupt return would cause
4557: the thread to do something useful.
4558:
4559: The function returns @code{KERN_SUCCESS} if the thread received an
4560: interrupt and @code{KERN_INVALID_ARGUMENT} if @var{target_thread} is not
4561: a thread.
4562: @end deftypefun
4563:
4564: @deftypefun kern_return_t thread_get_state (@w{thread_t @var{target_thread}}, @w{int @var{flavor}}, @w{thread_state_t @var{old_state}}, @w{mach_msg_type_number_t *@var{old_stateCnt}})
4565: The function @code{thread_get_state} returns the execution state
4566: (e.g. the machine registers) of @var{target_thread} as specified by
4567: @var{flavor}. The @var{old_state} is an array of integers that is
4568: provided by the caller and returned filled with the specified
4569: information. @var{old_stateCnt} is input set to the maximum number of
4570: integers in @var{old_state} and returned equal to the actual number of
4571: integers in @var{old_state}.
4572:
4573: @var{target_thread} may not be @code{mach_thread_self()}.
4574:
4575: The definition of the state structures can be found in
4576: @file{machine/thread_status.h}.
4577:
4578: The function returns @code{KERN_SUCCESS} if the state has been returned,
4579: @code{KERN_INVALID_ARGUMENT} if @var{target_thread} is not a thread or
1.1.1.2 root 4580: is @code{mach_thread_self} or @var{flavor} is unrecognized for this machine.
1.1 root 4581: The function returns @code{MIG_ARRAY_TOO_LARGE} if the returned state is
4582: too large for @var{old_state}. In this case, @var{old_state} is filled
4583: as much as possible and @var{old_stateCnt} is set to the number of
4584: elements that would have been returned if there were enough room.
4585: @end deftypefun
4586:
4587: @deftypefun kern_return_t thread_set_state (@w{thread_t @var{target_thread}}, @w{int @var{flavor}}, @w{thread_state_t @var{new_state}}, @w{mach_msg_type_number_t @var{new_state_count}})
4588: The function @code{thread_set_state} sets the execution state (e.g. the
4589: machine registers) of @var{target_thread} as specified by @var{flavor}.
4590: The @var{new_state} is an array of integers. @var{new_state_count} is
4591: the number of elements in @var{new_state}. The entire set of registers
4592: is reset. This will do unpredictable things if @var{target_thread} is
4593: not suspended.
4594:
4595: @var{target_thread} may not be @code{mach_thread_self}.
4596:
4597: The definition of the state structures can be found in
4598: @file{machine/thread_status.h}.
4599:
4600: The function returns @code{KERN_SUCCESS} if the state has been set and
4601: @code{KERN_INVALID_ARGUMENT} if @var{target_thread} is not a thread or
1.1.1.2 root 4602: is @code{mach_thread_self} or @var{flavor} is unrecognized for this
1.1 root 4603: machine.
4604: @end deftypefun
4605:
4606:
4607: @node Scheduling
4608: @subsection Scheduling
4609:
4610: @menu
4611: * Thread Priority:: Changing the priority of a thread.
4612: * Hand-Off Scheduling:: Switching to a new thread.
4613: * Scheduling Policy:: Setting the scheduling policy.
4614: @end menu
4615:
4616:
4617: @node Thread Priority
4618: @subsubsection Thread Priority
4619:
4620: Threads have three priorities associated with them by the system, a
4621: priority, a maximum priority, and a scheduled priority. The scheduled
4622: priority is used to make scheduling decisions about the thread. It is
4623: determined from the priority by the policy (for timesharing, this means
4624: adding an increment derived from cpu usage). The priority can be set
4625: under user control, but may never exceed the maximum priority. Changing
4626: the maximum priority requires presentation of the control port for the
4627: thread's processor set; since the control port for the default processor
4628: set is privileged, users cannot raise their maximum priority to unfairly
4629: compete with other users on that set. Newly created threads obtain
4630: their priority from their task and their max priority from the thread.
4631:
4632: @deftypefun kern_return_t thread_priority (@w{thread_t @var{thread}}, @w{int @var{prority}}, @w{boolean_t @var{set_max}})
4633: The function @code{thread_priority} changes the priority and optionally
1.1.1.3 root 4634: the maximum priority of @var{thread}. Priorities range from 0 to 49,
1.1 root 4635: where lower numbers denote higher priorities. If the new priority is
4636: higher than the priority of the current thread, preemption may occur as
4637: a result of this call. The maximum priority of the thread is also set
4638: if @var{set_max} is @code{TRUE}. This call will fail if @var{priority}
4639: is greater than the current maximum priority of the thread. As a
4640: result, this call can only lower the value of a thread's maximum
4641: priority.
4642:
4643: The functions returns @code{KERN_SUCCESS} if the operation completed
4644: successfully, @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a
1.1.1.3 root 4645: thread or @var{priority} is out of range (not in 0..49), and
1.1 root 4646: @code{KERN_FAILURE} if the requested operation would violate the
4647: thread's maximum priority (thread_priority).
4648: @end deftypefun
4649:
4650: @deftypefun kern_return_t thread_max_priority (@w{thread_t @var{thread}}, @w{processor_set_t @var{processor_set}}, @w{int @var{priority}})
4651: The function @code{thread_max_priority} changes the maximum priority of
4652: the thread. Because it requires presentation of the corresponding
4653: processor set port, this call can reset the maximum priority to any
4654: legal value.
4655:
4656: The functions returns @code{KERN_SUCCESS} if the operation completed
4657: successfully, @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a
4658: thread or @var{processor_set} is not a control port for a processor set
1.1.1.3 root 4659: or @var{priority} is out of range (not in 0..49), and
1.1 root 4660: @code{KERN_FAILURE} if the thread is not assigned to the processor set
4661: whose control port was presented.
4662: @end deftypefun
4663:
4664:
4665: @node Hand-Off Scheduling
4666: @subsubsection Hand-Off Scheduling
4667:
4668: @deftypefun kern_return_t thread_switch (@w{thread_t @var{new_thread}}, @w{int @var{option}}, @w{int @var{time}})
4669: The function @code{thread_switch} provides low-level access to the
4670: scheduler's context switching code. @var{new_thread} is a hint that
4671: implements hand-off scheduling. The operating system will attempt to
1.1.1.2 root 4672: switch directly to the new thread (bypassing the normal logic that
1.1 root 4673: selects the next thread to run) if possible. Since this is a hint, it
4674: may be incorrect; it is ignored if it doesn't specify a thread on the
4675: same host as the current thread or if that thread can't be switched to
1.1.1.2 root 4676: (i.e., not runnable or already running on another processor or giving
4677: a plainly invalid hint, such as @code{MACH_PORT_NULL}). In this case,
4678: the normal logic to select the next thread to run is used; the current
4679: thread may continue running if there is no other appropriate thread to
4680: run.
1.1 root 4681:
4682: Options for @var{option} are defined in @file{mach/thread_switch.h} and
4683: specify the interpretation of @var{time}. The possible values for
4684: @var{option} are:
4685:
4686: @table @code
4687: @item SWITCH_OPTION_NONE
4688: No options, the time argument is ignored.
4689:
4690: @item SWITCH_OPTION_WAIT
1.1.1.2 root 4691: The thread is blocked for the specified time (in milliseconds;
4692: specifying @code{0} will wait for the next tick). This can be aborted
4693: by @code{thread_abort}.
1.1 root 4694:
4695: @item SWITCH_OPTION_DEPRESS
4696: The thread's priority is depressed to the lowest possible value for the
4697: specified time. This can be aborted by @code{thread_depress_abort}.
4698: This depression is independent of operations that change the thread's
4699: priority (e.g. @code{thread_priority} will not abort the depression).
4700: The minimum time and units of time can be obtained as the
4701: @code{min_timeout} value from @code{host_info}. The depression is also
1.1.1.2 root 4702: aborted when the current thread is next run (either via hand-off
1.1 root 4703: scheduling or because the processor set has nothing better to do).
4704: @end table
4705:
4706: @code{thread_switch} is often called when the current thread can proceed
4707: no further for some reason; the various options and arguments allow
4708: information about this reason to be transmitted to the kernel. The
4709: @var{new_thread} argument (handoff scheduling) is useful when the
4710: identity of the thread that must make progress before the current thread
4711: runs again is known. The @code{WAIT} option is used when the amount of
4712: time that the current thread must wait before it can do anything useful
4713: can be estimated and is fairly long. The @code{DEPRESS} option is used
4714: when the amount of time that must be waited is fairly short, especially
4715: when the identity of the thread that is being waited for is not known.
4716:
4717: Users should beware of calling @code{thread_switch} with an invalid hint
4718: (e.g. @code{MACH_PORT_NULL}) and no option. Because the time-sharing
4719: scheduler varies the priority of threads based on usage, this may result
4720: in a waste of cpu time if the thread that must be run is of lower
4721: priority. The use of the @code{DEPRESS} option in this situation is
4722: highly recommended.
4723:
4724: @code{thread_switch} ignores policies. Users relying on the preemption
4725: semantics of a fixed time policy should be aware that
4726: @code{thread_switch} ignores these semantics; it will run the specified
1.1.1.2 root 4727: @var{new_thread} independent of its priority and the priority of any other
1.1 root 4728: threads that could be run instead.
4729:
4730: The function returns @code{KERN_SUCCESS} if the call succeeded,
4731: @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a thread or
4732: @var{option} is not a recognized option, and @code{KERN_FAILURE} if
4733: @code{kern_depress_abort} failed because the thread was not depressed.
4734: @end deftypefun
4735:
4736: @deftypefun kern_return_t thread_depress_abort (@w{thread_t @var{thread}})
4737: The function @code{thread_depress_abort} cancels any priority depression
4738: for @var{thread} caused by a @code{swtch_pri} or @code{thread_switch}
4739: call.
4740:
4741: The function returns @code{KERN_SUCCESS} if the call succeeded and
4742: @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a valid thread.
4743: @end deftypefun
4744:
4745: @deftypefun boolean_t swtch ()
4746: @c XXX Clear up wording.
4747: The system trap @code{swtch} attempts to switch the current thread off
4748: the processor. The return value indicates if more than the current
4749: thread is running in the processor set. This is useful for lock
4750: management routines.
4751:
4752: The call returns @code{FALSE} if the thread is justified in becoming a
4753: resource hog by continuing to spin because there's nothing else useful
4754: that the processor could do. @code{TRUE} is returned if the thread
4755: should make one more check on the lock and then be a good citizen and
4756: really suspend.
4757: @end deftypefun
4758:
4759: @deftypefun boolean_t swtch_pri (@w{int @var{priority}})
4760: The system trap @code{swtch_pri} attempts to switch the current thread
4761: off the processor as @code{swtch} does, but depressing the priority of
4762: the thread to the minimum possible value during the time.
4763: @var{priority} is not used currently.
4764:
4765: The return value is as for @code{swtch}.
4766: @end deftypefun
4767:
4768:
4769: @node Scheduling Policy
4770: @subsubsection Scheduling Policy
4771:
4772: @deftypefun kern_return_t thread_policy (@w{thread_t @var{thread}}, @w{int @var{policy}}, @w{int @var{data}})
4773: The function @code{thread_policy} changes the scheduling policy for
4774: @var{thread} to @var{policy}.
4775:
4776: @var{data} is policy-dependent scheduling information. There are
4777: currently two supported policies: @code{POLICY_TIMESHARE} and
4778: @code{POLICY_FIXEDPRI} defined in @file{mach/policy.h}; this file is
4779: included by @file{mach.h}. @var{data} is meaningless for timesharing,
4780: but is the quantum to be used (in milliseconds) for the fixed priority
4781: policy. To be meaningful, this quantum must be a multiple of the basic
4782: system quantum (min_quantum) which can be obtained from
4783: @code{host_info}. The system will always round up to the next multiple
4784: of the quantum.
4785:
4786: Processor sets may restrict the allowed policies, so this call will fail
4787: if the processor set to which @var{thread} is currently assigned does
4788: not permit @var{policy}.
4789:
4790: The function returns @code{KERN_SUCCESS} if the call succeeded.
4791: @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a thread or
4792: @var{policy} is not a recognized policy, and @code{KERN_FAILURE} if the
4793: processor set to which @var{thread} is currently assigned does not
4794: permit @var{policy}.
4795: @end deftypefun
4796:
4797:
4798: @node Thread Special Ports
4799: @subsection Thread Special Ports
4800:
4801: @deftypefun kern_return_t thread_get_special_port (@w{thread_t @var{thread}}, @w{int @var{which_port}}, @w{mach_port_t *@var{special_port}})
4802: The function @code{thread_get_special_port} returns send rights to one
4803: of a set of special ports for the thread specified by @var{thread}.
4804:
4805: The possible values for @var{which_port} are @code{THREAD_KERNEL_PORT}
4806: and @code{THREAD_EXCEPTION_PORT}. A thread also has access to its
4807: task's special ports.
4808:
4809: The function returns @code{KERN_SUCCESS} if the port was returned and
4810: @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a thread or
4811: @var{which_port} is an invalid port selector.
4812: @end deftypefun
4813:
4814: @deftypefun kern_return_t thread_get_kernel_port (@w{thread_t @var{thread}}, @w{mach_port_t *@var{kernel_port}})
4815: The function @code{thread_get_kernel_port} is equivalent to the function
4816: @code{thread_get_special_port} with the @var{which_port} argument set to
4817: @code{THREAD_KERNEL_PORT}.
4818: @end deftypefun
4819:
4820: @deftypefun kern_return_t thread_get_exception_port (@w{thread_t @var{thread}}, @w{mach_port_t *@var{exception_port}})
4821: The function @code{thread_get_exception_port} is equivalent to the
4822: function @code{thread_get_special_port} with the @var{which_port}
4823: argument set to @code{THREAD_EXCEPTION_PORT}.
4824: @end deftypefun
4825:
4826: @deftypefun kern_return_t thread_set_special_port (@w{thread_t @var{thread}}, @w{int @var{which_port}}, @w{mach_port_t @var{special_port}})
4827: The function @code{thread_set_special_port} sets one of a set of special
4828: ports for the thread specified by @var{thread}.
4829:
4830: The possible values for @var{which_port} are @code{THREAD_KERNEL_PORT}
4831: and @code{THREAD_EXCEPTION_PORT}. A thread also has access to its
4832: task's special ports.
4833:
4834: The function returns @code{KERN_SUCCESS} if the port was set and
4835: @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a thread or
4836: @var{which_port} is an invalid port selector.
4837: @end deftypefun
4838:
4839: @deftypefun kern_return_t thread_set_kernel_port (@w{thread_t @var{thread}}, @w{mach_port_t @var{kernel_port}})
4840: The function @code{thread_set_kernel_port} is equivalent to the function
4841: @code{thread_set_special_port} with the @var{which_port} argument set to
4842: @code{THREAD_KERNEL_PORT}.
4843: @end deftypefun
4844:
4845: @deftypefun kern_return_t thread_set_exception_port (@w{thread_t @var{thread}}, @w{mach_port_t @var{exception_port}})
4846: The function @code{thread_set_exception_port} is equivalent to the
4847: function @code{thread_set_special_port} with the @var{which_port}
4848: argument set to @code{THREAD_EXCEPTION_PORT}.
4849: @end deftypefun
4850:
4851:
4852: @node Exceptions
4853: @subsection Exceptions
4854:
4855: @deftypefun kern_return_t catch_exception_raise (@w{mach_port_t @var{exception_port}}, @w{thread_t @var{thread}}, @w{task_t @var{task}}, @w{int @var{exception}}, @w{int @var{code}}, @w{int @var{subcode}})
4856: XXX Fixme
4857: @end deftypefun
4858:
4859: @deftypefun kern_return_t exception_raise (@w{mach_port_t @var{exception_port}}, @w{mach_port_t @var{thread}}, @w{mach_port_t @var{task}}, @w{integer_t @var{exception}}, @w{integer_t @var{code}}, @w{integer_t @var{subcode}})
4860: XXX Fixme
4861: @end deftypefun
4862:
4863: @deftypefun kern_return_t evc_wait (@w{unsigned int @var{event}})
4864: @c XXX This is for user space drivers, the description is incomplete.
4865: The system trap @code{evc_wait} makes the calling thread wait for the
4866: event specified by @var{event}.
4867:
1.1.1.2 root 4868: The call returns @code{KERN_SUCCESS} if the event has occurred,
1.1 root 4869: @code{KERN_NO_SPACE} if another thread is waiting for the same event and
4870: @code{KERN_INVALID_ARGUMENT} if the event object is invalid.
4871: @end deftypefun
4872:
4873:
4874: @node Task Interface
4875: @section Task Interface
4876:
4877: @cindex task port
4878: @cindex port representing a task
4879: @deftp {Data type} task_t
4880: This is a @code{mach_port_t} and used to hold the port name of a task
4881: port that represents the thread. Manipulations of the task are
4882: implemented as remote procedure calls to the task port. A task can get
4883: a port to itself with the @code{mach_task_self} system call.
4884:
4885: The task port name is also used to identify the task's IPC space
4886: (@pxref{Port Manipulation Interface}) and the task's virtual memory map
4887: (@pxref{Virtual Memory Interface}).
4888: @end deftp
4889:
4890: @menu
4891: * Task Creation:: Creating tasks.
4892: * Task Termination:: Terminating tasks.
4893: * Task Information:: Informations on tasks.
4894: * Task Execution:: Thread scheduling in a task.
4895: * Task Special Ports:: How to get and set the task's special ports.
4896: * Syscall Emulation:: How to emulate system calls.
4897: @end menu
4898:
4899:
4900: @node Task Creation
4901: @subsection Task Creation
4902:
4903: @deftypefun kern_return_t task_create (@w{task_t @var{parent_task}}, @w{boolean_t @var{inherit_memory}}, @w{task_t *@var{child_task}})
4904: The function @code{task_create} creates a new task from
4905: @var{parent_task}; the resulting task (@var{child_task}) acquires shared
4906: or copied parts of the parent's address space (see @code{vm_inherit}).
4907: The child task initially contains no threads.
4908:
4909: If @var{inherit_memory} is set, the child task's address space is built
4910: from the parent task according to its memory inheritance values;
4911: otherwise, the child task is given an empty address space.
4912:
4913: The child task gets the three special ports created or copied for it at
4914: task creation. The @code{TASK_KERNEL_PORT} is created and send rights
4915: for it are given to the child and returned to the caller.
4916: @c The following is only relevant if MACH_IPC_COMPAT is used.
4917: @c The @code{TASK_NOTIFY_PORT} is created and receive, ownership and send rights
4918: @c for it are given to the child. The caller has no access to it.
4919: The @code{TASK_BOOTSTRAP_PORT} and the @code{TASK_EXCEPTION_PORT} are
4920: inherited from the parent task. The new task can get send rights to
4921: these ports with the call @code{task_get_special_port}.
4922:
4923: The function returns @code{KERN_SUCCESS} if a new task has been created,
4924: @code{KERN_INVALID_ARGUMENT} if @var{parent_task} is not a valid task
4925: port and @code{KERN_RESOURCE_SHORTAGE} if some critical kernel resource
4926: is unavailable.
4927: @end deftypefun
4928:
4929:
4930: @node Task Termination
4931: @subsection Task Termination
4932:
4933: @deftypefun kern_return_t task_terminate (@w{task_t @var{target_task}})
4934: The function @code{task_terminate} destroys the task specified by
4935: @var{target_task} and all its threads. All resources that are used only
4936: by this task are freed. Any port to which this task has receive and
4937: ownership rights is destroyed.
4938:
4939: The function returns @code{KERN_SUCCESS} if the task has been killed,
4940: @code{KERN_INVALID_ARGUMENT} if @var{target_task} is not a task.
4941: @end deftypefun
4942:
4943:
4944: @node Task Information
4945: @subsection Task Information
4946: @deftypefun task_t mach_task_self ()
4947: The @code{mach_task_self} system call returns the calling thread's task
4948: port.
4949:
4950: @code{mach_task_self} has an effect equivalent to receiving a send right
4951: for the task port. @code{mach_task_self} returns the name of the send
4952: right. In particular, successive calls will increase the calling task's
4953: user-reference count for the send right.
4954:
4955: As a special exception, the kernel will overrun the user reference count
4956: of the task name port, so that this function can not fail for that
4957: reason. Because of this, the user should not deallocate the port right
4958: if an overrun might have happened. Otherwise the reference count could
4959: drop to zero and the send right be destroyed while the user still
4960: expects to be able to use it. As the kernel does not make use of the
4961: number of extant send rights anyway, this is safe to do (the task port
4962: itself is not destroyed, even when there are no send rights anymore).
4963:
1.1.1.2 root 4964: The function returns @code{MACH_PORT_NULL} if a resource shortage
1.1 root 4965: prevented the reception of the send right, @code{MACH_PORT_NULL} if the
4966: task port is currently null, @code{MACH_PORT_DEAD} if the task port is
4967: currently dead.
4968: @end deftypefun
4969:
4970: @deftypefun kern_return_t task_threads (@w{task_t @var{target_task}}, @w{thread_array_t *@var{thread_list}}, @w{mach_msg_type_number_t *@var{thread_count}})
4971: The function @code{task_threads} gets send rights to the kernel port for
4972: each thread contained in @var{target_task}. @var{thread_list} is an
4973: array that is created as a result of this call. The caller may wish to
4974: @code{vm_deallocate} this array when the data is no longer needed.
4975:
4976: The function returns @code{KERN_SUCCESS} if the call succeeded and
4977: @code{KERN_INVALID_ARGUMENT} if @var{target_task} is not a task.
4978: @end deftypefun
4979:
4980: @deftypefun kern_return_t task_info (@w{task_t @var{target_task}}, @w{int @var{flavor}}, @w{task_info_t @var{task_info}}, @w{mach_msg_type_number_t *@var{task_info_count}})
4981: The function @code{task_info} returns the selected information array for
4982: a task, as specified by @var{flavor}. @var{task_info} is an array of
4983: integers that is supplied by the caller, and filled with specified
4984: information. @var{task_info_count} is supplied as the maximum number of
4985: integers in @var{task_info}. On return, it contains the actual number
4986: of integers in @var{task_info}. The maximum number of integers returned
4987: by any flavor is @code{TASK_INFO_MAX}.
4988:
4989: The type of information returned is defined by @var{flavor}, which can
4990: be one of the following:
4991:
4992: @table @code
4993: @item TASK_BASIC_INFO
4994: The function returns basic information about the task, as defined by
4995: @code{task_basic_info_t}. This includes the user and system time and
4996: memory consumption. The number of integers returned is
4997: @code{TASK_BASIC_INFO_COUNT}.
4998:
4999: @item TASK_EVENTS_INFO
5000: The function returns information about events for the task as defined by
5001: @code{thread_sched_info_t}. This includes statistics about virtual
5002: memory and IPC events like pageouts, pageins and messages sent and
5003: received. The number of integers returned is
5004: @code{TASK_EVENTS_INFO_COUNT}.
5005:
5006: @item TASK_THREAD_TIMES_INFO
5007: The function returns information about the total time for live threads
5008: as defined by @code{task_thread_times_info_t}. The number of integers
5009: returned is @code{TASK_THREAD_TIMES_INFO_COUNT}.
5010: @end table
5011:
5012: The function returns @code{KERN_SUCCESS} if the call succeeded and
5013: @code{KERN_INVALID_ARGUMENT} if @var{target_task} is not a thread or
5014: @var{flavor} is not recognized. The function returns
5015: @code{MIG_ARRAY_TOO_LARGE} if the returned info array is too large for
5016: @var{task_info}. In this case, @var{task_info} is filled as much as
5017: possible and @var{task_infoCnt} is set to the number of elements that
5018: would have been returned if there were enough room.
5019: @end deftypefun
5020:
5021: @deftp {Data type} {struct task_basic_info}
5022: This structure is returned in @var{task_info} by the @code{task_info}
5023: function and provides basic information about the task. You can cast a
5024: variable of type @code{task_info_t} to a pointer of this type if you
5025: provided it as the @var{task_info} parameter for the
5026: @code{TASK_BASIC_INFO} flavor of @code{task_info}. It has the following
5027: members:
5028:
5029: @table @code
5030: @item integer_t suspend_count
5031: suspend count for task
5032:
5033: @item integer_t base_priority
5034: base scheduling priority
5035:
5036: @item vm_size_t virtual_size
5037: number of virtual pages
5038:
5039: @item vm_size_t resident_size
5040: number of resident pages
5041:
5042: @item time_value_t user_time
5043: total user run time for terminated threads
5044:
5045: @item time_value_t system_time
5046: total system run time for terminated threads
5047:
5048: @item time_value_t creation_time
5049: creation time stamp
5050: @end table
5051: @end deftp
5052:
5053: @deftp {Data type} task_basic_info_t
5054: This is a pointer to a @code{struct task_basic_info}.
5055: @end deftp
5056:
5057: @deftp {Data type} {struct task_events_info}
5058: This structure is returned in @var{task_info} by the @code{task_info}
5059: function and provides event statistics for the task. You can cast a
5060: variable of type @code{task_info_t} to a pointer of this type if you
5061: provided it as the @var{task_info} parameter for the
5062: @code{TASK_EVENTS_INFO} flavor of @code{task_info}. It has the
5063: following members:
5064:
5065: @table @code
5066: @item natural_t faults
5067: number of page faults
5068:
5069: @item natural_t zero_fills
5070: number of zero fill pages
5071:
5072: @item natural_t reactivations
5073: number of reactivated pages
5074:
5075: @item natural_t pageins
5076: number of actual pageins
5077:
5078: @item natural_t cow_faults
5079: number of copy-on-write faults
5080:
5081: @item natural_t messages_sent
5082: number of messages sent
5083:
5084: @item natural_t messages_received
5085: number of messages received
5086: @end table
5087: @end deftp
5088:
5089: @deftp {Data type} task_events_info_t
5090: This is a pointer to a @code{struct task_events_info}.
5091: @end deftp
5092:
5093: @deftp {Data type} {struct task_thread_times_info}
5094: This structure is returned in @var{task_info} by the @code{task_info}
5095: function and provides event statistics for the task. You can cast a
5096: variable of type @code{task_info_t} to a pointer of this type if you
5097: provided it as the @var{task_info} parameter for the
5098: @code{TASK_THREAD_TIMES_INFO} flavor of @code{task_info}. It has the
5099: following members:
5100:
5101: @table @code
5102: @item time_value_t user_time
5103: total user run time for live threads
5104:
5105: @item time_value_t system_time
5106: total system run time for live threads
5107: @end table
5108: @end deftp
5109:
5110: @deftp {Data type} task_thread_times_info_t
5111: This is a pointer to a @code{struct task_thread_times_info}.
5112: @end deftp
5113:
1.1.1.3 root 5114: @deftypefun kern_return_t task_set_name (@w{task_t @var{target_task}}, @w{kernel_debug_name_t @var{name}})
5115:
5116: The function @code{task_set_name} sets the name of @var{target_task}
5117: to @var{name}, truncating it if necessary.
5118:
5119: This is a debugging aid. The name is used in diagnostic messages
5120: printed by the kernel.
5121:
5122: The function returns @code{KERN_SUCCESS} if the call succeeded.
5123: @end deftypefun
5124:
1.1 root 5125:
5126: @node Task Execution
5127: @subsection Task Execution
5128:
5129: @deftypefun kern_return_t task_suspend (@w{task_t @var{target_task}})
5130: The function @code{task_suspend} increments the task's suspend count and
5131: stops all threads in the task. As long as the suspend count is positive
5132: newly created threads will not run. This call does not return until all
5133: threads are suspended.
5134:
5135: The count may become greater than one, with the effect that it will take
5136: more than one resume call to restart the task.
5137:
5138: The function returns @code{KERN_SUCCESS} if the task has been suspended
5139: and @code{KERN_INVALID_ARGUMENT} if @var{target_task} is not a task.
5140: @end deftypefun
5141:
5142: @deftypefun kern_return_t task_resume (@w{task_t @var{target_task}})
5143: The function @code{task_resume} decrements the task's suspend count. If
5144: it becomes zero, all threads with zero suspend counts in the task are
5145: resumed. The count may not become negative.
5146:
5147: The function returns @code{KERN_SUCCESS} if the task has been resumed,
5148: @code{KERN_FAILURE} if the suspend count is already at zero and
5149: @code{KERN_INVALID_ARGUMENT} if @var{target_task} is not a task.
5150: @end deftypefun
5151:
5152: @c XXX Should probably be in the "Scheduling" node of the Thread Interface.
5153: @deftypefun kern_return_t task_priority (@w{task_t @var{task}}, @w{int @var{priority}}, @w{boolean_t @var{change_threads}})
5154: The priority of a task is used only for creation of new threads; a new
5155: thread's priority is set to the enclosing task's priority.
5156: @code{task_priority} changes this task priority. It also sets the
5157: priorities of all threads in the task to this new priority if
5158: @var{change_threads} is @code{TRUE}. Existing threads are not affected
5159: otherwise. If this priority change violates the maximum priority of
5160: some threads, as many threads as possible will be changed and an error
5161: code will be returned.
5162:
5163: The function returns @code{KERN_SUCCESS} if the call succeeded,
5164: @code{KERN_INVALID_ARGUMENT} if @var{task} is not a task, or
5165: @var{priority} is not a valid priority and @code{KERN_FAILURE} if
5166: @var{change_threads} was @code{TRUE} and the attempt to change the
5167: priority of at least one existing thread failed because the new priority
5168: would have exceeded that thread's maximum priority.
5169: @end deftypefun
5170:
5171: @deftypefun kern_return_t task_ras_control (@w{task_t @var{target_task}}, @w{vm_address_t @var{start_pc}}, @w{vm_address_t @var{end_pc}}, @w{int @var{flavor}})
5172: The function @code{task_ras_control} manipulates a task's set of
5173: restartable atomic sequences. If a sequence is installed, and any
5174: thread in the task is preempted within the range
5175: [@var{start_pc},@var{end_pc}], then the thread is resumed at
5176: @var{start_pc}. This enables applications to build atomic sequences
5177: which, when executed to completion, will have executed atomically.
5178: Restartable atomic sequences are intended to be used on systems that do
5179: not have hardware support for low-overhead atomic primitives.
5180:
5181: As a thread can be rolled-back, the code in the sequence should have no
5182: side effects other than a final store at @var{end_pc}. The kernel does
5183: not guarantee that the sequence is restartable. It assumes the
5184: application knows what it's doing.
5185:
5186: A task may have a finite number of atomic sequences that is defined at
5187: compile time.
5188:
1.1.1.2 root 5189: The flavor specifies the particular operation that should be applied to
1.1 root 5190: this restartable atomic sequence. Possible values for flavor can be:
5191:
5192: @table @code
5193: @item TASK_RAS_CONTROL_PURGE_ALL
5194: Remove all registered sequences for this task.
5195:
5196: @item TASK_RAS_CONTROL_PURGE_ONE
5197: Remove the named registered sequence for this task.
5198:
5199: @item TASK_RAS_CONTROL_PURGE_ALL_AND_INSTALL_ONE
5200: Atomically remove all registered sequences and install the named
5201: sequence.
5202:
5203: @item TASK_RAS_CONTROL_INSTALL_ONE
5204: Install this sequence.
5205: @end table
5206:
5207: The function returns @code{KERN_SUCCESS} if the operation has been
5208: performed, @code{KERN_INVALID_ADDRESS} if the @var{start_pc} or
5209: @var{end_pc} values are not a valid address for the requested operation
5210: (for example, it is invalid to purge a sequence that has not been
5211: registered), @code{KERN_RESOURCE_SHORTAGE} if an attempt was made to
5212: install more restartable atomic sequences for a task than can be
5213: supported by the kernel, @code{KERN_INVALID_VALUE} if a bad flavor was
5214: specified, @code{KERN_INVALID_ARGUMENT} if @var{target_task} is not a
5215: task and @code{KERN_FAILURE} if the call is not not supported on this
5216: configuration.
5217: @end deftypefun
5218:
5219:
5220: @node Task Special Ports
5221: @subsection Task Special Ports
5222:
5223: @deftypefun kern_return_t task_get_special_port (@w{task_t @var{task}}, @w{int @var{which_port}}, @w{mach_port_t *@var{special_port}})
5224: The function @code{task_get_special_port} returns send rights to one of
5225: a set of special ports for the task specified by @var{task}.
5226:
5227: The special ports associated with a task are the kernel port
5228: (@code{TASK_KERNEL_PORT}), the bootstrap port
5229: (@code{TASK_BOOTSTRAP_PORT}) and the exception port
5230: (@code{TASK_EXCEPTION_PORT}). The bootstrap port is a port to which a
5231: task may send a message requesting other system service ports. This
5232: port is not used by the kernel. The task's exception port is the port
5233: to which messages are sent by the kernel when an exception occurs and
5234: the thread causing the exception has no exception port of its own.
5235:
5236: The following macros to call @code{task_get_special_port} for a specific
5237: port are defined in @code{mach/task_special_ports.h}:
5238: @code{task_get_exception_port} and @code{task_get_bootstrap_port}.
5239:
5240: The function returns @code{KERN_SUCCESS} if the port was returned and
5241: @code{KERN_INVALID_ARGUMENT} if @var{task} is not a task or
5242: @var{which_port} is an invalid port selector.
5243: @end deftypefun
5244:
5245: @deftypefun kern_return_t task_get_kernel_port (@w{task_t @var{task}}, @w{mach_port_t *@var{kernel_port}})
5246: The function @code{task_get_kernel_port} is equivalent to the function
5247: @code{task_get_special_port} with the @var{which_port} argument set to
5248: @code{TASK_KERNEL_PORT}.
5249: @end deftypefun
5250:
5251: @deftypefun kern_return_t task_get_exception_port (@w{task_t @var{task}}, @w{mach_port_t *@var{exception_port}})
5252: The function @code{task_get_exception_port} is equivalent to the
5253: function @code{task_get_special_port} with the @var{which_port} argument
5254: set to @code{TASK_EXCEPTION_PORT}.
5255: @end deftypefun
5256:
5257: @deftypefun kern_return_t task_get_bootstrap_port (@w{task_t @var{task}}, @w{mach_port_t *@var{bootstrap_port}})
5258: The function @code{task_get_bootstrap_port} is equivalent to the
5259: function @code{task_get_special_port} with the @var{which_port} argument
5260: set to @code{TASK_BOOTSTRAP_PORT}.
5261: @end deftypefun
5262:
5263: @deftypefun kern_return_t task_set_special_port (@w{task_t @var{task}}, @w{int @var{which_port}}, @w{mach_port_t @var{special_port}})
5264: The function @code{thread_set_special_port} sets one of a set of special
5265: ports for the task specified by @var{task}.
5266:
5267: The special ports associated with a task are the kernel port
5268: (@code{TASK_KERNEL_PORT}), the bootstrap port
5269: (@code{TASK_BOOTSTRAP_PORT}) and the exception port
5270: (@code{TASK_EXCEPTION_PORT}). The bootstrap port is a port to which a
5271: thread may send a message requesting other system service ports. This
5272: port is not used by the kernel. The task's exception port is the port
5273: to which messages are sent by the kernel when an exception occurs and
5274: the thread causing the exception has no exception port of its own.
5275:
5276: The function returns @code{KERN_SUCCESS} if the port was set and
5277: @code{KERN_INVALID_ARGUMENT} if @var{task} is not a task or
5278: @var{which_port} is an invalid port selector.
5279: @end deftypefun
5280:
5281: @deftypefun kern_return_t task_set_kernel_port (@w{task_t @var{task}}, @w{mach_port_t @var{kernel_port}})
5282: The function @code{task_set_kernel_port} is equivalent to the function
5283: @code{task_set_special_port} with the @var{which_port} argument set to
5284: @code{TASK_KERNEL_PORT}.
5285: @end deftypefun
5286:
5287: @deftypefun kern_return_t task_set_exception_port (@w{task_t @var{task}}, @w{mach_port_t @var{exception_port}})
5288: The function @code{task_set_exception_port} is equivalent to the
5289: function @code{task_set_special_port} with the @var{which_port} argument
5290: set to @code{TASK_EXCEPTION_PORT}.
5291: @end deftypefun
5292:
5293: @deftypefun kern_return_t task_set_bootstrap_port (@w{task_t @var{task}}, @w{mach_port_t @var{bootstrap_port}})
5294: The function @code{task_set_bootstrap_port} is equivalent to the
5295: function @code{task_set_special_port} with the @var{which_port} argument
5296: set to @code{TASK_BOOTSTRAP_PORT}.
5297: @end deftypefun
5298:
5299:
5300: @node Syscall Emulation
5301: @subsection Syscall Emulation
5302:
5303: @deftypefun kern_return_t task_get_emulation_vector (@w{task_t @var{task}}, @w{int *@var{vector_start}}, @w{emulation_vector_t *@var{emulation_vector}}, @w{mach_msg_type_number_t *@var{emulation_vector_count}})
5304: The function @code{task_get_emulation_vector} gets the user-level
5305: handler entry points for all emulated system calls.
5306: @c XXX Fixme
5307: @end deftypefun
5308:
5309: @deftypefun kern_return_t task_set_emulation_vector (@w{task_t @var{task}}, @w{int @var{vector_start}}, @w{emulation_vector_t @var{emulation_vector}}, @w{mach_msg_type_number_t @var{emulation_vector_count}})
5310: The function @code{task_set_emulation_vector} establishes user-level
5311: handlers for the specified system calls. Non-emulated system calls are
5312: specified with an entry of @code{EML_ROUTINE_NULL}. System call
1.1.1.2 root 5313: emulation handlers are inherited by the children of @var{task}.
1.1 root 5314: @c XXX Fixme
5315: @end deftypefun
5316:
5317: @deftypefun kern_return_t task_set_emulation (@w{task_t @var{task}}, @w{vm_address_t @var{routine_entry_pt}}, @w{int @var{routine_number}})
5318: The function @code{task_set_emulation} establishes a user-level handler
5319: for the specified system call. System call emulation handlers are
1.1.1.2 root 5320: inherited by the children of @var{task}.
1.1 root 5321: @c XXX Fixme
5322: @end deftypefun
5323:
5324: @c XXX Fixme datatype emulation_vector_t
5325:
5326:
5327: @node Profiling
5328: @section Profiling
5329:
5330: @deftypefun kern_return_t task_enable_pc_sampling (@w{task_t @var{task}}, @w{int *@var{ticks}}, @w{sampled_pc_flavor_t @var{flavor}})
5331: @deftypefunx kern_return_t thread_enable_pc_sampling (@w{thread_t @var{thread}}, @w{int *@var{ticks}}, @w{sampled_pc_flavor_t @var{flavor}})
5332: The function @code{task_enable_pc_sampling} enables PC sampling for
5333: @var{task}, the function @code{thread_enable_pc_sampling} enables PC
5334: sampling for @var{thread}. The kernel's idea of clock granularity is
5335: returned in @var{ticks} in usecs. (this value should not be trusted). The
5336: sampling flavor is specified by @var{flavor}.
5337:
5338: The function returns @code{KERN_SUCCESS} if the operation is completed successfully
5339: and @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a valid thread.
5340: @end deftypefun
5341:
5342: @deftypefun kern_return_t task_disable_pc_sampling (@w{task_t @var{task}}, @w{int *@var{sample_count}})
5343: @deftypefunx kern_return_t thread_disable_pc_sampling (@w{thread_t @var{thread}}, @w{int *@var{sample_count}})
5344: The function @code{task_disable_pc_sampling} disables PC sampling for
5345: @var{task}, the function @code{thread_disable_pc_sampling} disables PC
5346: sampling for @var{thread}. The number of sample elements in the kernel
5347: for the thread is returned in @var{sample_count}.
5348:
5349: The function returns @code{KERN_SUCCESS} if the operation is completed successfully
5350: and @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a valid thread.
5351: @end deftypefun
5352:
5353: @deftypefun kern_return_t task_get_sampled_pcs (@w{task_t @var{task}}, @w{sampled_pc_seqno_t *@var{seqno}}, @w{sampled_pc_array_t @var{sampled_pcs}}, @w{mach_msg_type_number_t *@var{sample_count}})
5354: @deftypefunx kern_return_t thread_get_sampled_pcs (@w{thread_t @var{thread}}, @w{sampled_pc_seqno_t *@var{seqno}}, @w{sampled_pc_array_t @var{sampled_pcs}}, @w{int *@var{sample_count}})
5355: The function @code{task_get_sampled_pcs} extracts the PC samples for
5356: @var{task}, the function @code{thread_get_sampled_pcs} extracts the PC
5357: samples for @var{thread}. @var{seqno} is the sequence number of the
5358: sampled PCs. This is useful for determining when a collector thread has
5359: missed a sample. The sampled PCs for the thread are returned in
5360: @var{sampled_pcs}. @var{sample_count} contains the number of sample
5361: elements returned.
5362:
5363: The function returns @code{KERN_SUCCESS} if the operation is completed successfully,
5364: @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a valid thread and
5365: @code{KERN_FAILURE} if @var{thread} is not sampled.
5366: @end deftypefun
5367:
5368:
5369: @deftp {Data type} sampled_pc_t
5370: This structure is returned in @var{sampled_pcs} by the
5371: @code{thread_get_sampled_pcs} and @code{task_get_sampled_pcs} functions
5372: and provides pc samples for threads or tasks. It has the following
5373: members:
5374:
5375: @table @code
5376: @item natural_t id
5377: A thread-specific unique identifier.
5378:
5379: @item vm_offset_t pc
5380: A pc value.
5381:
5382: @item sampled_pc_flavor_t sampletype
5383: The type of the sample as per flavor.
5384: @end table
5385: @end deftp
5386:
5387:
5388: @deftp {Data type} sampled_pc_flavor_t
5389: This data type specifies a pc sample flavor, either as argument passed
5390: in @var{flavor} to the @code{thread_enable_pc_sample} and
5391: @code{thread_disable_pc_sample} functions, or as member
5392: @code{sampletype} in the @code{sample_pc_t} data type. The flavor is a
5393: bitwise-or of the possible flavors defined in @file{mach/pc_sample.h}:
5394:
5395: @table @code
5396: @item SAMPLED_PC_PERIODIC
5397: default
5398: @item SAMPLED_PC_VM_ZFILL_FAULTS
5399: zero filled fault
5400: @item SAMPLED_PC_VM_REACTIVATION_FAULTS
5401: reactivation fault
5402: @item SAMPLED_PC_VM_PAGEIN_FAULTS
5403: pagein fault
5404: @item SAMPLED_PC_VM_COW_FAULTS
5405: copy-on-write fault
5406: @item SAMPLED_PC_VM_FAULTS_ANY
5407: any fault
5408: @item SAMPLED_PC_VM_FAULTS
5409: the bitwise-or of @code{SAMPLED_PC_VM_ZFILL_FAULTS},
5410: @code{SAMPLED_PC_VM_REACTIVATION_FAULTS},
5411: @code{SAMPLED_PC_VM_PAGEIN_FAULTS} and @code{SAMPLED_PC_VM_COW_FAULTS}.
5412: @end table
5413: @end deftp
5414:
5415: @c XXX sampled_pc_array_t, sampled_pc_seqno_t
5416:
5417:
5418: @node Host Interface
5419: @chapter Host Interface
5420: @cindex host interface
5421:
5422: This section describes the Mach interface to a host executing a Mach
5423: kernel. The interface allows to query statistics about a host and
5424: control its behaviour.
5425:
5426: A host is represented by two ports, a name port @var{host} used to query
5427: information about the host accessible to everyone, and a control port
5428: @var{host_priv} used to manipulate it. For example, you can query the
5429: current time using the name port, but to change the time you need to
5430: send a message to the host control port.
5431:
5432: Everything described in this section is declared in the header file
5433: @file{mach.h}.
5434:
5435: @menu
5436: * Host Ports:: Ports representing a host.
5437: * Host Information:: Retrieval of information about a host.
5438: * Host Time:: Operations on the time as seen by a host.
5439: * Host Reboot:: Rebooting the system.
5440: @end menu
5441:
5442:
5443: @node Host Ports
5444: @section Host Ports
5445: @cindex host ports
5446: @cindex ports representing a host
5447:
5448: @cindex host name port
5449: @deftp {Data type} host_t
5450: This is a @code{mach_port_t} and used to hold the port name of a host
5451: name port (or short: host port). Any task can get a send right to the
5452: name port of the host running the task using the @code{mach_host_self}
5453: system call. The name port can be used query information about the
5454: host, for example the current time.
5455: @end deftp
5456:
5457: @deftypefun host_t mach_host_self ()
5458: The @code{mach_host_self} system call returns the calling thread's host
5459: name port. It has an effect equivalent to receiving a send right for
5460: the host port. @code{mach_host_self} returns the name of the send
5461: right. In particular, successive calls will increase the calling task's
5462: user-reference count for the send right.
5463:
5464: As a special exception, the kernel will overrun the user reference count
5465: of the host name port, so that this function can not fail for that
5466: reason. Because of this, the user should not deallocate the port right
5467: if an overrun might have happened. Otherwise the reference count could
5468: drop to zero and the send right be destroyed while the user still
5469: expects to be able to use it. As the kernel does not make use of the
5470: number of extant send rights anyway, this is safe to do (the host port
5471: itself is never destroyed).
5472:
5473: The function returns @code{MACH_PORT_NULL} if a resource shortage
5474: prevented the reception of the send right.
5475:
5476: This function is also available in @file{mach/mach_traps.h}.
5477: @end deftypefun
5478:
5479: @cindex host control port
5480: @deftp {Data type} host_priv_t
5481: This is a @code{mach_port_t} and used to hold the port name of a
5482: privileged host control port. A send right to the host control port is
5483: inserted into the first task at bootstrap (@pxref{Modules}). This is
5484: the only way to get access to the host control port in Mach, so the
5485: initial task has to preserve the send right carefully, moving a copy of
5486: it to other privileged tasks if necessary and denying access to
5487: unprivileged tasks.
5488: @end deftp
5489:
5490:
5491: @node Host Information
5492: @section Host Information
5493:
5494: @deftypefun kern_return_t host_info (@w{host_t @var{host}}, @w{int @var{flavor}}, @w{host_info_t @var{host_info}}, @w{mach_msg_type_number_t *@var{host_info_count}})
5495: The @code{host_info} function returns various information about
5496: @var{host}. @var{host_info} is an array of integers that is supplied by
5497: the caller. It will be filled with the requested information.
5498: @var{host_info_count} is supplied as the maximum number of integers in
5499: @var{host_info}. On return, it contains the actual number of integers
5500: in @var{host_info}. The maximum number of integers returned by any
5501: flavor is @code{HOST_INFO_MAX}.
5502:
5503: The type of information returned is defined by @var{flavor}, which can
5504: be one of the following:
5505:
5506: @table @code
5507: @item HOST_BASIC_INFO
5508: The function returns basic information about the host, as defined by
5509: @code{host_basic_info_t}. This includes the number of processors, their
5510: type, and the amount of memory installed in the system. The number of
5511: integers returned is @code{HOST_BASIC_INFO_COUNT}. For how to get more
5512: information about the processor, see @ref{Processor Interface}.
5513:
5514: @item HOST_PROCESSOR_SLOTS
5515: The function returns the numbers of the slots with active processors in
5516: them. The number of integers returned can be up to @code{max_cpus}, as
5517: returned by the @code{HOST_BASIC_INFO} flavor of @code{host_info}.
5518:
5519: @item HOST_SCHED_INFO
5520: The function returns information of interest to schedulers as defined by
5521: @code{host_sched_info_t}. The number of integers returned is
5522: @code{HOST_SCHED_INFO_COUNT}.
5523: @end table
5524:
5525: The function returns @code{KERN_SUCCESS} if the call succeeded and
5526: @code{KERN_INVALID_ARGUMENT} if @var{host} is not a host or @var{flavor}
5527: is not recognized. The function returns @code{MIG_ARRAY_TOO_LARGE} if
5528: the returned info array is too large for @var{host_info}. In this case,
5529: @var{host_info} is filled as much as possible and @var{host_info_count}
5530: is set to the number of elements that would be returned if there were
5531: enough room.
5532: @c BUGS Availability limited. Systems without this call support a
5533: @c host_info call with an incompatible calling sequence.
5534: @end deftypefun
5535:
5536: @deftp {Data type} {struct host_basic_info}
5537: A pointer to this structure is returned in @var{host_info} by the
5538: @code{host_info} function and provides basic information about the host.
5539: You can cast a variable of type @code{host_info_t} to a pointer of this
5540: type if you provided it as the @var{host_info} parameter for the
5541: @code{HOST_BASIC_INFO} flavor of @code{host_info}. It has the following
5542: members:
5543:
5544: @table @code
5545: @item int max_cpus
5546: The maximum number of possible processors for which the kernel is
5547: configured.
5548:
5549: @item int avail_cpus
5550: The number of cpus currently available.
5551:
5552: @item vm_size_t memory_size
5553: The size of physical memory in bytes.
5554:
5555: @item cpu_type_t cpu_type
5556: The type of the master processor.
5557:
5558: @item cpu_subtype_t cpu_subtype
5559: The subtype of the master processor.
5560: @end table
5561:
5562: The type and subtype of the individual processors are also available
5563: by @code{processor_info}, see @ref{Processor Interface}.
5564: @end deftp
5565:
5566: @deftp {Data type} host_basic_info_t
5567: This is a pointer to a @code{struct host_basic_info}.
5568: @end deftp
5569:
5570: @deftp {Data type} {struct host_sched_info}
5571: A pointer to this structure is returned in @var{host_info} by the
5572: @code{host_info} function and provides information of interest to
5573: schedulers. You can cast a variable of type @code{host_info_t} to a
5574: pointer of this type if you provided it as the @var{host_info} parameter
5575: for the @code{HOST_SCHED_INFO} flavor of @code{host_info}. It has the
5576: following members:
5577:
5578: @table @code
5579: @item int min_timeout
5580: The minimum timeout and unit of time in milliseconds.
5581:
5582: @item int min_quantum
5583: The minimum quantum and unit of quantum in milliseconds.
5584: @end table
5585: @end deftp
5586:
5587: @deftp {Data type} host_sched_info_t
5588: This is a pointer to a @code{struct host_sched_info}.
5589: @end deftp
5590:
5591: @deftypefun kern_return_t host_kernel_version (@w{host_t @var{host}}, @w{kernel_version_t *@var{version}})
5592: The @code{host_kernel_version} function returns the version string
5593: compiled into the kernel executing on @var{host} at the time it was
5594: built in the character string @var{version}. This string describes the
5595: version of the kernel. The constant @code{KERNEL_VERSION_MAX} should be
5596: used to dimension storage for the returned string if the
5597: @code{kernel_version_t} declaration is not used.
5598:
5599: If the version string compiled into the kernel is longer than
5600: @code{KERNEL_VERSION_MAX}, the result is truncated and not necessarily
5601: null-terminated.
5602:
5603: If @var{host} is not a valid send right to a host port, the function
5604: returns @code{KERN_INVALID_ARGUMENT}. If @var{version} points to
5605: inaccessible memory, it returns @code{KERN_INVALID_ADDRESS}, and
5606: @code{KERN_SUCCESS} otherwise.
5607: @end deftypefun
5608:
5609: @deftypefun kern_return_t host_get_boot_info (@w{host_priv_t @var{host_priv}}, @w{kernel_boot_info_t @var{boot_info}})
5610: The @code{host_get_boot_info} function returns the boot-time information
5611: string supplied by the operator to the kernel executing on
5612: @var{host_priv} in the character string @var{boot_info}. The constant
5613: @code{KERNEL_BOOT_INFO_MAX} should be used to dimension storage for the
5614: returned string if the @code{kernel_boot_info_t} declaration is not
5615: used.
5616:
5617: If the boot-time information string supplied by the operator is longer
5618: than @code{KERNEL_BOOT_INFO_MAX}, the result is truncated and not
5619: necessarily null-terminated.
5620: @end deftypefun
5621:
5622:
5623: @node Host Time
5624: @section Host Time
5625:
5626: @deftp {Data type} time_value_t
5627: This is the representation of a time in Mach. It is a @code{struct
5628: time_value} and consists of the following members:
5629:
5630: @table @code
5631: @item integer_t seconds
5632: The number of seconds.
5633: @item integer_t microseconds
5634: The number of microseconds.
5635: @end table
5636: @end deftp
5637:
5638: The number of microseconds should always be smaller than
5639: @code{TIME_MICROS_MAX} (100000). A time with this property is
5640: @dfn{normalized}. Normalized time values can be manipulated with the
5641: following macros:
5642:
5643: @defmac time_value_add_usec (@w{time_value_t *@var{val}}, @w{integer_t *@var{micros}})
5644: Add @var{micros} microseconds to @var{val}. If @var{val} is normalized
5645: and @var{micros} smaller than @code{TIME_MICROS_MAX}, @var{val} will be
5646: normalized afterwards.
5647: @end defmac
5648:
5649: @defmac time_value_add (@w{time_value_t *@var{result}}, @w{time_value_t *@var{addend}})
5650: Add the values in @var{addend} to @var{result}. If both are normalized,
5651: @var{result} will be normalized afterwards.
5652: @end defmac
5653:
5654: A variable of type @code{time_value_t} can either represent a duration
5655: or a fixed point in time. In the latter case, it shall be interpreted as
5656: the number of seconds and microseconds after the epoch 1. Jan 1970.
5657:
5658: @deftypefun kern_return_t host_get_time (@w{host_t @var{host}}, @w{time_value_t *@var{current_time}})
5659: Get the current time as seen by @var{host}. On success, the time passed
5660: since the epoch is returned in @var{current_time}.
5661: @end deftypefun
5662:
5663: @deftypefun kern_return_t host_set_time (@w{host_priv_t @var{host_priv}}, @w{time_value_t @var{new_time}})
5664: Set the time of @var{host_priv} to @var{new_time}.
5665: @end deftypefun
5666:
5667: @deftypefun kern_return_t host_adjust_time (@w{host_priv_t @var{host_priv}}, @w{time_value_t @var{new_adjustment}}, @w{time_value_t *@var{old_adjustment}})
5668: Arrange for the current time as seen by @var{host_priv} to be gradually
5669: changed by the adjustment value @var{new_adjustment}, and return the old
5670: adjustment value in @var{old_adjustment}.
5671: @end deftypefun
5672:
5673: For efficiency, the current time is available through a mapped-time
5674: interface.
5675:
5676: @deftp {Data type} mapped_time_value_t
5677: This structure defines the mapped-time interface. It has the following
5678: members:
5679:
5680: @table @code
5681: @item integer_t seconds
5682: The number of seconds.
5683:
5684: @item integer_t microseconds
5685: The number of microseconds.
5686:
5687: @item integer_t check_seconds
5688: This is a copy of the seconds value, which must be checked to protect
5689: against a race condition when reading out the two time values.
5690: @end table
5691: @end deftp
5692:
5693: Here is an example how to read out the current time using the
5694: mapped-time interface:
5695:
5696: @c XXX Complete the example.
5697: @example
5698: do
5699: @{
5700: secs = mtime->seconds;
5701: usecs = mtime->microseconds;
5702: @}
5703: while (secs != mtime->check_seconds);
5704: @end example
5705:
5706:
5707: @node Host Reboot
5708: @section Host Reboot
5709:
5710: @deftypefun kern_return_t host_reboot (@w{host_priv_t @var{host_priv}}, @w{int @var{options}})
5711: Reboot the host specified by @var{host_priv}. The argument
5712: @var{options} specifies the flags. The available flags are defined in
5713: @file{sys/reboot.h}:
5714:
5715: @table @code
5716: @item RB_HALT
5717: Do not reboot, but halt the machine.
5718:
5719: @item RB_DEBUGGER
5720: Do not reboot, but enter kernel debugger from user space.
5721: @end table
5722:
5723: If successful, the function might not return.
5724: @end deftypefun
5725:
5726:
5727: @node Processors and Processor Sets
5728: @chapter Processors and Processor Sets
5729:
5730: This section describes the Mach interface to processor sets and
5731: individual processors. The interface allows to group processors into
5732: sets and control the processors and processor sets.
5733:
5734: A processor is not a central part of the interface. It is mostly of
5735: relevance as a part of a processor set. Threads are always assigned to
5736: processor sets, and all processors in a set are equally involved in
5737: executing all threads assigned to that set.
5738:
5739: The processor set is represented by two ports, a name port
5740: @var{processor_set_name} used to query information about the host
5741: accessible to everyone, and a control port @var{processor_set} used to
5742: manipulate it.
5743:
5744: @menu
5745: * Processor Set Interface:: How to work with processor sets.
5746: * Processor Interface:: How to work with individual processors.
5747: @end menu
5748:
5749:
5750: @node Processor Set Interface
5751: @section Processor Set Interface
5752:
5753: @menu
5754: * Processor Set Ports:: Ports representing a processor set.
5755: * Processor Set Access:: How the processor sets are accessed.
5756: * Processor Set Creation:: How new processor sets are created.
5757: * Processor Set Destruction:: How processor sets are destroyed.
5758: * Tasks and Threads on Sets:: Assigning tasks, threads to processor sets.
5759: * Processor Set Priority:: Specifying the priority of a processor set.
5760: * Processor Set Policy:: Changing the processor set policies.
5761: * Processor Set Info:: Obtaining information about a processor set.
5762: @end menu
5763:
5764:
5765: @node Processor Set Ports
5766: @subsection Processor Set Ports
5767: @cindex processor set ports
5768: @cindex ports representing a processor set
5769:
5770: @cindex processor set name port
5771: @cindex port representing a processor set name
5772: @deftp {Data type} processor_set_name_t
5773: This is a @code{mach_port_t} and used to hold the port name of a
5774: processor set name port that names the processor set. Any task can get
5775: a send right to name port of a processor set. The processor set name
5776: port allows to get information about the processor set.
5777: @end deftp
5778:
5779: @cindex processor set port
5780: @deftp {Data type} processor_set_t
5781: This is a @code{mach_port_t} and used to hold the port name of a
5782: privileged processor set control port that represents the processor set.
5783: Operations on the processor set are implemented as remote procedure
5784: calls to the processor set port. The processor set port allows to
5785: manipulate the processor set.
5786: @end deftp
5787:
5788:
5789: @node Processor Set Access
5790: @subsection Processor Set Access
5791:
5792: @deftypefun kern_return_t host_processor_sets (@w{host_t @var{host}}, @w{processor_set_name_array_t *@var{processor_sets}}, @w{mach_msg_type_number_t *@var{processor_sets_count}})
5793: The function @code{host_processor_sets} gets send rights to the name
5794: port for each processor set currently assigned to @var{host}.
5795:
5796: @code{host_processor_set_priv} can be used to obtain the control ports
5797: from these if desired. @var{processor_sets} is an array that is
5798: created as a result of this call. The caller may wish to
5799: @code{vm_deallocate} this array when the data is no longer needed.
5800: @var{processor_sets_count} is set to the number of processor sets in the
5801: @var{processor_sets}.
5802:
5803: This function returns @code{KERN_SUCCESS} if the call succeeded and
5804: @code{KERN_INVALID_ARGUMENT} if @var{host} is not a host.
5805: @end deftypefun
5806:
5807: @deftypefun kern_return_t host_processor_set_priv (@w{host_priv_t @var{host_priv}}, @w{processor_set_name_t @var{set_name}}, @w{processor_set_t *@var{set}})
5808: The function @code{host_processor_set_priv} allows a privileged
5809: application to obtain the control port @var{set} for an existing
5810: processor set from its name port @var{set_name}. The privileged host
5811: port @var{host_priv} is required.
5812:
5813: This function returns @code{KERN_SUCCESS} if the call succeeded and
5814: @code{KERN_INVALID_ARGUMENT} if @var{host_priv} is not a valid host
5815: control port.
5816: @end deftypefun
5817:
5818: @deftypefun kern_return_t processor_set_default (@w{host_t @var{host}}, @w{processor_set_name_t *@var{default_set}})
5819: The function @code{processor_set_default} returns the default processor
5820: set of @var{host} in @var{default_set}. The default processor set is
5821: used by all threads, tasks, and processors that are not explicitly
5822: assigned to other sets. processor_set_default returns a port that can
5823: be used to obtain information about this set (e.g. how many threads are
5824: assigned to it). This port cannot be used to perform operations on that
5825: set.
5826:
5827: This function returns @code{KERN_SUCCESS} if the call succeeded,
5828: @code{KERN_INVALID_ARGUMENT} if @var{host} is not a host and
5829: @code{KERN_INVALID_ADDRESS} if @var{default_set} points to
5830: inaccessible memory.
5831: @end deftypefun
5832:
5833:
5834: @node Processor Set Creation
5835: @subsection Processor Set Creation
5836:
5837: @deftypefun kern_return_t processor_set_create (@w{host_t @var{host}}, @w{processor_set_t *@var{new_set}}, @w{processor_set_name_t *@var{new_name}})
5838: The function @code{processor_set_create} creates a new processor set on
5839: @var{host} and returns the two ports associated with it. The port
5840: returned in @var{new_set} is the actual port representing the set. It
5841: is used to perform operations such as assigning processors, tasks, or
5842: threads. The port returned in @var{new_name} identifies the set, and is
5843: used to obtain information about the set.
5844:
5845: This function returns @code{KERN_SUCCESS} if the call succeeded,
5846: @code{KERN_INVALID_ARGUMENT} if @var{host} is not a host,
5847: @code{KERN_INVALID_ADDRESS} if @var{new_set} or @var{new_name} points to
5848: inaccessible memory and @code{KERN_FAILURE} is the operating system does
5849: not support processor allocation.
5850: @end deftypefun
5851:
5852:
5853: @node Processor Set Destruction
5854: @subsection Processor Set Destruction
5855:
5856: @deftypefun kern_return_t processor_set_destroy (@w{processor_set_t @var{processor_set}})
5857: The function @code{processor_set_destroy} destroys the specified
5858: processor set. Any assigned processors, tasks, or threads are
5859: reassigned to the default set. The object port for the processor set is
5860: required (not the name port). The default processor set cannot be
5861: destroyed.
5862:
5863: This function returns @code{KERN_SUCCESS} if the set was destroyed,
5864: @code{KERN_FAILURE} if an attempt was made to destroy the default
5865: processor set, or the operating system does not support processor
5866: allocation, and @code{KERN_INVALID_ARGUMENT} if @var{processor_set} is
5867: not a valid processor set control port.
5868: @end deftypefun
5869:
5870:
5871: @node Tasks and Threads on Sets
5872: @subsection Tasks and Threads on Sets
5873:
5874: @deftypefun kern_return_t processor_set_tasks (@w{processor_set_t @var{processor_set}}, @w{task_array_t *@var{task_list}}, @w{mach_msg_type_number_t *@var{task_count}})
5875: The function @code{processor_set_tasks} gets send rights to the kernel
5876: port for each task currently assigned to @var{processor_set}.
5877:
5878: @var{task_list} is an array that is created as a result of this call.
5879: The caller may wish to @code{vm_deallocate} this array when the data is
5880: no longer needed. @var{task_count} is set to the number of tasks in the
5881: @var{task_list}.
5882:
5883: This function returns @code{KERN_SUCCESS} if the call succeeded and
5884: @code{KERN_INVALID_ARGUMENT} if @var{processor_set} is not a processor
5885: set.
5886: @end deftypefun
5887:
5888: @deftypefun kern_return_t processor_set_threads (@w{processor_set_t @var{processor_set}}, @w{thread_array_t *@var{thread_list}}, @w{mach_msg_type_number_t *@var{thread_count}})
5889: The function @code{processor_set_thread} gets send rights to the kernel
5890: port for each thread currently assigned to @var{processor_set}.
5891:
5892: @var{thread_list} is an array that is created as a result of this call.
5893: The caller may wish to @code{vm_deallocate} this array when the data is
5894: no longer needed. @var{thread_count} is set to the number of threads in
5895: the @var{thread_list}.
5896:
5897: This function returns @code{KERN_SUCCESS} if the call succeeded and
5898: @code{KERN_INVALID_ARGUMENT} if @var{processor_set} is not a processor
5899: set.
5900: @end deftypefun
5901:
5902: @deftypefun kern_return_t task_assign (@w{task_t @var{task}}, @w{processor_set_t @var{processor_set}}, @w{boolean_t @var{assign_threads}})
5903: The function @code{task_assign} assigns @var{task} the set
5904: @var{processor_set}. This assignment is for the purposes of determining
5905: the initial assignment of newly created threads in task. Any previous
5906: assignment of the task is nullified. Existing threads within the task
5907: are also reassigned if @var{assign_threads} is @code{TRUE}. They are
5908: not affected if it is @code{FALSE}.
5909:
5910: This function returns @code{KERN_SUCCESS} if the assignment has been
5911: performed and @code{KERN_INVALID_ARGUMENT} if @var{task} is not a task,
5912: or @var{processor_set} is not a processor set on the same host as
5913: @var{task}.
5914: @end deftypefun
5915:
5916: @deftypefun kern_return_t task_assign_default (@w{task_t @var{task}}, @w{boolean_t @var{assign_threads}})
5917: The function @code{task_assign_default} is a variant of
5918: @code{task_assign} that assigns the task to the default processor set on
5919: that task's host. This variant exists because the control port for the
1.1.1.2 root 5920: default processor set is privileged and not usually available to users.
1.1 root 5921:
5922: This function returns @code{KERN_SUCCESS} if the assignment has been
5923: performed and @code{KERN_INVALID_ARGUMENT} if @var{task} is not a task.
5924: @end deftypefun
5925:
5926: @deftypefun kern_return_t task_get_assignment (@w{task_t @var{task}}, @w{processor_set_name_t *@var{assigned_set}})
5927: The function @code{task_get_assignment} returns the name of the
5928: processor set to which the thread is currently assigned in
5929: @var{assigned_set}. This port can only be used to obtain information
5930: about the processor set.
5931:
5932: This function returns @code{KERN_SUCCESS} if the assignment has been
5933: performed, @code{KERN_INVALID_ADDRESS} if @var{processor_set} points to
5934: inaccessible memory, and @code{KERN_INVALID_ARGUMENT} if @var{task} is
5935: not a task.
5936: @end deftypefun
5937:
5938: @deftypefun kern_return_t thread_assign (@w{thread_t @var{thread}}, @w{processor_set_t @var{processor_set}})
5939: The function @code{thread_assign} assigns @var{thread} the set
5940: @var{processor_set}. After the assignment is completed, the thread only
5941: executes on processors assigned to the designated processor set. If
5942: there are no such processors, then the thread is unable to execute. Any
5943: previous assignment of the thread is nullified. Unix system call
5944: compatibility code may temporarily force threads to execute on the
5945: master processor.
5946:
5947: This function returns @code{KERN_SUCCESS} if the assignment has been
5948: performed and @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a
5949: thread, or @var{processor_set} is not a processor set on the same host
5950: as @var{thread}.
5951: @end deftypefun
5952:
5953: @deftypefun kern_return_t thread_assign_default (@w{thread_t @var{thread}})
5954: The function @code{thread_assign_default} is a variant of
5955: @code{thread_assign} that assigns the thread to the default processor
5956: set on that thread's host. This variant exists because the control port
1.1.1.2 root 5957: for the default processor set is privileged and not usually available
1.1 root 5958: to users.
5959:
5960: This function returns @code{KERN_SUCCESS} if the assignment has been
5961: performed and @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a
5962: thread.
5963: @end deftypefun
5964:
5965: @deftypefun kern_return_t thread_get_assignment (@w{thread_t @var{thread}}, @w{processor_set_name_t *@var{assigned_set}})
5966: The function @code{thread_get_assignment} returns the name of the
5967: processor set to which the thread is currently assigned in
5968: @var{assigned_set}. This port can only be used to obtain information
5969: about the processor set.
5970:
5971: This function returns @code{KERN_SUCCESS} if the assignment has been
5972: performed, @code{KERN_INVALID_ADDRESS} if @var{processor_set} points to
5973: inaccessible memory, and @code{KERN_INVALID_ARGUMENT} if @var{thread} is
5974: not a thread.
5975: @end deftypefun
5976:
5977:
5978: @node Processor Set Priority
5979: @subsection Processor Set Priority
5980:
5981: @deftypefun kern_return_t processor_set_max_priority (@w{processor_set_t @var{processor_set}}, @w{int @var{max_priority}}, @w{boolean_t @var{change_threads}})
5982: The function @code{processor_set_max_priority} is used to set the
5983: maximum priority for a processor set. The priority of a processor set
5984: is used only for newly created threads (thread's maximum priority is set
5985: to processor set's) and the assignment of threads to the set (thread's
5986: maximum priority is reduced if it exceeds the set's maximum priority,
5987: thread's priority is similarly reduced).
5988: @code{processor_set_max_priority} changes this priority. It also sets
5989: the maximum priority of all threads assigned to the processor set to
5990: this new priority if @var{change_threads} is @code{TRUE}. If this
5991: maximum priority is less than the priorities of any of these threads,
5992: their priorities will also be set to this new value.
5993:
5994: This function returns @code{KERN_SUCCESS} if the call succeeded and
5995: @code{KERN_INVALID_ARGUMENT} if @var{processor_set} is not a processor
5996: set or @var{priority} is not a valid priority.
5997: @end deftypefun
5998:
5999:
6000: @node Processor Set Policy
6001: @subsection Processor Set Policy
6002:
6003: @deftypefun kern_return_t processor_set_policy_enable (@w{processor_set_t @var{processor_set}}, @w{int @var{policy}})
6004: @deftypefunx kern_return_t processor_set_policy_disable (@w{processor_set_t @var{processor_set}}, @w{int @var{policy}}, @w{boolean_t @var{change_threads}})
6005: Processor sets may restrict the scheduling policies to be used for
6006: threads assigned to them. These two calls provide the mechanism for
6007: designating permitted and forbidden policies. The current set of
6008: permitted policies can be obtained from @code{processor_set_info}.
6009: Timesharing may not be forbidden by any processor set. This is a
6010: compromise to reduce the complexity of the assign operation; any thread
6011: whose policy is forbidden by the target processor set has its policy
6012: reset to timesharing. If the @var{change_threads} argument to
6013: @code{processor_set_policy_disable} is true, threads currently assigned
6014: to this processor set and using the newly disabled policy will have
6015: their policy reset to timesharing.
6016:
6017: @file{mach/policy.h} contains the allowed policies; it is included by
6018: @file{mach.h}. Not all policies (e.g. fixed priority) are supported by
6019: all systems.
6020:
6021: This function returns @code{KERN_SUCCESS} if the operation was completed
6022: successfully and @code{KERN_INVALID_ARGUMENT} if @var{processor_set} is
6023: not a processor set or @var{policy} is not a valid policy, or an attempt
6024: was made to disable timesharing.
6025: @end deftypefun
6026:
6027:
6028: @node Processor Set Info
6029: @subsection Processor Set Info
6030:
6031: @deftypefun kern_return_t processor_set_info (@w{processor_set_name_t @var{set_name}}, @w{int @var{flavor}}, @w{host_t *@var{host}}, @w{processor_set_info_t @var{processor_set_info}}, @w{mach_msg_type_number_t *@var{processor_set_info_count}})
6032: The function @code{processor_set_info} returns the selected information array
6033: for a processor set, as specified by @var{flavor}.
6034:
6035: @var{host} is set to the host on which the processor set resides. This
6036: is the non-privileged host port.
6037:
6038: @var{processor_set_info} is an array of integers that is supplied by the
6039: caller and returned filled with specified information.
6040: @var{processor_set_info_count} is supplied as the maximum number of
6041: integers in @var{processor_set_info}. On return, it contains the actual
6042: number of integers in @var{processor_set_info}. The maximum number of
6043: integers returned by any flavor is @code{PROCESSOR_SET_INFO_MAX}.
6044:
6045: The type of information returned is defined by @var{flavor}, which can
6046: be one of the following:
6047:
6048: @table @code
6049: @item PROCESSOR_SET_BASIC_INFO
6050: The function returns basic information about the processor set, as
6051: defined by @code{processor_set_basic_info_t}. This includes the number
6052: of tasks and threads assigned to the processor set. The number of
6053: integers returned is @code{PROCESSOR_SET_BASIC_INFO_COUNT}.
6054:
6055: @item PROCESSOR_SET_SCHED_INFO
1.1.1.2 root 6056: The function returns information about the scheduling policy for the
1.1 root 6057: processor set as defined by @code{processor_set_sched_info_t}. The
6058: number of integers returned is @code{PROCESSOR_SET_SCHED_INFO_COUNT}.
6059: @end table
6060:
6061: Some machines may define additional (machine-dependent) flavors.
6062:
6063: The function returns @code{KERN_SUCCESS} if the call succeeded and
6064: @code{KERN_INVALID_ARGUMENT} if @var{processor_set} is not a processor
6065: set or @var{flavor} is not recognized. The function returns
6066: @code{MIG_ARRAY_TOO_LARGE} if the returned info array is too large for
6067: @var{processor_set_info}. In this case, @var{processor_set_info} is
6068: filled as much as possible and @var{processor_set_info_count} is set to the
6069: number of elements that would have been returned if there were enough
6070: room.
6071: @end deftypefun
6072:
6073: @deftp {Data type} {struct processor_set_basic_info}
6074: This structure is returned in @var{processor_set_info} by the
6075: @code{processor_set_info} function and provides basic information about
6076: the processor set. You can cast a variable of type
6077: @code{processor_set_info_t} to a pointer of this type if you provided it
6078: as the @var{processor_set_info} parameter for the
6079: @code{PROCESSOR_SET_BASIC_INFO} flavor of @code{processor_set_info}. It
6080: has the following members:
6081:
6082: @table @code
6083: @item int processor_count
6084: number of processors
6085:
6086: @item int task_count
6087: number of tasks
6088:
6089: @item int thread_count
6090: number of threads
6091:
6092: @item int load_average
6093: scaled load average
6094:
6095: @item int mach_factor
6096: scaled mach factor
6097: @end table
6098: @end deftp
6099:
6100: @deftp {Data type} processor_set_basic_info_t
6101: This is a pointer to a @code{struct processor_set_basic_info}.
6102: @end deftp
6103:
6104: @deftp {Data type} {struct processor_set_sched_info}
6105: This structure is returned in @var{processor_set_info} by the
6106: @code{processor_set_info} function and provides schedule information
6107: about the processor set. You can cast a variable of type
6108: @code{processor_set_info_t} to a pointer of this type if you provided it
6109: as the @var{processor_set_info} parameter for the
6110: @code{PROCESSOR_SET_SCHED_INFO} flavor of @code{processor_set_info}. It
6111: has the following members:
6112:
6113: @table @code
6114: @item int policies
6115: allowed policies
6116:
6117: @item int max_priority
6118: max priority for new threads
6119: @end table
6120: @end deftp
6121:
6122: @deftp {Data type} processor_set_sched_info_t
6123: This is a pointer to a @code{struct processor_set_sched_info}.
6124: @end deftp
6125:
6126:
6127: @node Processor Interface
6128: @section Processor Interface
6129:
6130: @cindex processor port
6131: @cindex port representing a processor
6132: @deftp {Data type} processor_t
6133: This is a @code{mach_port_t} and used to hold the port name of a
6134: processor port that represents the processor. Operations on the
6135: processor are implemented as remote procedure calls to the processor
6136: port.
6137: @end deftp
6138:
6139: @menu
6140: * Hosted Processors:: Getting a list of all processors on a host.
6141: * Processor Control:: Starting, stopping, controlling processors.
6142: * Processors and Sets:: Combining processors into processor sets.
6143: * Processor Info:: Obtaining information on processors.
6144: @end menu
6145:
6146:
6147: @node Hosted Processors
6148: @subsection Hosted Processors
6149:
6150: @deftypefun kern_return_t host_processors (@w{host_priv_t @var{host_priv}}, @w{processor_array_t *@var{processor_list}}, @w{mach_msg_type_number_t *@var{processor_count}})
6151: The function @code{host_processors} gets send rights to the processor
6152: port for each processor existing on @var{host_priv}. This is the
6153: privileged port that allows its holder to control a processor.
6154:
6155: @var{processor_list} is an array that is created as a result of this
6156: call. The caller may wish to @code{vm_deallocate} this array when the
6157: data is no longer needed. @var{processor_count} is set to the number of
6158: processors in the @var{processor_list}.
6159:
6160: This function returns @code{KERN_SUCCESS} if the call succeeded,
6161: @code{KERN_INVALID_ARGUMENT} if @var{host_priv} is not a privileged host
6162: port, and @code{KERN_INVALID_ADDRESS} if @var{processor_count} points to
6163: inaccessible memory.
6164: @end deftypefun
6165:
6166:
6167: @node Processor Control
6168: @subsection Processor Control
6169:
6170: @deftypefun kern_return_t processor_start (@w{processor_t @var{processor}})
6171: @deftypefunx kern_return_t processor_exit (@w{processor_t @var{processor}})
6172: @deftypefunx kern_return_t processor_control (@w{processor_t @var{processor}}, @w{processor_info_t *@var{cmd}}, @w{mach_msg_type_number_t @var{count}})
6173: Some multiprocessors may allow privileged software to control
6174: processors. The @code{processor_start}, @code{processor_exit}, and
6175: @code{processor_control} operations implement this. The interpretation
6176: of the command in @var{cmd} is machine dependent. A newly started
6177: processor is assigned to the default processor set. An exited processor
6178: is removed from the processor set to which it was assigned and ceases to
6179: be active.
6180:
6181: @var{count} contains the length of the command @var{cmd} as a number of
6182: ints.
6183:
6184: Availability limited. All of these operations are machine-dependent.
6185: They may do nothing. The ability to restart an exited processor is also
6186: machine-dependent.
6187:
6188: This function returns @code{KERN_SUCCESS} if the operation was
6189: performed, @code{KERN_FAILURE} if the operation was not performed (a
6190: likely reason is that it is not supported on this processor),
6191: @code{KERN_INVALID_ARGUMENT} if @var{processor} is not a processor, and
6192: @code{KERN_INVALID_ADDRESS} if @var{cmd} points to inaccessible memory.
6193: @end deftypefun
6194:
6195: @node Processors and Sets
6196: @subsection Processors and Sets
6197:
6198: @deftypefun kern_return_t processor_assign (@w{processor_t @var{processor}}, @w{processor_set_t @var{processor_set}}, @w{boolean_t @var{wait}})
1.1.1.2 root 6199: The function @code{processor_assign} assigns @var{processor} to the
1.1 root 6200: set @var{processor_set}. After the assignment is completed, the
6201: processor only executes threads that are assigned to that processor set.
6202: Any previous assignment of the processor is nullified. The master
6203: processor cannot be reassigned. All processors take clock interrupts at
6204: all times. The @var{wait} argument indicates whether the caller should
6205: wait for the assignment to be completed or should return immediately.
6206: Dedicated kernel threads are used to perform processor assignment, so
6207: setting wait to @code{FALSE} allows assignment requests to be queued and
6208: performed faster, especially if the kernel has more than one dedicated
6209: internal thread for processor assignment. Redirection of other device
6210: interrupts away from processors assigned to other than the default
6211: processor set is machine-dependent. Intermediaries that interpose on
6212: ports must be sure to interpose on both ports involved in this call if
6213: they interpose on either.
6214:
6215: This function returns @code{KERN_SUCCESS} if the assignment has been
6216: performed, @code{KERN_INVALID_ARGUMENT} if @var{processor} is not a
6217: processor, or @var{processor_set} is not a processor set on the same
6218: host as @var{processor}.
6219: @end deftypefun
6220:
6221: @deftypefun kern_return_t processor_get_assignment (@w{processor_t @var{processor}}, @w{processor_set_name_t *@var{assigned_set}})
6222: The function @code{processor_get_assignment} obtains the current
6223: assignment of a processor. The name port of the processor set is
6224: returned in @var{assigned_set}.
6225: @end deftypefun
6226:
6227: @node Processor Info
6228: @subsection Processor Info
6229:
6230: @deftypefun kern_return_t processor_info (@w{processor_t @var{processor}}, @w{int @var{flavor}}, @w{host_t *@var{host}}, @w{processor_info_t @var{processor_info}}, @w{mach_msg_type_number_t *@var{processor_info_count}})
6231: The function @code{processor_info} returns the selected information array
6232: for a processor, as specified by @var{flavor}.
6233:
6234: @var{host} is set to the host on which the processor set resides. This
6235: is the non-privileged host port.
6236:
6237: @var{processor_info} is an array of integers that is supplied by the
6238: caller and returned filled with specified information.
6239: @var{processor_info_count} is supplied as the maximum number of integers in
6240: @var{processor_info}. On return, it contains the actual number of
6241: integers in @var{processor_info}. The maximum number of integers
6242: returned by any flavor is @code{PROCESSOR_INFO_MAX}.
6243:
6244: The type of information returned is defined by @var{flavor}, which can
6245: be one of the following:
6246:
6247: @table @code
6248: @item PROCESSOR_BASIC_INFO
6249: The function returns basic information about the processor, as defined
6250: by @code{processor_basic_info_t}. This includes the slot number of the
6251: processor. The number of integers returned is
6252: @code{PROCESSOR_BASIC_INFO_COUNT}.
6253: @end table
6254:
6255: Machines which require more configuration information beyond the slot
6256: number are expected to define additional (machine-dependent) flavors.
6257:
6258: The function returns @code{KERN_SUCCESS} if the call succeeded and
6259: @code{KERN_INVALID_ARGUMENT} if @var{processor} is not a processor or
6260: @var{flavor} is not recognized. The function returns
6261: @code{MIG_ARRAY_TOO_LARGE} if the returned info array is too large for
6262: @var{processor_info}. In this case, @var{processor_info} is filled as
6263: much as possible and @var{processor_infoCnt} is set to the number of
6264: elements that would have been returned if there were enough room.
6265: @end deftypefun
6266:
6267: @deftp {Data type} {struct processor_basic_info}
6268: This structure is returned in @var{processor_info} by the
6269: @code{processor_info} function and provides basic information about the
6270: processor. You can cast a variable of type @code{processor_info_t} to a
6271: pointer of this type if you provided it as the @var{processor_info}
6272: parameter for the @code{PROCESSOR_BASIC_INFO} flavor of
6273: @code{processor_info}. It has the following members:
6274:
6275: @table @code
6276: @item cpu_type_t cpu_type
6277: cpu type
6278:
6279: @item cpu_subtype_t cpu_subtype
6280: cpu subtype
6281:
6282: @item boolean_t running
6283: is processor running?
6284:
6285: @item int slot_num
6286: slot number
6287:
6288: @item boolean_t is_master
6289: is this the master processor
6290: @end table
6291: @end deftp
6292:
6293: @deftp {Data type} processor_basic_info_t
6294: This is a pointer to a @code{struct processor_basic_info}.
6295: @end deftp
6296:
6297:
6298: @node Device Interface
6299: @chapter Device Interface
6300:
6301: The GNU Mach microkernel provides a simple device interface that allows
6302: the user space programs to access the underlying hardware devices. Each
6303: device has a unique name, which is a string up to 127 characters long.
6304: To open a device, the device master port has to be supplied. The device
6305: master port is only available through the bootstrap port. Anyone who
6306: has control over the device master port can use all hardware devices.
6307: @c XXX FIXME bootstrap port, bootstrap
6308:
6309: @cindex device port
6310: @cindex port representing a device
6311: @deftp {Data type} device_t
6312: This is a @code{mach_port_t} and used to hold the port name of a
6313: device port that represents the device. Operations on the device are
6314: implemented as remote procedure calls to the device port. Each device
6315: provides a sequence of records. The length of a record is specific to
6316: the device. Data can be transferred ``out-of-line'' or ``in-line''
6317: (@pxref{Memory}).
6318: @end deftp
6319:
6320: All constants and functions in this chapter are defined in
6321: @file{device/device.h}.
6322:
6323: @menu
6324: * Device Reply Server:: Handling device reply messages.
6325: * Device Open:: Opening hardware devices.
6326: * Device Close:: Closing hardware devices.
6327: * Device Read:: Reading data from the device.
6328: * Device Write:: Writing data to the device.
6329: * Device Map:: Mapping devices into virtual memory.
6330: * Device Status:: Querying and manipulating a device.
6331: * Device Filter:: Filtering packets arriving on a device.
6332: @end menu
6333:
6334:
6335: @node Device Reply Server
6336: @section Device Reply Server
6337:
6338: Beside the usual synchronous interface, an asynchronous interface is
6339: provided. For this, the caller has to receive and handle the reply
1.1.1.2 root 6340: messages separately from the function call.
1.1 root 6341:
6342: @deftypefun boolean_t device_reply_server (@w{msg_header_t *@var{in_msg}}, @w{msg_header_t *@var{out_msg}})
6343: The function @code{device_reply_server} is produced by the
6344: remote procedure call generator to handle a received message. This
6345: function does all necessary argument handling, and actually calls one of
6346: the following functions: @code{ds_device_open_reply},
6347: @code{ds_device_read_reply}, @code{ds_device_read_reply_inband},
6348: @code{ds_device_write_reply} and @code{ds_device_write_reply_inband}.
6349:
6350: The @var{in_msg} argument is the message that has been received from the
6351: kernel. The @var{out_msg} is a reply message, but this is not used for
6352: this server.
6353:
6354: The function returns @code{TRUE} to indicate that the message in
6355: question was applicable to this interface, and that the appropriate
6356: routine was called to interpret the message. It returns @code{FALSE} to
6357: indicate that the message did not apply to this interface, and that no
6358: other action was taken.
6359: @end deftypefun
6360:
6361:
6362: @node Device Open
6363: @section Device Open
6364:
6365: @deftypefun kern_return_t device_open (@w{mach_port_t @var{master_port}}, @w{dev_mode_t @var{mode}}, @w{dev_name_t @var{name}}, @w{device_t *@var{device}})
6366: The function @code{device_open} opens the device @var{name} and returns
6367: a port to it in @var{device}. The open count for the device is
6368: incremented by one. If the open count was 0, the open handler for the
6369: device is invoked.
6370:
6371: @var{master_port} must hold the master device port. @var{name}
6372: specifies the device to open, and is a string up to 128 characters long.
6373: @var{mode} is the open mode. It is a bitwise-or of the following
6374: constants:
6375:
6376: @table @code
6377: @item D_READ
6378: Request read access for the device.
6379:
6380: @item D_WRITE
6381: Request write access for the device.
6382:
6383: @item D_NODELAY
6384: Do not delay an open.
6385: @c XXX Is this really used at all? Maybe for tape drives? What does it mean?
6386: @end table
6387:
6388: The function returns @code{D_SUCCESS} if the device was successfully
6389: opened, @code{D_INVALID_OPERATION} if @var{master_port} is not the
6390: master device port, @code{D_WOULD_BLOCK} is the device is busy and
6391: @code{D_NOWAIT} was specified in mode, @code{D_ALREADY_OPEN} if the
6392: device is already open in an incompatible mode and
6393: @code{D_NO_SUCH_DEVICE} if @var{name} does not denote a know device.
6394: @end deftypefun
6395:
6396: @deftypefun kern_return_t device_open_request (@w{mach_port_t @var{master_port}}, @w{mach_port_t @var{reply_port}}, @w{dev_mode_t @var{mode}}, @w{dev_name_t @var{name}})
6397: @deftypefunx kern_return_t ds_device_open_reply (@w{mach_port_t @var{reply_port}}, @w{kern_return_t @var{return}}, @w{device_t *@var{device}})
6398: This is the asynchronous form of the @code{device_open} function.
6399: @code{device_open_request} performs the open request. The meaning for
6400: the parameters is as in @code{device_open}. Additionally, the caller
6401: has to supply a reply port to which the @code{ds_device_open_reply}
6402: message is sent by the kernel when the open has been performed. The
6403: return value of the open operation is stored in @var{return_code}.
6404:
6405: As neither function receives a reply message, only message transmission
6406: errors apply. If no error occurs, @code{KERN_SUCCESS} is returned.
6407: @end deftypefun
6408:
6409:
6410: @node Device Close
6411: @section Device Close
6412:
6413: @deftypefun kern_return_t device_close (@w{device_t @var{device}})
6414: The function @code{device_close} decrements the open count of the device
6415: by one. If the open count drops to zero, the close handler for the
6416: device is called. The device to close is specified by its port
6417: @var{device}.
6418:
6419: The function returns @code{D_SUCCESS} if the device was successfully
6420: closed and @code{D_NO_SUCH_DEVICE} if @var{device} does not denote a
6421: device port.
6422: @end deftypefun
6423:
6424:
6425: @node Device Read
6426: @section Device Read
6427:
6428: @deftypefun kern_return_t device_read (@w{device_t @var{device}}, @w{dev_mode_t @var{mode}}, @w{recnum_t @var{recnum}}, @w{int @var{bytes_wanted}}, @w{io_buf_ptr_t *@var{data}}, @w{mach_msg_type_number_t *@var{data_count}})
6429: The function @code{device_read} reads @var{bytes_wanted} bytes from
6430: @var{device}, and stores them in a buffer allocated with
6431: @code{vm_allocate}, which address is returned in @var{data}. The caller
6432: must deallocated it if it is no longer needed. The number of bytes
6433: actually returned is stored in @var{data_count}.
6434:
6435: If @var{mode} is @code{D_NOWAIT}, the operation does not block.
6436: Otherwise @var{mode} should be 0. @var{recnum} is the record number to
6437: be read, its meaning is device specific.
6438:
6439: The function returns @code{D_SUCCESS} if some data was successfully
6440: read, @code{D_WOULD_BLOCK} if no data is currently available and
6441: @code{D_NOWAIT} is specified, and @code{D_NO_SUCH_DEVICE} if
6442: @var{device} does not denote a device port.
6443: @end deftypefun
6444:
6445: @deftypefun kern_return_t device_read_inband (@w{device_t @var{device}}, @w{dev_mode_t @var{mode}}, @w{recnum_t @var{recnum}}, @w{int @var{bytes_wanted}}, @w{io_buf_ptr_inband_t *@var{data}}, @w{mach_msg_type_number_t *@var{data_count}})
6446: The @code{device_read_inband} function works as the @code{device_read}
6447: function, except that the data is returned ``in-line'' in the reply IPC
6448: message (@pxref{Memory}).
6449: @end deftypefun
6450:
6451: @deftypefun kern_return_t device_read_request (@w{device_t @var{device}}, @w{mach_port_t @var{reply_port}}, @w{dev_mode_t @var{mode}}, @w{recnum_t @var{recnum}}, @w{int @var{bytes_wanted}})
6452: @deftypefunx kern_return_t ds_device_read_reply (@w{mach_port_t @var{reply_port}}, @w{kern_return_t @var{return_code}}, @w{io_buf_ptr_t @var{data}}, @w{mach_msg_type_number_t @var{data_count}})
6453: This is the asynchronous form of the @code{device_read} function.
6454: @code{device_read_request} performs the read request. The meaning for
6455: the parameters is as in @code{device_read}. Additionally, the caller
6456: has to supply a reply port to which the @code{ds_device_read_reply}
6457: message is sent by the kernel when the read has been performed. The
6458: return value of the read operation is stored in @var{return_code}.
6459:
6460: As neither function receives a reply message, only message transmission
6461: errors apply. If no error occurs, @code{KERN_SUCCESS} is returned.
6462: @end deftypefun
6463:
6464: @deftypefun kern_return_t device_read_request_inband (@w{device_t @var{device}}, @w{mach_port_t @var{reply_port}}, @w{dev_mode_t @var{mode}}, @w{recnum_t @var{recnum}}, @w{int @var{bytes_wanted}})
6465: @deftypefunx kern_return_t ds_device_read_reply_inband (@w{mach_port_t @var{reply_port}}, @w{kern_return_t @var{return_code}}, @w{io_buf_ptr_t @var{data}}, @w{mach_msg_type_number_t @var{data_count}})
6466: The @code{device_read_request_inband} and
6467: @code{ds_device_read_reply_inband} functions work as the
6468: @code{device_read_request} and @code{ds_device_read_reply} functions,
6469: except that the data is returned ``in-line'' in the reply IPC message
6470: (@pxref{Memory}).
6471: @end deftypefun
6472:
6473:
6474: @node Device Write
6475: @section Device Write
6476:
6477: @deftypefun kern_return_t device_write (@w{device_t @var{device}}, @w{dev_mode_t @var{mode}}, @w{recnum_t @var{recnum}}, @w{io_buf_ptr_t @var{data}}, @w{mach_msg_type_number_t @var{data_count}}, @w{int *@var{bytes_written}})
6478: The function @code{device_write} writes @var{data_count} bytes from the
6479: buffer @var{data} to @var{device}. The number of bytes actually written
6480: is returned in @var{bytes_written}.
6481:
6482: If @var{mode} is @code{D_NOWAIT}, the function returns without waiting
6483: for I/O completion. Otherwise @var{mode} should be 0. @var{recnum} is
6484: the record number to be written, its meaning is device specific.
6485:
6486: The function returns @code{D_SUCCESS} if some data was successfully
6487: written and @code{D_NO_SUCH_DEVICE} if @var{device} does not denote a
6488: device port or the device is dead or not completely open.
6489: @end deftypefun
6490:
6491: @deftypefun kern_return_t device_write_inband (@w{device_t @var{device}}, @w{dev_mode_t @var{mode}}, @w{recnum_t @var{recnum}}, @w{int @var{bytes_wanted}}, @w{io_buf_ptr_inband_t *@var{data}}, @w{mach_msg_type_number_t *@var{data_count}})
6492: The @code{device_write_inband} function works as the @code{device_write}
6493: function, except that the data is sent ``in-line'' in the request IPC
6494: message (@pxref{Memory}).
6495: @end deftypefun
6496:
6497: @deftypefun kern_return_t device_write_request (@w{device_t @var{device}}, @w{mach_port_t @var{reply_port}}, @w{dev_mode_t @var{mode}}, @w{recnum_t @var{recnum}}, @w{io_buf_ptr_t @var{data}}, @w{mach_msg_type_number_t @var{data_count}})
6498: @deftypefunx kern_return_t ds_device_write_reply (@w{mach_port_t @var{reply_port}}, @w{kern_return_t @var{return_code}}, @w{int @var{bytes_written}})
6499: This is the asynchronous form of the @code{device_write} function.
6500: @code{device_write_request} performs the write request. The meaning for
6501: the parameters is as in @code{device_write}. Additionally, the caller
6502: has to supply a reply port to which the @code{ds_device_write_reply}
6503: message is sent by the kernel when the write has been performed. The
6504: return value of the write operation is stored in @var{return_code}.
6505:
6506: As neither function receives a reply message, only message transmission
6507: errors apply. If no error occurs, @code{KERN_SUCCESS} is returned.
6508: @end deftypefun
6509:
6510: @deftypefun kern_return_t device_write_request_inband (@w{device_t @var{device}}, @w{mach_port_t @var{reply_port}}, @w{dev_mode_t @var{mode}}, @w{recnum_t @var{recnum}}, @w{io_buf_ptr_t @var{data}}, @w{mach_msg_type_number_t @var{data_count}})
6511: @deftypefunx kern_return_t ds_device_write_reply_inband (@w{mach_port_t @var{reply_port}}, @w{kern_return_t @var{return_code}}, @w{int @var{bytes_written}})
6512: The @code{device_write_request_inband} and
6513: @code{ds_device_write_reply_inband} functions work as the
6514: @code{device_write_request} and @code{ds_device_write_reply} functions,
6515: except that the data is sent ``in-line'' in the request IPC message
6516: (@pxref{Memory}).
6517: @end deftypefun
6518:
6519:
6520: @node Device Map
6521: @section Device Map
6522:
6523: @deftypefun kern_return_t device_map (@w{device_t @var{device}}, @w{vm_prot_t @var{prot}}, @w{vm_offset_t @var{offset}}, @w{vm_size_t @var{size}}, @w{mach_port_t *@var{pager}}, @w{int @var{unmap}})
6524: The function @code{device_map} creates a new memory manager for
6525: @var{device} and returns a port to it in @var{pager}. The memory
6526: manager is usable as a memory object in a @code{vm_map} call. The call
1.1.1.2 root 6527: is device dependent.
1.1 root 6528:
6529: The protection for the memory object is specified by @var{prot}. The
6530: memory object starts at @var{offset} within the device and extends
6531: @var{size} bytes. @var{unmap} is currently unused.
6532: @c XXX I suppose the caller should set it to 0.
6533:
6534: The function returns @code{D_SUCCESS} if some data was successfully
6535: written and @code{D_NO_SUCH_DEVICE} if @var{device} does not denote a
6536: device port or the device is dead or not completely open.
6537: @end deftypefun
6538:
6539:
6540: @node Device Status
6541: @section Device Status
6542:
6543: @deftypefun kern_return_t device_set_status (@w{device_t @var{device}}, @w{dev_flavor_t @var{flavor}}, @w{dev_status_t @var{status}}, @w{mach_msg_type_number_t @var{status_count}})
6544: The function @code{device_set_status} sets the status of a device. The
6545: possible values for @var{flavor} and their interpretation is device
6546: specific.
6547:
6548: The function returns @code{D_SUCCESS} if some data was successfully
6549: written and @code{D_NO_SUCH_DEVICE} if @var{device} does not denote a
6550: device port or the device is dead or not completely open.
6551: @end deftypefun
6552:
6553: @deftypefun kern_return_t device_get_status (@w{device_t @var{device}}, @w{dev_flavor_t @var{flavor}}, @w{dev_status_t @var{status}}, @w{mach_msg_type_number_t *@var{status_count}})
6554: The function @code{device_get_status} gets the status of a device. The
6555: possible values for @var{flavor} and their interpretation is device
6556: specific.
6557:
6558: The function returns @code{D_SUCCESS} if some data was successfully
6559: written and @code{D_NO_SUCH_DEVICE} if @var{device} does not denote a
6560: device port or the device is dead or not completely open.
6561: @end deftypefun
6562:
6563:
6564: @node Device Filter
6565: @section Device Filter
6566:
6567: @deftypefun kern_return_t device_set_filter (@w{device_t @var{device}}, @w{mach_port_t @var{receive_port}}, @w{mach_msg_type_name_t @var{receive_port_type}}, @w{int @var{priority}}, @w{filter_array_t @var{filter}}, @w{mach_msg_type_number_t @var{filter_count}})
6568: The function @code{device_set_filter} makes it possible to filter out
1.1.1.2 root 6569: selected data arriving at or leaving the device and forward it to a port.
1.1 root 6570: @var{filter} is a list of filter commands, which are applied to incoming
6571: data to determine if the data should be sent to @var{receive_port}. The
6572: IPC type of the send right is specified by @var{receive_port_right}, it
6573: is either @code{MACH_MSG_TYPE_MAKE_SEND} or
6574: @code{MACH_MSG_TYPE_MOVE_SEND}. The @var{priority} value is used to
6575: order multiple filters.
6576:
6577: There can be up to @code{NET_MAX_FILTER} commands in @var{filter}. The
6578: actual number of commands is passed in @var{filter_count}. For the
6579: purpose of the filter test, an internal stack is provided. After all
6580: commands have been processed, the value on the top of the stack
6581: determines if the data is forwarded or the next filter is tried.
6582:
1.1.1.2 root 6583: The first command is a header which contains two fields: one for flags
6584: and the other for the type of interpreter used to run the rest of the
6585: commands.
6586:
6587: Any combination of the following flags is allowed but at least one of them
6588: must be specified.
6589:
6590: @table @code
6591: @item NETF_IN
6592: The filter will be applied to data received by the device.
6593:
6594: @item NETF_OUT
6595: The filter will be applied to data transmitted by the device.
6596: @end table
6597:
6598: Unless the type is given explicitly the native NETF interpreter will be used.
6599: To select an alternative implementation use one of the following types:
6600:
6601: @table @code
6602: @item NETF_BPF
6603: Use Berkeley Packet Filter.
6604: @end table
6605:
6606: For the listener to know what kind of packet is being received, when the
6607: filter code accepts a packet the message sent to @var{receive_port} is
6608: tagged with either NETF_IN or NETF_OUT.
6609:
1.1 root 6610: @c XXX The following description was taken verbatim from the
6611: @c kernel_interface.pdf document.
6612: Each word of the command list specifies a data (push) operation (high
6613: order NETF_NBPO bits) as well as a binary operator (low order NETF_NBPA
6614: bits). The value to be pushed onto the stack is chosen as follows.
6615:
6616: @table @code
6617: @item NETF_PUSHLIT
6618: Use the next short word of the filter as the value.
6619:
6620: @item NETF_PUSHZERO
6621: Use 0 as the value.
6622:
6623: @item NETF_PUSHWORD+N
6624: Use short word N of the ``data'' portion of the message as the value.
6625:
6626: @item NETF_PUSHHDR+N
6627: Use short word N of the ``header'' portion of the message as the value.
6628:
6629: @item NETF_PUSHIND+N
6630: Pops the top long word from the stack and then uses short word N of the
6631: ``data'' portion of the message as the value.
6632:
6633: @item NETF_PUSHHDRIND+N
6634: Pops the top long word from the stack and then uses short word N of the
6635: ``header'' portion of the message as the value.
6636:
6637: @item NETF_PUSHSTK+N
6638: Use long word N of the stack (where the top of stack is long word 0) as
6639: the value.
6640:
6641: @item NETF_NOPUSH
6642: Don't push a value.
6643: @end table
6644:
6645: The unsigned value so chosen is promoted to a long word before being
6646: pushed. Once a value is pushed (except for the case of
6647: @code{NETF_NOPUSH}), the top two long words of the stack are popped and
6648: a binary operator applied to them (with the old top of stack as the
6649: second operand). The result of the operator is pushed on the stack.
6650: These operators are:
6651:
6652: @table @code
6653: @item NETF_NOP
6654: Don't pop off any values and do no operation.
6655:
6656: @item NETF_EQ
6657: Perform an equal comparison.
6658:
6659: @item NETF_LT
6660: Perform a less than comparison.
6661:
6662: @item NETF_LE
6663: Perform a less than or equal comparison.
6664:
6665: @item NETF_GT
6666: Perform a greater than comparison.
6667:
6668: @item NETF_GE
6669: Perform a greater than or equal comparison.
6670:
6671: @item NETF_AND
6672: Perform a bitise boolean AND operation.
6673:
6674: @item NETF_OR
6675: Perform a bitise boolean inclusive OR operation.
6676:
6677: @item NETF_XOR
6678: Perform a bitise boolean exclusive OR operation.
6679:
6680: @item NETF_NEQ
6681: Perform a not equal comparison.
6682:
6683: @item NETF_LSH
6684: Perform a left shift operation.
6685:
6686: @item NETF_RSH
6687: Perform a right shift operation.
6688:
6689: @item NETF_ADD
6690: Perform an addition.
6691:
6692: @item NETF_SUB
6693: Perform a subtraction.
6694:
6695: @item NETF_COR
6696: Perform an equal comparison. If the comparison is @code{TRUE}, terminate
6697: the filter list. Otherwise, pop the result of the comparison off the
6698: stack.
6699:
6700: @item NETF_CAND
6701: Perform an equal comparison. If the comparison is @code{FALSE},
6702: terminate the filter list. Otherwise, pop the result of the comparison
6703: off the stack.
6704:
6705: @item NETF_CNOR
6706: Perform a not equal comparison. If the comparison is @code{FALSE},
6707: terminate the filter list. Otherwise, pop the result of the comparison
6708: off the stack.
6709:
6710: @item NETF_CNAND
6711: Perform a not equal comparison. If the comparison is @code{TRUE},
6712: terminate the filter list. Otherwise, pop the result of the comparison
6713: off the stack. The scan of the filter list terminates when the filter
6714: list is emptied, or a @code{NETF_C...} operation terminates the list. At
6715: this time, if the final value of the top of the stack is @code{TRUE},
6716: then the message is accepted for the filter.
6717: @end table
6718:
6719: The function returns @code{D_SUCCESS} if some data was successfully
6720: written, @code{D_INVALID_OPERATION} if @var{receive_port} is not a valid
6721: send right, and @code{D_NO_SUCH_DEVICE} if @var{device} does not denote
6722: a device port or the device is dead or not completely open.
6723: @end deftypefun
6724:
6725:
6726: @node Kernel Debugger
6727: @chapter Kernel Debugger
6728:
6729: The GNU Mach kernel debugger @code{ddb} is a powerful built-in debugger
6730: with a gdb like syntax. It is enabled at compile time using the
6731: @option{--enable-kdb} option. Whenever you want to enter the debugger
6732: while running the kernel, you can press the key combination
6733: @key{Ctrl-Alt-D}.
6734:
6735: @menu
6736: * Operation:: Basic architecture of the kernel debugger.
6737: * Commands:: Available commands in the kernel debugger.
6738: * Variables:: Access of variables from the kernel debugger.
6739: * Expressions:: Usage of expressions in the kernel debugger.
6740: @end menu
6741:
6742:
6743: @node Operation
6744: @section Operation
6745:
6746: The current location is called @dfn{dot}. The dot is displayed with a
6747: hexadecimal format at a prompt. Examine and write commands update dot
6748: to the address of the last line examined or the last location modified,
6749: and set @dfn{next} to the address of the next location to be examined or
6750: changed. Other commands don't change dot, and set next to be the same
6751: as dot.
6752:
6753: The general command syntax is:
6754:
6755: @example
6756: @var{command}[/@var{modifier}] @var{address} [,@var{count}]
6757: @end example
6758:
6759: @kbd{!!} repeats the previous command, and a blank line repeats from the
6760: address next with count 1 and no modifiers. Specifying @var{address} sets
6761: dot to the address. Omitting @var{address} uses dot. A missing @var{count}
6762: is taken to be 1 for printing commands or infinity for stack traces.
6763:
6764: Current @code{ddb} is enhanced to support multi-thread debugging. A
6765: break point can be set only for a specific thread, and the address space
6766: or registers of non current thread can be examined or modified if
6767: supported by machine dependent routines. For example,
6768:
6769: @example
6770: break/t mach_msg_trap $task11.0
6771: @end example
6772:
6773: sets a break point at @code{mach_msg_trap} for the first thread of task
6774: 11 listed by a @code{show all threads} command.
6775:
6776: In the above example, @code{$task11.0} is translated to the
6777: corresponding thread structure's address by variable translation
6778: mechanism described later. If a default target thread is set in a
6779: variable @code{$thread}, the @code{$task11.0} can be omitted. In
6780: general, if @code{t} is specified in a modifier of a command line, a
6781: specified thread or a default target thread is used as a target thread
6782: instead of the current one. The @code{t} modifier in a command line is
6783: not valid in evaluating expressions in a command line. If you want to
6784: get a value indirectly from a specific thread's address space or access
6785: to its registers within an expression, you have to specify a default
6786: target thread in advance, and to use @code{:t} modifier immediately
6787: after the indirect access or the register reference like as follows:
6788:
6789: @example
6790: set $thread $task11.0
6791: print $eax:t *(0x100):tuh
6792: @end example
6793:
6794: No sign extension and indirection @code{size(long, half word, byte)} can
6795: be specified with @code{u}, @code{l}, @code{h} and @code{b} respectively
6796: for the indirect access.
6797:
6798: Note: Support of non current space/register access and user space break
6799: point depend on the machines. If not supported, attempts of such
6800: operation may provide incorrect information or may cause strange
6801: behavior. Even if supported, the user space access is limited to the
6802: pages resident in the main memory at that time. If a target page is not
6803: in the main memory, an error will be reported.
6804:
6805: @code{ddb} has a feature like a command @code{more} for the output. If
6806: an output line exceeds the number set in the @code{$lines} variable, it
6807: displays @samp{--db_more--} and waits for a response. The valid
6808: responses for it are:
6809:
6810: @table @kbd
6811: @item @key{SPC}
6812: one more page
6813:
6814: @item @key{RET}
6815: one more line
6816:
6817: @item q
6818: abort the current command, and return to the command input mode
6819: @end table
6820:
6821:
6822: @node Commands
6823: @section Commands
6824:
6825: @table @code
6826: @item examine(x) [/@var{modifier}] @var{addr}[,@var{count}] [ @var{thread} ]
6827: Display the addressed locations according to the formats in the
6828: modifier. Multiple modifier formats display multiple locations. If no
6829: format is specified, the last formats specified for this command is
6830: used. Address space other than that of the current thread can be
6831: specified with @code{t} option in the modifier and @var{thread}
6832: parameter. The format characters are
6833:
6834: @table @code
6835: @item b
6836: look at by bytes(8 bits)
6837:
6838: @item h
6839: look at by half words(16 bits)
6840:
6841: @item l
6842: look at by long words(32 bits)
6843:
6844: @item a
6845: print the location being displayed
6846:
6847: @item ,
6848: skip one unit producing no output
6849:
6850: @item A
6851: print the location with a line number if possible
6852:
6853: @item x
6854: display in unsigned hex
6855:
6856: @item z
6857: display in signed hex
6858:
6859: @item o
6860: display in unsigned octal
6861:
6862: @item d
6863: display in signed decimal
6864:
6865: @item u
6866: display in unsigned decimal
6867:
6868: @item r
6869: display in current radix, signed
6870:
6871: @item c
6872: display low 8 bits as a character. Non-printing characters are
6873: displayed as an octal escape code (e.g. '\000').
6874:
6875: @item s
6876: display the null-terminated string at the location. Non-printing
6877: characters are displayed as octal escapes.
6878:
6879: @item m
6880: display in unsigned hex with character dump at the end of each line.
6881: The location is also displayed in hex at the beginning of each line.
6882:
6883: @item i
6884: display as an instruction
6885:
6886: @item I
6887: display as an instruction with possible alternate formats depending on
6888: the machine:
6889:
6890: @table @code
6891: @item vax
6892: don't assume that each external label is a procedure entry mask
6893:
6894: @item i386
6895: don't round to the next long word boundary
6896:
6897: @item mips
6898: print register contents
6899: @end table
6900: @end table
6901:
6902: @item xf
6903: Examine forward. It executes an examine command with the last specified
6904: parameters to it except that the next address displayed by it is used as
6905: the start address.
6906:
6907: @item xb
6908: Examine backward. It executes an examine command with the last
6909: specified parameters to it except that the last start address subtracted
6910: by the size displayed by it is used as the start address.
6911:
6912: @item print[/axzodurc] @var{addr1} [ @var{addr2} @dots{} ]
6913: Print @var{addr}'s according to the modifier character. Valid formats
6914: are: @code{a} @code{x} @code{z} @code{o} @code{d} @code{u} @code{r}
6915: @code{c}. If no modifier is specified, the last one specified to it is
6916: used. @var{addr} can be a string, and it is printed as it is. For
6917: example,
6918:
6919: @example
6920: print/x "eax = " $eax "\necx = " $ecx "\n"
6921: @end example
6922:
6923: will print like
6924:
6925: @example
6926: eax = xxxxxx
6927: ecx = yyyyyy
6928: @end example
6929:
6930: @item write[/bhlt] @var{addr} [ @var{thread} ] @var{expr1} [ @var{expr2} @dots{} ]
6931: Write the expressions at succeeding locations. The write unit size can
6932: be specified in the modifier with a letter b (byte), h (half word) or
6933: l(long word) respectively. If omitted, long word is assumed. Target
6934: address space can also be specified with @code{t} option in the modifier
6935: and @var{thread} parameter. Warning: since there is no delimiter
6936: between expressions, strange things may happen. It's best to enclose
6937: each expression in parentheses.
6938:
6939: @item set $@var{variable} [=] @var{expr}
6940: Set the named variable or register with the value of @var{expr}. Valid
6941: variable names are described below.
6942:
6943: @item break[/tuTU] @var{addr}[,@var{count}] [ @var{thread1} @dots{} ]
6944: Set a break point at @var{addr}. If count is supplied, continues
6945: (@var{count}-1) times before stopping at the break point. If the break
6946: point is set, a break point number is printed with @samp{#}. This
6947: number can be used in deleting the break point or adding conditions to
6948: it.
6949:
6950: @table @code
6951: @item t
6952: Set a break point only for a specific thread. The thread is specified
6953: by @var{thread} parameter, or default one is used if the parameter is
6954: omitted.
6955:
6956: @item u
6957: Set a break point in user space address. It may be combined with
6958: @code{t} or @code{T} option to specify the non-current target user
6959: space. Without @code{u} option, the address is considered in the kernel
6960: space, and wrong space address is rejected with an error message. This
6961: option can be used only if it is supported by machine dependent
6962: routines.
6963:
6964: @item T
6965: Set a break point only for threads in a specific task. It is like
6966: @code{t} option except that the break point is valid for all threads
6967: which belong to the same task as the specified target thread.
6968:
6969: @item U
6970: Set a break point in shared user space address. It is like @code{u}
6971: option, except that the break point is valid for all threads which share
6972: the same address space even if @code{t} option is specified. @code{t}
6973: option is used only to specify the target shared space. Without
6974: @code{t} option, @code{u} and @code{U} have the same meanings. @code{U}
6975: is useful for setting a user space break point in non-current address
6976: space with @code{t} option such as in an emulation library space. This
6977: option can be used only if it is supported by machine dependent
6978: routines.
6979: @end table
6980:
6981: Warning: if a user text is shadowed by a normal user space debugger,
6982: user space break points may not work correctly. Setting a break point
6983: at the low-level code paths may also cause strange behavior.
6984:
6985: @item delete[/tuTU] @var{addr}|#@var{number} [ @var{thread1} @dots{} ]
6986: Delete the break point. The target break point can be specified by a
6987: break point number with @code{#}, or by @var{addr} like specified in
6988: @code{break} command.
6989:
6990: @item cond #@var{number} [ @var{condition} @var{commands} ]
6991: Set or delete a condition for the break point specified by the
6992: @var{number}. If the @var{condition} and @var{commands} are null, the
6993: condition is deleted. Otherwise the condition is set for it. When the
6994: break point is hit, the @var{condition} is evaluated. The
6995: @var{commands} will be executed if the condition is true and the break
6996: point count set by a break point command becomes zero. @var{commands}
6997: is a list of commands separated by semicolons. Each command in the list
6998: is executed in that order, but if a @code{continue} command is executed,
6999: the command execution stops there, and the stopped thread resumes
7000: execution. If the command execution reaches the end of the list, and it
7001: enters into a command input mode. For example,
7002:
7003: @example
7004: set $work0 0
7005: break/Tu xxx_start $task7.0
7006: cond #1 (1) set $work0 1; set $work1 0; cont
7007: break/T vm_fault $task7.0
7008: cond #2 ($work0) set $work1 ($work1+1); cont
7009: break/Tu xxx_end $task7.0
7010: cond #3 ($work0) print $work1 " faults\n"; set $work0 0
7011: cont
7012: @end example
7013:
7014: will print page fault counts from @code{xxx_start} to @code{xxx_end} in
7015: @code{task7}.
7016:
7017: @item step[/p] [,@var{count}]
7018: Single step @var{count} times. If @code{p} option is specified, print
7019: each instruction at each step. Otherwise, only print the last
7020: instruction.
7021:
7022: Warning: depending on machine type, it may not be possible to
7023: single-step through some low-level code paths or user space code. On
7024: machines with software-emulated single-stepping (e.g., pmax), stepping
7025: through code executed by interrupt handlers will probably do the wrong
7026: thing.
7027:
7028: @item continue[/c]
7029: Continue execution until a breakpoint or watchpoint. If @code{/c},
7030: count instructions while executing. Some machines (e.g., pmax) also
7031: count loads and stores.
7032:
7033: Warning: when counting, the debugger is really silently single-stepping.
7034: This means that single-stepping on low-level code may cause strange
7035: behavior.
7036:
7037: @item until
7038: Stop at the next call or return instruction.
7039:
7040: @item next[/p]
7041: Stop at the matching return instruction. If @code{p} option is
7042: specified, print the call nesting depth and the cumulative instruction
7043: count at each call or return. Otherwise, only print when the matching
7044: return is hit.
7045:
7046: @item match[/p]
7047: A synonym for @code{next}.
7048:
7049: @item trace[/tu] [ @var{frame_addr}|@var{thread} ][,@var{count}]
7050: Stack trace. @code{u} option traces user space; if omitted, only traces
7051: kernel space. If @code{t} option is specified, it shows the stack trace
7052: of the specified thread or a default target thread. Otherwise, it shows
7053: the stack trace of the current thread from the frame address specified
7054: by a parameter or from the current frame. @var{count} is the number of
7055: frames to be traced. If the @var{count} is omitted, all frames are
7056: printed.
7057:
7058: Warning: If the target thread's stack is not in the main memory at that
7059: time, the stack trace will fail. User space stack trace is valid only
7060: if the machine dependent code supports it.
7061:
7062: @item search[/bhl] @var{addr} @var{value} [@var{mask}] [,@var{count}]
7063: Search memory for a value. This command might fail in interesting ways
7064: if it doesn't find the searched-for value. This is because @code{ddb}
7065: doesn't always recover from touching bad memory. The optional count
7066: argument limits the search.
7067:
7068: @item macro @var{name} @var{commands}
7069: Define a debugger macro as @var{name}. @var{commands} is a list of
7070: commands to be associated with the macro. In the expressions of the
7071: command list, a variable @code{$argxx} can be used to get a parameter
7072: passed to the macro. When a macro is called, each argument is evaluated
7073: as an expression, and the value is assigned to each parameter,
7074: @code{$arg1}, @code{$arg2}, @dots{} respectively. 10 @code{$arg}
7075: variables are reserved to each level of macros, and they can be used as
7076: local variables. The nesting of macro can be allowed up to 5 levels.
7077: For example,
7078:
7079: @example
7080: macro xinit set $work0 $arg1
7081: macro xlist examine/m $work0,4; set $work0 *($work0)
7082: xinit *(xxx_list)
7083: xlist
7084: @enddots{}
7085: @end example
7086:
7087: will print the contents of a list starting from @code{xxx_list} by each
7088: @code{xlist} command.
7089:
7090: @item dmacro @var{name}
7091: Delete the macro named @var{name}.
7092:
7093: @item show all threads[/ul]
7094: Display all tasks and threads information. This version of @code{ddb}
7095: prints more information than previous one. It shows UNIX process
7096: information like @command{ps} for each task. The UNIX process
7097: information may not be shown if it is not supported in the machine, or
7098: the bottom of the stack of the target task is not in the main memory at
7099: that time. It also shows task and thread identification numbers. These
7100: numbers can be used to specify a task or a thread symbolically in
7101: various commands. The numbers are valid only in the same debugger
7102: session. If the execution is resumed again, the numbers may change.
7103: The current thread can be distinguished from others by a @code{#} after
7104: the thread id instead of @code{:}. Without @code{l} option, it only
7105: shows thread id, thread structure address and the status for each
1.1.1.3 root 7106: thread. The status consists of 6 letters, R(run), W(wait), S(suspended),
7107: O(swapped out), N(interruptible), and F(loating) point arithmetic used (if
7108: supported by the platform). If the corresponding
1.1 root 7109: status bit is off, @code{.} is printed instead. If @code{l} option is
7110: specified, more detail information is printed for each thread.
7111:
7112: @item show task [ @var{addr} ]
7113: Display the information of a task specified by @var{addr}. If
7114: @var{addr} is omitted, current task information is displayed.
7115:
7116: @item show thread [ @var{addr} ]
7117: Display the information of a thread specified by @var{addr}. If
7118: @var{addr} is omitted, current thread information is displayed.
7119:
7120: @item show registers[/tu [ @var{thread} ]]
7121: Display the register set. Target thread can be specified with @code{t}
7122: option and @var{thread} parameter. If @code{u} option is specified, it
7123: displays user registers instead of kernel or currently saved one.
7124:
7125: Warning: The support of @code{t} and @code{u} option depends on the
7126: machine. If not supported, incorrect information will be displayed.
7127:
7128: @item show map @var{addr}
7129: Prints the @code{vm_map} at @var{addr}.
7130:
7131: @item show object @var{addr}
7132: Prints the @code{vm_object} at @var{addr}.
7133:
7134: @item show page @var{addr}
7135: Prints the @code{vm_page} structure at @var{addr}.
7136:
7137: @item show port @var{addr}
7138: Prints the @code{ipc_port} structure at @var{addr}.
7139:
7140: @item show ipc_port[/t [ @var{thread} ]]
7141: Prints all @code{ipc_port} structure's addresses the target thread has.
7142: The target thread is a current thread or that specified by a parameter.
7143:
7144: @item show macro [ @var{name} ]
7145: Show the definitions of macros. If @var{name} is specified, only the
7146: definition of it is displayed. Otherwise, definitions of all macros are
7147: displayed.
7148:
7149: @item show watches
7150: Displays all watchpoints.
7151:
7152: @item watch[/T] @var{addr},@var{size} [ @var{task} ]
7153: Set a watchpoint for a region. Execution stops when an attempt to
7154: modify the region occurs. The @var{size} argument defaults to 4.
7155: Without @code{T} option, @var{addr} is assumed to be a kernel address.
7156: If you want to set a watch point in user space, specify @code{T} and
7157: @var{task} parameter where the address belongs to. If the @var{task}
7158: parameter is omitted, a task of the default target thread or a current
7159: task is assumed. If you specify a wrong space address, the request is
7160: rejected with an error message.
7161:
7162: Warning: Attempts to watch wired kernel memory may cause unrecoverable
7163: error in some systems such as i386. Watchpoints on user addresses work
7164: best.
1.1.1.2 root 7165:
7166: @item dwatch[/T] @var{addr} [ @var{task} ]
7167: Clears a watchpoint previously set for a region.
7168: Without @code{T} option, @var{addr} is assumed to be a kernel address.
7169: If you want to clear a watch point in user space, specify @code{T} and
7170: @var{task} parameter where the address belongs to. If the @var{task}
7171: parameter is omitted, a task of the default target thread or a current
7172: task is assumed. If you specify a wrong space address, the request is
7173: rejected with an error message.
1.1 root 7174: @end table
7175:
7176:
7177: @node Variables
7178: @section Variables
7179:
7180: The debugger accesses registers and variables as $@var{name}. Register
7181: names are as in the @code{show registers} command. Some variables are
7182: suffixed with numbers, and may have some modifier following a colon
7183: immediately after the variable name. For example, register variables
7184: can have @code{u} and @code{t} modifier to indicate user register and
7185: that of a default target thread instead of that of the current thread
7186: (e.g. @code{$eax:tu}).
7187:
7188: Built-in variables currently supported are:
7189:
7190: @table @code
7191: @item task@var{xx}[.@var{yy}]
7192: Task or thread structure address. @var{xx} and @var{yy} are task and
7193: thread identification numbers printed by a @code{show all threads}
7194: command respectively. This variable is read only.
7195:
7196: @item thread
7197: The default target thread. The value is used when @code{t} option is
7198: specified without explicit thread structure address parameter in command
7199: lines or expression evaluation.
7200:
7201: @item radix
7202: Input and output radix
7203:
7204: @item maxoff
7205: Addresses are printed as @var{symbol}+@var{offset} unless offset is greater than
7206: maxoff.
7207:
7208: @item maxwidth
7209: The width of the displayed line.
7210:
7211: @item lines
7212: The number of lines. It is used by @code{more} feature.
7213:
7214: @item tabstops
7215: Tab stop width.
7216:
7217: @item arg@var{xx}
7218: Parameters passed to a macro. @var{xx} can be 1 to 10.
7219:
7220: @item work@var{xx}
7221: Work variable. @var{xx} can be 0 to 31.
7222: @end table
7223:
7224:
7225: @node Expressions
7226: @section Expressions
7227:
7228: Almost all expression operators in C are supported except @code{~},
7229: @code{^}, and unary @code{&}. Special rules in @code{ddb} are:
7230:
7231: @table @code
7232: @item @var{identifier}
7233: name of a symbol. It is translated to the address(or value) of it.
7234: @code{.} and @code{:} can be used in the identifier. If supported by
7235: an object format dependent routine,
7236: [@var{file_name}:]@var{func}[:@var{line_number}]
7237: [@var{file_name}:]@var{variable}, and
7238: @var{file_name}[:@var{line_number}] can be accepted as a symbol. The
7239: symbol may be prefixed with @code{@var{symbol_table_name}::} like
7240: @code{emulator::mach_msg_trap} to specify other than kernel symbols.
7241:
7242: @item @var{number}
7243: radix is determined by the first two letters:
7244: @table @code
7245: @item 0x
7246: hex
7247: @item 0o
7248: octal
7249: @item 0t
7250: decimal
7251: @end table
7252:
7253: otherwise, follow current radix.
7254:
7255: @item .
7256: dot
7257:
7258: @item +
7259: next
7260:
7261: @item ..
7262: address of the start of the last line examined. Unlike dot or next,
7263: this is only changed by @code{examine} or @code{write} command.
7264:
7265: @item �
7266: last address explicitly specified.
7267:
7268: @item $@var{variable}
7269: register name or variable. It is translated to the value of it. It may
7270: be followed by a @code{:} and modifiers as described above.
7271:
7272: @item a
7273: multiple of right hand side.
7274:
7275: @item *@var{expr}
7276: indirection. It may be followed by a @code{:} and modifiers as
7277: described above.
7278: @end table
7279:
7280: @include gpl.texi
7281:
7282: @node Documentation License
7283: @appendix Documentation License
7284:
7285: This manual is copyrighted and licensed under the GNU Free Documentation
7286: license.
7287:
7288: Parts of this manual are derived from the Mach manual packages
7289: originally provided by Carnegie Mellon University.
7290:
7291: @menu
1.1.1.2 root 7292: * GNU Free Documentation License:: The GNU Free Documentation License.
1.1 root 7293: * CMU License:: The CMU license applies to the original Mach
7294: kernel and its documentation.
7295: @end menu
7296:
7297: @include fdl.texi
7298:
7299: @node CMU License
7300: @appendixsec CMU License
7301:
7302: @quotation
7303: @display
7304: Mach Operating System
7305: Copyright @copyright{} 1991,1990,1989 Carnegie Mellon University
7306: All Rights Reserved.
7307: @end display
7308:
7309: Permission to use, copy, modify and distribute this software and its
7310: documentation is hereby granted, provided that both the copyright
7311: notice and this permission notice appear in all copies of the
7312: software, derivative works or modified versions, and any portions
7313: thereof, and that both notices appear in supporting documentation.
7314:
7315: @sc{carnegie mellon allows free use of this software in its ``as is''
7316: condition. carnegie mellon disclaims any liability of any kind for
7317: any damages whatsoever resulting from the use of this software.}
7318:
7319: Carnegie Mellon requests users of this software to return to
7320:
7321: @display
7322: Software Distribution Coordinator
7323: School of Computer Science
7324: Carnegie Mellon University
7325: Pittsburgh PA 15213-3890
7326: @end display
7327:
7328: @noindent
7329: or @email{Software.Distribution@@CS.CMU.EDU} any improvements or
7330: extensions that they make and grant Carnegie Mellon the rights to
7331: redistribute these changes.
7332: @end quotation
7333:
7334: @node Concept Index
7335: @unnumbered Concept Index
7336:
7337: @printindex cp
7338:
7339:
7340: @node Function and Data Index
7341: @unnumbered Function and Data Index
7342:
7343: @printindex fn
7344:
7345:
7346: @summarycontents
7347: @contents
7348: @bye
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.