UnixSysCallExtensions.mesa
Copyright Ó 1988, 1989, 1991, 1992 by Xerox Corporation. All rights reserved.
Christian Jacobi, January 24, 1991 5:30 pm PST
Demers, November 10, 1988 10:03:09 am PST
Carl Hauser, December 8, 1988 12:56:08 pm PST
Michael Plass, August 13, 1991 12:56 pm PDT
DIRECTORY
UnixTypes USING [CHARPtr, FD, FileFlags, IPCCtlCmd, Mode, RawVM, RES, SharedMemoryIdentifier, ShmIdDs, SockAddr, SockAddrPtr];
UnixSysCallExtensions: CEDAR DEFINITIONS
~ { OPEN UnixTypes;
Non-Unix-like I/O
FDKind: TYPE ~ MACHINE DEPENDENT {
std(0),  -- file system, socket
stream(1),  -- System V stream
error (CARD.LAST)
};
These specialized open procedures are more efficient than UnixSysCalls.Open when the kind of fd desired is known. UnixSysCalls.Open figures it out from the path.
Open4: PROC [path: CHARPtr, flags: FileFlags, mode: Mode, kind: FDKind] RETURNS [FD];
The general form.
OpenStd: PROC [path: CHARPtr, flags: FileFlags, mode: Mode] RETURNS [FD] ~ INLINE {
RETURN [Open4[path, flags, mode, std]];
};
Form to use when files and sockets are being opened.
OpenStream: PROC [path: CHARPtr, flags: FileFlags, mode: Mode] RETURNS [FD] ~ INLINE {
RETURN [Open4[path, flags, mode, stream]];
};
Form to use when stream is being opened.
GetDescriptorKind: PROC [d: FD] RETURNS [FDKind];
GetDTableSize1: PROC [kind: FDKind] RETURNS [INT];
Like GetDTableSize, but, in fact, there is a separate pool of descriptors for each FDKind.
ExpandPath: PROC [path: CHARPtr] RETURNS [CHARPtr];
Expand path to full path name by prepending PCR working directory if necessary.
The result either is identical to the argument (equal pointers) or is heap-allocated.
GetNumberOfFreeFDs: PROC [kind: FDKind] RETURNS [INT];
Get the number of available descriptor slots of the specified kind.
NonBlocking I/O
BlockingMode: TYPE ~ MACHINE DEPENDENT {
someData(0), -- until eof/eom or > 0 bytes delivered
allData(1),  -- until eof/eom or all requested data delivered
never(2),  -- never
(CARD.LAST)
};
SetGetBlocking: PROC [s: FD, blocking: BlockingMode] RETURNS [RES];
Set "blocking mode" associated with descriptor.
GetGetBlocking: PROC [s: FD] RETURNS [BlockingMode];
Get input blocking behavior of descriptor.
SetPutBlocking: PROC [s: FD, blocking: BlockingMode] RETURNS [RES];
Set "blocking mode" associated with descriptor.
GetPutBlocking: PROC [s: FD] RETURNS [BlockingMode];
Get input blocking behavior of descriptor.
Timeouts
waitForever: CARD ~ 0;
SetGetTimeout: PROC [s: FD, timeoutMsec: CARD ¬ waitForever] RETURNS [RES];
Set "get timeout" associated with descriptor, if any.
GetGetTimeout: PROC [s: FD] RETURNS [CARD];
Return get timeout of descriptor, or CARD.LAST on error.
SetPutTimeout: PROC [s: FD, timeoutMsec: CARD ¬ waitForever] RETURNS [RES];
Set "put timeout" associated with descriptor, if any.
GetPutTimeout: PROC [s: FD] RETURNS [CARD];
Return put timeout of descriptor, or CARD.LAST on error.
Unix command access
Spawn: PROC [cmd, stdin, stdout, stderr: CHARPtr] RETURNS [INT];
fork a (Unix) process to run cmd, attaching its standard input, output and error file descriptors to the files named by stdin, stdout, stderr. n.b. the files may be named pipes.
The returned value is the exit status of the spawned process or -1 for failure.
CDSpawn: PROC [cmd, wd, stdin, stdout, stderr: CHARPtr]
RETURNS
[INT];
fork a (Unix) process to run cmd in working directory wd, attaching its standard input, output and error file descriptors to the files named by stdin, stdout, stderr. n.b. the files may be named pipes.
The returned value is the exit status of the spawned process or -1 for failure.
PPOpen: PROC [cmd: CHARPtr] RETURNS [FD];
Fork off a Unix(tm) process running cmd.
Return a fildes connected to the cmd's stdin/stdout, or FD.error on failure.
RExec2: PROC [host: SockAddrPtr, port: CARD, user: CHARPtr, passwd: CHARPtr, cmd: CHARPtr, errbuf: CHARPtr, errbufbytes: INT ¬ 0] RETURNS [FD];
UnixTM remote exec protocol.
If host = NIL, use localhost.
If host does not specify a port, and the port argument is nonzero, use it.
If connection to remote host fails, return error with code available using UnixErrno.GetErrno
Use the user and passwd arguments to authenticate to remote host.
If authentication fails,
return error with errno == ENOEXEC and store error message in *errbuf.
Execute cmd on remote host.
If command initiation fails
return error with errno == ENOEXEC and store error message in *errbuf.
If command initiation succeeds
return fildes connected cmd's stdin/stdout.
It is permissible to pass errbuf == NIL, in which case error output is discarded.
Virtual memory allocation
VMReserve: PROC [nbytes: CARD] RETURNS [address: RawVM];
Returns page aligned address to virtual address space segment at least nbytes long. This is a good address to use with the MMap and ShmAt system calls.
Termination cleanup aids
UNTHREADEDShmCtl: UNSAFE PROC [shmId: SharedMemoryIdentifier, cmd: IPCCtlCmd, buf: POINTER TO ShmIdDs] RETURNS [RES];
UNTHREADEDShmCtl must not be used by normal Cedar code but only by a registered cleanup procedure from a Unix process.
It is needed for returning allocated segments when the process dies.
RegisterUNTHREADEDTerminationCleanupProc: UNSAFE PROC [cleanup: PROC [REF], data: REF ¬ NIL] RETURNS [RES];
Register a cleanup proc to be called automatically just before PCR terminates. The cleanup proc is called from a Unix process rather than a thread -- it should do native Unix system calls and avoid thread operations such as entering monitors.
RegisterUNTHREADEDTerminationCleanupProc is not a Unix shared memory feature, but it is always necessary to provide cleanup when using Unix shared memory..
}.
CHauser: February 22, 1989: added Open4 and friends.
Plass, August 6, 1991: Replaced SetBlocking with SetGetBlocking and SetPutBlocking; merged CDSpawn from the extras interface, added PPOpen, RExec2