(. [SVID 85]). - . 158 setjmp, longjmp, , setjmp, , 1. 6.4.5 -   , - () . - , , , - , , - read. , - . , , , , - ; - , , - , (, - , ). " ", . +--------------------------------------------------------+ | fubyte: # | | # | | prober $3,$1,*4(ap) # ? | | beql eret # | | movzbl *4(ap),r0 | | ret | | eret: | | mnegl $1,r0 # (-1) | | ret | +--------------------------------------------------------+ 6.17. VAX 6.17 VAX - - . prober , , ( - + 4), ( 3), , eret, -1 ; . , , - 0 . 1 - ( fubyte). 6.5  , - , , - . , - 159 , , . ; , , . , . , : * , - * ( , , ) * * * () , : - - - - , * , , . : , , , - , , , , . , exec, - , , , , , . - - , ( - ), - ( 9). 6.5.1  - , , - - - - ( iget iput). , , , . , , , , - . 6.5.2  ( allocreg, 6.18) fork, exec shmget ( ). , , - . - , - , ( ). 160 ( , exec), allocreg , . , . - , unlink, 7.5. allocreg . +------------------------------------------------------------+ | allocreg /* | | */ | | : (1) | | (2) | | : | | { | | ; | | ; | | ; | | ( ) | | ; | | ; | | ( ); | | } | +------------------------------------------------------------+ 6.18. 6.5.3  - fork, exec shmat ( attachreg, 6.19). , . , , , , - , , - . - , - . , - - 8 - , 1 7.5M . , , , , - . , attachreg , . - , growreg (. ) ; - . , - , . , , 0 (- ) , 7 ( 6.20). 161 +------------------------------------------------------------+ | attachreg /* */ | | : (1) - | | () | | (2) , | | | | (3) ,| | -| | | | (4) | | : | | | | { | | - | | ; | | : | | ; | | ; | | ; | | | | ; | | ; | | -| | ; | | | | ; | | ( -| | ); | | } | +------------------------------------------------------------+ 6.19. , (0) - (9 ). 6.5.4  - sbrk. - ( ) . growreg (- 6.21). , - - - . growreg , ; , - , - . growreg : sbrk . ( ) . - 162 +---------+-------------+--------+ | | | | | | -| | | | | | | | | | +---------+-------------+--------+ | | 0 | 9 | +----+----+-------------+--------+ +----+ v +-------------+ | | +-------------+ | | +-------------+ | 846K | +-------------+ | 752K | +-------------+ | 341K | +-------------+ | 484K | +-------------+ | 976K | +-------------+ | 342K | +-------------+ | 779K | +-------------+ 6.20. . . , ( ) , . - - growreg; , (. 9). - , , - . (, - ). , , - 128 6 - 1 (1 ). - 134 135 - 1 - , - , . , - . 6.22. 6.5.5  , , 163 +------------------------------------------------------------+ | growreg /* */ | | : (1) | | | | (2) , - | | ( | | , - | | ) | | : | | { | | ( ) | | { | | ; | | (); | | ( | | ) | | { | | ; | | | | ; | | } | | } | | /* */ | | { | | ; | | ; | | } | | | | | | ; | | - | | ; | | } | +------------------------------------------------------------+ 6.21. "" - exec, (. 9). - , , . , - , "" ( - 6.20). , , - (memory fault) ( ). ( 0) . , , , , . loadreg ( 6.23) , - , , , . 164 +-------+----------+------+ +-------+----------+------+ | | -| - | | | -| - | | -| | | | -| | | | | - | | | | - | | | - | | -| | - | | -| | | | | | | | | +-------+----------+------+ +-------+----------+------+ | | | | | | | | +-------+----------+------+ +-------+----------+------+ | | | | | | | | +-------+----------+------+ +-------+----------+------+ | | 128K | 6K | | | 128K | 7K | +---+---+----------+------+ +---+---+----------+------+ +--+ +--+ v v +-------------+ +-------------+ | 342K | | 342K | +-------------+ +-------------+ | 779K | | 779K | +-------------+ +-------------+ | 846K | | 846K | +-------------+ +-------------+ | 752K | | 752K | +-------------+ +-------------+ | 341K | | 341K | +-------------+ +-------------+ | 484K | | 484K | +-------------+ +-------------+ | | -->| 976K | +-------------+ +-------------+ | | | | +-------------+ +-------------+ | | | | +-------------+ +-------------+ 6.22. 1 " ", read. , - , , , , - - . , , , exec 9. - , , . loadreg , , (", "). , , 7K - , 0, - 1 ( 6.24). 165 +------------------------------------------------------------+ | loadreg /* */ | | : (1) | | | | (2) | | (3) | | (4) -| | | | (5) | | : | | { | | (| | growreg); | | " "; | | ; | | | | : | | , -| | ; | | ; | | , , ; | | ( - | | read); | | ; | | " -| | "; | | , -| | ; | | } | +------------------------------------------------------------+ 6.23. 0 allocreg attachreg. - loadreg, growreg - -, 1 , -, - growreg . : 7 , , ( ), - 1K. +-------+----------+------+ +-------+----------+------+ | | -| - | | | -| - | | -| | | | -| | | | | - | | | | - | | | - | | -| | - | | -| | | | | | | | | +-------+----------+------+ +-------+----------+------+ | --- | | 0 | | | 0 | 8 | +-------+----------+------+ +---+---+----------+------+ () - +--+ | v 166 +-------------+ | | +-------------+ | 779K | +-------+----------+------+ +-------------+ | | -| - | | 846K | | -| | | +-------------+ | | - | | | 752K | | - | | -| +-------------+ | | | | | 341K | +-------+----------+------+ +-------------+ | | 0 | 1 | | 484K | +---+---+----------+------+ +-------------+ +--+ | 976K | | +-------------+ v | 794K | +-------------+ +-------------+ | | | | +-------------+ +-------------+ () , () - - growreg ( growreg) 6.24. () +------------------------------------------------------------+ | freereg /* */| | : () | | : | | { | | ( - | | ) | | { | | /* */| | ; | | ( ) | | ; | | ; | | } | | ( ) | | ( iput); | | ; | | ;| | ; | | ; | | ; | | } | +------------------------------------------------------------+ 6.25. 167 6.5.6  , ( 6.25). , - iput, , - allocreg. - , . , , , 6.22. , 7 . +------------------------------------------------------------+ | detachreg /* */ | | : | | | | : | | { | | , | | , | | , ; | | ; | | ; | | ( -| | ) | | ( freereg); | | /* | | 0, - | | */ | | { | | ( - | | ); | | ; | | } | | } | +------------------------------------------------------------+ 6.26. 6.5.7  exec, exit shmdt ( ). - , - ( detachreg, 6.26). , ( freereg). , , - . 0 ( , 7.5), freereg. - , , (. 7.5), - . 168 +--------------+ +-------------+ | +-------------->| | +--------------+ +------->+-------------+ | +----+ | +--------------+ | | +-------------+ | +--+ +-|------->| +-+ +--------------+ | | +-------------+ | - A | | | - | | +-------------+ | +---|------->| +-|-+ - +--------------+ | +-------------+ | | | +------+ | | +--------------+ +-------------+ | | | +-------------->| |<+ | +--------------+ +-------------+ | | +------+ | +--------------+ | +-------------+ | B +------->| |<--+ +-------------+ 6.27. +------------------------------------------------------------+ | dupreg /* | | */ | | : -| | | | : , - | | | | { | | ( ) | | /* - | | , - | | attachreg */ | | ( ); | | ( allocreg); | | | | -| | ; | | ; | | "" -| | ; | | ( ); | | } | +------------------------------------------------------------+ 6.28. 6.5.8  fork , - . ( - ), ; , - . - - , , 169 . - 6.27, A fork B . A - , B A. ( ), B . - , ( 9). 6.28 - (dupreg). 6.6  , - " " - , , - " ". - , "- " " " - " " . +-------------------------------+ | 2 | | - | | | | | | - | | | | | -+-------------------------------+ ^ | 1 | | | - | | | | | |