From 1b135a78054e05cd62dfa1a2606f93e3486f2b57 Mon Sep 17 00:00:00 2001 From: rsc Date: Mon, 19 Apr 2004 23:04:36 +0000 Subject: clean up when finished. don't set PLAN9 don't set PLAN9 --- src/cmd/factotum/mkfile | 1 - src/cmd/graph/graph.c | 5 - src/cmd/graph/mkfile | 1 - src/cmd/grep/mkfile | 1 - src/cmd/gzip/mkfile | 1 - src/cmd/hoc/mkfile | 1 - src/cmd/mk/mkfile | 1 - src/cmd/plot/libplot/mkfile | 1 - src/cmd/plot/libplot/subr.c | 1 + src/cmd/plot/mkfile | 1 - src/cmd/plumb/mkfile | 1 - src/cmd/rc/mkfile | 1 - src/cmd/rio/mkfile | 1 - src/cmd/sam/mkfile | 1 - src/cmd/samterm/mkfile | 1 - src/cmd/spell/mkfile | 1 - src/cmd/vac/mkfile | 1 - src/cmd/venti/mkfile | 1 - src/lib9/fmt/mkfile | 1 - src/lib9/mkfile | 1 - src/lib9/utf/mkfile | 1 - src/lib9p/mkfile | 1 - src/libString/mkfile | 1 - src/libString/s_parse.c | 1 + src/libbin/mkfile | 1 - src/libbio/mkfile | 1 - src/libcomplete/mkfile | 1 - src/libdraw/chan.c | 7 -- src/libdraw/mkfile | 1 - src/libflate/mkfile | 1 - src/libframe/mkfile | 1 - src/libfs/mkfile | 1 - src/libhttpd/mkfile | 1 - src/libip/mkfile | 1 - src/libmach/FreeBSD.c | 293 ++++++++++++++++++++++++++++++++++++++++++-- src/libmach/mkfile | 8 ++ src/libmp/mkfile | 1 - src/libmp/port/mkfile | 1 - src/libmux/mkfile | 1 - src/libplumb/mkfile | 1 - src/libregexp/mkfile | 1 - src/libsec/mkfile | 1 - src/libsec/port/mkfile | 1 - src/libthread/mkfile | 1 - src/libventi/mkfile | 1 - 45 files changed, 294 insertions(+), 60 deletions(-) (limited to 'src') diff --git a/src/cmd/factotum/mkfile b/src/cmd/factotum/mkfile index 3aa9bb70..7fb7ffde 100644 --- a/src/cmd/factotum/mkfile +++ b/src/cmd/factotum/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr TARG=factotum diff --git a/src/cmd/graph/graph.c b/src/cmd/graph/graph.c index d1b6938f..7f41dfab 100644 --- a/src/cmd/graph/graph.c +++ b/src/cmd/graph/graph.c @@ -243,11 +243,6 @@ void limread(struct xy *p, int *argcp, char ***argvp){ p->xqf = 1; } -int -isdigit(char c){ - return '0'<=c && c<='9'; -} - int numb(float *np, int *argcp, char ***argvp){ char c; diff --git a/src/cmd/graph/mkfile b/src/cmd/graph/mkfile index 4a45add1..13447d0a 100644 --- a/src/cmd/graph/mkfile +++ b/src/cmd/graph/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr TARG=graph diff --git a/src/cmd/grep/mkfile b/src/cmd/grep/mkfile index fd17abdd..38619325 100644 --- a/src/cmd/grep/mkfile +++ b/src/cmd/grep/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr # Calling this grep breaks a LOT. Like egrep on Linux. diff --git a/src/cmd/gzip/mkfile b/src/cmd/gzip/mkfile index 29b8bdb0..2894f1fb 100644 --- a/src/cmd/gzip/mkfile +++ b/src/cmd/gzip/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr HFILES=\ diff --git a/src/cmd/hoc/mkfile b/src/cmd/hoc/mkfile index d3bfd274..dd43b0fb 100644 --- a/src/cmd/hoc/mkfile +++ b/src/cmd/hoc/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr TARG=hoc diff --git a/src/cmd/mk/mkfile b/src/cmd/mk/mkfile index 9b054053..6e8f52b9 100644 --- a/src/cmd/mk/mkfile +++ b/src/cmd/mk/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr TARG=mk diff --git a/src/cmd/plot/libplot/mkfile b/src/cmd/plot/libplot/mkfile index a73bd617..dc33ac63 100644 --- a/src/cmd/plot/libplot/mkfile +++ b/src/cmd/plot/libplot/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../../.. <$PLAN9/src/mkhdr LIB=../libplot.a diff --git a/src/cmd/plot/libplot/subr.c b/src/cmd/plot/libplot/subr.c index cf4cf89e..886659fa 100644 --- a/src/cmd/plot/libplot/subr.c +++ b/src/cmd/plot/libplot/subr.c @@ -11,6 +11,7 @@ struct penvir E[9] = { { 0., 1024., 0., 0., 1., -1.,1024., -1024., 0., 0., pSMALL, 1., 1, 0.,1, DBlack, DWhite} }; struct penvir *e0 = E, *e1 = &E[1], *esave; +int bcolor(char *s){ int c; while (*s != NULL) { diff --git a/src/cmd/plot/mkfile b/src/cmd/plot/mkfile index 0eb1a795..77ebd7e1 100644 --- a/src/cmd/plot/mkfile +++ b/src/cmd/plot/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr TARG=plot diff --git a/src/cmd/plumb/mkfile b/src/cmd/plumb/mkfile index 967cbb3b..902ebf01 100644 --- a/src/cmd/plumb/mkfile +++ b/src/cmd/plumb/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr TARG=plumber plumb diff --git a/src/cmd/rc/mkfile b/src/cmd/rc/mkfile index c1440ce4..f7d50e3f 100644 --- a/src/cmd/rc/mkfile +++ b/src/cmd/rc/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr YACC=yacc -d diff --git a/src/cmd/rio/mkfile b/src/cmd/rio/mkfile index b5e8b110..1bec50ef 100644 --- a/src/cmd/rio/mkfile +++ b/src/cmd/rio/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr OFILES=\ diff --git a/src/cmd/sam/mkfile b/src/cmd/sam/mkfile index aa9a59f4..8402579d 100644 --- a/src/cmd/sam/mkfile +++ b/src/cmd/sam/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr TARG=sam diff --git a/src/cmd/samterm/mkfile b/src/cmd/samterm/mkfile index facc78d2..78454909 100644 --- a/src/cmd/samterm/mkfile +++ b/src/cmd/samterm/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr TARG=samterm diff --git a/src/cmd/spell/mkfile b/src/cmd/spell/mkfile index e9e600f9..b92c125f 100644 --- a/src/cmd/spell/mkfile +++ b/src/cmd/spell/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr TARG=sprog diff --git a/src/cmd/vac/mkfile b/src/cmd/vac/mkfile index a4b7a298..ed464d05 100644 --- a/src/cmd/vac/mkfile +++ b/src/cmd/vac/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr LIBFILES=\ diff --git a/src/cmd/venti/mkfile b/src/cmd/venti/mkfile index 99d8c98f..bb31f50a 100644 --- a/src/cmd/venti/mkfile +++ b/src/cmd/venti/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr LIBOFILES=\ diff --git a/src/lib9/fmt/mkfile b/src/lib9/fmt/mkfile index 0a5d3b67..52b0d48f 100644 --- a/src/lib9/fmt/mkfile +++ b/src/lib9/fmt/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libfmt.a diff --git a/src/lib9/mkfile b/src/lib9/mkfile index 6dfab749..00674b0a 100644 --- a/src/lib9/mkfile +++ b/src/lib9/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=lib9.a diff --git a/src/lib9/utf/mkfile b/src/lib9/utf/mkfile index 46c92fef..030a6dbd 100644 --- a/src/lib9/utf/mkfile +++ b/src/lib9/utf/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libutf.a diff --git a/src/lib9p/mkfile b/src/lib9p/mkfile index 17a10a3c..d131c4c7 100644 --- a/src/lib9p/mkfile +++ b/src/lib9p/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=lib9p.a diff --git a/src/libString/mkfile b/src/libString/mkfile index 49803b45..d92e4d90 100644 --- a/src/libString/mkfile +++ b/src/libString/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libString.a diff --git a/src/libString/s_parse.c b/src/libString/s_parse.c index 376a41e2..bcf2aef9 100644 --- a/src/libString/s_parse.c +++ b/src/libString/s_parse.c @@ -2,6 +2,7 @@ #include #include "libString.h" +#undef isspace #define isspace(c) ((c)==' ' || (c)=='\t' || (c)=='\n') /* Get the next field from a String. The field is delimited by white space, diff --git a/src/libbin/mkfile b/src/libbin/mkfile index c4501d0d..96f939e3 100644 --- a/src/libbin/mkfile +++ b/src/libbin/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libbin.a diff --git a/src/libbio/mkfile b/src/libbio/mkfile index e808b178..8c3d2601 100644 --- a/src/libbio/mkfile +++ b/src/libbio/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libbio.a diff --git a/src/libcomplete/mkfile b/src/libcomplete/mkfile index 233dbef8..35740d7d 100644 --- a/src/libcomplete/mkfile +++ b/src/libcomplete/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libcomplete.a diff --git a/src/libdraw/chan.c b/src/libdraw/chan.c index 3b76a32a..1677c5b5 100644 --- a/src/libdraw/chan.c +++ b/src/libdraw/chan.c @@ -29,13 +29,6 @@ chantostr(char *buf, u32int cc) return buf; } -/* avoid pulling in ctype when using with drawterm etc. */ -static int -isspace(char c) -{ - return c==' ' || c== '\t' || c=='\r' || c=='\n'; -} - u32int strtochan(char *s) { diff --git a/src/libdraw/mkfile b/src/libdraw/mkfile index 521c6d3f..e734fd5f 100644 --- a/src/libdraw/mkfile +++ b/src/libdraw/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libdraw.a diff --git a/src/libflate/mkfile b/src/libflate/mkfile index 074e9d07..973fb9b7 100644 --- a/src/libflate/mkfile +++ b/src/libflate/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libflate.a diff --git a/src/libframe/mkfile b/src/libframe/mkfile index 7ca23013..6d47c32e 100644 --- a/src/libframe/mkfile +++ b/src/libframe/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libframe.a diff --git a/src/libfs/mkfile b/src/libfs/mkfile index d4c8b49f..17d197ec 100644 --- a/src/libfs/mkfile +++ b/src/libfs/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libfs.a diff --git a/src/libhttpd/mkfile b/src/libhttpd/mkfile index bd4db82c..a70c5e76 100644 --- a/src/libhttpd/mkfile +++ b/src/libhttpd/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libhttpd.a diff --git a/src/libip/mkfile b/src/libip/mkfile index b08999a6..98496738 100644 --- a/src/libip/mkfile +++ b/src/libip/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libip.a diff --git a/src/libmach/FreeBSD.c b/src/libmach/FreeBSD.c index 2838b392..7cf5c1f4 100644 --- a/src/libmach/FreeBSD.c +++ b/src/libmach/FreeBSD.c @@ -1,43 +1,318 @@ /* - * process interface for FreeBSD + * process interface for FreeBSD + * + * we could be a little more careful about not using + * ptrace unless absolutely necessary. this would let us + * look at processes without stopping them. + * + * I'd like to make this a bit more generic (there's too much + * duplication with Linux and presumably other systems), + * but ptrace is too damn system-specific. */ #include #include #include #include +#include #include #include #include #include #include "ureg386.h" +Mach *machcpu = &mach386; + +typedef struct PtraceRegs PtraceRegs; +struct PtraceRegs +{ + Regs r; + int pid; +}; + +static int ptracerw(Map*, Seg*, ulong, void*, uint, int); +static int ptraceregrw(Regs*, char*, ulong*, int); + void -unmapproc(Map*) +unmapproc(Map *map) { + int i; + + if(map == nil) + return; + for(i=0; inseg; i++) + while(inseg && map->seg[i].pid){ + map->nseg--; + memmove(&map->seg[i], &map->seg[i+1], + (map->nseg-i)*sizeof(map->seg[0])); + } } int -mapproc(int, Map*, Regs**) +mapproc(int pid, Map *map, Regs **rp) { + Seg s; + PtraceRegs *r; + + if(ptrace(PT_ATTACH, pid, 0, 0) < 0) + if(ptrace(PT_READ_I, pid, 0, 0)<0 && errno!=EINVAL) + if(ptrace(PT_ATTACH, pid, 0, 0) < 0){ + werrstr("ptrace attach %d: %r", pid); + return -1; + } + + if(ctlproc(pid, "waitanyway") < 0){ + ptrace(PT_DETACH, pid, 0, 0); + return -1; + } + + memset(&s, 0, sizeof s); + s.base = 0; + s.size = 0xFFFFFFFF; + s.offset = 0; + s.name = "data"; + s.file = nil; + s.rw = ptracerw; + s.pid = pid; + if(addseg(map, s) < 0) + return -1; + + if((r = mallocz(sizeof(PtraceRegs), 1)) == nil) + return -1; + r->r.rw = ptraceregrw; + r->pid = pid; + *rp = (Regs*)r; + return 0; } int -detachproc(int) +detachproc(int pid) { + return ptrace(PT_DETACH, pid, 0, 0); } -int -procnotes(int, char***) +static int +ptracerw(Map *map, Seg *seg, ulong addr, void *v, uint n, int isr) { + int i; + u32int u; + uchar buf[4]; + + addr += seg->base; + for(i=0; ipid, (char*)addr+i, 0); + if(errno) + goto ptraceerr; + if(n-i >= 4) + *(u32int*)((char*)v+i) = u; + else{ + *(u32int*)buf = u; + memmove((char*)v+i, buf, n-i); + } + }else{ + if(n-i >= 4) + u = *(u32int*)((char*)v+i); + else{ + errno = 0; + u = ptrace(PT_READ_D, seg->pid, (char*)addr+i, 0); + if(errno) + return -1; + *(u32int*)buf = u; + memmove(buf, (char*)v+i, n-i); + u = *(u32int*)buf; + } + if(ptrace(PT_WRITE_D, seg->pid, (char*)addr+i, u) < 0) + goto ptraceerr; + } + } + return 0; + +ptraceerr: + werrstr("ptrace: %r"); + return -1; } -int -ctlproc(int, char*) +static char *freebsdregs[] = { + "FS", + "ES", + "DS", + "DI", + "SI", + "BP", + "SP", + "BX", + "DX", + "CX", + "AX", + "TRAP", + "PC", + "CS", + "EFLAGS", + "SP", + "SS", + "GS", +}; + +static ulong +reg2freebsd(char *reg) +{ + int i; + + for(i=0; ipid; + if(ptrace(PT_GETREGS, pid, (char*)&mregs, 0) < 0) + return -1; + if(isr) + *val = *(u32int*)((char*)&mregs+addr); + else{ + *(u32int*)((char*)&mregs+addr) = *val; + if(ptrace(PT_SETREGS, pid, (char*)&mregs, 0) < 0) + return -1; + } + return 0; } char* -proctextfile(int) +proctextfile(int pid) { + static char buf[1024], pbuf[128]; + + snprint(pbuf, sizeof pbuf, "/proc/%d/file", pid); + if(readlink(pbuf, buf, sizeof buf) >= 0) + return buf; + if(access(pbuf, AEXIST) >= 0) + return pbuf; + return nil; +} + +/* + + status The process status. This file is read-only and returns a single + line containing multiple space-separated fields as follows: + + o command name + o process id + o parent process id + o process group id + o session id + o major,minor of the controlling terminal, or -1,-1 if there is + no controlling terminal. + o a list of process flags: ctty if there is a controlling ter- + minal, sldr if the process is a session leader, noflags if + neither of the other two flags are set. + o the process start time in seconds and microseconds, comma + separated. + o the user time in seconds and microseconds, comma separated. + o the system time in seconds and microseconds, comma separated. + o the wait channel message + o the process credentials consisting of the effective user id + and the list of groups (whose first member is the effective + group id) all comma separated. +*/ + +int +procnotes(int pid, char ***pnotes) +{ + /* figure out the set of pending notes - how? */ + *pnotes = nil; + return 0; +} + +static int +isstopped(int pid) +{ + char buf[1024], *f[12]; + int fd, n, nf; + + snprint(buf, sizeof buf, "/proc/%d/status", pid); + if((fd = open(buf, OREAD)) < 0) + return 0; + n = read(fd, buf, sizeof buf-1); + close(fd); + if(n <= 0) + return 0; + buf[n] = 0; + + if((nf = tokenize(buf, f, nelem(f))) < 11) + return 0; + if(strcmp(f[10], "nochan") == 0) + return 1; + return 0; +} + +#undef waitpid + +int +ctlproc(int pid, char *msg) +{ + int p, status; + + if(strcmp(msg, "hang") == 0){ + if(pid == getpid()) + return ptrace(PT_TRACE_ME, 0, 0, 0); + werrstr("can only hang self"); + return -1; + } + if(strcmp(msg, "kill") == 0) + return ptrace(PT_KILL, pid, 0, 0); + if(strcmp(msg, "startstop") == 0){ + if(ptrace(PT_CONTINUE, pid, 0, 0) < 0) + return -1; + goto waitstop; + } +/* + if(strcmp(msg, "sysstop") == 0){ + if(ptrace(PTRACE_SYSCALL, pid, 0, 0) < 0) + return -1; + goto waitstop; + } +*/ + if(strcmp(msg, "stop") == 0){ + if(kill(pid, SIGSTOP) < 0) + return -1; + goto waitstop; + } + if(strcmp(msg, "waitanyway") == 0) + goto waitanyway; + if(strcmp(msg, "waitstop") == 0){ + waitstop: + if(isstopped(pid)) + return 0; + waitanyway: + for(;;){ + p = waitpid(pid, &status, WUNTRACED); + if(p <= 0) + return -1; + if(WIFEXITED(status) || WIFSTOPPED(status)) + return 0; + } + } + if(strcmp(msg, "start") == 0) + return ptrace(PT_CONTINUE, pid, 0, 0); + werrstr("unknown control message '%s'", msg); + return -1; } diff --git a/src/libmach/mkfile b/src/libmach/mkfile index a690a000..5f93c199 100644 --- a/src/libmach/mkfile +++ b/src/libmach/mkfile @@ -56,3 +56,11 @@ dwarfdump: dwarfdump.o $LIBDIR/$LIB nm: nm.o $LIBDIR/$LIB $LD -o $target $prereq -l9 + +Linux.$O: ptrace.c +FreeBSD.$O: ptrace.c +SunOS.$O: nosys.c +Darwin.$O: nosys.c +OpenBSD.$O: nosys.c +NetBSD.$O: nosys.c + diff --git a/src/libmp/mkfile b/src/libmp/mkfile index 5e3998a2..aab57462 100644 --- a/src/libmp/mkfile +++ b/src/libmp/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr DIRS=\ diff --git a/src/libmp/port/mkfile b/src/libmp/port/mkfile index 43670918..a9176dd3 100644 --- a/src/libmp/port/mkfile +++ b/src/libmp/port/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr LIB=libmp.a diff --git a/src/libmux/mkfile b/src/libmux/mkfile index 71d62a43..71ed3e4e 100644 --- a/src/libmux/mkfile +++ b/src/libmux/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libmux.a diff --git a/src/libplumb/mkfile b/src/libplumb/mkfile index eb6d0552..606113ac 100755 --- a/src/libplumb/mkfile +++ b/src/libplumb/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libplumb.a diff --git a/src/libregexp/mkfile b/src/libregexp/mkfile index ad482240..f90c321b 100644 --- a/src/libregexp/mkfile +++ b/src/libregexp/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libregexp9.a diff --git a/src/libsec/mkfile b/src/libsec/mkfile index 9dcac09b..443d890e 100644 --- a/src/libsec/mkfile +++ b/src/libsec/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr DIRS=\ diff --git a/src/libsec/port/mkfile b/src/libsec/port/mkfile index eb0a7e02..ca37b0b4 100644 --- a/src/libsec/port/mkfile +++ b/src/libsec/port/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr LIB=libsec.a diff --git a/src/libthread/mkfile b/src/libthread/mkfile index 58a757b3..20ab5a8d 100644 --- a/src/libthread/mkfile +++ b/src/libthread/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libthread.a diff --git a/src/libventi/mkfile b/src/libventi/mkfile index 24a80aa1..517e355f 100644 --- a/src/libventi/mkfile +++ b/src/libventi/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libventi.a -- cgit v1.2.3