v7bugs.doc 6.2 KB

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