dgg@ci-dandelion.UUCP (Dave Grubbs) (11/01/86)
A couple weeks ago, I found this in unix-wizards and couldn't believe it, so I saved it for the day I would have time to check it out: > Path: ci-dandelion!talcott! ... !brl-smoke!smoke!ron@BRL.ARPA > From: ron@BRL.ARPA > Newsgroups: net.unix-wizards > Subject: brl-vgr Bug Report > Date: 13 Oct 86 23:03:55 GMT > > Subject: Warning to those who would change proc.h > Index: sys/h/proc.h 4.3BSD > > Description: > Changing the length of the proc structure so that it is not > double word aligned anymore will cause the system to crash > in bizarre ways. > Repeat-By: > Add a word to the proc structure and then put a load on the > system. Soon things like ps will stop working and then the > whole machine will experience a strange trap. > Fix: > 1. Don't change the proc structure. > 2. If you do, pad it out to the next double word. > I still don't believe it. I worked with System V for a year as a developer, I worked on Project Athena for two years and changed all sorts of things without showing this sort of problem. I now work on Ultrix source code, which has been hacked even more, by DEC and by me and it works perfectly. The reason is pretty obvious. The C compiler on all the SysV, 4.2, 4.3 and Ultrix systems I have worked on have all aligned every field in a structure to their own size. (i.e. longs on double word, words on word boundaries) The proc structure starts with a (struct proc *), which means that all the array elements (each of which is a structure) start on long word boundaries, no matter what the structure ends with or what size the last element is. Run the following program: Note the results. struct a { struct a *ap; char ac; }; struct b { struct b *bp; short bc; }; struct c { struct c *cp; long cc; }; main() { struct a aa[10]; struct b bb[10]; struct c cc[10]; printf ("A: Element size(%d) array size(%d)\n", sizeof(aa[0]), sizeof(aa)); printf ("B: Element size(%d) array size(%d)\n", sizeof(bb[0]), sizeof(bb)); printf ("C: Element size(%d) array size(%d)\n", sizeof(cc[0]), sizeof(cc)); } Output: A: Element size(8) array size(80) B: Element size(8) array size(80) C: Element size(8) array size(80) Something else must be wrong with whatever you did to the proc structure.