commit 1b135a78054e05cd62dfa1a2606f93e3486f2b57 from: rsc date: Mon Apr 19 23:04:36 2004 UTC clean up when finished. don't set PLAN9 don't set PLAN9 commit - e15e6c08203eea8c32e95f42ad16c2aeb7fb65ba commit + 1b135a78054e05cd62dfa1a2606f93e3486f2b57 blob - 3aa9bb7071bc4062bb60867081e0d1c64a027319 blob + 7fb7ffde56754575afb5739f64590242e9fb5765 --- src/cmd/factotum/mkfile +++ src/cmd/factotum/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr TARG=factotum blob - d1b6938f26edbcbac3db03b8bafeb71b227f066c blob + 7f41dfabf4131f364c5f0a34a51bf5e316f85b0a --- src/cmd/graph/graph.c +++ src/cmd/graph/graph.c @@ -244,11 +244,6 @@ void limread(struct xy *p, int *argcp, char ***argvp){ } int -isdigit(char c){ - return '0'<=c && c<='9'; -} - -int numb(float *np, int *argcp, char ***argvp){ char c; blob - 4a45add104c46a54f8a0e4987600459da7e3616f blob + 13447d0a88fb91669e940826088fd1dd7bd1ec68 --- src/cmd/graph/mkfile +++ src/cmd/graph/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr TARG=graph blob - fd17abdd08f5e050fbf90d8d0f55912aa62e9814 blob + 38619325112fbf7ed049e9a5fb07ccf66737294d --- src/cmd/grep/mkfile +++ src/cmd/grep/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr # Calling this grep breaks a LOT. Like egrep on Linux. blob - 29b8bdb0d52764d3db494d971342c7b5303a5223 blob + 2894f1fbafa8a36b3dfec582b4a499e3786266a5 --- src/cmd/gzip/mkfile +++ src/cmd/gzip/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr HFILES=\ blob - d3bfd274979d1e0a53f30778300bd422bf83480a blob + dd43b0fb641d21e9cc24acbae66bf020edc84281 --- src/cmd/hoc/mkfile +++ src/cmd/hoc/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr TARG=hoc blob - 9b054053184763bc0deae327fad9903d2e9af914 blob + 6e8f52b9a73269284450685d670b69bed3a37bb8 --- src/cmd/mk/mkfile +++ src/cmd/mk/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr TARG=mk blob - a73bd6179148dfe3042c0a1d0d975f3f54e350d1 blob + dc33ac6380c07117539be010f0a3348a560fb983 --- src/cmd/plot/libplot/mkfile +++ src/cmd/plot/libplot/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../../.. <$PLAN9/src/mkhdr LIB=../libplot.a blob - cf4cf89e51649f9659b0990d3921741382228847 blob + 886659fa375007d712e2d805cb9e2d5d40fade2c --- src/cmd/plot/libplot/subr.c +++ 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) { blob - 0eb1a7955e7b6cb4b1b042b7bdc86bf1896465f9 blob + 77ebd7e1f30c39e9391b0acf3ccf5d2700e596c9 --- src/cmd/plot/mkfile +++ src/cmd/plot/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr TARG=plot blob - 967cbb3b5d36ccea0c2d6a902c984ea9ae42adc6 blob + 902ebf01da3aae9be84c5cf23ac28d62b7a441d4 --- src/cmd/plumb/mkfile +++ src/cmd/plumb/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr TARG=plumber plumb blob - c1440ce4aabe3375755812e8ff04dc8622d14d38 blob + f7d50e3f0702f8de7d3d54afbf6a722ff5e49051 --- src/cmd/rc/mkfile +++ src/cmd/rc/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr YACC=yacc -d blob - b5e8b11098ad1aa6743b6f0373853af1b4c931fe blob + 1bec50eff948215ecb68293c94376168346911a3 --- src/cmd/rio/mkfile +++ src/cmd/rio/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr OFILES=\ blob - aa9a59f444847cbd2311f2f3820ebe99fca18141 blob + 8402579d11146d8217775f037b8026b89c5a4c8c --- src/cmd/sam/mkfile +++ src/cmd/sam/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr TARG=sam blob - facc78d2ee0236bbe30f949a5365a1222c4bdf9b blob + 784549090b16d57a70701d1a6a8b1437cfa49ab0 --- src/cmd/samterm/mkfile +++ src/cmd/samterm/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr TARG=samterm blob - e9e600f9e883b3b995e3d90cce301ed8b3532b7e blob + b92c125f451ee2af860e59e56638b4dcafad909b --- src/cmd/spell/mkfile +++ src/cmd/spell/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr TARG=sprog blob - a4b7a29824e2142bf703a05c9bfe2fd9a42742a4 blob + ed464d0508d50335eaaf81079a41db72ac23fb22 --- src/cmd/vac/mkfile +++ src/cmd/vac/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr LIBFILES=\ blob - 99d8c98f494d38bd7ba12c2dd3a13c38178f24cd blob + bb31f50a151095fccb6dc2520939dcb29785acb8 --- src/cmd/venti/mkfile +++ src/cmd/venti/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr LIBOFILES=\ blob - 0a5d3b6725fd6557becff7f37dd62ba71e794f81 blob + 52b0d48f1d781b6410948486c2ea993c1695fdc4 --- src/lib9/fmt/mkfile +++ src/lib9/fmt/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libfmt.a blob - 6dfab74985504e2375b5f0180256bb66bf47cb60 blob + 00674b0a24fc8d5d34cd8d787dc131afcb652697 --- src/lib9/mkfile +++ src/lib9/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=lib9.a blob - 46c92fefacf217e3f4dd1ee977791f5cc3510560 blob + 030a6dbdb330e555923fb995ce61dc7b4f512008 --- src/lib9/utf/mkfile +++ src/lib9/utf/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libutf.a blob - 17a10a3c18a03163b8542662ceb54214ee5da7b5 blob + d131c4c71069707393951b3c9db9a80dede7f221 --- src/lib9p/mkfile +++ src/lib9p/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=lib9p.a blob - 49803b45115bbc4748cf779d51bdd867ef1c977c blob + d92e4d901a8af10c92dbf8a03712c34a094d0f37 --- src/libString/mkfile +++ src/libString/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libString.a blob - 376a41e29fa7e9c91d43113b278e7e83a4986b98 blob + bcf2aef9dcecc7a19cdf3b9c033281a385de624e --- src/libString/s_parse.c +++ 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, blob - c4501d0d3b2d07f8eb6da44b9d54fef60e678cf5 blob + 96f939e3ae492f650d41cf977cce687ccf7f2b42 --- src/libbin/mkfile +++ src/libbin/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libbin.a blob - e808b17869d586553ccf5db1a90891c9f44a6210 blob + 8c3d2601d8ce363b9b6ae952c62aa05c0b5edec9 --- src/libbio/mkfile +++ src/libbio/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libbio.a blob - 233dbef8add2fd9d58aa47d1fd12b81d250e50a2 blob + 35740d7d6b7bff5dcddf42b3020e308cf453ce91 --- src/libcomplete/mkfile +++ src/libcomplete/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libcomplete.a blob - 3b76a32ae4f27db0361185c64a259899eca988a1 blob + 1677c5b527325b73f1f37f259e6919655eace27f --- src/libdraw/chan.c +++ 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) { blob - 521c6d3f59f74354d98f7800f4a04e50b74ede7b blob + e734fd5f39da17bcebc49da293c89eb17bde31c5 --- src/libdraw/mkfile +++ src/libdraw/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libdraw.a blob - 074e9d075ec1c95214fdc70a7f13489f0a3c17aa blob + 973fb9b7f492b9671247e17e3ad521ee7e01e1c6 --- src/libflate/mkfile +++ src/libflate/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libflate.a blob - 7ca2301383324214ddbabe0473ce3c714b0b3cce blob + 6d47c32ea93d9e3fba698a01b8787c13f5450fc6 --- src/libframe/mkfile +++ src/libframe/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libframe.a blob - d4c8b49fe3573074cf606e298951aa860616f2e9 blob + 17d197ecdbb6221a93cd99baa3741f13c95214f9 --- src/libfs/mkfile +++ src/libfs/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libfs.a blob - bd4db82c241d704d93a39b9ce5d7d0b8f018027e blob + a70c5e76060993de650efc539c2ee45c83c7c72d --- src/libhttpd/mkfile +++ src/libhttpd/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libhttpd.a blob - b08999a621dfa081728a0615c13e48f291e2bbdd blob + 984967382ca7a3e8d7ede54984bc2849cab55c76 --- src/libip/mkfile +++ src/libip/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libip.a blob - 2838b392b01b5b92934293b71763d1f539ff57f6 blob + 7cf5c1f44869ca0a8bce621fb746776393d2b64d --- src/libmach/FreeBSD.c +++ 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; +} blob - a690a0005e4f6e7face674a51956bff423ca2da5 blob + 5f93c199811e54418b1039ce314a63ee73096cba --- src/libmach/mkfile +++ 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 + blob - 5e3998a27b19bf502ccf25a1a066adcf6fb49d82 blob + aab574626cec04a8f2d2ea0f245f9f167dc97a13 --- src/libmp/mkfile +++ src/libmp/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr DIRS=\ blob - 43670918f4a6bd0f16abec1f39624588989e07f4 blob + a9176dd3c15f9dd1e7abcc692e8e1c905edffa9f --- src/libmp/port/mkfile +++ src/libmp/port/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr LIB=libmp.a blob - 71d62a433c5a346bcc007203d4f6fc61a5e16cde blob + 71ed3e4efade28a81d6e430c49ce7a3d13109c5c --- src/libmux/mkfile +++ src/libmux/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libmux.a blob - eb6d0552d92654c6eda0d0d2a00fc5f30203c357 blob + 606113acfeb66433b31af03dc57b0b5a1c406600 --- src/libplumb/mkfile +++ src/libplumb/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libplumb.a blob - ad4822406e4cbf3e0790994e94174177de535e5f blob + f90c321bb4fdbf8c398164af2d0fa86063a9a8dd --- src/libregexp/mkfile +++ src/libregexp/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libregexp9.a blob - 9dcac09bbee46ae4e08838da3f2678367cb38ff6 blob + 443d890e9fd7e5f612399efb1412f4027f88bed3 --- src/libsec/mkfile +++ src/libsec/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr DIRS=\ blob - eb0a7e028c66fdfc1b36f96c96012aa247994f62 blob + ca37b0b459fe90cc68983269b73c631490b007b5 --- src/libsec/port/mkfile +++ src/libsec/port/mkfile @@ -1,4 +1,3 @@ -PLAN9=../../.. <$PLAN9/src/mkhdr LIB=libsec.a blob - 58a757b357ad528ede33acd4a070b9404da46089 blob + 20ab5a8d59071aee9a8f6afa43b6a405420a7e2d --- src/libthread/mkfile +++ src/libthread/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libthread.a blob - 24a80aa12b76cc518e7291a1cd539032001773e3 blob + 517e355f3584df05a2a6deb0bf3b0c4fe1a179a8 --- src/libventi/mkfile +++ src/libventi/mkfile @@ -1,4 +1,3 @@ -PLAN9=../.. <$PLAN9/src/mkhdr LIB=libventi.a