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, January 26, 1993 8:42 pm PST
UnixSysCallsImpl:
CEDAR
PROGRAM
IMPORTS ProcessorFace
EXPORTS UnixSysCalls, UnixSysCallExtensions
~ { OPEN UnixSysCallExtensions, UnixTypes;
Acct
AdjTime
Audit
AuditOn
Brk
SBrk
Chown
FChown
Close:
PUBLIC
PROC [fd:
FD]
RETURNS [
RES] ~ {
close:
PROC [fd:
FD]
RETURNS [
RES] ~
TRUSTED
MACHINE
CODE {
"XR𡤌lose"
};
RETURN[ close[fd] ];
};
Dup
Dup2 ????
ExecVE
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] ];
};
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] ];
};
SetHostName
GetITimer
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] ];
};
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] ];
};
MsgCtl
MsgGet
NFSSvc
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
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] ];
};
Select
SemCtl
SemGet
SetREGID
SigBlock
SigPause
SigSetMask
SigStack
FStat:
PUBLIC
UNSAFE
PROC [fd:
FD, buf: StatPtr]
RETURNS [
RES] ~
UNCHECKED {
fstat4:
UNSAFE
PROC [fd:
FD, buf: StatPtr]
RETURNS [
RES] ~
UNCHECKED
MACHINE
CODE {
"XR𡤏Stat"
};
fstat3:
UNSAFE
PROC [fd:
FD, buf: Stat3Ptr]
RETURNS [
RES] ~
UNCHECKED
MACHINE
CODE {
"XR𡤏Stat"
};
SELECT ProcessorFace.GetProcessorType[]
FROM
sun4 => RETURN[ fstat4[fd, buf] ];
sun3 => {
buf3: Stat3;
res: RES ¬ fstat3[fd, @buf3];
AssignStat[buf, @buf3];
RETURN[res];
}
ENDCASE => ERROR;
};
UMask
Unlink:
PUBLIC
PROC [path: CHARPtr]
RETURNS [
RES] ~ {
unlink:
PROC [path: CHARPtr]
RETURNS [
RES] ~
TRUSTED
MACHINE
CODE {
"XR←Unlink"
};
RETURN[ unlink[path] ];
};
VAdvise
VFork
Wait
Wait3
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 are different on Sun3/Sun4. We want Cedar code to always use the same stat structure so we transform Stat3s to Stats here.
Stat3Ptr: TYPE = POINTER TO Stat3;
Stat3:
TYPE =
WORD16
MACHINE
DEPENDENT
RECORD [
dev: Dev, -- device inode resides on
pad0: INT16, -- no padding on sun3
ino: INum, -- this inode's number
mode: Mode, -- protection
nlink: INT16, -- number of hard links to the file
uid: UID, -- user ID of owner
gid: GID, -- group ID of owner
rdev: Dev, -- the device type, for inode that is device
pad1: INT16, -- no padding on sun3
size: CARD32, -- total size of file, in bytes
atime: Time, -- file last access time
spare1: INT32,
mtime: Time, -- file last modify time
spare2: INT32,
ctime: Time, -- file last status change time
spare3: INT32,
blksize: CARD32, -- optimal blocksize for file system i/o ops
blocks: CARD32, -- actual number of blocks allocated
spare4: ARRAY [0..2) OF INT32
];
AssignStat:
PRIVATE
UNSAFE
PROC [s4: StatPtr, s3: Stat3Ptr]
RETURNS [] ~
UNCHECKED {
s4.dev ¬ s3.dev;
s4.ino ¬ s3.ino;
s4.mode ¬ s3.mode;
s4.nlink ¬ s3.nlink;
s4.uid ¬ s3.uid;
s4.gid ¬ s3.gid;
s4.rdev ¬ s3.rdev;
s4.size ¬ s3.size;
s4.atime ¬ s3.atime;
s4.spare1 ¬ s3.spare1;
s4.mtime ¬ s3.mtime;
s4.spare2 ¬ s3.spare2;
s4.ctime ¬ s3.ctime;
s4.spare3 ¬ s3.spare3;
s4.blksize ¬ s3.blksize;
s4.blocks ¬ s3.blocks;
s4.spare4 ¬ s3.spare4;
};
}.