|
|
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:
3529: When the memory manager is prepared to accept requests for data for this
3530: object, it must call @code{memory_object_ready} with the attribute.
3531: Otherwise the kernel will not process requests on this object. To
3532: reject all mappings of this object, the memory manager may use
3533: @code{memory_object_destroy}.
3534:
3535: The argument @var{memory_object} is the port that represents the memory
3536: object data, as supplied to the kernel in a @code{vm_map} call.
3537: @var{memory_control} is the request port to which a response is
3538: requested. (In the event that a memory object has been supplied to more
3539: than one the kernel that has made the request.)
3540: @var{memory_object_name} is a port used by the kernel to refer to the
1.1.1.2 root 3541: memory object data in response to @code{vm_region} calls.
1.1 root 3542: @code{memory_object_page_size} is the page size to be used by this
3543: kernel. All data sizes in calls involving this kernel must be an
3544: integral multiple of the page size. Note that different kernels,
3545: indicated by a different @code{memory_control}, may have different page
3546: sizes.
3547:
3548: The function should return @code{KERN_SUCCESS}, but since this routine
3549: is called by the kernel, which does not wait for a reply message, this
3550: value is ignored.
3551: @end deftypefun
3552:
3553: @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}})
3554: The function @code{memory_object_ready} informs the kernel that the
3555: memory manager is ready to receive data or unlock requests on behalf of
3556: the clients. The argument @var{memory_control} is the port, provided by
3557: the kernel in a @code{memory_object_init} call, to which cache
3558: management requests may be issued. If @var{may_cache_object} is set,
3559: the kernel may keep data associated with this memory object, even after
3560: virtual memory references to it are gone.
3561:
3562: @var{copy_strategy} tells how the kernel should copy regions of the
3563: associated memory object. There are three possible caching strategies:
3564: @code{MEMORY_OBJECT_COPY_NONE} which specifies that nothing special
3565: should be done when data in the object is copied;
3566: @code{MEMORY_OBJECT_COPY_CALL} which specifies that the memory manager
3567: should be notified via a @code{memory_object_copy} call before any part
3568: of the object is copied; and @code{MEMORY_OBJECT_COPY_DELAY} which
3569: guarantees that the memory manager does not externally modify the data
3570: so that the kernel can use its normal copy-on-write algorithms.
3571: @code{MEMORY_OBJECT_COPY_DELAY} is the strategy most commonly used.
3572:
3573: This routine does not receive a reply message (and consequently has no
3574: return value), so only message transmission errors apply.
3575: @end deftypefun
3576:
3577:
3578: @node Memory Object Termination
3579: @section Memory Object Termination
3580:
3581: @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}})
3582: @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}})
3583: The function @code{memory_object_terminate} indicates that the kernel
3584: has completed its use of the given memory object. All rights to the
3585: memory object control and name ports are included, so that the memory
3586: manager can destroy them (using @code{mach_port_deallocate}) after doing
3587: appropriate bookkeeping. The kernel will terminate a memory object only
3588: after all address space mappings of that memory object have been
3589: deallocated, or upon explicit request by the memory manager.
3590:
3591: The argument @var{memory_object} is the port that represents the memory
3592: object data, as supplied to the kernel in a @code{vm_map} call.
3593: @var{memory_control} is the request port to which a response is
3594: requested. (In the event that a memory object has been supplied to more
3595: than one the kernel that has made the request.)
3596: @var{memory_object_name} is a port used by the kernel to refer to the
1.1.1.2 root 3597: memory object data in response to @code{vm_region} calls.
1.1 root 3598:
3599: The function should return @code{KERN_SUCCESS}, but since this routine
3600: is called by the kernel, which does not wait for a reply message, this
3601: value is ignored.
3602: @end deftypefun
3603:
3604: @deftypefun kern_return_t memory_object_destroy (@w{memory_object_control_t @var{memory_control}}, @w{kern_return_t @var{reason}})
3605: The function @code{memory_object_destroy} tells the kernel to shut down
3606: the memory object. As a result of this call the kernel will no longer
3607: support paging activity or any @code{memory_object} calls on this
3608: object, and all rights to the memory object port, the memory control
3609: port and the memory name port will be returned to the memory manager in
3610: a memory_object_terminate call. If the memory manager is concerned that
3611: any modified cached data be returned to it before the object is
3612: terminated, it should call @code{memory_object_lock_request} with
3613: @var{should_flush} set and a lock value of @code{VM_PROT_WRITE} before
3614: making this call.
3615:
3616: The argument @var{memory_control} is the port, provided by the kernel in
3617: a @code{memory_object_init} call, to which cache management requests may
3618: be issued. @var{reason} is an error code indicating why the object
3619: must be destroyed.
1.1.1.2 root 3620: @c The error code is currently ignored.
1.1 root 3621:
3622: This routine does not receive a reply message (and consequently has no
3623: return value), so only message transmission errors apply.
3624: @end deftypefun
3625:
3626:
3627: @node Memory Objects and Data
3628: @section Memory Objects and Data
3629:
3630: @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}})
3631: @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}})
3632: The function @code{memory_object_data_return} provides the memory
3633: manager with data that has been modified while cached in physical
3634: memory. Once the memory manager no longer needs this data (e.g., it has
3635: been written to another storage medium), it should be deallocated using
3636: @code{vm_deallocate}.
3637:
3638: The argument @var{memory_object} is the port that represents the memory
3639: object data, as supplied to the kernel in a @code{vm_map} call.
3640: @var{memory_control} is the request port to which a response is
3641: requested. (In the event that a memory object has been supplied to more
3642: than one the kernel that has made the request.) @var{offset} is the
3643: offset within a memory object to which this call refers. This will be
3644: page aligned. @var{data} is the data which has been modified while
3645: cached in physical memory. @var{data_count} is the amount of data to be
3646: written, in bytes. This will be an integral number of memory object
3647: pages.
3648:
3649: The kernel will also use this call to return precious pages. If an
3650: unmodified precious age is returned, @var{dirty} is set to @code{FALSE},
3651: otherwise it is @code{TRUE}. If @var{kernel_copy} is @code{TRUE}, the
3652: kernel kept a copy of the page. Precious data remains precious if the
3653: kernel keeps a copy. The indication that the kernel kept a copy is only
3654: a hint if the data is not precious; the cleaned copy may be discarded
3655: without further notifying the manager.
3656:
3657: The function should return @code{KERN_SUCCESS}, but since this routine
3658: is called by the kernel, which does not wait for a reply message, this
3659: value is ignored.
3660: @end deftypefun
3661:
3662: @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}})
3663: @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}})
3664: The function @code{memory_object_data_request} is a request for data
3665: from the specified memory object, for at least the access specified.
3666: The memory manager is expected to return at least the specified data,
3667: with as much access as it can allow, using
3668: @code{memory_object_data_supply}. If the memory manager is unable to
3669: provide the data (for example, because of a hardware error), it may use
3670: the @code{memory_object_data_error} call. The
3671: @code{memory_object_data_unavailable} call may be used to tell the
3672: kernel to supply zero-filled memory for this region.
3673:
3674: The argument @var{memory_object} is the port that represents the memory
3675: object data, as supplied to the kernel in a @code{vm_map} call.
3676: @var{memory_control} is the request port to which a response is
3677: requested. (In the event that a memory object has been supplied to more
3678: than one the kernel that has made the request.) @var{offset} is the
3679: offset within a memory object to which this call refers. This will be
3680: page aligned. @var{length} is the number of bytes of data, starting at
3681: @var{offset}, to which this call refers. This will be an integral
3682: number of memory object pages. @var{desired_access} is a protection
3683: value describing the memory access modes which must be permitted on the
3684: specified cached data. One or more of: @code{VM_PROT_READ},
3685: @code{VM_PROT_WRITE} or @code{VM_PROT_EXECUTE}.
3686:
3687: The function should return @code{KERN_SUCCESS}, but since this routine
3688: is called by the kernel, which does not wait for a reply message, this
3689: value is ignored.
3690: @end deftypefun
3691:
3692: @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}})
3693: The function @code{memory_object_data_supply} supplies the kernel with
3694: data for the specified memory object. Ordinarily, memory managers
1.1.1.2 root 3695: should only provide data in response to @code{memory_object_data_request}
1.1 root 3696: calls from the kernel (but they may provide data in advance as desired).
3697: When data already held by this kernel is provided again, the new data is
3698: ignored. The kernel may not provide any data (or protection)
3699: consistency among pages with different virtual page alignments within
3700: the same object.
3701:
3702: The argument @var{memory_control} is the port, provided by the kernel in
3703: a @code{memory_object_init} call, to which cache management requests may
3704: be issued. @var{offset} is an offset within a memory object in bytes.
3705: This must be page aligned. @var{data} is the data that is being
3706: provided to the kernel. This is a pointer to the data.
3707: @var{data_count} is the amount of data to be provided. Only whole
3708: virtual pages of data can be accepted; partial pages will be discarded.
3709:
3710: @var{lock_value} is a protection value indicating those forms of access
3711: that should @strong{not} be permitted to the specified cached data. The
3712: lock values must be one or more of the set: @code{VM_PROT_NONE},
3713: @code{VM_PROT_READ}, @code{VM_PROT_WRITE}, @code{VM_PROT_EXECUTE} and
3714: @code{VM_PROT_ALL} as defined in @file{mach/vm_prot.h}.
3715:
3716: If @var{precious} is @code{FALSE}, the kernel treats the data as a
3717: temporary and may throw it away if it hasn't been changed. If the
3718: @var{precious} value is @code{TRUE}, the kernel treats its copy as a
3719: data repository and promises to return it to the manager; the manager
3720: may tell the kernel to throw it away instead by flushing and not
3721: cleaning the data (see @code{memory_object_lock_request}).
3722:
3723: If @var{reply_to} is not @code{MACH_PORT_NULL}, the kernel will send a
3724: completion message to the provided port (see
3725: @code{memory_object_supply_completed}).
3726:
3727: This routine does not receive a reply message (and consequently has no
3728: return value), so only message transmission errors apply.
3729: @end deftypefun
3730:
3731: @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}})
3732: @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}})
3733: The function @code{memory_object_supply_completed} indicates that a
3734: previous @code{memory_object_data_supply} has been completed. Note that
3735: this call is made on whatever port was specified in the
3736: @code{memory_object_data_supply} call; that port need not be the memory
3737: object port itself. No reply is expected after this call.
3738:
3739: The argument @var{memory_object} is the port that represents the memory
3740: object data, as supplied to the kernel in a @code{vm_map} call.
3741: @var{memory_control} is the request port to which a response is
3742: requested. (In the event that a memory object has been supplied to more
3743: than one the kernel that has made the request.) @var{offset} is the
3744: offset within a memory object to which this call refers. @var{length}
3745: is the length of the data covered by the lock request. The @var{result}
3746: parameter indicates what happened during the supply. If it is not
3747: @code{KERN_SUCCESS}, then @var{error_offset} identifies the first offset
3748: at which a problem occurred. The pagein operation stopped at this
3749: point. Note that the only failures reported by this mechanism are
3750: @code{KERN_MEMORY_PRESENT}. All other failures (invalid argument, error
3751: on pagein of supplied data in manager's address space) cause the entire
3752: operation to fail.
3753:
3754:
3755: @end deftypefun
3756:
3757: @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}})
3758: The function @code{memory_object_data_error} indicates that the memory
3759: manager cannot return the data requested for the given region,
3760: specifying a reason for the error. This is typically used when a
3761: hardware error is encountered.
3762:
3763: The argument @var{memory_control} is the port, provided by the kernel in
3764: a @code{memory_object_init} call, to which cache management requests may
3765: be issued. @var{offset} is an offset within a memory object in bytes.
3766: This must be page aligned. @var{data} is the data that is being
3767: provided to the kernel. This is a pointer to the data. @var{size} is
3768: the amount of cached data (starting at @var{offset}) to be handled.
3769: This must be an integral number of the memory object page size.
1.1.1.2 root 3770: @var{reason} is an error code indicating what type of error occurred.
3771: @c The error code is currently ignored.
1.1 root 3772:
3773: This routine does not receive a reply message (and consequently has no
3774: return value), so only message transmission errors apply.
3775: @end deftypefun
3776:
3777: @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}})
3778: The function @code{memory_object_data_unavailable} indicates that the
3779: memory object does not have data for the given region and that the
3780: kernel should provide the data for this range. The memory manager may
3781: use this call in three different situations.
3782:
3783: @enumerate
3784: @item
3785: The object was created by @code{memory_object_create} and the kernel has
3786: not yet provided data for this range (either via a
3787: @code{memory_object_data_initialize}, @code{memory_object_data_write} or
3788: a @code{memory_object_data_return} for the object.
3789:
3790: @item
3791: The object was created by an @code{memory_object_data_copy} and the
3792: kernel should copy this region from the original memory object.
3793:
3794: @item
3795: The object is a normal user-created memory object and the kernel should
3796: supply unlocked zero-filled pages for the range.
3797: @end enumerate
3798:
3799: The argument @var{memory_control} is the port, provided by the kernel in
3800: a @code{memory_object_init} call, to which cache management requests may
3801: be issued. @var{offset} is an offset within a memory object, in bytes.
3802: This must be page aligned. @var{size} is the amount of cached data
3803: (starting at @var{offset}) to be handled. This must be an integral
3804: number of the memory object page size.
3805:
3806: This routine does not receive a reply message (and consequently has no
3807: return value), so only message transmission errors apply.
3808: @end deftypefun
3809:
3810: @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}})
3811: @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}})
3812: The function @code{memory_object_copy} indicates that a copy has been
3813: made of the specified range of the given original memory object. This
3814: call includes only the new memory object itself; a
3815: @code{memory_object_init} call will be made on the new memory object
3816: after the currently cached pages of the original object are prepared.
3817: After the memory manager receives the init call, it must reply with the
3818: @code{memory_object_ready} call to assert the "ready" attribute. The
3819: kernel will use the new memory object, control and name ports to refer
3820: to the new copy.
3821:
3822: This call is made when the original memory object had the caching
3823: parameter set to @code{MEMORY_OBJECT_COPY_CALL} and a user of the object
3824: has asked the kernel to copy it.
3825:
3826: Cached pages from the original memory object at the time of the copy
3827: operation are handled as follows: Readable pages may be silently copied
3828: to the new memory object (with all access permissions). Pages not
3829: copied are locked to prevent write access.
3830:
3831: The new memory object is @strong{temporary}, meaning that the memory
3832: manager should not change its contents or allow the memory object to be
3833: mapped in another client. The memory manager may use the
3834: @code{memory_object_data_unavailable} call to indicate that the
3835: appropriate pages of the original memory object may be used to fulfill
3836: the data request.
3837:
3838: The argument @var{old_memory_object} is the port that represents the old
3839: memory object data. @var{old_memory_control} is the kernel port for the
3840: old object. @var{offset} is the offset within a memory object to which
3841: this call refers. This will be page aligned. @var{length} is the
3842: number of bytes of data, starting at @var{offset}, to which this call
3843: refers. This will be an integral number of memory object pages.
3844: @var{new_memory_object} is a new memory object created by the kernel;
3845: see synopsis for further description. Note that all port rights
3846: (including receive rights) are included for the new memory object.
3847:
3848: The function should return @code{KERN_SUCCESS}, but since this routine
3849: is called by the kernel, which does not wait for a reply message, this
3850: value is ignored.
3851: @end deftypefun
3852:
1.1.1.2 root 3853: The remaining interfaces in this section are obsolete.
1.1 root 3854:
3855: @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}})
3856: @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}})
3857: The function @code{memory_object_data_write} provides the memory manager
3858: with data that has been modified while cached in physical memory. It is the old form of @code{memory_object_data_return}. Once
3859: the memory manager no longer needs this data (e.g., it has been written
3860: to another storage medium), it should be deallocated using
3861: @code{vm_deallocate}.
3862:
3863: The argument @var{memory_object} is the port that represents the memory
3864: object data, as supplied to the kernel in a @code{vm_map} call.
3865: @var{memory_control} is the request port to which a response is
3866: requested. (In the event that a memory object has been supplied to more
3867: than one the kernel that has made the request.) @var{offset} is the
3868: offset within a memory object to which this call refers. This will be
3869: page aligned. @var{data} is the data which has been modified while
3870: cached in physical memory. @var{data_count} is the amount of data to be
3871: written, in bytes. This will be an integral number of memory object
3872: pages.
3873:
3874: The function should return @code{KERN_SUCCESS}, but since this routine
3875: is called by the kernel, which does not wait for a reply message, this
3876: value is ignored.
3877: @end deftypefun
3878:
3879: @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}})
3880: The function @code{memory_object_data_provided} supplies the kernel with
3881: data for the specified memory object. It is the old form of
3882: @code{memory_object_data_supply}. Ordinarily, memory managers should
1.1.1.2 root 3883: only provide data in response to @code{memory_object_data_request} calls
1.1 root 3884: from the kernel. The @var{lock_value} specifies what type of access
3885: will not be allowed to the data range. The lock values must be one or
3886: more of the set: @code{VM_PROT_NONE}, @code{VM_PROT_READ},
3887: @code{VM_PROT_WRITE}, @code{VM_PROT_EXECUTE} and @code{VM_PROT_ALL} as
3888: defined in @file{mach/vm_prot.h}.
3889:
3890: The argument @var{memory_control} is the port, provided by the kernel in
3891: a @code{memory_object_init} call, to which cache management requests may
3892: be issued. @var{offset} is an offset within a memory object in bytes.
3893: This must be page aligned. @var{data} is the data that is being
3894: provided to the kernel. This is a pointer to the data.
3895: @var{data_count} is the amount of data to be provided. This must be an
3896: integral number of memory object pages. @var{lock_value} is a
3897: protection value indicating those forms of access that should
3898: @strong{not} be permitted to the specified cached data.
3899:
3900: This routine does not receive a reply message (and consequently has no
3901: return value), so only message transmission errors apply.
3902: @end deftypefun
3903:
3904:
3905: @node Memory Object Locking
3906: @section Memory Object Locking
3907:
3908: @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}})
3909: The function @code{memory_object_lock_request} allows a memory manager
3910: to make cache management requests. As specified in arguments to the
3911: call, the kernel will:
3912: @itemize
3913: @item
3914: clean (i.e., write back using @code{memory_object_data_supply} or
3915: @code{memory_object_data_write}) any cached data which has been modified
3916: since the last time it was written
3917:
3918: @item
3919: flush (i.e., remove any uses of) that data from memory
3920:
3921: @item
3922: lock (i.e., prohibit the specified uses of) the cached data
3923: @end itemize
3924:
3925: Locks applied to cached data are not cumulative; new lock values
3926: override previous ones. Thus, data may also be unlocked using this
3927: primitive. The lock values must be one or more of the following values:
3928: @code{VM_PROT_NONE}, @code{VM_PROT_READ}, @code{VM_PROT_WRITE},
3929: @code{VM_PROT_EXECUTE} and @code{VM_PROT_ALL} as defined in
3930: @file{mach/vm_prot.h}.
3931:
3932: Only data which is cached at the time of this call is affected. When a
3933: running thread requires a prohibited access to cached data, the kernel
3934: will issue a @code{memory_object_data_unlock} call specifying the forms
3935: of access required.
3936:
3937: Once all of the actions requested by this call have been completed, the
3938: kernel issues a @code{memory_object_lock_completed} call on the
3939: specified reply port.
3940:
3941: The argument @var{memory_control} is the port, provided by the kernel in
3942: a @code{memory_object_init} call, to which cache management requests may
3943: be issued. @var{offset} is an offset within a memory object, in bytes.
3944: This must be page aligned. @var{size} is the amount of cached data
3945: (starting at @var{offset}) to be handled. This must be an integral
3946: number of the memory object page size. If @var{should_clean} is set,
3947: modified data should be written back to the memory manager. If
3948: @var{should_flush} is set, the specified cached data should be
3949: invalidated, and all uses of that data should be revoked.
3950: @var{lock_value} is a protection value indicating those forms of access
3951: that should @strong{not} be permitted to the specified cached data.
1.1.1.2 root 3952: @var{reply_to} is a port on which a @code{memory_object_lock_completed}
1.1 root 3953: call should be issued, or @code{MACH_PORT_NULL} if no acknowledgement is
3954: desired.
3955:
3956: This routine does not receive a reply message (and consequently has no
3957: return value), so only message transmission errors apply.
3958: @end deftypefun
3959:
3960: @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}})
3961: @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}})
3962: The function @code{memory_object_lock_completed} indicates that a
3963: previous @code{memory_object_lock_request} has been completed. Note
3964: that this call is made on whatever port was specified in the
3965: @code{memory_object_lock_request} call; that port need not be the memory
3966: object port itself. No reply is expected after this call.
3967:
3968: The argument @var{memory_object} is the port that represents the memory
3969: object data, as supplied to the kernel in a @code{vm_map} call.
3970: @var{memory_control} is the request port to which a response is
3971: requested. (In the event that a memory object has been supplied to more
3972: than one the kernel that has made the request.) @var{offset} is the
3973: offset within a memory object to which this call refers. @var{length}
3974: is the length of the data covered by the lock request.
3975:
3976: The function should return @code{KERN_SUCCESS}, but since this routine
3977: is called by the kernel, which does not wait for a reply message, this
3978: value is ignored.
3979: @end deftypefun
3980:
3981: @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}})
3982: @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}})
3983: The function @code{memory_object_data_unlock} is a request that the
3984: memory manager permit at least the desired access to the specified data
3985: cached by the kernel. A call to @code{memory_object_lock_request} is
3986: expected in response.
3987:
3988: The argument @var{memory_object} is the port that represents the memory
3989: object data, as supplied to the kernel in a @code{vm_map} call.
3990: @var{memory_control} is the request port to which a response is
3991: requested. (In the event that a memory object has been supplied to more
3992: than one the kernel that has made the request.) @var{offset} is the
3993: offset within a memory object to which this call refers. This will be
3994: page aligned. @var{length} is the number of bytes of data, starting at
3995: @var{offset}, to which this call refers. This will be an integral
3996: number of memory object pages. @var{desired_access} a protection value
3997: describing the memory access modes which must be permitted on the
3998: specified cached data. One or more of: @code{VM_PROT_READ},
3999: @code{VM_PROT_WRITE} or @code{VM_PROT_EXECUTE}.
4000:
4001: The function should return @code{KERN_SUCCESS}, but since this routine
4002: is called by the kernel, which does not wait for a reply message, this
4003: value is ignored.
4004: @end deftypefun
4005:
4006:
4007: @node Memory Object Attributes
4008: @section Memory Object Attributes
4009:
4010: @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}})
4011: The function @code{memory_object_get_attribute} retrieves the current
4012: attributes associated with the memory object.
4013:
4014: The argument @var{memory_control} is the port, provided by the kernel in
4015: a @code{memory_object_init} call, to which cache management requests may
4016: be issued. If @var{object_ready} is set, the kernel may issue new data
4017: and unlock requests on the associated memory object. If
4018: @var{may_cache_object} is set, the kernel may keep data associated with
4019: this memory object, even after virtual memory references to it are gone.
4020: @var{copy_strategy} tells how the kernel should copy regions of the
4021: associated memory object.
4022:
4023: This routine does not receive a reply message (and consequently has no
4024: return value), so only message transmission errors apply.
4025: @end deftypefun
4026:
4027: @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}})
4028: The function @code{memory_object_change_attribute} sets
4029: performance-related attributes for the specified memory object. If the
4030: caching attribute is asserted, the kernel is permitted (and encouraged)
4031: to maintain cached data for this memory object even after no virtual
4032: address space contains this data.
4033:
4034: There are three possible caching strategies:
4035: @code{MEMORY_OBJECT_COPY_NONE} which specifies that nothing special
4036: should be done when data in the object is copied;
4037: @code{MEMORY_OBJECT_COPY_CALL} which specifies that the memory manager
4038: should be notified via a @code{memory_object_copy} call before any part
4039: of the object is copied; and @code{MEMORY_OBJECT_COPY_DELAY} which
4040: guarantees that the memory manager does not externally modify the data
4041: so that the kernel can use its normal copy-on-write algorithms.
4042: @code{MEMORY_OBJECT_COPY_DELAY} is the strategy most commonly used.
4043:
4044: The argument @var{memory_control} is the port, provided by the kernel in
4045: a @code{memory_object_init} call, to which cache management requests may
4046: be issued. If @var{may_cache_object} is set, the kernel may keep data
4047: associated with this memory object, even after virtual memory references
4048: to it are gone. @var{copy_strategy} tells how the kernel should copy
4049: regions of the associated memory object. @var{reply_to} is a port on
1.1.1.2 root 4050: which a @code{memory_object_change_completed} call will be issued upon
1.1 root 4051: completion of the attribute change, or @code{MACH_PORT_NULL} if no
4052: acknowledgement is desired.
4053:
4054: This routine does not receive a reply message (and consequently has no
4055: return value), so only message transmission errors apply.
4056: @end deftypefun
4057:
4058: @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}})
4059: @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}})
4060: The function @code{memory_object_change_completed} indicates the
4061: completion of an attribute change call.
4062:
4063: @c Warning: This routine does NOT contain a memory_object_control_t because
4064: @c the memory_object_change_attributes call may cause memory object
4065: @c termination (by uncaching the object). This would yield an invalid
4066: @c port.
4067: @end deftypefun
4068:
4069: The following interface is obsoleted by @code{memory_object_ready} and
4070: @code{memory_object_change_attributes}. If the old form
4071: @code{memory_object_set_attributes} is used to make a memory object
4072: ready, the kernel will write back data using the old
4073: @code{memory_object_data_write} interface rather than
4074: @code{memory_object_data_return}..
4075:
4076: @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 4077: The function @code{memory_object_set_attribute} controls how the
1.1 root 4078: memory object. The kernel will only make data or unlock requests when
4079: the ready attribute is asserted. If the caching attribute is asserted,
4080: the kernel is permitted (and encouraged) to maintain cached data for
4081: this memory object even after no virtual address space contains this
4082: data.
4083:
4084: There are three possible caching strategies:
4085: @code{MEMORY_OBJECT_COPY_NONE} which specifies that nothing special
4086: should be done when data in the object is copied;
4087: @code{MEMORY_OBJECT_COPY_CALL} which specifies that the memory manager
4088: should be notified via a @code{memory_object_copy} call before any part
4089: of the object is copied; and @code{MEMORY_OBJECT_COPY_DELAY} which
4090: guarantees that the memory manager does not externally modify the data
4091: so that the kernel can use its normal copy-on-write algorithms.
4092: @code{MEMORY_OBJECT_COPY_DELAY} is the strategy most commonly used.
4093:
4094: The argument @var{memory_control} is the port, provided by the kernel in
4095: a @code{memory_object_init} call, to which cache management requests may
4096: be issued. If @var{object_ready} is set, the kernel may issue new data
4097: and unlock requests on the associated memory object. If
4098: @var{may_cache_object} is set, the kernel may keep data associated with
4099: this memory object, even after virtual memory references to it are gone.
4100: @var{copy_strategy} tells how the kernel should copy regions of the
4101: associated memory object.
4102:
4103: This routine does not receive a reply message (and consequently has no
4104: return value), so only message transmission errors apply.
4105: @end deftypefun
4106:
4107:
4108: @node Default Memory Manager
4109: @section Default Memory Manager
4110:
4111: @deftypefun kern_return_t vm_set_default_memory_manager (@w{host_t @var{host}}, @w{mach_port_t *@var{default_manager}})
4112: The function @code{vm_set_default_memory_manager} sets the kernel's
4113: default memory manager. It sets the port to which newly-created
4114: temporary memory objects are delivered by @code{memory_object_create} to
4115: the host. The old memory manager port is returned. If
4116: @var{default_manager} is @code{MACH_PORT_NULL} then this routine just returns
4117: the current default manager port without changing it.
4118:
4119: The argument @var{host} is a task port to the kernel whose default
4120: memory manager is to be changed. @var{default_manager} is an in/out
4121: parameter. As input, @var{default_manager} is the port that the new
4122: memory manager is listening on for @code{memory_object_create} calls.
4123: As output, it is the old default memory manager's port.
4124:
4125: The function returns @code{KERN_SUCCESS} if the new memory manager is
4126: installed, and @code{KERN_INVALID_ARGUMENT} if this task does not have
4127: the privileges required for this call.
4128: @end deftypefun
4129:
4130: @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}})
4131: @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}})
4132: The function @code{memory_object_create} is a request that the given
4133: memory manager accept responsibility for the given memory object created
4134: by the kernel. This call will only be made to the system
4135: @strong{default memory manager}. The memory object in question
4136: initially consists of zero-filled memory; only memory pages that are
4137: actually written will ever be provided to
4138: @code{memory_object_data_request} calls, the default memory manager must
4139: use @code{memory_object_data_unavailable} for any pages that have not
4140: previously been written.
4141:
4142: No reply is expected after this call. Since this call is directed to
4143: the default memory manager, the kernel assumes that it will be ready to
4144: handle data requests to this object and does not need the confirmation
4145: of a @code{memory_object_set_attributes} call.
4146:
4147: The argument @var{old_memory_object} is a memory object provided by the
4148: default memory manager on which the kernel can make
4149: @code{memory_object_create} calls. @var{new_memory_object} is a new
4150: memory object created by the kernel; see synopsis for further
4151: description. Note that all port rights (including receive rights) are
4152: included for the new memory object. @var{new_object_size} is the
4153: maximum size of the new object. @var{new_control} is a port, created by
4154: the kernel, on which a memory manager may issue cache management
4155: requests for the new object. @var{new_name} a port used by the kernel
4156: to refer to the new memory object data in response to @code{vm_region}
4157: calls. @var{new_page_size} is the page size to be used by this kernel.
4158: All data sizes in calls involving this kernel must be an integral
4159: multiple of the page size. Note that different kernels, indicated by
4160: different a @code{memory_control}, may have different page sizes.
4161:
4162: The function should return @code{KERN_SUCCESS}, but since this routine
4163: is called by the kernel, which does not wait for a reply message, this
4164: value is ignored.
4165: @end deftypefun
4166:
4167: @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}})
4168: @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}})
4169: The function @code{memory_object_data_initialize} provides the memory
4170: manager with initial data for a kernel-created memory object. If the
4171: memory manager already has been supplied data (by a previous
4172: @code{memory_object_data_initialize}, @code{memory_object_data_write} or
4173: @code{memory_object_data_return}), then this data should be ignored.
4174: Otherwise, this call behaves exactly as does
4175: @code{memory_object_data_return} on memory objects created by the kernel
4176: via @code{memory_object_create} and thus will only be made to default
4177: memory managers. This call will not be made on objects created via
4178: @code{memory_object_copy}.
4179:
4180: The argument @var{memory_object} the port that represents the memory
4181: object data, as supplied by the kernel in a @code{memory_object_create}
4182: call. @var{memory_control} is the request port to which a response is
4183: requested. (In the event that a memory object has been supplied to more
4184: than one the kernel that has made the request.) @var{offset} is the
4185: offset within a memory object to which this call refers. This will be
1.1.1.2 root 4186: page aligned. @var{data} is the data which has been modified while
1.1 root 4187: cached in physical memory. @var{data_count} is the amount of data to be
4188: written, in bytes. This will be an integral number of memory object
4189: pages.
4190:
4191: The function should return @code{KERN_SUCCESS}, but since this routine
4192: is called by the kernel, which does not wait for a reply message, this
4193: value is ignored.
4194: @end deftypefun
4195:
4196:
4197: @node Threads and Tasks
4198: @chapter Threads and Tasks
4199:
4200: @menu
4201: * Thread Interface:: Manipulating threads.
4202: * Task Interface:: Manipulating tasks.
4203: * Profiling:: Profiling threads and tasks.
4204: @end menu
4205:
4206:
4207: @node Thread Interface
4208: @section Thread Interface
4209:
4210: @cindex thread port
4211: @cindex port representing a thread
4212: @deftp {Data type} thread_t
4213: This is a @code{mach_port_t} and used to hold the port name of a
4214: thread port that represents the thread. Manipulations of the thread are
4215: implemented as remote procedure calls to the thread port. A thread can
4216: get a port to itself with the @code{mach_thread_self} system call.
4217: @end deftp
4218:
4219: @menu
4220: * Thread Creation:: Creating new threads.
4221: * Thread Termination:: Terminating existing threads.
4222: * Thread Information:: How to get informations on threads.
4223: * Thread Settings:: How to set threads related informations.
4224: * Thread Execution:: How to control the thread's machine state.
4225: * Scheduling:: Operations on thread scheduling.
4226: * Thread Special Ports:: How to handle the thread's special ports.
4227: * Exceptions:: Managing exceptions.
4228: @end menu
4229:
4230:
4231: @node Thread Creation
4232: @subsection Thread Creation
4233:
4234: @deftypefun kern_return_t thread_create (@w{task_t @var{parent_task}}, @w{thread_t *@var{child_thread}})
4235: The function @code{thread_create} creates a new thread within the task
4236: specified by @var{parent_task}. The new thread has no processor state,
4237: and has a suspend count of 1. To get a new thread to run, first
4238: @code{thread_create} is called to get the new thread's identifier,
4239: (@var{child_thread}). Then @code{thread_set_state} is called to set a
4240: processor state, and finally @code{thread_resume} is called to get the
4241: thread scheduled to execute.
4242:
4243: When the thread is created send rights to its thread kernel port are
4244: given to it and returned to the caller in @var{child_thread}. The new
4245: thread's exception port is set to @code{MACH_PORT_NULL}.
4246:
4247: The function returns @code{KERN_SUCCESS} if a new thread has been
4248: created, @code{KERN_INVALID_ARGUMENT} if @var{parent_task} is not a
4249: valid task and @code{KERN_RESOURCE_SHORTAGE} if some critical kernel
4250: resource is not available.
4251: @end deftypefun
4252:
4253:
4254: @node Thread Termination
4255: @subsection Thread Termination
4256:
4257: @deftypefun kern_return_t thread_terminate (@w{thread_t @var{target_thread}})
4258: The function @code{thread_terminate} destroys the thread specified by
4259: @var{target_thread}.
4260:
4261: The function returns @code{KERN_SUCCESS} if the thread has been killed
4262: and @code{KERN_INVALID_ARGUMENT} if @var{target_thread} is not a thread.
4263: @end deftypefun
4264:
4265:
4266: @node Thread Information
4267: @subsection Thread Information
4268:
4269: @deftypefun thread_t mach_thread_self ()
4270: The @code{mach_thread_self} system call returns the calling thread's
4271: thread port.
4272:
4273: @code{mach_thread_self} has an effect equivalent to receiving a send
4274: right for the thread port. @code{mach_thread_self} returns the name of
4275: the send right. In particular, successive calls will increase the
4276: calling task's user-reference count for the send right.
4277:
4278: @c author{marcus}
4279: As a special exception, the kernel will overrun the user reference count
4280: of the thread name port, so that this function can not fail for that
4281: reason. Because of this, the user should not deallocate the port right
4282: if an overrun might have happened. Otherwise the reference count could
4283: drop to zero and the send right be destroyed while the user still
4284: expects to be able to use it. As the kernel does not make use of the
4285: number of extant send rights anyway, this is safe to do (the thread port
4286: itself is not destroyed, even when there are no send rights anymore).
4287:
4288: The function returns @code{MACH_PORT_NULL} if a resource shortage
4289: prevented the reception of the send right or if the thread port is
4290: currently null and @code{MACH_PORT_DEAD} if the thread port is currently
4291: dead.
4292: @end deftypefun
4293:
4294: @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}})
4295: The function @code{thread_info} returns the selected information array
4296: for a thread, as specified by @var{flavor}.
4297:
4298: @var{thread_info} is an array of integers that is supplied by the caller
4299: and returned filled with specified information. @var{thread_infoCnt} is
4300: supplied as the maximum number of integers in @var{thread_info}. On
4301: return, it contains the actual number of integers in @var{thread_info}.
4302: The maximum number of integers returned by any flavor is
4303: @code{THREAD_INFO_MAX}.
4304:
4305: The type of information returned is defined by @var{flavor}, which can
4306: be one of the following:
4307:
4308: @table @code
4309: @item THREAD_BASIC_INFO
4310: The function returns basic information about the thread, as defined by
4311: @code{thread_basic_info_t}. This includes the user and system time, the
4312: run state, and scheduling priority. The number of integers returned is
4313: @code{THREAD_BASIC_INFO_COUNT}.
4314:
4315: @item THREAD_SCHED_INFO
1.1.1.2 root 4316: The function returns information about the scheduling policy for the
1.1 root 4317: thread as defined by @code{thread_sched_info_t}. The number of integers
4318: returned is @code{THREAD_SCHED_INFO_COUNT}.
4319: @end table
4320:
4321: The function returns @code{KERN_SUCCESS} if the call succeeded and
4322: @code{KERN_INVALID_ARGUMENT} if @var{target_thread} is not a thread or
4323: @var{flavor} is not recognized. The function returns
4324: @code{MIG_ARRAY_TOO_LARGE} if the returned info array is too large for
4325: @var{thread_info}. In this case, @var{thread_info} is filled as much as
4326: possible and @var{thread_infoCnt} is set to the number of elements that
4327: would have been returned if there were enough room.
4328: @end deftypefun
4329:
4330: @deftp {Data type} {struct thread_basic_info}
4331: This structure is returned in @var{thread_info} by the
4332: @code{thread_info} function and provides basic information about the
4333: thread. You can cast a variable of type @code{thread_info_t} to a
4334: pointer of this type if you provided it as the @var{thread_info}
4335: parameter for the @code{THREAD_BASIC_INFO} flavor of @code{thread_info}.
4336: It has the following members:
4337:
4338: @table @code
4339: @item time_value_t user_time
4340: user run time
4341:
4342: @item time_value_t system_time
4343: system run time
4344: @item int cpu_usage
4345: Scaled cpu usage percentage. The scale factor is @code{TH_USAGE_SCALE}.
4346:
4347: @item int base_priority
4348: The base scheduling priority of the thread.
4349:
4350: @item int cur_priority
4351: The current scheduling priority of the thread.
4352:
4353: @item integer_t run_state
1.1.1.2 root 4354: The run state of the thread. The possible values of this field are:
1.1 root 4355: @table @code
4356: @item TH_STATE_RUNNING
4357: The thread is running normally.
4358:
4359: @item TH_STATE_STOPPED
4360: The thread is suspended.
4361:
4362: @item TH_STATE_WAITING
4363: The thread is waiting normally.
4364:
4365: @item TH_STATE_UNINTERRUPTIBLE
4366: The thread is in an uninterruptible wait.
4367:
4368: @item TH_STATE_HALTED
4369: The thread is halted at a clean point.
4370: @end table
4371:
4372: @item flags
4373: Various flags. The possible values of this field are:
4374: @table @code
4375: @item TH_FLAGS_SWAPPED
4376: The thread is swapped out.
4377:
4378: @item TH_FLAGS_IDLE
4379: The thread is an idle thread.
4380: @end table
4381:
4382: @item int suspend_count
4383: The suspend count for the thread.
4384:
4385: @item int sleep_time
4386: The number of seconds that the thread has been sleeping.
4387:
4388: @item time_value_t creation_time
4389: The time stamp of creation.
4390: @end table
4391: @end deftp
4392:
4393: @deftp {Data type} thread_basic_info_t
4394: This is a pointer to a @code{struct thread_basic_info}.
4395: @end deftp
4396:
4397: @deftp {Data type} {struct thread_sched_info}
4398: This structure is returned in @var{thread_info} by the
4399: @code{thread_info} function and provides schedule information about the
4400: thread. You can cast a variable of type @code{thread_info_t} to a
4401: pointer of this type if you provided it as the @var{thread_info}
4402: parameter for the @code{THREAD_SCHED_INFO} flavor of @code{thread_info}.
4403: It has the following members:
4404:
4405: @table @code
4406: @item int policy
4407: The scheduling policy of the thread, @ref{Scheduling Policy}.
4408:
4409: @item integer_t data
4410: Policy-dependent scheduling information, @ref{Scheduling Policy}.
4411:
4412: @item int base_priority
4413: The base scheduling priority of the thread.
4414:
4415: @item int max_priority
4416: The maximum scheduling priority of the thread.
4417:
4418: @item int cur_priority
4419: The current scheduling priority of the thread.
4420:
4421: @item int depressed
4422: @code{TRUE} if the thread is depressed.
4423:
4424: @item int depress_priority
4425: The priority the thread was depressed from.
4426: @end table
4427: @end deftp
4428:
4429: @deftp {Data type} thread_sched_info_t
4430: This is a pointer to a @code{struct thread_sched_info}.
4431: @end deftp
4432:
4433:
4434: @node Thread Settings
4435: @subsection Thread Settings
4436:
4437: @deftypefun kern_return_t thread_wire (@w{host_priv_t @var{host_priv}}, @w{thread_t @var{thread}}, @w{boolean_t @var{wired}})
4438: The function @code{thread_wire} controls the VM privilege level of the
4439: thread @var{thread}. A VM-privileged thread never waits inside the
4440: kernel for memory allocation from the kernel's free list of pages or for
4441: allocation of a kernel stack.
4442:
4443: Threads that are part of the default pageout path should be
4444: VM-privileged, to prevent system deadlocks. Threads that are not part
4445: of the default pageout path should not be VM-privileged, to prevent the
4446: kernel's free list of pages from being exhausted.
4447:
4448: The functions returns @code{KERN_SUCCESS} if the call succeeded,
4449: @code{KERN_INVALID_ARGUMENT} if @var{host_priv} or @var{thread} was
4450: invalid.
4451:
4452: The @code{thread_wire} call is actually an RPC to @var{host_priv},
4453: normally a send right for a privileged host port, but potentially any
4454: send right. In addition to the normal diagnostic return codes from the
4455: call's server (normally the kernel), the call may return @code{mach_msg}
4456: return codes.
4457: @c See also: vm_wire(2), vm_set_default_memory_manager(2).
4458: @end deftypefun
4459:
4460:
4461: @node Thread Execution
4462: @subsection Thread Execution
4463:
4464: @deftypefun kern_return_t thread_suspend (@w{thread_t @var{target_thread}})
4465: Increments the thread's suspend count and prevents the thread from
4466: executing any more user level instructions. In this context a user
4467: level instruction is either a machine instruction executed in user mode
4468: or a system trap instruction including page faults. Thus if a thread is
4469: currently executing within a system trap the kernel code may continue to
1.1.1.2 root 4470: execute until it reaches the system return code or it may suspend within
1.1 root 4471: the kernel code. In either case, when the thread is resumed the system
1.1.1.2 root 4472: trap will return. This could cause unpredictable results if the user
1.1 root 4473: did a suspend and then altered the user state of the thread in order to
4474: change its direction upon a resume. The call @code{thread_abort} is
4475: provided to allow the user to abort any system call that is in progress
4476: in a predictable way.
4477:
4478: The suspend count may become greater than one with the effect that it
4479: will take more than one resume call to restart the thread.
4480:
4481: The function returns @code{KERN_SUCCESS} if the thread has been
4482: suspended and @code{KERN_INVALID_ARGUMENT} if @var{target_thread} is not
4483: a thread.
4484: @end deftypefun
4485:
4486: @deftypefun kern_return_t thread_resume (@w{thread_t @var{target_thread}})
1.1.1.2 root 4487: Decrements the thread's suspend count. If the count becomes zero the
1.1 root 4488: thread is resumed. If it is still positive, the thread is left
4489: suspended. The suspend count may not become negative.
4490:
4491: The function returns @code{KERN_SUCCESS} if the thread has been resumed,
4492: @code{KERN_FAILURE} if the suspend count is already zero and
4493: @code{KERN_INVALID_ARGUMENT} if @var{target_thread} is not a thread.
4494: @end deftypefun
4495:
4496: @deftypefun kern_return_t thread_abort (@w{thread_t @var{target_thread}})
4497: The function @code{thread_abort} aborts the kernel primitives:
4498: @code{mach_msg}, @code{msg_send}, @code{msg_receive} and @code{msg_rpc}
4499: and page-faults, making the call return a code indicating that it was
4500: interrupted. The call is interrupted whether or not the thread (or task
1.1.1.2 root 4501: containing it) is currently suspended. If it is suspended, the thread
4502: receives the interrupt when it is resumed.
1.1 root 4503:
4504: A thread will retry an aborted page-fault if its state is not modified
4505: before it is resumed. @code{msg_send} returns @code{SEND_INTERRUPTED};
4506: @code{msg_receive} returns @code{RCV_INTERRUPTED}; @code{msg_rpc}
4507: returns either @code{SEND_INTERRUPTED} or @code{RCV_INTERRUPTED},
4508: depending on which half of the RPC was interrupted.
4509:
4510: The main reason for this primitive is to allow one thread to cleanly
4511: stop another thread in a manner that will allow the future execution of
4512: the target thread to be controlled in a predictable way.
4513: @code{thread_suspend} keeps the target thread from executing any further
4514: instructions at the user level, including the return from a system call.
4515: @code{thread_get_state}/@code{thread_set_state} allows the examination
4516: or modification of the user state of a target thread. However, if a
4517: suspended thread was executing within a system call, it also has
4518: associated with it a kernel state. This kernel state can not be
4519: modified by @code{thread_set_state} with the result that when the thread
4520: is resumed the system call may return changing the user state and
4521: possibly user memory. @code{thread_abort} aborts the kernel call from
4522: the target thread's point of view by resetting the kernel state so that
4523: the thread will resume execution at the system call return with the
4524: return code value set to one of the interrupted codes. The system call
4525: itself will either be entirely completed or entirely aborted, depending
4526: on the precise moment at which the abort was received. Thus if the
4527: thread's user state has been changed by @code{thread_set_state}, it will
4528: not be modified by any unexpected system call side effects.
4529:
4530: For example to simulate a Unix signal, the following sequence of calls
4531: may be used:
4532:
4533: @enumerate
4534: @item
4535: @code{thread_suspend}: Stops the thread.
4536:
4537: @item
4538: @code{thread_abort}: Interrupts any system call in progress, setting the
4539: return value to `interrupted'. Since the thread is stopped, it will not
4540: return to user code.
4541:
4542: @item
4543: @code{thread_set_state}: Alters thread's state to simulate a procedure
4544: call to the signal handler
4545:
4546: @item
4547: @code{thread_resume}: Resumes execution at the signal handler. If the
4548: thread's stack has been correctly set up, the thread may return to the
4549: interrupted system call. (Of course, the code to push an extra stack
4550: frame and change the registers is VERY machine-dependent.)
4551: @end enumerate
4552:
4553: Calling @code{thread_abort} on a non-suspended thread is pretty risky,
4554: since it is very difficult to know exactly what system trap, if any, the
4555: thread might be executing and whether an interrupt return would cause
4556: the thread to do something useful.
4557:
4558: The function returns @code{KERN_SUCCESS} if the thread received an
4559: interrupt and @code{KERN_INVALID_ARGUMENT} if @var{target_thread} is not
4560: a thread.
4561: @end deftypefun
4562:
4563: @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}})
4564: The function @code{thread_get_state} returns the execution state
4565: (e.g. the machine registers) of @var{target_thread} as specified by
4566: @var{flavor}. The @var{old_state} is an array of integers that is
4567: provided by the caller and returned filled with the specified
4568: information. @var{old_stateCnt} is input set to the maximum number of
4569: integers in @var{old_state} and returned equal to the actual number of
4570: integers in @var{old_state}.
4571:
4572: @var{target_thread} may not be @code{mach_thread_self()}.
4573:
4574: The definition of the state structures can be found in
4575: @file{machine/thread_status.h}.
4576:
4577: The function returns @code{KERN_SUCCESS} if the state has been returned,
4578: @code{KERN_INVALID_ARGUMENT} if @var{target_thread} is not a thread or
1.1.1.2 root 4579: is @code{mach_thread_self} or @var{flavor} is unrecognized for this machine.
1.1 root 4580: The function returns @code{MIG_ARRAY_TOO_LARGE} if the returned state is
4581: too large for @var{old_state}. In this case, @var{old_state} is filled
4582: as much as possible and @var{old_stateCnt} is set to the number of
4583: elements that would have been returned if there were enough room.
4584: @end deftypefun
4585:
4586: @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}})
4587: The function @code{thread_set_state} sets the execution state (e.g. the
4588: machine registers) of @var{target_thread} as specified by @var{flavor}.
4589: The @var{new_state} is an array of integers. @var{new_state_count} is
4590: the number of elements in @var{new_state}. The entire set of registers
4591: is reset. This will do unpredictable things if @var{target_thread} is
4592: not suspended.
4593:
4594: @var{target_thread} may not be @code{mach_thread_self}.
4595:
4596: The definition of the state structures can be found in
4597: @file{machine/thread_status.h}.
4598:
4599: The function returns @code{KERN_SUCCESS} if the state has been set and
4600: @code{KERN_INVALID_ARGUMENT} if @var{target_thread} is not a thread or
1.1.1.2 root 4601: is @code{mach_thread_self} or @var{flavor} is unrecognized for this
1.1 root 4602: machine.
4603: @end deftypefun
4604:
4605:
4606: @node Scheduling
4607: @subsection Scheduling
4608:
4609: @menu
4610: * Thread Priority:: Changing the priority of a thread.
4611: * Hand-Off Scheduling:: Switching to a new thread.
4612: * Scheduling Policy:: Setting the scheduling policy.
4613: @end menu
4614:
4615:
4616: @node Thread Priority
4617: @subsubsection Thread Priority
4618:
4619: Threads have three priorities associated with them by the system, a
4620: priority, a maximum priority, and a scheduled priority. The scheduled
4621: priority is used to make scheduling decisions about the thread. It is
4622: determined from the priority by the policy (for timesharing, this means
4623: adding an increment derived from cpu usage). The priority can be set
4624: under user control, but may never exceed the maximum priority. Changing
4625: the maximum priority requires presentation of the control port for the
4626: thread's processor set; since the control port for the default processor
4627: set is privileged, users cannot raise their maximum priority to unfairly
4628: compete with other users on that set. Newly created threads obtain
4629: their priority from their task and their max priority from the thread.
4630:
4631: @deftypefun kern_return_t thread_priority (@w{thread_t @var{thread}}, @w{int @var{prority}}, @w{boolean_t @var{set_max}})
4632: The function @code{thread_priority} changes the priority and optionally
1.1.1.3 root 4633: the maximum priority of @var{thread}. Priorities range from 0 to 49,
1.1 root 4634: where lower numbers denote higher priorities. If the new priority is
4635: higher than the priority of the current thread, preemption may occur as
4636: a result of this call. The maximum priority of the thread is also set
4637: if @var{set_max} is @code{TRUE}. This call will fail if @var{priority}
4638: is greater than the current maximum priority of the thread. As a
4639: result, this call can only lower the value of a thread's maximum
4640: priority.
4641:
4642: The functions returns @code{KERN_SUCCESS} if the operation completed
4643: successfully, @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a
1.1.1.3 root 4644: thread or @var{priority} is out of range (not in 0..49), and
1.1 root 4645: @code{KERN_FAILURE} if the requested operation would violate the
4646: thread's maximum priority (thread_priority).
4647: @end deftypefun
4648:
4649: @deftypefun kern_return_t thread_max_priority (@w{thread_t @var{thread}}, @w{processor_set_t @var{processor_set}}, @w{int @var{priority}})
4650: The function @code{thread_max_priority} changes the maximum priority of
4651: the thread. Because it requires presentation of the corresponding
4652: processor set port, this call can reset the maximum priority to any
4653: legal value.
4654:
4655: The functions returns @code{KERN_SUCCESS} if the operation completed
4656: successfully, @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a
4657: thread or @var{processor_set} is not a control port for a processor set
1.1.1.3 root 4658: or @var{priority} is out of range (not in 0..49), and
1.1 root 4659: @code{KERN_FAILURE} if the thread is not assigned to the processor set
4660: whose control port was presented.
4661: @end deftypefun
4662:
4663:
4664: @node Hand-Off Scheduling
4665: @subsubsection Hand-Off Scheduling
4666:
4667: @deftypefun kern_return_t thread_switch (@w{thread_t @var{new_thread}}, @w{int @var{option}}, @w{int @var{time}})
4668: The function @code{thread_switch} provides low-level access to the
4669: scheduler's context switching code. @var{new_thread} is a hint that
4670: implements hand-off scheduling. The operating system will attempt to
1.1.1.2 root 4671: switch directly to the new thread (bypassing the normal logic that
1.1 root 4672: selects the next thread to run) if possible. Since this is a hint, it
4673: may be incorrect; it is ignored if it doesn't specify a thread on the
4674: same host as the current thread or if that thread can't be switched to
1.1.1.2 root 4675: (i.e., not runnable or already running on another processor or giving
4676: a plainly invalid hint, such as @code{MACH_PORT_NULL}). In this case,
4677: the normal logic to select the next thread to run is used; the current
4678: thread may continue running if there is no other appropriate thread to
4679: run.
1.1 root 4680:
4681: Options for @var{option} are defined in @file{mach/thread_switch.h} and
4682: specify the interpretation of @var{time}. The possible values for
4683: @var{option} are:
4684:
4685: @table @code
4686: @item SWITCH_OPTION_NONE
4687: No options, the time argument is ignored.
4688:
4689: @item SWITCH_OPTION_WAIT
1.1.1.2 root 4690: The thread is blocked for the specified time (in milliseconds;
4691: specifying @code{0} will wait for the next tick). This can be aborted
4692: by @code{thread_abort}.
1.1 root 4693:
4694: @item SWITCH_OPTION_DEPRESS
4695: The thread's priority is depressed to the lowest possible value for the
4696: specified time. This can be aborted by @code{thread_depress_abort}.
4697: This depression is independent of operations that change the thread's
4698: priority (e.g. @code{thread_priority} will not abort the depression).
4699: The minimum time and units of time can be obtained as the
4700: @code{min_timeout} value from @code{host_info}. The depression is also
1.1.1.2 root 4701: aborted when the current thread is next run (either via hand-off
1.1 root 4702: scheduling or because the processor set has nothing better to do).
4703: @end table
4704:
4705: @code{thread_switch} is often called when the current thread can proceed
4706: no further for some reason; the various options and arguments allow
4707: information about this reason to be transmitted to the kernel. The
4708: @var{new_thread} argument (handoff scheduling) is useful when the
4709: identity of the thread that must make progress before the current thread
4710: runs again is known. The @code{WAIT} option is used when the amount of
4711: time that the current thread must wait before it can do anything useful
4712: can be estimated and is fairly long. The @code{DEPRESS} option is used
4713: when the amount of time that must be waited is fairly short, especially
4714: when the identity of the thread that is being waited for is not known.
4715:
4716: Users should beware of calling @code{thread_switch} with an invalid hint
4717: (e.g. @code{MACH_PORT_NULL}) and no option. Because the time-sharing
4718: scheduler varies the priority of threads based on usage, this may result
4719: in a waste of cpu time if the thread that must be run is of lower
4720: priority. The use of the @code{DEPRESS} option in this situation is
4721: highly recommended.
4722:
4723: @code{thread_switch} ignores policies. Users relying on the preemption
4724: semantics of a fixed time policy should be aware that
4725: @code{thread_switch} ignores these semantics; it will run the specified
1.1.1.2 root 4726: @var{new_thread} independent of its priority and the priority of any other
1.1 root 4727: threads that could be run instead.
4728:
4729: The function returns @code{KERN_SUCCESS} if the call succeeded,
4730: @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a thread or
4731: @var{option} is not a recognized option, and @code{KERN_FAILURE} if
4732: @code{kern_depress_abort} failed because the thread was not depressed.
4733: @end deftypefun
4734:
4735: @deftypefun kern_return_t thread_depress_abort (@w{thread_t @var{thread}})
4736: The function @code{thread_depress_abort} cancels any priority depression
4737: for @var{thread} caused by a @code{swtch_pri} or @code{thread_switch}
4738: call.
4739:
4740: The function returns @code{KERN_SUCCESS} if the call succeeded and
4741: @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a valid thread.
4742: @end deftypefun
4743:
4744: @deftypefun boolean_t swtch ()
4745: @c XXX Clear up wording.
4746: The system trap @code{swtch} attempts to switch the current thread off
4747: the processor. The return value indicates if more than the current
4748: thread is running in the processor set. This is useful for lock
4749: management routines.
4750:
4751: The call returns @code{FALSE} if the thread is justified in becoming a
4752: resource hog by continuing to spin because there's nothing else useful
4753: that the processor could do. @code{TRUE} is returned if the thread
4754: should make one more check on the lock and then be a good citizen and
4755: really suspend.
4756: @end deftypefun
4757:
4758: @deftypefun boolean_t swtch_pri (@w{int @var{priority}})
4759: The system trap @code{swtch_pri} attempts to switch the current thread
4760: off the processor as @code{swtch} does, but depressing the priority of
4761: the thread to the minimum possible value during the time.
4762: @var{priority} is not used currently.
4763:
4764: The return value is as for @code{swtch}.
4765: @end deftypefun
4766:
4767:
4768: @node Scheduling Policy
4769: @subsubsection Scheduling Policy
4770:
4771: @deftypefun kern_return_t thread_policy (@w{thread_t @var{thread}}, @w{int @var{policy}}, @w{int @var{data}})
4772: The function @code{thread_policy} changes the scheduling policy for
4773: @var{thread} to @var{policy}.
4774:
4775: @var{data} is policy-dependent scheduling information. There are
4776: currently two supported policies: @code{POLICY_TIMESHARE} and
4777: @code{POLICY_FIXEDPRI} defined in @file{mach/policy.h}; this file is
4778: included by @file{mach.h}. @var{data} is meaningless for timesharing,
4779: but is the quantum to be used (in milliseconds) for the fixed priority
4780: policy. To be meaningful, this quantum must be a multiple of the basic
4781: system quantum (min_quantum) which can be obtained from
4782: @code{host_info}. The system will always round up to the next multiple
4783: of the quantum.
4784:
4785: Processor sets may restrict the allowed policies, so this call will fail
4786: if the processor set to which @var{thread} is currently assigned does
4787: not permit @var{policy}.
4788:
4789: The function returns @code{KERN_SUCCESS} if the call succeeded.
4790: @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a thread or
4791: @var{policy} is not a recognized policy, and @code{KERN_FAILURE} if the
4792: processor set to which @var{thread} is currently assigned does not
4793: permit @var{policy}.
4794: @end deftypefun
4795:
4796:
4797: @node Thread Special Ports
4798: @subsection Thread Special Ports
4799:
4800: @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}})
4801: The function @code{thread_get_special_port} returns send rights to one
4802: of a set of special ports for the thread specified by @var{thread}.
4803:
4804: The possible values for @var{which_port} are @code{THREAD_KERNEL_PORT}
4805: and @code{THREAD_EXCEPTION_PORT}. A thread also has access to its
4806: task's special ports.
4807:
4808: The function returns @code{KERN_SUCCESS} if the port was returned and
4809: @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a thread or
4810: @var{which_port} is an invalid port selector.
4811: @end deftypefun
4812:
4813: @deftypefun kern_return_t thread_get_kernel_port (@w{thread_t @var{thread}}, @w{mach_port_t *@var{kernel_port}})
4814: The function @code{thread_get_kernel_port} is equivalent to the function
4815: @code{thread_get_special_port} with the @var{which_port} argument set to
4816: @code{THREAD_KERNEL_PORT}.
4817: @end deftypefun
4818:
4819: @deftypefun kern_return_t thread_get_exception_port (@w{thread_t @var{thread}}, @w{mach_port_t *@var{exception_port}})
4820: The function @code{thread_get_exception_port} is equivalent to the
4821: function @code{thread_get_special_port} with the @var{which_port}
4822: argument set to @code{THREAD_EXCEPTION_PORT}.
4823: @end deftypefun
4824:
4825: @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}})
4826: The function @code{thread_set_special_port} sets one of a set of special
4827: ports for the thread specified by @var{thread}.
4828:
4829: The possible values for @var{which_port} are @code{THREAD_KERNEL_PORT}
4830: and @code{THREAD_EXCEPTION_PORT}. A thread also has access to its
4831: task's special ports.
4832:
4833: The function returns @code{KERN_SUCCESS} if the port was set and
4834: @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a thread or
4835: @var{which_port} is an invalid port selector.
4836: @end deftypefun
4837:
4838: @deftypefun kern_return_t thread_set_kernel_port (@w{thread_t @var{thread}}, @w{mach_port_t @var{kernel_port}})
4839: The function @code{thread_set_kernel_port} is equivalent to the function
4840: @code{thread_set_special_port} with the @var{which_port} argument set to
4841: @code{THREAD_KERNEL_PORT}.
4842: @end deftypefun
4843:
4844: @deftypefun kern_return_t thread_set_exception_port (@w{thread_t @var{thread}}, @w{mach_port_t @var{exception_port}})
4845: The function @code{thread_set_exception_port} is equivalent to the
4846: function @code{thread_set_special_port} with the @var{which_port}
4847: argument set to @code{THREAD_EXCEPTION_PORT}.
4848: @end deftypefun
4849:
4850:
4851: @node Exceptions
4852: @subsection Exceptions
4853:
4854: @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}})
4855: XXX Fixme
4856: @end deftypefun
4857:
4858: @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}})
4859: XXX Fixme
4860: @end deftypefun
4861:
4862: @deftypefun kern_return_t evc_wait (@w{unsigned int @var{event}})
4863: @c XXX This is for user space drivers, the description is incomplete.
4864: The system trap @code{evc_wait} makes the calling thread wait for the
4865: event specified by @var{event}.
4866:
1.1.1.2 root 4867: The call returns @code{KERN_SUCCESS} if the event has occurred,
1.1 root 4868: @code{KERN_NO_SPACE} if another thread is waiting for the same event and
4869: @code{KERN_INVALID_ARGUMENT} if the event object is invalid.
4870: @end deftypefun
4871:
4872:
4873: @node Task Interface
4874: @section Task Interface
4875:
4876: @cindex task port
4877: @cindex port representing a task
4878: @deftp {Data type} task_t
4879: This is a @code{mach_port_t} and used to hold the port name of a task
4880: port that represents the thread. Manipulations of the task are
4881: implemented as remote procedure calls to the task port. A task can get
4882: a port to itself with the @code{mach_task_self} system call.
4883:
4884: The task port name is also used to identify the task's IPC space
4885: (@pxref{Port Manipulation Interface}) and the task's virtual memory map
4886: (@pxref{Virtual Memory Interface}).
4887: @end deftp
4888:
4889: @menu
4890: * Task Creation:: Creating tasks.
4891: * Task Termination:: Terminating tasks.
4892: * Task Information:: Informations on tasks.
4893: * Task Execution:: Thread scheduling in a task.
4894: * Task Special Ports:: How to get and set the task's special ports.
4895: * Syscall Emulation:: How to emulate system calls.
4896: @end menu
4897:
4898:
4899: @node Task Creation
4900: @subsection Task Creation
4901:
4902: @deftypefun kern_return_t task_create (@w{task_t @var{parent_task}}, @w{boolean_t @var{inherit_memory}}, @w{task_t *@var{child_task}})
4903: The function @code{task_create} creates a new task from
4904: @var{parent_task}; the resulting task (@var{child_task}) acquires shared
4905: or copied parts of the parent's address space (see @code{vm_inherit}).
4906: The child task initially contains no threads.
4907:
4908: If @var{inherit_memory} is set, the child task's address space is built
4909: from the parent task according to its memory inheritance values;
4910: otherwise, the child task is given an empty address space.
4911:
4912: The child task gets the three special ports created or copied for it at
4913: task creation. The @code{TASK_KERNEL_PORT} is created and send rights
4914: for it are given to the child and returned to the caller.
4915: @c The following is only relevant if MACH_IPC_COMPAT is used.
4916: @c The @code{TASK_NOTIFY_PORT} is created and receive, ownership and send rights
4917: @c for it are given to the child. The caller has no access to it.
4918: The @code{TASK_BOOTSTRAP_PORT} and the @code{TASK_EXCEPTION_PORT} are
4919: inherited from the parent task. The new task can get send rights to
4920: these ports with the call @code{task_get_special_port}.
4921:
4922: The function returns @code{KERN_SUCCESS} if a new task has been created,
4923: @code{KERN_INVALID_ARGUMENT} if @var{parent_task} is not a valid task
4924: port and @code{KERN_RESOURCE_SHORTAGE} if some critical kernel resource
4925: is unavailable.
4926: @end deftypefun
4927:
4928:
4929: @node Task Termination
4930: @subsection Task Termination
4931:
4932: @deftypefun kern_return_t task_terminate (@w{task_t @var{target_task}})
4933: The function @code{task_terminate} destroys the task specified by
4934: @var{target_task} and all its threads. All resources that are used only
4935: by this task are freed. Any port to which this task has receive and
4936: ownership rights is destroyed.
4937:
4938: The function returns @code{KERN_SUCCESS} if the task has been killed,
4939: @code{KERN_INVALID_ARGUMENT} if @var{target_task} is not a task.
4940: @end deftypefun
4941:
4942:
4943: @node Task Information
4944: @subsection Task Information
4945: @deftypefun task_t mach_task_self ()
4946: The @code{mach_task_self} system call returns the calling thread's task
4947: port.
4948:
4949: @code{mach_task_self} has an effect equivalent to receiving a send right
4950: for the task port. @code{mach_task_self} returns the name of the send
4951: right. In particular, successive calls will increase the calling task's
4952: user-reference count for the send right.
4953:
4954: As a special exception, the kernel will overrun the user reference count
4955: of the task name port, so that this function can not fail for that
4956: reason. Because of this, the user should not deallocate the port right
4957: if an overrun might have happened. Otherwise the reference count could
4958: drop to zero and the send right be destroyed while the user still
4959: expects to be able to use it. As the kernel does not make use of the
4960: number of extant send rights anyway, this is safe to do (the task port
4961: itself is not destroyed, even when there are no send rights anymore).
4962:
1.1.1.2 root 4963: The function returns @code{MACH_PORT_NULL} if a resource shortage
1.1 root 4964: prevented the reception of the send right, @code{MACH_PORT_NULL} if the
4965: task port is currently null, @code{MACH_PORT_DEAD} if the task port is
4966: currently dead.
4967: @end deftypefun
4968:
4969: @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}})
4970: The function @code{task_threads} gets send rights to the kernel port for
4971: each thread contained in @var{target_task}. @var{thread_list} is an
4972: array that is created as a result of this call. The caller may wish to
4973: @code{vm_deallocate} this array when the data is no longer needed.
4974:
4975: The function returns @code{KERN_SUCCESS} if the call succeeded and
4976: @code{KERN_INVALID_ARGUMENT} if @var{target_task} is not a task.
4977: @end deftypefun
4978:
4979: @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}})
4980: The function @code{task_info} returns the selected information array for
4981: a task, as specified by @var{flavor}. @var{task_info} is an array of
4982: integers that is supplied by the caller, and filled with specified
4983: information. @var{task_info_count} is supplied as the maximum number of
4984: integers in @var{task_info}. On return, it contains the actual number
4985: of integers in @var{task_info}. The maximum number of integers returned
4986: by any flavor is @code{TASK_INFO_MAX}.
4987:
4988: The type of information returned is defined by @var{flavor}, which can
4989: be one of the following:
4990:
4991: @table @code
4992: @item TASK_BASIC_INFO
4993: The function returns basic information about the task, as defined by
4994: @code{task_basic_info_t}. This includes the user and system time and
4995: memory consumption. The number of integers returned is
4996: @code{TASK_BASIC_INFO_COUNT}.
4997:
4998: @item TASK_EVENTS_INFO
4999: The function returns information about events for the task as defined by
5000: @code{thread_sched_info_t}. This includes statistics about virtual
5001: memory and IPC events like pageouts, pageins and messages sent and
5002: received. The number of integers returned is
5003: @code{TASK_EVENTS_INFO_COUNT}.
5004:
5005: @item TASK_THREAD_TIMES_INFO
5006: The function returns information about the total time for live threads
5007: as defined by @code{task_thread_times_info_t}. The number of integers
5008: returned is @code{TASK_THREAD_TIMES_INFO_COUNT}.
5009: @end table
5010:
5011: The function returns @code{KERN_SUCCESS} if the call succeeded and
5012: @code{KERN_INVALID_ARGUMENT} if @var{target_task} is not a thread or
5013: @var{flavor} is not recognized. The function returns
5014: @code{MIG_ARRAY_TOO_LARGE} if the returned info array is too large for
5015: @var{task_info}. In this case, @var{task_info} is filled as much as
5016: possible and @var{task_infoCnt} is set to the number of elements that
5017: would have been returned if there were enough room.
5018: @end deftypefun
5019:
5020: @deftp {Data type} {struct task_basic_info}
5021: This structure is returned in @var{task_info} by the @code{task_info}
5022: function and provides basic information about the task. You can cast a
5023: variable of type @code{task_info_t} to a pointer of this type if you
5024: provided it as the @var{task_info} parameter for the
5025: @code{TASK_BASIC_INFO} flavor of @code{task_info}. It has the following
5026: members:
5027:
5028: @table @code
5029: @item integer_t suspend_count
5030: suspend count for task
5031:
5032: @item integer_t base_priority
5033: base scheduling priority
5034:
5035: @item vm_size_t virtual_size
5036: number of virtual pages
5037:
5038: @item vm_size_t resident_size
5039: number of resident pages
5040:
5041: @item time_value_t user_time
5042: total user run time for terminated threads
5043:
5044: @item time_value_t system_time
5045: total system run time for terminated threads
5046:
5047: @item time_value_t creation_time
5048: creation time stamp
5049: @end table
5050: @end deftp
5051:
5052: @deftp {Data type} task_basic_info_t
5053: This is a pointer to a @code{struct task_basic_info}.
5054: @end deftp
5055:
5056: @deftp {Data type} {struct task_events_info}
5057: This structure is returned in @var{task_info} by the @code{task_info}
5058: function and provides event statistics for the task. You can cast a
5059: variable of type @code{task_info_t} to a pointer of this type if you
5060: provided it as the @var{task_info} parameter for the
5061: @code{TASK_EVENTS_INFO} flavor of @code{task_info}. It has the
5062: following members:
5063:
5064: @table @code
5065: @item natural_t faults
5066: number of page faults
5067:
5068: @item natural_t zero_fills
5069: number of zero fill pages
5070:
5071: @item natural_t reactivations
5072: number of reactivated pages
5073:
5074: @item natural_t pageins
5075: number of actual pageins
5076:
5077: @item natural_t cow_faults
5078: number of copy-on-write faults
5079:
5080: @item natural_t messages_sent
5081: number of messages sent
5082:
5083: @item natural_t messages_received
5084: number of messages received
5085: @end table
5086: @end deftp
5087:
5088: @deftp {Data type} task_events_info_t
5089: This is a pointer to a @code{struct task_events_info}.
5090: @end deftp
5091:
5092: @deftp {Data type} {struct task_thread_times_info}
5093: This structure is returned in @var{task_info} by the @code{task_info}
5094: function and provides event statistics for the task. You can cast a
5095: variable of type @code{task_info_t} to a pointer of this type if you
5096: provided it as the @var{task_info} parameter for the
5097: @code{TASK_THREAD_TIMES_INFO} flavor of @code{task_info}. It has the
5098: following members:
5099:
5100: @table @code
5101: @item time_value_t user_time
5102: total user run time for live threads
5103:
5104: @item time_value_t system_time
5105: total system run time for live threads
5106: @end table
5107: @end deftp
5108:
5109: @deftp {Data type} task_thread_times_info_t
5110: This is a pointer to a @code{struct task_thread_times_info}.
5111: @end deftp
5112:
1.1.1.3 root 5113: @deftypefun kern_return_t task_set_name (@w{task_t @var{target_task}}, @w{kernel_debug_name_t @var{name}})
5114:
5115: The function @code{task_set_name} sets the name of @var{target_task}
5116: to @var{name}, truncating it if necessary.
5117:
5118: This is a debugging aid. The name is used in diagnostic messages
5119: printed by the kernel.
5120:
5121: The function returns @code{KERN_SUCCESS} if the call succeeded.
5122: @end deftypefun
5123:
1.1 root 5124:
5125: @node Task Execution
5126: @subsection Task Execution
5127:
5128: @deftypefun kern_return_t task_suspend (@w{task_t @var{target_task}})
5129: The function @code{task_suspend} increments the task's suspend count and
5130: stops all threads in the task. As long as the suspend count is positive
5131: newly created threads will not run. This call does not return until all
5132: threads are suspended.
5133:
5134: The count may become greater than one, with the effect that it will take
5135: more than one resume call to restart the task.
5136:
5137: The function returns @code{KERN_SUCCESS} if the task has been suspended
5138: and @code{KERN_INVALID_ARGUMENT} if @var{target_task} is not a task.
5139: @end deftypefun
5140:
5141: @deftypefun kern_return_t task_resume (@w{task_t @var{target_task}})
5142: The function @code{task_resume} decrements the task's suspend count. If
5143: it becomes zero, all threads with zero suspend counts in the task are
5144: resumed. The count may not become negative.
5145:
5146: The function returns @code{KERN_SUCCESS} if the task has been resumed,
5147: @code{KERN_FAILURE} if the suspend count is already at zero and
5148: @code{KERN_INVALID_ARGUMENT} if @var{target_task} is not a task.
5149: @end deftypefun
5150:
5151: @c XXX Should probably be in the "Scheduling" node of the Thread Interface.
5152: @deftypefun kern_return_t task_priority (@w{task_t @var{task}}, @w{int @var{priority}}, @w{boolean_t @var{change_threads}})
5153: The priority of a task is used only for creation of new threads; a new
5154: thread's priority is set to the enclosing task's priority.
5155: @code{task_priority} changes this task priority. It also sets the
5156: priorities of all threads in the task to this new priority if
5157: @var{change_threads} is @code{TRUE}. Existing threads are not affected
5158: otherwise. If this priority change violates the maximum priority of
5159: some threads, as many threads as possible will be changed and an error
5160: code will be returned.
5161:
5162: The function returns @code{KERN_SUCCESS} if the call succeeded,
5163: @code{KERN_INVALID_ARGUMENT} if @var{task} is not a task, or
5164: @var{priority} is not a valid priority and @code{KERN_FAILURE} if
5165: @var{change_threads} was @code{TRUE} and the attempt to change the
5166: priority of at least one existing thread failed because the new priority
5167: would have exceeded that thread's maximum priority.
5168: @end deftypefun
5169:
5170: @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}})
5171: The function @code{task_ras_control} manipulates a task's set of
5172: restartable atomic sequences. If a sequence is installed, and any
5173: thread in the task is preempted within the range
5174: [@var{start_pc},@var{end_pc}], then the thread is resumed at
5175: @var{start_pc}. This enables applications to build atomic sequences
5176: which, when executed to completion, will have executed atomically.
5177: Restartable atomic sequences are intended to be used on systems that do
5178: not have hardware support for low-overhead atomic primitives.
5179:
5180: As a thread can be rolled-back, the code in the sequence should have no
5181: side effects other than a final store at @var{end_pc}. The kernel does
5182: not guarantee that the sequence is restartable. It assumes the
5183: application knows what it's doing.
5184:
5185: A task may have a finite number of atomic sequences that is defined at
5186: compile time.
5187:
1.1.1.2 root 5188: The flavor specifies the particular operation that should be applied to
1.1 root 5189: this restartable atomic sequence. Possible values for flavor can be:
5190:
5191: @table @code
5192: @item TASK_RAS_CONTROL_PURGE_ALL
5193: Remove all registered sequences for this task.
5194:
5195: @item TASK_RAS_CONTROL_PURGE_ONE
5196: Remove the named registered sequence for this task.
5197:
5198: @item TASK_RAS_CONTROL_PURGE_ALL_AND_INSTALL_ONE
5199: Atomically remove all registered sequences and install the named
5200: sequence.
5201:
5202: @item TASK_RAS_CONTROL_INSTALL_ONE
5203: Install this sequence.
5204: @end table
5205:
5206: The function returns @code{KERN_SUCCESS} if the operation has been
5207: performed, @code{KERN_INVALID_ADDRESS} if the @var{start_pc} or
5208: @var{end_pc} values are not a valid address for the requested operation
5209: (for example, it is invalid to purge a sequence that has not been
5210: registered), @code{KERN_RESOURCE_SHORTAGE} if an attempt was made to
5211: install more restartable atomic sequences for a task than can be
5212: supported by the kernel, @code{KERN_INVALID_VALUE} if a bad flavor was
5213: specified, @code{KERN_INVALID_ARGUMENT} if @var{target_task} is not a
5214: task and @code{KERN_FAILURE} if the call is not not supported on this
5215: configuration.
5216: @end deftypefun
5217:
5218:
5219: @node Task Special Ports
5220: @subsection Task Special Ports
5221:
5222: @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}})
5223: The function @code{task_get_special_port} returns send rights to one of
5224: a set of special ports for the task specified by @var{task}.
5225:
5226: The special ports associated with a task are the kernel port
5227: (@code{TASK_KERNEL_PORT}), the bootstrap port
5228: (@code{TASK_BOOTSTRAP_PORT}) and the exception port
5229: (@code{TASK_EXCEPTION_PORT}). The bootstrap port is a port to which a
5230: task may send a message requesting other system service ports. This
5231: port is not used by the kernel. The task's exception port is the port
5232: to which messages are sent by the kernel when an exception occurs and
5233: the thread causing the exception has no exception port of its own.
5234:
5235: The following macros to call @code{task_get_special_port} for a specific
5236: port are defined in @code{mach/task_special_ports.h}:
5237: @code{task_get_exception_port} and @code{task_get_bootstrap_port}.
5238:
5239: The function returns @code{KERN_SUCCESS} if the port was returned and
5240: @code{KERN_INVALID_ARGUMENT} if @var{task} is not a task or
5241: @var{which_port} is an invalid port selector.
5242: @end deftypefun
5243:
5244: @deftypefun kern_return_t task_get_kernel_port (@w{task_t @var{task}}, @w{mach_port_t *@var{kernel_port}})
5245: The function @code{task_get_kernel_port} is equivalent to the function
5246: @code{task_get_special_port} with the @var{which_port} argument set to
5247: @code{TASK_KERNEL_PORT}.
5248: @end deftypefun
5249:
5250: @deftypefun kern_return_t task_get_exception_port (@w{task_t @var{task}}, @w{mach_port_t *@var{exception_port}})
5251: The function @code{task_get_exception_port} is equivalent to the
5252: function @code{task_get_special_port} with the @var{which_port} argument
5253: set to @code{TASK_EXCEPTION_PORT}.
5254: @end deftypefun
5255:
5256: @deftypefun kern_return_t task_get_bootstrap_port (@w{task_t @var{task}}, @w{mach_port_t *@var{bootstrap_port}})
5257: The function @code{task_get_bootstrap_port} is equivalent to the
5258: function @code{task_get_special_port} with the @var{which_port} argument
5259: set to @code{TASK_BOOTSTRAP_PORT}.
5260: @end deftypefun
5261:
5262: @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}})
5263: The function @code{thread_set_special_port} sets one of a set of special
5264: ports for the task specified by @var{task}.
5265:
5266: The special ports associated with a task are the kernel port
5267: (@code{TASK_KERNEL_PORT}), the bootstrap port
5268: (@code{TASK_BOOTSTRAP_PORT}) and the exception port
5269: (@code{TASK_EXCEPTION_PORT}). The bootstrap port is a port to which a
5270: thread may send a message requesting other system service ports. This
5271: port is not used by the kernel. The task's exception port is the port
5272: to which messages are sent by the kernel when an exception occurs and
5273: the thread causing the exception has no exception port of its own.
5274:
5275: The function returns @code{KERN_SUCCESS} if the port was set and
5276: @code{KERN_INVALID_ARGUMENT} if @var{task} is not a task or
5277: @var{which_port} is an invalid port selector.
5278: @end deftypefun
5279:
5280: @deftypefun kern_return_t task_set_kernel_port (@w{task_t @var{task}}, @w{mach_port_t @var{kernel_port}})
5281: The function @code{task_set_kernel_port} is equivalent to the function
5282: @code{task_set_special_port} with the @var{which_port} argument set to
5283: @code{TASK_KERNEL_PORT}.
5284: @end deftypefun
5285:
5286: @deftypefun kern_return_t task_set_exception_port (@w{task_t @var{task}}, @w{mach_port_t @var{exception_port}})
5287: The function @code{task_set_exception_port} is equivalent to the
5288: function @code{task_set_special_port} with the @var{which_port} argument
5289: set to @code{TASK_EXCEPTION_PORT}.
5290: @end deftypefun
5291:
5292: @deftypefun kern_return_t task_set_bootstrap_port (@w{task_t @var{task}}, @w{mach_port_t @var{bootstrap_port}})
5293: The function @code{task_set_bootstrap_port} is equivalent to the
5294: function @code{task_set_special_port} with the @var{which_port} argument
5295: set to @code{TASK_BOOTSTRAP_PORT}.
5296: @end deftypefun
5297:
5298:
5299: @node Syscall Emulation
5300: @subsection Syscall Emulation
5301:
5302: @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}})
5303: The function @code{task_get_emulation_vector} gets the user-level
5304: handler entry points for all emulated system calls.
5305: @c XXX Fixme
5306: @end deftypefun
5307:
5308: @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}})
5309: The function @code{task_set_emulation_vector} establishes user-level
5310: handlers for the specified system calls. Non-emulated system calls are
5311: specified with an entry of @code{EML_ROUTINE_NULL}. System call
1.1.1.2 root 5312: emulation handlers are inherited by the children of @var{task}.
1.1 root 5313: @c XXX Fixme
5314: @end deftypefun
5315:
5316: @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}})
5317: The function @code{task_set_emulation} establishes a user-level handler
5318: for the specified system call. System call emulation handlers are
1.1.1.2 root 5319: inherited by the children of @var{task}.
1.1 root 5320: @c XXX Fixme
5321: @end deftypefun
5322:
5323: @c XXX Fixme datatype emulation_vector_t
5324:
5325:
5326: @node Profiling
5327: @section Profiling
5328:
5329: @deftypefun kern_return_t task_enable_pc_sampling (@w{task_t @var{task}}, @w{int *@var{ticks}}, @w{sampled_pc_flavor_t @var{flavor}})
5330: @deftypefunx kern_return_t thread_enable_pc_sampling (@w{thread_t @var{thread}}, @w{int *@var{ticks}}, @w{sampled_pc_flavor_t @var{flavor}})
5331: The function @code{task_enable_pc_sampling} enables PC sampling for
5332: @var{task}, the function @code{thread_enable_pc_sampling} enables PC
5333: sampling for @var{thread}. The kernel's idea of clock granularity is
5334: returned in @var{ticks} in usecs. (this value should not be trusted). The
5335: sampling flavor is specified by @var{flavor}.
5336:
5337: The function returns @code{KERN_SUCCESS} if the operation is completed successfully
5338: and @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a valid thread.
5339: @end deftypefun
5340:
5341: @deftypefun kern_return_t task_disable_pc_sampling (@w{task_t @var{task}}, @w{int *@var{sample_count}})
5342: @deftypefunx kern_return_t thread_disable_pc_sampling (@w{thread_t @var{thread}}, @w{int *@var{sample_count}})
5343: The function @code{task_disable_pc_sampling} disables PC sampling for
5344: @var{task}, the function @code{thread_disable_pc_sampling} disables PC
5345: sampling for @var{thread}. The number of sample elements in the kernel
5346: for the thread is returned in @var{sample_count}.
5347:
5348: The function returns @code{KERN_SUCCESS} if the operation is completed successfully
5349: and @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a valid thread.
5350: @end deftypefun
5351:
5352: @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}})
5353: @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}})
5354: The function @code{task_get_sampled_pcs} extracts the PC samples for
5355: @var{task}, the function @code{thread_get_sampled_pcs} extracts the PC
5356: samples for @var{thread}. @var{seqno} is the sequence number of the
5357: sampled PCs. This is useful for determining when a collector thread has
5358: missed a sample. The sampled PCs for the thread are returned in
5359: @var{sampled_pcs}. @var{sample_count} contains the number of sample
5360: elements returned.
5361:
5362: The function returns @code{KERN_SUCCESS} if the operation is completed successfully,
5363: @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a valid thread and
5364: @code{KERN_FAILURE} if @var{thread} is not sampled.
5365: @end deftypefun
5366:
5367:
5368: @deftp {Data type} sampled_pc_t
5369: This structure is returned in @var{sampled_pcs} by the
5370: @code{thread_get_sampled_pcs} and @code{task_get_sampled_pcs} functions
5371: and provides pc samples for threads or tasks. It has the following
5372: members:
5373:
5374: @table @code
5375: @item natural_t id
5376: A thread-specific unique identifier.
5377:
5378: @item vm_offset_t pc
5379: A pc value.
5380:
5381: @item sampled_pc_flavor_t sampletype
5382: The type of the sample as per flavor.
5383: @end table
5384: @end deftp
5385:
5386:
5387: @deftp {Data type} sampled_pc_flavor_t
5388: This data type specifies a pc sample flavor, either as argument passed
5389: in @var{flavor} to the @code{thread_enable_pc_sample} and
5390: @code{thread_disable_pc_sample} functions, or as member
5391: @code{sampletype} in the @code{sample_pc_t} data type. The flavor is a
5392: bitwise-or of the possible flavors defined in @file{mach/pc_sample.h}:
5393:
5394: @table @code
5395: @item SAMPLED_PC_PERIODIC
5396: default
5397: @item SAMPLED_PC_VM_ZFILL_FAULTS
5398: zero filled fault
5399: @item SAMPLED_PC_VM_REACTIVATION_FAULTS
5400: reactivation fault
5401: @item SAMPLED_PC_VM_PAGEIN_FAULTS
5402: pagein fault
5403: @item SAMPLED_PC_VM_COW_FAULTS
5404: copy-on-write fault
5405: @item SAMPLED_PC_VM_FAULTS_ANY
5406: any fault
5407: @item SAMPLED_PC_VM_FAULTS
5408: the bitwise-or of @code{SAMPLED_PC_VM_ZFILL_FAULTS},
5409: @code{SAMPLED_PC_VM_REACTIVATION_FAULTS},
5410: @code{SAMPLED_PC_VM_PAGEIN_FAULTS} and @code{SAMPLED_PC_VM_COW_FAULTS}.
5411: @end table
5412: @end deftp
5413:
5414: @c XXX sampled_pc_array_t, sampled_pc_seqno_t
5415:
5416:
5417: @node Host Interface
5418: @chapter Host Interface
5419: @cindex host interface
5420:
5421: This section describes the Mach interface to a host executing a Mach
5422: kernel. The interface allows to query statistics about a host and
5423: control its behaviour.
5424:
5425: A host is represented by two ports, a name port @var{host} used to query
5426: information about the host accessible to everyone, and a control port
5427: @var{host_priv} used to manipulate it. For example, you can query the
5428: current time using the name port, but to change the time you need to
5429: send a message to the host control port.
5430:
5431: Everything described in this section is declared in the header file
5432: @file{mach.h}.
5433:
5434: @menu
5435: * Host Ports:: Ports representing a host.
5436: * Host Information:: Retrieval of information about a host.
5437: * Host Time:: Operations on the time as seen by a host.
5438: * Host Reboot:: Rebooting the system.
5439: @end menu
5440:
5441:
5442: @node Host Ports
5443: @section Host Ports
5444: @cindex host ports
5445: @cindex ports representing a host
5446:
5447: @cindex host name port
5448: @deftp {Data type} host_t
5449: This is a @code{mach_port_t} and used to hold the port name of a host
5450: name port (or short: host port). Any task can get a send right to the
5451: name port of the host running the task using the @code{mach_host_self}
5452: system call. The name port can be used query information about the
5453: host, for example the current time.
5454: @end deftp
5455:
5456: @deftypefun host_t mach_host_self ()
5457: The @code{mach_host_self} system call returns the calling thread's host
5458: name port. It has an effect equivalent to receiving a send right for
5459: the host port. @code{mach_host_self} returns the name of the send
5460: right. In particular, successive calls will increase the calling task's
5461: user-reference count for the send right.
5462:
5463: As a special exception, the kernel will overrun the user reference count
5464: of the host name port, so that this function can not fail for that
5465: reason. Because of this, the user should not deallocate the port right
5466: if an overrun might have happened. Otherwise the reference count could
5467: drop to zero and the send right be destroyed while the user still
5468: expects to be able to use it. As the kernel does not make use of the
5469: number of extant send rights anyway, this is safe to do (the host port
5470: itself is never destroyed).
5471:
5472: The function returns @code{MACH_PORT_NULL} if a resource shortage
5473: prevented the reception of the send right.
5474:
5475: This function is also available in @file{mach/mach_traps.h}.
5476: @end deftypefun
5477:
5478: @cindex host control port
5479: @deftp {Data type} host_priv_t
5480: This is a @code{mach_port_t} and used to hold the port name of a
5481: privileged host control port. A send right to the host control port is
5482: inserted into the first task at bootstrap (@pxref{Modules}). This is
5483: the only way to get access to the host control port in Mach, so the
5484: initial task has to preserve the send right carefully, moving a copy of
5485: it to other privileged tasks if necessary and denying access to
5486: unprivileged tasks.
5487: @end deftp
5488:
5489:
5490: @node Host Information
5491: @section Host Information
5492:
5493: @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}})
5494: The @code{host_info} function returns various information about
5495: @var{host}. @var{host_info} is an array of integers that is supplied by
5496: the caller. It will be filled with the requested information.
5497: @var{host_info_count} is supplied as the maximum number of integers in
5498: @var{host_info}. On return, it contains the actual number of integers
5499: in @var{host_info}. The maximum number of integers returned by any
5500: flavor is @code{HOST_INFO_MAX}.
5501:
5502: The type of information returned is defined by @var{flavor}, which can
5503: be one of the following:
5504:
5505: @table @code
5506: @item HOST_BASIC_INFO
5507: The function returns basic information about the host, as defined by
5508: @code{host_basic_info_t}. This includes the number of processors, their
5509: type, and the amount of memory installed in the system. The number of
5510: integers returned is @code{HOST_BASIC_INFO_COUNT}. For how to get more
5511: information about the processor, see @ref{Processor Interface}.
5512:
5513: @item HOST_PROCESSOR_SLOTS
5514: The function returns the numbers of the slots with active processors in
5515: them. The number of integers returned can be up to @code{max_cpus}, as
5516: returned by the @code{HOST_BASIC_INFO} flavor of @code{host_info}.
5517:
5518: @item HOST_SCHED_INFO
5519: The function returns information of interest to schedulers as defined by
5520: @code{host_sched_info_t}. The number of integers returned is
5521: @code{HOST_SCHED_INFO_COUNT}.
5522: @end table
5523:
5524: The function returns @code{KERN_SUCCESS} if the call succeeded and
5525: @code{KERN_INVALID_ARGUMENT} if @var{host} is not a host or @var{flavor}
5526: is not recognized. The function returns @code{MIG_ARRAY_TOO_LARGE} if
5527: the returned info array is too large for @var{host_info}. In this case,
5528: @var{host_info} is filled as much as possible and @var{host_info_count}
5529: is set to the number of elements that would be returned if there were
5530: enough room.
5531: @c BUGS Availability limited. Systems without this call support a
5532: @c host_info call with an incompatible calling sequence.
5533: @end deftypefun
5534:
5535: @deftp {Data type} {struct host_basic_info}
5536: A pointer to this structure is returned in @var{host_info} by the
5537: @code{host_info} function and provides basic information about the host.
5538: You can cast a variable of type @code{host_info_t} to a pointer of this
5539: type if you provided it as the @var{host_info} parameter for the
5540: @code{HOST_BASIC_INFO} flavor of @code{host_info}. It has the following
5541: members:
5542:
5543: @table @code
5544: @item int max_cpus
5545: The maximum number of possible processors for which the kernel is
5546: configured.
5547:
5548: @item int avail_cpus
5549: The number of cpus currently available.
5550:
5551: @item vm_size_t memory_size
5552: The size of physical memory in bytes.
5553:
5554: @item cpu_type_t cpu_type
5555: The type of the master processor.
5556:
5557: @item cpu_subtype_t cpu_subtype
5558: The subtype of the master processor.
5559: @end table
5560:
5561: The type and subtype of the individual processors are also available
5562: by @code{processor_info}, see @ref{Processor Interface}.
5563: @end deftp
5564:
5565: @deftp {Data type} host_basic_info_t
5566: This is a pointer to a @code{struct host_basic_info}.
5567: @end deftp
5568:
5569: @deftp {Data type} {struct host_sched_info}
5570: A pointer to this structure is returned in @var{host_info} by the
5571: @code{host_info} function and provides information of interest to
5572: schedulers. You can cast a variable of type @code{host_info_t} to a
5573: pointer of this type if you provided it as the @var{host_info} parameter
5574: for the @code{HOST_SCHED_INFO} flavor of @code{host_info}. It has the
5575: following members:
5576:
5577: @table @code
5578: @item int min_timeout
5579: The minimum timeout and unit of time in milliseconds.
5580:
5581: @item int min_quantum
5582: The minimum quantum and unit of quantum in milliseconds.
5583: @end table
5584: @end deftp
5585:
5586: @deftp {Data type} host_sched_info_t
5587: This is a pointer to a @code{struct host_sched_info}.
5588: @end deftp
5589:
5590: @deftypefun kern_return_t host_kernel_version (@w{host_t @var{host}}, @w{kernel_version_t *@var{version}})
5591: The @code{host_kernel_version} function returns the version string
5592: compiled into the kernel executing on @var{host} at the time it was
5593: built in the character string @var{version}. This string describes the
5594: version of the kernel. The constant @code{KERNEL_VERSION_MAX} should be
5595: used to dimension storage for the returned string if the
5596: @code{kernel_version_t} declaration is not used.
5597:
5598: If the version string compiled into the kernel is longer than
5599: @code{KERNEL_VERSION_MAX}, the result is truncated and not necessarily
5600: null-terminated.
5601:
5602: If @var{host} is not a valid send right to a host port, the function
5603: returns @code{KERN_INVALID_ARGUMENT}. If @var{version} points to
5604: inaccessible memory, it returns @code{KERN_INVALID_ADDRESS}, and
5605: @code{KERN_SUCCESS} otherwise.
5606: @end deftypefun
5607:
5608: @deftypefun kern_return_t host_get_boot_info (@w{host_priv_t @var{host_priv}}, @w{kernel_boot_info_t @var{boot_info}})
5609: The @code{host_get_boot_info} function returns the boot-time information
5610: string supplied by the operator to the kernel executing on
5611: @var{host_priv} in the character string @var{boot_info}. The constant
5612: @code{KERNEL_BOOT_INFO_MAX} should be used to dimension storage for the
5613: returned string if the @code{kernel_boot_info_t} declaration is not
5614: used.
5615:
5616: If the boot-time information string supplied by the operator is longer
5617: than @code{KERNEL_BOOT_INFO_MAX}, the result is truncated and not
5618: necessarily null-terminated.
5619: @end deftypefun
5620:
5621:
5622: @node Host Time
5623: @section Host Time
5624:
5625: @deftp {Data type} time_value_t
5626: This is the representation of a time in Mach. It is a @code{struct
5627: time_value} and consists of the following members:
5628:
5629: @table @code
5630: @item integer_t seconds
5631: The number of seconds.
5632: @item integer_t microseconds
5633: The number of microseconds.
5634: @end table
5635: @end deftp
5636:
5637: The number of microseconds should always be smaller than
5638: @code{TIME_MICROS_MAX} (100000). A time with this property is
5639: @dfn{normalized}. Normalized time values can be manipulated with the
5640: following macros:
5641:
5642: @defmac time_value_add_usec (@w{time_value_t *@var{val}}, @w{integer_t *@var{micros}})
5643: Add @var{micros} microseconds to @var{val}. If @var{val} is normalized
5644: and @var{micros} smaller than @code{TIME_MICROS_MAX}, @var{val} will be
5645: normalized afterwards.
5646: @end defmac
5647:
5648: @defmac time_value_add (@w{time_value_t *@var{result}}, @w{time_value_t *@var{addend}})
5649: Add the values in @var{addend} to @var{result}. If both are normalized,
5650: @var{result} will be normalized afterwards.
5651: @end defmac
5652:
5653: A variable of type @code{time_value_t} can either represent a duration
5654: or a fixed point in time. In the latter case, it shall be interpreted as
5655: the number of seconds and microseconds after the epoch 1. Jan 1970.
5656:
5657: @deftypefun kern_return_t host_get_time (@w{host_t @var{host}}, @w{time_value_t *@var{current_time}})
5658: Get the current time as seen by @var{host}. On success, the time passed
5659: since the epoch is returned in @var{current_time}.
5660: @end deftypefun
5661:
5662: @deftypefun kern_return_t host_set_time (@w{host_priv_t @var{host_priv}}, @w{time_value_t @var{new_time}})
5663: Set the time of @var{host_priv} to @var{new_time}.
5664: @end deftypefun
5665:
5666: @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}})
5667: Arrange for the current time as seen by @var{host_priv} to be gradually
5668: changed by the adjustment value @var{new_adjustment}, and return the old
5669: adjustment value in @var{old_adjustment}.
5670: @end deftypefun
5671:
5672: For efficiency, the current time is available through a mapped-time
5673: interface.
5674:
5675: @deftp {Data type} mapped_time_value_t
5676: This structure defines the mapped-time interface. It has the following
5677: members:
5678:
5679: @table @code
5680: @item integer_t seconds
5681: The number of seconds.
5682:
5683: @item integer_t microseconds
5684: The number of microseconds.
5685:
5686: @item integer_t check_seconds
5687: This is a copy of the seconds value, which must be checked to protect
5688: against a race condition when reading out the two time values.
5689: @end table
5690: @end deftp
5691:
5692: Here is an example how to read out the current time using the
5693: mapped-time interface:
5694:
5695: @c XXX Complete the example.
5696: @example
5697: do
5698: @{
5699: secs = mtime->seconds;
5700: usecs = mtime->microseconds;
5701: @}
5702: while (secs != mtime->check_seconds);
5703: @end example
5704:
5705:
5706: @node Host Reboot
5707: @section Host Reboot
5708:
5709: @deftypefun kern_return_t host_reboot (@w{host_priv_t @var{host_priv}}, @w{int @var{options}})
5710: Reboot the host specified by @var{host_priv}. The argument
5711: @var{options} specifies the flags. The available flags are defined in
5712: @file{sys/reboot.h}:
5713:
5714: @table @code
5715: @item RB_HALT
5716: Do not reboot, but halt the machine.
5717:
5718: @item RB_DEBUGGER
5719: Do not reboot, but enter kernel debugger from user space.
5720: @end table
5721:
5722: If successful, the function might not return.
5723: @end deftypefun
5724:
5725:
5726: @node Processors and Processor Sets
5727: @chapter Processors and Processor Sets
5728:
5729: This section describes the Mach interface to processor sets and
5730: individual processors. The interface allows to group processors into
5731: sets and control the processors and processor sets.
5732:
5733: A processor is not a central part of the interface. It is mostly of
5734: relevance as a part of a processor set. Threads are always assigned to
5735: processor sets, and all processors in a set are equally involved in
5736: executing all threads assigned to that set.
5737:
5738: The processor set is represented by two ports, a name port
5739: @var{processor_set_name} used to query information about the host
5740: accessible to everyone, and a control port @var{processor_set} used to
5741: manipulate it.
5742:
5743: @menu
5744: * Processor Set Interface:: How to work with processor sets.
5745: * Processor Interface:: How to work with individual processors.
5746: @end menu
5747:
5748:
5749: @node Processor Set Interface
5750: @section Processor Set Interface
5751:
5752: @menu
5753: * Processor Set Ports:: Ports representing a processor set.
5754: * Processor Set Access:: How the processor sets are accessed.
5755: * Processor Set Creation:: How new processor sets are created.
5756: * Processor Set Destruction:: How processor sets are destroyed.
5757: * Tasks and Threads on Sets:: Assigning tasks, threads to processor sets.
5758: * Processor Set Priority:: Specifying the priority of a processor set.
5759: * Processor Set Policy:: Changing the processor set policies.
5760: * Processor Set Info:: Obtaining information about a processor set.
5761: @end menu
5762:
5763:
5764: @node Processor Set Ports
5765: @subsection Processor Set Ports
5766: @cindex processor set ports
5767: @cindex ports representing a processor set
5768:
5769: @cindex processor set name port
5770: @cindex port representing a processor set name
5771: @deftp {Data type} processor_set_name_t
5772: This is a @code{mach_port_t} and used to hold the port name of a
5773: processor set name port that names the processor set. Any task can get
5774: a send right to name port of a processor set. The processor set name
5775: port allows to get information about the processor set.
5776: @end deftp
5777:
5778: @cindex processor set port
5779: @deftp {Data type} processor_set_t
5780: This is a @code{mach_port_t} and used to hold the port name of a
5781: privileged processor set control port that represents the processor set.
5782: Operations on the processor set are implemented as remote procedure
5783: calls to the processor set port. The processor set port allows to
5784: manipulate the processor set.
5785: @end deftp
5786:
5787:
5788: @node Processor Set Access
5789: @subsection Processor Set Access
5790:
5791: @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}})
5792: The function @code{host_processor_sets} gets send rights to the name
5793: port for each processor set currently assigned to @var{host}.
5794:
5795: @code{host_processor_set_priv} can be used to obtain the control ports
5796: from these if desired. @var{processor_sets} is an array that is
5797: created as a result of this call. The caller may wish to
5798: @code{vm_deallocate} this array when the data is no longer needed.
5799: @var{processor_sets_count} is set to the number of processor sets in the
5800: @var{processor_sets}.
5801:
5802: This function returns @code{KERN_SUCCESS} if the call succeeded and
5803: @code{KERN_INVALID_ARGUMENT} if @var{host} is not a host.
5804: @end deftypefun
5805:
5806: @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}})
5807: The function @code{host_processor_set_priv} allows a privileged
5808: application to obtain the control port @var{set} for an existing
5809: processor set from its name port @var{set_name}. The privileged host
5810: port @var{host_priv} is required.
5811:
5812: This function returns @code{KERN_SUCCESS} if the call succeeded and
5813: @code{KERN_INVALID_ARGUMENT} if @var{host_priv} is not a valid host
5814: control port.
5815: @end deftypefun
5816:
5817: @deftypefun kern_return_t processor_set_default (@w{host_t @var{host}}, @w{processor_set_name_t *@var{default_set}})
5818: The function @code{processor_set_default} returns the default processor
5819: set of @var{host} in @var{default_set}. The default processor set is
5820: used by all threads, tasks, and processors that are not explicitly
5821: assigned to other sets. processor_set_default returns a port that can
5822: be used to obtain information about this set (e.g. how many threads are
5823: assigned to it). This port cannot be used to perform operations on that
5824: set.
5825:
5826: This function returns @code{KERN_SUCCESS} if the call succeeded,
5827: @code{KERN_INVALID_ARGUMENT} if @var{host} is not a host and
5828: @code{KERN_INVALID_ADDRESS} if @var{default_set} points to
5829: inaccessible memory.
5830: @end deftypefun
5831:
5832:
5833: @node Processor Set Creation
5834: @subsection Processor Set Creation
5835:
5836: @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}})
5837: The function @code{processor_set_create} creates a new processor set on
5838: @var{host} and returns the two ports associated with it. The port
5839: returned in @var{new_set} is the actual port representing the set. It
5840: is used to perform operations such as assigning processors, tasks, or
5841: threads. The port returned in @var{new_name} identifies the set, and is
5842: used to obtain information about the set.
5843:
5844: This function returns @code{KERN_SUCCESS} if the call succeeded,
5845: @code{KERN_INVALID_ARGUMENT} if @var{host} is not a host,
5846: @code{KERN_INVALID_ADDRESS} if @var{new_set} or @var{new_name} points to
5847: inaccessible memory and @code{KERN_FAILURE} is the operating system does
5848: not support processor allocation.
5849: @end deftypefun
5850:
5851:
5852: @node Processor Set Destruction
5853: @subsection Processor Set Destruction
5854:
5855: @deftypefun kern_return_t processor_set_destroy (@w{processor_set_t @var{processor_set}})
5856: The function @code{processor_set_destroy} destroys the specified
5857: processor set. Any assigned processors, tasks, or threads are
5858: reassigned to the default set. The object port for the processor set is
5859: required (not the name port). The default processor set cannot be
5860: destroyed.
5861:
5862: This function returns @code{KERN_SUCCESS} if the set was destroyed,
5863: @code{KERN_FAILURE} if an attempt was made to destroy the default
5864: processor set, or the operating system does not support processor
5865: allocation, and @code{KERN_INVALID_ARGUMENT} if @var{processor_set} is
5866: not a valid processor set control port.
5867: @end deftypefun
5868:
5869:
5870: @node Tasks and Threads on Sets
5871: @subsection Tasks and Threads on Sets
5872:
5873: @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}})
5874: The function @code{processor_set_tasks} gets send rights to the kernel
5875: port for each task currently assigned to @var{processor_set}.
5876:
5877: @var{task_list} is an array that is created as a result of this call.
5878: The caller may wish to @code{vm_deallocate} this array when the data is
5879: no longer needed. @var{task_count} is set to the number of tasks in the
5880: @var{task_list}.
5881:
5882: This function returns @code{KERN_SUCCESS} if the call succeeded and
5883: @code{KERN_INVALID_ARGUMENT} if @var{processor_set} is not a processor
5884: set.
5885: @end deftypefun
5886:
5887: @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}})
5888: The function @code{processor_set_thread} gets send rights to the kernel
5889: port for each thread currently assigned to @var{processor_set}.
5890:
5891: @var{thread_list} is an array that is created as a result of this call.
5892: The caller may wish to @code{vm_deallocate} this array when the data is
5893: no longer needed. @var{thread_count} is set to the number of threads in
5894: the @var{thread_list}.
5895:
5896: This function returns @code{KERN_SUCCESS} if the call succeeded and
5897: @code{KERN_INVALID_ARGUMENT} if @var{processor_set} is not a processor
5898: set.
5899: @end deftypefun
5900:
5901: @deftypefun kern_return_t task_assign (@w{task_t @var{task}}, @w{processor_set_t @var{processor_set}}, @w{boolean_t @var{assign_threads}})
5902: The function @code{task_assign} assigns @var{task} the set
5903: @var{processor_set}. This assignment is for the purposes of determining
5904: the initial assignment of newly created threads in task. Any previous
5905: assignment of the task is nullified. Existing threads within the task
5906: are also reassigned if @var{assign_threads} is @code{TRUE}. They are
5907: not affected if it is @code{FALSE}.
5908:
5909: This function returns @code{KERN_SUCCESS} if the assignment has been
5910: performed and @code{KERN_INVALID_ARGUMENT} if @var{task} is not a task,
5911: or @var{processor_set} is not a processor set on the same host as
5912: @var{task}.
5913: @end deftypefun
5914:
5915: @deftypefun kern_return_t task_assign_default (@w{task_t @var{task}}, @w{boolean_t @var{assign_threads}})
5916: The function @code{task_assign_default} is a variant of
5917: @code{task_assign} that assigns the task to the default processor set on
5918: that task's host. This variant exists because the control port for the
1.1.1.2 root 5919: default processor set is privileged and not usually available to users.
1.1 root 5920:
5921: This function returns @code{KERN_SUCCESS} if the assignment has been
5922: performed and @code{KERN_INVALID_ARGUMENT} if @var{task} is not a task.
5923: @end deftypefun
5924:
5925: @deftypefun kern_return_t task_get_assignment (@w{task_t @var{task}}, @w{processor_set_name_t *@var{assigned_set}})
5926: The function @code{task_get_assignment} returns the name of the
5927: processor set to which the thread is currently assigned in
5928: @var{assigned_set}. This port can only be used to obtain information
5929: about the processor set.
5930:
5931: This function returns @code{KERN_SUCCESS} if the assignment has been
5932: performed, @code{KERN_INVALID_ADDRESS} if @var{processor_set} points to
5933: inaccessible memory, and @code{KERN_INVALID_ARGUMENT} if @var{task} is
5934: not a task.
5935: @end deftypefun
5936:
5937: @deftypefun kern_return_t thread_assign (@w{thread_t @var{thread}}, @w{processor_set_t @var{processor_set}})
5938: The function @code{thread_assign} assigns @var{thread} the set
5939: @var{processor_set}. After the assignment is completed, the thread only
5940: executes on processors assigned to the designated processor set. If
5941: there are no such processors, then the thread is unable to execute. Any
5942: previous assignment of the thread is nullified. Unix system call
5943: compatibility code may temporarily force threads to execute on the
5944: master processor.
5945:
5946: This function returns @code{KERN_SUCCESS} if the assignment has been
5947: performed and @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a
5948: thread, or @var{processor_set} is not a processor set on the same host
5949: as @var{thread}.
5950: @end deftypefun
5951:
5952: @deftypefun kern_return_t thread_assign_default (@w{thread_t @var{thread}})
5953: The function @code{thread_assign_default} is a variant of
5954: @code{thread_assign} that assigns the thread to the default processor
5955: set on that thread's host. This variant exists because the control port
1.1.1.2 root 5956: for the default processor set is privileged and not usually available
1.1 root 5957: to users.
5958:
5959: This function returns @code{KERN_SUCCESS} if the assignment has been
5960: performed and @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a
5961: thread.
5962: @end deftypefun
5963:
5964: @deftypefun kern_return_t thread_get_assignment (@w{thread_t @var{thread}}, @w{processor_set_name_t *@var{assigned_set}})
5965: The function @code{thread_get_assignment} returns the name of the
5966: processor set to which the thread is currently assigned in
5967: @var{assigned_set}. This port can only be used to obtain information
5968: about the processor set.
5969:
5970: This function returns @code{KERN_SUCCESS} if the assignment has been
5971: performed, @code{KERN_INVALID_ADDRESS} if @var{processor_set} points to
5972: inaccessible memory, and @code{KERN_INVALID_ARGUMENT} if @var{thread} is
5973: not a thread.
5974: @end deftypefun
5975:
5976:
5977: @node Processor Set Priority
5978: @subsection Processor Set Priority
5979:
5980: @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}})
5981: The function @code{processor_set_max_priority} is used to set the
5982: maximum priority for a processor set. The priority of a processor set
5983: is used only for newly created threads (thread's maximum priority is set
5984: to processor set's) and the assignment of threads to the set (thread's
5985: maximum priority is reduced if it exceeds the set's maximum priority,
5986: thread's priority is similarly reduced).
5987: @code{processor_set_max_priority} changes this priority. It also sets
5988: the maximum priority of all threads assigned to the processor set to
5989: this new priority if @var{change_threads} is @code{TRUE}. If this
5990: maximum priority is less than the priorities of any of these threads,
5991: their priorities will also be set to this new value.
5992:
5993: This function returns @code{KERN_SUCCESS} if the call succeeded and
5994: @code{KERN_INVALID_ARGUMENT} if @var{processor_set} is not a processor
5995: set or @var{priority} is not a valid priority.
5996: @end deftypefun
5997:
5998:
5999: @node Processor Set Policy
6000: @subsection Processor Set Policy
6001:
6002: @deftypefun kern_return_t processor_set_policy_enable (@w{processor_set_t @var{processor_set}}, @w{int @var{policy}})
6003: @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}})
6004: Processor sets may restrict the scheduling policies to be used for
6005: threads assigned to them. These two calls provide the mechanism for
6006: designating permitted and forbidden policies. The current set of
6007: permitted policies can be obtained from @code{processor_set_info}.
6008: Timesharing may not be forbidden by any processor set. This is a
6009: compromise to reduce the complexity of the assign operation; any thread
6010: whose policy is forbidden by the target processor set has its policy
6011: reset to timesharing. If the @var{change_threads} argument to
6012: @code{processor_set_policy_disable} is true, threads currently assigned
6013: to this processor set and using the newly disabled policy will have
6014: their policy reset to timesharing.
6015:
6016: @file{mach/policy.h} contains the allowed policies; it is included by
6017: @file{mach.h}. Not all policies (e.g. fixed priority) are supported by
6018: all systems.
6019:
6020: This function returns @code{KERN_SUCCESS} if the operation was completed
6021: successfully and @code{KERN_INVALID_ARGUMENT} if @var{processor_set} is
6022: not a processor set or @var{policy} is not a valid policy, or an attempt
6023: was made to disable timesharing.
6024: @end deftypefun
6025:
6026:
6027: @node Processor Set Info
6028: @subsection Processor Set Info
6029:
6030: @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}})
6031: The function @code{processor_set_info} returns the selected information array
6032: for a processor set, as specified by @var{flavor}.
6033:
6034: @var{host} is set to the host on which the processor set resides. This
6035: is the non-privileged host port.
6036:
6037: @var{processor_set_info} is an array of integers that is supplied by the
6038: caller and returned filled with specified information.
6039: @var{processor_set_info_count} is supplied as the maximum number of
6040: integers in @var{processor_set_info}. On return, it contains the actual
6041: number of integers in @var{processor_set_info}. The maximum number of
6042: integers returned by any flavor is @code{PROCESSOR_SET_INFO_MAX}.
6043:
6044: The type of information returned is defined by @var{flavor}, which can
6045: be one of the following:
6046:
6047: @table @code
6048: @item PROCESSOR_SET_BASIC_INFO
6049: The function returns basic information about the processor set, as
6050: defined by @code{processor_set_basic_info_t}. This includes the number
6051: of tasks and threads assigned to the processor set. The number of
6052: integers returned is @code{PROCESSOR_SET_BASIC_INFO_COUNT}.
6053:
6054: @item PROCESSOR_SET_SCHED_INFO
1.1.1.2 root 6055: The function returns information about the scheduling policy for the
1.1 root 6056: processor set as defined by @code{processor_set_sched_info_t}. The
6057: number of integers returned is @code{PROCESSOR_SET_SCHED_INFO_COUNT}.
6058: @end table
6059:
6060: Some machines may define additional (machine-dependent) flavors.
6061:
6062: The function returns @code{KERN_SUCCESS} if the call succeeded and
6063: @code{KERN_INVALID_ARGUMENT} if @var{processor_set} is not a processor
6064: set or @var{flavor} is not recognized. The function returns
6065: @code{MIG_ARRAY_TOO_LARGE} if the returned info array is too large for
6066: @var{processor_set_info}. In this case, @var{processor_set_info} is
6067: filled as much as possible and @var{processor_set_info_count} is set to the
6068: number of elements that would have been returned if there were enough
6069: room.
6070: @end deftypefun
6071:
6072: @deftp {Data type} {struct processor_set_basic_info}
6073: This structure is returned in @var{processor_set_info} by the
6074: @code{processor_set_info} function and provides basic information about
6075: the processor set. You can cast a variable of type
6076: @code{processor_set_info_t} to a pointer of this type if you provided it
6077: as the @var{processor_set_info} parameter for the
6078: @code{PROCESSOR_SET_BASIC_INFO} flavor of @code{processor_set_info}. It
6079: has the following members:
6080:
6081: @table @code
6082: @item int processor_count
6083: number of processors
6084:
6085: @item int task_count
6086: number of tasks
6087:
6088: @item int thread_count
6089: number of threads
6090:
6091: @item int load_average
6092: scaled load average
6093:
6094: @item int mach_factor
6095: scaled mach factor
6096: @end table
6097: @end deftp
6098:
6099: @deftp {Data type} processor_set_basic_info_t
6100: This is a pointer to a @code{struct processor_set_basic_info}.
6101: @end deftp
6102:
6103: @deftp {Data type} {struct processor_set_sched_info}
6104: This structure is returned in @var{processor_set_info} by the
6105: @code{processor_set_info} function and provides schedule information
6106: about the processor set. You can cast a variable of type
6107: @code{processor_set_info_t} to a pointer of this type if you provided it
6108: as the @var{processor_set_info} parameter for the
6109: @code{PROCESSOR_SET_SCHED_INFO} flavor of @code{processor_set_info}. It
6110: has the following members:
6111:
6112: @table @code
6113: @item int policies
6114: allowed policies
6115:
6116: @item int max_priority
6117: max priority for new threads
6118: @end table
6119: @end deftp
6120:
6121: @deftp {Data type} processor_set_sched_info_t
6122: This is a pointer to a @code{struct processor_set_sched_info}.
6123: @end deftp
6124:
6125:
6126: @node Processor Interface
6127: @section Processor Interface
6128:
6129: @cindex processor port
6130: @cindex port representing a processor
6131: @deftp {Data type} processor_t
6132: This is a @code{mach_port_t} and used to hold the port name of a
6133: processor port that represents the processor. Operations on the
6134: processor are implemented as remote procedure calls to the processor
6135: port.
6136: @end deftp
6137:
6138: @menu
6139: * Hosted Processors:: Getting a list of all processors on a host.
6140: * Processor Control:: Starting, stopping, controlling processors.
6141: * Processors and Sets:: Combining processors into processor sets.
6142: * Processor Info:: Obtaining information on processors.
6143: @end menu
6144:
6145:
6146: @node Hosted Processors
6147: @subsection Hosted Processors
6148:
6149: @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}})
6150: The function @code{host_processors} gets send rights to the processor
6151: port for each processor existing on @var{host_priv}. This is the
6152: privileged port that allows its holder to control a processor.
6153:
6154: @var{processor_list} is an array that is created as a result of this
6155: call. The caller may wish to @code{vm_deallocate} this array when the
6156: data is no longer needed. @var{processor_count} is set to the number of
6157: processors in the @var{processor_list}.
6158:
6159: This function returns @code{KERN_SUCCESS} if the call succeeded,
6160: @code{KERN_INVALID_ARGUMENT} if @var{host_priv} is not a privileged host
6161: port, and @code{KERN_INVALID_ADDRESS} if @var{processor_count} points to
6162: inaccessible memory.
6163: @end deftypefun
6164:
6165:
6166: @node Processor Control
6167: @subsection Processor Control
6168:
6169: @deftypefun kern_return_t processor_start (@w{processor_t @var{processor}})
6170: @deftypefunx kern_return_t processor_exit (@w{processor_t @var{processor}})
6171: @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}})
6172: Some multiprocessors may allow privileged software to control
6173: processors. The @code{processor_start}, @code{processor_exit}, and
6174: @code{processor_control} operations implement this. The interpretation
6175: of the command in @var{cmd} is machine dependent. A newly started
6176: processor is assigned to the default processor set. An exited processor
6177: is removed from the processor set to which it was assigned and ceases to
6178: be active.
6179:
6180: @var{count} contains the length of the command @var{cmd} as a number of
6181: ints.
6182:
6183: Availability limited. All of these operations are machine-dependent.
6184: They may do nothing. The ability to restart an exited processor is also
6185: machine-dependent.
6186:
6187: This function returns @code{KERN_SUCCESS} if the operation was
6188: performed, @code{KERN_FAILURE} if the operation was not performed (a
6189: likely reason is that it is not supported on this processor),
6190: @code{KERN_INVALID_ARGUMENT} if @var{processor} is not a processor, and
6191: @code{KERN_INVALID_ADDRESS} if @var{cmd} points to inaccessible memory.
6192: @end deftypefun
6193:
6194: @node Processors and Sets
6195: @subsection Processors and Sets
6196:
6197: @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 6198: The function @code{processor_assign} assigns @var{processor} to the
1.1 root 6199: set @var{processor_set}. After the assignment is completed, the
6200: processor only executes threads that are assigned to that processor set.
6201: Any previous assignment of the processor is nullified. The master
6202: processor cannot be reassigned. All processors take clock interrupts at
6203: all times. The @var{wait} argument indicates whether the caller should
6204: wait for the assignment to be completed or should return immediately.
6205: Dedicated kernel threads are used to perform processor assignment, so
6206: setting wait to @code{FALSE} allows assignment requests to be queued and
6207: performed faster, especially if the kernel has more than one dedicated
6208: internal thread for processor assignment. Redirection of other device
6209: interrupts away from processors assigned to other than the default
6210: processor set is machine-dependent. Intermediaries that interpose on
6211: ports must be sure to interpose on both ports involved in this call if
6212: they interpose on either.
6213:
6214: This function returns @code{KERN_SUCCESS} if the assignment has been
6215: performed, @code{KERN_INVALID_ARGUMENT} if @var{processor} is not a
6216: processor, or @var{processor_set} is not a processor set on the same
6217: host as @var{processor}.
6218: @end deftypefun
6219:
6220: @deftypefun kern_return_t processor_get_assignment (@w{processor_t @var{processor}}, @w{processor_set_name_t *@var{assigned_set}})
6221: The function @code{processor_get_assignment} obtains the current
6222: assignment of a processor. The name port of the processor set is
6223: returned in @var{assigned_set}.
6224: @end deftypefun
6225:
6226: @node Processor Info
6227: @subsection Processor Info
6228:
6229: @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}})
6230: The function @code{processor_info} returns the selected information array
6231: for a processor, as specified by @var{flavor}.
6232:
6233: @var{host} is set to the host on which the processor set resides. This
6234: is the non-privileged host port.
6235:
6236: @var{processor_info} is an array of integers that is supplied by the
6237: caller and returned filled with specified information.
6238: @var{processor_info_count} is supplied as the maximum number of integers in
6239: @var{processor_info}. On return, it contains the actual number of
6240: integers in @var{processor_info}. The maximum number of integers
6241: returned by any flavor is @code{PROCESSOR_INFO_MAX}.
6242:
6243: The type of information returned is defined by @var{flavor}, which can
6244: be one of the following:
6245:
6246: @table @code
6247: @item PROCESSOR_BASIC_INFO
6248: The function returns basic information about the processor, as defined
6249: by @code{processor_basic_info_t}. This includes the slot number of the
6250: processor. The number of integers returned is
6251: @code{PROCESSOR_BASIC_INFO_COUNT}.
6252: @end table
6253:
6254: Machines which require more configuration information beyond the slot
6255: number are expected to define additional (machine-dependent) flavors.
6256:
6257: The function returns @code{KERN_SUCCESS} if the call succeeded and
6258: @code{KERN_INVALID_ARGUMENT} if @var{processor} is not a processor or
6259: @var{flavor} is not recognized. The function returns
6260: @code{MIG_ARRAY_TOO_LARGE} if the returned info array is too large for
6261: @var{processor_info}. In this case, @var{processor_info} is filled as
6262: much as possible and @var{processor_infoCnt} is set to the number of
6263: elements that would have been returned if there were enough room.
6264: @end deftypefun
6265:
6266: @deftp {Data type} {struct processor_basic_info}
6267: This structure is returned in @var{processor_info} by the
6268: @code{processor_info} function and provides basic information about the
6269: processor. You can cast a variable of type @code{processor_info_t} to a
6270: pointer of this type if you provided it as the @var{processor_info}
6271: parameter for the @code{PROCESSOR_BASIC_INFO} flavor of
6272: @code{processor_info}. It has the following members:
6273:
6274: @table @code
6275: @item cpu_type_t cpu_type
6276: cpu type
6277:
6278: @item cpu_subtype_t cpu_subtype
6279: cpu subtype
6280:
6281: @item boolean_t running
6282: is processor running?
6283:
6284: @item int slot_num
6285: slot number
6286:
6287: @item boolean_t is_master
6288: is this the master processor
6289: @end table
6290: @end deftp
6291:
6292: @deftp {Data type} processor_basic_info_t
6293: This is a pointer to a @code{struct processor_basic_info}.
6294: @end deftp
6295:
6296:
6297: @node Device Interface
6298: @chapter Device Interface
6299:
6300: The GNU Mach microkernel provides a simple device interface that allows
6301: the user space programs to access the underlying hardware devices. Each
6302: device has a unique name, which is a string up to 127 characters long.
6303: To open a device, the device master port has to be supplied. The device
6304: master port is only available through the bootstrap port. Anyone who
6305: has control over the device master port can use all hardware devices.
6306: @c XXX FIXME bootstrap port, bootstrap
6307:
6308: @cindex device port
6309: @cindex port representing a device
6310: @deftp {Data type} device_t
6311: This is a @code{mach_port_t} and used to hold the port name of a
6312: device port that represents the device. Operations on the device are
6313: implemented as remote procedure calls to the device port. Each device
6314: provides a sequence of records. The length of a record is specific to
6315: the device. Data can be transferred ``out-of-line'' or ``in-line''
6316: (@pxref{Memory}).
6317: @end deftp
6318:
6319: All constants and functions in this chapter are defined in
6320: @file{device/device.h}.
6321:
6322: @menu
6323: * Device Reply Server:: Handling device reply messages.
6324: * Device Open:: Opening hardware devices.
6325: * Device Close:: Closing hardware devices.
6326: * Device Read:: Reading data from the device.
6327: * Device Write:: Writing data to the device.
6328: * Device Map:: Mapping devices into virtual memory.
6329: * Device Status:: Querying and manipulating a device.
6330: * Device Filter:: Filtering packets arriving on a device.
6331: @end menu
6332:
6333:
6334: @node Device Reply Server
6335: @section Device Reply Server
6336:
6337: Beside the usual synchronous interface, an asynchronous interface is
6338: provided. For this, the caller has to receive and handle the reply
1.1.1.2 root 6339: messages separately from the function call.
1.1 root 6340:
6341: @deftypefun boolean_t device_reply_server (@w{msg_header_t *@var{in_msg}}, @w{msg_header_t *@var{out_msg}})
6342: The function @code{device_reply_server} is produced by the
6343: remote procedure call generator to handle a received message. This
6344: function does all necessary argument handling, and actually calls one of
6345: the following functions: @code{ds_device_open_reply},
6346: @code{ds_device_read_reply}, @code{ds_device_read_reply_inband},
6347: @code{ds_device_write_reply} and @code{ds_device_write_reply_inband}.
6348:
6349: The @var{in_msg} argument is the message that has been received from the
6350: kernel. The @var{out_msg} is a reply message, but this is not used for
6351: this server.
6352:
6353: The function returns @code{TRUE} to indicate that the message in
6354: question was applicable to this interface, and that the appropriate
6355: routine was called to interpret the message. It returns @code{FALSE} to
6356: indicate that the message did not apply to this interface, and that no
6357: other action was taken.
6358: @end deftypefun
6359:
6360:
6361: @node Device Open
6362: @section Device Open
6363:
6364: @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}})
6365: The function @code{device_open} opens the device @var{name} and returns
6366: a port to it in @var{device}. The open count for the device is
6367: incremented by one. If the open count was 0, the open handler for the
6368: device is invoked.
6369:
6370: @var{master_port} must hold the master device port. @var{name}
6371: specifies the device to open, and is a string up to 128 characters long.
6372: @var{mode} is the open mode. It is a bitwise-or of the following
6373: constants:
6374:
6375: @table @code
6376: @item D_READ
6377: Request read access for the device.
6378:
6379: @item D_WRITE
6380: Request write access for the device.
6381:
6382: @item D_NODELAY
6383: Do not delay an open.
6384: @c XXX Is this really used at all? Maybe for tape drives? What does it mean?
6385: @end table
6386:
6387: The function returns @code{D_SUCCESS} if the device was successfully
6388: opened, @code{D_INVALID_OPERATION} if @var{master_port} is not the
6389: master device port, @code{D_WOULD_BLOCK} is the device is busy and
6390: @code{D_NOWAIT} was specified in mode, @code{D_ALREADY_OPEN} if the
6391: device is already open in an incompatible mode and
6392: @code{D_NO_SUCH_DEVICE} if @var{name} does not denote a know device.
6393: @end deftypefun
6394:
6395: @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}})
6396: @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}})
6397: This is the asynchronous form of the @code{device_open} function.
6398: @code{device_open_request} performs the open request. The meaning for
6399: the parameters is as in @code{device_open}. Additionally, the caller
6400: has to supply a reply port to which the @code{ds_device_open_reply}
6401: message is sent by the kernel when the open has been performed. The
6402: return value of the open operation is stored in @var{return_code}.
6403:
6404: As neither function receives a reply message, only message transmission
6405: errors apply. If no error occurs, @code{KERN_SUCCESS} is returned.
6406: @end deftypefun
6407:
6408:
6409: @node Device Close
6410: @section Device Close
6411:
6412: @deftypefun kern_return_t device_close (@w{device_t @var{device}})
6413: The function @code{device_close} decrements the open count of the device
6414: by one. If the open count drops to zero, the close handler for the
6415: device is called. The device to close is specified by its port
6416: @var{device}.
6417:
6418: The function returns @code{D_SUCCESS} if the device was successfully
6419: closed and @code{D_NO_SUCH_DEVICE} if @var{device} does not denote a
6420: device port.
6421: @end deftypefun
6422:
6423:
6424: @node Device Read
6425: @section Device Read
6426:
6427: @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}})
6428: The function @code{device_read} reads @var{bytes_wanted} bytes from
6429: @var{device}, and stores them in a buffer allocated with
6430: @code{vm_allocate}, which address is returned in @var{data}. The caller
6431: must deallocated it if it is no longer needed. The number of bytes
6432: actually returned is stored in @var{data_count}.
6433:
6434: If @var{mode} is @code{D_NOWAIT}, the operation does not block.
6435: Otherwise @var{mode} should be 0. @var{recnum} is the record number to
6436: be read, its meaning is device specific.
6437:
6438: The function returns @code{D_SUCCESS} if some data was successfully
6439: read, @code{D_WOULD_BLOCK} if no data is currently available and
6440: @code{D_NOWAIT} is specified, and @code{D_NO_SUCH_DEVICE} if
6441: @var{device} does not denote a device port.
6442: @end deftypefun
6443:
6444: @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}})
6445: The @code{device_read_inband} function works as the @code{device_read}
6446: function, except that the data is returned ``in-line'' in the reply IPC
6447: message (@pxref{Memory}).
6448: @end deftypefun
6449:
6450: @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}})
6451: @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}})
6452: This is the asynchronous form of the @code{device_read} function.
6453: @code{device_read_request} performs the read request. The meaning for
6454: the parameters is as in @code{device_read}. Additionally, the caller
6455: has to supply a reply port to which the @code{ds_device_read_reply}
6456: message is sent by the kernel when the read has been performed. The
6457: return value of the read operation is stored in @var{return_code}.
6458:
6459: As neither function receives a reply message, only message transmission
6460: errors apply. If no error occurs, @code{KERN_SUCCESS} is returned.
6461: @end deftypefun
6462:
6463: @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}})
6464: @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}})
6465: The @code{device_read_request_inband} and
6466: @code{ds_device_read_reply_inband} functions work as the
6467: @code{device_read_request} and @code{ds_device_read_reply} functions,
6468: except that the data is returned ``in-line'' in the reply IPC message
6469: (@pxref{Memory}).
6470: @end deftypefun
6471:
6472:
6473: @node Device Write
6474: @section Device Write
6475:
6476: @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}})
6477: The function @code{device_write} writes @var{data_count} bytes from the
6478: buffer @var{data} to @var{device}. The number of bytes actually written
6479: is returned in @var{bytes_written}.
6480:
6481: If @var{mode} is @code{D_NOWAIT}, the function returns without waiting
6482: for I/O completion. Otherwise @var{mode} should be 0. @var{recnum} is
6483: the record number to be written, its meaning is device specific.
6484:
6485: The function returns @code{D_SUCCESS} if some data was successfully
6486: written and @code{D_NO_SUCH_DEVICE} if @var{device} does not denote a
6487: device port or the device is dead or not completely open.
6488: @end deftypefun
6489:
6490: @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}})
6491: The @code{device_write_inband} function works as the @code{device_write}
6492: function, except that the data is sent ``in-line'' in the request IPC
6493: message (@pxref{Memory}).
6494: @end deftypefun
6495:
6496: @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}})
6497: @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}})
6498: This is the asynchronous form of the @code{device_write} function.
6499: @code{device_write_request} performs the write request. The meaning for
6500: the parameters is as in @code{device_write}. Additionally, the caller
6501: has to supply a reply port to which the @code{ds_device_write_reply}
6502: message is sent by the kernel when the write has been performed. The
6503: return value of the write operation is stored in @var{return_code}.
6504:
6505: As neither function receives a reply message, only message transmission
6506: errors apply. If no error occurs, @code{KERN_SUCCESS} is returned.
6507: @end deftypefun
6508:
6509: @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}})
6510: @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}})
6511: The @code{device_write_request_inband} and
6512: @code{ds_device_write_reply_inband} functions work as the
6513: @code{device_write_request} and @code{ds_device_write_reply} functions,
6514: except that the data is sent ``in-line'' in the request IPC message
6515: (@pxref{Memory}).
6516: @end deftypefun
6517:
6518:
6519: @node Device Map
6520: @section Device Map
6521:
6522: @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}})
6523: The function @code{device_map} creates a new memory manager for
6524: @var{device} and returns a port to it in @var{pager}. The memory
6525: manager is usable as a memory object in a @code{vm_map} call. The call
1.1.1.2 root 6526: is device dependent.
1.1 root 6527:
6528: The protection for the memory object is specified by @var{prot}. The
6529: memory object starts at @var{offset} within the device and extends
6530: @var{size} bytes. @var{unmap} is currently unused.
6531: @c XXX I suppose the caller should set it to 0.
6532:
6533: The function returns @code{D_SUCCESS} if some data was successfully
6534: written and @code{D_NO_SUCH_DEVICE} if @var{device} does not denote a
6535: device port or the device is dead or not completely open.
6536: @end deftypefun
6537:
6538:
6539: @node Device Status
6540: @section Device Status
6541:
6542: @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}})
6543: The function @code{device_set_status} sets the status of a device. The
6544: possible values for @var{flavor} and their interpretation is device
6545: specific.
6546:
6547: The function returns @code{D_SUCCESS} if some data was successfully
6548: written and @code{D_NO_SUCH_DEVICE} if @var{device} does not denote a
6549: device port or the device is dead or not completely open.
6550: @end deftypefun
6551:
6552: @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}})
6553: The function @code{device_get_status} gets the status of a device. The
6554: possible values for @var{flavor} and their interpretation is device
6555: specific.
6556:
6557: The function returns @code{D_SUCCESS} if some data was successfully
6558: written and @code{D_NO_SUCH_DEVICE} if @var{device} does not denote a
6559: device port or the device is dead or not completely open.
6560: @end deftypefun
6561:
6562:
6563: @node Device Filter
6564: @section Device Filter
6565:
6566: @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}})
6567: The function @code{device_set_filter} makes it possible to filter out
1.1.1.2 root 6568: selected data arriving at or leaving the device and forward it to a port.
1.1 root 6569: @var{filter} is a list of filter commands, which are applied to incoming
6570: data to determine if the data should be sent to @var{receive_port}. The
6571: IPC type of the send right is specified by @var{receive_port_right}, it
6572: is either @code{MACH_MSG_TYPE_MAKE_SEND} or
6573: @code{MACH_MSG_TYPE_MOVE_SEND}. The @var{priority} value is used to
6574: order multiple filters.
6575:
6576: There can be up to @code{NET_MAX_FILTER} commands in @var{filter}. The
6577: actual number of commands is passed in @var{filter_count}. For the
6578: purpose of the filter test, an internal stack is provided. After all
6579: commands have been processed, the value on the top of the stack
6580: determines if the data is forwarded or the next filter is tried.
6581:
1.1.1.2 root 6582: The first command is a header which contains two fields: one for flags
6583: and the other for the type of interpreter used to run the rest of the
6584: commands.
6585:
6586: Any combination of the following flags is allowed but at least one of them
6587: must be specified.
6588:
6589: @table @code
6590: @item NETF_IN
6591: The filter will be applied to data received by the device.
6592:
6593: @item NETF_OUT
6594: The filter will be applied to data transmitted by the device.
6595: @end table
6596:
6597: Unless the type is given explicitly the native NETF interpreter will be used.
6598: To select an alternative implementation use one of the following types:
6599:
6600: @table @code
6601: @item NETF_BPF
6602: Use Berkeley Packet Filter.
6603: @end table
6604:
6605: For the listener to know what kind of packet is being received, when the
6606: filter code accepts a packet the message sent to @var{receive_port} is
6607: tagged with either NETF_IN or NETF_OUT.
6608:
1.1 root 6609: @c XXX The following description was taken verbatim from the
6610: @c kernel_interface.pdf document.
6611: Each word of the command list specifies a data (push) operation (high
6612: order NETF_NBPO bits) as well as a binary operator (low order NETF_NBPA
6613: bits). The value to be pushed onto the stack is chosen as follows.
6614:
6615: @table @code
6616: @item NETF_PUSHLIT
6617: Use the next short word of the filter as the value.
6618:
6619: @item NETF_PUSHZERO
6620: Use 0 as the value.
6621:
6622: @item NETF_PUSHWORD+N
6623: Use short word N of the ``data'' portion of the message as the value.
6624:
6625: @item NETF_PUSHHDR+N
6626: Use short word N of the ``header'' portion of the message as the value.
6627:
6628: @item NETF_PUSHIND+N
6629: Pops the top long word from the stack and then uses short word N of the
6630: ``data'' portion of the message as the value.
6631:
6632: @item NETF_PUSHHDRIND+N
6633: Pops the top long word from the stack and then uses short word N of the
6634: ``header'' portion of the message as the value.
6635:
6636: @item NETF_PUSHSTK+N
6637: Use long word N of the stack (where the top of stack is long word 0) as
6638: the value.
6639:
6640: @item NETF_NOPUSH
6641: Don't push a value.
6642: @end table
6643:
6644: The unsigned value so chosen is promoted to a long word before being
6645: pushed. Once a value is pushed (except for the case of
6646: @code{NETF_NOPUSH}), the top two long words of the stack are popped and
6647: a binary operator applied to them (with the old top of stack as the
6648: second operand). The result of the operator is pushed on the stack.
6649: These operators are:
6650:
6651: @table @code
6652: @item NETF_NOP
6653: Don't pop off any values and do no operation.
6654:
6655: @item NETF_EQ
6656: Perform an equal comparison.
6657:
6658: @item NETF_LT
6659: Perform a less than comparison.
6660:
6661: @item NETF_LE
6662: Perform a less than or equal comparison.
6663:
6664: @item NETF_GT
6665: Perform a greater than comparison.
6666:
6667: @item NETF_GE
6668: Perform a greater than or equal comparison.
6669:
6670: @item NETF_AND
6671: Perform a bitise boolean AND operation.
6672:
6673: @item NETF_OR
6674: Perform a bitise boolean inclusive OR operation.
6675:
6676: @item NETF_XOR
6677: Perform a bitise boolean exclusive OR operation.
6678:
6679: @item NETF_NEQ
6680: Perform a not equal comparison.
6681:
6682: @item NETF_LSH
6683: Perform a left shift operation.
6684:
6685: @item NETF_RSH
6686: Perform a right shift operation.
6687:
6688: @item NETF_ADD
6689: Perform an addition.
6690:
6691: @item NETF_SUB
6692: Perform a subtraction.
6693:
6694: @item NETF_COR
6695: Perform an equal comparison. If the comparison is @code{TRUE}, terminate
6696: the filter list. Otherwise, pop the result of the comparison off the
6697: stack.
6698:
6699: @item NETF_CAND
6700: Perform an equal comparison. If the comparison is @code{FALSE},
6701: terminate the filter list. Otherwise, pop the result of the comparison
6702: off the stack.
6703:
6704: @item NETF_CNOR
6705: Perform a not equal comparison. If the comparison is @code{FALSE},
6706: terminate the filter list. Otherwise, pop the result of the comparison
6707: off the stack.
6708:
6709: @item NETF_CNAND
6710: Perform a not equal comparison. If the comparison is @code{TRUE},
6711: terminate the filter list. Otherwise, pop the result of the comparison
6712: off the stack. The scan of the filter list terminates when the filter
6713: list is emptied, or a @code{NETF_C...} operation terminates the list. At
6714: this time, if the final value of the top of the stack is @code{TRUE},
6715: then the message is accepted for the filter.
6716: @end table
6717:
6718: The function returns @code{D_SUCCESS} if some data was successfully
6719: written, @code{D_INVALID_OPERATION} if @var{receive_port} is not a valid
6720: send right, and @code{D_NO_SUCH_DEVICE} if @var{device} does not denote
6721: a device port or the device is dead or not completely open.
6722: @end deftypefun
6723:
6724:
6725: @node Kernel Debugger
6726: @chapter Kernel Debugger
6727:
6728: The GNU Mach kernel debugger @code{ddb} is a powerful built-in debugger
6729: with a gdb like syntax. It is enabled at compile time using the
6730: @option{--enable-kdb} option. Whenever you want to enter the debugger
6731: while running the kernel, you can press the key combination
6732: @key{Ctrl-Alt-D}.
6733:
6734: @menu
6735: * Operation:: Basic architecture of the kernel debugger.
6736: * Commands:: Available commands in the kernel debugger.
6737: * Variables:: Access of variables from the kernel debugger.
6738: * Expressions:: Usage of expressions in the kernel debugger.
6739: @end menu
6740:
6741:
6742: @node Operation
6743: @section Operation
6744:
6745: The current location is called @dfn{dot}. The dot is displayed with a
6746: hexadecimal format at a prompt. Examine and write commands update dot
6747: to the address of the last line examined or the last location modified,
6748: and set @dfn{next} to the address of the next location to be examined or
6749: changed. Other commands don't change dot, and set next to be the same
6750: as dot.
6751:
6752: The general command syntax is:
6753:
6754: @example
6755: @var{command}[/@var{modifier}] @var{address} [,@var{count}]
6756: @end example
6757:
6758: @kbd{!!} repeats the previous command, and a blank line repeats from the
6759: address next with count 1 and no modifiers. Specifying @var{address} sets
6760: dot to the address. Omitting @var{address} uses dot. A missing @var{count}
6761: is taken to be 1 for printing commands or infinity for stack traces.
6762:
6763: Current @code{ddb} is enhanced to support multi-thread debugging. A
6764: break point can be set only for a specific thread, and the address space
6765: or registers of non current thread can be examined or modified if
6766: supported by machine dependent routines. For example,
6767:
6768: @example
6769: break/t mach_msg_trap $task11.0
6770: @end example
6771:
6772: sets a break point at @code{mach_msg_trap} for the first thread of task
6773: 11 listed by a @code{show all threads} command.
6774:
6775: In the above example, @code{$task11.0} is translated to the
6776: corresponding thread structure's address by variable translation
6777: mechanism described later. If a default target thread is set in a
6778: variable @code{$thread}, the @code{$task11.0} can be omitted. In
6779: general, if @code{t} is specified in a modifier of a command line, a
6780: specified thread or a default target thread is used as a target thread
6781: instead of the current one. The @code{t} modifier in a command line is
6782: not valid in evaluating expressions in a command line. If you want to
6783: get a value indirectly from a specific thread's address space or access
6784: to its registers within an expression, you have to specify a default
6785: target thread in advance, and to use @code{:t} modifier immediately
6786: after the indirect access or the register reference like as follows:
6787:
6788: @example
6789: set $thread $task11.0
6790: print $eax:t *(0x100):tuh
6791: @end example
6792:
6793: No sign extension and indirection @code{size(long, half word, byte)} can
6794: be specified with @code{u}, @code{l}, @code{h} and @code{b} respectively
6795: for the indirect access.
6796:
6797: Note: Support of non current space/register access and user space break
6798: point depend on the machines. If not supported, attempts of such
6799: operation may provide incorrect information or may cause strange
6800: behavior. Even if supported, the user space access is limited to the
6801: pages resident in the main memory at that time. If a target page is not
6802: in the main memory, an error will be reported.
6803:
6804: @code{ddb} has a feature like a command @code{more} for the output. If
6805: an output line exceeds the number set in the @code{$lines} variable, it
6806: displays @samp{--db_more--} and waits for a response. The valid
6807: responses for it are:
6808:
6809: @table @kbd
6810: @item @key{SPC}
6811: one more page
6812:
6813: @item @key{RET}
6814: one more line
6815:
6816: @item q
6817: abort the current command, and return to the command input mode
6818: @end table
6819:
6820:
6821: @node Commands
6822: @section Commands
6823:
6824: @table @code
6825: @item examine(x) [/@var{modifier}] @var{addr}[,@var{count}] [ @var{thread} ]
6826: Display the addressed locations according to the formats in the
6827: modifier. Multiple modifier formats display multiple locations. If no
6828: format is specified, the last formats specified for this command is
6829: used. Address space other than that of the current thread can be
6830: specified with @code{t} option in the modifier and @var{thread}
6831: parameter. The format characters are
6832:
6833: @table @code
6834: @item b
6835: look at by bytes(8 bits)
6836:
6837: @item h
6838: look at by half words(16 bits)
6839:
6840: @item l
6841: look at by long words(32 bits)
6842:
6843: @item a
6844: print the location being displayed
6845:
6846: @item ,
6847: skip one unit producing no output
6848:
6849: @item A
6850: print the location with a line number if possible
6851:
6852: @item x
6853: display in unsigned hex
6854:
6855: @item z
6856: display in signed hex
6857:
6858: @item o
6859: display in unsigned octal
6860:
6861: @item d
6862: display in signed decimal
6863:
6864: @item u
6865: display in unsigned decimal
6866:
6867: @item r
6868: display in current radix, signed
6869:
6870: @item c
6871: display low 8 bits as a character. Non-printing characters are
6872: displayed as an octal escape code (e.g. '\000').
6873:
6874: @item s
6875: display the null-terminated string at the location. Non-printing
6876: characters are displayed as octal escapes.
6877:
6878: @item m
6879: display in unsigned hex with character dump at the end of each line.
6880: The location is also displayed in hex at the beginning of each line.
6881:
6882: @item i
6883: display as an instruction
6884:
6885: @item I
6886: display as an instruction with possible alternate formats depending on
6887: the machine:
6888:
6889: @table @code
6890: @item vax
6891: don't assume that each external label is a procedure entry mask
6892:
6893: @item i386
6894: don't round to the next long word boundary
6895:
6896: @item mips
6897: print register contents
6898: @end table
6899: @end table
6900:
6901: @item xf
6902: Examine forward. It executes an examine command with the last specified
6903: parameters to it except that the next address displayed by it is used as
6904: the start address.
6905:
6906: @item xb
6907: Examine backward. It executes an examine command with the last
6908: specified parameters to it except that the last start address subtracted
6909: by the size displayed by it is used as the start address.
6910:
6911: @item print[/axzodurc] @var{addr1} [ @var{addr2} @dots{} ]
6912: Print @var{addr}'s according to the modifier character. Valid formats
6913: are: @code{a} @code{x} @code{z} @code{o} @code{d} @code{u} @code{r}
6914: @code{c}. If no modifier is specified, the last one specified to it is
6915: used. @var{addr} can be a string, and it is printed as it is. For
6916: example,
6917:
6918: @example
6919: print/x "eax = " $eax "\necx = " $ecx "\n"
6920: @end example
6921:
6922: will print like
6923:
6924: @example
6925: eax = xxxxxx
6926: ecx = yyyyyy
6927: @end example
6928:
6929: @item write[/bhlt] @var{addr} [ @var{thread} ] @var{expr1} [ @var{expr2} @dots{} ]
6930: Write the expressions at succeeding locations. The write unit size can
6931: be specified in the modifier with a letter b (byte), h (half word) or
6932: l(long word) respectively. If omitted, long word is assumed. Target
6933: address space can also be specified with @code{t} option in the modifier
6934: and @var{thread} parameter. Warning: since there is no delimiter
6935: between expressions, strange things may happen. It's best to enclose
6936: each expression in parentheses.
6937:
6938: @item set $@var{variable} [=] @var{expr}
6939: Set the named variable or register with the value of @var{expr}. Valid
6940: variable names are described below.
6941:
6942: @item break[/tuTU] @var{addr}[,@var{count}] [ @var{thread1} @dots{} ]
6943: Set a break point at @var{addr}. If count is supplied, continues
6944: (@var{count}-1) times before stopping at the break point. If the break
6945: point is set, a break point number is printed with @samp{#}. This
6946: number can be used in deleting the break point or adding conditions to
6947: it.
6948:
6949: @table @code
6950: @item t
6951: Set a break point only for a specific thread. The thread is specified
6952: by @var{thread} parameter, or default one is used if the parameter is
6953: omitted.
6954:
6955: @item u
6956: Set a break point in user space address. It may be combined with
6957: @code{t} or @code{T} option to specify the non-current target user
6958: space. Without @code{u} option, the address is considered in the kernel
6959: space, and wrong space address is rejected with an error message. This
6960: option can be used only if it is supported by machine dependent
6961: routines.
6962:
6963: @item T
6964: Set a break point only for threads in a specific task. It is like
6965: @code{t} option except that the break point is valid for all threads
6966: which belong to the same task as the specified target thread.
6967:
6968: @item U
6969: Set a break point in shared user space address. It is like @code{u}
6970: option, except that the break point is valid for all threads which share
6971: the same address space even if @code{t} option is specified. @code{t}
6972: option is used only to specify the target shared space. Without
6973: @code{t} option, @code{u} and @code{U} have the same meanings. @code{U}
6974: is useful for setting a user space break point in non-current address
6975: space with @code{t} option such as in an emulation library space. This
6976: option can be used only if it is supported by machine dependent
6977: routines.
6978: @end table
6979:
6980: Warning: if a user text is shadowed by a normal user space debugger,
6981: user space break points may not work correctly. Setting a break point
6982: at the low-level code paths may also cause strange behavior.
6983:
6984: @item delete[/tuTU] @var{addr}|#@var{number} [ @var{thread1} @dots{} ]
6985: Delete the break point. The target break point can be specified by a
6986: break point number with @code{#}, or by @var{addr} like specified in
6987: @code{break} command.
6988:
6989: @item cond #@var{number} [ @var{condition} @var{commands} ]
6990: Set or delete a condition for the break point specified by the
6991: @var{number}. If the @var{condition} and @var{commands} are null, the
6992: condition is deleted. Otherwise the condition is set for it. When the
6993: break point is hit, the @var{condition} is evaluated. The
6994: @var{commands} will be executed if the condition is true and the break
6995: point count set by a break point command becomes zero. @var{commands}
6996: is a list of commands separated by semicolons. Each command in the list
6997: is executed in that order, but if a @code{continue} command is executed,
6998: the command execution stops there, and the stopped thread resumes
6999: execution. If the command execution reaches the end of the list, and it
7000: enters into a command input mode. For example,
7001:
7002: @example
7003: set $work0 0
7004: break/Tu xxx_start $task7.0
7005: cond #1 (1) set $work0 1; set $work1 0; cont
7006: break/T vm_fault $task7.0
7007: cond #2 ($work0) set $work1 ($work1+1); cont
7008: break/Tu xxx_end $task7.0
7009: cond #3 ($work0) print $work1 " faults\n"; set $work0 0
7010: cont
7011: @end example
7012:
7013: will print page fault counts from @code{xxx_start} to @code{xxx_end} in
7014: @code{task7}.
7015:
7016: @item step[/p] [,@var{count}]
7017: Single step @var{count} times. If @code{p} option is specified, print
7018: each instruction at each step. Otherwise, only print the last
7019: instruction.
7020:
7021: Warning: depending on machine type, it may not be possible to
7022: single-step through some low-level code paths or user space code. On
7023: machines with software-emulated single-stepping (e.g., pmax), stepping
7024: through code executed by interrupt handlers will probably do the wrong
7025: thing.
7026:
7027: @item continue[/c]
7028: Continue execution until a breakpoint or watchpoint. If @code{/c},
7029: count instructions while executing. Some machines (e.g., pmax) also
7030: count loads and stores.
7031:
7032: Warning: when counting, the debugger is really silently single-stepping.
7033: This means that single-stepping on low-level code may cause strange
7034: behavior.
7035:
7036: @item until
7037: Stop at the next call or return instruction.
7038:
7039: @item next[/p]
7040: Stop at the matching return instruction. If @code{p} option is
7041: specified, print the call nesting depth and the cumulative instruction
7042: count at each call or return. Otherwise, only print when the matching
7043: return is hit.
7044:
7045: @item match[/p]
7046: A synonym for @code{next}.
7047:
7048: @item trace[/tu] [ @var{frame_addr}|@var{thread} ][,@var{count}]
7049: Stack trace. @code{u} option traces user space; if omitted, only traces
7050: kernel space. If @code{t} option is specified, it shows the stack trace
7051: of the specified thread or a default target thread. Otherwise, it shows
7052: the stack trace of the current thread from the frame address specified
7053: by a parameter or from the current frame. @var{count} is the number of
7054: frames to be traced. If the @var{count} is omitted, all frames are
7055: printed.
7056:
7057: Warning: If the target thread's stack is not in the main memory at that
7058: time, the stack trace will fail. User space stack trace is valid only
7059: if the machine dependent code supports it.
7060:
7061: @item search[/bhl] @var{addr} @var{value} [@var{mask}] [,@var{count}]
7062: Search memory for a value. This command might fail in interesting ways
7063: if it doesn't find the searched-for value. This is because @code{ddb}
7064: doesn't always recover from touching bad memory. The optional count
7065: argument limits the search.
7066:
7067: @item macro @var{name} @var{commands}
7068: Define a debugger macro as @var{name}. @var{commands} is a list of
7069: commands to be associated with the macro. In the expressions of the
7070: command list, a variable @code{$argxx} can be used to get a parameter
7071: passed to the macro. When a macro is called, each argument is evaluated
7072: as an expression, and the value is assigned to each parameter,
7073: @code{$arg1}, @code{$arg2}, @dots{} respectively. 10 @code{$arg}
7074: variables are reserved to each level of macros, and they can be used as
7075: local variables. The nesting of macro can be allowed up to 5 levels.
7076: For example,
7077:
7078: @example
7079: macro xinit set $work0 $arg1
7080: macro xlist examine/m $work0,4; set $work0 *($work0)
7081: xinit *(xxx_list)
7082: xlist
7083: @enddots{}
7084: @end example
7085:
7086: will print the contents of a list starting from @code{xxx_list} by each
7087: @code{xlist} command.
7088:
7089: @item dmacro @var{name}
7090: Delete the macro named @var{name}.
7091:
7092: @item show all threads[/ul]
7093: Display all tasks and threads information. This version of @code{ddb}
7094: prints more information than previous one. It shows UNIX process
7095: information like @command{ps} for each task. The UNIX process
7096: information may not be shown if it is not supported in the machine, or
7097: the bottom of the stack of the target task is not in the main memory at
7098: that time. It also shows task and thread identification numbers. These
7099: numbers can be used to specify a task or a thread symbolically in
7100: various commands. The numbers are valid only in the same debugger
7101: session. If the execution is resumed again, the numbers may change.
7102: The current thread can be distinguished from others by a @code{#} after
7103: the thread id instead of @code{:}. Without @code{l} option, it only
7104: shows thread id, thread structure address and the status for each
1.1.1.3 root 7105: thread. The status consists of 6 letters, R(run), W(wait), S(suspended),
7106: O(swapped out), N(interruptible), and F(loating) point arithmetic used (if
7107: supported by the platform). If the corresponding
1.1 root 7108: status bit is off, @code{.} is printed instead. If @code{l} option is
7109: specified, more detail information is printed for each thread.
7110:
7111: @item show task [ @var{addr} ]
7112: Display the information of a task specified by @var{addr}. If
7113: @var{addr} is omitted, current task information is displayed.
7114:
7115: @item show thread [ @var{addr} ]
7116: Display the information of a thread specified by @var{addr}. If
7117: @var{addr} is omitted, current thread information is displayed.
7118:
7119: @item show registers[/tu [ @var{thread} ]]
7120: Display the register set. Target thread can be specified with @code{t}
7121: option and @var{thread} parameter. If @code{u} option is specified, it
7122: displays user registers instead of kernel or currently saved one.
7123:
7124: Warning: The support of @code{t} and @code{u} option depends on the
7125: machine. If not supported, incorrect information will be displayed.
7126:
7127: @item show map @var{addr}
7128: Prints the @code{vm_map} at @var{addr}.
7129:
7130: @item show object @var{addr}
7131: Prints the @code{vm_object} at @var{addr}.
7132:
7133: @item show page @var{addr}
7134: Prints the @code{vm_page} structure at @var{addr}.
7135:
7136: @item show port @var{addr}
7137: Prints the @code{ipc_port} structure at @var{addr}.
7138:
7139: @item show ipc_port[/t [ @var{thread} ]]
7140: Prints all @code{ipc_port} structure's addresses the target thread has.
7141: The target thread is a current thread or that specified by a parameter.
7142:
7143: @item show macro [ @var{name} ]
7144: Show the definitions of macros. If @var{name} is specified, only the
7145: definition of it is displayed. Otherwise, definitions of all macros are
7146: displayed.
7147:
7148: @item show watches
7149: Displays all watchpoints.
7150:
7151: @item watch[/T] @var{addr},@var{size} [ @var{task} ]
7152: Set a watchpoint for a region. Execution stops when an attempt to
7153: modify the region occurs. The @var{size} argument defaults to 4.
7154: Without @code{T} option, @var{addr} is assumed to be a kernel address.
7155: If you want to set a watch point in user space, specify @code{T} and
7156: @var{task} parameter where the address belongs to. If the @var{task}
7157: parameter is omitted, a task of the default target thread or a current
7158: task is assumed. If you specify a wrong space address, the request is
7159: rejected with an error message.
7160:
7161: Warning: Attempts to watch wired kernel memory may cause unrecoverable
7162: error in some systems such as i386. Watchpoints on user addresses work
7163: best.
1.1.1.2 root 7164:
7165: @item dwatch[/T] @var{addr} [ @var{task} ]
7166: Clears a watchpoint previously set for a region.
7167: Without @code{T} option, @var{addr} is assumed to be a kernel address.
7168: If you want to clear a watch point in user space, specify @code{T} and
7169: @var{task} parameter where the address belongs to. If the @var{task}
7170: parameter is omitted, a task of the default target thread or a current
7171: task is assumed. If you specify a wrong space address, the request is
7172: rejected with an error message.
1.1 root 7173: @end table
7174:
7175:
7176: @node Variables
7177: @section Variables
7178:
7179: The debugger accesses registers and variables as $@var{name}. Register
7180: names are as in the @code{show registers} command. Some variables are
7181: suffixed with numbers, and may have some modifier following a colon
7182: immediately after the variable name. For example, register variables
7183: can have @code{u} and @code{t} modifier to indicate user register and
7184: that of a default target thread instead of that of the current thread
7185: (e.g. @code{$eax:tu}).
7186:
7187: Built-in variables currently supported are:
7188:
7189: @table @code
7190: @item task@var{xx}[.@var{yy}]
7191: Task or thread structure address. @var{xx} and @var{yy} are task and
7192: thread identification numbers printed by a @code{show all threads}
7193: command respectively. This variable is read only.
7194:
7195: @item thread
7196: The default target thread. The value is used when @code{t} option is
7197: specified without explicit thread structure address parameter in command
7198: lines or expression evaluation.
7199:
7200: @item radix
7201: Input and output radix
7202:
7203: @item maxoff
7204: Addresses are printed as @var{symbol}+@var{offset} unless offset is greater than
7205: maxoff.
7206:
7207: @item maxwidth
7208: The width of the displayed line.
7209:
7210: @item lines
7211: The number of lines. It is used by @code{more} feature.
7212:
7213: @item tabstops
7214: Tab stop width.
7215:
7216: @item arg@var{xx}
7217: Parameters passed to a macro. @var{xx} can be 1 to 10.
7218:
7219: @item work@var{xx}
7220: Work variable. @var{xx} can be 0 to 31.
7221: @end table
7222:
7223:
7224: @node Expressions
7225: @section Expressions
7226:
7227: Almost all expression operators in C are supported except @code{~},
7228: @code{^}, and unary @code{&}. Special rules in @code{ddb} are:
7229:
7230: @table @code
7231: @item @var{identifier}
7232: name of a symbol. It is translated to the address(or value) of it.
7233: @code{.} and @code{:} can be used in the identifier. If supported by
7234: an object format dependent routine,
7235: [@var{file_name}:]@var{func}[:@var{line_number}]
7236: [@var{file_name}:]@var{variable}, and
7237: @var{file_name}[:@var{line_number}] can be accepted as a symbol. The
7238: symbol may be prefixed with @code{@var{symbol_table_name}::} like
7239: @code{emulator::mach_msg_trap} to specify other than kernel symbols.
7240:
7241: @item @var{number}
7242: radix is determined by the first two letters:
7243: @table @code
7244: @item 0x
7245: hex
7246: @item 0o
7247: octal
7248: @item 0t
7249: decimal
7250: @end table
7251:
7252: otherwise, follow current radix.
7253:
7254: @item .
7255: dot
7256:
7257: @item +
7258: next
7259:
7260: @item ..
7261: address of the start of the last line examined. Unlike dot or next,
7262: this is only changed by @code{examine} or @code{write} command.
7263:
7264: @item �
7265: last address explicitly specified.
7266:
7267: @item $@var{variable}
7268: register name or variable. It is translated to the value of it. It may
7269: be followed by a @code{:} and modifiers as described above.
7270:
7271: @item a
7272: multiple of right hand side.
7273:
7274: @item *@var{expr}
7275: indirection. It may be followed by a @code{:} and modifiers as
7276: described above.
7277: @end table
7278:
7279: @include gpl.texi
7280:
7281: @node Documentation License
7282: @appendix Documentation License
7283:
7284: This manual is copyrighted and licensed under the GNU Free Documentation
7285: license.
7286:
7287: Parts of this manual are derived from the Mach manual packages
7288: originally provided by Carnegie Mellon University.
7289:
7290: @menu
1.1.1.2 root 7291: * GNU Free Documentation License:: The GNU Free Documentation License.
1.1 root 7292: * CMU License:: The CMU license applies to the original Mach
7293: kernel and its documentation.
7294: @end menu
7295:
7296: @include fdl.texi
7297:
7298: @node CMU License
7299: @appendixsec CMU License
7300:
7301: @quotation
7302: @display
7303: Mach Operating System
7304: Copyright @copyright{} 1991,1990,1989 Carnegie Mellon University
7305: All Rights Reserved.
7306: @end display
7307:
7308: Permission to use, copy, modify and distribute this software and its
7309: documentation is hereby granted, provided that both the copyright
7310: notice and this permission notice appear in all copies of the
7311: software, derivative works or modified versions, and any portions
7312: thereof, and that both notices appear in supporting documentation.
7313:
7314: @sc{carnegie mellon allows free use of this software in its ``as is''
7315: condition. carnegie mellon disclaims any liability of any kind for
7316: any damages whatsoever resulting from the use of this software.}
7317:
7318: Carnegie Mellon requests users of this software to return to
7319:
7320: @display
7321: Software Distribution Coordinator
7322: School of Computer Science
7323: Carnegie Mellon University
7324: Pittsburgh PA 15213-3890
7325: @end display
7326:
7327: @noindent
7328: or @email{Software.Distribution@@CS.CMU.EDU} any improvements or
7329: extensions that they make and grant Carnegie Mellon the rights to
7330: redistribute these changes.
7331: @end quotation
7332:
7333: @node Concept Index
7334: @unnumbered Concept Index
7335:
7336: @printindex cp
7337:
7338:
7339: @node Function and Data Index
7340: @unnumbered Function and Data Index
7341:
7342: @printindex fn
7343:
7344:
7345: @summarycontents
7346: @contents
7347: @bye
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.