|
|
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.
196: @c * Inherited Ports:: How to work with the inherited system ports.
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:
1333: @item mach_port_seqno_t msgh_seqno
1334: The @code{msgh_seqno} field provides a sequence number for the message.
1335: It is only valid in received messages; its value in sent messages is
1336: overwritten.
1337: @c XXX The "MESSAGE RECEIVE" section discusses message sequence numbers.
1338:
1339: @item mach_msg_id_t msgh_id
1340: The @code{mach_msg} call doesn't use the @code{msgh_id} field, but it
1341: conventionally conveys an operation or function id.
1342: @end table
1343: @end deftp
1344:
1345: @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}})
1346: This macro composes two @code{mach_msg_type_name_t} values that specify
1347: the port rights in the @code{msgh_remote_port} and
1348: @code{msgh_local_port} fields of a @code{mach_msg} call into an
1349: appropriate @code{mach_msg_bits_t} value.
1350: @end deftypefn
1351:
1352: @deftypefn Macro mach_msg_type_name_t MACH_MSGH_BITS_REMOTE (@w{mach_msg_bits_t @var{bits}})
1353: This macro extracts the @code{mach_msg_type_name_t} value for the remote
1354: port right in a @code{mach_msg_bits_t} value.
1355: @end deftypefn
1356:
1357: @deftypefn Macro mach_msg_type_name_t MACH_MSGH_BITS_LOCAL (@w{mach_msg_bits_t @var{bits}})
1358: This macro extracts the @code{mach_msg_type_name_t} value for the local
1359: port right in a @code{mach_msg_bits_t} value.
1360: @end deftypefn
1361:
1362: @deftypefn Macro mach_msg_bits_t MACH_MSGH_BITS_PORTS (@w{mach_msg_bits_t @var{bits}})
1363: This macro extracts the @code{mach_msg_bits_t} component consisting of
1364: the @code{mach_msg_type_name_t} values for the remote and local port
1365: right in a @code{mach_msg_bits_t} value.
1366: @end deftypefn
1367:
1368: @deftypefn Macro mach_msg_bits_t MACH_MSGH_BITS_OTHER (@w{mach_msg_bits_t @var{bits}})
1369: This macro extracts the @code{mach_msg_bits_t} component consisting of
1370: everything except the @code{mach_msg_type_name_t} values for the remote
1371: and local port right in a @code{mach_msg_bits_t} value.
1372: @end deftypefn
1373:
1374: Each data item has a type descriptor, a @code{mach_msg_type_t} or a
1375: @code{mach_msg_type_long_t}. The @code{mach_msg_type_long_t} type
1376: descriptor allows larger values for some fields. The
1377: @code{msgtl_header} field in the long descriptor is only used for its
1378: inline, longform, and deallocate bits.
1379:
1380: @deftp {Data type} mach_msg_type_name_t
1381: This is an @code{unsigned int} and can be used to hold the
1382: @code{msgt_name} component of the @code{mach_msg_type_t} and
1383: @code{mach_msg_type_long_t} structure.
1384: @end deftp
1385:
1386: @deftp {Data type} mach_msg_type_size_t
1387: This is an @code{unsigned int} and can be used to hold the
1388: @code{msgt_size} component of the @code{mach_msg_type_t} and
1389: @code{mach_msg_type_long_t} structure.
1390: @end deftp
1391:
1392: @deftp {Data type} mach_msg_type_number_t
1393: This is an @code{natural_t} and can be used to hold the
1394: @code{msgt_number} component of the @code{mach_msg_type_t} and
1395: @code{mach_msg_type_long_t} structure.
1396: @c XXX This is used for the size of arrays, too. Mmh?
1397: @end deftp
1398:
1399: @deftp {Data type} mach_msg_type_t
1400: This structure has the following members:
1401:
1402: @table @code
1403: @item unsigned int msgt_name : 8
1404: The @code{msgt_name} field specifies the data's type. The following
1405: types are predefined:
1406:
1407: @table @code
1408: @item MACH_MSG_TYPE_UNSTRUCTURED
1409: @item MACH_MSG_TYPE_BIT
1410: @item MACH_MSG_TYPE_BOOLEAN
1411: @item MACH_MSG_TYPE_INTEGER_16
1412: @item MACH_MSG_TYPE_INTEGER_32
1413: @item MACH_MSG_TYPE_CHAR
1414: @item MACH_MSG_TYPE_BYTE
1415: @item MACH_MSG_TYPE_INTEGER_8
1416: @item MACH_MSG_TYPE_REAL
1417: @item MACH_MSG_TYPE_STRING
1418: @item MACH_MSG_TYPE_STRING_C
1419: @item MACH_MSG_TYPE_PORT_NAME
1420: @end table
1421:
1422: The following predefined types specify port rights, and receive special
1423: treatment. The next section discusses these types in detail. The type
1424: @c XXX cross ref
1425: @code{MACH_MSG_TYPE_PORT_NAME} describes port right names, when no
1426: rights are being transferred, but just names. For this purpose, it
1427: should be used in preference to @code{MACH_MSG_TYPE_INTEGER_32}.
1428:
1429: @table @code
1430: @item MACH_MSG_TYPE_MOVE_RECEIVE
1431: @item MACH_MSG_TYPE_MOVE_SEND
1432: @item MACH_MSG_TYPE_MOVE_SEND_ONCE
1433: @item MACH_MSG_TYPE_COPY_SEND
1434: @item MACH_MSG_TYPE_MAKE_SEND
1435: @item MACH_MSG_TYPE_MAKE_SEND_ONCE
1436: @end table
1437:
1438: @item msgt_size : 8
1439: The @code{msgt_size} field specifies the size of each datum, in bits. For
1440: example, the msgt_size of @code{MACH_MSG_TYPE_INTEGER_32} data is 32.
1441:
1442: @item msgt_number : 12
1443: The @code{msgt_number} field specifies how many data elements comprise
1444: the data item. Zero is a legitimate number.
1445:
1446: The total length specified by a type descriptor is @w{@code{(msgt_size *
1447: msgt_number)}}, rounded up to an integral number of bytes. In-line data
1448: is then padded to an integral number of long-words. This ensures that
1449: type descriptors always start on long-word boundaries. It implies that
1450: message sizes are always an integral multiple of a long-word's size.
1451:
1452: @item msgt_inline : 1
1453: The @code{msgt_inline} bit specifies, when @code{FALSE}, that the data
1454: actually resides in an out-of-line region. The address of the memory
1455: region (a @code{vm_offset_t} or @code{vm_address_t}) follows the type
1456: descriptor in the message body. The @code{msgt_name}, @code{msgt_size},
1457: and @code{msgt_number} fields describe the memory region, not the
1458: address.
1459:
1460: @item msgt_longform : 1
1461: The @code{msgt_longform} bit specifies, when @code{TRUE}, that this type
1462: descriptor is a @code{mach_msg_type_long_t} instead of a
1463: @code{mach_msg_type_t}. The @code{msgt_name}, @code{msgt_size}, and
1464: @code{msgt_number} fields should be zero. Instead, @code{mach_msg} uses
1465: the following @code{msgtl_name}, @code{msgtl_size}, and
1466: @code{msgtl_number} fields.
1467:
1468: @item msgt_deallocate : 1
1469: The @code{msgt_deallocate} bit is used with out-of-line regions. When
1470: @code{TRUE}, it specifies that the memory region should be deallocated
1471: from the sender's address space (as if with @code{vm_deallocate}) when
1472: the message is sent.
1473:
1474: @item msgt_unused : 1
1475: The @code{msgt_unused} bit should be zero.
1476: @end table
1477: @end deftp
1478:
1479: @deftypefn Macro boolean_t MACH_MSG_TYPE_PORT_ANY (mach_msg_type_name_t type)
1480: This macro returns @code{TRUE} if the given type name specifies a port
1481: type, otherwise it returns @code{FALSE}.
1482: @end deftypefn
1483:
1484: @deftypefn Macro boolean_t MACH_MSG_TYPE_PORT_ANY_SEND (mach_msg_type_name_t type)
1485: This macro returns @code{TRUE} if the given type name specifies a port
1486: type with a send or send-once right, otherwise it returns @code{FALSE}.
1487: @end deftypefn
1488:
1489: @deftypefn Macro boolean_t MACH_MSG_TYPE_PORT_ANY_RIGHT (mach_msg_type_name_t type)
1490: This macro returns @code{TRUE} if the given type name specifies a port
1491: right type which is moved, otherwise it returns @code{FALSE}.
1492: @end deftypefn
1493:
1494: @deftp {Data type} mach_msg_type_long_t
1495: This structure has the following members:
1496:
1497: @table @code
1498: @item mach_msg_type_t msgtl_header
1499: Same meaning as @code{msgt_header}.
1500: @c XXX cross ref
1501:
1502: @item unsigned short msgtl_name
1503: Same meaning as @code{msgt_name}.
1504:
1505: @item unsigned short msgtl_size
1506: Same meaning as @code{msgt_size}.
1507:
1508: @item unsigned int msgtl_number
1509: Same meaning as @code{msgt_number}.
1510: @end table
1511: @end deftp
1512:
1513:
1514: @node Exchanging Port Rights
1515: @subsection Exchanging Port Rights
1516: @cindex sending port rights
1517: @cindex receiving port rights
1518: @cindex moving port rights
1519:
1520: Each task has its own space of port rights. Port rights are named with
1521: positive integers. Except for the reserved values
1522: @w{@code{MACH_PORT_NULL (0)}@footnote{In the Hurd system, we don't make
1523: the assumption that @code{MACH_PORT_NULL} is zero and evaluates to
1524: false, but rather compare port names to @code{MACH_PORT_NULL}
1.1.1.2 ! root 1525: explicitly}} and @w{@code{MACH_PORT_DEAD (~0)}}, this is a full 32-bit
1.1 root 1526: name space. When the kernel chooses a name for a new right, it is free
1527: to pick any unused name (one which denotes no right) in the space.
1528:
1529: There are five basic kinds of rights: receive rights, send rights,
1530: send-once rights, port-set rights, and dead names. Dead names are not
1531: capabilities. They act as place-holders to prevent a name from being
1532: otherwise used.
1533:
1534: A port is destroyed, or dies, when its receive right is deallocated.
1535: When a port dies, send and send-once rights for the port turn into dead
1536: names. Any messages queued at the port are destroyed, which deallocates
1537: the port rights and out-of-line memory in the messages.
1538:
1539: Tasks may hold multiple user-references for send rights and dead names.
1540: When a task receives a send right which it already holds, the kernel
1541: increments the right's user-reference count. When a task deallocates a
1542: send right, the kernel decrements its user-reference count, and the task
1543: only loses the send right when the count goes to zero.
1544:
1545: Send-once rights always have a user-reference count of one, although a
1546: port can have multiple send-once rights, because each send-once right
1547: held by a task has a different name. In contrast, when a task holds
1548: send rights or a receive right for a port, the rights share a single
1549: name.
1550:
1551: A message body can carry port rights; the @code{msgt_name}
1552: (@code{msgtl_name}) field in a type descriptor specifies the type of
1553: port right and how the port right is to be extracted from the caller.
1554: The values @code{MACH_PORT_NULL} and @code{MACH_PORT_DEAD} are always
1555: valid in place of a port right in a message body. In a sent message,
1556: the following @code{msgt_name} values denote port rights:
1557:
1558: @table @code
1559: @item MACH_MSG_TYPE_MAKE_SEND
1560: The message will carry a send right, but the caller must supply a
1561: receive right. The send right is created from the receive right, and
1562: the receive right's make-send count is incremented.
1563:
1564: @item MACH_MSG_TYPE_COPY_SEND
1565: The message will carry a send right, and the caller should supply a send
1566: right. The user reference count for the supplied send right is not
1567: changed. The caller may also supply a dead name and the receiving task
1568: will get @code{MACH_PORT_DEAD}.
1569:
1570: @item MACH_MSG_TYPE_MOVE_SEND
1571: The message will carry a send right, and the caller should supply a send
1572: right. The user reference count for the supplied send right is
1573: decremented, and the right is destroyed if the count becomes zero.
1574: Unless a receive right remains, the name becomes available for
1575: recycling. The caller may also supply a dead name, which loses a user
1576: reference, and the receiving task will get @code{MACH_PORT_DEAD}.
1577:
1578: @item MACH_MSG_TYPE_MAKE_SEND_ONCE
1579: The message will carry a send-once right, but the caller must supply a
1580: receive right. The send-once right is created from the receive right.
1581:
1582: @item MACH_MSG_TYPE_MOVE_SEND_ONCE
1583: The message will carry a send-once right, and the caller should supply a
1584: send-once right. The caller loses the supplied send-once right. The
1585: caller may also supply a dead name, which loses a user reference, and
1586: the receiving task will get @code{MACH_PORT_DEAD}.
1587:
1588: @item MACH_MSG_TYPE_MOVE_RECEIVE
1589: The message will carry a receive right, and the caller should supply a
1590: receive right. The caller loses the supplied receive right, but retains
1591: any send rights with the same name.
1592: @end table
1593:
1594: If a message carries a send or send-once right, and the port dies while
1595: the message is in transit, then the receiving task will get
1596: @code{MACH_PORT_DEAD} instead of a right. The following
1597: @code{msgt_name} values in a received message indicate that it carries
1598: port rights:
1599:
1600: @table @code
1601: @item MACH_MSG_TYPE_PORT_SEND
1602: This name is an alias for @code{MACH_MSG_TYPE_MOVE_SEND}. The message
1603: carried a send right. If the receiving task already has send and/or
1604: receive rights for the port, then that name for the port will be reused.
1605: Otherwise, the new right will have a new name. If the task already has
1606: send rights, it gains a user reference for the right (unless this would
1607: cause the user-reference count to overflow). Otherwise, it acquires the
1608: send right, with a user-reference count of one.
1609:
1610: @item MACH_MSG_TYPE_PORT_SEND_ONCE
1611: This name is an alias for @code{MACH_MSG_TYPE_MOVE_SEND_ONCE}. The
1612: message carried a send-once right. The right will have a new name.
1613:
1614: @item MACH_MSG_TYPE_PORT_RECEIVE
1615: This name is an alias for @code{MACH_MSG_TYPE_MOVE_RECEIVE}. The
1616: message carried a receive right. If the receiving task already has send
1617: rights for the port, then that name for the port will be reused.
1618: Otherwise, the right will have a new name. The make-send count of the
1619: receive right is reset to zero, but the port retains other attributes
1620: like queued messages, extant send and send-once rights, and requests for
1621: port-destroyed and no-senders notifications.
1622: @end table
1623:
1624: When the kernel chooses a new name for a port right, it can choose any
1625: name, other than @code{MACH_PORT_NULL} and @code{MACH_PORT_DEAD}, which
1626: is not currently being used for a port right or dead name. It might
1627: choose a name which at some previous time denoted a port right, but is
1628: currently unused.
1629:
1630:
1631: @node Memory
1632: @subsection Memory
1633: @cindex sending memory
1634: @cindex receiving memory
1635:
1636: A message body can contain the address of a region in the sender's
1637: address space which should be transferred as part of the message. The
1638: message carries a logical copy of the memory, but the kernel uses VM
1639: techniques to defer any actual page copies. Unless the sender or the
1640: receiver modifies the data, the physical pages remain shared.
1641:
1642: An out-of-line transfer occurs when the data's type descriptor specifies
1643: @code{msgt_inline} as @code{FALSE}. The address of the memory region (a
1644: @code{vm_offset_t} or @code{vm_address_t}) should follow the type
1645: descriptor in the message body. The type descriptor and the address
1646: contribute to the message's size (@code{send_size}, @code{msgh_size}).
1647: The out-of-line data does not contribute to the message's size.
1648:
1649: The name, size, and number fields in the type descriptor describe the
1650: type and length of the out-of-line data, not the in-line address.
1651: Out-of-line memory frequently requires long type descriptors
1652: (@code{mach_msg_type_long_t}), because the @code{msgt_number} field is
1653: too small to describe a page of 4K bytes.
1654:
1655: Out-of-line memory arrives somewhere in the receiver's address space as
1656: new memory. It has the same inheritance and protection attributes as
1657: newly @code{vm_allocate}'d memory. The receiver has the responsibility
1658: of deallocating (with @code{vm_deallocate}) the memory when it is no
1659: longer needed. Security-conscious receivers should exercise caution
1660: when using out-of-line memory from untrustworthy sources, because the
1661: memory may be backed by an unreliable memory manager.
1662:
1663: Null out-of-line memory is legal. If the out-of-line region size is
1664: zero (for example, because @code{msgtl_number} is zero), then the
1665: region's specified address is ignored. A received null out-of-line
1666: memory region always has a zero address.
1667:
1668: Unaligned addresses and region sizes that are not page multiples are
1669: legal. A received message can also contain memory with unaligned
1670: addresses and funny sizes. In the general case, the first and last
1671: pages in the new memory region in the receiver do not contain only data
1672: from the sender, but are partly zero.@footnote{Sending out-of-line
1673: memory with a non-page-aligned address, or a size which is not a page
1674: multiple, works but with a caveat. The extra bytes in the first and
1675: last page of the received memory are not zeroed, so the receiver can
1676: peek at more data than the sender intended to transfer. This might be a
1677: security problem for the sender.} The received address points to the
1678: start of the data in the first page. This possibility doesn't
1679: complicate deallocation, because @code{vm_deallocate} does the right
1680: thing, rounding the start address down and the end address up to
1681: deallocate all arrived pages.
1682:
1683: Out-of-line memory has a deallocate option, controlled by the
1684: @code{msgt_deallocate} bit. If it is @code{TRUE} and the out-of-line
1685: memory region is not null, then the region is implicitly deallocated
1686: from the sender, as if by @code{vm_deallocate}. In particular, the
1687: start and end addresses are rounded so that every page overlapped by the
1688: memory region is deallocated. The use of @code{msgt_deallocate}
1689: effectively changes the memory copy into a memory movement. In a
1690: received message, @code{msgt_deallocate} is @code{TRUE} in type
1691: descriptors for out-of-line memory.
1692:
1693: Out-of-line memory can carry port rights.
1694:
1695:
1696: @node Message Send
1697: @subsection Message Send
1698: @cindex sending messages
1699:
1700: The send operation queues a message to a port. The message carries a
1701: copy of the caller's data. After the send, the caller can freely modify
1702: the message buffer or the out-of-line memory regions and the message
1703: contents will remain unchanged.
1704:
1705: Message delivery is reliable and sequenced. Messages are not lost, and
1706: messages sent to a port, from a single thread, are received in the order
1707: in which they were sent.
1708:
1709: If the destination port's queue is full, then several things can happen.
1710: If the message is sent to a send-once right (@code{msgh_remote_port}
1711: carries a send-once right), then the kernel ignores the queue limit and
1712: delivers the message. Otherwise the caller blocks until there is room
1713: in the queue, unless the @code{MACH_SEND_TIMEOUT} or
1714: @code{MACH_SEND_NOTIFY} options are used. If a port has several blocked
1715: senders, then any of them may queue the next message when space in the
1716: queue becomes available, with the proviso that a blocked sender will not
1717: be indefinitely starved.
1718:
1719: These options modify @code{MACH_SEND_MSG}. If @code{MACH_SEND_MSG} is
1720: not also specified, they are ignored.
1721:
1722: @table @code
1723: @item MACH_SEND_TIMEOUT
1724: The timeout argument should specify a maximum time (in milliseconds) for
1725: the call to block before giving up.@footnote{If MACH_SEND_TIMEOUT is
1726: used without MACH_SEND_INTERRUPT, then the timeout duration might not be
1727: accurate. When the call is interrupted and automatically retried, the
1728: original timeout is used. If interrupts occur frequently enough, the
1729: timeout interval might never expire.} If the message can't be queued
1730: before the timeout interval elapses, then the call returns
1731: @code{MACH_SEND_TIMED_OUT}. A zero timeout is legitimate.
1732:
1733: @item MACH_SEND_NOTIFY
1734: The notify argument should specify a receive right for a notify port.
1735: If the send were to block, then instead the message is queued,
1736: @code{MACH_SEND_WILL_NOTIFY} is returned, and a msg-accepted
1737: notification is requested. If @code{MACH_SEND_TIMEOUT} is also
1738: specified, then @code{MACH_SEND_NOTIFY} doesn't take effect until the
1739: timeout interval elapses.
1740:
1741: With @code{MACH_SEND_NOTIFY}, a task can forcibly queue to a send right
1.1.1.2 ! root 1742: one message at a time. A msg-accepted notification is sent to the
1.1 root 1743: notify port when another message can be forcibly queued. If an attempt
1744: is made to use @code{MACH_SEND_NOTIFY} before then, the call returns a
1745: @code{MACH_SEND_NOTIFY_IN_PROGRESS} error.
1746:
1747: The msg-accepted notification carries the name of the send right. If
1748: the send right is deallocated before the msg-accepted notification is
1749: generated, then the msg-accepted notification carries the value
1750: @code{MACH_PORT_NULL}. If the destination port is destroyed before the
1751: notification is generated, then a send-once notification is generated
1752: instead.
1753:
1754: @item MACH_SEND_INTERRUPT
1755: If specified, the @code{mach_msg} call will return
1756: @code{MACH_SEND_INTERRUPTED} if a software interrupt aborts the call.
1757: Otherwise, the send operation will be retried.
1758:
1759: @item MACH_SEND_CANCEL
1760: The notify argument should specify a receive right for a notify port.
1761: If the send operation removes the destination port right from the
1762: caller, and the removed right had a dead-name request registered for it,
1763: and notify is the notify port for the dead-name request, then the
1764: dead-name request may be silently canceled (instead of resulting in a
1765: port-deleted notification).
1766:
1767: This option is typically used to cancel a dead-name request made with
1768: the @code{MACH_RCV_NOTIFY} option. It should only be used as an optimization.
1769: @end table
1770:
1771: The send operation can generate the following return codes. These
1772: return codes imply that the call did nothing:
1773:
1774: @table @code
1775: @item MACH_SEND_MSG_TOO_SMALL
1776: The specified send_size was smaller than the minimum size for a message.
1777:
1778: @item MACH_SEND_NO_BUFFER
1779: A resource shortage prevented the kernel from allocating a message
1780: buffer.
1781:
1782: @item MACH_SEND_INVALID_DATA
1783: The supplied message buffer was not readable.
1784:
1785: @item MACH_SEND_INVALID_HEADER
1786: The @code{msgh_bits} value was invalid.
1787:
1788: @item MACH_SEND_INVALID_DEST
1789: The @code{msgh_remote_port} value was invalid.
1790:
1791: @item MACH_SEND_INVALID_REPLY
1792: The @code{msgh_local_port} value was invalid.
1793:
1794: @item MACH_SEND_INVALID_NOTIFY
1795: When using @code{MACH_SEND_CANCEL}, the notify argument did not denote a
1796: valid receive right.
1797: @end table
1798:
1799: These return codes imply that some or all of the message was destroyed:
1800:
1801: @table @code
1802: @item MACH_SEND_INVALID_MEMORY
1803: The message body specified out-of-line data that was not readable.
1804:
1805: @item MACH_SEND_INVALID_RIGHT
1806: The message body specified a port right which the caller didn't possess.
1807:
1808: @item MACH_SEND_INVALID_TYPE
1809: A type descriptor was invalid.
1810:
1811: @item MACH_SEND_MSG_TOO_SMALL
1812: The last data item in the message ran over the end of the message.
1813: @end table
1814:
1815: These return codes imply that the message was returned to the caller
1816: with a pseudo-receive operation:
1817:
1818: @table @code
1819: @item MACH_SEND_TIMED_OUT
1820: The timeout interval expired.
1821:
1822: @item MACH_SEND_INTERRUPTED
1823: A software interrupt occurred.
1824:
1825: @item MACH_SEND_INVALID_NOTIFY
1826: When using @code{MACH_SEND_NOTIFY}, the notify argument did not denote a
1827: valid receive right.
1828:
1829: @item MACH_SEND_NO_NOTIFY
1830: A resource shortage prevented the kernel from setting up a msg-accepted
1831: notification.
1832:
1833: @item MACH_SEND_NOTIFY_IN_PROGRESS
1834: A msg-accepted notification was already requested, and hasn't yet been
1835: generated.
1836: @end table
1837:
1838: These return codes imply that the message was queued:
1839:
1840: @table @code
1841: @item MACH_SEND_WILL_NOTIFY
1842: The message was forcibly queued, and a msg-accepted notification was
1843: requested.
1844:
1845: @item MACH_MSG_SUCCESS
1846: The message was queued.
1847: @end table
1848:
1849: Some return codes, like @code{MACH_SEND_TIMED_OUT}, imply that the
1850: message was almost sent, but could not be queued. In these situations,
1851: the kernel tries to return the message contents to the caller with a
1852: pseudo-receive operation. This prevents the loss of port rights or
1853: memory which only exist in the message. For example, a receive right
1854: which was moved into the message, or out-of-line memory sent with the
1855: deallocate bit.
1856:
1857: The pseudo-receive operation is very similar to a normal receive
1858: operation. The pseudo-receive handles the port rights in the message
1859: header as if they were in the message body. They are not reversed.
1860: After the pseudo-receive, the message is ready to be resent. If the
1861: message is not resent, note that out-of-line memory regions may have
1862: moved and some port rights may have changed names.
1863:
1864: The pseudo-receive operation may encounter resource shortages. This is
1865: similar to a @code{MACH_RCV_BODY_ERROR} return code from a receive
1866: operation. When this happens, the normal send return codes are
1867: augmented with the @code{MACH_MSG_IPC_SPACE}, @code{MACH_MSG_VM_SPACE},
1868: @code{MACH_MSG_IPC_KERNEL}, and @code{MACH_MSG_VM_KERNEL} bits to
1869: indicate the nature of the resource shortage.
1870:
1871: The queueing of a message carrying receive rights may create a circular
1872: loop of receive rights and messages, which can never be received. For
1873: example, a message carrying a receive right can be sent to that receive
1874: right. This situation is not an error, but the kernel will
1875: garbage-collect such loops, destroying the messages and ports involved.
1876:
1877:
1878: @node Message Receive
1879: @subsection Message Receive
1880:
1881: The receive operation dequeues a message from a port. The receiving
1882: task acquires the port rights and out-of-line memory regions carried in
1883: the message.
1884:
1885: The @code{rcv_name} argument specifies a port or port set from which to
1886: receive. If a port is specified, the caller must possess the receive
1887: right for the port and the port must not be a member of a port set. If
1888: no message is present, then the call blocks, subject to the
1889: @code{MACH_RCV_TIMEOUT} option.
1890:
1891: If a port set is specified, the call will receive a message sent to any
1892: of the member ports. It is permissible for the port set to have no
1893: member ports, and ports may be added and removed while a receive from
1894: the port set is in progress. The received message can come from any of
1895: the member ports which have messages, with the proviso that a member
1896: port with messages will not be indefinitely starved. The
1897: @code{msgh_local_port} field in the received message header specifies
1898: from which port in the port set the message came.
1899:
1900: The @code{rcv_size} argument specifies the size of the caller's message
1901: buffer. The @code{mach_msg} call will not receive a message larger than
1902: @code{rcv_size}. Messages that are too large are destroyed, unless the
1903: @code{MACH_RCV_LARGE} option is used.
1904:
1905: The destination and reply ports are reversed in a received message
1906: header. The @code{msgh_local_port} field names the destination port,
1907: from which the message was received, and the @code{msgh_remote_port}
1908: field names the reply port right. The bits in @code{msgh_bits} are also
1909: reversed. The @code{MACH_MSGH_BITS_LOCAL} bits have the value
1910: @code{MACH_MSG_TYPE_PORT_SEND} if the message was sent to a send right,
1911: and the value @code{MACH_MSG_TYPE_PORT_SEND_ONCE} if was sent to a
1912: send-once right. The @code{MACH_MSGH_BITS_REMOTE} bits describe the
1913: reply port right.
1914:
1915: A received message can contain port rights and out-of-line memory. The
1916: @code{msgh_local_port} field does not receive a port right; the act of
1917: receiving the message destroys the send or send-once right for the
1918: destination port. The msgh_remote_port field does name a received port
1919: right, the reply port right, and the message body can carry port rights
1920: and memory if @code{MACH_MSGH_BITS_COMPLEX} is present in msgh_bits.
1921: Received port rights and memory should be consumed or deallocated in
1922: some fashion.
1923:
1924: In almost all cases, @code{msgh_local_port} will specify the name of a
1925: receive right, either @code{rcv_name} or if @code{rcv_name} is a port
1926: set, a member of @code{rcv_name}. If other threads are concurrently
1927: manipulating the receive right, the situation is more complicated. If
1928: the receive right is renamed during the call, then
1929: @code{msgh_local_port} specifies the right's new name. If the caller
1930: loses the receive right after the message was dequeued from it, then
1931: @code{mach_msg} will proceed instead of returning
1932: @code{MACH_RCV_PORT_DIED}. If the receive right was destroyed, then
1933: @code{msgh_local_port} specifies @code{MACH_PORT_DEAD}. If the receive
1934: right still exists, but isn't held by the caller, then
1935: @code{msgh_local_port} specifies @code{MACH_PORT_NULL}.
1936:
1937: Received messages are stamped with a sequence number, taken from the
1938: port from which the message was received. (Messages received from a
1939: port set are stamped with a sequence number from the appropriate member
1940: port.) Newly created ports start with a zero sequence number, and the
1941: sequence number is reset to zero whenever the port's receive right moves
1942: between tasks. When a message is dequeued from the port, it is stamped
1943: with the port's sequence number and the port's sequence number is then
1944: incremented. The dequeue and increment operations are atomic, so that
1945: multiple threads receiving messages from a port can use the
1946: @code{msgh_seqno} field to reconstruct the original order of the
1947: messages.
1948:
1949: These options modify @code{MACH_RCV_MSG}. If @code{MACH_RCV_MSG} is not
1950: also specified, they are ignored.
1951:
1952: @table @code
1953: @item MACH_RCV_TIMEOUT
1954: The timeout argument should specify a maximum time (in milliseconds) for
1955: the call to block before giving up.@footnote{If MACH_RCV_TIMEOUT is used
1956: without MACH_RCV_INTERRUPT, then the timeout duration might not be
1957: accurate. When the call is interrupted and automatically retried, the
1958: original timeout is used. If interrupts occur frequently enough, the
1959: timeout interval might never expire.} If no message arrives before the
1960: timeout interval elapses, then the call returns
1961: @code{MACH_RCV_TIMED_OUT}. A zero timeout is legitimate.
1962:
1963: @item MACH_RCV_NOTIFY
1964: The notify argument should specify a receive right for a notify port.
1965: If receiving the reply port creates a new port right in the caller, then
1966: the notify port is used to request a dead-name notification for the new
1967: port right.
1968:
1969: @item MACH_RCV_INTERRUPT
1970: If specified, the @code{mach_msg} call will return
1971: @code{MACH_RCV_INTERRUPTED} if a software interrupt aborts the call.
1972: Otherwise, the receive operation will be retried.
1973:
1974: @item MACH_RCV_LARGE
1975: If the message is larger than @code{rcv_size}, then the message remains
1976: queued instead of being destroyed. The call returns
1977: @code{MACH_RCV_TOO_LARGE} and the actual size of the message is returned
1978: in the @code{msgh_size} field of the message header.
1979: @end table
1980:
1981: The receive operation can generate the following return codes. These
1982: return codes imply that the call did not dequeue a message:
1983:
1984: @table @code
1985: @item MACH_RCV_INVALID_NAME
1986: The specified @code{rcv_name} was invalid.
1987:
1988: @item MACH_RCV_IN_SET
1989: The specified port was a member of a port set.
1990:
1991: @item MACH_RCV_TIMED_OUT
1992: The timeout interval expired.
1993:
1994: @item MACH_RCV_INTERRUPTED
1995: A software interrupt occurred.
1996:
1997: @item MACH_RCV_PORT_DIED
1998: The caller lost the rights specified by @code{rcv_name}.
1999:
2000: @item MACH_RCV_PORT_CHANGED
2001: @code{rcv_name} specified a receive right which was moved into a port
2002: set during the call.
2003:
2004: @item MACH_RCV_TOO_LARGE
2005: When using @code{MACH_RCV_LARGE}, and the message was larger than
2006: @code{rcv_size}. The message is left queued, and its actual size is
2007: returned in the @code{msgh_size} field of the message buffer.
2008: @end table
2009:
2010: These return codes imply that a message was dequeued and destroyed:
2011:
2012: @table @code
2013: @item MACH_RCV_HEADER_ERROR
2014: A resource shortage prevented the reception of the port rights in the
2015: message header.
2016:
2017: @item MACH_RCV_INVALID_NOTIFY
2018: When using @code{MACH_RCV_NOTIFY}, the notify argument did not denote a
2019: valid receive right.
2020:
2021: @item MACH_RCV_TOO_LARGE
2022: When not using @code{MACH_RCV_LARGE}, a message larger than
2023: @code{rcv_size} was dequeued and destroyed.
2024: @end table
2025:
2026: In these situations, when a message is dequeued and then destroyed, the
2027: reply port and all port rights and memory in the message body are
2028: destroyed. However, the caller receives the message's header, with all
2029: fields correct, including the destination port but excepting the reply
2030: port, which is @code{MACH_PORT_NULL}.
2031:
2032: These return codes imply that a message was received:
2033:
2034: @table @code
2035: @item MACH_RCV_BODY_ERROR
2036: A resource shortage prevented the reception of a port right or
2037: out-of-line memory region in the message body. The message header,
2038: including the reply port, is correct. The kernel attempts to transfer
2039: all port rights and memory regions in the body, and only destroys those
2040: that can't be transferred.
2041:
2042: @item MACH_RCV_INVALID_DATA
2043: The specified message buffer was not writable. The calling task did
2044: successfully receive the port rights and out-of-line memory regions in
2045: the message.
2046:
2047: @item MACH_MSG_SUCCESS
2048: A message was received.
2049: @end table
2050:
2051: Resource shortages can occur after a message is dequeued, while
2052: transferring port rights and out-of-line memory regions to the receiving
2053: task. The @code{mach_msg} call returns @code{MACH_RCV_HEADER_ERROR} or
2054: @code{MACH_RCV_BODY_ERROR} in this situation. These return codes always
2055: carry extra bits (bitwise-ored) that indicate the nature of the resource
2056: shortage:
2057:
2058: @table @code
2059: @item MACH_MSG_IPC_SPACE
2060: There was no room in the task's IPC name space for another port name.
2061:
2062: @item MACH_MSG_VM_SPACE
2063: There was no room in the task's VM address space for an out-of-line
2064: memory region.
2065:
2066: @item MACH_MSG_IPC_KERNEL
2067: A kernel resource shortage prevented the reception of a port right.
2068:
2069: @item MACH_MSG_VM_KERNEL
2070: A kernel resource shortage prevented the reception of an out-of-line
2071: memory region.
2072: @end table
2073:
2074: If a resource shortage prevents the reception of a port right, the port
2075: right is destroyed and the caller sees the name @code{MACH_PORT_NULL}.
2076: If a resource shortage prevents the reception of an out-of-line memory
2077: region, the region is destroyed and the caller receives a zero address.
2078: In addition, the @code{msgt_size} (@code{msgtl_size}) field in the
2079: data's type descriptor is changed to zero. If a resource shortage
2080: prevents the reception of out-of-line memory carrying port rights, then
2081: the port rights are always destroyed if the memory region can not be
2082: received. A task never receives port rights or memory regions that it
2083: isn't told about.
2084:
2085:
2086: @node Atomicity
2087: @subsection Atomicity
2088:
2089: The @code{mach_msg} call handles port rights in a message header
2090: atomically. Port rights and out-of-line memory in a message body do not
2091: enjoy this atomicity guarantee. The message body may be processed
2092: front-to-back, back-to-front, first out-of-line memory then port rights,
2093: in some random order, or even atomically.
2094:
2095: For example, consider sending a message with the destination port
2096: specified as @code{MACH_MSG_TYPE_MOVE_SEND} and the reply port specified
2097: as @code{MACH_MSG_TYPE_COPY_SEND}. The same send right, with one
2098: user-reference, is supplied for both the @code{msgh_remote_port} and
2099: @code{msgh_local_port} fields. Because @code{mach_msg} processes the
2100: message header atomically, this succeeds. If @code{msgh_remote_port}
2101: were processed before @code{msgh_local_port}, then @code{mach_msg} would
2102: return @code{MACH_SEND_INVALID_REPLY} in this situation.
2103:
2104: On the other hand, suppose the destination and reply port are both
2105: specified as @code{MACH_MSG_TYPE_MOVE_SEND}, and again the same send
2106: right with one user-reference is supplied for both. Now the send
2107: operation fails, but because it processes the header atomically,
2108: mach_msg can return either @code{MACH_SEND_INVALID_DEST} or
2109: @code{MACH_SEND_INVALID_REPLY}.
2110:
2111: For example, consider receiving a message at the same time another
2112: thread is deallocating the destination receive right. Suppose the reply
2113: port field carries a send right for the destination port. If the
2114: deallocation happens before the dequeuing, then the receiver gets
2115: @code{MACH_RCV_PORT_DIED}. If the deallocation happens after the
2116: receive, then the @code{msgh_local_port} and the @code{msgh_remote_port}
2117: fields both specify the same right, which becomes a dead name when the
2118: receive right is deallocated. If the deallocation happens between the
2119: dequeue and the receive, then the @code{msgh_local_port} and
2120: @code{msgh_remote_port} fields both specify @code{MACH_PORT_DEAD}.
2121: Because the header is processed atomically, it is not possible for just
2122: one of the two fields to hold @code{MACH_PORT_DEAD}.
2123:
2124: The @code{MACH_RCV_NOTIFY} option provides a more likely example.
2125: Suppose a message carrying a send-once right reply port is received with
2126: @code{MACH_RCV_NOTIFY} at the same time the reply port is destroyed. If
2127: the reply port is destroyed first, then @code{msgh_remote_port}
2128: specifies @code{MACH_PORT_DEAD} and the kernel does not generate a
2129: dead-name notification. If the reply port is destroyed after it is
2130: received, then @code{msgh_remote_port} specifies a dead name for which
2131: the kernel generates a dead-name notification. It is not possible to
2132: receive the reply port right and have it turn into a dead name before
2133: the dead-name notification is requested; as part of the message header
2134: the reply port is received atomically.
2135:
2136:
2137: @node Port Manipulation Interface
2138: @section Port Manipulation Interface
2139:
2140: This section describes the interface to create, destroy and manipulate
2141: ports, port rights and port sets.
2142:
2143: @cindex IPC space port
2144: @cindex port representing an IPC space
2145: @deftp {Data type} ipc_space_t
2146: This is a @code{task_t} (and as such a @code{mach_port_t}), which holds
2147: a port name associated with a port that represents an IPC space in the
2148: kernel. An IPC space is used by the kernel to manage the port names and
2149: rights available to a task. The IPC space doesn't get a port name of
2150: its own. Instead the port name of the task containing the IPC space is
2151: used to name the IPC space of the task (as is indicated by the fact that
2152: the type of @code{ipc_space_t} is actually @code{task_t}).
2153:
2154: The IPC spaces of tasks are the only ones accessible outside of
2155: the kernel.
2156: @end deftp
2157:
2158: @menu
2159: * Port Creation:: How to create new ports and port sets.
2160: * Port Destruction:: How to destroy ports and port sets.
2161: * Port Names:: How to query and manipulate port names.
2162: * Port Rights:: How to work with port rights.
2163: * Ports and other Tasks:: How to move rights between tasks.
2164: * Receive Rights:: How to work with receive rights.
2165: * Port Sets:: How to work with port sets.
2166: * Request Notifications:: How to request notifications for events.
2167: @c * Inherited Ports:: How to work with the inherited system ports.
2168: @end menu
2169:
2170:
2171: @node Port Creation
2172: @subsection Port Creation
2173:
2174: @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}})
2175: The @code{mach_port_allocate} function creates a new right in the
2176: specified task. The new right's name is returned in @var{name}, which
2177: may be any name that wasn't in use.
2178:
2179: The @var{right} argument takes the following values:
2180:
2181: @table @code
2182: @item MACH_PORT_RIGHT_RECEIVE
2183: @code{mach_port_allocate} creates a port. The new port is not a member
2184: of any port set. It doesn't have any extant send or send-once rights.
2185: Its make-send count is zero, its sequence number is zero, its queue
2186: limit is @code{MACH_PORT_QLIMIT_DEFAULT}, and it has no queued messages.
2187: @var{name} denotes the receive right for the new port.
2188:
2189: @var{task} does not hold send rights for the new port, only the receive
2190: right. @code{mach_port_insert_right} and @code{mach_port_extract_right}
2191: can be used to convert the receive right into a combined send/receive
2192: right.
2193:
2194: @item MACH_PORT_RIGHT_PORT_SET
2195: @code{mach_port_allocate} creates a port set. The new port set has no
2196: members.
2197:
2198: @item MACH_PORT_RIGHT_DEAD_NAME
2199: @code{mach_port_allocate} creates a dead name. The new dead name has
2200: one user reference.
2201: @end table
2202:
2203: The function returns @code{KERN_SUCCESS} if the call succeeded,
2204: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2205: @code{KERN_INVALID_VALUE} if @var{right} was invalid, @code{KERN_NO_SPACE} if
2206: there was no room in @var{task}'s IPC name space for another right and
2207: @code{KERN_RESOURCE_SHORTAGE} if the kernel ran out of memory.
2208:
2209: The @code{mach_port_allocate} call is actually an RPC to @var{task},
2210: normally a send right for a task port, but potentially any send right.
2211: In addition to the normal diagnostic return codes from the call's server
2212: (normally the kernel), the call may return @code{mach_msg} return codes.
2213: @end deftypefun
2214:
2215: @deftypefun mach_port_t mach_reply_port ()
2216: The @code{mach_reply_port} system call creates a reply port in the
2217: calling task.
2218:
2219: @code{mach_reply_port} creates a port, giving the calling task the
2220: receive right for the port. The call returns the name of the new
2221: receive right.
2222:
2223: This is very much like creating a receive right with the
2224: @code{mach_port_allocate} call, with two differences. First,
2225: @code{mach_reply_port} is a system call and not an RPC (which requires a
2226: reply port). Second, the port created by @code{mach_reply_port} may be
2227: optimized for use as a reply port.
2228:
2229: The function returns @code{MACH_PORT_NULL} if a resource shortage
2230: prevented the creation of the receive right.
2231: @end deftypefun
2232:
2233: @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}})
2234: The function @code{mach_port_allocate_name} creates a new right in the
2235: specified task, with a specified name for the new right. @var{name}
2236: must not already be in use for some right, and it can't be the reserved
2237: values @code{MACH_PORT_NULL} and @code{MACH_PORT_DEAD}.
2238:
2239: The @var{right} argument takes the following values:
2240:
2241: @table @code
2242: @item MACH_PORT_RIGHT_RECEIVE
2243: @code{mach_port_allocate_name} creates a port. The new port is not a
2244: member of any port set. It doesn't have any extant send or send-once
2245: rights. Its make-send count is zero, its sequence number is zero, its
2246: queue limit is @code{MACH_PORT_QLIMIT_DEFAULT}, and it has no queued
2247: messages. @var{name} denotes the receive right for the new port.
2248:
2249: @var{task} does not hold send rights for the new port, only the receive
2250: right. @code{mach_port_insert_right} and @code{mach_port_extract_right}
2251: can be used to convert the receive right into a combined send/receive
2252: right.
2253:
2254: @item MACH_PORT_RIGHT_PORT_SET
2255: @code{mach_port_allocate_name} creates a port set. The new port set has
2256: no members.
2257:
2258: @item MACH_PORT_RIGHT_DEAD_NAME
2259: @code{mach_port_allocate_name} creates a new dead name. The new dead
2260: name has one user reference.
2261: @end table
2262:
2263: The function returns @code{KERN_SUCCESS} if the call succeeded,
2264: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2265: @code{KERN_INVALID_VALUE} if @var{right} was invalid or @var{name} was
2266: @code{MACH_PORT_NULL} or @code{MACH_PORT_DEAD}, @code{KERN_NAME_EXISTS}
2267: if @var{name} was already in use for a port right and
2268: @code{KERN_RESOURCE_SHORTAGE} if the kernel ran out of memory.
2269:
2270: The @code{mach_port_allocate_name} call is actually an RPC to
2271: @var{task}, normally a send right for a task port, but potentially any
2272: send right. In addition to the normal diagnostic return codes from the
2273: call's server (normally the kernel), the call may return @code{mach_msg}
2274: return codes.
2275: @end deftypefun
2276:
2277:
2278: @node Port Destruction
2279: @subsection Port Destruction
2280:
2281: @deftypefun kern_return_t mach_port_deallocate (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}})
2282: The function @code{mach_port_deallocate} releases a user reference for a
2283: right in @var{task}'s IPC name space. It allows a task to release a
2284: user reference for a send or send-once right without failing if the port
2285: has died and the right is now actually a dead name.
2286:
2287: If @var{name} denotes a dead name, send right, or send-once right, then
2288: the right loses one user reference. If it only had one user reference,
2289: then the right is destroyed.
2290:
2291: The function returns @code{KERN_SUCCESS} if the call succeeded,
2292: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2293: @code{KERN_INVALID_NAME} if @var{name} did not denote a right and
2294: @code{KERN_INVALID_RIGHT} if @var{name} denoted an invalid right.
2295:
2296: The @code{mach_port_deallocate} call is actually an RPC to
2297: @var{task}, normally a send right for a task port, but potentially any
2298: send right. In addition to the normal diagnostic return codes from the
2299: call's server (normally the kernel), the call may return @code{mach_msg}
2300: return codes.
2301: @end deftypefun
2302:
2303: @deftypefun kern_return_t mach_port_destroy (@w{ipc_space_t @var{task}}, @w{mach_port_t @var{name}})
2304: The function @code{mach_port_destroy} deallocates all rights denoted by
2305: a name. The name becomes immediately available for reuse.
2306:
2307: For most purposes, @code{mach_port_mod_refs} and
2308: @code{mach_port_deallocate} are preferable.
2309:
2310: If @var{name} denotes a port set, then all members of the port set are
2311: implicitly removed from the port set.
2312:
2313: If @var{name} denotes a receive right that is a member of a port set,
2314: the receive right is implicitly removed from the port set. If there is
2315: a port-destroyed request registered for the port, then the receive right
2316: is not actually destroyed, but instead is sent in a port-destroyed
2317: notification to the backup port. If there is no registered
2318: port-destroyed request, remaining messages queued to the port are
2319: destroyed and extant send and send-once rights turn into dead names. If
2320: those send and send-once rights have dead-name requests registered, then
2321: dead-name notifications are generated for them.
2322:
2323: If @var{name} denotes a send-once right, then the send-once right is
2324: used to produce a send-once notification for the port.
2325:
2326: If @var{name} denotes a send-once, send, and/or receive right, and it
2327: has a dead-name request registered, then the registered send-once right
2328: is used to produce a port-deleted notification for the name.
2329:
2330: The function returns @code{KERN_SUCCESS} if the call succeeded,
2331: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2332: @code{KERN_INVALID_NAME} if @var{name} did not denote a right.
2333:
2334: The @code{mach_port_destroy} call is actually an RPC to
2335: @var{task}, normally a send right for a task port, but potentially any
2336: send right. In addition to the normal diagnostic return codes from the
2337: call's server (normally the kernel), the call may return @code{mach_msg}
2338: return codes.
2339: @end deftypefun
2340:
2341:
2342: @node Port Names
2343: @subsection Port Names
2344:
2345: @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}})
2346: The function @code{mach_port_names} returns information about
2347: @var{task}'s port name space. For each name, it also returns what type
2348: of rights @var{task} holds. (The same information returned by
2349: @code{mach_port_type}.) @var{names} and @var{types} are arrays that are
2350: automatically allocated when the reply message is received. The user
2351: should @code{vm_deallocate} them when the data is no longer needed.
2352:
2353: @code{mach_port_names} will return in @var{names} the names of the
2354: ports, port sets, and dead names in the task's port name space, in no
2355: particular order and in @var{ncount} the number of names returned. It
2356: will return in @var{types} the type of each corresponding name, which
2357: indicates what kind of rights the task holds with that name.
2358: @var{tcount} should be the same as @var{ncount}.
2359:
2360: The function returns @code{KERN_SUCCESS} if the call succeeded,
2361: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2362: @code{KERN_RESOURCE_SHORTAGE} if the kernel ran out of memory.
2363:
2364: The @code{mach_port_names} call is actually an RPC to @var{task},
2365: normally a send right for a task port, but potentially any send right.
2366: In addition to the normal diagnostic return codes from the call's server
2367: (normally the kernel), the call may return @code{mach_msg} return codes.
2368: @end deftypefun
2369:
2370: @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}})
2371: The function @code{mach_port_type} returns information about
2372: @var{task}'s rights for a specific name in its port name space. The
2373: returned @var{ptype} is a bitmask indicating what rights @var{task}
2374: holds for the port, port set or dead name. The bitmask is composed of
2375: the following bits:
2376:
2377: @table @code
2378: @item MACH_PORT_TYPE_SEND
2379: The name denotes a send right.
2380:
2381: @item MACH_PORT_TYPE_RECEIVE
2382: The name denotes a receive right.
2383:
2384: @item MACH_PORT_TYPE_SEND_ONCE
2385: The name denotes a send-once right.
2386:
2387: @item MACH_PORT_TYPE_PORT_SET
2388: The name denotes a port set.
2389:
2390: @item MACH_PORT_TYPE_DEAD_NAME
2391: The name is a dead name.
2392:
2393: @item MACH_PORT_TYPE_DNREQUEST
2394: A dead-name request has been registered for the right.
2395:
2396: @item MACH_PORT_TYPE_MAREQUEST
2397: A msg-accepted request for the right is pending.
2398:
2399: @item MACH_PORT_TYPE_COMPAT
2400: The port right was created in the compatibility mode.
2401: @end table
2402:
2403: The function returns @code{KERN_SUCCESS} if the call succeeded,
2404: @code{KERN_INVALID_TASK} if @var{task} was invalid and
2405: @code{KERN_INVALID_NAME} if @var{name} did not denote a right.
2406:
2407: The @code{mach_port_type} call is actually an RPC to @var{task},
2408: normally a send right for a task port, but potentially any send right.
2409: In addition to the normal diagnostic return codes from the call's server
2410: (normally the kernel), the call may return @code{mach_msg} return codes.
2411: @end deftypefun
2412:
2413: @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}})
2414: The function @code{mach_port_rename} changes the name by which a port,
2415: port set, or dead name is known to @var{task}. @var{old_name} is the
2416: original name and @var{new_name} the new name for the port right.
2417: @var{new_name} must not already be in use, and it can't be the
2418: distinguished values @code{MACH_PORT_NULL} and @code{MACH_PORT_DEAD}.
2419:
2420: The function returns @code{KERN_SUCCESS} if the call succeeded,
2421: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2422: @code{KERN_INVALID_NAME} if @var{old_name} did not denote a right,
2423: @code{KERN_INVALID_VALUE} if @var{new_name} was @code{MACH_PORT_NULL} or
2424: @code{MACH_PORT_DEAD}, @code{KERN_NAME_EXISTS} if @code{new_name}
2425: already denoted a right and @code{KERN_RESOURCE_SHORTAGE} if the kernel
2426: ran out of memory.
2427:
2428: The @code{mach_port_rename} call is actually an RPC to @var{task},
2429: normally a send right for a task port, but potentially any send right.
2430: In addition to the normal diagnostic return codes from the call's server
2431: (normally the kernel), the call may return @code{mach_msg} return codes.
2432: @end deftypefun
2433:
2434:
2435: @node Port Rights
2436: @subsection Port Rights
2437:
2438: @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}})
2439: The function @code{mach_port_get_refs} returns the number of user
2440: references a task has for a right.
2441:
2442: The @var{right} argument takes the following values:
2443: @itemize @bullet
2444: @item @code{MACH_PORT_RIGHT_SEND}
2445: @item @code{MACH_PORT_RIGHT_RECEIVE}
2446: @item @code{MACH_PORT_RIGHT_SEND_ONCE}
2447: @item @code{MACH_PORT_RIGHT_PORT_SET}
2448: @item @code{MACH_PORT_RIGHT_DEAD_NAME}
2449: @end itemize
2450:
2451: If @var{name} denotes a right, but not the type of right specified, then
2452: zero is returned. Otherwise a positive number of user references is
2453: returned. Note that a name may simultaneously denote send and receive
2454: rights.
2455:
2456: The function returns @code{KERN_SUCCESS} if the call succeeded,
2457: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2458: @code{KERN_INVALID_VALUE} if @var{right} was invalid and
2459: @code{KERN_INVALID_NAME} if @var{name} did not denote a right.
2460:
2461: The @code{mach_port_get_refs} call is actually an RPC to @var{task},
2462: normally a send right for a task port, but potentially any send right.
2463: In addition to the normal diagnostic return codes from the call's server
2464: (normally the kernel), the call may return @code{mach_msg} return codes.
2465: @end deftypefun
2466:
2467: @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}})
2468: The function @code{mach_port_mod_refs} requests that the number of user
2469: references a task has for a right be changed. This results in the right
2470: being destroyed, if the number of user references is changed to zero.
2471: The task holding the right is @var{task}, @var{name} should denote the
2472: specified right. @var{right} denotes the type of right being modified.
2473: @var{delta} is the signed change to the number of user references.
2474:
2475: The @var{right} argument takes the following values:
2476: @itemize @bullet
2477: @item @code{MACH_PORT_RIGHT_SEND}
2478: @item @code{MACH_PORT_RIGHT_RECEIVE}
2479: @item @code{MACH_PORT_RIGHT_SEND_ONCE}
2480: @item @code{MACH_PORT_RIGHT_PORT_SET}
2481: @item @code{MACH_PORT_RIGHT_DEAD_NAME}
2482: @end itemize
2483:
2484: The number of user references for the right is changed by the amount
2485: @var{delta}, subject to the following restrictions: port sets, receive
2486: rights, and send-once rights may only have one user reference. The
2487: resulting number of user references can't be negative. If the resulting
2488: number of user references is zero, the effect is to deallocate the
2489: right. For dead names and send rights, there is an
2490: implementation-defined maximum number of user references.
2491:
2492: If the call destroys the right, then the effect is as described for
2493: @code{mach_port_destroy}, with the exception that
2494: @code{mach_port_destroy} simultaneously destroys all the rights denoted
2495: by a name, while @code{mach_port_mod_refs} can only destroy one right.
2496: The name will be available for reuse if it only denoted the one right.
2497:
2498: The function returns @code{KERN_SUCCESS} if the call succeeded,
2499: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2500: @code{KERN_INVALID_VALUE} if @var{right} was invalid or the
2501: user-reference count would become negative, @code{KERN_INVALID_NAME} if
2502: @var{name} did not denote a right, @code{KERN_INVALID_RIGHT} if
2503: @var{name} denoted a right, but not the specified right and
2504: @code{KERN_UREFS_OVERFLOW} if the user-reference count would overflow.
2505:
2506: The @code{mach_port_mod_refs} call is actually an RPC to @var{task},
2507: normally a send right for a task port, but potentially any send right.
2508: In addition to the normal diagnostic return codes from the call's server
2509: (normally the kernel), the call may return @code{mach_msg} return codes.
2510: @end deftypefun
2511:
2512:
2513: @node Ports and other Tasks
2514: @subsection Ports and other Tasks
2515:
2516: @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}})
2517: The function @var{mach_port_insert_right} inserts into @var{task} the
2518: caller's right for a port, using a specified name for the right in the
2519: target task.
2520:
2521: The specified @var{name} can't be one of the reserved values
2522: @code{MACH_PORT_NULL} or @code{MACH_PORT_DEAD}. The @var{right} can't
2523: be @code{MACH_PORT_NULL} or @code{MACH_PORT_DEAD}.
2524:
2525: The argument @var{right_type} specifies a right to be inserted and how
2526: that right should be extracted from the caller. It should be a value
2527: appropriate for @var{msgt_name}; see @code{mach_msg}. @c XXX cross ref
2528:
2529: If @var{right_type} is @code{MACH_MSG_TYPE_MAKE_SEND},
2530: @code{MACH_MSG_TYPE_MOVE_SEND}, or @code{MACH_MSG_TYPE_COPY_SEND}, then
2531: a send right is inserted. If the target already holds send or receive
2532: rights for the port, then @var{name} should denote those rights in the
2533: target. Otherwise, @var{name} should be unused in the target. If the
2534: target already has send rights, then those send rights gain an
2535: additional user reference. Otherwise, the target gains a send right,
2536: with a user reference count of one.
2537:
2538: If @var{right_type} is @code{MACH_MSG_TYPE_MAKE_SEND_ONCE} or
2539: @code{MACH_MSG_TYPE_MOVE_SEND_ONCE}, then a send-once right is inserted.
2540: The name should be unused in the target. The target gains a send-once
2541: right.
2542:
2543: If @var{right_type} is @code{MACH_MSG_TYPE_MOVE_RECEIVE}, then a receive
2544: right is inserted. If the target already holds send rights for the
2545: port, then name should denote those rights in the target. Otherwise,
2546: name should be unused in the target. The receive right is moved into
2547: the target task.
2548:
2549: The function returns @code{KERN_SUCCESS} if the call succeeded,
2550: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2551: @code{KERN_INVALID_VALUE} if @var{right} was not a port right or
2552: @var{name} was @code{MACH_PORT_NULL} or @code{MACH_PORT_DEAD},
2553: @code{KERN_NAME_EXISTS} if @var{name} already denoted a right,
2554: @code{KERN_INVALID_CAPABILITY} if @var{right} was @code{MACH_PORT_NULL}
2555: or @code{MACH_PORT_DEAD} @code{KERN_RIGHT_EXISTS} if @var{task} already
2556: had rights for the port, with a different name,
2557: @code{KERN_UREFS_OVERFLOW} if the user-reference count would overflow
2558: and @code{KERN_RESOURCE_SHORTAGE} if the kernel ran out of memory.
2559:
2560: The @code{mach_port_insert_right} call is actually an RPC to @var{task},
2561: normally a send right for a task port, but potentially any send right.
2562: In addition to the normal diagnostic return codes from the call's server
2563: (normally the kernel), the call may return @code{mach_msg} return codes.
2564: @end deftypefun
2565:
2566: @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}})
2567: The function @var{mach_port_extract_right} extracts a port right from
2568: the target @var{task} and returns it to the caller as if the task sent
2569: the right voluntarily, using @var{desired_type} as the value of
2570: @var{msgt_name}. @xref{Mach Message Call}.
2571:
2572: The returned value of @var{acquired_type} will be
2573: @code{MACH_MSG_TYPE_PORT_SEND} if a send right is extracted,
2574: @code{MACH_MSG_TYPE_PORT_RECEIVE} if a receive right is extracted, and
2575: @code{MACH_MSG_TYPE_PORT_SEND_ONCE} if a send-once right is extracted.
2576:
2577: The function returns @code{KERN_SUCCESS} if the call succeeded,
2578: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2579: @code{KERN_INVALID_NAME} if @var{name} did not denote a right,
2580: @code{KERN_INVALID_RIGHT} if @var{name} denoted a right, but an invalid one,
2581: @code{KERN_INVALID_VALUE} if @var{desired_type} was invalid.
2582:
2583: The @code{mach_port_extract_right} call is actually an RPC to
2584: @var{task}, normally a send right for a task port, but potentially any
2585: send right. In addition to the normal diagnostic return codes from the
2586: call's server (normally the kernel), the call may return @code{mach_msg}
2587: return codes.
2588: @end deftypefun
2589:
2590:
2591: @node Receive Rights
2592: @subsection Receive Rights
2593:
2594: @deftp {Data type} mach_port_seqno_t
2595: The @code{mach_port_seqno_t} data type is an @code{unsigned int} which
2596: contains the sequence number of a port.
2597: @end deftp
2598:
2599: @deftp {Data type} mach_port_mscount_t
2600: The @code{mach_port_mscount_t} data type is an @code{unsigned int} which
2601: contains the make-send count for a port.
2602: @end deftp
2603:
2604: @deftp {Data type} mach_port_msgcount_t
2605: The @code{mach_port_msgcount_t} data type is an @code{unsigned int} which
2606: contains a number of messages.
2607: @end deftp
2608:
2609: @deftp {Data type} mach_port_rights_t
2610: The @code{mach_port_rights_t} data type is an @code{unsigned int} which
2611: contains a number of rights for a port.
2612: @end deftp
2613:
2614: @deftp {Data type} mach_port_status_t
2615: This structure contains some status information about a port, which can
2616: be queried with @code{mach_port_get_receive_status}. It has the following
2617: members:
2618:
2619: @table @code
2620: @item mach_port_t mps_pset
2621: The containing port set.
2622:
2623: @item mach_port_seqno_t mps_seqno
2624: The sequence number.
2625:
2626: @item mach_port_mscount_t mps_mscount
2627: The make-send count.
2628:
2629: @item mach_port_msgcount_t mps_qlimit
2630: The maximum number of messages in the queue.
2631:
2632: @item mach_port_msgcount_t mps_msgcount
2633: The current number of messages in the queue.
2634:
2635: @item mach_port_rights_t mps_sorights
2636: The number of send-once rights that exist.
2637:
2638: @item boolean_t mps_srights
2639: @code{TRUE} if send rights exist.
2640:
2641: @item boolean_t mps_pdrequest
2642: @code{TRUE} if port-deleted notification is requested.
2643:
2644: @item boolean_t mps_nsrequest
2645: @code{TRUE} if no-senders notification is requested.
2646: @end table
2647: @end deftp
2648:
2649: @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}})
2650: The function @code{mach_port_get_receive_status} returns the current
2651: status of the specified receive right.
2652:
2653: The function returns @code{KERN_SUCCESS} if the call succeeded,
2654: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2655: @code{KERN_INVALID_NAME} if @var{name} did not denote a right and
2656: @code{KERN_INVALID_RIGHT} if @var{name} denoted a right, but not a
2657: receive right.
2658:
2659: The @code{mach_port_get_receive_status} call is actually an RPC to @var{task},
2660: normally a send right for a task port, but potentially any send right.
2661: In addition to the normal diagnostic return codes from the call's server
2662: (normally the kernel), the call may return @code{mach_msg} return codes.
2663: @end deftypefun
2664:
2665: @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}})
2666: The function @code{mach_port_set_mscount} changes the make-send count of
2667: @var{task}'s receive right named @var{name} to @var{mscount}. All
2668: values for @var{mscount} are valid.
2669:
2670: The function returns @code{KERN_SUCCESS} if the call succeeded,
2671: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2672: @code{KERN_INVALID_NAME} if @var{name} did not denote a right and
2673: @code{KERN_INVALID_RIGHT} if @var{name} denoted a right, but not a
2674: receive right.
2675:
2676: The @code{mach_port_set_mscount} call is actually an RPC to @var{task},
2677: normally a send right for a task port, but potentially any send right.
2678: In addition to the normal diagnostic return codes from the call's server
2679: (normally the kernel), the call may return @code{mach_msg} return codes.
2680: @end deftypefun
2681:
2682: @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}})
2683: The function @code{mach_port_set_qlimit} changes the queue limit
2684: @var{task}'s receive right named @var{name} to @var{qlimit}. Valid
2685: values for @var{qlimit} are between zero and
2686: @code{MACH_PORT_QLIMIT_MAX}, inclusive.
2687:
2688: The function returns @code{KERN_SUCCESS} if the call succeeded,
2689: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2690: @code{KERN_INVALID_NAME} if @var{name} did not denote a right,
2691: @code{KERN_INVALID_RIGHT} if @var{name} denoted a right, but not a
2692: receive right and @code{KERN_INVALID_VALUE} if @var{qlimit} was invalid.
2693:
2694: The @code{mach_port_set_qlimit} call is actually an RPC to @var{task},
2695: normally a send right for a task port, but potentially any send right.
2696: In addition to the normal diagnostic return codes from the call's server
2697: (normally the kernel), the call may return @code{mach_msg} return codes.
2698: @end deftypefun
2699:
2700: @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}})
2701: The function @code{mach_port_set_seqno} changes the sequence number
2702: @var{task}'s receive right named @var{name} to @var{seqno}. All
2703: sequence number values are valid. The next message received from the
2704: port will be stamped with the specified sequence number.
2705:
2706: The function returns @code{KERN_SUCCESS} if the call succeeded,
2707: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2708: @code{KERN_INVALID_NAME} if @var{name} did not denote a right and
2709: @code{KERN_INVALID_RIGHT} if @var{name} denoted a right, but not a
2710: receive right.
2711:
2712: The @code{mach_port_set_seqno} call is actually an RPC to @var{task},
2713: normally a send right for a task port, but potentially any send right.
2714: In addition to the normal diagnostic return codes from the call's server
2715: (normally the kernel), the call may return @code{mach_msg} return codes.
2716: @end deftypefun
2717:
2718:
2719: @node Port Sets
2720: @subsection Port Sets
2721:
2722: @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}})
2723: The function @code{mach_port_get_set_status} returns the members of a
2724: port set. @var{members} is an array that is automatically allocated
2725: when the reply message is received. The user should
2726: @code{vm_deallocate} it when the data is no longer needed.
2727:
2728: The function returns @code{KERN_SUCCESS} if the call succeeded,
2729: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2730: @code{KERN_INVALID_NAME} if @var{name} did not denote a right,
2731: @code{KERN_INVALID_RIGHT} if @var{name} denoted a right, but not a
2732: receive right and @code{KERN_RESOURCE_SHORTAGE} if the kernel ran out of
2733: memory.
2734:
2735: The @code{mach_port_get_set_status} call is actually an RPC to
2736: @var{task}, normally a send right for a task port, but potentially any
2737: send right. In addition to the normal diagnostic return codes from the
2738: call's server (normally the kernel), the call may return @code{mach_msg}
2739: return codes.
2740: @end deftypefun
2741:
2742: @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}})
2743: The function @var{mach_port_move_member} moves the receive right
2744: @var{member} into the port set @var{after}. If the receive right is
2745: already a member of another port set, it is removed from that set first
2746: (the whole operation is atomic). If the port set is
2747: @code{MACH_PORT_NULL}, then the receive right is not put into a port
2748: set, but removed from its current port set.
2749:
2750: The function returns @code{KERN_SUCCESS} if the call succeeded,
2751: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2752: @code{KERN_INVALID_NAME} if @var{member} or @var{after} did not denote a
2753: right, @code{KERN_INVALID_RIGHT} if @var{member} denoted a right, but
2754: not a receive right or @var{after} denoted a right, but not a port set,
2755: and @code{KERN_NOT_IN_SET} if @var{after} was @code{MACH_PORT_NULL}, but
2756: @code{member} wasn't currently in a port set.
2757:
2758: The @code{mach_port_move_member} call is actually an RPC to @var{task},
2759: normally a send right for a task port, but potentially any send right.
2760: In addition to the normal diagnostic return codes from the call's server
2761: (normally the kernel), the call may return @code{mach_msg} return codes.
2762: @end deftypefun
2763:
2764:
2765: @node Request Notifications
2766: @subsection Request Notifications
2767:
2768: @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}})
2769: The function @code{mach_port_request_notification} registers a request
2770: for a notification and supplies the send-once right @var{notify} to
2771: which the notification will be sent. The @var{notify_type} denotes the
2772: IPC type for the send-once right, which can be
2773: @code{MACH_MSG_TYPE_MAKE_SEND_ONCE} or
2774: @code{MACH_MSG_TYPE_MOVE_SEND_ONCE}. It is an atomic swap, returning
2775: the previously registered send-once right (or @code{MACH_PORT_NULL} for
2776: none) in @var{previous}. A previous notification request may be
2777: cancelled by providing @code{MACH_PORT_NULL} for @var{notify}.
2778:
2779: The @var{variant} argument takes the following values:
2780:
2781: @table @code
2782: @item MACH_NOTIFY_PORT_DESTROYED
2783: @var{sync} must be zero. The @var{name} must specify a receive right,
2784: and the call requests a port-destroyed notification for the receive
2785: right. If the receive right were to have been destroyed, say by
2786: @code{mach_port_destroy}, then instead the receive right will be sent in
2787: a port-destroyed notification to the registered send-once right.
2788:
2789: @item MACH_NOTIFY_DEAD_NAME
2790: The call requests a dead-name notification. @var{name} specifies send,
2791: receive, or send-once rights for a port. If the port is destroyed (and
2792: the right remains, becoming a dead name), then a dead-name notification
2793: which carries the name of the right will be sent to the registered
2794: send-once right. If @var{notify} is not null and sync is non-zero, the
2795: name may specify a dead name, and a dead-name notification is
2796: immediately generated.
2797:
2798: Whenever a dead-name notification is generated, the user reference count
2799: of the dead name is incremented. For example, a send right with two
2800: user refs has a registered dead-name request. If the port is destroyed,
2801: the send right turns into a dead name with three user refs (instead of
2802: two), and a dead-name notification is generated.
2803:
2804: If the name is made available for reuse, perhaps because of
2805: @code{mach_port_destroy} or @code{mach_port_mod_refs}, or the name
2806: denotes a send-once right which has a message sent to it, then the
2807: registered send-once right is used to generate a port-deleted
2808: notification.
2809:
2810: @item MACH_NOTIFY_NO_SENDERS
2811: The call requests a no-senders notification. @var{name} must specify a
2812: receive right. If @var{notify} is not null, and the receive right's
2813: make-send count is greater than or equal to the sync value, and it has
2814: no extant send rights, than an immediate no-senders notification is
2815: generated. Otherwise the notification is generated when the receive
2816: right next loses its last extant send right. In either case, any
2817: previously registered send-once right is returned.
2818:
2819: The no-senders notification carries the value the port's make-send count
2820: had when it was generated. The make-send count is incremented whenever
2821: @code{MACH_MSG_TYPE_MAKE_SEND} is used to create a new send right from
2822: the receive right. The make-send count is reset to zero when the
2823: receive right is carried in a message.
2824: @end table
2825:
2826: The function returns @code{KERN_SUCCESS} if the call succeeded,
2827: @code{KERN_INVALID_TASK} if @var{task} was invalid,
2828: @code{KERN_INVALID_VALUE} if @var{variant} was invalid,
2829: @code{KERN_INVALID_NAME} if @var{name} did not denote a right,
2830: @code{KERN_INVALID_RIGHT} if @var{name} denoted an invalid right and
2831: @code{KERN_INVALID_CAPABILITY} if @var{notify} was invalid.
2832:
2833: When using @code{MACH_NOTIFY_PORT_DESTROYED}, the function returns
2834: @code{KERN_INVALID_VALUE} if @var{sync} wasn't zero.
2835:
2836: When using @code{MACH_NOTIFY_DEAD_NAME}, the function returns
2837: @code{KERN_RESOURCE_SHORTAGE} if the kernel ran out of memory,
2838: @code{KERN_INVALID_ARGUMENT} if @var{name} denotes a dead name, but
2839: @var{sync} is zero or @var{notify} is @code{MACH_PORT_NULL}, and
2840: @code{KERN_UREFS_OVERFLOW} if @var{name} denotes a dead name, but
2841: generating an immediate dead-name notification would overflow the name's
2842: user-reference count.
2843:
2844: The @code{mach_port_request_notification} call is actually an RPC to
2845: @var{task}, normally a send right for a task port, but potentially any
2846: send right. In addition to the normal diagnostic return codes from the
2847: call's server (normally the kernel), the call may return @code{mach_msg}
2848: return codes.
2849: @end deftypefun
2850:
2851: @c The inherited ports concept is not used in the Hurd,
2852: @c and so the _SLOT macros are not defined in GNU Mach.
2853:
2854: @c @node Inherited Ports
2855: @c @subsection Inherited Ports
2856:
2857: @c @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}})
2858: @c @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}})
2859: @c @code{mach_ports_register} manipulates the inherited ports array,
2860: @c @code{mach_ports_lookup} is used to acquire specific parent ports.
2861: @c @var{target_task} is the task to be affected. @var{init_port_set} is an
2862: @c array of system ports to be registered, or returned. Although the array
2863: @c size is given as variable, the kernel will only accept a limited number
2864: @c of ports. @var{init_port_array_count} is the number of ports returned
2865: @c in @var{init_port_set}.
2866:
2867: @c @code{mach_ports_register} registers an array of well-known system ports
2868: @c with the kernel on behalf of a specific task. Currently the ports to be
2869: @c registered are: the port to the Network Name Server, the port to the
2870: @c Environment Manager, and a port to the Service server. These port
2871: @c values must be placed in specific slots in the init_port_set. The slot
2872: @c numbers are given by the global constants defined in @file{mach_init.h}:
2873: @c @code{NAME_SERVER_SLOT}, @code{ENVIRONMENT_SLOT}, and
2874: @c @code{SERVICE_SLOT}. These ports may later be retrieved with
2875: @c @code{mach_ports_lookup}.
2876:
2877: @c When a new task is created (see @code{task_create}), the child task will
2878: @c be given access to these ports. Only port send rights may be
2879: @c registered. Furthermore, the number of ports which may be registered is
2880: @c fixed and given by the global constant @code{MACH_PORT_SLOTS_USED}
2881: @c Attempts to register too many ports will fail.
2882:
2883: @c It is intended that this mechanism be used only for task initialization,
2884: @c and then only by runtime support modules. A parent task has three
2885: @c choices in passing these system ports to a child task. Most commonly it
2886: @c can do nothing and its child will inherit access to the same
2887: @c @var{init_port_set} that the parent has; or a parent task may register a
2888: @c set of ports it wishes to have passed to all of its children by calling
2889: @c @code{mach_ports_register} using its task port; or it may make necessary
2890: @c modifications to the set of ports it wishes its child to see, and then
2891: @c register those ports using the child's task port prior to starting the
2892: @c child's thread(s). The @code{mach_ports_lookup} call which is done by
2893: @c @code{mach_init} in the child task will acquire these initial ports for
2894: @c the child.
2895:
1.1.1.2 ! root 2896: @c Tasks other than the Network Name Server and the Environment Manager
1.1 root 2897: @c should not need access to the Service port. The Network Name Server port
2898: @c is the same for all tasks on a given machine. The Environment port is
2899: @c the only port likely to have different values for different tasks.
2900:
2901: @c Since the number of ports which may be registered is limited, ports
2902: @c other than those used by the runtime system to initialize a task should
2903: @c be passed to children either through an initial message, or through the
2904: @c Network Name Server for public ports, or the Environment Manager for
2905: @c private ports.
2906:
2907: @c The function returns @code{KERN_SUCCESS} if the memory was allocated,
2908: @c and @code{KERN_INVALID_ARGUMENT} if an attempt was made to register more
2909: @c ports than the current kernel implementation allows.
2910: @c @end deftypefun
2911:
2912:
2913: @node Virtual Memory Interface
2914: @chapter Virtual Memory Interface
2915:
2916: @cindex virtual memory map port
2917: @cindex port representing a virtual memory map
2918: @deftp {Data type} vm_task_t
2919: This is a @code{task_t} (and as such a @code{mach_port_t}), which holds
2920: a port name associated with a port that represents a virtual memory map
2921: in the kernel. An virtual memory map is used by the kernel to manage
2922: the address space of a task. The virtual memory map doesn't get a port
2923: name of its own. Instead the port name of the task provided with the
2924: virtual memory is used to name the virtual memory map of the task (as is
2925: indicated by the fact that the type of @code{vm_task_t} is actually
2926: @code{task_t}).
2927:
2928: The virtual memory maps of tasks are the only ones accessible outside of
2929: the kernel.
2930: @end deftp
2931:
2932: @menu
2933: * Memory Allocation:: Allocation of new virtual memory.
2934: * Memory Deallocation:: Freeing unused virtual memory.
2935: * Data Transfer:: Reading, writing and copying memory.
2936: * Memory Attributes:: Tweaking memory regions.
2937: * Mapping Memory Objects:: How to map memory objects.
2938: * Memory Statistics:: How to get statistics about memory usage.
2939: @end menu
2940:
2941: @node Memory Allocation
2942: @section Memory Allocation
2943:
2944: @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}})
2945: The function @code{vm_allocate} allocates a region of virtual memory,
2946: placing it in the specified @var{task}'s address space.
2947:
2948: The starting address is @var{address}. If the @var{anywhere} option is
2949: false, an attempt is made to allocate virtual memory starting at this
2950: virtual address. If this address is not at the beginning of a virtual
2951: page, it will be rounded down to one. If there is not enough space at
2952: this address, no memory will be allocated. If the @var{anywhere} option
2953: is true, the input value of this address will be ignored, and the space
2954: will be allocated wherever it is available. In either case, the address
2955: at which memory was actually allocated will be returned in
2956: @var{address}.
2957:
2958: @var{size} is the number of bytes to allocate (rounded by the system in
2959: a machine dependent way to an integral number of virtual pages).
2960:
2961: If @var{anywhere} is true, the kernel should find and allocate any
2962: region of the specified size, and return the address of the resulting
2963: region in address address, rounded to a virtual page boundary if there
2964: is sufficient space.
2965:
2966: The physical memory is not actually allocated until the new virtual
2967: memory is referenced. By default, the kernel rounds all addresses down
2968: to the nearest page boundary and all memory sizes up to the nearest page
2969: size. The global variable @code{vm_page_size} contains the page size.
2970: @code{mach_task_self} returns the value of the current task port which
2971: should be used as the @var{target_task} argument in order to allocate
2972: memory in the caller's address space. For languages other than C, these
2973: values can be obtained by the calls @code{vm_statistics} and
2974: @code{mach_task_self}. Initially, the pages of allocated memory will be
2975: protected to allow all forms of access, and will be inherited in child
2976: tasks as a copy. Subsequent calls to @code{vm_protect} and
2977: @code{vm_inherit} may be used to change these properties. The allocated
2978: region is always zero-filled.
2979:
2980: The function returns @code{KERN_SUCCESS} if the memory was successfully
2981: allocated, @code{KERN_INVALID_ADDRESS} if an invalid address was
2982: specified and @code{KERN_NO_SPACE} if there was not enough space left to
2983: satisfy the request.
2984: @end deftypefun
2985:
2986:
2987: @node Memory Deallocation
2988: @section Memory Deallocation
2989:
2990: @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}})
2991: @code{vm_deallocate} relinquishes access to a region of a @var{task}'s
2992: address space, causing further access to that memory to fail. This
2993: address range will be available for reallocation. @var{address} is the
2994: starting address, which will be rounded down to a page boundary.
2995: @var{size} is the number of bytes to deallocate, which will be rounded
2996: up to give a page boundary. Note, that because of the rounding to
2997: virtual page boundaries, more than @var{size} bytes may be deallocated.
2998: Use @code{vm_page_size} or @code{vm_statistics} to find out the current
2999: virtual page size.
3000:
1.1.1.2 ! root 3001: This call may be used to deallocate memory that was passed to a task in a
1.1 root 3002: message (via out of line data). In that case, the rounding should cause
3003: no trouble, since the region of memory was allocated as a set of pages.
3004:
3005: The @code{vm_deallocate} call affects only the task specified by the
3006: @var{target_task}. Other tasks which may have access to this memory may
3007: continue to reference it.
3008:
3009: The function returns @code{KERN_SUCCESS} if the memory was successfully
3010: deallocated and @code{KERN_INVALID_ADDRESS} if an invalid or
3011: non-allocated address was specified.
3012: @end deftypefun
3013:
3014:
3015: @node Data Transfer
3016: @section Data Transfer
3017:
3018: @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}})
3019: The function @code{vm_read} allows one task's virtual memory to be read
3020: by another task. The @var{target_task} is the task whose memory is to
3021: be read. @var{address} is the first address to be read and must be on a
3022: page boundary. @var{size} is the number of bytes of data to be read and
3023: must be an integral number of pages. @var{data} is the array of data
3024: copied from the given task, and @var{data_count} is the size of the data
3025: array in bytes (will be an integral number of pages).
3026:
3027: Note that the data array is returned in a newly allocated region; the
3028: task reading the data should @code{vm_deallocate} this region when it is
3029: done with the data.
3030:
3031: The function returns @code{KERN_SUCCESS} if the memory was successfully
3032: read, @code{KERN_INVALID_ADDRESS} if an invalid or non-allocated address
3033: was specified or there was not @var{size} bytes of data following the
3034: address, @code{KERN_INVALID_ARGUMENT} if the address does not start on a
3035: page boundary or the size is not an integral number of pages,
3036: @code{KERN_PROTECTION_FAILURE} if the address region in the target task
3037: is protected against reading and @code{KERN_NO_SPACE} if there was not
3038: enough room in the callers virtual memory to allocate space for the data
3039: to be returned.
3040: @end deftypefun
3041:
3042: @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 3043: The function @code{vm_write} allows a task to write to the virtual memory
1.1 root 3044: of @var{target_task}. @var{address} is the starting address in task to
3045: be affected. @var{data} is an array of bytes to be written, and
3046: @var{data_count} the size of the @var{data} array.
3047:
3048: The current implementation requires that @var{address}, @var{data} and
3049: @var{data_count} all be page-aligned. Otherwise,
3050: @code{KERN_INVALID_ARGUMENT} is returned.
3051:
3052: The function returns @code{KERN_SUCCESS} if the memory was successfully
3053: written, @code{KERN_INVALID_ADDRESS} if an invalid or non-allocated
3054: address was specified or there was not @var{data_count} bytes of
3055: allocated memory starting at @var{address} and
3056: @code{KERN_PROTECTION_FAILURE} if the address region in the target task
3057: is protected against writing.
3058: @end deftypefun
3059:
3060: @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}})
3061: The function @code{vm_copy} causes the source memory range to be copied
3062: to the destination address. The source and destination memory ranges
3063: may overlap. The destination address range must already be allocated
3064: and writable; the source range must be readable.
3065:
3066: @code{vm_copy} is equivalent to @code{vm_read} followed by
3067: @code{vm_write}.
3068:
3069: The current implementation requires that @var{address}, @var{data} and
3070: @var{data_count} all be page-aligned. Otherwise,
3071: @code{KERN_INVALID_ARGUMENT} is returned.
3072:
3073: The function returns @code{KERN_SUCCESS} if the memory was successfully
3074: written, @code{KERN_INVALID_ADDRESS} if an invalid or non-allocated
3075: address was specified or there was insufficient memory allocated at one
3076: of the addresses and @code{KERN_PROTECTION_FAILURE} if the destination
3077: region was not writable or the source region was not readable.
3078: @end deftypefun
3079:
3080:
3081: @node Memory Attributes
3082: @section Memory Attributes
3083:
3084: @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}})
3085: The function @code{vm_region} returns a description of the specified
3086: region of @var{target_task}'s virtual address space. @code{vm_region}
3087: begins at @var{address} and looks forward through memory until it comes
3088: to an allocated region. If address is within a region, then that region
3089: is used. Various bits of information about the region are returned. If
3090: @var{address} was not within a region, then @var{address} is set to the
3091: start of the first region which follows the incoming value. In this way
3092: an entire address space can be scanned.
3093:
3094: The @var{size} returned is the size of the located region in bytes.
3095: @var{protection} is the current protection of the region,
3096: @var{max_protection} is the maximum allowable protection for this
3097: region. @var{inheritance} is the inheritance attribute for this region.
3098: @var{shared} tells if the region is shared or not. The port
3099: @var{object_name} identifies the memory object associated with this
3100: region, and @var{offset} is the offset into the pager object that this
3101: region begins at.
3102: @c XXX cross ref pager_init
3103:
3104: The function returns @code{KERN_SUCCESS} if the memory region was
3105: successfully located and the information returned and @code{KERN_NO_SPACE} if
3106: there is no region at or above @var{address} in the specified task.
3107: @end deftypefun
3108:
3109: @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}})
3110: The function @code{vm_protect} sets the virtual memory access privileges
3111: for a range of allocated addresses in @var{target_task}'s virtual
3112: address space. The protection argument describes a combination of read,
3113: write, and execute accesses that should be @emph{permitted}.
3114:
3115: @var{address} is the starting address, which will be rounded down to a
3116: page boundary. @var{size} is the size in bytes of the region for which
3117: protection is to change, and will be rounded up to give a page boundary.
3118: If @var{set_maximum} is set, make the protection change apply to the
3119: maximum protection associated with this address range; otherwise, the
3120: current protection on this range is changed. If the maximum protection
3121: is reduced below the current protection, both will be changed to reflect
3122: the new maximum. @var{new_protection} is the new protection value for
3123: this region; a set of: @code{VM_PROT_READ}, @code{VM_PROT_WRITE},
3124: @code{VM_PROT_EXECUTE}.
3125:
3126: The enforcement of virtual memory protection is machine-dependent.
3127: Nominally read access requires @code{VM_PROT_READ} permission, write
3128: access requires @code{VM_PROT_WRITE} permission, and execute access
3129: requires @code{VM_PROT_EXECUTE} permission. However, some combinations
3130: of access rights may not be supported. In particular, the kernel
3131: interface allows write access to require @code{VM_PROT_READ} and
3132: @code{VM_PROT_WRITE} permission and execute access to require
3133: @code{VM_PROT_READ} permission.
3134:
3135: The function returns @code{KERN_SUCCESS} if the memory was successfully
3136: protected, @code{KERN_INVALID_ADDRESS} if an invalid or non-allocated
3137: address was specified and @code{KERN_PROTECTION_FAILURE} if an attempt
3138: was made to increase the current or maximum protection beyond the
3139: existing maximum protection value.
3140: @end deftypefun
3141:
3142: @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}})
3143: The function @code{vm_inherit} specifies how a region of
3144: @var{target_task}'s address space is to be passed to child tasks at the
3145: time of task creation. Inheritance is an attribute of virtual pages, so
3146: @var{address} to start from will be rounded down to a page boundary and
1.1.1.2 ! root 3147: @var{size}, the size in bytes of the region for which inheritance is to
1.1 root 3148: change, will be rounded up to give a page boundary. How this memory is
3149: to be inherited in child tasks is specified by @var{new_inheritance}.
3150: Inheritance is specified by using one of these following three values:
3151:
3152: @table @code
3153: @item VM_INHERIT_SHARE
3154: Child tasks will share this memory with this task.
3155:
3156: @item VM_INHERIT_COPY
3157: Child tasks will receive a copy of this region.
3158:
3159: @item VM_INHERIT_NONE
3160: This region will be absent from child tasks.
3161: @end table
3162:
3163: Setting @code{vm_inherit} to @code{VM_INHERIT_SHARE} and forking a child
3164: task is the only way two Mach tasks can share physical memory. Remember
1.1.1.2 ! root 3165: that all the threads of a given task share all the same memory.
1.1 root 3166:
3167: The function returns @code{KERN_SUCCESS} if the memory inheritance was
3168: successfully set and @code{KERN_INVALID_ADDRESS} if an invalid or
3169: non-allocated address was specified.
3170: @end deftypefun
3171:
3172: @deftypefun kern_return_t vm_wire (@w{host_priv_t @var{host_priv}}, @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}})
3173: The function @code{vm_wire} allows privileged applications to control
3174: memory pageability. @var{host_priv} is the privileged host port for the
3175: host on which @var{target_task} resides. @var{address} is the starting
3176: address, which will be rounded down to a page boundary. @var{size} is
3177: the size in bytes of the region for which protection is to change, and
3178: will be rounded up to give a page boundary. @var{access} specifies the
3179: types of accesses that must not cause page faults.
3180:
3181: The semantics of a successful @code{vm_wire} operation are that memory
3182: in the specified range will not cause page faults for any accesses
3183: included in access. Data memory can be made non-pageable (wired) with a
3184: access argument of @code{VM_PROT_READ | VM_PROT_WRITE}. A special case
3185: is that @code{VM_PROT_NONE} makes the memory pageable.
3186:
3187: The function returns @code{KERN_SUCCESS} if the call succeeded,
3188: @code{KERN_INVALID_HOST} if @var{host_priv} was not the privileged host
3189: port, @code{KERN_INVALID_TASK} if @var{task} was not a valid task,
3190: @code{KERN_INVALID_VALUE} if @var{access} specified an invalid access
3191: mode, @code{KERN_FAILURE} if some memory in the specified range is not
3192: present or has an inappropriate protection value, and
3193: @code{KERN_INVALID_ARGUMENT} if unwiring (@var{access} is
3194: @code{VM_PROT_NONE}) and the memory is not already wired.
3195:
3196: The @code{vm_wire} call is actually an RPC to @var{host_priv}, normally
3197: a send right for a privileged host port, but potentially any send right.
3198: In addition to the normal diagnostic return codes from the call's server
3199: (normally the kernel), the call may return @code{mach_msg} return codes.
3200: @end deftypefun
3201:
3202: @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}})
3203: The function @code{vm_machine_attribute} specifies machine-specific
3204: attributes for a VM mapping, such as cachability, migrability,
3205: replicability. This is used on machines that allow the user control
3206: over the cache (this is the case for MIPS architectures) or placement of
3207: memory pages as in NUMA architectures (Non-Uniform Memory Access time)
3208: such as the IBM ACE multiprocessor.
3209:
3210: Machine-specific attributes can be consider additions to the
3211: machine-independent ones such as protection and inheritance, but they
3212: are not guaranteed to be supported by any given machine. Moreover,
3213: implementations of Mach on new architectures might find the need for new
3214: attribute types and or values besides the ones defined in the initial
3215: implementation.
3216:
3217: The types currently defined are
3218: @table @code
3219: @item MATTR_CACHE
3220: Controls caching of memory pages
3221:
3222: @item MATTR_MIGRATE
3223: Controls migrability of memory pages
3224:
3225: @item MATTR_REPLICATE
3226: Controls replication of memory pages
3227: @end table
3228:
3229: Corresponding values, and meaning of a specific call to
3230: @code{vm_machine_attribute}
3231: @table @code
3232: @item MATTR_VAL_ON
3233: Enables the attribute. Being enabled is the default value for any
3234: applicable attribute.
3235:
3236: @item MATTR_VAL_OFF
3237: Disables the attribute, making memory non-cached, or non-migratable, or
3238: non-replicatable.
3239:
3240: @item MATTR_VAL_GET
3241: Returns the current value of the attribute for the memory segment. If
3242: the attribute does not apply uniformly to the given range the value
3243: returned applies to the initial portion of the segment only.
3244:
3245: @item MATTR_VAL_CACHE_FLUSH
3246: Flush the memory pages from the Cache. The size value in this case
3247: might be meaningful even if not a multiple of the page size, depending
3248: on the implementation.
3249:
3250: @item MATTR_VAL_ICACHE_FLUSH
3251: Same as above, applied to the Instruction Cache alone.
3252:
3253: @item MATTR_VAL_DCACHE_FLUSH
3254: Same as above, applied to the Data Cache alone.
3255: @end table
3256:
3257: The function returns @code{KERN_SUCCESS} if call succeeded, and
3258: @code{KERN_INVALID_ARGUMENT} if @var{task} is not a task, or
3259: @var{address} and @var{size} do not define a valid address range in
3260: task, or @var{attribute} is not a valid attribute type, or it is not
3261: implemented, or @var{value} is not a permissible value for attribute.
3262: @end deftypefun
3263:
3264:
3265: @node Mapping Memory Objects
3266: @section Mapping Memory Objects
3267:
3268: @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}})
3269: The function @code{vm_map} maps a region of virtual memory at the
3270: specified address, for which data is to be supplied by the given memory
3271: object, starting at the given offset within that object. In addition to
3272: the arguments used in @code{vm_allocate}, the @code{vm_map} call allows
3273: the specification of an address alignment parameter, and of the initial
3274: protection and inheritance values.
3275: @c XXX See the descriptions of vm_allocate, vm_protect , and vm_inherit
3276:
3277: If the memory object in question is not currently in use, the kernel
3278: will perform a @code{memory_object_init} call at this time. If the copy
3279: parameter is asserted, the specified region of the memory object will be
3280: copied to this address space; changes made to this object by other tasks
3281: will not be visible in this mapping, and changes made in this mapping
3282: will not be visible to others (or returned to the memory object).
3283:
3284: The @code{vm_map} call returns once the mapping is established.
3285: Completion of the call does not require any action on the part of the
3286: memory manager.
3287:
3288: Warning: Only memory objects that are provided by bona fide memory
3289: managers should be used in the @code{vm_map} call. A memory manager
3290: must implement the memory object interface described elsewhere in this
3291: manual. If other ports are used, a thread that accesses the mapped
3292: virtual memory may become permanently hung or may receive a memory
3293: exception.
3294:
3295: @var{target_task} is the task to be affected. The starting address is
3296: @var{address}. If the @var{anywhere} option is used, this address is
3297: ignored. The address actually allocated will be returned in
3298: @var{address}. @var{size} is the number of bytes to allocate (rounded by
3299: the system in a machine dependent way). The alignment restriction is
3300: specified by @var{mask}. Bits asserted in this mask must not be
3301: asserted in the address returned. If @var{anywhere} is set, the kernel
3302: should find and allocate any region of the specified size, and return
3303: the address of the resulting region in @var{address}.
3304:
3305: @var{memory_object} is the port that represents the memory object: used
3306: by user tasks in @code{vm_map}; used by the make requests for data or
3307: other management actions. If this port is @code{MEMORY_OBJECT_NULL},
3308: then zero-filled memory is allocated instead. Within a memory object,
1.1.1.2 ! root 3309: @var{offset} specifies an offset in bytes. This must be page aligned.
1.1 root 3310: If @var{copy} is set, the range of the memory object should be copied to
3311: the target task, rather than mapped read-write.
3312:
3313: The function returns @code{KERN_SUCCESS} if the object is mapped,
3314: @code{KERN_NO_SPACE} if no unused region of the task's virtual address
3315: space that meets the address, size, and alignment criteria could be
3316: found, and @code{KERN_INVALID_ARGUMENT} if an invalid argument was provided.
3317: @end deftypefun
3318:
3319:
3320: @node Memory Statistics
3321: @section Memory Statistics
3322:
3323: @deftp {Data type} vm_statistics_data_t
3324: This structure is returned in @var{vm_stats} by the @code{vm_statistics}
3325: function and provides virtual memory statistics for the system. It has
3326: the following members:
3327:
3328: @table @code
3329: @item long pagesize
3330: The page size in bytes.
3331:
3332: @item long free_count
3333: The number of free pages.
3334:
3335: @item long active_count
3336: The umber of active pages.
3337:
3338: @item long inactive_count
3339: The number of inactive pages.
3340:
3341: @item long wire_count
3342: The number of pages wired down.
3343:
3344: @item long zero_fill_count
3345: The number of zero filled pages.
3346:
3347: @item long reactivations
3348: The number of reactivated pages.
3349:
3350: @item long pageins
3351: The number of pageins.
3352:
3353: @item long pageouts
3354: The number of pageouts.
3355:
3356: @item long faults
3357: The number of faults.
3358:
3359: @item long cow_faults
3360: The number of copy-on-writes.
3361:
3362: @item long lookups
3363: The number of object cache lookups.
3364:
3365: @item long hits
3366: The number of object cache hits.
3367: @end table
3368: @end deftp
3369:
3370: @deftypefun kern_return_t vm_statistics (@w{vm_task_t @var{target_task}}, @w{vm_statistics_data_t *@var{vm_stats}})
3371: The function @code{vm_statistics} returns the statistics about the
3372: kernel's use of virtual memory since the kernel was booted.
3373: @code{pagesize} can also be found as a global variable
3374: @code{vm_page_size} which is set at task initialization and remains
3375: constant for the life of the task.
3376: @end deftypefun
3377:
3378:
3379: @node External Memory Management
3380: @chapter External Memory Management
3381:
3382: @menu
3383: * Memory Object Server:: The basics of external memory management.
3384: * Memory Object Creation:: How new memory objects are created.
3385: * Memory Object Termination:: How memory objects are terminated.
3386: * Memory Objects and Data:: Data transfer to and from memory objects.
3387: * Memory Object Locking:: How memory objects are locked.
3388: * Memory Object Attributes:: Manipulating attributes of memory objects.
3389: * Default Memory Manager:: Setting and using the default memory manager.
3390: @end menu
3391:
3392:
3393: @node Memory Object Server
3394: @section Memory Object Server
3395:
3396: @deftypefun boolean_t memory_object_server (@w{msg_header_t *@var{in_msg}}, @w{msg_header_t *@var{out_msg}})
3397: @deftypefunx boolean_t memory_object_default_server (@w{msg_header_t *@var{in_msg}}, @w{msg_header_t *@var{out_msg}})
3398: @deftypefunx boolean_t seqnos_memory_object_server (@w{msg_header_t *@var{in_msg}}, @w{msg_header_t *@var{out_msg}})
3399: @deftypefunx boolean_t seqnos_memory_object_default_server (@w{msg_header_t *@var{in_msg}}, @w{msg_header_t *@var{out_msg}})
3400: A memory manager is a server task that responds to specific messages
3401: from the kernel in order to handle memory management functions for the
3402: kernel.
3403:
3404: In order to isolate the memory manager from the specifics of message
3405: formatting, the remote procedure call generator produces a procedure,
3406: @code{memory_object_server}, to handle a received message. This
3407: function does all necessary argument handling, and actually calls one of
3408: the following functions: @code{memory_object_init},
3409: @code{memory_object_data_write}, @code{memory_object_data_return},
3410: @code{memory_object_data_request}, @code{memory_object_data_unlock},
3411: @code{memory_object_lock_completed}, @code{memory_object_copy},
3412: @code{memory_object_terminate}. The @strong{default memory manager} may
3413: get two additional requests from the kernel: @code{memory_object_create}
3414: and @code{memory_object_data_initialize}. The remote procedure call
3415: generator produces a procedure @code{memory_object_default_server} to
3416: handle those functions specific to the default memory manager.
3417:
3418: The @code{seqnos_memory_object_server} and
3419: @code{seqnos_memory_object_default_server} differ from
3420: @code{memory_object_server} and @code{memory_object_default_server} in
3421: that they supply message sequence numbers to the server interfaces.
3422: They call the @code{seqnos_memory_object_*} functions, which complement
3423: the @code{memory_object_*} set of functions.
3424:
3425: The return value from the @code{memory_object_server} function indicates
3426: that the message was appropriate to the memory management interface
3427: (returning @code{TRUE}), or that it could not handle this message
3428: (returning @code{FALSE}).
3429:
3430: The @var{in_msg} argument is the message that has been received from the
3431: kernel. The @var{out_msg} is a reply message, but this is not used for
3432: this server.
3433:
3434: The function returns @code{TRUE} to indicate that the message in
3435: question was applicable to this interface, and that the appropriate
3436: routine was called to interpret the message. It returns @code{FALSE} to
3437: indicate that the message did not apply to this interface, and that no
3438: other action was taken.
3439: @end deftypefun
3440:
3441:
3442: @node Memory Object Creation
3443: @section Memory Object Creation
3444:
3445: @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}})
3446: @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}})
3447: The function @code{memory_object_init} serves as a notification that the
3448: kernel has been asked to map the given memory object into a task's
3449: virtual address space. Additionally, it provides a port on which the
3450: memory manager may issue cache management requests, and a port which the
3451: kernel will use to name this data region. In the event that different
3452: each will perform a @code{memory_object_init} call with new request and
3453: name ports. The virtual page size that is used by the calling kernel is
3454: included for planning purposes.
3455:
3456: When the memory manager is prepared to accept requests for data for this
3457: object, it must call @code{memory_object_ready} with the attribute.
3458: Otherwise the kernel will not process requests on this object. To
3459: reject all mappings of this object, the memory manager may use
3460: @code{memory_object_destroy}.
3461:
3462: The argument @var{memory_object} is the port that represents the memory
3463: object data, as supplied to the kernel in a @code{vm_map} call.
3464: @var{memory_control} is the request port to which a response is
3465: requested. (In the event that a memory object has been supplied to more
3466: than one the kernel that has made the request.)
3467: @var{memory_object_name} is a port used by the kernel to refer to the
1.1.1.2 ! root 3468: memory object data in response to @code{vm_region} calls.
1.1 root 3469: @code{memory_object_page_size} is the page size to be used by this
3470: kernel. All data sizes in calls involving this kernel must be an
3471: integral multiple of the page size. Note that different kernels,
3472: indicated by a different @code{memory_control}, may have different page
3473: sizes.
3474:
3475: The function should return @code{KERN_SUCCESS}, but since this routine
3476: is called by the kernel, which does not wait for a reply message, this
3477: value is ignored.
3478: @end deftypefun
3479:
3480: @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}})
3481: The function @code{memory_object_ready} informs the kernel that the
3482: memory manager is ready to receive data or unlock requests on behalf of
3483: the clients. The argument @var{memory_control} is the port, provided by
3484: the kernel in a @code{memory_object_init} call, to which cache
3485: management requests may be issued. If @var{may_cache_object} is set,
3486: the kernel may keep data associated with this memory object, even after
3487: virtual memory references to it are gone.
3488:
3489: @var{copy_strategy} tells how the kernel should copy regions of the
3490: associated memory object. There are three possible caching strategies:
3491: @code{MEMORY_OBJECT_COPY_NONE} which specifies that nothing special
3492: should be done when data in the object is copied;
3493: @code{MEMORY_OBJECT_COPY_CALL} which specifies that the memory manager
3494: should be notified via a @code{memory_object_copy} call before any part
3495: of the object is copied; and @code{MEMORY_OBJECT_COPY_DELAY} which
3496: guarantees that the memory manager does not externally modify the data
3497: so that the kernel can use its normal copy-on-write algorithms.
3498: @code{MEMORY_OBJECT_COPY_DELAY} is the strategy most commonly used.
3499:
3500: This routine does not receive a reply message (and consequently has no
3501: return value), so only message transmission errors apply.
3502: @end deftypefun
3503:
3504:
3505: @node Memory Object Termination
3506: @section Memory Object Termination
3507:
3508: @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}})
3509: @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}})
3510: The function @code{memory_object_terminate} indicates that the kernel
3511: has completed its use of the given memory object. All rights to the
3512: memory object control and name ports are included, so that the memory
3513: manager can destroy them (using @code{mach_port_deallocate}) after doing
3514: appropriate bookkeeping. The kernel will terminate a memory object only
3515: after all address space mappings of that memory object have been
3516: deallocated, or upon explicit request by the memory manager.
3517:
3518: The argument @var{memory_object} is the port that represents the memory
3519: object data, as supplied to the kernel in a @code{vm_map} call.
3520: @var{memory_control} is the request port to which a response is
3521: requested. (In the event that a memory object has been supplied to more
3522: than one the kernel that has made the request.)
3523: @var{memory_object_name} is a port used by the kernel to refer to the
1.1.1.2 ! root 3524: memory object data in response to @code{vm_region} calls.
1.1 root 3525:
3526: The function should return @code{KERN_SUCCESS}, but since this routine
3527: is called by the kernel, which does not wait for a reply message, this
3528: value is ignored.
3529: @end deftypefun
3530:
3531: @deftypefun kern_return_t memory_object_destroy (@w{memory_object_control_t @var{memory_control}}, @w{kern_return_t @var{reason}})
3532: The function @code{memory_object_destroy} tells the kernel to shut down
3533: the memory object. As a result of this call the kernel will no longer
3534: support paging activity or any @code{memory_object} calls on this
3535: object, and all rights to the memory object port, the memory control
3536: port and the memory name port will be returned to the memory manager in
3537: a memory_object_terminate call. If the memory manager is concerned that
3538: any modified cached data be returned to it before the object is
3539: terminated, it should call @code{memory_object_lock_request} with
3540: @var{should_flush} set and a lock value of @code{VM_PROT_WRITE} before
3541: making this call.
3542:
3543: The argument @var{memory_control} is the port, provided by the kernel in
3544: a @code{memory_object_init} call, to which cache management requests may
3545: be issued. @var{reason} is an error code indicating why the object
3546: must be destroyed.
1.1.1.2 ! root 3547: @c The error code is currently ignored.
1.1 root 3548:
3549: This routine does not receive a reply message (and consequently has no
3550: return value), so only message transmission errors apply.
3551: @end deftypefun
3552:
3553:
3554: @node Memory Objects and Data
3555: @section Memory Objects and Data
3556:
3557: @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}})
3558: @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}})
3559: The function @code{memory_object_data_return} provides the memory
3560: manager with data that has been modified while cached in physical
3561: memory. Once the memory manager no longer needs this data (e.g., it has
3562: been written to another storage medium), it should be deallocated using
3563: @code{vm_deallocate}.
3564:
3565: The argument @var{memory_object} is the port that represents the memory
3566: object data, as supplied to the kernel in a @code{vm_map} call.
3567: @var{memory_control} is the request port to which a response is
3568: requested. (In the event that a memory object has been supplied to more
3569: than one the kernel that has made the request.) @var{offset} is the
3570: offset within a memory object to which this call refers. This will be
3571: page aligned. @var{data} is the data which has been modified while
3572: cached in physical memory. @var{data_count} is the amount of data to be
3573: written, in bytes. This will be an integral number of memory object
3574: pages.
3575:
3576: The kernel will also use this call to return precious pages. If an
3577: unmodified precious age is returned, @var{dirty} is set to @code{FALSE},
3578: otherwise it is @code{TRUE}. If @var{kernel_copy} is @code{TRUE}, the
3579: kernel kept a copy of the page. Precious data remains precious if the
3580: kernel keeps a copy. The indication that the kernel kept a copy is only
3581: a hint if the data is not precious; the cleaned copy may be discarded
3582: without further notifying the manager.
3583:
3584: The function should return @code{KERN_SUCCESS}, but since this routine
3585: is called by the kernel, which does not wait for a reply message, this
3586: value is ignored.
3587: @end deftypefun
3588:
3589: @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}})
3590: @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}})
3591: The function @code{memory_object_data_request} is a request for data
3592: from the specified memory object, for at least the access specified.
3593: The memory manager is expected to return at least the specified data,
3594: with as much access as it can allow, using
3595: @code{memory_object_data_supply}. If the memory manager is unable to
3596: provide the data (for example, because of a hardware error), it may use
3597: the @code{memory_object_data_error} call. The
3598: @code{memory_object_data_unavailable} call may be used to tell the
3599: kernel to supply zero-filled memory for this region.
3600:
3601: The argument @var{memory_object} is the port that represents the memory
3602: object data, as supplied to the kernel in a @code{vm_map} call.
3603: @var{memory_control} is the request port to which a response is
3604: requested. (In the event that a memory object has been supplied to more
3605: than one the kernel that has made the request.) @var{offset} is the
3606: offset within a memory object to which this call refers. This will be
3607: page aligned. @var{length} is the number of bytes of data, starting at
3608: @var{offset}, to which this call refers. This will be an integral
3609: number of memory object pages. @var{desired_access} is a protection
3610: value describing the memory access modes which must be permitted on the
3611: specified cached data. One or more of: @code{VM_PROT_READ},
3612: @code{VM_PROT_WRITE} or @code{VM_PROT_EXECUTE}.
3613:
3614: The function should return @code{KERN_SUCCESS}, but since this routine
3615: is called by the kernel, which does not wait for a reply message, this
3616: value is ignored.
3617: @end deftypefun
3618:
3619: @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}})
3620: The function @code{memory_object_data_supply} supplies the kernel with
3621: data for the specified memory object. Ordinarily, memory managers
1.1.1.2 ! root 3622: should only provide data in response to @code{memory_object_data_request}
1.1 root 3623: calls from the kernel (but they may provide data in advance as desired).
3624: When data already held by this kernel is provided again, the new data is
3625: ignored. The kernel may not provide any data (or protection)
3626: consistency among pages with different virtual page alignments within
3627: the same object.
3628:
3629: The argument @var{memory_control} is the port, provided by the kernel in
3630: a @code{memory_object_init} call, to which cache management requests may
3631: be issued. @var{offset} is an offset within a memory object in bytes.
3632: This must be page aligned. @var{data} is the data that is being
3633: provided to the kernel. This is a pointer to the data.
3634: @var{data_count} is the amount of data to be provided. Only whole
3635: virtual pages of data can be accepted; partial pages will be discarded.
3636:
3637: @var{lock_value} is a protection value indicating those forms of access
3638: that should @strong{not} be permitted to the specified cached data. The
3639: lock values must be one or more of the set: @code{VM_PROT_NONE},
3640: @code{VM_PROT_READ}, @code{VM_PROT_WRITE}, @code{VM_PROT_EXECUTE} and
3641: @code{VM_PROT_ALL} as defined in @file{mach/vm_prot.h}.
3642:
3643: If @var{precious} is @code{FALSE}, the kernel treats the data as a
3644: temporary and may throw it away if it hasn't been changed. If the
3645: @var{precious} value is @code{TRUE}, the kernel treats its copy as a
3646: data repository and promises to return it to the manager; the manager
3647: may tell the kernel to throw it away instead by flushing and not
3648: cleaning the data (see @code{memory_object_lock_request}).
3649:
3650: If @var{reply_to} is not @code{MACH_PORT_NULL}, the kernel will send a
3651: completion message to the provided port (see
3652: @code{memory_object_supply_completed}).
3653:
3654: This routine does not receive a reply message (and consequently has no
3655: return value), so only message transmission errors apply.
3656: @end deftypefun
3657:
3658: @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}})
3659: @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}})
3660: The function @code{memory_object_supply_completed} indicates that a
3661: previous @code{memory_object_data_supply} has been completed. Note that
3662: this call is made on whatever port was specified in the
3663: @code{memory_object_data_supply} call; that port need not be the memory
3664: object port itself. No reply is expected after this call.
3665:
3666: The argument @var{memory_object} is the port that represents the memory
3667: object data, as supplied to the kernel in a @code{vm_map} call.
3668: @var{memory_control} is the request port to which a response is
3669: requested. (In the event that a memory object has been supplied to more
3670: than one the kernel that has made the request.) @var{offset} is the
3671: offset within a memory object to which this call refers. @var{length}
3672: is the length of the data covered by the lock request. The @var{result}
3673: parameter indicates what happened during the supply. If it is not
3674: @code{KERN_SUCCESS}, then @var{error_offset} identifies the first offset
3675: at which a problem occurred. The pagein operation stopped at this
3676: point. Note that the only failures reported by this mechanism are
3677: @code{KERN_MEMORY_PRESENT}. All other failures (invalid argument, error
3678: on pagein of supplied data in manager's address space) cause the entire
3679: operation to fail.
3680:
3681:
3682: @end deftypefun
3683:
3684: @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}})
3685: The function @code{memory_object_data_error} indicates that the memory
3686: manager cannot return the data requested for the given region,
3687: specifying a reason for the error. This is typically used when a
3688: hardware error is encountered.
3689:
3690: The argument @var{memory_control} is the port, provided by the kernel in
3691: a @code{memory_object_init} call, to which cache management requests may
3692: be issued. @var{offset} is an offset within a memory object in bytes.
3693: This must be page aligned. @var{data} is the data that is being
3694: provided to the kernel. This is a pointer to the data. @var{size} is
3695: the amount of cached data (starting at @var{offset}) to be handled.
3696: This must be an integral number of the memory object page size.
1.1.1.2 ! root 3697: @var{reason} is an error code indicating what type of error occurred.
! 3698: @c The error code is currently ignored.
1.1 root 3699:
3700: This routine does not receive a reply message (and consequently has no
3701: return value), so only message transmission errors apply.
3702: @end deftypefun
3703:
3704: @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}})
3705: The function @code{memory_object_data_unavailable} indicates that the
3706: memory object does not have data for the given region and that the
3707: kernel should provide the data for this range. The memory manager may
3708: use this call in three different situations.
3709:
3710: @enumerate
3711: @item
3712: The object was created by @code{memory_object_create} and the kernel has
3713: not yet provided data for this range (either via a
3714: @code{memory_object_data_initialize}, @code{memory_object_data_write} or
3715: a @code{memory_object_data_return} for the object.
3716:
3717: @item
3718: The object was created by an @code{memory_object_data_copy} and the
3719: kernel should copy this region from the original memory object.
3720:
3721: @item
3722: The object is a normal user-created memory object and the kernel should
3723: supply unlocked zero-filled pages for the range.
3724: @end enumerate
3725:
3726: The argument @var{memory_control} is the port, provided by the kernel in
3727: a @code{memory_object_init} call, to which cache management requests may
3728: be issued. @var{offset} is an offset within a memory object, in bytes.
3729: This must be page aligned. @var{size} is the amount of cached data
3730: (starting at @var{offset}) to be handled. This must be an integral
3731: number of the memory object page size.
3732:
3733: This routine does not receive a reply message (and consequently has no
3734: return value), so only message transmission errors apply.
3735: @end deftypefun
3736:
3737: @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}})
3738: @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}})
3739: The function @code{memory_object_copy} indicates that a copy has been
3740: made of the specified range of the given original memory object. This
3741: call includes only the new memory object itself; a
3742: @code{memory_object_init} call will be made on the new memory object
3743: after the currently cached pages of the original object are prepared.
3744: After the memory manager receives the init call, it must reply with the
3745: @code{memory_object_ready} call to assert the "ready" attribute. The
3746: kernel will use the new memory object, control and name ports to refer
3747: to the new copy.
3748:
3749: This call is made when the original memory object had the caching
3750: parameter set to @code{MEMORY_OBJECT_COPY_CALL} and a user of the object
3751: has asked the kernel to copy it.
3752:
3753: Cached pages from the original memory object at the time of the copy
3754: operation are handled as follows: Readable pages may be silently copied
3755: to the new memory object (with all access permissions). Pages not
3756: copied are locked to prevent write access.
3757:
3758: The new memory object is @strong{temporary}, meaning that the memory
3759: manager should not change its contents or allow the memory object to be
3760: mapped in another client. The memory manager may use the
3761: @code{memory_object_data_unavailable} call to indicate that the
3762: appropriate pages of the original memory object may be used to fulfill
3763: the data request.
3764:
3765: The argument @var{old_memory_object} is the port that represents the old
3766: memory object data. @var{old_memory_control} is the kernel port for the
3767: old object. @var{offset} is the offset within a memory object to which
3768: this call refers. This will be page aligned. @var{length} is the
3769: number of bytes of data, starting at @var{offset}, to which this call
3770: refers. This will be an integral number of memory object pages.
3771: @var{new_memory_object} is a new memory object created by the kernel;
3772: see synopsis for further description. Note that all port rights
3773: (including receive rights) are included for the new memory object.
3774:
3775: The function should return @code{KERN_SUCCESS}, but since this routine
3776: is called by the kernel, which does not wait for a reply message, this
3777: value is ignored.
3778: @end deftypefun
3779:
1.1.1.2 ! root 3780: The remaining interfaces in this section are obsolete.
1.1 root 3781:
3782: @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}})
3783: @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}})
3784: The function @code{memory_object_data_write} provides the memory manager
3785: with data that has been modified while cached in physical memory. It is the old form of @code{memory_object_data_return}. Once
3786: the memory manager no longer needs this data (e.g., it has been written
3787: to another storage medium), it should be deallocated using
3788: @code{vm_deallocate}.
3789:
3790: The argument @var{memory_object} is the port that represents the memory
3791: object data, as supplied to the kernel in a @code{vm_map} call.
3792: @var{memory_control} is the request port to which a response is
3793: requested. (In the event that a memory object has been supplied to more
3794: than one the kernel that has made the request.) @var{offset} is the
3795: offset within a memory object to which this call refers. This will be
3796: page aligned. @var{data} is the data which has been modified while
3797: cached in physical memory. @var{data_count} is the amount of data to be
3798: written, in bytes. This will be an integral number of memory object
3799: pages.
3800:
3801: The function should return @code{KERN_SUCCESS}, but since this routine
3802: is called by the kernel, which does not wait for a reply message, this
3803: value is ignored.
3804: @end deftypefun
3805:
3806: @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}})
3807: The function @code{memory_object_data_provided} supplies the kernel with
3808: data for the specified memory object. It is the old form of
3809: @code{memory_object_data_supply}. Ordinarily, memory managers should
1.1.1.2 ! root 3810: only provide data in response to @code{memory_object_data_request} calls
1.1 root 3811: from the kernel. The @var{lock_value} specifies what type of access
3812: will not be allowed to the data range. The lock values must be one or
3813: more of the set: @code{VM_PROT_NONE}, @code{VM_PROT_READ},
3814: @code{VM_PROT_WRITE}, @code{VM_PROT_EXECUTE} and @code{VM_PROT_ALL} as
3815: defined in @file{mach/vm_prot.h}.
3816:
3817: The argument @var{memory_control} is the port, provided by the kernel in
3818: a @code{memory_object_init} call, to which cache management requests may
3819: be issued. @var{offset} is an offset within a memory object in bytes.
3820: This must be page aligned. @var{data} is the data that is being
3821: provided to the kernel. This is a pointer to the data.
3822: @var{data_count} is the amount of data to be provided. This must be an
3823: integral number of memory object pages. @var{lock_value} is a
3824: protection value indicating those forms of access that should
3825: @strong{not} be permitted to the specified cached data.
3826:
3827: This routine does not receive a reply message (and consequently has no
3828: return value), so only message transmission errors apply.
3829: @end deftypefun
3830:
3831:
3832: @node Memory Object Locking
3833: @section Memory Object Locking
3834:
3835: @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}})
3836: The function @code{memory_object_lock_request} allows a memory manager
3837: to make cache management requests. As specified in arguments to the
3838: call, the kernel will:
3839: @itemize
3840: @item
3841: clean (i.e., write back using @code{memory_object_data_supply} or
3842: @code{memory_object_data_write}) any cached data which has been modified
3843: since the last time it was written
3844:
3845: @item
3846: flush (i.e., remove any uses of) that data from memory
3847:
3848: @item
3849: lock (i.e., prohibit the specified uses of) the cached data
3850: @end itemize
3851:
3852: Locks applied to cached data are not cumulative; new lock values
3853: override previous ones. Thus, data may also be unlocked using this
3854: primitive. The lock values must be one or more of the following values:
3855: @code{VM_PROT_NONE}, @code{VM_PROT_READ}, @code{VM_PROT_WRITE},
3856: @code{VM_PROT_EXECUTE} and @code{VM_PROT_ALL} as defined in
3857: @file{mach/vm_prot.h}.
3858:
3859: Only data which is cached at the time of this call is affected. When a
3860: running thread requires a prohibited access to cached data, the kernel
3861: will issue a @code{memory_object_data_unlock} call specifying the forms
3862: of access required.
3863:
3864: Once all of the actions requested by this call have been completed, the
3865: kernel issues a @code{memory_object_lock_completed} call on the
3866: specified reply port.
3867:
3868: The argument @var{memory_control} is the port, provided by the kernel in
3869: a @code{memory_object_init} call, to which cache management requests may
3870: be issued. @var{offset} is an offset within a memory object, in bytes.
3871: This must be page aligned. @var{size} is the amount of cached data
3872: (starting at @var{offset}) to be handled. This must be an integral
3873: number of the memory object page size. If @var{should_clean} is set,
3874: modified data should be written back to the memory manager. If
3875: @var{should_flush} is set, the specified cached data should be
3876: invalidated, and all uses of that data should be revoked.
3877: @var{lock_value} is a protection value indicating those forms of access
3878: that should @strong{not} be permitted to the specified cached data.
1.1.1.2 ! root 3879: @var{reply_to} is a port on which a @code{memory_object_lock_completed}
1.1 root 3880: call should be issued, or @code{MACH_PORT_NULL} if no acknowledgement is
3881: desired.
3882:
3883: This routine does not receive a reply message (and consequently has no
3884: return value), so only message transmission errors apply.
3885: @end deftypefun
3886:
3887: @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}})
3888: @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}})
3889: The function @code{memory_object_lock_completed} indicates that a
3890: previous @code{memory_object_lock_request} has been completed. Note
3891: that this call is made on whatever port was specified in the
3892: @code{memory_object_lock_request} call; that port need not be the memory
3893: object port itself. No reply is expected after this call.
3894:
3895: The argument @var{memory_object} is the port that represents the memory
3896: object data, as supplied to the kernel in a @code{vm_map} call.
3897: @var{memory_control} is the request port to which a response is
3898: requested. (In the event that a memory object has been supplied to more
3899: than one the kernel that has made the request.) @var{offset} is the
3900: offset within a memory object to which this call refers. @var{length}
3901: is the length of the data covered by the lock request.
3902:
3903: The function should return @code{KERN_SUCCESS}, but since this routine
3904: is called by the kernel, which does not wait for a reply message, this
3905: value is ignored.
3906: @end deftypefun
3907:
3908: @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}})
3909: @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}})
3910: The function @code{memory_object_data_unlock} is a request that the
3911: memory manager permit at least the desired access to the specified data
3912: cached by the kernel. A call to @code{memory_object_lock_request} is
3913: expected in response.
3914:
3915: The argument @var{memory_object} is the port that represents the memory
3916: object data, as supplied to the kernel in a @code{vm_map} call.
3917: @var{memory_control} is the request port to which a response is
3918: requested. (In the event that a memory object has been supplied to more
3919: than one the kernel that has made the request.) @var{offset} is the
3920: offset within a memory object to which this call refers. This will be
3921: page aligned. @var{length} is the number of bytes of data, starting at
3922: @var{offset}, to which this call refers. This will be an integral
3923: number of memory object pages. @var{desired_access} a protection value
3924: describing the memory access modes which must be permitted on the
3925: specified cached data. One or more of: @code{VM_PROT_READ},
3926: @code{VM_PROT_WRITE} or @code{VM_PROT_EXECUTE}.
3927:
3928: The function should return @code{KERN_SUCCESS}, but since this routine
3929: is called by the kernel, which does not wait for a reply message, this
3930: value is ignored.
3931: @end deftypefun
3932:
3933:
3934: @node Memory Object Attributes
3935: @section Memory Object Attributes
3936:
3937: @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}})
3938: The function @code{memory_object_get_attribute} retrieves the current
3939: attributes associated with the memory object.
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. If @var{object_ready} is set, the kernel may issue new data
3944: and unlock requests on the associated memory object. If
3945: @var{may_cache_object} is set, the kernel may keep data associated with
3946: this memory object, even after virtual memory references to it are gone.
3947: @var{copy_strategy} tells how the kernel should copy regions of the
3948: associated memory object.
3949:
3950: This routine does not receive a reply message (and consequently has no
3951: return value), so only message transmission errors apply.
3952: @end deftypefun
3953:
3954: @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}})
3955: The function @code{memory_object_change_attribute} sets
3956: performance-related attributes for the specified memory object. If the
3957: caching attribute is asserted, the kernel is permitted (and encouraged)
3958: to maintain cached data for this memory object even after no virtual
3959: address space contains this data.
3960:
3961: There are three possible caching strategies:
3962: @code{MEMORY_OBJECT_COPY_NONE} which specifies that nothing special
3963: should be done when data in the object is copied;
3964: @code{MEMORY_OBJECT_COPY_CALL} which specifies that the memory manager
3965: should be notified via a @code{memory_object_copy} call before any part
3966: of the object is copied; and @code{MEMORY_OBJECT_COPY_DELAY} which
3967: guarantees that the memory manager does not externally modify the data
3968: so that the kernel can use its normal copy-on-write algorithms.
3969: @code{MEMORY_OBJECT_COPY_DELAY} is the strategy most commonly used.
3970:
3971: The argument @var{memory_control} is the port, provided by the kernel in
3972: a @code{memory_object_init} call, to which cache management requests may
3973: be issued. If @var{may_cache_object} is set, the kernel may keep data
3974: associated with this memory object, even after virtual memory references
3975: to it are gone. @var{copy_strategy} tells how the kernel should copy
3976: regions of the associated memory object. @var{reply_to} is a port on
1.1.1.2 ! root 3977: which a @code{memory_object_change_completed} call will be issued upon
1.1 root 3978: completion of the attribute change, or @code{MACH_PORT_NULL} if no
3979: acknowledgement is desired.
3980:
3981: This routine does not receive a reply message (and consequently has no
3982: return value), so only message transmission errors apply.
3983: @end deftypefun
3984:
3985: @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}})
3986: @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}})
3987: The function @code{memory_object_change_completed} indicates the
3988: completion of an attribute change call.
3989:
3990: @c Warning: This routine does NOT contain a memory_object_control_t because
3991: @c the memory_object_change_attributes call may cause memory object
3992: @c termination (by uncaching the object). This would yield an invalid
3993: @c port.
3994: @end deftypefun
3995:
3996: The following interface is obsoleted by @code{memory_object_ready} and
3997: @code{memory_object_change_attributes}. If the old form
3998: @code{memory_object_set_attributes} is used to make a memory object
3999: ready, the kernel will write back data using the old
4000: @code{memory_object_data_write} interface rather than
4001: @code{memory_object_data_return}..
4002:
4003: @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 4004: The function @code{memory_object_set_attribute} controls how the
1.1 root 4005: memory object. The kernel will only make data or unlock requests when
4006: the ready attribute is asserted. If the caching attribute is asserted,
4007: the kernel is permitted (and encouraged) to maintain cached data for
4008: this memory object even after no virtual address space contains this
4009: data.
4010:
4011: There are three possible caching strategies:
4012: @code{MEMORY_OBJECT_COPY_NONE} which specifies that nothing special
4013: should be done when data in the object is copied;
4014: @code{MEMORY_OBJECT_COPY_CALL} which specifies that the memory manager
4015: should be notified via a @code{memory_object_copy} call before any part
4016: of the object is copied; and @code{MEMORY_OBJECT_COPY_DELAY} which
4017: guarantees that the memory manager does not externally modify the data
4018: so that the kernel can use its normal copy-on-write algorithms.
4019: @code{MEMORY_OBJECT_COPY_DELAY} is the strategy most commonly used.
4020:
4021: The argument @var{memory_control} is the port, provided by the kernel in
4022: a @code{memory_object_init} call, to which cache management requests may
4023: be issued. If @var{object_ready} is set, the kernel may issue new data
4024: and unlock requests on the associated memory object. If
4025: @var{may_cache_object} is set, the kernel may keep data associated with
4026: this memory object, even after virtual memory references to it are gone.
4027: @var{copy_strategy} tells how the kernel should copy regions of the
4028: associated memory object.
4029:
4030: This routine does not receive a reply message (and consequently has no
4031: return value), so only message transmission errors apply.
4032: @end deftypefun
4033:
4034:
4035: @node Default Memory Manager
4036: @section Default Memory Manager
4037:
4038: @deftypefun kern_return_t vm_set_default_memory_manager (@w{host_t @var{host}}, @w{mach_port_t *@var{default_manager}})
4039: The function @code{vm_set_default_memory_manager} sets the kernel's
4040: default memory manager. It sets the port to which newly-created
4041: temporary memory objects are delivered by @code{memory_object_create} to
4042: the host. The old memory manager port is returned. If
4043: @var{default_manager} is @code{MACH_PORT_NULL} then this routine just returns
4044: the current default manager port without changing it.
4045:
4046: The argument @var{host} is a task port to the kernel whose default
4047: memory manager is to be changed. @var{default_manager} is an in/out
4048: parameter. As input, @var{default_manager} is the port that the new
4049: memory manager is listening on for @code{memory_object_create} calls.
4050: As output, it is the old default memory manager's port.
4051:
4052: The function returns @code{KERN_SUCCESS} if the new memory manager is
4053: installed, and @code{KERN_INVALID_ARGUMENT} if this task does not have
4054: the privileges required for this call.
4055: @end deftypefun
4056:
4057: @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}})
4058: @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}})
4059: The function @code{memory_object_create} is a request that the given
4060: memory manager accept responsibility for the given memory object created
4061: by the kernel. This call will only be made to the system
4062: @strong{default memory manager}. The memory object in question
4063: initially consists of zero-filled memory; only memory pages that are
4064: actually written will ever be provided to
4065: @code{memory_object_data_request} calls, the default memory manager must
4066: use @code{memory_object_data_unavailable} for any pages that have not
4067: previously been written.
4068:
4069: No reply is expected after this call. Since this call is directed to
4070: the default memory manager, the kernel assumes that it will be ready to
4071: handle data requests to this object and does not need the confirmation
4072: of a @code{memory_object_set_attributes} call.
4073:
4074: The argument @var{old_memory_object} is a memory object provided by the
4075: default memory manager on which the kernel can make
4076: @code{memory_object_create} calls. @var{new_memory_object} is a new
4077: memory object created by the kernel; see synopsis for further
4078: description. Note that all port rights (including receive rights) are
4079: included for the new memory object. @var{new_object_size} is the
4080: maximum size of the new object. @var{new_control} is a port, created by
4081: the kernel, on which a memory manager may issue cache management
4082: requests for the new object. @var{new_name} a port used by the kernel
4083: to refer to the new memory object data in response to @code{vm_region}
4084: calls. @var{new_page_size} is the page size to be used by this kernel.
4085: All data sizes in calls involving this kernel must be an integral
4086: multiple of the page size. Note that different kernels, indicated by
4087: different a @code{memory_control}, may have different page sizes.
4088:
4089: The function should return @code{KERN_SUCCESS}, but since this routine
4090: is called by the kernel, which does not wait for a reply message, this
4091: value is ignored.
4092: @end deftypefun
4093:
4094: @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}})
4095: @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}})
4096: The function @code{memory_object_data_initialize} provides the memory
4097: manager with initial data for a kernel-created memory object. If the
4098: memory manager already has been supplied data (by a previous
4099: @code{memory_object_data_initialize}, @code{memory_object_data_write} or
4100: @code{memory_object_data_return}), then this data should be ignored.
4101: Otherwise, this call behaves exactly as does
4102: @code{memory_object_data_return} on memory objects created by the kernel
4103: via @code{memory_object_create} and thus will only be made to default
4104: memory managers. This call will not be made on objects created via
4105: @code{memory_object_copy}.
4106:
4107: The argument @var{memory_object} the port that represents the memory
4108: object data, as supplied by the kernel in a @code{memory_object_create}
4109: call. @var{memory_control} is the request port to which a response is
4110: requested. (In the event that a memory object has been supplied to more
4111: than one the kernel that has made the request.) @var{offset} is the
4112: offset within a memory object to which this call refers. This will be
1.1.1.2 ! root 4113: page aligned. @var{data} is the data which has been modified while
1.1 root 4114: cached in physical memory. @var{data_count} is the amount of data to be
4115: written, in bytes. This will be an integral number of memory object
4116: pages.
4117:
4118: The function should return @code{KERN_SUCCESS}, but since this routine
4119: is called by the kernel, which does not wait for a reply message, this
4120: value is ignored.
4121: @end deftypefun
4122:
4123:
4124: @node Threads and Tasks
4125: @chapter Threads and Tasks
4126:
4127: @menu
4128: * Thread Interface:: Manipulating threads.
4129: * Task Interface:: Manipulating tasks.
4130: * Profiling:: Profiling threads and tasks.
4131: @end menu
4132:
4133:
4134: @node Thread Interface
4135: @section Thread Interface
4136:
4137: @cindex thread port
4138: @cindex port representing a thread
4139: @deftp {Data type} thread_t
4140: This is a @code{mach_port_t} and used to hold the port name of a
4141: thread port that represents the thread. Manipulations of the thread are
4142: implemented as remote procedure calls to the thread port. A thread can
4143: get a port to itself with the @code{mach_thread_self} system call.
4144: @end deftp
4145:
4146: @menu
4147: * Thread Creation:: Creating new threads.
4148: * Thread Termination:: Terminating existing threads.
4149: * Thread Information:: How to get informations on threads.
4150: * Thread Settings:: How to set threads related informations.
4151: * Thread Execution:: How to control the thread's machine state.
4152: * Scheduling:: Operations on thread scheduling.
4153: * Thread Special Ports:: How to handle the thread's special ports.
4154: * Exceptions:: Managing exceptions.
4155: @end menu
4156:
4157:
4158: @node Thread Creation
4159: @subsection Thread Creation
4160:
4161: @deftypefun kern_return_t thread_create (@w{task_t @var{parent_task}}, @w{thread_t *@var{child_thread}})
4162: The function @code{thread_create} creates a new thread within the task
4163: specified by @var{parent_task}. The new thread has no processor state,
4164: and has a suspend count of 1. To get a new thread to run, first
4165: @code{thread_create} is called to get the new thread's identifier,
4166: (@var{child_thread}). Then @code{thread_set_state} is called to set a
4167: processor state, and finally @code{thread_resume} is called to get the
4168: thread scheduled to execute.
4169:
4170: When the thread is created send rights to its thread kernel port are
4171: given to it and returned to the caller in @var{child_thread}. The new
4172: thread's exception port is set to @code{MACH_PORT_NULL}.
4173:
4174: The function returns @code{KERN_SUCCESS} if a new thread has been
4175: created, @code{KERN_INVALID_ARGUMENT} if @var{parent_task} is not a
4176: valid task and @code{KERN_RESOURCE_SHORTAGE} if some critical kernel
4177: resource is not available.
4178: @end deftypefun
4179:
4180:
4181: @node Thread Termination
4182: @subsection Thread Termination
4183:
4184: @deftypefun kern_return_t thread_terminate (@w{thread_t @var{target_thread}})
4185: The function @code{thread_terminate} destroys the thread specified by
4186: @var{target_thread}.
4187:
4188: The function returns @code{KERN_SUCCESS} if the thread has been killed
4189: and @code{KERN_INVALID_ARGUMENT} if @var{target_thread} is not a thread.
4190: @end deftypefun
4191:
4192:
4193: @node Thread Information
4194: @subsection Thread Information
4195:
4196: @deftypefun thread_t mach_thread_self ()
4197: The @code{mach_thread_self} system call returns the calling thread's
4198: thread port.
4199:
4200: @code{mach_thread_self} has an effect equivalent to receiving a send
4201: right for the thread port. @code{mach_thread_self} returns the name of
4202: the send right. In particular, successive calls will increase the
4203: calling task's user-reference count for the send right.
4204:
4205: @c author{marcus}
4206: As a special exception, the kernel will overrun the user reference count
4207: of the thread name port, so that this function can not fail for that
4208: reason. Because of this, the user should not deallocate the port right
4209: if an overrun might have happened. Otherwise the reference count could
4210: drop to zero and the send right be destroyed while the user still
4211: expects to be able to use it. As the kernel does not make use of the
4212: number of extant send rights anyway, this is safe to do (the thread port
4213: itself is not destroyed, even when there are no send rights anymore).
4214:
4215: The function returns @code{MACH_PORT_NULL} if a resource shortage
4216: prevented the reception of the send right or if the thread port is
4217: currently null and @code{MACH_PORT_DEAD} if the thread port is currently
4218: dead.
4219: @end deftypefun
4220:
4221: @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}})
4222: The function @code{thread_info} returns the selected information array
4223: for a thread, as specified by @var{flavor}.
4224:
4225: @var{thread_info} is an array of integers that is supplied by the caller
4226: and returned filled with specified information. @var{thread_infoCnt} is
4227: supplied as the maximum number of integers in @var{thread_info}. On
4228: return, it contains the actual number of integers in @var{thread_info}.
4229: The maximum number of integers returned by any flavor is
4230: @code{THREAD_INFO_MAX}.
4231:
4232: The type of information returned is defined by @var{flavor}, which can
4233: be one of the following:
4234:
4235: @table @code
4236: @item THREAD_BASIC_INFO
4237: The function returns basic information about the thread, as defined by
4238: @code{thread_basic_info_t}. This includes the user and system time, the
4239: run state, and scheduling priority. The number of integers returned is
4240: @code{THREAD_BASIC_INFO_COUNT}.
4241:
4242: @item THREAD_SCHED_INFO
1.1.1.2 ! root 4243: The function returns information about the scheduling policy for the
1.1 root 4244: thread as defined by @code{thread_sched_info_t}. The number of integers
4245: returned is @code{THREAD_SCHED_INFO_COUNT}.
4246: @end table
4247:
4248: The function returns @code{KERN_SUCCESS} if the call succeeded and
4249: @code{KERN_INVALID_ARGUMENT} if @var{target_thread} is not a thread or
4250: @var{flavor} is not recognized. The function returns
4251: @code{MIG_ARRAY_TOO_LARGE} if the returned info array is too large for
4252: @var{thread_info}. In this case, @var{thread_info} is filled as much as
4253: possible and @var{thread_infoCnt} is set to the number of elements that
4254: would have been returned if there were enough room.
4255: @end deftypefun
4256:
4257: @deftp {Data type} {struct thread_basic_info}
4258: This structure is returned in @var{thread_info} by the
4259: @code{thread_info} function and provides basic information about the
4260: thread. You can cast a variable of type @code{thread_info_t} to a
4261: pointer of this type if you provided it as the @var{thread_info}
4262: parameter for the @code{THREAD_BASIC_INFO} flavor of @code{thread_info}.
4263: It has the following members:
4264:
4265: @table @code
4266: @item time_value_t user_time
4267: user run time
4268:
4269: @item time_value_t system_time
4270: system run time
4271: @item int cpu_usage
4272: Scaled cpu usage percentage. The scale factor is @code{TH_USAGE_SCALE}.
4273:
4274: @item int base_priority
4275: The base scheduling priority of the thread.
4276:
4277: @item int cur_priority
4278: The current scheduling priority of the thread.
4279:
4280: @item integer_t run_state
1.1.1.2 ! root 4281: The run state of the thread. The possible values of this field are:
1.1 root 4282: @table @code
4283: @item TH_STATE_RUNNING
4284: The thread is running normally.
4285:
4286: @item TH_STATE_STOPPED
4287: The thread is suspended.
4288:
4289: @item TH_STATE_WAITING
4290: The thread is waiting normally.
4291:
4292: @item TH_STATE_UNINTERRUPTIBLE
4293: The thread is in an uninterruptible wait.
4294:
4295: @item TH_STATE_HALTED
4296: The thread is halted at a clean point.
4297: @end table
4298:
4299: @item flags
4300: Various flags. The possible values of this field are:
4301: @table @code
4302: @item TH_FLAGS_SWAPPED
4303: The thread is swapped out.
4304:
4305: @item TH_FLAGS_IDLE
4306: The thread is an idle thread.
4307: @end table
4308:
4309: @item int suspend_count
4310: The suspend count for the thread.
4311:
4312: @item int sleep_time
4313: The number of seconds that the thread has been sleeping.
4314:
4315: @item time_value_t creation_time
4316: The time stamp of creation.
4317: @end table
4318: @end deftp
4319:
4320: @deftp {Data type} thread_basic_info_t
4321: This is a pointer to a @code{struct thread_basic_info}.
4322: @end deftp
4323:
4324: @deftp {Data type} {struct thread_sched_info}
4325: This structure is returned in @var{thread_info} by the
4326: @code{thread_info} function and provides schedule information about the
4327: thread. You can cast a variable of type @code{thread_info_t} to a
4328: pointer of this type if you provided it as the @var{thread_info}
4329: parameter for the @code{THREAD_SCHED_INFO} flavor of @code{thread_info}.
4330: It has the following members:
4331:
4332: @table @code
4333: @item int policy
4334: The scheduling policy of the thread, @ref{Scheduling Policy}.
4335:
4336: @item integer_t data
4337: Policy-dependent scheduling information, @ref{Scheduling Policy}.
4338:
4339: @item int base_priority
4340: The base scheduling priority of the thread.
4341:
4342: @item int max_priority
4343: The maximum scheduling priority of the thread.
4344:
4345: @item int cur_priority
4346: The current scheduling priority of the thread.
4347:
4348: @item int depressed
4349: @code{TRUE} if the thread is depressed.
4350:
4351: @item int depress_priority
4352: The priority the thread was depressed from.
4353: @end table
4354: @end deftp
4355:
4356: @deftp {Data type} thread_sched_info_t
4357: This is a pointer to a @code{struct thread_sched_info}.
4358: @end deftp
4359:
4360:
4361: @node Thread Settings
4362: @subsection Thread Settings
4363:
4364: @deftypefun kern_return_t thread_wire (@w{host_priv_t @var{host_priv}}, @w{thread_t @var{thread}}, @w{boolean_t @var{wired}})
4365: The function @code{thread_wire} controls the VM privilege level of the
4366: thread @var{thread}. A VM-privileged thread never waits inside the
4367: kernel for memory allocation from the kernel's free list of pages or for
4368: allocation of a kernel stack.
4369:
4370: Threads that are part of the default pageout path should be
4371: VM-privileged, to prevent system deadlocks. Threads that are not part
4372: of the default pageout path should not be VM-privileged, to prevent the
4373: kernel's free list of pages from being exhausted.
4374:
4375: The functions returns @code{KERN_SUCCESS} if the call succeeded,
4376: @code{KERN_INVALID_ARGUMENT} if @var{host_priv} or @var{thread} was
4377: invalid.
4378:
4379: The @code{thread_wire} call is actually an RPC to @var{host_priv},
4380: normally a send right for a privileged host port, but potentially any
4381: send right. In addition to the normal diagnostic return codes from the
4382: call's server (normally the kernel), the call may return @code{mach_msg}
4383: return codes.
4384: @c See also: vm_wire(2), vm_set_default_memory_manager(2).
4385: @end deftypefun
4386:
4387:
4388: @node Thread Execution
4389: @subsection Thread Execution
4390:
4391: @deftypefun kern_return_t thread_suspend (@w{thread_t @var{target_thread}})
4392: Increments the thread's suspend count and prevents the thread from
4393: executing any more user level instructions. In this context a user
4394: level instruction is either a machine instruction executed in user mode
4395: or a system trap instruction including page faults. Thus if a thread is
4396: currently executing within a system trap the kernel code may continue to
1.1.1.2 ! root 4397: execute until it reaches the system return code or it may suspend within
1.1 root 4398: the kernel code. In either case, when the thread is resumed the system
1.1.1.2 ! root 4399: trap will return. This could cause unpredictable results if the user
1.1 root 4400: did a suspend and then altered the user state of the thread in order to
4401: change its direction upon a resume. The call @code{thread_abort} is
4402: provided to allow the user to abort any system call that is in progress
4403: in a predictable way.
4404:
4405: The suspend count may become greater than one with the effect that it
4406: will take more than one resume call to restart the thread.
4407:
4408: The function returns @code{KERN_SUCCESS} if the thread has been
4409: suspended and @code{KERN_INVALID_ARGUMENT} if @var{target_thread} is not
4410: a thread.
4411: @end deftypefun
4412:
4413: @deftypefun kern_return_t thread_resume (@w{thread_t @var{target_thread}})
1.1.1.2 ! root 4414: Decrements the thread's suspend count. If the count becomes zero the
1.1 root 4415: thread is resumed. If it is still positive, the thread is left
4416: suspended. The suspend count may not become negative.
4417:
4418: The function returns @code{KERN_SUCCESS} if the thread has been resumed,
4419: @code{KERN_FAILURE} if the suspend count is already zero and
4420: @code{KERN_INVALID_ARGUMENT} if @var{target_thread} is not a thread.
4421: @end deftypefun
4422:
4423: @deftypefun kern_return_t thread_abort (@w{thread_t @var{target_thread}})
4424: The function @code{thread_abort} aborts the kernel primitives:
4425: @code{mach_msg}, @code{msg_send}, @code{msg_receive} and @code{msg_rpc}
4426: and page-faults, making the call return a code indicating that it was
4427: interrupted. The call is interrupted whether or not the thread (or task
1.1.1.2 ! root 4428: containing it) is currently suspended. If it is suspended, the thread
! 4429: receives the interrupt when it is resumed.
1.1 root 4430:
4431: A thread will retry an aborted page-fault if its state is not modified
4432: before it is resumed. @code{msg_send} returns @code{SEND_INTERRUPTED};
4433: @code{msg_receive} returns @code{RCV_INTERRUPTED}; @code{msg_rpc}
4434: returns either @code{SEND_INTERRUPTED} or @code{RCV_INTERRUPTED},
4435: depending on which half of the RPC was interrupted.
4436:
4437: The main reason for this primitive is to allow one thread to cleanly
4438: stop another thread in a manner that will allow the future execution of
4439: the target thread to be controlled in a predictable way.
4440: @code{thread_suspend} keeps the target thread from executing any further
4441: instructions at the user level, including the return from a system call.
4442: @code{thread_get_state}/@code{thread_set_state} allows the examination
4443: or modification of the user state of a target thread. However, if a
4444: suspended thread was executing within a system call, it also has
4445: associated with it a kernel state. This kernel state can not be
4446: modified by @code{thread_set_state} with the result that when the thread
4447: is resumed the system call may return changing the user state and
4448: possibly user memory. @code{thread_abort} aborts the kernel call from
4449: the target thread's point of view by resetting the kernel state so that
4450: the thread will resume execution at the system call return with the
4451: return code value set to one of the interrupted codes. The system call
4452: itself will either be entirely completed or entirely aborted, depending
4453: on the precise moment at which the abort was received. Thus if the
4454: thread's user state has been changed by @code{thread_set_state}, it will
4455: not be modified by any unexpected system call side effects.
4456:
4457: For example to simulate a Unix signal, the following sequence of calls
4458: may be used:
4459:
4460: @enumerate
4461: @item
4462: @code{thread_suspend}: Stops the thread.
4463:
4464: @item
4465: @code{thread_abort}: Interrupts any system call in progress, setting the
4466: return value to `interrupted'. Since the thread is stopped, it will not
4467: return to user code.
4468:
4469: @item
4470: @code{thread_set_state}: Alters thread's state to simulate a procedure
4471: call to the signal handler
4472:
4473: @item
4474: @code{thread_resume}: Resumes execution at the signal handler. If the
4475: thread's stack has been correctly set up, the thread may return to the
4476: interrupted system call. (Of course, the code to push an extra stack
4477: frame and change the registers is VERY machine-dependent.)
4478: @end enumerate
4479:
4480: Calling @code{thread_abort} on a non-suspended thread is pretty risky,
4481: since it is very difficult to know exactly what system trap, if any, the
4482: thread might be executing and whether an interrupt return would cause
4483: the thread to do something useful.
4484:
4485: The function returns @code{KERN_SUCCESS} if the thread received an
4486: interrupt and @code{KERN_INVALID_ARGUMENT} if @var{target_thread} is not
4487: a thread.
4488: @end deftypefun
4489:
4490: @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}})
4491: The function @code{thread_get_state} returns the execution state
4492: (e.g. the machine registers) of @var{target_thread} as specified by
4493: @var{flavor}. The @var{old_state} is an array of integers that is
4494: provided by the caller and returned filled with the specified
4495: information. @var{old_stateCnt} is input set to the maximum number of
4496: integers in @var{old_state} and returned equal to the actual number of
4497: integers in @var{old_state}.
4498:
4499: @var{target_thread} may not be @code{mach_thread_self()}.
4500:
4501: The definition of the state structures can be found in
4502: @file{machine/thread_status.h}.
4503:
4504: The function returns @code{KERN_SUCCESS} if the state has been returned,
4505: @code{KERN_INVALID_ARGUMENT} if @var{target_thread} is not a thread or
1.1.1.2 ! root 4506: is @code{mach_thread_self} or @var{flavor} is unrecognized for this machine.
1.1 root 4507: The function returns @code{MIG_ARRAY_TOO_LARGE} if the returned state is
4508: too large for @var{old_state}. In this case, @var{old_state} is filled
4509: as much as possible and @var{old_stateCnt} is set to the number of
4510: elements that would have been returned if there were enough room.
4511: @end deftypefun
4512:
4513: @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}})
4514: The function @code{thread_set_state} sets the execution state (e.g. the
4515: machine registers) of @var{target_thread} as specified by @var{flavor}.
4516: The @var{new_state} is an array of integers. @var{new_state_count} is
4517: the number of elements in @var{new_state}. The entire set of registers
4518: is reset. This will do unpredictable things if @var{target_thread} is
4519: not suspended.
4520:
4521: @var{target_thread} may not be @code{mach_thread_self}.
4522:
4523: The definition of the state structures can be found in
4524: @file{machine/thread_status.h}.
4525:
4526: The function returns @code{KERN_SUCCESS} if the state has been set and
4527: @code{KERN_INVALID_ARGUMENT} if @var{target_thread} is not a thread or
1.1.1.2 ! root 4528: is @code{mach_thread_self} or @var{flavor} is unrecognized for this
1.1 root 4529: machine.
4530: @end deftypefun
4531:
4532:
4533: @node Scheduling
4534: @subsection Scheduling
4535:
4536: @menu
4537: * Thread Priority:: Changing the priority of a thread.
4538: * Hand-Off Scheduling:: Switching to a new thread.
4539: * Scheduling Policy:: Setting the scheduling policy.
4540: @end menu
4541:
4542:
4543: @node Thread Priority
4544: @subsubsection Thread Priority
4545:
4546: Threads have three priorities associated with them by the system, a
4547: priority, a maximum priority, and a scheduled priority. The scheduled
4548: priority is used to make scheduling decisions about the thread. It is
4549: determined from the priority by the policy (for timesharing, this means
4550: adding an increment derived from cpu usage). The priority can be set
4551: under user control, but may never exceed the maximum priority. Changing
4552: the maximum priority requires presentation of the control port for the
4553: thread's processor set; since the control port for the default processor
4554: set is privileged, users cannot raise their maximum priority to unfairly
4555: compete with other users on that set. Newly created threads obtain
4556: their priority from their task and their max priority from the thread.
4557:
4558: @deftypefun kern_return_t thread_priority (@w{thread_t @var{thread}}, @w{int @var{prority}}, @w{boolean_t @var{set_max}})
4559: The function @code{thread_priority} changes the priority and optionally
4560: the maximum priority of @var{thread}. Priorities range from 0 to 31,
4561: where lower numbers denote higher priorities. If the new priority is
4562: higher than the priority of the current thread, preemption may occur as
4563: a result of this call. The maximum priority of the thread is also set
4564: if @var{set_max} is @code{TRUE}. This call will fail if @var{priority}
4565: is greater than the current maximum priority of the thread. As a
4566: result, this call can only lower the value of a thread's maximum
4567: priority.
4568:
4569: The functions returns @code{KERN_SUCCESS} if the operation completed
4570: successfully, @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a
4571: thread or @var{priority} is out of range (not in 0..31), and
4572: @code{KERN_FAILURE} if the requested operation would violate the
4573: thread's maximum priority (thread_priority).
4574: @end deftypefun
4575:
4576: @deftypefun kern_return_t thread_max_priority (@w{thread_t @var{thread}}, @w{processor_set_t @var{processor_set}}, @w{int @var{priority}})
4577: The function @code{thread_max_priority} changes the maximum priority of
4578: the thread. Because it requires presentation of the corresponding
4579: processor set port, this call can reset the maximum priority to any
4580: legal value.
4581:
4582: The functions returns @code{KERN_SUCCESS} if the operation completed
4583: successfully, @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a
4584: thread or @var{processor_set} is not a control port for a processor set
4585: or @var{priority} is out of range (not in 0..31), and
4586: @code{KERN_FAILURE} if the thread is not assigned to the processor set
4587: whose control port was presented.
4588: @end deftypefun
4589:
4590:
4591: @node Hand-Off Scheduling
4592: @subsubsection Hand-Off Scheduling
4593:
4594: @deftypefun kern_return_t thread_switch (@w{thread_t @var{new_thread}}, @w{int @var{option}}, @w{int @var{time}})
4595: The function @code{thread_switch} provides low-level access to the
4596: scheduler's context switching code. @var{new_thread} is a hint that
4597: implements hand-off scheduling. The operating system will attempt to
1.1.1.2 ! root 4598: switch directly to the new thread (bypassing the normal logic that
1.1 root 4599: selects the next thread to run) if possible. Since this is a hint, it
4600: may be incorrect; it is ignored if it doesn't specify a thread on the
4601: same host as the current thread or if that thread can't be switched to
1.1.1.2 ! root 4602: (i.e., not runnable or already running on another processor or giving
! 4603: a plainly invalid hint, such as @code{MACH_PORT_NULL}). In this case,
! 4604: the normal logic to select the next thread to run is used; the current
! 4605: thread may continue running if there is no other appropriate thread to
! 4606: run.
1.1 root 4607:
4608: Options for @var{option} are defined in @file{mach/thread_switch.h} and
4609: specify the interpretation of @var{time}. The possible values for
4610: @var{option} are:
4611:
4612: @table @code
4613: @item SWITCH_OPTION_NONE
4614: No options, the time argument is ignored.
4615:
4616: @item SWITCH_OPTION_WAIT
1.1.1.2 ! root 4617: The thread is blocked for the specified time (in milliseconds;
! 4618: specifying @code{0} will wait for the next tick). This can be aborted
! 4619: by @code{thread_abort}.
1.1 root 4620:
4621: @item SWITCH_OPTION_DEPRESS
4622: The thread's priority is depressed to the lowest possible value for the
4623: specified time. This can be aborted by @code{thread_depress_abort}.
4624: This depression is independent of operations that change the thread's
4625: priority (e.g. @code{thread_priority} will not abort the depression).
4626: The minimum time and units of time can be obtained as the
4627: @code{min_timeout} value from @code{host_info}. The depression is also
1.1.1.2 ! root 4628: aborted when the current thread is next run (either via hand-off
1.1 root 4629: scheduling or because the processor set has nothing better to do).
4630: @end table
4631:
4632: @code{thread_switch} is often called when the current thread can proceed
4633: no further for some reason; the various options and arguments allow
4634: information about this reason to be transmitted to the kernel. The
4635: @var{new_thread} argument (handoff scheduling) is useful when the
4636: identity of the thread that must make progress before the current thread
4637: runs again is known. The @code{WAIT} option is used when the amount of
4638: time that the current thread must wait before it can do anything useful
4639: can be estimated and is fairly long. The @code{DEPRESS} option is used
4640: when the amount of time that must be waited is fairly short, especially
4641: when the identity of the thread that is being waited for is not known.
4642:
4643: Users should beware of calling @code{thread_switch} with an invalid hint
4644: (e.g. @code{MACH_PORT_NULL}) and no option. Because the time-sharing
4645: scheduler varies the priority of threads based on usage, this may result
4646: in a waste of cpu time if the thread that must be run is of lower
4647: priority. The use of the @code{DEPRESS} option in this situation is
4648: highly recommended.
4649:
4650: @code{thread_switch} ignores policies. Users relying on the preemption
4651: semantics of a fixed time policy should be aware that
4652: @code{thread_switch} ignores these semantics; it will run the specified
1.1.1.2 ! root 4653: @var{new_thread} independent of its priority and the priority of any other
1.1 root 4654: threads that could be run instead.
4655:
4656: The function returns @code{KERN_SUCCESS} if the call succeeded,
4657: @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a thread or
4658: @var{option} is not a recognized option, and @code{KERN_FAILURE} if
4659: @code{kern_depress_abort} failed because the thread was not depressed.
4660: @end deftypefun
4661:
4662: @deftypefun kern_return_t thread_depress_abort (@w{thread_t @var{thread}})
4663: The function @code{thread_depress_abort} cancels any priority depression
4664: for @var{thread} caused by a @code{swtch_pri} or @code{thread_switch}
4665: call.
4666:
4667: The function returns @code{KERN_SUCCESS} if the call succeeded and
4668: @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a valid thread.
4669: @end deftypefun
4670:
4671: @deftypefun boolean_t swtch ()
4672: @c XXX Clear up wording.
4673: The system trap @code{swtch} attempts to switch the current thread off
4674: the processor. The return value indicates if more than the current
4675: thread is running in the processor set. This is useful for lock
4676: management routines.
4677:
4678: The call returns @code{FALSE} if the thread is justified in becoming a
4679: resource hog by continuing to spin because there's nothing else useful
4680: that the processor could do. @code{TRUE} is returned if the thread
4681: should make one more check on the lock and then be a good citizen and
4682: really suspend.
4683: @end deftypefun
4684:
4685: @deftypefun boolean_t swtch_pri (@w{int @var{priority}})
4686: The system trap @code{swtch_pri} attempts to switch the current thread
4687: off the processor as @code{swtch} does, but depressing the priority of
4688: the thread to the minimum possible value during the time.
4689: @var{priority} is not used currently.
4690:
4691: The return value is as for @code{swtch}.
4692: @end deftypefun
4693:
4694:
4695: @node Scheduling Policy
4696: @subsubsection Scheduling Policy
4697:
4698: @deftypefun kern_return_t thread_policy (@w{thread_t @var{thread}}, @w{int @var{policy}}, @w{int @var{data}})
4699: The function @code{thread_policy} changes the scheduling policy for
4700: @var{thread} to @var{policy}.
4701:
4702: @var{data} is policy-dependent scheduling information. There are
4703: currently two supported policies: @code{POLICY_TIMESHARE} and
4704: @code{POLICY_FIXEDPRI} defined in @file{mach/policy.h}; this file is
4705: included by @file{mach.h}. @var{data} is meaningless for timesharing,
4706: but is the quantum to be used (in milliseconds) for the fixed priority
4707: policy. To be meaningful, this quantum must be a multiple of the basic
4708: system quantum (min_quantum) which can be obtained from
4709: @code{host_info}. The system will always round up to the next multiple
4710: of the quantum.
4711:
4712: Processor sets may restrict the allowed policies, so this call will fail
4713: if the processor set to which @var{thread} is currently assigned does
4714: not permit @var{policy}.
4715:
4716: The function returns @code{KERN_SUCCESS} if the call succeeded.
4717: @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a thread or
4718: @var{policy} is not a recognized policy, and @code{KERN_FAILURE} if the
4719: processor set to which @var{thread} is currently assigned does not
4720: permit @var{policy}.
4721: @end deftypefun
4722:
4723:
4724: @node Thread Special Ports
4725: @subsection Thread Special Ports
4726:
4727: @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}})
4728: The function @code{thread_get_special_port} returns send rights to one
4729: of a set of special ports for the thread specified by @var{thread}.
4730:
4731: The possible values for @var{which_port} are @code{THREAD_KERNEL_PORT}
4732: and @code{THREAD_EXCEPTION_PORT}. A thread also has access to its
4733: task's special ports.
4734:
4735: The function returns @code{KERN_SUCCESS} if the port was returned and
4736: @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a thread or
4737: @var{which_port} is an invalid port selector.
4738: @end deftypefun
4739:
4740: @deftypefun kern_return_t thread_get_kernel_port (@w{thread_t @var{thread}}, @w{mach_port_t *@var{kernel_port}})
4741: The function @code{thread_get_kernel_port} is equivalent to the function
4742: @code{thread_get_special_port} with the @var{which_port} argument set to
4743: @code{THREAD_KERNEL_PORT}.
4744: @end deftypefun
4745:
4746: @deftypefun kern_return_t thread_get_exception_port (@w{thread_t @var{thread}}, @w{mach_port_t *@var{exception_port}})
4747: The function @code{thread_get_exception_port} is equivalent to the
4748: function @code{thread_get_special_port} with the @var{which_port}
4749: argument set to @code{THREAD_EXCEPTION_PORT}.
4750: @end deftypefun
4751:
4752: @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}})
4753: The function @code{thread_set_special_port} sets one of a set of special
4754: ports for the thread specified by @var{thread}.
4755:
4756: The possible values for @var{which_port} are @code{THREAD_KERNEL_PORT}
4757: and @code{THREAD_EXCEPTION_PORT}. A thread also has access to its
4758: task's special ports.
4759:
4760: The function returns @code{KERN_SUCCESS} if the port was set and
4761: @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a thread or
4762: @var{which_port} is an invalid port selector.
4763: @end deftypefun
4764:
4765: @deftypefun kern_return_t thread_set_kernel_port (@w{thread_t @var{thread}}, @w{mach_port_t @var{kernel_port}})
4766: The function @code{thread_set_kernel_port} is equivalent to the function
4767: @code{thread_set_special_port} with the @var{which_port} argument set to
4768: @code{THREAD_KERNEL_PORT}.
4769: @end deftypefun
4770:
4771: @deftypefun kern_return_t thread_set_exception_port (@w{thread_t @var{thread}}, @w{mach_port_t @var{exception_port}})
4772: The function @code{thread_set_exception_port} is equivalent to the
4773: function @code{thread_set_special_port} with the @var{which_port}
4774: argument set to @code{THREAD_EXCEPTION_PORT}.
4775: @end deftypefun
4776:
4777:
4778: @node Exceptions
4779: @subsection Exceptions
4780:
4781: @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}})
4782: XXX Fixme
4783: @end deftypefun
4784:
4785: @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}})
4786: XXX Fixme
4787: @end deftypefun
4788:
4789: @deftypefun kern_return_t evc_wait (@w{unsigned int @var{event}})
4790: @c XXX This is for user space drivers, the description is incomplete.
4791: The system trap @code{evc_wait} makes the calling thread wait for the
4792: event specified by @var{event}.
4793:
1.1.1.2 ! root 4794: The call returns @code{KERN_SUCCESS} if the event has occurred,
1.1 root 4795: @code{KERN_NO_SPACE} if another thread is waiting for the same event and
4796: @code{KERN_INVALID_ARGUMENT} if the event object is invalid.
4797: @end deftypefun
4798:
4799:
4800: @node Task Interface
4801: @section Task Interface
4802:
4803: @cindex task port
4804: @cindex port representing a task
4805: @deftp {Data type} task_t
4806: This is a @code{mach_port_t} and used to hold the port name of a task
4807: port that represents the thread. Manipulations of the task are
4808: implemented as remote procedure calls to the task port. A task can get
4809: a port to itself with the @code{mach_task_self} system call.
4810:
4811: The task port name is also used to identify the task's IPC space
4812: (@pxref{Port Manipulation Interface}) and the task's virtual memory map
4813: (@pxref{Virtual Memory Interface}).
4814: @end deftp
4815:
4816: @menu
4817: * Task Creation:: Creating tasks.
4818: * Task Termination:: Terminating tasks.
4819: * Task Information:: Informations on tasks.
4820: * Task Execution:: Thread scheduling in a task.
4821: * Task Special Ports:: How to get and set the task's special ports.
4822: * Syscall Emulation:: How to emulate system calls.
4823: @end menu
4824:
4825:
4826: @node Task Creation
4827: @subsection Task Creation
4828:
4829: @deftypefun kern_return_t task_create (@w{task_t @var{parent_task}}, @w{boolean_t @var{inherit_memory}}, @w{task_t *@var{child_task}})
4830: The function @code{task_create} creates a new task from
4831: @var{parent_task}; the resulting task (@var{child_task}) acquires shared
4832: or copied parts of the parent's address space (see @code{vm_inherit}).
4833: The child task initially contains no threads.
4834:
4835: If @var{inherit_memory} is set, the child task's address space is built
4836: from the parent task according to its memory inheritance values;
4837: otherwise, the child task is given an empty address space.
4838:
4839: The child task gets the three special ports created or copied for it at
4840: task creation. The @code{TASK_KERNEL_PORT} is created and send rights
4841: for it are given to the child and returned to the caller.
4842: @c The following is only relevant if MACH_IPC_COMPAT is used.
4843: @c The @code{TASK_NOTIFY_PORT} is created and receive, ownership and send rights
4844: @c for it are given to the child. The caller has no access to it.
4845: The @code{TASK_BOOTSTRAP_PORT} and the @code{TASK_EXCEPTION_PORT} are
4846: inherited from the parent task. The new task can get send rights to
4847: these ports with the call @code{task_get_special_port}.
4848:
4849: The function returns @code{KERN_SUCCESS} if a new task has been created,
4850: @code{KERN_INVALID_ARGUMENT} if @var{parent_task} is not a valid task
4851: port and @code{KERN_RESOURCE_SHORTAGE} if some critical kernel resource
4852: is unavailable.
4853: @end deftypefun
4854:
4855:
4856: @node Task Termination
4857: @subsection Task Termination
4858:
4859: @deftypefun kern_return_t task_terminate (@w{task_t @var{target_task}})
4860: The function @code{task_terminate} destroys the task specified by
4861: @var{target_task} and all its threads. All resources that are used only
4862: by this task are freed. Any port to which this task has receive and
4863: ownership rights is destroyed.
4864:
4865: The function returns @code{KERN_SUCCESS} if the task has been killed,
4866: @code{KERN_INVALID_ARGUMENT} if @var{target_task} is not a task.
4867: @end deftypefun
4868:
4869:
4870: @node Task Information
4871: @subsection Task Information
4872: @deftypefun task_t mach_task_self ()
4873: The @code{mach_task_self} system call returns the calling thread's task
4874: port.
4875:
4876: @code{mach_task_self} has an effect equivalent to receiving a send right
4877: for the task port. @code{mach_task_self} returns the name of the send
4878: right. In particular, successive calls will increase the calling task's
4879: user-reference count for the send right.
4880:
4881: As a special exception, the kernel will overrun the user reference count
4882: of the task name port, so that this function can not fail for that
4883: reason. Because of this, the user should not deallocate the port right
4884: if an overrun might have happened. Otherwise the reference count could
4885: drop to zero and the send right be destroyed while the user still
4886: expects to be able to use it. As the kernel does not make use of the
4887: number of extant send rights anyway, this is safe to do (the task port
4888: itself is not destroyed, even when there are no send rights anymore).
4889:
1.1.1.2 ! root 4890: The function returns @code{MACH_PORT_NULL} if a resource shortage
1.1 root 4891: prevented the reception of the send right, @code{MACH_PORT_NULL} if the
4892: task port is currently null, @code{MACH_PORT_DEAD} if the task port is
4893: currently dead.
4894: @end deftypefun
4895:
4896: @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}})
4897: The function @code{task_threads} gets send rights to the kernel port for
4898: each thread contained in @var{target_task}. @var{thread_list} is an
4899: array that is created as a result of this call. The caller may wish to
4900: @code{vm_deallocate} this array when the data is no longer needed.
4901:
4902: The function returns @code{KERN_SUCCESS} if the call succeeded and
4903: @code{KERN_INVALID_ARGUMENT} if @var{target_task} is not a task.
4904: @end deftypefun
4905:
4906: @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}})
4907: The function @code{task_info} returns the selected information array for
4908: a task, as specified by @var{flavor}. @var{task_info} is an array of
4909: integers that is supplied by the caller, and filled with specified
4910: information. @var{task_info_count} is supplied as the maximum number of
4911: integers in @var{task_info}. On return, it contains the actual number
4912: of integers in @var{task_info}. The maximum number of integers returned
4913: by any flavor is @code{TASK_INFO_MAX}.
4914:
4915: The type of information returned is defined by @var{flavor}, which can
4916: be one of the following:
4917:
4918: @table @code
4919: @item TASK_BASIC_INFO
4920: The function returns basic information about the task, as defined by
4921: @code{task_basic_info_t}. This includes the user and system time and
4922: memory consumption. The number of integers returned is
4923: @code{TASK_BASIC_INFO_COUNT}.
4924:
4925: @item TASK_EVENTS_INFO
4926: The function returns information about events for the task as defined by
4927: @code{thread_sched_info_t}. This includes statistics about virtual
4928: memory and IPC events like pageouts, pageins and messages sent and
4929: received. The number of integers returned is
4930: @code{TASK_EVENTS_INFO_COUNT}.
4931:
4932: @item TASK_THREAD_TIMES_INFO
4933: The function returns information about the total time for live threads
4934: as defined by @code{task_thread_times_info_t}. The number of integers
4935: returned is @code{TASK_THREAD_TIMES_INFO_COUNT}.
4936: @end table
4937:
4938: The function returns @code{KERN_SUCCESS} if the call succeeded and
4939: @code{KERN_INVALID_ARGUMENT} if @var{target_task} is not a thread or
4940: @var{flavor} is not recognized. The function returns
4941: @code{MIG_ARRAY_TOO_LARGE} if the returned info array is too large for
4942: @var{task_info}. In this case, @var{task_info} is filled as much as
4943: possible and @var{task_infoCnt} is set to the number of elements that
4944: would have been returned if there were enough room.
4945: @end deftypefun
4946:
4947: @deftp {Data type} {struct task_basic_info}
4948: This structure is returned in @var{task_info} by the @code{task_info}
4949: function and provides basic information about the task. You can cast a
4950: variable of type @code{task_info_t} to a pointer of this type if you
4951: provided it as the @var{task_info} parameter for the
4952: @code{TASK_BASIC_INFO} flavor of @code{task_info}. It has the following
4953: members:
4954:
4955: @table @code
4956: @item integer_t suspend_count
4957: suspend count for task
4958:
4959: @item integer_t base_priority
4960: base scheduling priority
4961:
4962: @item vm_size_t virtual_size
4963: number of virtual pages
4964:
4965: @item vm_size_t resident_size
4966: number of resident pages
4967:
4968: @item time_value_t user_time
4969: total user run time for terminated threads
4970:
4971: @item time_value_t system_time
4972: total system run time for terminated threads
4973:
4974: @item time_value_t creation_time
4975: creation time stamp
4976: @end table
4977: @end deftp
4978:
4979: @deftp {Data type} task_basic_info_t
4980: This is a pointer to a @code{struct task_basic_info}.
4981: @end deftp
4982:
4983: @deftp {Data type} {struct task_events_info}
4984: This structure is returned in @var{task_info} by the @code{task_info}
4985: function and provides event statistics for the task. You can cast a
4986: variable of type @code{task_info_t} to a pointer of this type if you
4987: provided it as the @var{task_info} parameter for the
4988: @code{TASK_EVENTS_INFO} flavor of @code{task_info}. It has the
4989: following members:
4990:
4991: @table @code
4992: @item natural_t faults
4993: number of page faults
4994:
4995: @item natural_t zero_fills
4996: number of zero fill pages
4997:
4998: @item natural_t reactivations
4999: number of reactivated pages
5000:
5001: @item natural_t pageins
5002: number of actual pageins
5003:
5004: @item natural_t cow_faults
5005: number of copy-on-write faults
5006:
5007: @item natural_t messages_sent
5008: number of messages sent
5009:
5010: @item natural_t messages_received
5011: number of messages received
5012: @end table
5013: @end deftp
5014:
5015: @deftp {Data type} task_events_info_t
5016: This is a pointer to a @code{struct task_events_info}.
5017: @end deftp
5018:
5019: @deftp {Data type} {struct task_thread_times_info}
5020: This structure is returned in @var{task_info} by the @code{task_info}
5021: function and provides event statistics for the task. You can cast a
5022: variable of type @code{task_info_t} to a pointer of this type if you
5023: provided it as the @var{task_info} parameter for the
5024: @code{TASK_THREAD_TIMES_INFO} flavor of @code{task_info}. It has the
5025: following members:
5026:
5027: @table @code
5028: @item time_value_t user_time
5029: total user run time for live threads
5030:
5031: @item time_value_t system_time
5032: total system run time for live threads
5033: @end table
5034: @end deftp
5035:
5036: @deftp {Data type} task_thread_times_info_t
5037: This is a pointer to a @code{struct task_thread_times_info}.
5038: @end deftp
5039:
5040:
5041: @node Task Execution
5042: @subsection Task Execution
5043:
5044: @deftypefun kern_return_t task_suspend (@w{task_t @var{target_task}})
5045: The function @code{task_suspend} increments the task's suspend count and
5046: stops all threads in the task. As long as the suspend count is positive
5047: newly created threads will not run. This call does not return until all
5048: threads are suspended.
5049:
5050: The count may become greater than one, with the effect that it will take
5051: more than one resume call to restart the task.
5052:
5053: The function returns @code{KERN_SUCCESS} if the task has been suspended
5054: and @code{KERN_INVALID_ARGUMENT} if @var{target_task} is not a task.
5055: @end deftypefun
5056:
5057: @deftypefun kern_return_t task_resume (@w{task_t @var{target_task}})
5058: The function @code{task_resume} decrements the task's suspend count. If
5059: it becomes zero, all threads with zero suspend counts in the task are
5060: resumed. The count may not become negative.
5061:
5062: The function returns @code{KERN_SUCCESS} if the task has been resumed,
5063: @code{KERN_FAILURE} if the suspend count is already at zero and
5064: @code{KERN_INVALID_ARGUMENT} if @var{target_task} is not a task.
5065: @end deftypefun
5066:
5067: @c XXX Should probably be in the "Scheduling" node of the Thread Interface.
5068: @deftypefun kern_return_t task_priority (@w{task_t @var{task}}, @w{int @var{priority}}, @w{boolean_t @var{change_threads}})
5069: The priority of a task is used only for creation of new threads; a new
5070: thread's priority is set to the enclosing task's priority.
5071: @code{task_priority} changes this task priority. It also sets the
5072: priorities of all threads in the task to this new priority if
5073: @var{change_threads} is @code{TRUE}. Existing threads are not affected
5074: otherwise. If this priority change violates the maximum priority of
5075: some threads, as many threads as possible will be changed and an error
5076: code will be returned.
5077:
5078: The function returns @code{KERN_SUCCESS} if the call succeeded,
5079: @code{KERN_INVALID_ARGUMENT} if @var{task} is not a task, or
5080: @var{priority} is not a valid priority and @code{KERN_FAILURE} if
5081: @var{change_threads} was @code{TRUE} and the attempt to change the
5082: priority of at least one existing thread failed because the new priority
5083: would have exceeded that thread's maximum priority.
5084: @end deftypefun
5085:
5086: @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}})
5087: The function @code{task_ras_control} manipulates a task's set of
5088: restartable atomic sequences. If a sequence is installed, and any
5089: thread in the task is preempted within the range
5090: [@var{start_pc},@var{end_pc}], then the thread is resumed at
5091: @var{start_pc}. This enables applications to build atomic sequences
5092: which, when executed to completion, will have executed atomically.
5093: Restartable atomic sequences are intended to be used on systems that do
5094: not have hardware support for low-overhead atomic primitives.
5095:
5096: As a thread can be rolled-back, the code in the sequence should have no
5097: side effects other than a final store at @var{end_pc}. The kernel does
5098: not guarantee that the sequence is restartable. It assumes the
5099: application knows what it's doing.
5100:
5101: A task may have a finite number of atomic sequences that is defined at
5102: compile time.
5103:
1.1.1.2 ! root 5104: The flavor specifies the particular operation that should be applied to
1.1 root 5105: this restartable atomic sequence. Possible values for flavor can be:
5106:
5107: @table @code
5108: @item TASK_RAS_CONTROL_PURGE_ALL
5109: Remove all registered sequences for this task.
5110:
5111: @item TASK_RAS_CONTROL_PURGE_ONE
5112: Remove the named registered sequence for this task.
5113:
5114: @item TASK_RAS_CONTROL_PURGE_ALL_AND_INSTALL_ONE
5115: Atomically remove all registered sequences and install the named
5116: sequence.
5117:
5118: @item TASK_RAS_CONTROL_INSTALL_ONE
5119: Install this sequence.
5120: @end table
5121:
5122: The function returns @code{KERN_SUCCESS} if the operation has been
5123: performed, @code{KERN_INVALID_ADDRESS} if the @var{start_pc} or
5124: @var{end_pc} values are not a valid address for the requested operation
5125: (for example, it is invalid to purge a sequence that has not been
5126: registered), @code{KERN_RESOURCE_SHORTAGE} if an attempt was made to
5127: install more restartable atomic sequences for a task than can be
5128: supported by the kernel, @code{KERN_INVALID_VALUE} if a bad flavor was
5129: specified, @code{KERN_INVALID_ARGUMENT} if @var{target_task} is not a
5130: task and @code{KERN_FAILURE} if the call is not not supported on this
5131: configuration.
5132: @end deftypefun
5133:
5134:
5135: @node Task Special Ports
5136: @subsection Task Special Ports
5137:
5138: @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}})
5139: The function @code{task_get_special_port} returns send rights to one of
5140: a set of special ports for the task specified by @var{task}.
5141:
5142: The special ports associated with a task are the kernel port
5143: (@code{TASK_KERNEL_PORT}), the bootstrap port
5144: (@code{TASK_BOOTSTRAP_PORT}) and the exception port
5145: (@code{TASK_EXCEPTION_PORT}). The bootstrap port is a port to which a
5146: task may send a message requesting other system service ports. This
5147: port is not used by the kernel. The task's exception port is the port
5148: to which messages are sent by the kernel when an exception occurs and
5149: the thread causing the exception has no exception port of its own.
5150:
5151: The following macros to call @code{task_get_special_port} for a specific
5152: port are defined in @code{mach/task_special_ports.h}:
5153: @code{task_get_exception_port} and @code{task_get_bootstrap_port}.
5154:
5155: The function returns @code{KERN_SUCCESS} if the port was returned and
5156: @code{KERN_INVALID_ARGUMENT} if @var{task} is not a task or
5157: @var{which_port} is an invalid port selector.
5158: @end deftypefun
5159:
5160: @deftypefun kern_return_t task_get_kernel_port (@w{task_t @var{task}}, @w{mach_port_t *@var{kernel_port}})
5161: The function @code{task_get_kernel_port} is equivalent to the function
5162: @code{task_get_special_port} with the @var{which_port} argument set to
5163: @code{TASK_KERNEL_PORT}.
5164: @end deftypefun
5165:
5166: @deftypefun kern_return_t task_get_exception_port (@w{task_t @var{task}}, @w{mach_port_t *@var{exception_port}})
5167: The function @code{task_get_exception_port} is equivalent to the
5168: function @code{task_get_special_port} with the @var{which_port} argument
5169: set to @code{TASK_EXCEPTION_PORT}.
5170: @end deftypefun
5171:
5172: @deftypefun kern_return_t task_get_bootstrap_port (@w{task_t @var{task}}, @w{mach_port_t *@var{bootstrap_port}})
5173: The function @code{task_get_bootstrap_port} is equivalent to the
5174: function @code{task_get_special_port} with the @var{which_port} argument
5175: set to @code{TASK_BOOTSTRAP_PORT}.
5176: @end deftypefun
5177:
5178: @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}})
5179: The function @code{thread_set_special_port} sets one of a set of special
5180: ports for the task specified by @var{task}.
5181:
5182: The special ports associated with a task are the kernel port
5183: (@code{TASK_KERNEL_PORT}), the bootstrap port
5184: (@code{TASK_BOOTSTRAP_PORT}) and the exception port
5185: (@code{TASK_EXCEPTION_PORT}). The bootstrap port is a port to which a
5186: thread may send a message requesting other system service ports. This
5187: port is not used by the kernel. The task's exception port is the port
5188: to which messages are sent by the kernel when an exception occurs and
5189: the thread causing the exception has no exception port of its own.
5190:
5191: The function returns @code{KERN_SUCCESS} if the port was set and
5192: @code{KERN_INVALID_ARGUMENT} if @var{task} is not a task or
5193: @var{which_port} is an invalid port selector.
5194: @end deftypefun
5195:
5196: @deftypefun kern_return_t task_set_kernel_port (@w{task_t @var{task}}, @w{mach_port_t @var{kernel_port}})
5197: The function @code{task_set_kernel_port} is equivalent to the function
5198: @code{task_set_special_port} with the @var{which_port} argument set to
5199: @code{TASK_KERNEL_PORT}.
5200: @end deftypefun
5201:
5202: @deftypefun kern_return_t task_set_exception_port (@w{task_t @var{task}}, @w{mach_port_t @var{exception_port}})
5203: The function @code{task_set_exception_port} is equivalent to the
5204: function @code{task_set_special_port} with the @var{which_port} argument
5205: set to @code{TASK_EXCEPTION_PORT}.
5206: @end deftypefun
5207:
5208: @deftypefun kern_return_t task_set_bootstrap_port (@w{task_t @var{task}}, @w{mach_port_t @var{bootstrap_port}})
5209: The function @code{task_set_bootstrap_port} is equivalent to the
5210: function @code{task_set_special_port} with the @var{which_port} argument
5211: set to @code{TASK_BOOTSTRAP_PORT}.
5212: @end deftypefun
5213:
5214:
5215: @node Syscall Emulation
5216: @subsection Syscall Emulation
5217:
5218: @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}})
5219: The function @code{task_get_emulation_vector} gets the user-level
5220: handler entry points for all emulated system calls.
5221: @c XXX Fixme
5222: @end deftypefun
5223:
5224: @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}})
5225: The function @code{task_set_emulation_vector} establishes user-level
5226: handlers for the specified system calls. Non-emulated system calls are
5227: specified with an entry of @code{EML_ROUTINE_NULL}. System call
1.1.1.2 ! root 5228: emulation handlers are inherited by the children of @var{task}.
1.1 root 5229: @c XXX Fixme
5230: @end deftypefun
5231:
5232: @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}})
5233: The function @code{task_set_emulation} establishes a user-level handler
5234: for the specified system call. System call emulation handlers are
1.1.1.2 ! root 5235: inherited by the children of @var{task}.
1.1 root 5236: @c XXX Fixme
5237: @end deftypefun
5238:
5239: @c XXX Fixme datatype emulation_vector_t
5240:
5241:
5242: @node Profiling
5243: @section Profiling
5244:
5245: @deftypefun kern_return_t task_enable_pc_sampling (@w{task_t @var{task}}, @w{int *@var{ticks}}, @w{sampled_pc_flavor_t @var{flavor}})
5246: @deftypefunx kern_return_t thread_enable_pc_sampling (@w{thread_t @var{thread}}, @w{int *@var{ticks}}, @w{sampled_pc_flavor_t @var{flavor}})
5247: The function @code{task_enable_pc_sampling} enables PC sampling for
5248: @var{task}, the function @code{thread_enable_pc_sampling} enables PC
5249: sampling for @var{thread}. The kernel's idea of clock granularity is
5250: returned in @var{ticks} in usecs. (this value should not be trusted). The
5251: sampling flavor is specified by @var{flavor}.
5252:
5253: The function returns @code{KERN_SUCCESS} if the operation is completed successfully
5254: and @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a valid thread.
5255: @end deftypefun
5256:
5257: @deftypefun kern_return_t task_disable_pc_sampling (@w{task_t @var{task}}, @w{int *@var{sample_count}})
5258: @deftypefunx kern_return_t thread_disable_pc_sampling (@w{thread_t @var{thread}}, @w{int *@var{sample_count}})
5259: The function @code{task_disable_pc_sampling} disables PC sampling for
5260: @var{task}, the function @code{thread_disable_pc_sampling} disables PC
5261: sampling for @var{thread}. The number of sample elements in the kernel
5262: for the thread is returned in @var{sample_count}.
5263:
5264: The function returns @code{KERN_SUCCESS} if the operation is completed successfully
5265: and @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a valid thread.
5266: @end deftypefun
5267:
5268: @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}})
5269: @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}})
5270: The function @code{task_get_sampled_pcs} extracts the PC samples for
5271: @var{task}, the function @code{thread_get_sampled_pcs} extracts the PC
5272: samples for @var{thread}. @var{seqno} is the sequence number of the
5273: sampled PCs. This is useful for determining when a collector thread has
5274: missed a sample. The sampled PCs for the thread are returned in
5275: @var{sampled_pcs}. @var{sample_count} contains the number of sample
5276: elements returned.
5277:
5278: The function returns @code{KERN_SUCCESS} if the operation is completed successfully,
5279: @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a valid thread and
5280: @code{KERN_FAILURE} if @var{thread} is not sampled.
5281: @end deftypefun
5282:
5283:
5284: @deftp {Data type} sampled_pc_t
5285: This structure is returned in @var{sampled_pcs} by the
5286: @code{thread_get_sampled_pcs} and @code{task_get_sampled_pcs} functions
5287: and provides pc samples for threads or tasks. It has the following
5288: members:
5289:
5290: @table @code
5291: @item natural_t id
5292: A thread-specific unique identifier.
5293:
5294: @item vm_offset_t pc
5295: A pc value.
5296:
5297: @item sampled_pc_flavor_t sampletype
5298: The type of the sample as per flavor.
5299: @end table
5300: @end deftp
5301:
5302:
5303: @deftp {Data type} sampled_pc_flavor_t
5304: This data type specifies a pc sample flavor, either as argument passed
5305: in @var{flavor} to the @code{thread_enable_pc_sample} and
5306: @code{thread_disable_pc_sample} functions, or as member
5307: @code{sampletype} in the @code{sample_pc_t} data type. The flavor is a
5308: bitwise-or of the possible flavors defined in @file{mach/pc_sample.h}:
5309:
5310: @table @code
5311: @item SAMPLED_PC_PERIODIC
5312: default
5313: @item SAMPLED_PC_VM_ZFILL_FAULTS
5314: zero filled fault
5315: @item SAMPLED_PC_VM_REACTIVATION_FAULTS
5316: reactivation fault
5317: @item SAMPLED_PC_VM_PAGEIN_FAULTS
5318: pagein fault
5319: @item SAMPLED_PC_VM_COW_FAULTS
5320: copy-on-write fault
5321: @item SAMPLED_PC_VM_FAULTS_ANY
5322: any fault
5323: @item SAMPLED_PC_VM_FAULTS
5324: the bitwise-or of @code{SAMPLED_PC_VM_ZFILL_FAULTS},
5325: @code{SAMPLED_PC_VM_REACTIVATION_FAULTS},
5326: @code{SAMPLED_PC_VM_PAGEIN_FAULTS} and @code{SAMPLED_PC_VM_COW_FAULTS}.
5327: @end table
5328: @end deftp
5329:
5330: @c XXX sampled_pc_array_t, sampled_pc_seqno_t
5331:
5332:
5333: @node Host Interface
5334: @chapter Host Interface
5335: @cindex host interface
5336:
5337: This section describes the Mach interface to a host executing a Mach
5338: kernel. The interface allows to query statistics about a host and
5339: control its behaviour.
5340:
5341: A host is represented by two ports, a name port @var{host} used to query
5342: information about the host accessible to everyone, and a control port
5343: @var{host_priv} used to manipulate it. For example, you can query the
5344: current time using the name port, but to change the time you need to
5345: send a message to the host control port.
5346:
5347: Everything described in this section is declared in the header file
5348: @file{mach.h}.
5349:
5350: @menu
5351: * Host Ports:: Ports representing a host.
5352: * Host Information:: Retrieval of information about a host.
5353: * Host Time:: Operations on the time as seen by a host.
5354: * Host Reboot:: Rebooting the system.
5355: @end menu
5356:
5357:
5358: @node Host Ports
5359: @section Host Ports
5360: @cindex host ports
5361: @cindex ports representing a host
5362:
5363: @cindex host name port
5364: @deftp {Data type} host_t
5365: This is a @code{mach_port_t} and used to hold the port name of a host
5366: name port (or short: host port). Any task can get a send right to the
5367: name port of the host running the task using the @code{mach_host_self}
5368: system call. The name port can be used query information about the
5369: host, for example the current time.
5370: @end deftp
5371:
5372: @deftypefun host_t mach_host_self ()
5373: The @code{mach_host_self} system call returns the calling thread's host
5374: name port. It has an effect equivalent to receiving a send right for
5375: the host port. @code{mach_host_self} returns the name of the send
5376: right. In particular, successive calls will increase the calling task's
5377: user-reference count for the send right.
5378:
5379: As a special exception, the kernel will overrun the user reference count
5380: of the host name port, so that this function can not fail for that
5381: reason. Because of this, the user should not deallocate the port right
5382: if an overrun might have happened. Otherwise the reference count could
5383: drop to zero and the send right be destroyed while the user still
5384: expects to be able to use it. As the kernel does not make use of the
5385: number of extant send rights anyway, this is safe to do (the host port
5386: itself is never destroyed).
5387:
5388: The function returns @code{MACH_PORT_NULL} if a resource shortage
5389: prevented the reception of the send right.
5390:
5391: This function is also available in @file{mach/mach_traps.h}.
5392: @end deftypefun
5393:
5394: @cindex host control port
5395: @deftp {Data type} host_priv_t
5396: This is a @code{mach_port_t} and used to hold the port name of a
5397: privileged host control port. A send right to the host control port is
5398: inserted into the first task at bootstrap (@pxref{Modules}). This is
5399: the only way to get access to the host control port in Mach, so the
5400: initial task has to preserve the send right carefully, moving a copy of
5401: it to other privileged tasks if necessary and denying access to
5402: unprivileged tasks.
5403: @end deftp
5404:
5405:
5406: @node Host Information
5407: @section Host Information
5408:
5409: @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}})
5410: The @code{host_info} function returns various information about
5411: @var{host}. @var{host_info} is an array of integers that is supplied by
5412: the caller. It will be filled with the requested information.
5413: @var{host_info_count} is supplied as the maximum number of integers in
5414: @var{host_info}. On return, it contains the actual number of integers
5415: in @var{host_info}. The maximum number of integers returned by any
5416: flavor is @code{HOST_INFO_MAX}.
5417:
5418: The type of information returned is defined by @var{flavor}, which can
5419: be one of the following:
5420:
5421: @table @code
5422: @item HOST_BASIC_INFO
5423: The function returns basic information about the host, as defined by
5424: @code{host_basic_info_t}. This includes the number of processors, their
5425: type, and the amount of memory installed in the system. The number of
5426: integers returned is @code{HOST_BASIC_INFO_COUNT}. For how to get more
5427: information about the processor, see @ref{Processor Interface}.
5428:
5429: @item HOST_PROCESSOR_SLOTS
5430: The function returns the numbers of the slots with active processors in
5431: them. The number of integers returned can be up to @code{max_cpus}, as
5432: returned by the @code{HOST_BASIC_INFO} flavor of @code{host_info}.
5433:
5434: @item HOST_SCHED_INFO
5435: The function returns information of interest to schedulers as defined by
5436: @code{host_sched_info_t}. The number of integers returned is
5437: @code{HOST_SCHED_INFO_COUNT}.
5438: @end table
5439:
5440: The function returns @code{KERN_SUCCESS} if the call succeeded and
5441: @code{KERN_INVALID_ARGUMENT} if @var{host} is not a host or @var{flavor}
5442: is not recognized. The function returns @code{MIG_ARRAY_TOO_LARGE} if
5443: the returned info array is too large for @var{host_info}. In this case,
5444: @var{host_info} is filled as much as possible and @var{host_info_count}
5445: is set to the number of elements that would be returned if there were
5446: enough room.
5447: @c BUGS Availability limited. Systems without this call support a
5448: @c host_info call with an incompatible calling sequence.
5449: @end deftypefun
5450:
5451: @deftp {Data type} {struct host_basic_info}
5452: A pointer to this structure is returned in @var{host_info} by the
5453: @code{host_info} function and provides basic information about the host.
5454: You can cast a variable of type @code{host_info_t} to a pointer of this
5455: type if you provided it as the @var{host_info} parameter for the
5456: @code{HOST_BASIC_INFO} flavor of @code{host_info}. It has the following
5457: members:
5458:
5459: @table @code
5460: @item int max_cpus
5461: The maximum number of possible processors for which the kernel is
5462: configured.
5463:
5464: @item int avail_cpus
5465: The number of cpus currently available.
5466:
5467: @item vm_size_t memory_size
5468: The size of physical memory in bytes.
5469:
5470: @item cpu_type_t cpu_type
5471: The type of the master processor.
5472:
5473: @item cpu_subtype_t cpu_subtype
5474: The subtype of the master processor.
5475: @end table
5476:
5477: The type and subtype of the individual processors are also available
5478: by @code{processor_info}, see @ref{Processor Interface}.
5479: @end deftp
5480:
5481: @deftp {Data type} host_basic_info_t
5482: This is a pointer to a @code{struct host_basic_info}.
5483: @end deftp
5484:
5485: @deftp {Data type} {struct host_sched_info}
5486: A pointer to this structure is returned in @var{host_info} by the
5487: @code{host_info} function and provides information of interest to
5488: schedulers. You can cast a variable of type @code{host_info_t} to a
5489: pointer of this type if you provided it as the @var{host_info} parameter
5490: for the @code{HOST_SCHED_INFO} flavor of @code{host_info}. It has the
5491: following members:
5492:
5493: @table @code
5494: @item int min_timeout
5495: The minimum timeout and unit of time in milliseconds.
5496:
5497: @item int min_quantum
5498: The minimum quantum and unit of quantum in milliseconds.
5499: @end table
5500: @end deftp
5501:
5502: @deftp {Data type} host_sched_info_t
5503: This is a pointer to a @code{struct host_sched_info}.
5504: @end deftp
5505:
5506: @deftypefun kern_return_t host_kernel_version (@w{host_t @var{host}}, @w{kernel_version_t *@var{version}})
5507: The @code{host_kernel_version} function returns the version string
5508: compiled into the kernel executing on @var{host} at the time it was
5509: built in the character string @var{version}. This string describes the
5510: version of the kernel. The constant @code{KERNEL_VERSION_MAX} should be
5511: used to dimension storage for the returned string if the
5512: @code{kernel_version_t} declaration is not used.
5513:
5514: If the version string compiled into the kernel is longer than
5515: @code{KERNEL_VERSION_MAX}, the result is truncated and not necessarily
5516: null-terminated.
5517:
5518: If @var{host} is not a valid send right to a host port, the function
5519: returns @code{KERN_INVALID_ARGUMENT}. If @var{version} points to
5520: inaccessible memory, it returns @code{KERN_INVALID_ADDRESS}, and
5521: @code{KERN_SUCCESS} otherwise.
5522: @end deftypefun
5523:
5524: @deftypefun kern_return_t host_get_boot_info (@w{host_priv_t @var{host_priv}}, @w{kernel_boot_info_t @var{boot_info}})
5525: The @code{host_get_boot_info} function returns the boot-time information
5526: string supplied by the operator to the kernel executing on
5527: @var{host_priv} in the character string @var{boot_info}. The constant
5528: @code{KERNEL_BOOT_INFO_MAX} should be used to dimension storage for the
5529: returned string if the @code{kernel_boot_info_t} declaration is not
5530: used.
5531:
5532: If the boot-time information string supplied by the operator is longer
5533: than @code{KERNEL_BOOT_INFO_MAX}, the result is truncated and not
5534: necessarily null-terminated.
5535: @end deftypefun
5536:
5537:
5538: @node Host Time
5539: @section Host Time
5540:
5541: @deftp {Data type} time_value_t
5542: This is the representation of a time in Mach. It is a @code{struct
5543: time_value} and consists of the following members:
5544:
5545: @table @code
5546: @item integer_t seconds
5547: The number of seconds.
5548: @item integer_t microseconds
5549: The number of microseconds.
5550: @end table
5551: @end deftp
5552:
5553: The number of microseconds should always be smaller than
5554: @code{TIME_MICROS_MAX} (100000). A time with this property is
5555: @dfn{normalized}. Normalized time values can be manipulated with the
5556: following macros:
5557:
5558: @defmac time_value_add_usec (@w{time_value_t *@var{val}}, @w{integer_t *@var{micros}})
5559: Add @var{micros} microseconds to @var{val}. If @var{val} is normalized
5560: and @var{micros} smaller than @code{TIME_MICROS_MAX}, @var{val} will be
5561: normalized afterwards.
5562: @end defmac
5563:
5564: @defmac time_value_add (@w{time_value_t *@var{result}}, @w{time_value_t *@var{addend}})
5565: Add the values in @var{addend} to @var{result}. If both are normalized,
5566: @var{result} will be normalized afterwards.
5567: @end defmac
5568:
5569: A variable of type @code{time_value_t} can either represent a duration
5570: or a fixed point in time. In the latter case, it shall be interpreted as
5571: the number of seconds and microseconds after the epoch 1. Jan 1970.
5572:
5573: @deftypefun kern_return_t host_get_time (@w{host_t @var{host}}, @w{time_value_t *@var{current_time}})
5574: Get the current time as seen by @var{host}. On success, the time passed
5575: since the epoch is returned in @var{current_time}.
5576: @end deftypefun
5577:
5578: @deftypefun kern_return_t host_set_time (@w{host_priv_t @var{host_priv}}, @w{time_value_t @var{new_time}})
5579: Set the time of @var{host_priv} to @var{new_time}.
5580: @end deftypefun
5581:
5582: @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}})
5583: Arrange for the current time as seen by @var{host_priv} to be gradually
5584: changed by the adjustment value @var{new_adjustment}, and return the old
5585: adjustment value in @var{old_adjustment}.
5586: @end deftypefun
5587:
5588: For efficiency, the current time is available through a mapped-time
5589: interface.
5590:
5591: @deftp {Data type} mapped_time_value_t
5592: This structure defines the mapped-time interface. It has the following
5593: members:
5594:
5595: @table @code
5596: @item integer_t seconds
5597: The number of seconds.
5598:
5599: @item integer_t microseconds
5600: The number of microseconds.
5601:
5602: @item integer_t check_seconds
5603: This is a copy of the seconds value, which must be checked to protect
5604: against a race condition when reading out the two time values.
5605: @end table
5606: @end deftp
5607:
5608: Here is an example how to read out the current time using the
5609: mapped-time interface:
5610:
5611: @c XXX Complete the example.
5612: @example
5613: do
5614: @{
5615: secs = mtime->seconds;
5616: usecs = mtime->microseconds;
5617: @}
5618: while (secs != mtime->check_seconds);
5619: @end example
5620:
5621:
5622: @node Host Reboot
5623: @section Host Reboot
5624:
5625: @deftypefun kern_return_t host_reboot (@w{host_priv_t @var{host_priv}}, @w{int @var{options}})
5626: Reboot the host specified by @var{host_priv}. The argument
5627: @var{options} specifies the flags. The available flags are defined in
5628: @file{sys/reboot.h}:
5629:
5630: @table @code
5631: @item RB_HALT
5632: Do not reboot, but halt the machine.
5633:
5634: @item RB_DEBUGGER
5635: Do not reboot, but enter kernel debugger from user space.
5636: @end table
5637:
5638: If successful, the function might not return.
5639: @end deftypefun
5640:
5641:
5642: @node Processors and Processor Sets
5643: @chapter Processors and Processor Sets
5644:
5645: This section describes the Mach interface to processor sets and
5646: individual processors. The interface allows to group processors into
5647: sets and control the processors and processor sets.
5648:
5649: A processor is not a central part of the interface. It is mostly of
5650: relevance as a part of a processor set. Threads are always assigned to
5651: processor sets, and all processors in a set are equally involved in
5652: executing all threads assigned to that set.
5653:
5654: The processor set is represented by two ports, a name port
5655: @var{processor_set_name} used to query information about the host
5656: accessible to everyone, and a control port @var{processor_set} used to
5657: manipulate it.
5658:
5659: @menu
5660: * Processor Set Interface:: How to work with processor sets.
5661: * Processor Interface:: How to work with individual processors.
5662: @end menu
5663:
5664:
5665: @node Processor Set Interface
5666: @section Processor Set Interface
5667:
5668: @menu
5669: * Processor Set Ports:: Ports representing a processor set.
5670: * Processor Set Access:: How the processor sets are accessed.
5671: * Processor Set Creation:: How new processor sets are created.
5672: * Processor Set Destruction:: How processor sets are destroyed.
5673: * Tasks and Threads on Sets:: Assigning tasks, threads to processor sets.
5674: * Processor Set Priority:: Specifying the priority of a processor set.
5675: * Processor Set Policy:: Changing the processor set policies.
5676: * Processor Set Info:: Obtaining information about a processor set.
5677: @end menu
5678:
5679:
5680: @node Processor Set Ports
5681: @subsection Processor Set Ports
5682: @cindex processor set ports
5683: @cindex ports representing a processor set
5684:
5685: @cindex processor set name port
5686: @cindex port representing a processor set name
5687: @deftp {Data type} processor_set_name_t
5688: This is a @code{mach_port_t} and used to hold the port name of a
5689: processor set name port that names the processor set. Any task can get
5690: a send right to name port of a processor set. The processor set name
5691: port allows to get information about the processor set.
5692: @end deftp
5693:
5694: @cindex processor set port
5695: @deftp {Data type} processor_set_t
5696: This is a @code{mach_port_t} and used to hold the port name of a
5697: privileged processor set control port that represents the processor set.
5698: Operations on the processor set are implemented as remote procedure
5699: calls to the processor set port. The processor set port allows to
5700: manipulate the processor set.
5701: @end deftp
5702:
5703:
5704: @node Processor Set Access
5705: @subsection Processor Set Access
5706:
5707: @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}})
5708: The function @code{host_processor_sets} gets send rights to the name
5709: port for each processor set currently assigned to @var{host}.
5710:
5711: @code{host_processor_set_priv} can be used to obtain the control ports
5712: from these if desired. @var{processor_sets} is an array that is
5713: created as a result of this call. The caller may wish to
5714: @code{vm_deallocate} this array when the data is no longer needed.
5715: @var{processor_sets_count} is set to the number of processor sets in the
5716: @var{processor_sets}.
5717:
5718: This function returns @code{KERN_SUCCESS} if the call succeeded and
5719: @code{KERN_INVALID_ARGUMENT} if @var{host} is not a host.
5720: @end deftypefun
5721:
5722: @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}})
5723: The function @code{host_processor_set_priv} allows a privileged
5724: application to obtain the control port @var{set} for an existing
5725: processor set from its name port @var{set_name}. The privileged host
5726: port @var{host_priv} is required.
5727:
5728: This function returns @code{KERN_SUCCESS} if the call succeeded and
5729: @code{KERN_INVALID_ARGUMENT} if @var{host_priv} is not a valid host
5730: control port.
5731: @end deftypefun
5732:
5733: @deftypefun kern_return_t processor_set_default (@w{host_t @var{host}}, @w{processor_set_name_t *@var{default_set}})
5734: The function @code{processor_set_default} returns the default processor
5735: set of @var{host} in @var{default_set}. The default processor set is
5736: used by all threads, tasks, and processors that are not explicitly
5737: assigned to other sets. processor_set_default returns a port that can
5738: be used to obtain information about this set (e.g. how many threads are
5739: assigned to it). This port cannot be used to perform operations on that
5740: set.
5741:
5742: This function returns @code{KERN_SUCCESS} if the call succeeded,
5743: @code{KERN_INVALID_ARGUMENT} if @var{host} is not a host and
5744: @code{KERN_INVALID_ADDRESS} if @var{default_set} points to
5745: inaccessible memory.
5746: @end deftypefun
5747:
5748:
5749: @node Processor Set Creation
5750: @subsection Processor Set Creation
5751:
5752: @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}})
5753: The function @code{processor_set_create} creates a new processor set on
5754: @var{host} and returns the two ports associated with it. The port
5755: returned in @var{new_set} is the actual port representing the set. It
5756: is used to perform operations such as assigning processors, tasks, or
5757: threads. The port returned in @var{new_name} identifies the set, and is
5758: used to obtain information about the set.
5759:
5760: This function returns @code{KERN_SUCCESS} if the call succeeded,
5761: @code{KERN_INVALID_ARGUMENT} if @var{host} is not a host,
5762: @code{KERN_INVALID_ADDRESS} if @var{new_set} or @var{new_name} points to
5763: inaccessible memory and @code{KERN_FAILURE} is the operating system does
5764: not support processor allocation.
5765: @end deftypefun
5766:
5767:
5768: @node Processor Set Destruction
5769: @subsection Processor Set Destruction
5770:
5771: @deftypefun kern_return_t processor_set_destroy (@w{processor_set_t @var{processor_set}})
5772: The function @code{processor_set_destroy} destroys the specified
5773: processor set. Any assigned processors, tasks, or threads are
5774: reassigned to the default set. The object port for the processor set is
5775: required (not the name port). The default processor set cannot be
5776: destroyed.
5777:
5778: This function returns @code{KERN_SUCCESS} if the set was destroyed,
5779: @code{KERN_FAILURE} if an attempt was made to destroy the default
5780: processor set, or the operating system does not support processor
5781: allocation, and @code{KERN_INVALID_ARGUMENT} if @var{processor_set} is
5782: not a valid processor set control port.
5783: @end deftypefun
5784:
5785:
5786: @node Tasks and Threads on Sets
5787: @subsection Tasks and Threads on Sets
5788:
5789: @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}})
5790: The function @code{processor_set_tasks} gets send rights to the kernel
5791: port for each task currently assigned to @var{processor_set}.
5792:
5793: @var{task_list} is an array that is created as a result of this call.
5794: The caller may wish to @code{vm_deallocate} this array when the data is
5795: no longer needed. @var{task_count} is set to the number of tasks in the
5796: @var{task_list}.
5797:
5798: This function returns @code{KERN_SUCCESS} if the call succeeded and
5799: @code{KERN_INVALID_ARGUMENT} if @var{processor_set} is not a processor
5800: set.
5801: @end deftypefun
5802:
5803: @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}})
5804: The function @code{processor_set_thread} gets send rights to the kernel
5805: port for each thread currently assigned to @var{processor_set}.
5806:
5807: @var{thread_list} is an array that is created as a result of this call.
5808: The caller may wish to @code{vm_deallocate} this array when the data is
5809: no longer needed. @var{thread_count} is set to the number of threads in
5810: the @var{thread_list}.
5811:
5812: This function returns @code{KERN_SUCCESS} if the call succeeded and
5813: @code{KERN_INVALID_ARGUMENT} if @var{processor_set} is not a processor
5814: set.
5815: @end deftypefun
5816:
5817: @deftypefun kern_return_t task_assign (@w{task_t @var{task}}, @w{processor_set_t @var{processor_set}}, @w{boolean_t @var{assign_threads}})
5818: The function @code{task_assign} assigns @var{task} the set
5819: @var{processor_set}. This assignment is for the purposes of determining
5820: the initial assignment of newly created threads in task. Any previous
5821: assignment of the task is nullified. Existing threads within the task
5822: are also reassigned if @var{assign_threads} is @code{TRUE}. They are
5823: not affected if it is @code{FALSE}.
5824:
5825: This function returns @code{KERN_SUCCESS} if the assignment has been
5826: performed and @code{KERN_INVALID_ARGUMENT} if @var{task} is not a task,
5827: or @var{processor_set} is not a processor set on the same host as
5828: @var{task}.
5829: @end deftypefun
5830:
5831: @deftypefun kern_return_t task_assign_default (@w{task_t @var{task}}, @w{boolean_t @var{assign_threads}})
5832: The function @code{task_assign_default} is a variant of
5833: @code{task_assign} that assigns the task to the default processor set on
5834: that task's host. This variant exists because the control port for the
1.1.1.2 ! root 5835: default processor set is privileged and not usually available to users.
1.1 root 5836:
5837: This function returns @code{KERN_SUCCESS} if the assignment has been
5838: performed and @code{KERN_INVALID_ARGUMENT} if @var{task} is not a task.
5839: @end deftypefun
5840:
5841: @deftypefun kern_return_t task_get_assignment (@w{task_t @var{task}}, @w{processor_set_name_t *@var{assigned_set}})
5842: The function @code{task_get_assignment} returns the name of the
5843: processor set to which the thread is currently assigned in
5844: @var{assigned_set}. This port can only be used to obtain information
5845: about the processor set.
5846:
5847: This function returns @code{KERN_SUCCESS} if the assignment has been
5848: performed, @code{KERN_INVALID_ADDRESS} if @var{processor_set} points to
5849: inaccessible memory, and @code{KERN_INVALID_ARGUMENT} if @var{task} is
5850: not a task.
5851: @end deftypefun
5852:
5853: @deftypefun kern_return_t thread_assign (@w{thread_t @var{thread}}, @w{processor_set_t @var{processor_set}})
5854: The function @code{thread_assign} assigns @var{thread} the set
5855: @var{processor_set}. After the assignment is completed, the thread only
5856: executes on processors assigned to the designated processor set. If
5857: there are no such processors, then the thread is unable to execute. Any
5858: previous assignment of the thread is nullified. Unix system call
5859: compatibility code may temporarily force threads to execute on the
5860: master processor.
5861:
5862: This function returns @code{KERN_SUCCESS} if the assignment has been
5863: performed and @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a
5864: thread, or @var{processor_set} is not a processor set on the same host
5865: as @var{thread}.
5866: @end deftypefun
5867:
5868: @deftypefun kern_return_t thread_assign_default (@w{thread_t @var{thread}})
5869: The function @code{thread_assign_default} is a variant of
5870: @code{thread_assign} that assigns the thread to the default processor
5871: set on that thread's host. This variant exists because the control port
1.1.1.2 ! root 5872: for the default processor set is privileged and not usually available
1.1 root 5873: to users.
5874:
5875: This function returns @code{KERN_SUCCESS} if the assignment has been
5876: performed and @code{KERN_INVALID_ARGUMENT} if @var{thread} is not a
5877: thread.
5878: @end deftypefun
5879:
5880: @deftypefun kern_return_t thread_get_assignment (@w{thread_t @var{thread}}, @w{processor_set_name_t *@var{assigned_set}})
5881: The function @code{thread_get_assignment} returns the name of the
5882: processor set to which the thread is currently assigned in
5883: @var{assigned_set}. This port can only be used to obtain information
5884: about the processor set.
5885:
5886: This function returns @code{KERN_SUCCESS} if the assignment has been
5887: performed, @code{KERN_INVALID_ADDRESS} if @var{processor_set} points to
5888: inaccessible memory, and @code{KERN_INVALID_ARGUMENT} if @var{thread} is
5889: not a thread.
5890: @end deftypefun
5891:
5892:
5893: @node Processor Set Priority
5894: @subsection Processor Set Priority
5895:
5896: @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}})
5897: The function @code{processor_set_max_priority} is used to set the
5898: maximum priority for a processor set. The priority of a processor set
5899: is used only for newly created threads (thread's maximum priority is set
5900: to processor set's) and the assignment of threads to the set (thread's
5901: maximum priority is reduced if it exceeds the set's maximum priority,
5902: thread's priority is similarly reduced).
5903: @code{processor_set_max_priority} changes this priority. It also sets
5904: the maximum priority of all threads assigned to the processor set to
5905: this new priority if @var{change_threads} is @code{TRUE}. If this
5906: maximum priority is less than the priorities of any of these threads,
5907: their priorities will also be set to this new value.
5908:
5909: This function returns @code{KERN_SUCCESS} if the call succeeded and
5910: @code{KERN_INVALID_ARGUMENT} if @var{processor_set} is not a processor
5911: set or @var{priority} is not a valid priority.
5912: @end deftypefun
5913:
5914:
5915: @node Processor Set Policy
5916: @subsection Processor Set Policy
5917:
5918: @deftypefun kern_return_t processor_set_policy_enable (@w{processor_set_t @var{processor_set}}, @w{int @var{policy}})
5919: @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}})
5920: Processor sets may restrict the scheduling policies to be used for
5921: threads assigned to them. These two calls provide the mechanism for
5922: designating permitted and forbidden policies. The current set of
5923: permitted policies can be obtained from @code{processor_set_info}.
5924: Timesharing may not be forbidden by any processor set. This is a
5925: compromise to reduce the complexity of the assign operation; any thread
5926: whose policy is forbidden by the target processor set has its policy
5927: reset to timesharing. If the @var{change_threads} argument to
5928: @code{processor_set_policy_disable} is true, threads currently assigned
5929: to this processor set and using the newly disabled policy will have
5930: their policy reset to timesharing.
5931:
5932: @file{mach/policy.h} contains the allowed policies; it is included by
5933: @file{mach.h}. Not all policies (e.g. fixed priority) are supported by
5934: all systems.
5935:
5936: This function returns @code{KERN_SUCCESS} if the operation was completed
5937: successfully and @code{KERN_INVALID_ARGUMENT} if @var{processor_set} is
5938: not a processor set or @var{policy} is not a valid policy, or an attempt
5939: was made to disable timesharing.
5940: @end deftypefun
5941:
5942:
5943: @node Processor Set Info
5944: @subsection Processor Set Info
5945:
5946: @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}})
5947: The function @code{processor_set_info} returns the selected information array
5948: for a processor set, as specified by @var{flavor}.
5949:
5950: @var{host} is set to the host on which the processor set resides. This
5951: is the non-privileged host port.
5952:
5953: @var{processor_set_info} is an array of integers that is supplied by the
5954: caller and returned filled with specified information.
5955: @var{processor_set_info_count} is supplied as the maximum number of
5956: integers in @var{processor_set_info}. On return, it contains the actual
5957: number of integers in @var{processor_set_info}. The maximum number of
5958: integers returned by any flavor is @code{PROCESSOR_SET_INFO_MAX}.
5959:
5960: The type of information returned is defined by @var{flavor}, which can
5961: be one of the following:
5962:
5963: @table @code
5964: @item PROCESSOR_SET_BASIC_INFO
5965: The function returns basic information about the processor set, as
5966: defined by @code{processor_set_basic_info_t}. This includes the number
5967: of tasks and threads assigned to the processor set. The number of
5968: integers returned is @code{PROCESSOR_SET_BASIC_INFO_COUNT}.
5969:
5970: @item PROCESSOR_SET_SCHED_INFO
1.1.1.2 ! root 5971: The function returns information about the scheduling policy for the
1.1 root 5972: processor set as defined by @code{processor_set_sched_info_t}. The
5973: number of integers returned is @code{PROCESSOR_SET_SCHED_INFO_COUNT}.
5974: @end table
5975:
5976: Some machines may define additional (machine-dependent) flavors.
5977:
5978: The function returns @code{KERN_SUCCESS} if the call succeeded and
5979: @code{KERN_INVALID_ARGUMENT} if @var{processor_set} is not a processor
5980: set or @var{flavor} is not recognized. The function returns
5981: @code{MIG_ARRAY_TOO_LARGE} if the returned info array is too large for
5982: @var{processor_set_info}. In this case, @var{processor_set_info} is
5983: filled as much as possible and @var{processor_set_info_count} is set to the
5984: number of elements that would have been returned if there were enough
5985: room.
5986: @end deftypefun
5987:
5988: @deftp {Data type} {struct processor_set_basic_info}
5989: This structure is returned in @var{processor_set_info} by the
5990: @code{processor_set_info} function and provides basic information about
5991: the processor set. You can cast a variable of type
5992: @code{processor_set_info_t} to a pointer of this type if you provided it
5993: as the @var{processor_set_info} parameter for the
5994: @code{PROCESSOR_SET_BASIC_INFO} flavor of @code{processor_set_info}. It
5995: has the following members:
5996:
5997: @table @code
5998: @item int processor_count
5999: number of processors
6000:
6001: @item int task_count
6002: number of tasks
6003:
6004: @item int thread_count
6005: number of threads
6006:
6007: @item int load_average
6008: scaled load average
6009:
6010: @item int mach_factor
6011: scaled mach factor
6012: @end table
6013: @end deftp
6014:
6015: @deftp {Data type} processor_set_basic_info_t
6016: This is a pointer to a @code{struct processor_set_basic_info}.
6017: @end deftp
6018:
6019: @deftp {Data type} {struct processor_set_sched_info}
6020: This structure is returned in @var{processor_set_info} by the
6021: @code{processor_set_info} function and provides schedule information
6022: about the processor set. You can cast a variable of type
6023: @code{processor_set_info_t} to a pointer of this type if you provided it
6024: as the @var{processor_set_info} parameter for the
6025: @code{PROCESSOR_SET_SCHED_INFO} flavor of @code{processor_set_info}. It
6026: has the following members:
6027:
6028: @table @code
6029: @item int policies
6030: allowed policies
6031:
6032: @item int max_priority
6033: max priority for new threads
6034: @end table
6035: @end deftp
6036:
6037: @deftp {Data type} processor_set_sched_info_t
6038: This is a pointer to a @code{struct processor_set_sched_info}.
6039: @end deftp
6040:
6041:
6042: @node Processor Interface
6043: @section Processor Interface
6044:
6045: @cindex processor port
6046: @cindex port representing a processor
6047: @deftp {Data type} processor_t
6048: This is a @code{mach_port_t} and used to hold the port name of a
6049: processor port that represents the processor. Operations on the
6050: processor are implemented as remote procedure calls to the processor
6051: port.
6052: @end deftp
6053:
6054: @menu
6055: * Hosted Processors:: Getting a list of all processors on a host.
6056: * Processor Control:: Starting, stopping, controlling processors.
6057: * Processors and Sets:: Combining processors into processor sets.
6058: * Processor Info:: Obtaining information on processors.
6059: @end menu
6060:
6061:
6062: @node Hosted Processors
6063: @subsection Hosted Processors
6064:
6065: @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}})
6066: The function @code{host_processors} gets send rights to the processor
6067: port for each processor existing on @var{host_priv}. This is the
6068: privileged port that allows its holder to control a processor.
6069:
6070: @var{processor_list} is an array that is created as a result of this
6071: call. The caller may wish to @code{vm_deallocate} this array when the
6072: data is no longer needed. @var{processor_count} is set to the number of
6073: processors in the @var{processor_list}.
6074:
6075: This function returns @code{KERN_SUCCESS} if the call succeeded,
6076: @code{KERN_INVALID_ARGUMENT} if @var{host_priv} is not a privileged host
6077: port, and @code{KERN_INVALID_ADDRESS} if @var{processor_count} points to
6078: inaccessible memory.
6079: @end deftypefun
6080:
6081:
6082: @node Processor Control
6083: @subsection Processor Control
6084:
6085: @deftypefun kern_return_t processor_start (@w{processor_t @var{processor}})
6086: @deftypefunx kern_return_t processor_exit (@w{processor_t @var{processor}})
6087: @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}})
6088: Some multiprocessors may allow privileged software to control
6089: processors. The @code{processor_start}, @code{processor_exit}, and
6090: @code{processor_control} operations implement this. The interpretation
6091: of the command in @var{cmd} is machine dependent. A newly started
6092: processor is assigned to the default processor set. An exited processor
6093: is removed from the processor set to which it was assigned and ceases to
6094: be active.
6095:
6096: @var{count} contains the length of the command @var{cmd} as a number of
6097: ints.
6098:
6099: Availability limited. All of these operations are machine-dependent.
6100: They may do nothing. The ability to restart an exited processor is also
6101: machine-dependent.
6102:
6103: This function returns @code{KERN_SUCCESS} if the operation was
6104: performed, @code{KERN_FAILURE} if the operation was not performed (a
6105: likely reason is that it is not supported on this processor),
6106: @code{KERN_INVALID_ARGUMENT} if @var{processor} is not a processor, and
6107: @code{KERN_INVALID_ADDRESS} if @var{cmd} points to inaccessible memory.
6108: @end deftypefun
6109:
6110: @node Processors and Sets
6111: @subsection Processors and Sets
6112:
6113: @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 6114: The function @code{processor_assign} assigns @var{processor} to the
1.1 root 6115: set @var{processor_set}. After the assignment is completed, the
6116: processor only executes threads that are assigned to that processor set.
6117: Any previous assignment of the processor is nullified. The master
6118: processor cannot be reassigned. All processors take clock interrupts at
6119: all times. The @var{wait} argument indicates whether the caller should
6120: wait for the assignment to be completed or should return immediately.
6121: Dedicated kernel threads are used to perform processor assignment, so
6122: setting wait to @code{FALSE} allows assignment requests to be queued and
6123: performed faster, especially if the kernel has more than one dedicated
6124: internal thread for processor assignment. Redirection of other device
6125: interrupts away from processors assigned to other than the default
6126: processor set is machine-dependent. Intermediaries that interpose on
6127: ports must be sure to interpose on both ports involved in this call if
6128: they interpose on either.
6129:
6130: This function returns @code{KERN_SUCCESS} if the assignment has been
6131: performed, @code{KERN_INVALID_ARGUMENT} if @var{processor} is not a
6132: processor, or @var{processor_set} is not a processor set on the same
6133: host as @var{processor}.
6134: @end deftypefun
6135:
6136: @deftypefun kern_return_t processor_get_assignment (@w{processor_t @var{processor}}, @w{processor_set_name_t *@var{assigned_set}})
6137: The function @code{processor_get_assignment} obtains the current
6138: assignment of a processor. The name port of the processor set is
6139: returned in @var{assigned_set}.
6140: @end deftypefun
6141:
6142: @node Processor Info
6143: @subsection Processor Info
6144:
6145: @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}})
6146: The function @code{processor_info} returns the selected information array
6147: for a processor, as specified by @var{flavor}.
6148:
6149: @var{host} is set to the host on which the processor set resides. This
6150: is the non-privileged host port.
6151:
6152: @var{processor_info} is an array of integers that is supplied by the
6153: caller and returned filled with specified information.
6154: @var{processor_info_count} is supplied as the maximum number of integers in
6155: @var{processor_info}. On return, it contains the actual number of
6156: integers in @var{processor_info}. The maximum number of integers
6157: returned by any flavor is @code{PROCESSOR_INFO_MAX}.
6158:
6159: The type of information returned is defined by @var{flavor}, which can
6160: be one of the following:
6161:
6162: @table @code
6163: @item PROCESSOR_BASIC_INFO
6164: The function returns basic information about the processor, as defined
6165: by @code{processor_basic_info_t}. This includes the slot number of the
6166: processor. The number of integers returned is
6167: @code{PROCESSOR_BASIC_INFO_COUNT}.
6168: @end table
6169:
6170: Machines which require more configuration information beyond the slot
6171: number are expected to define additional (machine-dependent) flavors.
6172:
6173: The function returns @code{KERN_SUCCESS} if the call succeeded and
6174: @code{KERN_INVALID_ARGUMENT} if @var{processor} is not a processor or
6175: @var{flavor} is not recognized. The function returns
6176: @code{MIG_ARRAY_TOO_LARGE} if the returned info array is too large for
6177: @var{processor_info}. In this case, @var{processor_info} is filled as
6178: much as possible and @var{processor_infoCnt} is set to the number of
6179: elements that would have been returned if there were enough room.
6180: @end deftypefun
6181:
6182: @deftp {Data type} {struct processor_basic_info}
6183: This structure is returned in @var{processor_info} by the
6184: @code{processor_info} function and provides basic information about the
6185: processor. You can cast a variable of type @code{processor_info_t} to a
6186: pointer of this type if you provided it as the @var{processor_info}
6187: parameter for the @code{PROCESSOR_BASIC_INFO} flavor of
6188: @code{processor_info}. It has the following members:
6189:
6190: @table @code
6191: @item cpu_type_t cpu_type
6192: cpu type
6193:
6194: @item cpu_subtype_t cpu_subtype
6195: cpu subtype
6196:
6197: @item boolean_t running
6198: is processor running?
6199:
6200: @item int slot_num
6201: slot number
6202:
6203: @item boolean_t is_master
6204: is this the master processor
6205: @end table
6206: @end deftp
6207:
6208: @deftp {Data type} processor_basic_info_t
6209: This is a pointer to a @code{struct processor_basic_info}.
6210: @end deftp
6211:
6212:
6213: @node Device Interface
6214: @chapter Device Interface
6215:
6216: The GNU Mach microkernel provides a simple device interface that allows
6217: the user space programs to access the underlying hardware devices. Each
6218: device has a unique name, which is a string up to 127 characters long.
6219: To open a device, the device master port has to be supplied. The device
6220: master port is only available through the bootstrap port. Anyone who
6221: has control over the device master port can use all hardware devices.
6222: @c XXX FIXME bootstrap port, bootstrap
6223:
6224: @cindex device port
6225: @cindex port representing a device
6226: @deftp {Data type} device_t
6227: This is a @code{mach_port_t} and used to hold the port name of a
6228: device port that represents the device. Operations on the device are
6229: implemented as remote procedure calls to the device port. Each device
6230: provides a sequence of records. The length of a record is specific to
6231: the device. Data can be transferred ``out-of-line'' or ``in-line''
6232: (@pxref{Memory}).
6233: @end deftp
6234:
6235: All constants and functions in this chapter are defined in
6236: @file{device/device.h}.
6237:
6238: @menu
6239: * Device Reply Server:: Handling device reply messages.
6240: * Device Open:: Opening hardware devices.
6241: * Device Close:: Closing hardware devices.
6242: * Device Read:: Reading data from the device.
6243: * Device Write:: Writing data to the device.
6244: * Device Map:: Mapping devices into virtual memory.
6245: * Device Status:: Querying and manipulating a device.
6246: * Device Filter:: Filtering packets arriving on a device.
6247: @end menu
6248:
6249:
6250: @node Device Reply Server
6251: @section Device Reply Server
6252:
6253: Beside the usual synchronous interface, an asynchronous interface is
6254: provided. For this, the caller has to receive and handle the reply
1.1.1.2 ! root 6255: messages separately from the function call.
1.1 root 6256:
6257: @deftypefun boolean_t device_reply_server (@w{msg_header_t *@var{in_msg}}, @w{msg_header_t *@var{out_msg}})
6258: The function @code{device_reply_server} is produced by the
6259: remote procedure call generator to handle a received message. This
6260: function does all necessary argument handling, and actually calls one of
6261: the following functions: @code{ds_device_open_reply},
6262: @code{ds_device_read_reply}, @code{ds_device_read_reply_inband},
6263: @code{ds_device_write_reply} and @code{ds_device_write_reply_inband}.
6264:
6265: The @var{in_msg} argument is the message that has been received from the
6266: kernel. The @var{out_msg} is a reply message, but this is not used for
6267: this server.
6268:
6269: The function returns @code{TRUE} to indicate that the message in
6270: question was applicable to this interface, and that the appropriate
6271: routine was called to interpret the message. It returns @code{FALSE} to
6272: indicate that the message did not apply to this interface, and that no
6273: other action was taken.
6274: @end deftypefun
6275:
6276:
6277: @node Device Open
6278: @section Device Open
6279:
6280: @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}})
6281: The function @code{device_open} opens the device @var{name} and returns
6282: a port to it in @var{device}. The open count for the device is
6283: incremented by one. If the open count was 0, the open handler for the
6284: device is invoked.
6285:
6286: @var{master_port} must hold the master device port. @var{name}
6287: specifies the device to open, and is a string up to 128 characters long.
6288: @var{mode} is the open mode. It is a bitwise-or of the following
6289: constants:
6290:
6291: @table @code
6292: @item D_READ
6293: Request read access for the device.
6294:
6295: @item D_WRITE
6296: Request write access for the device.
6297:
6298: @item D_NODELAY
6299: Do not delay an open.
6300: @c XXX Is this really used at all? Maybe for tape drives? What does it mean?
6301: @end table
6302:
6303: The function returns @code{D_SUCCESS} if the device was successfully
6304: opened, @code{D_INVALID_OPERATION} if @var{master_port} is not the
6305: master device port, @code{D_WOULD_BLOCK} is the device is busy and
6306: @code{D_NOWAIT} was specified in mode, @code{D_ALREADY_OPEN} if the
6307: device is already open in an incompatible mode and
6308: @code{D_NO_SUCH_DEVICE} if @var{name} does not denote a know device.
6309: @end deftypefun
6310:
6311: @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}})
6312: @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}})
6313: This is the asynchronous form of the @code{device_open} function.
6314: @code{device_open_request} performs the open request. The meaning for
6315: the parameters is as in @code{device_open}. Additionally, the caller
6316: has to supply a reply port to which the @code{ds_device_open_reply}
6317: message is sent by the kernel when the open has been performed. The
6318: return value of the open operation is stored in @var{return_code}.
6319:
6320: As neither function receives a reply message, only message transmission
6321: errors apply. If no error occurs, @code{KERN_SUCCESS} is returned.
6322: @end deftypefun
6323:
6324:
6325: @node Device Close
6326: @section Device Close
6327:
6328: @deftypefun kern_return_t device_close (@w{device_t @var{device}})
6329: The function @code{device_close} decrements the open count of the device
6330: by one. If the open count drops to zero, the close handler for the
6331: device is called. The device to close is specified by its port
6332: @var{device}.
6333:
6334: The function returns @code{D_SUCCESS} if the device was successfully
6335: closed and @code{D_NO_SUCH_DEVICE} if @var{device} does not denote a
6336: device port.
6337: @end deftypefun
6338:
6339:
6340: @node Device Read
6341: @section Device Read
6342:
6343: @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}})
6344: The function @code{device_read} reads @var{bytes_wanted} bytes from
6345: @var{device}, and stores them in a buffer allocated with
6346: @code{vm_allocate}, which address is returned in @var{data}. The caller
6347: must deallocated it if it is no longer needed. The number of bytes
6348: actually returned is stored in @var{data_count}.
6349:
6350: If @var{mode} is @code{D_NOWAIT}, the operation does not block.
6351: Otherwise @var{mode} should be 0. @var{recnum} is the record number to
6352: be read, its meaning is device specific.
6353:
6354: The function returns @code{D_SUCCESS} if some data was successfully
6355: read, @code{D_WOULD_BLOCK} if no data is currently available and
6356: @code{D_NOWAIT} is specified, and @code{D_NO_SUCH_DEVICE} if
6357: @var{device} does not denote a device port.
6358: @end deftypefun
6359:
6360: @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}})
6361: The @code{device_read_inband} function works as the @code{device_read}
6362: function, except that the data is returned ``in-line'' in the reply IPC
6363: message (@pxref{Memory}).
6364: @end deftypefun
6365:
6366: @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}})
6367: @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}})
6368: This is the asynchronous form of the @code{device_read} function.
6369: @code{device_read_request} performs the read request. The meaning for
6370: the parameters is as in @code{device_read}. Additionally, the caller
6371: has to supply a reply port to which the @code{ds_device_read_reply}
6372: message is sent by the kernel when the read has been performed. The
6373: return value of the read operation is stored in @var{return_code}.
6374:
6375: As neither function receives a reply message, only message transmission
6376: errors apply. If no error occurs, @code{KERN_SUCCESS} is returned.
6377: @end deftypefun
6378:
6379: @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}})
6380: @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}})
6381: The @code{device_read_request_inband} and
6382: @code{ds_device_read_reply_inband} functions work as the
6383: @code{device_read_request} and @code{ds_device_read_reply} functions,
6384: except that the data is returned ``in-line'' in the reply IPC message
6385: (@pxref{Memory}).
6386: @end deftypefun
6387:
6388:
6389: @node Device Write
6390: @section Device Write
6391:
6392: @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}})
6393: The function @code{device_write} writes @var{data_count} bytes from the
6394: buffer @var{data} to @var{device}. The number of bytes actually written
6395: is returned in @var{bytes_written}.
6396:
6397: If @var{mode} is @code{D_NOWAIT}, the function returns without waiting
6398: for I/O completion. Otherwise @var{mode} should be 0. @var{recnum} is
6399: the record number to be written, its meaning is device specific.
6400:
6401: The function returns @code{D_SUCCESS} if some data was successfully
6402: written and @code{D_NO_SUCH_DEVICE} if @var{device} does not denote a
6403: device port or the device is dead or not completely open.
6404: @end deftypefun
6405:
6406: @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}})
6407: The @code{device_write_inband} function works as the @code{device_write}
6408: function, except that the data is sent ``in-line'' in the request IPC
6409: message (@pxref{Memory}).
6410: @end deftypefun
6411:
6412: @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}})
6413: @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}})
6414: This is the asynchronous form of the @code{device_write} function.
6415: @code{device_write_request} performs the write request. The meaning for
6416: the parameters is as in @code{device_write}. Additionally, the caller
6417: has to supply a reply port to which the @code{ds_device_write_reply}
6418: message is sent by the kernel when the write has been performed. The
6419: return value of the write operation is stored in @var{return_code}.
6420:
6421: As neither function receives a reply message, only message transmission
6422: errors apply. If no error occurs, @code{KERN_SUCCESS} is returned.
6423: @end deftypefun
6424:
6425: @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}})
6426: @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}})
6427: The @code{device_write_request_inband} and
6428: @code{ds_device_write_reply_inband} functions work as the
6429: @code{device_write_request} and @code{ds_device_write_reply} functions,
6430: except that the data is sent ``in-line'' in the request IPC message
6431: (@pxref{Memory}).
6432: @end deftypefun
6433:
6434:
6435: @node Device Map
6436: @section Device Map
6437:
6438: @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}})
6439: The function @code{device_map} creates a new memory manager for
6440: @var{device} and returns a port to it in @var{pager}. The memory
6441: manager is usable as a memory object in a @code{vm_map} call. The call
1.1.1.2 ! root 6442: is device dependent.
1.1 root 6443:
6444: The protection for the memory object is specified by @var{prot}. The
6445: memory object starts at @var{offset} within the device and extends
6446: @var{size} bytes. @var{unmap} is currently unused.
6447: @c XXX I suppose the caller should set it to 0.
6448:
6449: The function returns @code{D_SUCCESS} if some data was successfully
6450: written and @code{D_NO_SUCH_DEVICE} if @var{device} does not denote a
6451: device port or the device is dead or not completely open.
6452: @end deftypefun
6453:
6454:
6455: @node Device Status
6456: @section Device Status
6457:
6458: @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}})
6459: The function @code{device_set_status} sets the status of a device. The
6460: possible values for @var{flavor} and their interpretation is device
6461: specific.
6462:
6463: The function returns @code{D_SUCCESS} if some data was successfully
6464: written and @code{D_NO_SUCH_DEVICE} if @var{device} does not denote a
6465: device port or the device is dead or not completely open.
6466: @end deftypefun
6467:
6468: @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}})
6469: The function @code{device_get_status} gets the status of a device. The
6470: possible values for @var{flavor} and their interpretation is device
6471: specific.
6472:
6473: The function returns @code{D_SUCCESS} if some data was successfully
6474: written and @code{D_NO_SUCH_DEVICE} if @var{device} does not denote a
6475: device port or the device is dead or not completely open.
6476: @end deftypefun
6477:
6478:
6479: @node Device Filter
6480: @section Device Filter
6481:
6482: @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}})
6483: The function @code{device_set_filter} makes it possible to filter out
1.1.1.2 ! root 6484: selected data arriving at or leaving the device and forward it to a port.
1.1 root 6485: @var{filter} is a list of filter commands, which are applied to incoming
6486: data to determine if the data should be sent to @var{receive_port}. The
6487: IPC type of the send right is specified by @var{receive_port_right}, it
6488: is either @code{MACH_MSG_TYPE_MAKE_SEND} or
6489: @code{MACH_MSG_TYPE_MOVE_SEND}. The @var{priority} value is used to
6490: order multiple filters.
6491:
6492: There can be up to @code{NET_MAX_FILTER} commands in @var{filter}. The
6493: actual number of commands is passed in @var{filter_count}. For the
6494: purpose of the filter test, an internal stack is provided. After all
6495: commands have been processed, the value on the top of the stack
6496: determines if the data is forwarded or the next filter is tried.
6497:
1.1.1.2 ! root 6498: The first command is a header which contains two fields: one for flags
! 6499: and the other for the type of interpreter used to run the rest of the
! 6500: commands.
! 6501:
! 6502: Any combination of the following flags is allowed but at least one of them
! 6503: must be specified.
! 6504:
! 6505: @table @code
! 6506: @item NETF_IN
! 6507: The filter will be applied to data received by the device.
! 6508:
! 6509: @item NETF_OUT
! 6510: The filter will be applied to data transmitted by the device.
! 6511: @end table
! 6512:
! 6513: Unless the type is given explicitly the native NETF interpreter will be used.
! 6514: To select an alternative implementation use one of the following types:
! 6515:
! 6516: @table @code
! 6517: @item NETF_BPF
! 6518: Use Berkeley Packet Filter.
! 6519: @end table
! 6520:
! 6521: For the listener to know what kind of packet is being received, when the
! 6522: filter code accepts a packet the message sent to @var{receive_port} is
! 6523: tagged with either NETF_IN or NETF_OUT.
! 6524:
1.1 root 6525: @c XXX The following description was taken verbatim from the
6526: @c kernel_interface.pdf document.
6527: Each word of the command list specifies a data (push) operation (high
6528: order NETF_NBPO bits) as well as a binary operator (low order NETF_NBPA
6529: bits). The value to be pushed onto the stack is chosen as follows.
6530:
6531: @table @code
6532: @item NETF_PUSHLIT
6533: Use the next short word of the filter as the value.
6534:
6535: @item NETF_PUSHZERO
6536: Use 0 as the value.
6537:
6538: @item NETF_PUSHWORD+N
6539: Use short word N of the ``data'' portion of the message as the value.
6540:
6541: @item NETF_PUSHHDR+N
6542: Use short word N of the ``header'' portion of the message as the value.
6543:
6544: @item NETF_PUSHIND+N
6545: Pops the top long word from the stack and then uses short word N of the
6546: ``data'' portion of the message as the value.
6547:
6548: @item NETF_PUSHHDRIND+N
6549: Pops the top long word from the stack and then uses short word N of the
6550: ``header'' portion of the message as the value.
6551:
6552: @item NETF_PUSHSTK+N
6553: Use long word N of the stack (where the top of stack is long word 0) as
6554: the value.
6555:
6556: @item NETF_NOPUSH
6557: Don't push a value.
6558: @end table
6559:
6560: The unsigned value so chosen is promoted to a long word before being
6561: pushed. Once a value is pushed (except for the case of
6562: @code{NETF_NOPUSH}), the top two long words of the stack are popped and
6563: a binary operator applied to them (with the old top of stack as the
6564: second operand). The result of the operator is pushed on the stack.
6565: These operators are:
6566:
6567: @table @code
6568: @item NETF_NOP
6569: Don't pop off any values and do no operation.
6570:
6571: @item NETF_EQ
6572: Perform an equal comparison.
6573:
6574: @item NETF_LT
6575: Perform a less than comparison.
6576:
6577: @item NETF_LE
6578: Perform a less than or equal comparison.
6579:
6580: @item NETF_GT
6581: Perform a greater than comparison.
6582:
6583: @item NETF_GE
6584: Perform a greater than or equal comparison.
6585:
6586: @item NETF_AND
6587: Perform a bitise boolean AND operation.
6588:
6589: @item NETF_OR
6590: Perform a bitise boolean inclusive OR operation.
6591:
6592: @item NETF_XOR
6593: Perform a bitise boolean exclusive OR operation.
6594:
6595: @item NETF_NEQ
6596: Perform a not equal comparison.
6597:
6598: @item NETF_LSH
6599: Perform a left shift operation.
6600:
6601: @item NETF_RSH
6602: Perform a right shift operation.
6603:
6604: @item NETF_ADD
6605: Perform an addition.
6606:
6607: @item NETF_SUB
6608: Perform a subtraction.
6609:
6610: @item NETF_COR
6611: Perform an equal comparison. If the comparison is @code{TRUE}, terminate
6612: the filter list. Otherwise, pop the result of the comparison off the
6613: stack.
6614:
6615: @item NETF_CAND
6616: Perform an equal comparison. If the comparison is @code{FALSE},
6617: terminate the filter list. Otherwise, pop the result of the comparison
6618: off the stack.
6619:
6620: @item NETF_CNOR
6621: Perform a not equal comparison. If the comparison is @code{FALSE},
6622: terminate the filter list. Otherwise, pop the result of the comparison
6623: off the stack.
6624:
6625: @item NETF_CNAND
6626: Perform a not equal comparison. If the comparison is @code{TRUE},
6627: terminate the filter list. Otherwise, pop the result of the comparison
6628: off the stack. The scan of the filter list terminates when the filter
6629: list is emptied, or a @code{NETF_C...} operation terminates the list. At
6630: this time, if the final value of the top of the stack is @code{TRUE},
6631: then the message is accepted for the filter.
6632: @end table
6633:
6634: The function returns @code{D_SUCCESS} if some data was successfully
6635: written, @code{D_INVALID_OPERATION} if @var{receive_port} is not a valid
6636: send right, and @code{D_NO_SUCH_DEVICE} if @var{device} does not denote
6637: a device port or the device is dead or not completely open.
6638: @end deftypefun
6639:
6640:
6641: @node Kernel Debugger
6642: @chapter Kernel Debugger
6643:
6644: The GNU Mach kernel debugger @code{ddb} is a powerful built-in debugger
6645: with a gdb like syntax. It is enabled at compile time using the
6646: @option{--enable-kdb} option. Whenever you want to enter the debugger
6647: while running the kernel, you can press the key combination
6648: @key{Ctrl-Alt-D}.
6649:
6650: @menu
6651: * Operation:: Basic architecture of the kernel debugger.
6652: * Commands:: Available commands in the kernel debugger.
6653: * Variables:: Access of variables from the kernel debugger.
6654: * Expressions:: Usage of expressions in the kernel debugger.
6655: @end menu
6656:
6657:
6658: @node Operation
6659: @section Operation
6660:
6661: The current location is called @dfn{dot}. The dot is displayed with a
6662: hexadecimal format at a prompt. Examine and write commands update dot
6663: to the address of the last line examined or the last location modified,
6664: and set @dfn{next} to the address of the next location to be examined or
6665: changed. Other commands don't change dot, and set next to be the same
6666: as dot.
6667:
6668: The general command syntax is:
6669:
6670: @example
6671: @var{command}[/@var{modifier}] @var{address} [,@var{count}]
6672: @end example
6673:
6674: @kbd{!!} repeats the previous command, and a blank line repeats from the
6675: address next with count 1 and no modifiers. Specifying @var{address} sets
6676: dot to the address. Omitting @var{address} uses dot. A missing @var{count}
6677: is taken to be 1 for printing commands or infinity for stack traces.
6678:
6679: Current @code{ddb} is enhanced to support multi-thread debugging. A
6680: break point can be set only for a specific thread, and the address space
6681: or registers of non current thread can be examined or modified if
6682: supported by machine dependent routines. For example,
6683:
6684: @example
6685: break/t mach_msg_trap $task11.0
6686: @end example
6687:
6688: sets a break point at @code{mach_msg_trap} for the first thread of task
6689: 11 listed by a @code{show all threads} command.
6690:
6691: In the above example, @code{$task11.0} is translated to the
6692: corresponding thread structure's address by variable translation
6693: mechanism described later. If a default target thread is set in a
6694: variable @code{$thread}, the @code{$task11.0} can be omitted. In
6695: general, if @code{t} is specified in a modifier of a command line, a
6696: specified thread or a default target thread is used as a target thread
6697: instead of the current one. The @code{t} modifier in a command line is
6698: not valid in evaluating expressions in a command line. If you want to
6699: get a value indirectly from a specific thread's address space or access
6700: to its registers within an expression, you have to specify a default
6701: target thread in advance, and to use @code{:t} modifier immediately
6702: after the indirect access or the register reference like as follows:
6703:
6704: @example
6705: set $thread $task11.0
6706: print $eax:t *(0x100):tuh
6707: @end example
6708:
6709: No sign extension and indirection @code{size(long, half word, byte)} can
6710: be specified with @code{u}, @code{l}, @code{h} and @code{b} respectively
6711: for the indirect access.
6712:
6713: Note: Support of non current space/register access and user space break
6714: point depend on the machines. If not supported, attempts of such
6715: operation may provide incorrect information or may cause strange
6716: behavior. Even if supported, the user space access is limited to the
6717: pages resident in the main memory at that time. If a target page is not
6718: in the main memory, an error will be reported.
6719:
6720: @code{ddb} has a feature like a command @code{more} for the output. If
6721: an output line exceeds the number set in the @code{$lines} variable, it
6722: displays @samp{--db_more--} and waits for a response. The valid
6723: responses for it are:
6724:
6725: @table @kbd
6726: @item @key{SPC}
6727: one more page
6728:
6729: @item @key{RET}
6730: one more line
6731:
6732: @item q
6733: abort the current command, and return to the command input mode
6734: @end table
6735:
6736:
6737: @node Commands
6738: @section Commands
6739:
6740: @table @code
6741: @item examine(x) [/@var{modifier}] @var{addr}[,@var{count}] [ @var{thread} ]
6742: Display the addressed locations according to the formats in the
6743: modifier. Multiple modifier formats display multiple locations. If no
6744: format is specified, the last formats specified for this command is
6745: used. Address space other than that of the current thread can be
6746: specified with @code{t} option in the modifier and @var{thread}
6747: parameter. The format characters are
6748:
6749: @table @code
6750: @item b
6751: look at by bytes(8 bits)
6752:
6753: @item h
6754: look at by half words(16 bits)
6755:
6756: @item l
6757: look at by long words(32 bits)
6758:
6759: @item a
6760: print the location being displayed
6761:
6762: @item ,
6763: skip one unit producing no output
6764:
6765: @item A
6766: print the location with a line number if possible
6767:
6768: @item x
6769: display in unsigned hex
6770:
6771: @item z
6772: display in signed hex
6773:
6774: @item o
6775: display in unsigned octal
6776:
6777: @item d
6778: display in signed decimal
6779:
6780: @item u
6781: display in unsigned decimal
6782:
6783: @item r
6784: display in current radix, signed
6785:
6786: @item c
6787: display low 8 bits as a character. Non-printing characters are
6788: displayed as an octal escape code (e.g. '\000').
6789:
6790: @item s
6791: display the null-terminated string at the location. Non-printing
6792: characters are displayed as octal escapes.
6793:
6794: @item m
6795: display in unsigned hex with character dump at the end of each line.
6796: The location is also displayed in hex at the beginning of each line.
6797:
6798: @item i
6799: display as an instruction
6800:
6801: @item I
6802: display as an instruction with possible alternate formats depending on
6803: the machine:
6804:
6805: @table @code
6806: @item vax
6807: don't assume that each external label is a procedure entry mask
6808:
6809: @item i386
6810: don't round to the next long word boundary
6811:
6812: @item mips
6813: print register contents
6814: @end table
6815: @end table
6816:
6817: @item xf
6818: Examine forward. It executes an examine command with the last specified
6819: parameters to it except that the next address displayed by it is used as
6820: the start address.
6821:
6822: @item xb
6823: Examine backward. It executes an examine command with the last
6824: specified parameters to it except that the last start address subtracted
6825: by the size displayed by it is used as the start address.
6826:
6827: @item print[/axzodurc] @var{addr1} [ @var{addr2} @dots{} ]
6828: Print @var{addr}'s according to the modifier character. Valid formats
6829: are: @code{a} @code{x} @code{z} @code{o} @code{d} @code{u} @code{r}
6830: @code{c}. If no modifier is specified, the last one specified to it is
6831: used. @var{addr} can be a string, and it is printed as it is. For
6832: example,
6833:
6834: @example
6835: print/x "eax = " $eax "\necx = " $ecx "\n"
6836: @end example
6837:
6838: will print like
6839:
6840: @example
6841: eax = xxxxxx
6842: ecx = yyyyyy
6843: @end example
6844:
6845: @item write[/bhlt] @var{addr} [ @var{thread} ] @var{expr1} [ @var{expr2} @dots{} ]
6846: Write the expressions at succeeding locations. The write unit size can
6847: be specified in the modifier with a letter b (byte), h (half word) or
6848: l(long word) respectively. If omitted, long word is assumed. Target
6849: address space can also be specified with @code{t} option in the modifier
6850: and @var{thread} parameter. Warning: since there is no delimiter
6851: between expressions, strange things may happen. It's best to enclose
6852: each expression in parentheses.
6853:
6854: @item set $@var{variable} [=] @var{expr}
6855: Set the named variable or register with the value of @var{expr}. Valid
6856: variable names are described below.
6857:
6858: @item break[/tuTU] @var{addr}[,@var{count}] [ @var{thread1} @dots{} ]
6859: Set a break point at @var{addr}. If count is supplied, continues
6860: (@var{count}-1) times before stopping at the break point. If the break
6861: point is set, a break point number is printed with @samp{#}. This
6862: number can be used in deleting the break point or adding conditions to
6863: it.
6864:
6865: @table @code
6866: @item t
6867: Set a break point only for a specific thread. The thread is specified
6868: by @var{thread} parameter, or default one is used if the parameter is
6869: omitted.
6870:
6871: @item u
6872: Set a break point in user space address. It may be combined with
6873: @code{t} or @code{T} option to specify the non-current target user
6874: space. Without @code{u} option, the address is considered in the kernel
6875: space, and wrong space address is rejected with an error message. This
6876: option can be used only if it is supported by machine dependent
6877: routines.
6878:
6879: @item T
6880: Set a break point only for threads in a specific task. It is like
6881: @code{t} option except that the break point is valid for all threads
6882: which belong to the same task as the specified target thread.
6883:
6884: @item U
6885: Set a break point in shared user space address. It is like @code{u}
6886: option, except that the break point is valid for all threads which share
6887: the same address space even if @code{t} option is specified. @code{t}
6888: option is used only to specify the target shared space. Without
6889: @code{t} option, @code{u} and @code{U} have the same meanings. @code{U}
6890: is useful for setting a user space break point in non-current address
6891: space with @code{t} option such as in an emulation library space. This
6892: option can be used only if it is supported by machine dependent
6893: routines.
6894: @end table
6895:
6896: Warning: if a user text is shadowed by a normal user space debugger,
6897: user space break points may not work correctly. Setting a break point
6898: at the low-level code paths may also cause strange behavior.
6899:
6900: @item delete[/tuTU] @var{addr}|#@var{number} [ @var{thread1} @dots{} ]
6901: Delete the break point. The target break point can be specified by a
6902: break point number with @code{#}, or by @var{addr} like specified in
6903: @code{break} command.
6904:
6905: @item cond #@var{number} [ @var{condition} @var{commands} ]
6906: Set or delete a condition for the break point specified by the
6907: @var{number}. If the @var{condition} and @var{commands} are null, the
6908: condition is deleted. Otherwise the condition is set for it. When the
6909: break point is hit, the @var{condition} is evaluated. The
6910: @var{commands} will be executed if the condition is true and the break
6911: point count set by a break point command becomes zero. @var{commands}
6912: is a list of commands separated by semicolons. Each command in the list
6913: is executed in that order, but if a @code{continue} command is executed,
6914: the command execution stops there, and the stopped thread resumes
6915: execution. If the command execution reaches the end of the list, and it
6916: enters into a command input mode. For example,
6917:
6918: @example
6919: set $work0 0
6920: break/Tu xxx_start $task7.0
6921: cond #1 (1) set $work0 1; set $work1 0; cont
6922: break/T vm_fault $task7.0
6923: cond #2 ($work0) set $work1 ($work1+1); cont
6924: break/Tu xxx_end $task7.0
6925: cond #3 ($work0) print $work1 " faults\n"; set $work0 0
6926: cont
6927: @end example
6928:
6929: will print page fault counts from @code{xxx_start} to @code{xxx_end} in
6930: @code{task7}.
6931:
6932: @item step[/p] [,@var{count}]
6933: Single step @var{count} times. If @code{p} option is specified, print
6934: each instruction at each step. Otherwise, only print the last
6935: instruction.
6936:
6937: Warning: depending on machine type, it may not be possible to
6938: single-step through some low-level code paths or user space code. On
6939: machines with software-emulated single-stepping (e.g., pmax), stepping
6940: through code executed by interrupt handlers will probably do the wrong
6941: thing.
6942:
6943: @item continue[/c]
6944: Continue execution until a breakpoint or watchpoint. If @code{/c},
6945: count instructions while executing. Some machines (e.g., pmax) also
6946: count loads and stores.
6947:
6948: Warning: when counting, the debugger is really silently single-stepping.
6949: This means that single-stepping on low-level code may cause strange
6950: behavior.
6951:
6952: @item until
6953: Stop at the next call or return instruction.
6954:
6955: @item next[/p]
6956: Stop at the matching return instruction. If @code{p} option is
6957: specified, print the call nesting depth and the cumulative instruction
6958: count at each call or return. Otherwise, only print when the matching
6959: return is hit.
6960:
6961: @item match[/p]
6962: A synonym for @code{next}.
6963:
6964: @item trace[/tu] [ @var{frame_addr}|@var{thread} ][,@var{count}]
6965: Stack trace. @code{u} option traces user space; if omitted, only traces
6966: kernel space. If @code{t} option is specified, it shows the stack trace
6967: of the specified thread or a default target thread. Otherwise, it shows
6968: the stack trace of the current thread from the frame address specified
6969: by a parameter or from the current frame. @var{count} is the number of
6970: frames to be traced. If the @var{count} is omitted, all frames are
6971: printed.
6972:
6973: Warning: If the target thread's stack is not in the main memory at that
6974: time, the stack trace will fail. User space stack trace is valid only
6975: if the machine dependent code supports it.
6976:
6977: @item search[/bhl] @var{addr} @var{value} [@var{mask}] [,@var{count}]
6978: Search memory for a value. This command might fail in interesting ways
6979: if it doesn't find the searched-for value. This is because @code{ddb}
6980: doesn't always recover from touching bad memory. The optional count
6981: argument limits the search.
6982:
6983: @item macro @var{name} @var{commands}
6984: Define a debugger macro as @var{name}. @var{commands} is a list of
6985: commands to be associated with the macro. In the expressions of the
6986: command list, a variable @code{$argxx} can be used to get a parameter
6987: passed to the macro. When a macro is called, each argument is evaluated
6988: as an expression, and the value is assigned to each parameter,
6989: @code{$arg1}, @code{$arg2}, @dots{} respectively. 10 @code{$arg}
6990: variables are reserved to each level of macros, and they can be used as
6991: local variables. The nesting of macro can be allowed up to 5 levels.
6992: For example,
6993:
6994: @example
6995: macro xinit set $work0 $arg1
6996: macro xlist examine/m $work0,4; set $work0 *($work0)
6997: xinit *(xxx_list)
6998: xlist
6999: @enddots{}
7000: @end example
7001:
7002: will print the contents of a list starting from @code{xxx_list} by each
7003: @code{xlist} command.
7004:
7005: @item dmacro @var{name}
7006: Delete the macro named @var{name}.
7007:
7008: @item show all threads[/ul]
7009: Display all tasks and threads information. This version of @code{ddb}
7010: prints more information than previous one. It shows UNIX process
7011: information like @command{ps} for each task. The UNIX process
7012: information may not be shown if it is not supported in the machine, or
7013: the bottom of the stack of the target task is not in the main memory at
7014: that time. It also shows task and thread identification numbers. These
7015: numbers can be used to specify a task or a thread symbolically in
7016: various commands. The numbers are valid only in the same debugger
7017: session. If the execution is resumed again, the numbers may change.
7018: The current thread can be distinguished from others by a @code{#} after
7019: the thread id instead of @code{:}. Without @code{l} option, it only
7020: shows thread id, thread structure address and the status for each
1.1.1.2 ! root 7021: thread. The status consists of 5 letters, R(run), W(wait), S(suspended),
! 7022: O(swapped out) and N(interruptible), and if corresponding
1.1 root 7023: status bit is off, @code{.} is printed instead. If @code{l} option is
7024: specified, more detail information is printed for each thread.
7025:
7026: @item show task [ @var{addr} ]
7027: Display the information of a task specified by @var{addr}. If
7028: @var{addr} is omitted, current task information is displayed.
7029:
7030: @item show thread [ @var{addr} ]
7031: Display the information of a thread specified by @var{addr}. If
7032: @var{addr} is omitted, current thread information is displayed.
7033:
7034: @item show registers[/tu [ @var{thread} ]]
7035: Display the register set. Target thread can be specified with @code{t}
7036: option and @var{thread} parameter. If @code{u} option is specified, it
7037: displays user registers instead of kernel or currently saved one.
7038:
7039: Warning: The support of @code{t} and @code{u} option depends on the
7040: machine. If not supported, incorrect information will be displayed.
7041:
7042: @item show map @var{addr}
7043: Prints the @code{vm_map} at @var{addr}.
7044:
7045: @item show object @var{addr}
7046: Prints the @code{vm_object} at @var{addr}.
7047:
7048: @item show page @var{addr}
7049: Prints the @code{vm_page} structure at @var{addr}.
7050:
7051: @item show port @var{addr}
7052: Prints the @code{ipc_port} structure at @var{addr}.
7053:
7054: @item show ipc_port[/t [ @var{thread} ]]
7055: Prints all @code{ipc_port} structure's addresses the target thread has.
7056: The target thread is a current thread or that specified by a parameter.
7057:
7058: @item show macro [ @var{name} ]
7059: Show the definitions of macros. If @var{name} is specified, only the
7060: definition of it is displayed. Otherwise, definitions of all macros are
7061: displayed.
7062:
7063: @item show watches
7064: Displays all watchpoints.
7065:
7066: @item watch[/T] @var{addr},@var{size} [ @var{task} ]
7067: Set a watchpoint for a region. Execution stops when an attempt to
7068: modify the region occurs. The @var{size} argument defaults to 4.
7069: Without @code{T} option, @var{addr} is assumed to be a kernel address.
7070: If you want to set a watch point in user space, specify @code{T} and
7071: @var{task} parameter where the address belongs to. If the @var{task}
7072: parameter is omitted, a task of the default target thread or a current
7073: task is assumed. If you specify a wrong space address, the request is
7074: rejected with an error message.
7075:
7076: Warning: Attempts to watch wired kernel memory may cause unrecoverable
7077: error in some systems such as i386. Watchpoints on user addresses work
7078: best.
1.1.1.2 ! root 7079:
! 7080: @item dwatch[/T] @var{addr} [ @var{task} ]
! 7081: Clears a watchpoint previously set for a region.
! 7082: Without @code{T} option, @var{addr} is assumed to be a kernel address.
! 7083: If you want to clear a watch point in user space, specify @code{T} and
! 7084: @var{task} parameter where the address belongs to. If the @var{task}
! 7085: parameter is omitted, a task of the default target thread or a current
! 7086: task is assumed. If you specify a wrong space address, the request is
! 7087: rejected with an error message.
1.1 root 7088: @end table
7089:
7090:
7091: @node Variables
7092: @section Variables
7093:
7094: The debugger accesses registers and variables as $@var{name}. Register
7095: names are as in the @code{show registers} command. Some variables are
7096: suffixed with numbers, and may have some modifier following a colon
7097: immediately after the variable name. For example, register variables
7098: can have @code{u} and @code{t} modifier to indicate user register and
7099: that of a default target thread instead of that of the current thread
7100: (e.g. @code{$eax:tu}).
7101:
7102: Built-in variables currently supported are:
7103:
7104: @table @code
7105: @item task@var{xx}[.@var{yy}]
7106: Task or thread structure address. @var{xx} and @var{yy} are task and
7107: thread identification numbers printed by a @code{show all threads}
7108: command respectively. This variable is read only.
7109:
7110: @item thread
7111: The default target thread. The value is used when @code{t} option is
7112: specified without explicit thread structure address parameter in command
7113: lines or expression evaluation.
7114:
7115: @item radix
7116: Input and output radix
7117:
7118: @item maxoff
7119: Addresses are printed as @var{symbol}+@var{offset} unless offset is greater than
7120: maxoff.
7121:
7122: @item maxwidth
7123: The width of the displayed line.
7124:
7125: @item lines
7126: The number of lines. It is used by @code{more} feature.
7127:
7128: @item tabstops
7129: Tab stop width.
7130:
7131: @item arg@var{xx}
7132: Parameters passed to a macro. @var{xx} can be 1 to 10.
7133:
7134: @item work@var{xx}
7135: Work variable. @var{xx} can be 0 to 31.
7136: @end table
7137:
7138:
7139: @node Expressions
7140: @section Expressions
7141:
7142: Almost all expression operators in C are supported except @code{~},
7143: @code{^}, and unary @code{&}. Special rules in @code{ddb} are:
7144:
7145: @table @code
7146: @item @var{identifier}
7147: name of a symbol. It is translated to the address(or value) of it.
7148: @code{.} and @code{:} can be used in the identifier. If supported by
7149: an object format dependent routine,
7150: [@var{file_name}:]@var{func}[:@var{line_number}]
7151: [@var{file_name}:]@var{variable}, and
7152: @var{file_name}[:@var{line_number}] can be accepted as a symbol. The
7153: symbol may be prefixed with @code{@var{symbol_table_name}::} like
7154: @code{emulator::mach_msg_trap} to specify other than kernel symbols.
7155:
7156: @item @var{number}
7157: radix is determined by the first two letters:
7158: @table @code
7159: @item 0x
7160: hex
7161: @item 0o
7162: octal
7163: @item 0t
7164: decimal
7165: @end table
7166:
7167: otherwise, follow current radix.
7168:
7169: @item .
7170: dot
7171:
7172: @item +
7173: next
7174:
7175: @item ..
7176: address of the start of the last line examined. Unlike dot or next,
7177: this is only changed by @code{examine} or @code{write} command.
7178:
7179: @item �
7180: last address explicitly specified.
7181:
7182: @item $@var{variable}
7183: register name or variable. It is translated to the value of it. It may
7184: be followed by a @code{:} and modifiers as described above.
7185:
7186: @item a
7187: multiple of right hand side.
7188:
7189: @item *@var{expr}
7190: indirection. It may be followed by a @code{:} and modifiers as
7191: described above.
7192: @end table
7193:
7194: @include gpl.texi
7195:
7196: @node Documentation License
7197: @appendix Documentation License
7198:
7199: This manual is copyrighted and licensed under the GNU Free Documentation
7200: license.
7201:
7202: Parts of this manual are derived from the Mach manual packages
7203: originally provided by Carnegie Mellon University.
7204:
7205: @menu
1.1.1.2 ! root 7206: * GNU Free Documentation License:: The GNU Free Documentation License.
1.1 root 7207: * CMU License:: The CMU license applies to the original Mach
7208: kernel and its documentation.
7209: @end menu
7210:
7211: @include fdl.texi
7212:
7213: @node CMU License
7214: @appendixsec CMU License
7215:
7216: @quotation
7217: @display
7218: Mach Operating System
7219: Copyright @copyright{} 1991,1990,1989 Carnegie Mellon University
7220: All Rights Reserved.
7221: @end display
7222:
7223: Permission to use, copy, modify and distribute this software and its
7224: documentation is hereby granted, provided that both the copyright
7225: notice and this permission notice appear in all copies of the
7226: software, derivative works or modified versions, and any portions
7227: thereof, and that both notices appear in supporting documentation.
7228:
7229: @sc{carnegie mellon allows free use of this software in its ``as is''
7230: condition. carnegie mellon disclaims any liability of any kind for
7231: any damages whatsoever resulting from the use of this software.}
7232:
7233: Carnegie Mellon requests users of this software to return to
7234:
7235: @display
7236: Software Distribution Coordinator
7237: School of Computer Science
7238: Carnegie Mellon University
7239: Pittsburgh PA 15213-3890
7240: @end display
7241:
7242: @noindent
7243: or @email{Software.Distribution@@CS.CMU.EDU} any improvements or
7244: extensions that they make and grant Carnegie Mellon the rights to
7245: redistribute these changes.
7246: @end quotation
7247:
7248: @node Concept Index
7249: @unnumbered Concept Index
7250:
7251: @printindex cp
7252:
7253:
7254: @node Function and Data Index
7255: @unnumbered Function and Data Index
7256:
7257: @printindex fn
7258:
7259:
7260: @summarycontents
7261: @contents
7262: @bye
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.