/* begincopyright Copyright (c) 1988 Xerox Corporation. All rights reserved. Use and copying of this software and preparation of derivative works based upon this software are permitted. Any distribution of this software or derivative works must comply with all applicable United States export control laws. This software is made available AS IS, and Xerox Corporation makes no warranty about the software, its performance or its conformity to any specification. Any person obtaining a copy of this software is requested to send their name and post office or electronic mail address to: PCR Coordinator Xerox PARC 3333 Coyote Hill Rd. Palo Alto, CA 94304 endcopyright */ /* * UIO.h * * * Public definitions for Unix I/O interface * for Xerox Runtime threads package. * * Demers, December 13, 1990 11:56:59 am PST * * Nearly every procedure here is a clone of a Unix I/O system call. * See Section 2 of the UPM for documentation. * * These are "exported" to UnixSysCalls.mesa and UnixSysCallExtensions.mesa */ #ifndef ←XR←UIO← #define ←XR←UIO← 1 #ifndef ←XR←THREADS← # include "Threads.h" #endif #include <sys/types.h> #include <sys/file.h> #include <sys/stat.h> /* #include <sys/vfs.h> -- breaks if included multiple times, sigh! */ /* * The macros XR←SYSCALL and XR←SYSCALLX below facilitate automatic * generation of assembly-language stubs for system call name * translation. * * Example: * * extern int * XR←SYSCALL(Read,read) * (/ * fildes, buf, nbytes * /); * * declares int proc XR←Read as a synonym for Unix read. * * WARNING: don't put spaces after the comma ... Sun's cpp is too stupid to * strip leading spaces from its arguments. */ #ifdef ←←STDC←← # define XR←SYSCALL(pcrName,unixName) XR←##pcrName # define XR←SYSCALLX(pcrName) XR←##pcrName #else # define XR←SYSCALL(pcrName,unixName) XR←/**/pcrName # define XR←SYSCALLX(pcrName) XR←/**/pcrName #endif /* * Descriptors */ typedef int XR←Fildes; #define XR←nullFildes ((XR←Fildes)(-1)) /* * * Non-Unix-like I/O * */ typedef unsigned XR←FDKind; # define XR←FD←KIND←STD ((XR←FDKind)(0)) /* file system, socket */ # define XR←FD←KIND←STREAM ((XR←FDKind)(1)) /* System V stream */ # define XR←FD←KIND←LAST ((XR←FDKind)(1)) typedef int XR←UIOBlocking; #define XR←UIO←BLOCKING←SOME←DATA 0 /* block until eof/eom or > 0 bytes delivered */ #define XR←UIO←BLOCKING←ALL←DATA 1 /* block until eof/eom or all requested data delivered */ #define XR←UIO←BLOCKING←NEVER 2 /* never block */ #define XR←UIO←BLOCKING←ERROR -1 /* the following are obsolete */ extern int XR←SYSCALLX(SetBlocking) (/* fildes, blocking */); /* XR←Fildes fildes; XR←UIOBlocking blocking; Set blocking behavior of descriptor. */ extern int XR←SYSCALLX(GetBlocking) (/* fildes */); /* XR←Fildes fildes; Return blocking behavior of descriptor, or (-1) on error. */ extern int XR←SYSCALLX(SetGetBlocking) (/* XR←Fildes fildes, XR←UIOBlocking blocking */); /* Set input blocking behavior of descriptor. */ extern XR←UIOBlocking XR←SYSCALLX(GetGetBlocking) (/* XR←Fildes fildes */); /* Get input blocking behavior of descriptor, or (-1) on error. */ extern int XR←SYSCALLX(SetPutBlocking) (/* XR←Fildes fildes, XR←UIOBlocking blocking */); /* Set output blocking behavior of descriptor. */ extern XR←UIOBlocking XR←SYSCALLX(GetPutBlocking) (/* XR←Fildes fildes */); /* Get output blocking behavior of descriptor, or (-1) on error. */ #define XR←WAIT←FOREVER←MSEC 0x0 extern int XR←SYSCALLX(SetGetTimeout) (/* fildes, timeoutMsec */); /* XR←Fildes fildes; unsigned timeoutMsec; Set get timeout of descriptors with this capability (e.g. TCP, UDP sockets). */ extern int XR←SYSCALLX(GetGetTimeout) (/* fildes */); /* XR←Fildes fildes; unsigned timeoutMsec; Return get timeout of descriptor, or (-1) on error. */ extern int XR←SYSCALLX(SetPutTimeout) (/* fildes, timeoutMsec */); /* XR←Fildes fildes; unsigned timeoutMsec; Set put timeout of descriptors with this capability (e.g. TCP sockets). */ extern int XR←SYSCALLX(GetPutTimeout) (/* fildes */); /* XR←Fildes fildes; unsigned timeoutMsec; Return put timeout of descriptor, or (-1) on error. */ extern int XR←SYSCALLX(Open4) (/* name, flags, mode, kind */); extern int XR←SYSCALLX(OpenStd) (/* name, flags, mode */); extern int XR←SYSCALLX(OpenStream) (/* name, flags, mode */); /* char *name; unsigned flags; unsigned mode; XR←FDKind kind; Each of the above procs is a version of open. On success, the result is a descriptor that is of the (implicitly- or explicitly-) specified kind. On failure the result is -1, with errno set appropriately. A descriptor-kind error will cause errno to be set to ENOSTR. */ extern char * XR←SYSCALLX(ExpandPath) (/* char *path */); /* 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. */ extern XR←FDKind XR←SYSCALLX(GetDescriptorKind) (/* fildes */); /* XR←Fildes fildes; Result is kind of descriptor, or -1 on error. */ extern int XR←SYSCALLX(GetDTableSize1) (/* kind */); /* XR←FDKind kind; Get the number of descriptor slots of the specified kind. Note: XR←GetDTableSize() returns the sum of XR←GetDTableSize1(kind) for all valid kind values. */ extern int XR←SYSCALLX(GetNumberOfFreeFDs) (/* kind */); /* XR←FDKind kind; Get the number of available descriptor slots of the specified kind. */ extern int XR←SYSCALLX(Spawn) (/* cmd, stdin, stdout, stderr */); /* char *cmd; char *stdin; char *stdout; char *stderr; Result is completion status of child (possibly <sysexits.h>.EX←DATAERR, EX←OSERR, ...) or -1 on failure. */ extern int XR←SYSCALLX(CDSpawn) (/* cmd, wd, stdin, stdout, stderr */); /* char *cmd; char *wd; char *stdin; char *stdout; char *stderr; Result is completion status of child (possibly <sysexits.h>.EX←DATAERR, EX←OSERR, ...) or -1 on failure. */ extern XR←Fildes XR←SYSCALLX(PPOpen) (/* cmd */); /* char *cmd; Fork off a Unix(tm) process running cmd. Return a fildes connected to the cmd's stdin/stdout, or -1 on failure. NOTE: This should probably be eliminated in favor of PPPOpen, below. */ extern int XR←SYSCALLX(PPPOpen) (/* fdp, separate, cmd */); /* XR←Fildes fdp[2]; bool separate; char *cmd; Fork off a Unix(tm) process running cmd. Store file descriptors for command's stdout and stderr in fdp[0] and fdp[1], respectively. Return -1 on failure. */ extern XR←Fildes XR←SYSCALLX(RExec2) (/* host, port, user, passwd, cmd, errbuf, errbufbytes */); /* struct sockaddr *host; unsigned port; char *user; char *passwd; char *cmd; char *errbuf; int errbufbytes; Unix(tm) 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 (-1) with code available using XR←GetErrno() Use the user and passwd arguments to authenticate to remote host. If authentication fails, return (-1) with errno == ENOEXEC and store error message in *errbuf. Execute cmd on remote host. If command initiation fails return (-1) with errno == ENOEXEC and store error message in *errbuf. If remote host does not know about the local host (i.e. first read from socket returns EOF), return (-1) with errno == ECONNREFUSED. If command initiation succeeds return fildes connected cmd's stdin/stdout. It is permissible to pass errbuf == NIL, in which case RExec2 behaves like RExec, below. */ extern XR←Fildes XR←SYSCALLX(RExec) (/* host, port, user, passwd, cmd */); /* struct sockaddr *host; unsigned port; char *user; char *passwd; char *cmd; Unix(tm) remote exec protocol. If host == NIL, use localhost. If host does not specify a port, and the port argument is nonzero, use it. Use the user and passwd arguments to authenticate to remote host. If that succeeds, execute cmd on remote host. Return a fildes connected to cmd's stdin/stdout, or -1 on failure. OBSOLESCENT: implemented by XR←RExec2(host, port, user, passwd, cmd, NIL) */ /* * * Unix-like descriptor I/O * */ extern int XR←SYSCALL(Access,access) (/* path, mode */); /* char *path; int mode; */ extern int XR←SYSCALL(ChMod,chmod) (/* name, mode */); /* char *name; int mode; */ extern int XR←SYSCALL(FChMod,fchmod) (/* fildes, mode */); /* XR←Fildes fildes; int mode; */ extern int XR←SYSCALL(Close,close) (/* fildes */); /* XR←Fildes fildes; */ extern int XR←SYSCALL(FSync,fsync) (/* fildes */); /* XR←Fildes fildes; */ extern int XR←SYSCALL(FCntl,fcntl) (/* fildes, cmd, arg */); /* XR←Fildes fildes; int cmd; int arg; */ extern int XR←SYSCALLX(FCntl4) (/* fildes, cmd, arg, doInIOP */); /* XR←Fildes fildes; int cmd; int arg; bool doInIOP; Caller controls whether fcntl is done in vp or iop. The Unix-style entry FCntl always does the fcntl call in the vp, which in some cases is inappropriate. */ extern int XR←SYSCALL(GetDEnts,getdents) (/* fildes, buf, nbytes */); /* XR←Fildes fildes; char *buf; int nbytes; */ extern int XR←SYSCALL(GetDTableSize,getdtablesize) (/* */); /* */ extern int XR←SYSCALL(GetRUsage,getrusage) (/* */); /* */ extern int XR←SYSCALL(IOCtl,ioctl) (/* d, request, argp */); /* XR←Fildes d; int request; char *argp; */ extern int XR←SYSCALLX(IOCtl4) (/* d, request, argp, doInIOP */); /* XR←Fildes d; int request; char *argp; bool doInIOP; Caller controls whether ioctl is done in vp or iop. The Unix-style entry IOCtl always does the ioctl call in the vp, which in some cases is inappropriate. */ extern int XR←SYSCALL(Link,link) (/* name1, name2 */); /* char *name1; char *name2; */ extern int XR←SYSCALL(LSeek,lseek) (/* fildes, offset, whence */); /* XR←Fildes fildes; int offset; int whence; */ extern int XR←SYSCALL(MkDir,mkdir) (/* name, mode */); /* char *name; int mode; */ extern int XR←SYSCALL(MkNod,mknod) (/* name, mode, dev */); /* char *name; int mode; int dev; */ extern XR←Fildes XR←SYSCALL(Open,open) (/* name, flags, mode */); /* char *name; unsigned flags; unsigned mode; */ extern int XR←SYSCALL(Read,read) (/* fildes, buf, nBytes */); /* XR←Fildes fildes; XR←Pointer buf; unsigned nBytes; */ extern int XR←SYSCALLX(ReadLong) (/* fildes, buf, nBytes */); /* XR←Fildes fildes; XR←Pointer buf; unsigned nBytes; (doesn't segment long requests into multiple short ones) */ extern int XR←SYSCALL(ReadV,readv) (/* fildes, iov, iovCnt */); /* XR←Fildes fildes; <sys/uio.h>.struct iovec * iov; int iovCnt; */ extern int XR←SYSCALL(ReadLink,readlink) (/* path, buf, bufsiz */); /* char *path; char *buf; int bufsiz; */ extern int XR←SYSCALL(Rename,rename) (/* from, to */); /* char *from; char *to; */ extern int XR←SYSCALL(RmDir,rmdir) (/* name */); /* char *name; */ extern int XR←SYSCALL(Stat,stat) (/* path, buf */); /* char *path; struct <sys/stat.h>.stat *buf; */ extern int XR←SYSCALL(FStat,fstat) (/* fildes, buf */); /* XR←Fildes fildes; struct <sys/stat.h>.stat *buf; */ extern int XR←SYSCALL(LStat,lstat) (/* path, buf */); /* char *path; struct <sys/stat.h>.stat *buf; */ extern int XR←SYSCALL(StatFS,statfs) (/* path, buf */); /* char *path; struct <sys/vfs.h>.statfs *buf; */ extern int XR←SYSCALL(FStatFS,fstatfs) (/* fildes, buf */); /* XR←Fildes fildes; struct <sys/vfs.h>.statfs *buf; */ extern int XR←SYSCALL(SymLink,symlink) (/* name1, name2 */); /* char *name1; char *name2; */ extern int XR←SYSCALL(Sync,sync) (/* */); extern int XR←SYSCALL(Truncate,truncate) (/* path, length */); /* char *path; unsigned length; */ extern int XR←SYSCALL(FTruncate,ftruncate) (/* fildes, length */); /* XR←Fildes fildes; unsigned length; */ extern XR←Fildes XR←SYSCALLX(TTYOpen) (/* char *name, unsigned flags, unsigned cflag */); /* Open a tty and condition it. If cflag is non-zero, it is used in a TCSETS ioctl call. */ extern int XR←SYSCALLX(TTYRead) (/* XR←Fildes fildes, XR←Pointer buf, unsigned nBytes */); /* Read from a tty. Because of peculiarities of the SunOS tty driver, XR←Read doesn't quite work correctly ... */ extern int XR←SYSCALL(Unlink,unlink) (/* path */); /* char *path; */ extern int XR←SYSCALL(UTimes,utimes) (/* file, tvp */); /* char *file; struct <sys/time.h>.timeval tvp[2]; */ extern int XR←SYSCALL(Write,write) (/* fildes, buf, nBytes */); /* XR←Fildes fildes; XR←Pointer buf; unsigned nBytes; */ extern int XR←SYSCALLX(WriteLong) (/* fildes, buf, nBytes */); /* XR←Fildes fildes; XR←Pointer buf; unsigned nBytes; (doesn't segment long requests into multiple short ones) */ extern int XR←SYSCALL(WriteV,writev) (/* fildes, iov, iovCnt */); /* XR←Fildes fildes; <sys/uio.h>.struct iovec * iov; int iovCnt; */ /* * * stream calls * */ extern int XR←SYSCALL(GetMsg,getmsg) (/* fildes, ctlptr, dataptr, flags */); /* XR←Fildes fildes; struct <stropts.h>.strbuf *ctlptr; struct <stropts.h>.strbuf *dataptr; int *flags; */ extern int XR←SYSCALL(PutMsg,putmsg) (/* fildes, ctlptr, dataptr, flags */); /* XR←Fildes fildes; struct <stropts.h>.strbuf *ctlptr; struct <stropts.h>.strbuf *dataptr; int *flags; */ extern int XR←SYSCALL(Poll,poll) (/* fds, nfds, timeout */); /* struct <poll.h>.pollfd *fds; unsigned nfds; int timeout; Similar to poll, but ... - works on an arbitrary descriptor - nfds must be 1 - the file descriptor specified in fds[0] must be valid (not -1) */ /* * * socket calls * */ extern XR←Fildes XR←SYSCALL(Accept,accept) (/* fildes, addr, addrlen */); /* XR←Fildes fildes; struct <sys/socket.h>.sockaddr *addr; int *addrlen; */ extern int XR←SYSCALL(Bind,bind) (/* fildes, name, namelen */); /* XR←Fildes fildes; struct <sys/socket.h>.sockaddr *name; int namelen; */ extern int XR←SYSCALL(Connect,connect) (/* fildes, name, namelen */); /* XR←Fildes fildes; struct <sys/socket.h>.sockaddr *name; int namelen; */ extern int XR←SYSCALL(GetPeerName,getpeername) (/* fildes, name, namelen */); /* XR←Fildes fildes; struct <sys/socket.h>.sockaddr *name; int *namelen; */ extern int XR←SYSCALL(GetSockName,getsockname) (/* fildes, name, namelen */); /* XR←Fildes fildes; struct <sys/socket.h>.sockaddr *name; int *namelen; */ extern int XR←SYSCALL(GetSockOpt,getsockopt) (/* fildes, level, optid, optval, optlen */); /* XR←Fildes fildes; int level; int optid; char *optval; int *optlen; */ extern int XR←SYSCALL(SetSockOpt,setsockopt) (/* fildes, level, optid, optval, optlen */); /* XR←Fildes fildes; int level; int optid; char *optval; int optlen; */ extern int XR←SYSCALL(Listen,listen) (/* fildes, backlog */); /* XR←Fildes fildes; int backlog; */ extern int XR←SYSCALL(Recv,recv) (/* fildes, buf, len, flags */); /* XR←Fildes fildes; char *buf; int len; unsigned flags; */ extern int XR←SYSCALL(RecvFrom,recvfrom) (/* fildes, buf, len, flags, from, fromlen */); /* XR←Fildes fildes; char *buf; int len; unsigned flags; struct <sys/socket.h>.sockaddr *from; int *fromlen; */ extern int XR←SYSCALL(Send,send) (/* fildes, buf, len, flags */); /* XR←Fildes fildes; char *buf; int len; unsigned flags; */ extern int XR←SYSCALL(SendTo,sendto) (/* fildes, buf, len, flags, to, tolen */); /* XR←Fildes fildes; char *buf; int len; unsigned flags; struct <sys/socket.h>.sockaddr *to; int tolen; */ extern int XR←SYSCALL(Shutdown,shutdown) (/* fildes, how */); /* XR←Fildes fildes; unsigned how; */ extern XR←Fildes XR←SYSCALL(Socket,socket) (/* af, type, protocol */); /* int af; int type; int protocol; */ /* * * Other Unix system calls * * (??? These probably belong in a different file ???) * */ extern int XR←SYSCALL(GetDomainName,getdomainname) (/* name, nameLen */); /* char *name; int nameLen; */ extern int XR←SYSCALL(GetGID,getgid) (/* */); /* */ extern int XR←SYSCALL(GetEGID,getegid) (/* */); /* */ extern int XR←SYSCALL(GetGroups,getgroups) (/* gidSetLen, gidSet */); /* int gidSetLen; int *gidSet */ extern int XR←SYSCALL(GetHostID,gethostid) (/* */); /* */ extern int XR←SYSCALL(GetHostName,gethostname) (/* name, nameLen */); /* char *name; int nameLen; */ extern int XR←SYSCALL(GetPageSize,getpagesize) (/* */); /* */ extern int XR←SYSCALL(GetPGrp,getpgrp) (/* pid */); /* int pid; */ extern int XR←SYSCALL(GetPID,getpid) (/* */); /* Always returns PID of VProcessor 0. */ extern int XR←SYSCALL(GetPPID,getppid) (/* */); /* Always returns PID of Debugger processor. */ extern int XR←SYSCALL(GetTimeOfDay,gettimeofday) (/* tp, tzp */); /* <sys/time.h>.struct timeval *tp; <sys/time.h>.struct timezone *tzp; */ extern int XR←SYSCALL(GetUID,getuid) (/* */); /* */ extern int XR←SYSCALL(GetEUID,geteuid) (/* */); /* */ extern int XR←SYSCALL(Kill,kill) (/* pid, sig */); /* int pid; int sig; */ extern int XR←SYSCALL(KillPG,killpg) (/* pgrp, sig */); /* int pgrp; int sig; */ extern int XR←SYSCALL(MInCore,mincore) (/* addr, len, vec */); /* char *addr; int len; char *vec; */ extern int XR←SYSCALL(MMap,mmap) (/* addr, len, prot, flags, fildes, off */); /* XR←Pointer addr; unsigned len; int prot; int flags; XR←Fildes fildes; unsigned off; Like SunOS or BSD mmap(2) call, done atomically in all vp's. Restrictions: (flags & (MAP←SHARED|MAP←FIXED)) == (MAP←SHARED|MAP←FIXED). addr must be page-aligned. range [addr, addr+len) must lie beyond the heap segment limit (see XR←SetSegLimit in ThreadsSharedMem.h). Return addr on success, (-1) on failure. */ extern int XR←SYSCALL(MProtect,mprotect) (/* addr, len, prot */); /* XR←Pointer addr; unsigned len; int prot; Like SunOS mprotect call, done atomically in all vp's. Restrictions: addr must be page-aligned. range [addr, addr+len) must lie outside heap segment. See ThreadsVirtualDirty.h for heap protection. Return 0 on success, (-1) on failure. */ extern int XR←SYSCALL(MSync,msync) (/* addr, len, flags */); /* XR←Pointer addr; int len; int flags; Like SunOS msync call. */ extern int XR←SYSCALL(MUnmap,munmap) (/* addr, len */); /* XR←Pointer addr; unsigned len; Like SunOS or BSD munmap(2) call, done atomically in all vp's. Restriction: addr must be page-aligned. munmapped region must lie beyond heap segment limit AND MUST BE MAPPED. Return 0 on success. Panic on failure. DANGER! */ extern int XR←SYSCALL(Profil,profil) (/* buf, bufSize, offset, scale */); /* char *buf; int bufSize; int offset; int scale; Currently buffer must be outside the heap, an admittedly unreasonable restriction. */ extern int XR←SYSCALL(ShmAt,shmat) (/* id, addr, flags */); /* int id; XR←Pointer addr; int flags; */ extern int XR←SYSCALL(ShmCtl,shmctl) (/* shmid, cmd, buf */); /* int shmid; int cmd; char *buf; */ extern int XR←SYSCALL(ShmDt,shmdt) (/* addr */); /* XR←Pointer addr; */ extern int XR←SYSCALL(ShmGet,shmget) (/* key, size, shmflag */); /* int key; int size; int shmflag; */ #endif ←XR←UIO←