Userland: suggestion for the userapi code
Peter da Silva
peter-dragonfly at taronga.com
Fri Jul 18 07:42:21 PDT 2003
In the userapi example you have:
ssize_t
read(int fd, void *buf, size_t bytes)
{
SysReadMsg msg;
initSysReadMsg(&msg, &_sysreplyport, fd, buf, bytes);
error = _syscallport->mp_SendMsg(syscallport, &msg);
if (error == EASYNC) {
error = waitmsg(&msg);
... blocks ...
}
errno = error;
return(msg.retcode);
}
I think there would be more flexibility with:
ssize_t
read(int fd, void *buf, size_t bytes)
{
SysReadMsg msg;
SysMsgPort *port, *reply; /* or whatever */
... check that fd is valid ...
port = _fdtab[fd].messagePort;
reply = _fdtab[fd].replyPort;
initSysReadMsg(&msg, reply, fd, buf, bytes);
error = port->mp_SendMsg(port, &msg);
if (error == EASYNC) {
error = reply->waitmsg(&msg);
... blocks ...
}
errno = error;
return(msg.retcode);
}
Most of the time the per-fd ports are the system ports.
This doesn't require any change in the kernel, but it makes user-level
layering a lot easier... you could test and implement pseudo-devices
as an _unprivileged_ user by wrapping open() or you could shortcut
implementations of things like /dev/null or /dev/zero so they made
no kernel crossings at all.
(I hope this doesn't come out in HTML, NewsFlash doesn't seem to have
a way to say "no, I don't bloody want rich text, I don't care how cool
it is"... I need a better newsreader for Mac OS X. I wish TRN had
multiple server support)
More information about the Kernel
mailing list