/* text.c 4.5 81/03/08 */
* relinquish use of the shared text segment
register struct text
*xp
;
register struct inode
*ip
;
if((xp
=u
.u_procp
->p_textp
) == NULL
)
if(--xp
->x_count
==0 && (ip
->i_mode
&ISVTX
)==0) {
xp
->x_rssize
-= vmemfree(tptopte(u
.u_procp
, 0), u
.u_tsize
);
sleep((caddr_t
)&xp
->x_poip
, PSWP
+1);
u
.u_procp
->p_textp
= NULL
;
* Attach to a shared text segment.
* If there is no shared text, just return.
* If there is, hook up to it:
* if it is not currently being used, it has to be read
* in from the inode (ip); the written bit is set to force it
* to be written out as appropriate.
* If it is being used, but is not currently in core,
* a swap has to be done to get it back.
register struct inode
*ip
;
register struct text
*xp
;
register struct text
*xp1
;
if(u
.u_exdata
.ux_tsize
== 0)
for (xp
= text
; xp
< textNTEXT
; xp
++) {
if ((xp
->x_count
> 0 || (xp
->x_iptr
->i_mode
&ISVTX
)) && xp
->x_iptr
== ip
) {
psignal(u
.u_procp
, SIGKILL
);
xp
->x_flag
= XLOAD
|XLOCK
;
ts
= clrnd(btoc(u
.u_exdata
.ux_tsize
));
if (vsxalloc(xp
) == NULL
) {
swkill(u
.u_procp
, "xalloc");
u
.u_count
= u
.u_exdata
.ux_tsize
;
u
.u_offset
= sizeof(u
.u_exdata
);
u
.u_procp
->p_flag
|= SKEEP
;
u
.u_procp
->p_flag
&= ~SKEEP
;
* Lock and unlock a text segment from swapping
register struct text
*xp
;
while(xp
->x_flag
&XLOCK
) {
sleep((caddr_t
)xp
, PSWP
);
* Wait for xp to be unlocked if it is currently locked.
register struct text
*xp
;
register struct text
*xp
;
xp
->x_flag
&= ~(XLOCK
|XWANT
);
* Decrement the in-core usage count of a shared text segment.
* When it drops to zero, free the core space.
register struct text
*xp
;
if (xp
==NULL
|| xp
->x_ccount
==0)
if (--xp
->x_ccount
== 0) {
if (xp
->x_flag
& XWRIT
) {
vsswap(p
, tptopte(p
, 0), CTEXT
, 0, xp
->x_size
, (struct dmap
*)0);
swap(p
, xp
->x_ptdaddr
, (caddr_t
)tptopte(p
, 0),
xp
->x_size
* sizeof (struct pte
),
B_WRITE
, B_PAGET
, swapdev
, 0);
xp
->x_rssize
-= vmemfree(tptopte(p
, 0), xp
->x_size
);
* free the swap image of all unused saved-text text segments
* which are from device dev (used by umount system call).
register struct text
*xp
;
for (xp
= text
; xp
< textNTEXT
; xp
++)
if (xp
->x_iptr
!=NULL
&& dev
==xp
->x_iptr
->i_dev
)
* remove a shared text segment from the text table, if possible.
register struct inode
*ip
;
register struct text
*xp
;
if ((ip
->i_flag
&ITEXT
)==0)
for (xp
= text
; xp
< textNTEXT
; xp
++)
* remove text image from the text table.
* the use count must be zero.
register struct text
*xp
;
register struct inode
*ip
;
* Add a process to those sharing a text segment by
* getting the page tables and then linking to x_caddr.
register struct text
*xp
= p
->p_textp
;
p
->p_xlink
= xp
->x_caddr
;
register struct text
*xp
= p
->p_textp
;
xp
->x_caddr
= p
->p_xlink
;
for (q
= xp
->x_caddr
; q
->p_xlink
; q
= q
->p_xlink
)
* Replace p by q in a text incore linked list.
* Used by vfork(), internally.
register struct text
*xp
= q
->p_textp
;
q
->p_xlink
= xp
->x_caddr
;