From: C H Forsyth <forsyth@vitanuova.com>
To: 9fans@cse.psu.edu
Subject: [9fans] fun with rfork
Date: Fri, 31 Oct 2003 10:25:58 +0000 [thread overview]
Message-ID: <13ab91b7d3a360a0ca444540bc498ba7@vitanuova.com> (raw)
here is part of an application of rfork(RFMEM|RFPROC ...).
most irrelevant code has been removed.
libinit was called early on before the process switched to
a stack on the malloc heap, and that's where it is running when it
calls oscmd.
what happens next?
--------
void
libinit(char *imod)
{
...
int fd, n, pid;
...
/*
* guess at a safe stack for vstack
*/
ustack = (ulong)&fd;
...
/* switch to stack on the heap ... */
tramp(sp+KSTACK, up->func, up->arg);
}
typedef struct Targ Targ;
struct Targ
{
int fd;
int* spin;
char* cmd;
};
void
exectramp(Targ *targ)
{
*targ->spin = 0;
...
exec(argv[0], argv);
exits("");
}
int
oscmd(char *cmd, int *rfd, int *sfd)
{
Targ targ;
int spin, *spinptr, fd[2];
if(pipe(fd) < 0)
return -1;
spinptr = &spin;
spin = 1;
targ.fd = fd[0];
targ.cmd = cmd;
targ.spin = spinptr;
switch(rfork(RFMEM|RFPROC|RFFDG|RFENVG|RFREND)) {
case -1:
return -1;
case 0:
vstack(&targ); /* Never returns */
default:
while(*spinptr)
;
break;
}
close(fd[0]);
*rfd = fd[1];
*sfd = fd[1];
return 0;
}
TEXT vstack(SB),$0
MOVL arg+0(FP), AX
MOVL ustack(SB), SP
PUSHL AX
CALL exectramp(SB)
POPL AX /* dammit ken! */
RET
next reply other threads:[~2003-10-31 10:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-10-31 10:25 C H Forsyth [this message]
2003-10-31 23:35 ` Bruce Ellis
2003-11-01 10:03 ` Charles Forsyth
2003-11-01 11:40 ` Bruce Ellis
2003-11-01 12:41 ` Charles Forsyth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=13ab91b7d3a360a0ca444540bc498ba7@vitanuova.com \
--to=forsyth@vitanuova.com \
--cc=9fans@cse.psu.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).