3 The Macintosh Operating System Interface

Access to the various system APIs of MacOS X is provided by p1 Modula-2 via a large set of foreign definition files. MacOS X distinguishes three groups of APIs:
  1. The core framework interface which may be used from Cocoa applications as well as from Carbon applications; the following parts are supported by p1 Modula-2 V9.3:
  2. The Cocoa interface: this is not yet directly supported by p1 Modula-2 V9.3.
  3. The Carbon interface: the following parts are supported by p1 Modula-2 V9.3:
  4. The Unix interface: only those system calls are defined which are used by the library of p1 Modula-2 V9.x.

The definition files for the core interface correspond in names and structure exactly with the C headers defined in the according frameworks. The core foundation interface, core graphics interface, and the the core text interface represent exactly the headers defined in MacOS X 10.10.

The definition files for the Carbon interface correspond in names and structure exactly with the "universal interface files" for Pascal and C / C++. The actual version where the p1 Modula-2 definition files are derived from is version 3.4.2. The description of the procedures can be taken directly from "Inside Macintosh" or the Carbon documentation supplied with the developer tools (ADC Reference Library). The HI toolbox definitions and the other additional definitions are derived from the corresponding C/C++ header files extracted from the Carbon framework and other frameworks. So they are covered by the "Carbon api reference".

The definition files for the Unix interface are grouped due to their use. As the procedure names have to be exactly those of the Unix header files, you can use the man pages for detailed descriptions. For each definition module of the Unix interface, the corresponding Unix header files are given.

The connection to the variuos interfaces is implemented as direct calls to the corresponding functions of the coreesponding frameworks resp. the runtime libraries. Therefore, no overhead is introduced by glue routines. For the same reason, no implementation modules are belonging to the definition modules—no objects have to be specified at link time. Please refer to the examples in the compiler manual (cf. compiler manual section 1.7) to see which libraries have to be specified in the link command for the different targets.

The symbol files for the core interface, the Carbon interface, and for the Unix interface are grouped together with those of the library in the folder "M2SYMS".

3.1 The Core Interface

The core interface consists of several frameworks that provide many basic functionality of MacOS X. The core interfaces may be used in Cocoa applications as well as in Carbon applications.

3.1.1 Core Foundation Files

These files give access to the core foundation objects of MaxOS X. All files correspond to the actual headers of MaxOS X 10.10.

The following files belong to this part of the Core interface:
CFArray.DEFCFAttributedString.DEFCFBag.DEFCFBase.DEF
CFBinaryHeap.DEFCFBitVector.DEFCFBundle.DEFCFCalendar.DEF
CFCharacterSet.DEFCFData.DEFCFDate.DEFCFDateFormatter.DEF
CFDictionary.DEFCFError.DEFCFFileDescriptor.DEFCFFileSecurity.DEF
CFLocale.DEFCFLocaleConsts.DEFCFMachPort.DEFCFMessagePort.DEF
CFNotificationCenter.DEFCFNumber.DEFCFPlugIn.DEFCFPlugInCOM.DEF
CFPreferences.DEFCFPropertyList.DEFCFRunLoop.DEFCFSet.DEF
CFSocket.DEFCFStream.DEFCFString.DEFCFStringEncodingExt.DEF
CFStringTokenizer.DEFCFTimeZone.DEFCFTree.DEFCFURL.DEF
CFURLAccess.DEFCFURLEnumerator.DEFCFUUID.DEFCFUserNotification.DEF
CFUtilities.DEFCFXMLNode.DEFCFXMLParser.DEF 

3.1.2 Core Graphics Files

These files give access to the graphics kernel of MaxOS X. All files correspond to the actual headers of MaxOS X 10.10.

The following files belong to this part of the Core interface:
CGAffineTransform.defCGBase.defCGBitmapContext.defCGColor.def
CGColorSpace.defCGContext.defCGDataConsumer.defCGDataProvider.def
CGDirectDisplay.defCGDirectPalette.defCGDisplayConfiguration.defCGDisplayFade.def
CGDisplayStream.defCGError.defCGEvent.defCGEventSource.def
CGEventTypes.defCGFont.defCGFunction.defCGGLContext.def
CGGeometry.defCGGradient.defCGImage.defCGLayer.def
CGPDFArray.defCGPDFContentStream.defCGPDFContext.defCGPDFDictionary.def
CGPDFDocument.defCGPDFObject.defCGPDFOperatorTable.defCGPDFPage.def
CGPDFScanner.defCGPDFStream.defCGPDFString.defCGPSConverter.def
CGPath.defCGPattern.defCGRemoteOperation.defCGSession.def
CGShading.defCGWindow.defCGWindowLevel.def 

3.1.3 Core Text Files

These files give access to the text rendering kernel of MaxOS X. All files correspond to the actual headers of MaxOS X 10.10.

The following files belong to this part of the Core interface:
CTFont.DEFCTFontCollection.DEFCTFontDescriptor.DEFCTFontManager.DEF
CTFontManagerErrors.DEFCTFontTraits.DEFCTFrame.DEFCTFramesetter.DEF
CTGlyphInfo.DEFCTLine.DEFCTParagraphStyle.DEFCTRubyAnnotation.DEF
CTRun.DEFCTRunDelegate.DEFCTStringAttributes.DEFCTTextTab.DEF
CTTypesetter.DEF   

3.2 The Cocoa Interface

Direct access to the Cocoa classes is not yet implemented by p1 Modula-2.

3.3 The Carbon Interface

The Carbon interface consists of all system APIs provided for by the Carbon framework that are not part of the Core APIs (which are accessible through the Carbon framework). They are accessed using a procedural view (as opposed to the object oriented view defined by the Cocoa APIs). As the Carbon framework does not support Intel 64 bit code, these symbol files are contained only in PPC and Intel 32 bit versions.

3.3.1 The Universal Definitions Files

This part of the Macintosh system APIs is in most parts backward compatible to Mac OS 9 via Carbon lib. Most of the definition files for the Carbon files are derived automatically from the Pascal interface files of the "universal interface files" version 3.4.2 and are identical with those files with respect to names as well as in semantics.

Only the module "MacTypes" is slightly different. A number of p1 Modula-2 specific universal data types (e.g. "CARD8", "CARD16", "CARD32", ...) are defined additionally in "MacTypes". Most of these types are originally defined in module "SYSTEM" since version 5.0, but (re-)exported from "MacTypes" for compatibility to older versions.

The definition files are all in the folder "M2UniversalDefs" of "$M2HOME".

The following files belong to this part of the Carbon interface:
ADSP.DEFAEDataModel.DEFAEHelpers.DEFAEInteraction.DEF
AEMach.DEFAEObjects.DEFAEPackObject.DEFAERegistry.DEF
AEUserTermTypes.DEFAIFF.DEFAliases.DEFAppearance.DEF
AppleDiskPartitions.DEFAppleEvents.DEFAppleGuide.DEFAppleHelp.DEF
AppleScript.DEFAppleTalk.DEFApplicationServices.DEFASDebugging.DEF
ASRegistry.DEFATA.DEFATSFont.DEFATSLayoutTypes.DEF
ATSTypes.DEFATSUnicode.DEFAVComponents.DEFAVLTree.DEF
Balloons.DEFCarbon.DEFCarbonEvents.DEFCardServices.DEF
CMAcceleration.DEFCMApplication.DEFCMCalibrator.DEFCMComponent.DEF
CMConversions.DEFCMDeviceIntegration.DEFCMICCProfile.DEFCMMComponent.DEF
CMPRComponent.DEFCMScriptingPlugin.DEFCMTypes.DEFCodeFragments.DEF
Collections.DEFColorPicker.DEFColorPickerComponents.DEFCommResources.DEF
Components.DEFConnections.DEFConnectionTools.DEFControlDefinitions.DEF
Controls.DEFControlStrip.DEFCoreServices.DEFCRMSerialDevices.DEF
CryptoMessageSyntax.DEFCTBUtilities.DEFCursorCtl.DEFCursorDevices.DEF
DatabaseAccess.DEFDateTimeUtils.DEFDebugging.DEFDeskBus.DEF
DesktopPrinting.DEFDeviceControl.DEFDevices.DEFDialogs.DEF
Dictionary.DEFDisAsmLookup.DEFDisassembler.DEFDiskInit.DEF
Disks.DEFDisplays.DEFDrag.DEFDrawSprocket.DEF
DriverFamilyMatching.DEFDriverGestalt.DEFDriverServices.DEFDriverSupport.DEF
DriverSynchronization.DEFEditions.DEFEndian.DEFENET.DEF
EPPC.DEFErrMgr.DEFErrors.DEFEvents.DEF
fenv.DEFFileMapping.DEFFiles.DEFFileSigning.DEF
FileTransfers.DEFFileTransferTools.DEFFileTypesAndCreators.DEFFindByContent.DEF
Finder.DEFFinderRegistry.DEFFixMath.DEFFolders.DEF
Fonts.DEFFontSync.DEFfp.DEFFSM.DEF
GestaltEqu.DEFGXEnvironment.DEFGXErrors.DEFGXFonts.DEF
GXGraphics.DEFGXLayout.DEFGXMath.DEFGXTypes.DEF
HFSVolumes.DEFHID.DEFHTMLRendering.DEFHyperXCmd.DEF
IAExtractor.DEFIBCarbonRuntime.DEFICAApplication.DEFICACamera.DEF
ICADevice.DEFIcons.DEFImageCodec.DEFImageCompression.DEF
InputSprocket.DEFIntEnv.DEFInternetConfig.DEFInterrupts.DEF
IntlResources.DEFIsochronousDataHandler.DEFJManager.DEFKernel.DEF
Keyboards.DEFKeychain.DEFKeychainCore.DEFKeychainHI.DEF
LanguageAnalysis.DEFLaunchServices.DEFLists.DEFLocationManager.DEF
LowMem.DEFMacApplication.DEFMacErrors.DEFMacHelp.DEF
MachineExceptions.DEFMacLocales.DEFMacMemory.DEFMacRuntime.DEF
MacTCP.DEFMacTextEditor.DEFMacTypes.DEFMacWindows.DEF
Math64.DEFMC68000Test.DEFMediaHandlers.DEFMemory.DEF
Menus.DEFMIDI.DEFMixedMode.DEFMovies.DEF
MoviesFormat.DEFMultiprocessing.DEFMultiprocessingInfo.DEFNameRegistry.DEF
Navigation.DEFNetSprocket.DEFNetworkSetup.DEFNotification.DEF
NSL.DEFNSLCore.DEFNumberFormatting.DEFOpenTptAppleTalk.DEF
OpenTptClient.DEFOpenTptCommon.DEFOpenTptConfig.DEFOpenTptDevLinks.DEF
OpenTptGlobalNew.DEFOpenTptInternet.DEFOpenTptISDN.DEFOpenTptLinks.DEF
OpenTptModule.DEFOpenTptPCISupport.DEFOpenTptSerial.DEFOpenTptXTI.DEF
OpenTransport.DEFOpenTransportKernel.DEFOpenTransportProtocol.DEFOpenTransportProviders.DEF
OpenTransportUNIX.DEFOSA.DEFOSAComp.DEFOSAGeneric.DEF
OSUtils.DEFPackages.DEFPalettes.DEFPasLibIntf.DEF
Patches.DEFPCCard.DEFPCCardAdapterPlugin.DEFPCCardEnablerPlugin.DEF
PCCardTuples.DEFPCI.DEFPEFBinaryFormat.DEFPictUtils.DEF
PLStringFuncs.DEFPMApplication.DEFPMCore.DEFPMDefinitions.DEF
Power.DEFPPCToolbox.DEFPrinting.DEFProcessesCarbon.DEF
QD3D.DEFQD3DAcceleration.DEFQD3DCamera.DEFQD3DController.DEF
QD3DCustomElements.DEFQD3DDrawContext.DEFQD3DErrors.DEFQD3DExtension.DEF
QD3DGeometry.DEFQD3DGroup.DEFQD3DIO.DEFQD3DLight.DEF
QD3DMath.DEFQD3DPick.DEFQD3DRenderer.DEFQD3DSet.DEF
QD3DShader.DEFQD3DStorage.DEFQD3DString.DEFQD3DStyle.DEF
QD3DTransform.DEFQD3DView.DEFQD3DViewer.DEFQD3DWinViewer.DEF
QDOffscreen.DEFQTML.DEFQTSMovie.DEFQTStreamingComponents.DEF
Quickdraw.DEFQuickdrawText.DEFQuickTime.DEFQuickTimeComponents.DEF
QuickTimeMusic.DEFQuickTimeStreaming.DEFQuickTimeVR.DEFQuickTimeVRFormat.DEF
RAVE.DEFRAVESystem.DEFResources.DEFRetrace.DEF
ROMDefs.DEFScalerStreamTypes.DEFScalerTypes.DEFScrap.DEF
Script.DEFSCSI.DEFSegLoad.DEFSerial.DEF
SFNTLayoutTypesC.DEFSFNTTypesC.DEFShutDown.DEFSlots.DEF
SocketServices.DEFSound.DEFSoundComponents.DEFSoundInput.DEF
SoundSprocket.DEFSpeech.DEFSpeechRecognition.DEFSpeechSynthesis.DEF
StandardFile.DEFStart.DEFStringCompare.DEFTargetConditionals.DEF
Telephones.DEFTerminals.DEFTerminalTools.DEFTextCommon.DEF
TextEdit.DEFTextEncodingConverter.DEFTextEncodingPlugin.DEFTextServices.DEF
TextUtils.DEFThreads.DEFTimer.DEFToolUtils.DEF
Translation.DEFTranslationExtensions.DEFTraps.DEFTSMTE.DEF
Types.DEFTypeSelect.DEFUnicode.DEFUnicodeConverter.DEF
UnicodeUtilities.DEFUnmangler.DEFURLAccess.DEFUSB.DEF
UTCUtils.DEFvBasicOps.DEFvBigNum.DEFvBLAS.DEF
vDSP.DEFvectorOps.DEFvfp.DEFVideo.DEF
VideoServices.DEFWindows.DEFWorldScript.DEFZoomedVideo.DEF

3.3.2 The HIToolbox API

This part of the Macintosh system APIs was newly introduced in MacOS X. It offers new functionality in designing programs that is not available under Classic. The definition files for these APIs are converted from the corresponding C header files and are identical with those files with respect to names as well as in semantics.

The definition files are all in the folder "M2UniversalDefs" of "$M2HOME".

The following files belong to this part of the Carbon interface:
HIArchive.DEFHIGeometry.DEFHIObject.DEFHIShape.DEF
HITextUtils.DEFHITheme.DEFHIToolbar.DEFHIView.DEF

3.3.3 Other APIs

As the HIToolbox APIs these APIs are also newly introduced in MacOS X. They offer new functionality in designing programs which is not available under Classic. The definition files for these APIs are converted from the corresponding C header files and are identical with those files with respect to names as well as in semantics.

The definition files are all in the folder "M2UniversalDefs" of "$M2HOME".

The following files belong to this part of the Carbon interface:

3.4 The Unix Interface

Only those procedures and data types available in the Unix interface are defined that are used by the implementation of the standard library. Though there should be no need to access these procedures directly, they give a good example of how to define interface modules of ones own.

For the semantics of the defined procedures and data types you can consult the corresponding man pages; if "man procedurename" does return the meaning of a command with the same name, you should try "man 2 procedurename" or "man 3 procedurename".

3.4.1 Unix

<* ASSIGN (Foreign, TRUE) *>
DEFINITION MODULE Unix;
    
FROM SYSTEM IMPORT CARD8, CARD16, SET16, INT32, CARD32, SET32, INT64, STR255, ADDRESS, TSIZE, CAST;

TYPE
Ptr = ADDRESS;

CONST
    (*error codes*)
    EPERM = 1;		(*Operation not permitted*)
    ENOENT = 2;		(*No such file or directory*)
    ESRCH = 3;		(*No such process*)
    EINTR = 4;		(*Interrupted system call*)
    EIO = 5;		(*I/0 error*)
    ENXIO = 6;		(*No such device or address*)
    E2BIG = 7;		(*Argument list too long*)
    ENOEXEC = 8;	(*Exec format error*)
    EBADF = 9;		(*Bad file number*)
    ENOMEM = 12;	(*Not enough space*)
    EACCES = 13;	(*Permission denied*)
    EEXIST = 17;	(*File exists*)
    ENODEV = 19;	(*Operation not supported by device*)
    ENOTDIR = 20;	(*Not a directory*)
    EISDIR = 21;	(*Is a directory*)
    EINVAL = 22;	(*Invalid parameter*)
    ENFILE = 23;	(*File table overflow*)
    EMFILE = 24;	(*Too many open files*)
    ENOTTY = 25;	(*Inappropriate ioctl for device*)
    ENOSPC = 28;	(*No space left on device*)
    ESPIPE = 29;	(*Illegal seek*)
    EROFS = 30;		(*Read-only file system*)
    EMLINK = 31;	(*Too many links*)
    EADDRINUSE = 48;	(*Address already in use*)
    EADDRNOTAVAIL = 49;	(*Can't assign requested address*)
    ECONNRESET = 54;	(*Connection reset by peer*)

    (*standard file descriptors*)
    InputFD = 0;
    OutputFD = 1;
    DiagnosticFD = 2;

    (* ioctl command consts*)

    IOC_VOID = 020000000H;
    IOC_IN = 080000000H;
    IOC_OUT = 040000000H;
    IOC_INOUT = IOC_IN + IOC_OUT;


TYPE
    Sgttyb = RECORD
        sg_ispeed: CARD8; (* input speed *)
        sg_ospeed: CARD8; (* output speed *)
        sg_erase: CARD8; (* erase character *)
        sg_kill: CARD8; (* kill character *)
        sg_flags: SET16; (* mode flags *)
    END(*RECORD*);
    Winsize = RECORD
        ws_row: CARD16;		(* rows, in characters *)
        ws_col: CARD16;		(* columns, in characters *)
        ws_xpixel: CARD16;	(* horizontal size, pixels *)
        ws_ypixel: CARD16;	(* vertical size, pixels *)
    END(*RECORD*);

CONST
    ECHO = 000000008H;	(* echo input *)
    RAW = 00000020H;	(* no IO processing *)
	TIOCLBIS = IOC_IN + TSIZE (INT32) * 65536 + ORD('t') * 256 + 127;	(* bis local mode bits *)
	TIOCLBIC = IOC_IN + TSIZE (INT32) * 65536 + ORD('t') * 256 + 126;	(* bic local mode bits *)
	TIOCLSET = IOC_IN + TSIZE (INT32) * 65536 + ORD('t') * 256 + 125;	(* set entire local mode word *)
	TIOCLGET = IOC_OUT + TSIZE (INT32) * 65536 + ORD('t') * 256 + 124;	(* get local modes *)
	TIOCGETP = IOC_OUT + TSIZE (Sgttyb) * 65536 + ORD ('t') * 256 + 8;	(* get parameters -- gtty *)
	TIOCSETP = IOC_IN + TSIZE (Sgttyb) * 65536 + ORD ('t') * 256 + 9;	(* set parameters -- stty *)
	TIOCGWINSZ = IOC_OUT + TSIZE (Winsize) * 65536 + ORD ('t') * 256 + 104;	(* get window size *)
	TIOCSWINSZ = IOC_IN + TSIZE (Winsize) * 65536 + ORD ('t') * 256 + 103;	(* set window size *)

    (*for 'fcntl'*)
    DUPFD = 0;
    F_GETFL = 1;			(* get file descriptor flags *)
    F_SETFL = 2;			(* set file descriptor flags *)

    (*mode values for 'lseek'*)
    fromStart = 0;
    fromCurPos = 1;
    fromEnd = 2;

    (* Commands passed to tcsetattr() for setting the termios structure. *)
    TCSANOW = 0;		(* make change immediate *)
    TCSADRAIN = 1;		(* drain output, then change *)
    TCSAFLUSH = 2;		(* drain output, flush input *)
    TCSASOFT = 010H;	(* flag - don't alter h.w. state '*)


CONST
    (*
     * Special Control Characters
     *
     * Index into controlChars character array.
     *
     *	Name	     Subscript	Enabled by
     **)
    VEOF			= 0;	(* ICANON *)
    VEOL			= 1;	(* ICANON *)
    VEOL2			= 2;	(* ICANON together with IEXTEN *)
    VERASE			= 3;	(* ICANON *)
    VWERASE			= 4;	(* ICANON together with IEXTEN *)
    VKILL			= 5;	(* ICANON *)
    VREPRINT		= 6;	(* ICANON together with IEXTEN *)

    VINTR			= 8;	(* ISIG *)
    VQUIT			= 9;	(* ISIG *)
    VSUSP			= 10;	(* ISIG *)
    VDSUSP			= 11;	(* ISIG *)
    VSTART			= 12;	(* IXON, IXOFF *)
    VSTOP			= 13;	(* IXON, IXOFF *)
    VLNEXT			= 14;	(* IEXTEN *)
    VDISCARD		= 15;	(* IEXTEN *)
    VMIN			= 16;	(* ! ICANON *)
    VTIME			= 17;	(* ! ICANON *)
    VSTATUS			= 18;	(* ICANON together with IEXTEN *)

    NCCS			= 20;

TYPE
    TCFlags = SET OF [0 .. 31];
    ControlChars = CARD8;
    Speed = CARD32;

    TermIOS = RECORD
        iflag: TCFlags;		(* input flags *)
        oflag: TCFlags;		(* output flags *)
        cflag: TCFlags;		(* control flags *)
        lflag: TCFlags;		(* local flags *)
        controlChars: ARRAY [0 .. NCCS - 1] OF ControlChars;	(* control chars *)
        ispeed: Speed;		(* input speed *)
        ospeed: Speed;		(* output speed *)
    END(*RECORD*);

CONST
    (* Input flags - software input processing *)
    IGNBRK = TCFlags {0};		(* ignore BREAK condition *)
    BRKINT = TCFlags {1};		(* map BREAK to SIGINTR *)
    IGNPAR = TCFlags {2};		(* ignore (discard) parity errors *)
    PARMRK = TCFlags {3};		(* mark parity and framing errors *)
    INPCK = TCFlags {4};		(* enable checking of parity errors *)
    ISTRIP = TCFlags {5};		(* strip 8th bit off chars *)
    INLCR = TCFlags {6};		(* map NL into CR *)
    IGNCR = TCFlags {7};		(* ignore CR *)
    ICRNL = TCFlags {8};		(* map CR to NL (ala CRMOD) *)
    IXON = TCFlags {9};			(* enable output flow control *)
    IXOFF = TCFlags {10};		(* enable input flow control *)
    IXANY = TCFlags {11};		(* any char will restart after stop *)
    IMAXBEL = TCFlags {13};		(* ring bell on input queue full *)


    (* Control flags - hardware control of terminal *)
    CIGNORE = TCFlags {0};		(* ignore control flags *)
    CSTOPB = TCFlags {10};		(* send 2 stop bits *)
    CREAD = TCFlags {11};		(* enable receiver *)
    PARENB = TCFlags {12};		(* parity enable *)
    PARODD = TCFlags {13};		(* odd parity, else even *)
    HUPCL = TCFlags {14};		(* hang up on last close *)
    CLOCAL = TCFlags {15};		(* ignore modem status lines *)
    CCTS_OFLOW = TCFlags {16};		(* CTS flow control of output *)
    CRTS_IFLOW = TCFlags {17};		(* RTS flow control of input *)
    CDTR_IFLOW = TCFlags {18};		(* DTR flow control of input *)
    CDSR_OFLOW = TCFlags {19};		(* DSR flow control of output *)
    CCAR_OFLOW = TCFlags {20};		(* DCD flow control of output *)
    MDMBUF = CCAR_OFLOW;		(* old name for CCAR_OFLOW *)
    CRTSCTS = CCTS_OFLOW + CRTS_IFLOW;
    
    CSIZE = TCFlags {8, 9};		(* character size mask *)
    CS5 = TCFlags {};			(* 5 bits (pseudo) *)
    CS6 = TCFlags {8};			(* 6 bits *)
    CS7 = TCFlags {9};			(* 7 bits *)
    CS8 = TCFlags {8, 9};		(* 8 bits *)
        
TYPE
    IEString = ARRAY [0..255] OF CHAR;					(* Modula2 - String !! *)
    IEStringPtr = POINTER TO IEString;
    IEStringVec = ARRAY [0..8191] OF IEStringPtr;
    IEStringVecPtr = POINTER TO IEStringVec;
    
    OFlagSet = SET OF [0..31];		(*for 'open'*)
    
    (*
     *	argument structure for use with F_SMARKER command
     *)
    MarkElement = RECORD
        start:		INT32;			(* start position of mark *)
        end:		INT32;			(* end position *)
        name:		STR255;			(* mark name as Pascal string *)
        (*
        charCount:	CARD8;			(* number of chars in mark name *)
        name:		CHAR;			(* first char of mark name *)
        (* note: typically extra space is allocated *)
        (*   in back to allow room for a longer string *)
    *)	END;
    
    
    (* file mode *)
    Permission = (S_IXOTH, S_IWOTH, S_IROTH, S_IXGRP, S_IWGRP, S_IRGRP, S_IXUSR, S_IWUSR, S_IRUSR, S_ISTXT, S_ISGID, S_ISUID);			(*V8.0*)
    Permissions = SET OF Permission;					(*V8.0*)
    
CONST
    O_RDONLY = OFlagSet {};
    O_WRONLY = OFlagSet {0};
    O_RDWR = OFlagSet {1};
    O_ACCMODE = OFlagSet {0, 1};						(*V8.0*)
    O_NONBLOCK = OFlagSet {2};
    O_APPEND = OFlagSet {3};
    O_SHLOCK = OFlagSet {4};
    O_EXLOCK = OFlagSet {5};							(*V8.0*)
    O_CREAT = OFlagSet {9};
    O_TRUNC = OFlagSet {10};
    O_EXCL = OFlagSet {11};
    O_NOCTTY = OFlagSet {17};
    
    S_IREAD = S_IRUSR;									(*V8.0*)
    S_IWRITE = S_IWUSR;									(*V8.0*)
    S_IEXEC = S_IXUSR;									(*V8.0*)
    S_IRWXO = Permissions {S_IXOTH, S_IWOTH, S_IROTH};	(*V8.0*)
    S_IRWXG = Permissions {S_IXGRP, S_IWGRP, S_IRGRP};	(*V8.0*)
    S_IRWXU = Permissions {S_IXUSR, S_IWUSR, S_IRUSR};	(*V8.0*)
    
    
PROCEDURE M2_GetArgs (VAR args: IEStringVecPtr; VAR argcnt: CARD32);
PROCEDURE M2_GetEnvPointer (VAR envp: IEStringVecPtr): BOOLEAN;
PROCEDURE M2_GetEnv (shellvar: ARRAY OF CHAR; VAR value: ARRAY OF CHAR): BOOLEAN;		(*V6.0b5*)

<* ASSIGN (Calling, "CCalling") *>
PROCEDURE _exit (status: INT32);
PROCEDURE access (filename: ARRAY OF CHAR; mode: INT32): INT32;
PROCEDURE open (filename: ARRAY OF CHAR; mode: OFlagSet): INT32;
PROCEDURE close (fd: INT32): INT32;
PROCEDURE read	(fd: INT32; buffer: Ptr; count: INT32): INT32;
PROCEDURE write (fd: INT32; buffer: Ptr; count: INT32): INT32;
PROCEDURE ioctl (fd: INT32; cmd: CARD32; arg: ADDRESS): INT32;
PROCEDURE lseek (fd: INT32; bytePos: INT64; mode: INT32): INT64;	(*V8.2*)
PROCEDURE fcntl (fd, cmd, arg: INT32): INT32;
PROCEDURE ftruncate (fd: INT32; bytePos: INT64): INT32;
PROCEDURE fchmod (fd: INT32; mode: Permissions): INT32;				(*V8.0*)
PROCEDURE fsync (fd: INT32): INT32;									(*V8.0*)
PROCEDURE unlink (filename: ARRAY OF CHAR): INT32;					(*V8.0*)
PROCEDURE ttyname (fd: INT32): IEStringPtr;							(*V8.0*)
PROCEDURE getcwd (VAR path: ARRAY OF CHAR; size: INTEGER);			(*V8.0*)
PROCEDURE isatty (fd: INT32): BOOLEAN;
PROCEDURE tcgetattr (fd: INT32; VAR attribute: TermIOS): INT32;
PROCEDURE tcsetattr (fd: INT32; command: INT32; <* ASSIGN (Reference, TRUE) *> attribute: TermIOS): INT32;
PROCEDURE cfsetispeed (VAR attribute: TermIOS; speed: Speed): INT32;
PROCEDURE cfsetospeed (VAR attribute: TermIOS; speed: Speed): INT32;

(* pipe, socketpair, fstat *)

TYPE
    INT32Ptr = POINTER TO INT32;

PROCEDURE __error (): INT32Ptr;

TYPE
    Fd_Set = ARRAY [0 .. 31] OF SET32;
    Fd_Set_Ptr = POINTER TO Fd_Set;
    TimeVal = RECORD
        tv_sec: CARD32;
        tv_usec: CARD32;
    END(*RECORD*);
    TimeValPtr = POINTER TO TimeVal;

PROCEDURE select (fd: INT32;  readfds: Fd_Set_Ptr; writefds: Fd_Set_Ptr;			(*V9.2*)
                  errfds: Fd_Set_Ptr; timeval: TimeValPtr): INT32;
    
END Unix.
The first three function procedures give access to the parameters of "main". "M2_GetEnvPointer" returns a pointer to the vector of the environment variables and "M2_GetArgs" returns a pointer to the command line arguments. "M2_GetEnv" returns in its second parameter the value of the shell variable with the name "shellvar". The function result "TRUE" signifies that the shell variable "shellvar" exists.

The other procedures have exactly the meaning as described in the man pages.

3.4.2 BasicMemory

<* ASSIGN (Foreign, TRUE) *>
DEFINITION MODULE BasicMemory;
FROM SYSTEM IMPORT ADDRESS;

<* ASSIGN (Calling, "CCalling") *>

PROCEDURE malloc (size: INTEGER): ADDRESS;
PROCEDURE free (ptr: ADDRESS);

END BasicMemory.

These are the basic procedures used by all memory managing modules ("Storage", "VectorStorage", "Garbage").

Do not use "free" for a pointer allocated by one of the Modula-2 library modules, as these modules habe a different memory management.

3.4.3 BasicNet

<* ASSIGN (Foreign, TRUE) *>
<* ASSIGN (Calling, "CCalling") *>
DEFINITION MODULE BasicNet;
    
FROM Unix IMPORT IEStringPtr, IEStringVecPtr;
FROM SYSTEM IMPORT CARD8, CARD16, INT16, INT32, CARD32, SET32, ADDRESS, TSIZE;
    
CONST
    (*
     * Sockettypes
     *)
    SOCK_STREAM	= 1;
    SOCK_DGRAM = 2;
    SOCK_RAW = 3;
    SOCK_RDM = 4;
    SOCK_SEQPACKET = 5;
    (*
     * Address families.
     *)
    AF_UNSPEC	= 0;		(* unspecified *)
    AF_UNIX		= 1;		(* local to host (pipes) *)
    AF_LOCAL	= AF_UNIX;	(* backward compatibility *)
    AF_INET		= 2;		(* internetwork: UDP, TCP, etc. *)
    AF_IMPLINK	= 3;		(* arpanet imp addresses *)
    AF_PUP		= 4;		(* pup protocols: e.g. BSP *)
    AF_CHAOS	= 5;		(* mit CHAOS protocols *)
    AF_NS		= 6;		(* XEROX NS protocols *)
    AF_ISO		= 7;		(* ISO protocols *)
    AF_OSI		= AF_ISO;
    AF_ECMA		= 8;		(* European computer manufacturers *)
    AF_DATAKIT	= 9;		(* datakit protocols *)
    AF_CCITT	= 10;		(* CCITT protocols, X.25 etc *)
    AF_SNA		= 11;		(* IBM SNA *)
    AF_DECnet	= 12;		(* DECnet *)
    AF_DLI		= 13;		(* DEC Direct data link interface *)
    AF_LAT		= 14;		(* LAT *)
    AF_HYLINK	= 15;		(* NSC Hyperchannel *)
    AF_APPLETALK	= 16;	(* Apple Talk *)
    AF_ROUTE	= 17;		(* Internal Routing Protocol *)
    AF_LINK		= 18;		(* Link layer interface *)
    pseudo_AF_XTP	= 19;	(* eXpress Transfer Protocol (no AF) *)
    AF_COIP		= 20;		(* connection-oriented IP, aka ST II *)
    AF_CNT		= 21;		(* Computer Network Technology *)
    pseudo_AF_RTIP	= 22;	(* Help Identify RTIP packets *)
    AF_IPX		= 23;		(* Novell Internet Protocol *)
    AF_SIP		= 24;		(* Simple Internet Protocol *)
    pseudo_AF_PIP	= 25;	(* Help Identify PIP packets *)
    pseudo_AF_BLUE	= 26;	(* Identify packets for Blue Box - Not used *)
    AF_NDRV		= 27;		(* Network Driver 'raw' access *)
    AF_ISDN		= 28;		(* Integrated Services Digital Network*)
    AF_E164		= AF_ISDN;	(* CCITT E.164 recommendation *)
    pseudo_AF_KEY	= 29;	(* Internal key-management function *)
    AF_INET6	= 30;		(* IPv6 *)
    AF_NATM		= 31;		(* native ATM access *)
    AF_SYSTEM	= 32;		(* Kernel event messages *)
    AF_NETBIOS	= 33;		(* NetBIOS *)
    AF_PPP		= 34;		(* PPP communication protocol *)
    pseudo_AF_HDRCMPLT = 35;(* Used by BPF to not rewrite headers in interface output routine *)
    AF_RESERVED_36	= 36;	(* Reserved for internal usage *)
    AF_NETGRAPH	= 32;		(* Netgraph sockets *)
    AF_IEEE80211    = 37;   (* IEEE 802.11 protocol *)
    AF_MAX		= 38;
    
    (*
     * Address constants
     *)
    INADDR_ANY = 0;         (* Accepts from every interface *)
    INADDR_BROADCAST = 0ffffffffH;
    
    
    (*
     * Option flags per-socket.
     *)
    SO_DEBUG            = 0001H;   (* turn on debugging info recording *)
    SO_ACCEPTCONN       = 0002H;   (* socket has had listen() *)
    SO_REUSEADDR        = 0004H;   (* allow local address reuse *)
    SO_KEEPALIVE        = 0008H;   (* keep connections alive *)
    SO_DONTROUTE        = 0010H;   (* just use interface addresses *)
    SO_BROADCAST        = 0020H;   (* permit sending of broadcast msgs *)
    SO_USELOOPBACK      = 0040H;   (* bypass hardware when possible *)
    SO_LINGER           = 0080H;   (* linger on close if data present (in ticks) *)
    SO_OOBINLINE        = 0100H;   (* leave received OOB data in line *)
    SO_REUSEPORT        = 0200H;   (* allow local address & port reuse *)
    SO_TIMESTAMP        = 0400H;   (* timestamp received dgram traffic *)
    SO_TIMESTAMP_MONOTONIC = 0800H;   (* Monotonically increasing timestamp on rcvd dgram *)
    SO_DONTTRUNC        = 2000H;   (* APPLE: Retain unread data *)
    (*  (ATOMIC proto) *)
    SO_WANTMORE         = 4000H;   (* APPLE: Give hint when more data ready *)
    SO_WANTOOBFLAG      = 8000H;   (* APPLE: Want OOB in MSG_FLAG on receive *)
    
    
    SO_SNDBUF           = 1001H;   (* send buffer size *)
    SO_RCVBUF           = 1002H;   (* receive buffer size *)
    SO_SNDLOWAT         = 1003H;   (* send low-water mark *)
    SO_RCVLOWAT         = 1004H;   (* receive low-water mark *)
    SO_SNDTIMEO         = 1005H;   (* send timeout *)
    SO_RCVTIMEO         = 1006H;   (* receive timeout *)
    SO_ERROR            = 1007H;   (* get error status and clear *)
    SO_TYPE             = 1008H;   (* get socket type *)
    SO_LABEL            = 1010H;   (* socket's MAC label *)
    SO_PEERLABEL        = 1011H;   (* socket's peer MAC label *)
    SO_NREAD            = 1020H;   (* APPLE: get 1st-packet byte count *)
    SO_NKE              = 1021H;   (* APPLE: Install socket-level NKE *)
    SO_NOSIGPIPE        = 1022H;   (* APPLE: No SIGPIPE on EPIPE *)
    SO_NOADDRERR        = 1023H;   (* APPLE: Returns EADDRNOTAVAIL when src is not available anymore *)
    SO_NWRITE           = 1024H;   (* APPLE: Get number of bytes currently in send socket buffer *)
    SO_REUSESHAREUID    = 1025H;   (* APPLE: Allow reuse of port/socket by different userids *)
    SO_NOTIFYCONFLICT   = 1026H;   (* APPLE: send notification if there is a bind on a port which is already in use *)
    SO_UPCALLCLOSEWAIT  = 1027H;   (* APPLE: block on close until an upcall returns *)
    SO_LINGER_SEC       = 1080H;   (* linger on close if data present (in seconds) *)
    SO_RESTRICTIONS     = 1081H;   (* APPLE: deny inbound/outbound/both/flag set *)
    SO_RESTRICT_DENYIN  = 00000001H;   (* flag for SO_RESTRICTIONS - deny inbound *)
    SO_RESTRICT_DENYOUT = 00000002H;   (* flag for SO_RESTRICTIONS - deny outbound *)
    SO_RESTRICT_DENYSET = 80000000H;   (* flag for SO_RESTRICTIONS - deny has been set *)
    SO_RANDOMPORT       = 1082H;   (* APPLE: request local port randomization *)
    SO_NP_EXTENSIONS    = 1083H;   (* To turn off some POSIX behavior *)
    
    
    SOL_SOCKET = 0ffffH;		(* options for socket level *)
    
TYPE
    IPAddress = CARD32;
    CharPtr = POINTER TO ARRAY [0 .. 255] OF CHAR;
    (**
     * Socket address, internet style.
     *)
    sockaddr_in = RECORD
        sin_len: CARD8;
        sin_family: CARD8;
        sin_port: CARD16;
        sin_addr: IPAddress;
        sin_zero: ARRAY [0 .. 7] OF CHAR;
    END(*RECORD*);
    SocketAddrPtr = POINTER TO sockaddr_in;
    sockaddr_inPtr = SocketAddrPtr;
    
    hostent = RECORD
        h_name: IEStringPtr; (* Official name of the host *)
        h_aliases: IEStringVecPtr; (* A NULL-terminated array of alternate names for the host *)
        h_addrtype: INT32; (* host address type *)
        h_length: INT32; (* length of address *)
        (* h_addr_list: IEStringVecPtr; (* list of addresses from name server *) *)
        h_addr: POINTER TO POINTER TO INT32; (* DIE IP-Adresse des Hosts *)
    END(*RECORD*);
    HostentPtr = POINTER TO hostent;
    
    sockaddr = RECORD
        sa_len: CARD8;      (* total length *)
        sa_family: CARD8;   (* [XSI] address family *)
        sa_data: ARRAY [0 .. 13] OF CARD8; (* [XSI] addr value (actually larger) *)
    END(*RECORD*);
    sockaddrPtr = POINTER TO sockaddr;
    
    ifaddrsPtr = POINTER TO ifaddrs;
    ifaddrs = RECORD
        ifa_next: ifaddrsPtr;
        ifa_name: POINTER TO ARRAY [0 .. 999] OF CHAR;
        ifa_flags: CARDINAL;
        ifa_addr: sockaddrPtr;
        ifa_nextmask: sockaddrPtr;
        ifa_dstaddr: sockaddrPtr;
        ifa_data: ADDRESS;
    END(*RECORD*);
    
TYPE
    ifreq = RECORD
        ifr_name: ARRAY [0 .. 15] OF CHAR;         (* if name, e.g. "en0" *)
        CASE : CARDINAL OF
        | 0:
            ifru_addr: sockaddr;
        | 1:
            ifru_dstaddr: sockaddr;
        | 2:
            ifru_broadaddr: sockaddr;
        | 3:
            ifru_flags: INT16;
        | 4:
            ifru_metric: INT32;
        | 5:
            ifru_mtu: INT32;
        | 6:
            ifru_phys: INT32;
        | 7:
            ifru_media: INT32;
        | 8:
            ifru_intval: INT32;
        | 9:
            ifru_data: ADDRESS;
        END(*CASE*);
    END(*RECORD*);
    ifreqPtr = POINTER TO ifreq;
    
    ifconf = RECORD
        ifc_len: INT32;
        CASE : CARDINAL OF
        | 0:
            ifru_addr: ADDRESS;
        | 1:
            ifcu_req: ifreqPtr;
        END(*CASE*);
    END(*RECORD*);
    
    
CONST
    (* ioctl command consts*)
    
    IOC_VOID = 020000000H;
    IOC_IN = 080000000H;
    IOC_OUT = 040000000H;
    IOC_INOUT = IOC_IN + IOC_OUT;
    
    SIOCGIFADDR     = IOC_INOUT + TSIZE (ifreq) * 65536 + ORD('i') * 256 + 33;     (* get ifnet address *)
    SIOCGIFDSTADDR  = IOC_INOUT + TSIZE (ifreq) * 65536 + ORD('i') * 256 + 34;     (* get p-p address *)
    SIOCGIFBRDADDR  = IOC_INOUT + TSIZE (ifreq) * 65536 + ORD('i') * 256 + 35;     (* get broadcast addr *)
    SIOCGIFCONF     = IOC_INOUT + TSIZE (ifconf) * 65536 + ORD('i') * 256 + 36;    (* get ifnet list *)
    SIOCGIFNETMASK  = IOC_INOUT + TSIZE (ifreq) * 65536 + ORD('i') * 256 + 37;     (* get net addr mask *)
    SIOCAUTOADDR    = IOC_INOUT + TSIZE (ifreq) * 65536 + ORD('i') * 256 + 38;     (* autoconf address *)
    SIOCAUTONETMASK = IOC_INOUT + TSIZE (ifreq) * 65536 + ORD('i') * 256 + 39;     (* autoconf netmask *)
    SIOCARPIPLL     = IOC_INOUT + TSIZE (ifreq) * 65536 + ORD('i') * 256 + 40;     (* arp for IPv4LL address *)
    
PROCEDURE getifaddrs (VAR ifaddrs: ifaddrsPtr): INT32;
PROCEDURE freeifaddrs (ifaddrs: ifaddrsPtr);
PROCEDURE ioctl (fd: INT32; cmd: CARD32; arg: ADDRESS; len: INT32): INT32;


PROCEDURE gethostname (VAR name: ARRAY OF CHAR; len: CARD32): INT32;
PROCEDURE gethostbyname (name: ARRAY OF CHAR): HostentPtr;
PROCEDURE gethostent (): HostentPtr;

PROCEDURE socket (domain: INT32; type: INT32; protokoll: INT32): INT32;
PROCEDURE bind (socket: INT32; addr: SocketAddrPtr; len: CARD32): INT32;
PROCEDURE listen (socket: INT32; backlog: INT32): INT32;
PROCEDURE accept (socket: INT32; addr: SocketAddrPtr; VAR len: CARD32): INT32;
PROCEDURE connect (socket: INT32; addr: SocketAddrPtr; len: CARD32): INT32;
PROCEDURE getsockopt (socket: INT32; level: INT32; option_name: INT32; option_value: ADDRESS; VAR option_len: INT32): INT32;
PROCEDURE setsockopt (socket: INT32; level: INT32; option_name: INT32; option_value: ADDRESS; option_len: INT32): INT32;
PROCEDURE getsockname (socket: INT32; VAR name: sockaddr; VAR name_len: CARD32): INT32;



PROCEDURE recv (socket: INT32; buffer: ADDRESS; buflen: INT32; flags: INT32): INT32;
PROCEDURE send (socket: INT32; buffer: ADDRESS; length: INT32; flags: INT32): INT32;
PROCEDURE recvfrom (socket: INT32; buffer: ADDRESS; buflen: INT32; flags: INT32; fromaddr: SocketAddrPtr; VAR len: CARD32): INT32;
PROCEDURE sendto (socket: INT32; buffer: ADDRESS; length: INT32; flags: INT32; toaddr: SocketAddrPtr; len: CARD32): INT32;

(* auxilliary procedures *)
PROCEDURE inet_ntoa (adr: IPAddress): CharPtr;
PROCEDURE inet_aton (adrstring: ARRAY OF CHAR; VAR adr: IPAddress): INT32;
PROCEDURE inet_ntop (family: INT32; source: ADDRESS; stingbuffer: ADDRESS; bufferSize: INT32);
    
TYPE
    Fd_set = ARRAY [0 .. 31] OF SET32;
    Fd_setPtr = POINTER TO Fd_set;
    Timeval = RECORD
        tv_sec: CARDINAL;       (* seconds *)
        tv_usec: INT32;         (* and microseconds *)
    END(*RECORD*);
    
PROCEDURE select (nfds: INT32; readfds: Fd_setPtr; writefds: Fd_setPtr; errorfds: Fd_setPtr; VAR timeout: Timeval): INT32;
    
END BasicNet.
This module provides for the basic procedures used in "NetFile".

3.4.4 BasicThread

<* ASSIGN (Foreign, TRUE) *>
<* ASSIGN (Calling, "CCalling") *>
DEFINITION MODULE BasicThread;

FROM Unix IMPORT IEStringPtr, IEStringVecPtr;
FROM BasicTime IMPORT TimeSpec;
FROM SYSTEM IMPORT CARD8, CARD16, INT32, CARD32, SET32, ADDRESS;

CONST
	__PTHREAD_ATTR_SIZE__ = <* IF ARCH = x86 THEN *> 56 <* ELSE *> 36 <* END *>;
	__PTHREAD_MUTEX_SIZE__ = <* IF ARCH = x86 THEN *> 56 <* ELSE *> 40 <* END *>;
	__PTHREAD_MUTEXATTR_SIZE__ = <* IF ARCH = x86 THEN *> 8 <* ELSE *> 8 <* END *>;
	__PTHREAD_COND_SIZE__ = <* IF ARCH = x86 THEN *> 40 <* ELSE *> 24 <* END *>;
	__PTHREAD_CONDATTR_SIZE__ = <* IF ARCH = x86 THEN *> 8 <* ELSE *> 4 <* END *>;
	__PTHREAD_SIZE__ = <* IF ARCH = x86 THEN *> 1168 <* ELSE *> 596 <* END *>;
    PTHREAD_STACK_MIN = 8192;

    _PTHREAD_MUTEX_SIG_init = 032AAABA7H;
    _PTHREAD_ERRORCHECK_MUTEX_SIG_init = 32AAABA1H;
    _PTHREAD_RECURSIVE_MUTEX_SIG_init = 32AAABA2H;
    _PTHREAD_FIRSTFIT_MUTEX_SIG_init = 32AAABA3H;

    _PTHREAD_COND_SIG_init = 3CB0B1BBH;
    _PTHREAD_ONCE_SIG_init = 30B1BCBAH;
    _PTHREAD_RWLOCK_SIG_init = 2DA8B3B4H;
    
	SCHED_OTHER = 1;
	SCHED_FIFO = 4;
	SCHED_RR = 2;
    __SCHED_PARAM_SIZE__ = 4;

TYPE
	CallProc = PROCEDURE (ADDRESS): ADDRESS;

    pthread_handler_recPtr = POINTER TO pthread_handler_rec;
    pthread_handler_rec = RECORD
    	__routine: CallProc;
        __arg: ADDRESS;
        __next: pthread_handler_recPtr;
    END(*RECORD*);
    
    pthread_attr_t = RECORD
    	__sig: INTEGER;
        dummy: ARRAY [0 .. __PTHREAD_ATTR_SIZE__ - 1] OF CHAR;
    END(*RECORD*);
    pthread_attr_tPtr = POINTER TO pthread_attr_t;
    
    pthread_condattr_t = RECORD
    	__sig: INTEGER;
        dummy: ARRAY [0 .. __PTHREAD_MUTEXATTR_SIZE__ - 1] OF CHAR;
    END(*RECORD*);
    pthread_condattr_tPtr = POINTER TO pthread_condattr_t;
    
    pthread_cond_t = RECORD
    	__sig: INTEGER;
        dummy: ARRAY [0 .. __PTHREAD_COND_SIZE__ - 1] OF CHAR;
    END(*RECORD*);
    _opaque_pthread_cond_tPtr = POINTER TO pthread_cond_t;
    
    pthread_mutexattr_t = RECORD
    	__sig: INTEGER;
        dummy: ARRAY [0 .. __PTHREAD_MUTEXATTR_SIZE__ - 1] OF CHAR;
    END(*RECORD*);
    pthread_mutexattr_tPtr = POINTER TO pthread_mutexattr_t;
    
    pthread_mutex_t = RECORD
    	__sig: INTEGER;
        dummy: ARRAY [0 .. __PTHREAD_MUTEX_SIZE__ - 1] OF CHAR;
    END(*RECORD*);
    pthread_mutex_tPtr = POINTER TO pthread_mutex_t;
    
    _opaque_pthread_t = RECORD
    	__sig: INTEGER;
        __cleanup_stack: pthread_handler_recPtr;
        dummy: ARRAY [0 .. __PTHREAD_SIZE__ - 1] OF CHAR;
    END(*RECORD*);
    pthread_t = POINTER TO _opaque_pthread_t;

    sched_param = RECORD
    	sched_priority: INT32;
        dummy: ARRAY [0 .. __SCHED_PARAM_SIZE__ - 1] OF CHAR;
    END(*RECORD*);
    sched_paramPtr = POINTER TO sched_param;


    StartProc = PROCEDURE (ADDRESS): ADDRESS;

CONST
	PTHREAD_MUTEX_INITIALIZER = pthread_mutex_t {_PTHREAD_MUTEX_SIG_init , {CHR (0) BY __PTHREAD_MUTEX_SIZE__} };
    PTHREAD_COND_INITIALIZER = pthread_cond_t {_PTHREAD_COND_SIG_init , {CHR (0) BY __PTHREAD_COND_SIZE__} };

PROCEDURE pthread_attr_destroy (VAR attr: pthread_attr_t): INT32;
PROCEDURE pthread_attr_getdetachstate (VAR attr: pthread_attr_t; VAR state: INT32): INT32;
PROCEDURE pthread_attr_getguardsize (VAR attr: pthread_attr_t; VAR size: CARDINAL): INT32;
PROCEDURE pthread_attr_getinheritsched (VAR attr: pthread_attr_t; VAR sched: INT32): INT32;
PROCEDURE pthread_attr_getschedparam (VAR attr: pthread_attr_t; VAR param: sched_param): INT32;
PROCEDURE pthread_attr_getscope (VAR attr: pthread_attr_t; VAR scope: INT32): INT32;
PROCEDURE pthread_attr_getschedpolicy (VAR attr: pthread_attr_t; VAR policy: INT32): INT32;
PROCEDURE pthread_attr_getstack (VAR attr: pthread_attr_t; VAR start: ADDRESS; VAR size: CARDINAL): INT32;
PROCEDURE pthread_attr_getstackaddr (VAR attr: pthread_attr_t; VAR start: ADDRESS): INT32;
PROCEDURE pthread_attr_getstacksize (VAR attr: pthread_attr_t; VAR size: CARDINAL): INT32;
PROCEDURE pthread_attr_init (VAR attr: pthread_attr_t): INT32;
PROCEDURE pthread_attr_setdetachstate (VAR attr: pthread_attr_t; state: INT32): INT32;
PROCEDURE pthread_attr_setguardsize (VAR attr: pthread_attr_t; size: CARDINAL): INT32;
PROCEDURE pthread_attr_setinheritsched (VAR attr: pthread_attr_t; sched: INT32): INT32;
PROCEDURE pthread_attr_setschedparam (VAR attr: pthread_attr_t; param: sched_paramPtr): INT32;
PROCEDURE pthread_attr_setscope (VAR attr: pthread_attr_t; scope: INT32): INT32;
PROCEDURE pthread_attr_setschedpolicy (VAR attr: pthread_attr_t; VAR policy: INT32): INT32;
PROCEDURE pthread_attr_setstack (VAR attr: pthread_attr_t; start: ADDRESS; size: CARDINAL): INT32;
PROCEDURE pthread_attr_setstackaddr (VAR attr: pthread_attr_t; start: ADDRESS): INT32;
PROCEDURE pthread_attr_setstacksize (VAR attr: pthread_attr_t; size: CARDINAL): INT32;

PROCEDURE pthread_create (VAR thread: pthread_t; attr: pthread_attr_tPtr; start_routine: StartProc; arg: ADDRESS): INT32;
PROCEDURE pthread_create_suspended_np (VAR thread: pthread_t; attr: pthread_attr_tPtr; start_routine: StartProc; arg: ADDRESS): INT32;
PROCEDURE pthread_exit (value_ptr: ADDRESS);
PROCEDURE pthread_cancel (thread: pthread_t): INT32;
PROCEDURE pthread_detach (thread: pthread_t): INT32;
PROCEDURE pthread_equal (thread1, thread2: pthread_t): INT32;
PROCEDURE pthread_getconcurrency (): INT32;
PROCEDURE pthread_getschedparam (thread: pthread_t; VAR policy: INT32; VAR parm: sched_param): INT32;
PROCEDURE pthread_join (thread: pthread_t; VAR param: ADDRESS): INT32;
PROCEDURE pthread_self (): pthread_t;
PROCEDURE pthread_kill (thread: pthread_t; sig: INT32): INT32;

PROCEDURE pthread_cond_broadcast (VAR cond: pthread_cond_t): INT32;
PROCEDURE pthread_cond_destroy (VAR cond: pthread_cond_t): INT32;
PROCEDURE pthread_cond_init (VAR cond: pthread_cond_t; attr: pthread_condattr_tPtr): INT32;
PROCEDURE pthread_cond_signal (VAR cond: pthread_cond_t): INT32;
PROCEDURE pthread_cond_signal_thread_np (VAR cond: pthread_cond_t; thread: pthread_t): INT32;
PROCEDURE pthread_cond_timedwait (VAR cond: pthread_cond_t; VAR mutex: pthread_mutex_t; VAR time: TimeSpec): INT32;
PROCEDURE pthread_cond_wait (VAR cond: pthread_cond_t; VAR mutex: pthread_mutex_t): INT32;

PROCEDURE pthread_condattr_destroy (VAR attr: pthread_condattr_t): INT32;
PROCEDURE pthread_condattr_init (VAR attr: pthread_condattr_t): INT32;
PROCEDURE pthread_condattr_getpshared (VAR attr: pthread_condattr_t; VAR shared: INT32): INT32;
PROCEDURE pthread_condattr_setpshared (VAR attr: pthread_condattr_t; shared: INT32): INT32;

PROCEDURE pthread_mutex_lock (VAR mutex: pthread_mutex_t): INT32;
PROCEDURE pthread_mutex_trylock (VAR mutex: pthread_mutex_t): INT32;
PROCEDURE pthread_mutex_unlock (VAR mutex: pthread_mutex_t): INT32;
PROCEDURE pthread_mutex_init (VAR mutex: pthread_mutex_t; attr: pthread_mutexattr_tPtr): INT32;
PROCEDURE pthread_mutex_destroy (VAR mutex: pthread_mutex_t): INT32;
PROCEDURE pthread_mutex_getprioceiling (VAR mutex: pthread_mutex_t; VAR ceiling: INT32): INT32;
PROCEDURE pthread_mutex_setprioceiling (VAR mutex: pthread_mutex_t; ceiling: INT32; VAR old: INT32): INT32;

PROCEDURE pthread_mutexattr_destroy (VAR attr: pthread_mutexattr_t): INT32;
PROCEDURE pthread_mutexattr_getprioceiling (VAR attr: pthread_mutexattr_t; VAR ceiling: INT32): INT32;
PROCEDURE pthread_mutexattr_getprotocol (VAR attr: pthread_mutexattr_t; VAR protocol: INT32): INT32;
PROCEDURE pthread_mutexattr_getpshared (VAR attr: pthread_mutexattr_t; VAR shared: INT32): INT32;
PROCEDURE pthread_mutexattr_gettype (VAR attr: pthread_mutexattr_t; VAR type: INT32): INT32;
PROCEDURE pthread_mutexattr_init (VAR attr: pthread_mutexattr_t): INT32;
PROCEDURE pthread_mutexattr_setprioceiling (VAR attr: pthread_mutexattr_t; ceiling: INT32): INT32;
PROCEDURE pthread_mutexattr_setprotocol (VAR attr: pthread_mutexattr_t; protocol: INT32): INT32;
PROCEDURE pthread_mutexattr_setpshared (VAR attr: pthread_mutexattr_t; shared: INT32): INT32;
PROCEDURE pthread_mutexattr_settype (VAR attr: pthread_mutexattr_t; type: INT32): INT32;

END BasicThread.

The modules "Processes" and "Semapohres" are based on this module.

3.4.5 BasicTime

<* ASSIGN (Foreign, TRUE) *>
DEFINITION MODULE BasicTime;
FROM SYSTEM IMPORT INT32, CARD32, ADDRESS;

CONST
	ticksPerSecond = 100;

TYPE
	TimePtr = POINTER TO INT32;
	CharPtr = POINTER TO CHAR;
	TimeRec = RECORD
		tm_sec: INTEGER;	(* seconds after the minute [0-60] *)
		tm_min: INTEGER;	(* minutes after the hour [0-59] *)
		tm_hour: INTEGER;	(* hours since midnight [0-23] *)
		tm_mday: INTEGER;	(* day of the month [1-31] *)
		tm_mon: INTEGER;	(* months since January [0-11] *)
		tm_year: INTEGER;	(* years since 1900 *)
		tm_wday: INTEGER;	(* days since Sunday [0-6] *)
		tm_yday: INTEGER;	(* days since January 1 [0-365] *)
		tm_isdst: INTEGER;	(* Daylight Savings Time flag *)
		tm_gmtoff: INT32;	(* offset from CUT in seconds *)
		tm_zone: CharPtr;	(* timezone abbreviation *)
	END;
	TimeRecPtr = POINTER TO TimeRec;
    TimeSpec = RECORD
    	tv_sec: INTEGER;	(* Sekunden *)
    	tv_nsec: INTEGER;	(* Nanosekunden *)
    END(*RECORD*);
	TimeSpecPtr = POINTER TO TimeSpec;

<* ASSIGN (Calling, "CCalling") *>

PROCEDURE time (t: TimePtr): INT32;
PROCEDURE clock (): CARD32;
PROCEDURE localtime (t: TimePtr): TimeRecPtr;
PROCEDURE ctime (t: TimePtr): ADDRESS;
PROCEDURE nanosleep (t: TimeSpecPtr; rest: TimeSpecPtr): INT32;
PROCEDURE usleep (usec: CARD32): INT32;

END BasicTime.

The procedures of this module are used in the standard library module "SysClock".

3.4.6 FpIntf

<* ASSIGN (Foreign, TRUE) *>
<* ASSIGN (Calling, "CCalling") *>
DEFINITION MODULE FpIntf;

FROM SYSTEM IMPORT INT16, INT32, ADDRESS;
IMPORT SYSTEM;



(*======================== from math.h ==========================================*)
TYPE
    ConstCStringPtr = ADDRESS;
    CStringPtr = ADDRESS;
	float_t = REAL;
	double_t = LONGREAL;

CONST 
	DECIMAL_DIG = 17;

PROCEDURE cos (x: double_t): double_t; 
PROCEDURE sin (x: double_t): double_t; 
PROCEDURE tan (x: double_t): double_t; 
PROCEDURE acos (x: double_t): double_t; 
PROCEDURE asin (x: double_t): double_t; 
PROCEDURE atan (x: double_t): double_t; 
PROCEDURE atan2 (y: double_t;x: double_t): double_t; 
PROCEDURE cosh (x: double_t): double_t; 
PROCEDURE sinh (x: double_t): double_t; 
PROCEDURE tanh (x: double_t): double_t; 
PROCEDURE acosh (x: double_t): double_t; 
PROCEDURE asinh (x: double_t): double_t; 
PROCEDURE atanh (x: double_t): double_t; 
PROCEDURE exp (x: double_t): double_t; 
PROCEDURE expm1 (x: double_t): double_t; 
PROCEDURE exp2 (x: double_t): double_t; 
PROCEDURE frexp (x: double_t;VAR exponent: INT32): double_t; 
PROCEDURE ldexp (x: double_t;n: INT32): double_t; 
PROCEDURE log (x: double_t): double_t; 
PROCEDURE log2 (x: double_t): double_t; 
PROCEDURE log1p (x: double_t): double_t; 
PROCEDURE log10 (x: double_t): double_t; 
PROCEDURE logb (x: double_t): double_t; 
PROCEDURE modf (x: double_t;VAR iptr: double_t): double_t; 
PROCEDURE modff (x: REAL;VAR iptrf: REAL): REAL; 
TYPE
	_scalb_n_type = INT32;
PROCEDURE scalb (x: double_t;n: _scalb_n_type): double_t; 
PROCEDURE fabs (x: double_t): double_t; 
PROCEDURE hypot (x: double_t;y: double_t): double_t; 
PROCEDURE pow (x: double_t;y: double_t): double_t; 
PROCEDURE sqrt (x: double_t): double_t; 
PROCEDURE erf (x: double_t): double_t; 
PROCEDURE erfc (x: double_t): double_t; 
PROCEDURE gamma (x: double_t): double_t; 
PROCEDURE lgamma (x: double_t): double_t; 
PROCEDURE ceil (x: double_t): double_t; 
PROCEDURE floor (x: double_t): double_t; 
PROCEDURE rint (x: double_t): double_t; 
PROCEDURE nearbyint (x: double_t): double_t; 
PROCEDURE rinttol (x: double_t): INT32; 
PROCEDURE round (x: double_t): double_t; 
PROCEDURE roundtol (round: double_t): INT32; 
TYPE 
	_trunc_return_type = double_t;
PROCEDURE trunc (x: double_t): _trunc_return_type; 
PROCEDURE fmod (x: double_t;y: double_t): double_t; 
PROCEDURE remainder (x: double_t;y: double_t): double_t; 
PROCEDURE remquo (x: double_t;y: double_t;VAR quo: INT32): double_t; 
PROCEDURE copysign (x: double_t;y: double_t): double_t; 
PROCEDURE nan (tagp: ConstCStringPtr): LONGREAL; 
PROCEDURE nanf (tagp: ConstCStringPtr): REAL; 
PROCEDURE nextafterd (x: LONGREAL;y: LONGREAL): LONGREAL; 
PROCEDURE nextafterf (x: REAL;y: REAL): REAL; 
PROCEDURE __fpclassifyd (x: LONGREAL): INT32; 
PROCEDURE __fpclassifyf (x: REAL): INT32; 
PROCEDURE __isnormald (x: LONGREAL): INT32; 
PROCEDURE __isnormalf (x: REAL): INT32; 
PROCEDURE __isfinited (x: LONGREAL): INT32; 
PROCEDURE __isfinitef (x: REAL): INT32; 
PROCEDURE __isnand (x: LONGREAL): INT32; 
PROCEDURE __isnanf (x: REAL): INT32; 
PROCEDURE __signbitd (x: LONGREAL): INT32; 
PROCEDURE __signbitf (x: REAL): INT32; 
PROCEDURE __inf (): double_t; 
CONST 
	FP_SNAN = 0;                                                (*       signaling NaN                          *)
	FP_QNAN = 1;                                                (*       quiet NaN                              *)
	FP_INFINITE = 2;                                            (*       + or - infinity                        *)
	FP_ZERO = 3;                                                (*       + or - zero                            *)
	FP_NORMAL = 4;                                              (*       all normal numbers                     *)
	FP_SUBNORMAL = 5;                                           (*       denormal numbers                       *)

PROCEDURE fdim (x: double_t;y: double_t): double_t; 
PROCEDURE fmax (x: double_t;y: double_t): double_t; 
PROCEDURE fmin (x: double_t;y: double_t): double_t; 

PROCEDURE compound (rate: double_t;periods: double_t): double_t; 
PROCEDURE annuity (rate: double_t;periods: double_t): double_t; 
PROCEDURE randomx (VAR x: double_t): double_t; 

TYPE 
	relop = INT16;

CONST 
	GREATERTHAN = 0;
	LESSTHAN = 1;
	EQUALTO = 2;
	UNORDERED = 3;
PROCEDURE relation (x: double_t;y: double_t): relop; 

TYPE 
	fenv_t = INT32;
	fexcept_t = INT32;
    (*	    Definitions of floating-point exception macros                          	*)

CONST 
	FE_INEXACT = 02000000H;
	FE_DIVBYZERO = 04000000H;
	FE_UNDERFLOW = 08000000H;
	FE_OVERFLOW = 10000000H;
	FE_INVALID = 20000000H;
	FE_ALL_EXCEPT = 3E000000H;         (*  FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID *)

    (*	    Definitions of rounding direction macros                                	*)
	FE_TONEAREST = 00000000H;
	FE_TOWARDZERO = 00000001H;
	FE_UPWARD = 00000002H;
	FE_DOWNWARD = 00000003H;


PROCEDURE feclearexcept (excepts: INT32);
PROCEDURE fegetexcept (VAR flagp: fexcept_t;excepts: INT32);
PROCEDURE feraiseexcept (excepts: INT32);
PROCEDURE fesetexcept (<* ASSIGN (Reference, TRUE) *>flagp: fexcept_t; excepts: INT32);
PROCEDURE fetestexcept (excepts: INT32): INT32;
PROCEDURE fegetround (): INT32; 
PROCEDURE fesetround (round: INT32): INT32; 
PROCEDURE fegetenv (VAR envp: fenv_t);
PROCEDURE feholdexcept (VAR envp: fenv_t): INT32;
PROCEDURE fesetenv (<* ASSIGN (Reference, TRUE) *>envp: fenv_t); 
PROCEDURE feupdateenv (<* ASSIGN (Reference, TRUE) *>envp: fenv_t);

END FpIntf.
This module defines a lot of mathematical functions and procedures for manipulation of variables of the floating point types.

Most of the functions are originally defined in "math.h" resp. "fenv.h". Their exact meaning can be viewed in the very well documented source file "pf.DEF" that defines this functions for the Carbon interface.

3.4.7 HFSAttributes

<* ASSIGN (Foreign, TRUE) *>
<* ASSIGN (Calling, "CCalling") *>
DEFINITION MODULE HFSAttributes;

FROM SYSTEM IMPORT
	ADRCARD,
	ADDRESS,
	CARD16,
	CARD32,
	INT32;


(*
     typedef u_int32_t attrgroup_t;

     struct attrlist {
         u_short     bitmapcount; /* number of attr. bit sets in list */
         u_int16_t   reserved;    /* (to maintain 4-byte alignment) */
         attrgroup_t commonattr;  /* common attribute group */
         attrgroup_t volattr;     /* volume attribute group */
         attrgroup_t dirattr;     /* directory attribute group */
         attrgroup_t fileattr;    /* file attribute group */
         attrgroup_t forkattr;    /* fork attribute group */
     };
     #define ATTR_BIT_MAP_COUNT 5
*)

TYPE
	attrgroup_t = CARD32;
	AttrList = RECORD
		bitmapcount: CARD16;
		reserved: CARD16;
		commonattr: attrgroup_t;
		volattr: attrgroup_t;
		dirattr: attrgroup_t;
		fileattr: attrgroup_t;
		forkattr: attrgroup_t;
	END(*RECORD*);
	AttrSet = RECORD
		commonattr: attrgroup_t;
		volattr: attrgroup_t;
		dirattr: attrgroup_t;
		fileattr: attrgroup_t;
		forkattr: attrgroup_t;
	END(*RECORD*);
CONST
	ATTR_BIT_MAP_COUNT = 5;
	FSOPT_NOFOLLOW = 01H;
	FSOPT_NOINMEMUPDATE = 02H;
	FSOPT_REPORT_FULLSIZE = 03H;

CONST
	ATTR_CMN_OBJTYPE = 00000008H;
	ATTR_CMN_FNDRINFO = 00004000H;



(*
     typedef struct attrreference {
         long        attr_dataoffset;
         size_t      attr_length;
     } attrreference_t;
*)
TYPE
	AttrReference = RECORD
		attr_dataoffset: CARD32;
		attr_length: ADRCARD;
	END(*RECORD*);

(*
     typedef struct vol_attributes_attr {
         attribute_set_t validattr;
         attribute_set_t nativeattr;
     } vol_attributes_attr_t;
*)
TYPE
	VolAttributesAttr = RECORD
		validattr: AttrSet;
		nativeattr: AttrSet;
	END(*RECORD*);


(*
int	getattrlist(const char*,void*,void*,size_t,unsigned long) __DARWIN_ALIAS(getattrlist);
int	setattrlist(const char*,void*,void*,size_t,unsigned long) __DARWIN_ALIAS(setattrlist);
*)

PROCEDURE getattrlist (path: ARRAY OF CHAR; VAR attrlist: AttrList; attrBuf: ADDRESS; attrBufSize: CARD32; options: INT32): INTEGER;
PROCEDURE setattrlist (path: ARRAY OF CHAR; VAR attrlist: AttrList; attrBuf: ADDRESS; attrBufSize: CARD32; options: INT32): INTEGER;
END HFSAttributes.
This module defines procedures to access the typical attributes of HFS / HFS+ volumes and the files stored therein.

The functions are originally defined in "unistd.h", the data structures come from "sys/attr.h". A very detailled description in found in the man pages: "man getattrlist" resp. "man setattrlist".

3.4.8 ThreadStateInfo

<* ASSIGN (Foreign, TRUE) *>
DEFINITION MODULE ThreadStateInfo;

FROM SYSTEM IMPORT INT32, CARD8, CARD16, CARD32, CARD64, SET16, SET32, ADDRESS;

<* ASSIGN (Calling, "CCalling") *>

TYPE
	ThreadID = CARD32;			(* Thread identifier *)


<* IF ARCH = ppc THEN *>
CONST
	PPC_THREAD_STATE = 1;
	PPC_FLOAT_STATE = 2;
	PPC_EXCEPTION_STATE = 3;
	PPC_VECTOR_STATE = 4;
	PPC_THREAD_STATE64 = 5;
	PPC_EXCEPTION_STATE64 = 6;
	THREAD_STATE_NONE = 7;

TYPE
	THREAD_STATE = RECORD  
		SSR0: CARD32;		(* Instruction address register (PC) *)
		SSR1: CARD32;		(* Machine state register (supervisor) *)
		R0: CARD32;
		R1: CARD32;
		R2: CARD32;
		R3: CARD32;
		R4: CARD32;
		R5: CARD32;
		R6: CARD32;
		R7: CARD32;
		R8: CARD32;
		R9: CARD32;
		R10: CARD32;
		R11: CARD32;
		R12: CARD32;
		R13: CARD32;
		R14: CARD32;
		R15: CARD32;
		R16: CARD32;
		R17: CARD32;
		R18: CARD32;
		R19: CARD32;
		R20: CARD32;
		R21: CARD32;
		R22: CARD32;
		R23: CARD32;
		R24: CARD32;
		R25: CARD32;
		R26: CARD32;
		R27: CARD32;
		R28: CARD32;
		R29: CARD32;
		R30: CARD32;
		R31: CARD32;

		CR: CARD32;			(* Condition register *)
		XER: CARD32;		(* User's integer exception register *)
		LR: CARD32;			(* Link register *)
		CTR: CARD32;		(* Count register *)
		MQ: CARD32;			(* MQ register (601 only) *)

		VRSAVE: CARD32;		(* Vector Save Register *)
	END;

	FLOAT_STATE = RECORD  
		Registers: ARRAY  [0..31] OF LONGREAL;
		Reserved: CARD32;	(* fpscr is 64 bits, 32 bits of rubbish *)
		FPSCR: CARD32;		(* floating point status register *)
	END;

	VECTOR_STATE = RECORD  
		Registers: ARRAY  [0..31] OF ARRAY [0 .. 3] OF CARD32;
		VSCR: ARRAY [0 .. 3] OF CARD32;
		Pad1: ARRAY [0 .. 3] OF CARD32;
		VRVALID: CARD32;	(* VRs that have been saved *)
		Pad2: ARRAY [0 .. 6] OF CARD32;
	END;

	EXCEPTION_STATE = RECORD  
		DAR: CARD32;
		DSISR: CARD32;
		Exception: CARD32;
		Pad1: CARD32;
		Pad2: ARRAY [0 .. 3] OF CARD32;
	END;
<* ELSIF ARCH = i386 THEN *>
CONST
	x86_THREAD_STATE32 = 1;
	x86_FLOAT_STATE32 = 2;
	x86_EXCEPTION_STATE32 = 3;
	x86_THREAD_STATE64 = 4;
	x86_FLOAT_STATE64 = 5;
	x86_EXCEPTION_STATE64 = 6;
	x86_THREAD_STATE = 7;
	x86_FLOAT_STATE = 8;
	x86_EXCEPTION_STATE = 9;
	x86_DEBUG_STATE32 = 10;
	x86_DEBUG_STATE64 = 11;
	x86_DEBUG_STATE = 12;
	THREAD_STATE_NONE = 13;

TYPE
	THREAD_STATE = RECORD  
		EAX: CARD32;
		EBX: CARD32;
		ECX: CARD32;
		EDX: CARD32;
		ESI: CARD32;
		EDI: CARD32;
		EBP: CARD32;
		ESP: CARD32;
		SS: CARD32;
		EFLAGS: CARD32;
		EIP: CARD32;
		CS: CARD32;
		DS: CARD32;
		ES: CARD32;
		FS: CARD32;
		GS: CARD32;
	END;

	FLOAT_STATE = RECORD  
		FPU_FCW: SET16;			(* x87 FPU control word *)
		FPU_FSW: SET16;			(* x87 FPU status word *)
		FPU_FTW: CARD8;			(* x87 FPU tag word *)
		FPU_RSRV1: CARD8;		(* reserved *)
		FPU_FOP: CARD16;		(* x87 FPU Opcode *)
		FPU_IP: CARD32;			(* x87 FPU Instruction Pointer offset *)
		FPU_CS: CARD16;			(* x87 FPU Instruction Pointer Selector *)
		FPU_RSRV2: CARD16;		(* reserved *)
		FPU_DP: CARD32;			(* x87 FPU Instruction Operand(Data) Pointer offset *)
		FPU_SS: CARD16;			(* x87 FPU Instruction Operand(Data) Pointer Selector *)
		FPU_RSRV3: CARD16;		(* reserved *)
		FPU_MXCSR: CARD32;		(* MXCSR Register state *)
		FPU_MXCSRMASK: CARD32;	(* MXCSR mask *)
		FPUSTMMO: ARRAY [0 .. 16] OF CHAR;	(* ST0/MM0 *)
		FPUSTMM1: ARRAY [0 .. 16] OF CHAR;	(* ST1/MM1 *)
		FPUSTMM2: ARRAY [0 .. 16] OF CHAR;	(* ST2/MM2 *)
		FPUSTMM3: ARRAY [0 .. 16] OF CHAR;	(* ST3/MM3 *)
		FPUSTMM4: ARRAY [0 .. 16] OF CHAR;	(* ST4/MM4 *)
		FPUSTMM5: ARRAY [0 .. 16] OF CHAR;	(* ST5/MM5 *)
		FPUSTMM6: ARRAY [0 .. 16] OF CHAR;	(* ST6/MM6 *)
		FPUSTMM7: ARRAY [0 .. 16] OF CHAR;	(* ST7/MM7 *)
		FPUXMMO: ARRAY [0 .. 16] OF CHAR;	(* XMM0 *)
		FPUXMM1: ARRAY [0 .. 16] OF CHAR;	(* XMM1 *)
		FPUXMM2: ARRAY [0 .. 16] OF CHAR;	(* XMM2 *)
		FPUXMM3: ARRAY [0 .. 16] OF CHAR;	(* XMM3 *)
		FPUXMM4: ARRAY [0 .. 16] OF CHAR;	(* XMM4 *)
		FPUXMM5: ARRAY [0 .. 16] OF CHAR;	(* XMM5 *)
		FPUXMM6: ARRAY [0 .. 16] OF CHAR;	(* XMM6 *)
		FPUXMM7: ARRAY [0 .. 16] OF CHAR;	(* XMM7 *)
		reserved : ARRAY [0 .. 14*16-1] OF CHAR;
		reserved2: INT32;
	END;

	EXCEPTION_STATE = RECORD  
		TRAPNO: CARD32;
		ERR: CARD32;
		FAULTVADDR: CARD32;
	END;

	DEBUG_STATE = RECORD  
		DR0: CARD32;
		DR1: CARD32;
		DR2: CARD32;
		DR3: CARD32;
		DR4: CARD32;
		DR5: CARD32;
		DR6: CARD32;
		DR7: CARD32;
	END;
<* ELSIF ARCH = x86 THEN *>
CONST
	x86_THREAD_STATE32 = 1;
	x86_FLOAT_STATE32 = 2;
	x86_EXCEPTION_STATE32 = 3;
	x86_THREAD_STATE64 = 4;
	x86_FLOAT_STATE64 = 5;
	x86_EXCEPTION_STATE64 = 6;
	x86_THREAD_STATE = 7;
	x86_FLOAT_STATE = 8;
	x86_EXCEPTION_STATE = 9;
	x86_DEBUG_STATE32 = 10;
	x86_DEBUG_STATE64 = 11;
	x86_DEBUG_STATE = 12;
	THREAD_STATE_NONE = 13;

TYPE
	THREAD_STATE = RECORD  
		RAX: CARD64;
		RBX: CARD64;
		RCX: CARD64;
		RDX: CARD64;
		RSI: CARD64;
		RDI: CARD64;
		RBP: CARD64;
		RSP: CARD64;
		R08: CARD64;
		R09: CARD64;
		R10: CARD64;
		R11: CARD64;
		R12: CARD64;
		R13: CARD64;
		R14: CARD64;
		R15: CARD64;
		RIP: CARD64;
		RFLAGS: CARD64;
		CS: CARD64;
		FS: CARD64;
		GS: CARD64;
	END;

	FLOAT_STATE = RECORD  
		reserved1: ARRAY [0 .. 1] OF CARD32;
		FPU_FCW: SET16;			(* x87 FPU control word *)
		FPU_FSW: SET16;			(* x87 FPU status word *)
		FPU_FTW: CARD8;			(* x87 FPU tag word *)
		FPU_RSRV1: CARD8;		(* reserved *)
		FPU_FOP: CARD16;		(* x87 FPU Opcode *)
		FPU_IP: CARD32;			(* x87 FPU Instruction Pointer offset *)
		FPU_CS: CARD16;			(* x87 FPU Instruction Pointer Selector *)
		FPU_RSRV2: CARD16;		(* reserved *)
		FPU_DP: CARD32;			(* x87 FPU Instruction Operand(Data) Pointer offset *)
		FPU_SS: CARD16;			(* x87 FPU Instruction Operand(Data) Pointer Selector *)
		FPU_RSRV3: CARD16;		(* reserved *)
		FPU_MXCSR: SET32;		(* MXCSR Register state *)
		FPU_MXCSRMASK: SET32;	(* MXCSR mask *)
		FPUSTMMO: ARRAY [0 .. 16] OF CHAR;	(* ST0/MM0 *)
		FPUSTMM1: ARRAY [0 .. 16] OF CHAR;	(* ST1/MM1 *)
		FPUSTMM2: ARRAY [0 .. 16] OF CHAR;	(* ST2/MM2 *)
		FPUSTMM3: ARRAY [0 .. 16] OF CHAR;	(* ST3/MM3 *)
		FPUSTMM4: ARRAY [0 .. 16] OF CHAR;	(* ST4/MM4 *)
		FPUSTMM5: ARRAY [0 .. 16] OF CHAR;	(* ST5/MM5 *)
		FPUSTMM6: ARRAY [0 .. 16] OF CHAR;	(* ST6/MM6 *)
		FPUSTMM7: ARRAY [0 .. 16] OF CHAR;	(* ST7/MM7 *)
		FPUXMMO: ARRAY [0 .. 16] OF CHAR;	(* XMM0 *)
		FPUXMM1: ARRAY [0 .. 16] OF CHAR;	(* XMM1 *)
		FPUXMM2: ARRAY [0 .. 16] OF CHAR;	(* XMM2 *)
		FPUXMM3: ARRAY [0 .. 16] OF CHAR;	(* XMM3 *)
		FPUXMM4: ARRAY [0 .. 16] OF CHAR;	(* XMM4 *)
		FPUXMM5: ARRAY [0 .. 16] OF CHAR;	(* XMM5 *)
		FPUXMM6: ARRAY [0 .. 16] OF CHAR;	(* XMM6 *)
		FPUXMM7: ARRAY [0 .. 16] OF CHAR;	(* XMM7 *)
		FPUXMM8: ARRAY [0 .. 16] OF CHAR;	(* XMM8 *)
		FPUXMM9: ARRAY [0 .. 16] OF CHAR;	(* XMM9 *)
		FPUXMM10: ARRAY [0 .. 16] OF CHAR;	(* XMM10 *)
		FPUXMM11: ARRAY [0 .. 16] OF CHAR;	(* XMM11 *)
		FPUXMM12: ARRAY [0 .. 16] OF CHAR;	(* XMM12 *)
		FPUXMM13: ARRAY [0 .. 16] OF CHAR;	(* XMM13 *)
		FPUXMM14: ARRAY [0 .. 16] OF CHAR;	(* XMM14 *)
		FPUXMM15: ARRAY [0 .. 16] OF CHAR;	(* XMM15 *)
		reserved2 : ARRAY [0 .. 14*16-1] OF CHAR;
		reserved3: INT32;
	END;

	EXCEPTION_STATE = RECORD  
		TRAPNO: CARD32;
		ERR: CARD32;
		FAULTVADDR: CARD64;
	END;

	DEBUG_STATE = RECORD  
		DR0: CARD64;
		DR1: CARD64;
		DR2: CARD64;
		DR3: CARD64;
		DR4: CARD64;
		DR5: CARD64;
		DR6: CARD64;
		DR7: CARD64;
	END;
<* END *>

(* ID des eigenen Threads *)
PROCEDURE mach_thread_self (): ThreadID;

(* StatusInformation, old_stateCnt muss beim Aufruf den freien Platz anzeigen (in 4-Byte-Worten) *)
PROCEDURE thread_get_state (target_act: ThreadID; flavour: INT32; old_state: ADDRESS; VAR old_stateCnt: CARDINAL): INTEGER; 

END ThreadStateInfo.

This module gives access to the state of a thread. This information is also available through the machine context pointer passed as part of the user context parameter of a signal handler.

"mach_thread_self" returns the id of the current thread.
"thread_get_state" returns information about the given thread. Possible values for flavour are given in the defined constants. On call old_stateCnt contains the available space as word count; on return it contains the actual size of the answer (also counted as four byte words).

3.4.9 Signal

<* ASSIGN (Foreign, TRUE) *>
<* ASSIGN (Calling, "CCalling") *>
DEFINITION MODULE Signal;

FROM ThreadStateInfo IMPORT EXCEPTION_STATE, THREAD_STATE, FLOAT_STATE <* IF ARCH = ppc THEN *>, VECTOR_STATE <* END *>;
FROM SYSTEM IMPORT INT32, CARD32, ADDRESS, CAST;

CONST
	SIGHUP		= 1;	(* hangup *)
	SIGINT		= 2;	(* interrupt *)
	SIGQUIT		= 3;	(* quit *)
	SIGILL		= 4;	(* illegal instruction (not reset when caught) *)
	SIGTRAP		= 5;	(* trace trap (not reset when caught) *)
	SIGABRT		= 6;	(* abort() *)
	SIGIOT	= SIGABRT;	(* compatibility *)
	SIGEMT		= 7;	(* EMT instruction *)
	SIGFPE		= 8;	(* floating point exception *)
	SIGKILL		= 9;	(* kill (cannot be caught or ignored) *)
	SIGBUS		= 10;	(* bus error *)
	SIGSEGV		= 11;	(* segmentation violation *)
	SIGSYS		= 12;	(* bad argument to system call *)
	SIGPIPE		= 13;	(* write on a pipe with no one to read it *)
	SIGALRM		= 14;	(* alarm clock *)
	SIGTERM		= 15;	(* software termination signal from kill *)
	SIGURG		= 16;	(* urgent condition on IO channel *)
	SIGSTOP		= 17;	(* sendable stop signal not from tty *)
	SIGTSTP		= 18;	(* stop signal from tty *)
	SIGCONT		= 19;	(* continue a stopped process *)
	SIGCHLD		= 20;	(* to parent on child stop or exit *)
	SIGTTIN		= 21;	(* to readers pgrp upon background tty read *)
	SIGTTOU		= 22;	(* like TTIN for output if (tp->t_local&LTOSTOP) *)
	SIGIO		= 23;	(* input/output possible signal *)
	SIGXCPU		= 24;	(* exceeded CPU time limit *)
	SIGXFSZ		= 25;	(* exceeded file size limit *)
	SIGVTALRM	= 26;	(* virtual time alarm *)
	SIGPROF		= 27;	(* profiling time alarm *)
	SIGWINCH	= 28;	(* window size changes *)
	SIGINFO		= 29;	(* information request *)
	SIGUSR1		= 30;	(* user defined signal 1 *)
	SIGUSR2		= 31;	(* user defined signal 2 *)

TYPE
	SigProc = PROCEDURE (INTEGER, SigInfoPtr, UserContextPtr);		(* new style signal handler *)
	SigSet = SET OF [0 .. 31];
	SigSetPtr = POINTER TO SigSet;
	SigInfoPtr = POINTER TO SigInfo;
	SigContextPtr = POINTER TO SigContext;

	SigContext = RECORD
		sc_onstack: INT32;	(* sigstack state to restore *)
		sc_mask: INT32;		(* signal mask to restore *)
		sc_ir: INT32;		(* pc *)
		sc_psw: INT32;		(* processor status word *)
		sc_sp: INT32;		(* stack pointer if sc_regs = NIL *)
		sc_regs: ADDRESS;	(* (kernel private) saved state *)
	END(*RECORD*);

	SigInfo = RECORD
		si_signo: INT32;		(* signal number *)
		si_errno: INT32;		(* errno association *)
		si_code: INT32;			(* signal code *)
		si_pid: INT32;			(* sending process *)
		si_uid: CARD32;			(* sender's ruid *)
		si_status: INT32;		(* exit value *)
		si_addr: ADDRESS;		(* faulting instruction *)
		CASE :BOOLEAN OF		(* signal value *)
		  TRUE:
			sigval_int: INT32;
		| FALSE:
			sigval_ptr: ADDRESS;
		END(*CASE*);
		si_band: INTEGER;		(* band event for SIGPOLL *)
		pad: ARRAY [0 .. 7] OF INT32;	(* Reserved for Future Use *)
	END(*RECORD*);

(* 
 * Incase of SIGILL and SIGFPE, si_addr contains the address of 
 *  faulting instruction.
 * Incase of SIGSEGV and SIGBUS, si_addr contains address of 
 *  faulting memory reference.
 * Incase of SIGCHLD, si_pid willhave child process ID,
 *  si_status will contain exit value or signal.
 *  si_uid contains real user ID of the process that sent the signal
 *)

CONST
	SIG_DFL = CAST (SigProc, 0);
	SIG_IGN = CAST (SigProc, 1);
	SIG_ERR = CAST (SigProc, -1);

(* Values for si_code *)

(* Codes for SIGILL *)
	ILL_NOOP	= 0;	(* if only I knew... *)
	ILL_ILLOPC	= 1;	(* illegal opcode *)
	ILL_ILLTRP	= 2;	(* illegal trap *)
	ILL_PRVOPC	= 3;	(* privileged opcode *)

(* Codes for SIGFPE *)
	FPE_NOOP	= 0;	(* if only I knew... *)
	FPE_FLTDIV	= 1;	(* floating point divide by zero *)
	FPE_FLTOVF	= 2;	(* floating point overflow *)
	FPE_FLTUND	= 3;	(* floating point underflow *)
	FPE_FLTRES	= 4;	(* floating point inexact result *)
	FPE_FLTINV	= 5;	(* invalid floating point operation *)

(* Codes for SIGSEGV *)
	SEGV_NOOP	= 0;	(* if only I knew... *)
	SEGV_MAPERR	= 1;	(* address not mapped to object *)
	SEGV_ACCERR	= 2;	(* invalid permissions for mapped to object *)

(* Codes for SIGBUS *)
	BUS_NOOP	= 0;	(* if only I knew... *)
	BUS_ADRALN	= 1;	(* invalid address alignment *)

(* Codes for SIGCHLD *)
	CLD_NOOP	= 0;	(* if only I knew... *)
	CLD_EXITED	= 1;	(* child has exited *)
	CLD_KILLED	= 2;	(* child has terminated abnormally and did not create a core file *)
	CLD_DUMPED	= 3;	(* child has terminated abnormally and create a core file *)
	CLD_TRAPPED	= 4;	(* traced child has trapped *)
	CLD_STOPPED	= 5;	(* child has stopped *)
	CLD_CONTINUED	= 6;	(* stopped child has continued *)


TYPE
	
	SigActionPtr = POINTER TO SigAction;
	SigAction = RECORD
		sa_sigaction: SigProc;  (* signal handler *)
		sa_mask: SigSet;		(* signal mask to apply *)
		sa_flags: INT32;		(* see signal options below *)
	END(*RECORD*);

CONST
	SA_ONSTACK		= 00001H;	(* take signal on signal stack *)
	SA_RESTART		= 00002H;	(* restart system on signal return *)
	SA_DISABLE		= 00004H;	(* disable taking signals on alternate stack *)
	SA_RESETHAND	= 00004H;	(* reset to SIG_DFL when taking signal *)
	SA_NODEFER		= 00010H;	(* don't mask the signal we're delivering *)
	SA_NOCLDWAIT	= 00020H;	(* don't keep zombies around *)
	SA_SIGINFO		= 00040H;	(* signal handler with SA_SIGINFO args *)
	SA_USERTRAMP	= 00100H;	(* do not bounce off kernel's sigtramp *)
	SA_64REGSET		= 00200H;	(* signal handler with SA_SIGINFO args with 64bit regs information *)
	SA_NOCLDSTOP	= 00008H;	(* do not generate SIGCHLD on child stop *)

(*
 * Flags for sigprocmask:
 *)
	SIG_BLOCK	= 1;	(* block specified signal set *)
	SIG_UNBLOCK	= 2;	(* unblock specified signal set *)
	SIG_SETMASK	= 3;	(* set specified signal set *)

(* POSIX 1003.1b required values. *)
	SI_USER		= 010001H;
	SI_QUEUE	= 010002H;
	SI_TIMER	= 010003H;
	SI_ASYNCIO	= 010004H;
	SI_MESGQ	= 010005H;

(*
 * Structure used in sigaltstack call.
 *)
TYPE
	SigAltStack = RECORD
		ss_sp: ADDRESS;		(* signal stack base *)
		ss_size: INT32;		(* signal stack length *)
		ss_flags: INT32;	(* SA_DISABLE and/or SA_ONSTACK *)
	END(*RECORD*);

CONST
	SS_ONSTACK	= 00001H;	(* take signal on signal stack *)
	SS_DISABLE	= 00004H;	(* disable taking signals on alternate stack *)
	MINSIGSTKSZ	= 32768;	(* (32K)minimum allowable stack *)
	SIGSTKSZ	= 131072;	(* (128K)recommended stack size *)

TYPE
	MaschineContextPtr = POINTER TO MachineContext;
	UserContextPtr = POINTER TO UserContext;
	UserContext = RECORD
		uc_onstack: INT32;
		uc_sigmask: CARD32;			(* signal mask used by this context *)
		uc_stack: SigAltStack;		(* stack used by this context *)
		uc_link: UserContextPtr;	(* pointer to resuming context *)
		uc_mcsize: CARD32;			(* size of the machine context passed in *)
		uc_mcontext: MaschineContextPtr;	(* pointer to machine specific context *)
	END(*RECORD*);

	MachineContext = RECORD
		es: EXCEPTION_STATE;
		ss: THREAD_STATE;
		fs: FLOAT_STATE;
		<* IF ARCH = ppc THEN *>
		vs: VECTOR_STATE;
		<* END *>
	END(*RECORD*);


PROCEDURE raise (param: INT32): INT32;

PROCEDURE sigaction (signal: INT32; <* ASSIGN (Reference, TRUE) *>action: SigAction; oldAction: SigActionPtr): INT32;

PROCEDURE sigprocmask (how: INT32; newSet: SigSetPtr; oldSet: SigSetPtr): INT32;

END Signal.
This module defines procedures to handle signals. Please keep in mind that the p1 runtime defines handlers for most of the typical signals. So if you define signal handlers of your own, you might eventually switch off the exception mechanism of Modula-2.

The functions are originally defined in "signal.h". A description is found in the man pages.
chapter 2 (library) start page table of contents (utilities)