v7bugs.doc 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. .wh 0 hd
  2. .wh 60 fo
  3. .de hd
  4. 'sp 5
  5. ..
  6. .de fo
  7. 'bp
  8. ..
  9. .nr e 0 1
  10. .de ER
  11. .br
  12. .ne 20
  13. .sp 2
  14. .in 5
  15. .ti -5
  16. ERROR \\n+e:
  17. ..
  18. .de PS
  19. .sp
  20. .nf
  21. .in +5
  22. ..
  23. .de PE
  24. .sp
  25. .fi
  26. .in -5
  27. ..
  28. .sp 3
  29. .ce
  30. UNIX version 7 bugs
  31. .sp 3
  32. This document describes the UNIX version 7 errors fixed at the
  33. Vrije Universiteit, Amsterdam.
  34. Several of these are discovered at the VU.
  35. Others are quoted from a list of bugs distributed by BellLabs.
  36. .sp
  37. For each error the differences between the original and modified
  38. source files are given,
  39. as well as a test program.
  40. .ER
  41. C optimizer bug for unsigned comparison
  42. .sp
  43. The following C program caused an IOT trap, while it should not
  44. (compile with 'cc -O prog.c'):
  45. .PS
  46. unsigned i = 0;
  47. main() {
  48. register j;
  49. j = -1;
  50. if (i > 40000)
  51. abort();
  52. }
  53. .PE
  54. BellLabs suggests to make the following patch in c21.c:
  55. .PS
  56. /* modified /usr/src/cmd/c/c21.c */
  57. 189 if (r==0) {
  58. 190 /* next 2 lines replaced as indicated by
  59. 191 * Bell Labs bug distribution ( v7optbug )
  60. 192 p->back->back->forw = p->forw;
  61. 193 p->forw->back = p->back->back;
  62. 194 End of lines changed */
  63. 195 if (p->forw->op==CBR
  64. 196 || p->forw->op==SXT
  65. 197 || p->forw->op==CFCC) {
  66. 198 p->back->forw = p->forw;
  67. 199 p->forw->back = p->back;
  68. 200 } else {
  69. 201 p->back->back->forw = p->forw;
  70. 202 p->forw->back = p->back->back;
  71. 203 }
  72. 204 /* End of new lines */
  73. 205 decref(p->ref);
  74. 206 p = p->back->back;
  75. 207 nchange++;
  76. 208 } else if (r>0) {
  77. .PE
  78. Use the previous program to test before and after the modification.
  79. .ER
  80. The loader fails for large data or text portions
  81. .sp
  82. The loader 'ld' produces a "local symbol botch" error
  83. for the following C program.
  84. .PS
  85. int big1[10000] = {
  86. 1
  87. };
  88. int big2[10000] = {
  89. 2
  90. };
  91. main() {
  92. printf("loader is fine\\n");
  93. }
  94. .PE
  95. We have made the following fix:
  96. .PS
  97. /* original /usr/src/cmd/ld.c */
  98. 113 struct {
  99. 114 int fmagic;
  100. 115 int tsize;
  101. 116 int dsize;
  102. 117 int bsize;
  103. 118 int ssize;
  104. 119 int entry;
  105. 120 int pad;
  106. 121 int relflg;
  107. 122 } filhdr;
  108. /* modified /usr/src/cmd/ld.c */
  109. 113 /*
  110. 114 * The original Version 7 loader had problems loading large
  111. 115 * text or data portions.
  112. 116 * Why not include <a.out.h> ???
  113. 117 * then they would be declared unsigned
  114. 118 */
  115. 119 struct {
  116. 120 int fmagic;
  117. 121 unsigned tsize; /* not int !!! */
  118. 122 unsigned dsize; /* not int !!! */
  119. 123 unsigned bsize; /* not int !!! */
  120. 124 unsigned ssize; /* not int !!! */
  121. 125 unsigned entry; /* not int !!! */
  122. 126 unsigned pad; /* not int !!! */
  123. 127 unsigned relflg; /* not int !!! */
  124. 128 } filhdr;
  125. .PE
  126. .ER
  127. Floating point registers
  128. .sp
  129. When a program is swapped to disk if it needs more memory,
  130. then the floating point registers were not saved, so that
  131. it may have different registers when it is restarted.
  132. A small assembly program demonstrates this for the status register.
  133. If the error is not fixed, then the program generates an IOT error.
  134. A "memory fault" is generated if all is fine.
  135. .PS
  136. start: ldfps $7400
  137. 1: stfps r0
  138. mov r0,-(sp)
  139. cmp r0,$7400
  140. beq 1b
  141. 4
  142. .PE
  143. You have to dig into the kernel to fix it.
  144. The following patch will do:
  145. .PS
  146. /* original /usr/sys/sys/slp.c */
  147. 563 a2 = malloc(coremap, newsize);
  148. 564 if(a2 == NULL) {
  149. 565 xswap(p, 1, n);
  150. 566 p->p_flag |= SSWAP;
  151. 567 qswtch();
  152. 568 /* no return */
  153. 569 }
  154. /* modified /usr/sys/sys/slp.c */
  155. 590 a2 = malloc(coremap, newsize);
  156. 591 if(a2 == NULL) {
  157. 592 #ifdef FPBUG
  158. 593 /*
  159. 594 * copy floating point register and status,
  160. 595 * but only if you must switch processes
  161. 596 */
  162. 597 if(u.u_fpsaved == 0) {
  163. 598 savfp(&u.u_fps);
  164. 599 u.u_fpsaved = 1;
  165. 600 }
  166. 601 #endif
  167. 602 xswap(p, 1, n);
  168. 603 p->p_flag |= SSWAP;
  169. 604 qswtch();
  170. 605 /* no return */
  171. 606 }
  172. .PE
  173. .ER
  174. Floating point registers.
  175. .sp
  176. A similar problem arises when a process forks.
  177. The child will have random floating point registers as is
  178. demonstrated by the following assembly language program.
  179. The child process will die by an IOT trap and the father prints
  180. the message "child failed".
  181. .PS
  182. exit = 1.
  183. fork = 2.
  184. write = 4.
  185. wait = 7.
  186. start: ldfps $7400
  187. sys fork
  188. br child
  189. sys wait
  190. tst r1
  191. bne bad
  192. stfps r2
  193. cmp r2,$7400
  194. beq start
  195. 4
  196. child: stfps r2
  197. cmp r2,$7400
  198. beq ex
  199. 4
  200. bad: clr r0
  201. sys write;mess;13.
  202. ex: clr r0
  203. sys exit
  204. .data
  205. mess: <child failed\\n>
  206. .PE
  207. The same file slp.c should be patched as follows:
  208. .PS
  209. /* original /usr/sys/sys/slp.c */
  210. 499 /*
  211. 500 * When the resume is executed for the new process,
  212. 501 * here's where it will resume.
  213. 502 */
  214. 503 if (save(u.u_ssav)) {
  215. 504 sureg();
  216. 505 return(1);
  217. 506 }
  218. 507 a2 = malloc(coremap, n);
  219. 508 /*
  220. 509 * If there is not enough core for the
  221. 510 * new process, swap out the current process to generate the
  222. 511 * copy.
  223. 512 */
  224. /* modified /usr/sys/sys/slp.c */
  225. 519 /*
  226. 520 * When the resume is executed for the new process,
  227. 521 * here's where it will resume.
  228. 522 */
  229. 523 if (save(u.u_ssav)) {
  230. 524 sureg();
  231. 525 return(1);
  232. 526 }
  233. 527 #ifdef FPBUG
  234. 528 /* copy the floating point registers and status to child */
  235. 529 if(u.u_fpsaved == 0) {
  236. 530 savfp(&u.u_fps);
  237. 531 u.u_fpsaved = 1;
  238. 532 }
  239. 533 #endif
  240. 534 a2 = malloc(coremap, n);
  241. 535 /*
  242. 536 * If there is not enough core for the
  243. 537 * new process, swap out the current process to generate the
  244. 538 * copy.
  245. 539 */
  246. .PE
  247. .ER
  248. /usr/src/libc/v6/stat.c
  249. .sp
  250. Some system calls are changed from version 6 to version 7.
  251. A library of system call entries, that make a version 6 UNIX look like
  252. a version 7 system, is provided to enable you to run some
  253. useful version 7 utilities, like 'tar', on UNIX-6.
  254. The entry for 'stat' contained two bugs:
  255. the 24-bit file size was incorrectly converted to 32 bits
  256. (sign extension of bit 15)
  257. and the uid/gid fields suffered from sign extension.
  258. .sp
  259. Transferring your files from version 6 to version 7 using 'tar'
  260. will fail for all files for which
  261. .sp
  262. ( (size & 0100000) != 0 )
  263. .sp
  264. These two errors are fixed if stat.c is modified as follows:
  265. .PS
  266. /* original /usr/src/libc/v6/stat.c */
  267. 11 char os_size0;
  268. 12 short os_size1;
  269. 13 short os_addr[8];
  270. 49 buf->st_nlink = osbuf.os_nlinks;
  271. 50 buf->st_uid = osbuf.os_uid;
  272. 51 buf->st_gid = osbuf.os_gid;
  273. 52 buf->st_rdev = 0;
  274. /* modified /usr/src/libc/v6/stat.c */
  275. 11 char os_size0;
  276. 12 unsigned os_size1;
  277. 13 short os_addr[8];
  278. 49 buf->st_nlink = osbuf.os_nlinks;
  279. 50 buf->st_uid = osbuf.os_uid & 0377;
  280. 51 buf->st_gid = osbuf.os_gid & 0377;
  281. 52 buf->st_rdev = 0;
  282. .PE