Path: utzoo!utgpu!water!watmath!clyde!rutgers!husc6!bloom-beacon!athena.mit.edu!wesommer From: wesommer@athena.mit.edu (William E. Sommerfeld) Newsgroups: comp.unix.wizards Subject: /dev/text driver. Message-ID: <2054@bloom-beacon.MIT.EDU> Date: 17 Dec 87 18:18:07 GMT Sender: daemon@bloom-beacon.MIT.EDU Reply-To: wesommer@athena.mit.edu (William E. Sommerfeld) Organization: Massachusetts Institute of Technology Lines: 51 Recently, there was some discussion here about finding a way to locate the file which contains a process's text segment. Someone (Chris Torek?) suggested creating a /dev/text special device which did the appropriate magic. This sounded pretty easy to do, so I tried implementing it. For simplicity (I didn't want to allocate another major device number), I added it as part of the memory special device, with minor device ID 42. Unfortunately, BSD4.3+NFS (specifically, the UW version, which is what we're running here at Athena) seems to go out of its way to prevent the device open routine from patching the file descriptor table -- the new file descriptor is not actually initialized until well after the device open routine is through. I had to pass an additional argument (of a pointer to a vnode pointer) to the device open routine (called from ufs_open() in ufs/ufs_vnodeops.c). This function will do as the open routine: mmopen(dev, flag, xxx, vpp) dev_t dev; int flag; struct vnode **vpp; { register struct text *xp; register struct vnode *vp; if (minor(dev) != 42) return 0; /* minor dev 42 is /dev/text.. */ xp = u.u_procp->p_textp; if (xp == NULL) return ENOENT; vp = xp->x_vptr; /* this shouldn't happen.. */ if (vp == NULL) return ENOENT; if (flag & (FWRITE|FTRUNC)) return ETXTBSY; VN_HOLD(vp); VN_RELE(*vpp); *vpp = vp; return 0; } Don't forget to patch ufs/ufs_vnodeops, change machine/conf.c, and "mknod /dev/text c 3 42". Bill Sommerfeld wesommer@athena.mit.edu