UnixSysCallsImpl.mesa
Copyright Ó 1988, 1989, 1991, 1993 by Xerox Corporation. All rights reserved.
Christian Jacobi, January 24, 1991 5:30 pm PST
CHauser, November 9, 1988 12:45:15 pm PST
Demers, November 9, 1988 5:41:50 pm PST
Carl Hauser, February 16, 1989 2:08:26 pm PST
Unix(tm) system calls for PCedar.
Commented-out names are unimplemented for good reason, and not to be used, except: "????" means we should implement some version of this eventually.
Michael Plass, September 1, 1992 2:40 pm PDT
Willie-s, March 16, 1994 12:09 pm PST
DIRECTORY
UnixSysCalls,
UnixSysCallExtensions,
UnixTypes
;
UnixSysCallsImpl: CEDAR PROGRAM
EXPORTS UnixSysCalls, UnixSysCallExtensions
~ { OPEN UnixSysCallExtensions, UnixTypes;
Acct
AdjTime
Audit
AuditOn
AuditSvc
Brk
SBrk
ChDir
Chown
FChown
Chroot
Close: PUBLIC PROC [fd: FD] RETURNS [RES] ~ {
close: PROC [fd: FD] RETURNS [RES] ~ TRUSTED MACHINE CODE {
"XR𡤌lose"
};
RETURN[ close[fd] ];
};
Creat
Dup
Dup2 ????
ExecVE
Exit
FLock
Fork
FSync: PUBLIC PROC [fd: FD] RETURNS [RES] ~ {
fsync: PROC [fd: FD] RETURNS [RES] ~ TRUSTED MACHINE CODE {
"XR𡤏Sync"
};
RETURN[ fsync[fd] ];
};
GetAUID
SetAUID
GetDEnts: PUBLIC UNSAFE PROC [fd: FD, buf: CHARPtr, nBytes: INT] RETURNS [INT] ~ UNCHECKED {
getdents: UNSAFE PROC [fd: FD, buf: CHARPtr, nBytes: INT] RETURNS [INT] ~ UNCHECKED MACHINE CODE {
"XR←GetDEnts"
};
RETURN[ getdents[fd, buf, nBytes] ];
};
GetDirentries
GetDTableSize: PUBLIC PROC RETURNS [INT] ~ {
getdtablesize: PROC RETURNS [INT] ~ TRUSTED MACHINE CODE {
"XR←GetDTableSize"
};
RETURN[ getdtablesize[] ];
};
GetDTableSize1: PUBLIC PROC [kind: FDKind] RETURNS [INT]
~ {
GetDTableSize1Inner: PROC [kind: FDKind] RETURNS [INT]
~ TRUSTED MACHINE CODE {
"XR←GetDTableSize1"
};
RETURN[ GetDTableSize1Inner[kind] ];
};
SetGroups
SetHostName
GetITimer
SetITimer
GetPriority
SetPriority
GetRLimit
SetRLimit
GetTimeOfDay: PUBLIC UNSAFE PROC [tp: TimeValPtr, tzp: TimeZonePtr] RETURNS [RES] ~ UNCHECKED {
gettimeofday: UNSAFE PROC [tp: TimeValPtr, tzp: TimeZonePtr] RETURNS [RES] ~ UNCHECKED MACHINE CODE {
"XR←GetTimeOfDay"
};
RETURN[ gettimeofday[tp, tzp] ];
};
SetTimeOfDay
LSeek: PUBLIC PROC [d: FD, offset: INT, whence: Whence] RETURNS [INT] ~ {
lseek: PROC [d: FD, offset: INT, whence: Whence] RETURNS [INT] ~ TRUSTED MACHINE CODE {
"XR←LSeek"
};
RETURN[ lseek[d, offset, whence] ];
};
MMap: PUBLIC UNSAFE PROC [addr: RawVM, nbytes: CARD, prot: Protections, flags: MMapFlags, d: FD, offset: CARD] RETURNS [RES] ~ {
There were two errors in the definition of MMap in the interface; UnixTypes.MMapFlags is wrong, and the mmap call returns the address, not a return code. We fix the first problem by translating the bits (this is really the "right way" to do this anayway, if we were not generally so lazy, since it would track changes in mman.h). The second one we'll ignore for now - clients should check res#failure instead of res=success.
mmap: PROC [addr: RawVM, nbytes: CARD, prot: Protections, flags: INT, d: FD, offset: CARD] RETURNS [RawVM] ~ TRUSTED MACHINE CODE {
"<sys/mman.h>.XR←MMap" -- the proc is really in <xr/UIO.h>, but the constants we need are in <sys/mman.h>
};
ConstructMMapFlags: PROC [shared, private, fixed: BOOL] RETURNS [INT] ~ TRUSTED MACHINE CODE {
"+#define CONSTRUCT←MMAP𡤏LAGS(shared, private, fixed) ( ((word)(shared))*((word)(MAP←SHARED)) + ((word)(private))*((word)(MAP←PRIVATE)) + ((word)(fixed))*((word)(MAP𡤏IXED)))\n";
".CONSTRUCT←MMAP𡤏LAGS";
};
RETURN[ IF mmap[addr, nbytes, prot, ConstructMMapFlags[shared: flags.shared, private: flags.private, fixed: flags.fixed], d, offset] = addr THEN success ELSE failure ];
};
MUnmap: PUBLIC UNSAFE PROC [addr: RawVM, nbytes: CARD] RETURNS [RES] ~ {
munmap: PROC [addr: RawVM, nbytes: CARD] RETURNS [RES] ~ TRUSTED MACHINE CODE {
"XR←MUnmap"
};
RETURN[ munmap[addr, nbytes] ];
};
Mount
MsgCtl
MsgGet
MsgOp
NFSSvc
AsyncDaemon
Open: PUBLIC PROC [path: CHARPtr, flags: FileFlags, mode: Mode] RETURNS [FD] ~ {
open: PROC [path: CHARPtr, flags: FileFlags, mode: Mode] RETURNS [FD] ~ TRUSTED MACHINE CODE {
"XR←Open"
};
RETURN[ open[path, flags, mode] ];
};
Pipe
PTrace
QuotaCtl
Read: PUBLIC UNSAFE PROC [d: FD, buf: CHARPtr, nBytes: INT] RETURNS [INT] ~ UNCHECKED {
read: UNSAFE PROC [d: FD, buf: CHARPtr, nBytes: INT] RETURNS [INT] ~ UNCHECKED MACHINE CODE {
"XR←Read"
};
RETURN[ read[d, buf, nBytes] ];
};
Reboot
RecvMsg
Select
SemCtl
SemGet
SemOp
SendMsg
SetPGRP
SetREGID
SetREUID
SetUserAudit
SigBlock
SigPause
SigSetMask
SigStack
SigVec
SocketPair ????
FStat: PUBLIC UNSAFE PROC [fd: FD, buf: StatPtr] RETURNS [RES] ~ UNCHECKED {
fstat: UNSAFE PROC [fd: FD, buf: StatPtr] RETURNS [RES] ~ UNCHECKED MACHINE CODE {
"XR𡤏Stat"
};
res: RES ¬ fstat[fd, buf];
RETURN[res];
spcr does the stat conversion
};
Swapon
Syscall
UMask
UName
Unlink: PUBLIC PROC [path: CHARPtr] RETURNS [RES] ~ {
unlink: PROC [path: CHARPtr] RETURNS [RES] ~ TRUSTED MACHINE CODE {
"XR←Unlink"
};
RETURN[ unlink[path] ];
};
Unmount
VAdvise
VFork
VHangup
Wait
Wait3
Wait4
Write: PUBLIC PROC [d: FD, buf: CHARPtr, nBytes: INT] RETURNS [INT] ~ {
write: PROC [d: FD, buf: CHARPtr, nBytes: INT] RETURNS [INT] ~ TRUSTED MACHINE CODE {
"XR←Write"
};
RETURN[ write[d, buf, nBytes] ];
};
Stat structures is differennt for solaris 2.x (from SunOs 4.1.x). We want Cedar code to always use the same stat structure so we transform SolarisStat to Stats here. This is a kludge to fix this immdeiate problem.
SolarisMode: TYPE ~ MACHINE DEPENDENT RECORD [
pad: [0..0FFFFh] ¬ 0,
fmt: Fmt ¬ LOOPHOLE[0], -- type of file
suid: Flag ¬ false, -- set user id on execution
sgid: Flag ¬ false, -- set group id on execution
svtx: Flag ¬ false, -- save swapped text even after use
owner: Permission ¬ [false, false, false],
group: Permission ¬ [false, false, false],
others: Permission ¬ [false, false, false]
];
SolarisStatPtr: TYPE = POINTER TO SolarisStat;
SolarisStat: TYPE ~ MACHINE DEPENDENT RECORD [
dev: INT,  -- device inode resides on
pad1: ARRAY [0..3) OF CARD,
ino: INum,  -- this inode's number
mode: SolarisMode, -- protection
nlink: CARD, -- number of hard links to the file
uid: INT,  -- user ID of owner
gid: INT,  -- group ID of owner
rdev: INT,  -- the device type, for inode that is device
pad2: ARRAY [0..2) OF CARD,
size: INT,  -- total size of file, in bytes
pad3: CARD,  -- reserve pad for future off←t expansion
atime: TimeVal, -- file last access time
mtime: TimeVal, -- file last modify time
ctime: TimeVal, -- file last status change time
blksize: CARD, -- optimal blocksize for file system i/o ops
blocks: CARD, -- actual number of blocks allocated
fstype: ARRAY [0..16) OF CHAR,
pad4: ARRAY [0..8) OF CARD-- expansion area
];
Structure filled in by stat/fstat.
TimeVal: TYPE = MACHINE DEPENDENT RECORD [
sec: CARD,  -- seconds since Jan 1, 1970
msec: CARD  -- plus this many microseconds
];
AssignStat: PRIVATE UNSAFE PROC [s4: StatPtr, ssp: SolarisStatPtr] ~ UNCHECKED {
s4.dev ¬ ssp.dev;
s4.ino ¬ ssp.ino;
s4.mode.fmt ¬ ssp.mode.fmt;
s4.mode.suid ¬ ssp.mode.suid;
s4.mode.sgid ¬ ssp.mode.sgid;
s4.mode.svtx ¬ ssp.mode.svtx;
s4.mode.owner ¬ ssp.mode.owner;
s4.mode.group ¬ ssp.mode.group;
s4.mode.others ¬ ssp.mode.others;
s4.nlink ¬ ssp.nlink;
s4.uid ¬ ssp.uid;
s4.gid ¬ ssp.gid;
s4.rdev ¬ ssp.rdev;
s4.size ¬ ssp.size;
s4.atime ¬ ssp.atime.sec;
s4.spare1 ¬ ssp.atime.msec;
s4.mtime ¬ ssp.mtime.sec;
s4.spare2 ¬ ssp.mtime.msec;
s4.ctime ¬ ssp.ctime.sec;
s4.spare3 ¬ ssp.ctime.msec;
s4.blksize ¬ 4096; -- hack
s4.blocks ¬ s4.size / s4.blksize; -- hack
};
}.
CHauser, February 16, 1989: Remove Dup, add GetSockOpt, SetSockOpt
CHauser, February 22, 1989: Added Poll, GetMsg, PutMsg
Plass, January 29, 1992: Added Access, FCntl, FCntl4, IOCtl4, MMap, MUnmap, MProtect, MSync