/* kern_exec.c 4.4 83/06/14 */
#include "../machine/reg.h"
#include "../machine/pte.h"
#include "../machine/psl.h"
* exec system call, with and without environments.
((struct execa
*)u
.u_ap
)->envp
= NULL
;
register struct execa
*uap
;
char cfname
[MAXCOMLEN
+ 1];
if ((ip
= namei(uchar
, LOOKUP
, 1)) == NULL
)
if ((u
.u_procp
->p_flag
&STRC
) && access(ip
, IREAD
))
if ((ip
->i_mode
& IFMT
) != IFREG
||
(ip
->i_mode
& (IEXEC
|(IEXEC
>>3)|(IEXEC
>>6))) == 0) {
* Read in first few bytes of file for segment sizes, ux_mag:
* 413 = demand paged RO text
* Also an ASCII line beginning with #! is
* the file name of a ``shell'' and arguments may be prepended
* to the argument list if given here.
* SHELL NAMES ARE LIMITED IN LENGTH.
* ONLY ONE ARGUMENT MAY BE PASSED TO THE SHELL FROM
u
.u_exdata
.ux_shell
[0] = 0; /* for zero length files */
u
.u_error
= rdwri(UIO_READ
, ip
, (caddr_t
)&u
.u_exdata
, sizeof (u
.u_exdata
),
if (u
.u_count
> sizeof(u
.u_exdata
) - sizeof(u
.u_exdata
.Ux_A
) &&
u
.u_exdata
.ux_shell
[0] != '#') {
switch (u
.u_exdata
.ux_mag
) {
u
.u_exdata
.ux_dsize
+= u
.u_exdata
.ux_tsize
;
if (u
.u_exdata
.ux_tsize
== 0) {
if (u
.u_exdata
.ux_shell
[0] != '#' ||
u
.u_exdata
.ux_shell
[1] != '!' ||
cp
= &u
.u_exdata
.ux_shell
[2]; /* skip "#!" */
while (cp
< &u
.u_exdata
.ux_shell
[SHSIZE
]) {
cp
= &u
.u_exdata
.ux_shell
[2];
while (*cp
&& *cp
!= ' ')
bcopy((caddr_t
)cp
, (caddr_t
)cfarg
, SHSIZE
);
if (u
.u_dent
.d_namlen
> MAXCOMLEN
)
u
.u_dent
.d_namlen
= MAXCOMLEN
;
bcopy((caddr_t
)u
.u_dent
.d_name
, (caddr_t
)cfname
,
(unsigned)(u
.u_dent
.d_namlen
+ 1));
ip
= namei(schar
, LOOKUP
, 1);
* Collect arguments on "file" in swap space.
uap
= (struct execa
*)u
.u_ap
;
if ((bno
= rmalloc(argmap
, (long)ctod(clrnd((int)btoc(NCARGS
))))) == 0) {
swkill(u
.u_procp
, "exece");
if (uap
->argp
) for (;;) {
if (indir
&& (na
== 1 || na
== 2 && sharg
))
ap
= fuword((caddr_t
)uap
->argp
);
if (ap
==NULL
&& uap
->envp
) {
if ((ap
= fuword((caddr_t
)uap
->envp
)) == NULL
)
if (indir
&& na
== 2 && sharg
!= NULL
)
else if ((c
= fubyte((caddr_t
)ap
++)) < 0)
if (nc
% (CLSIZE
*NBPG
) == 0) {
bp
= getblk(argdev
, bno
+ ctod(nc
/ NBPG
),
nc
= (nc
+ NBPW
-1) & ~(NBPW
-1);
u
.u_dent
.d_namlen
= strlen(cfname
);
bcopy((caddr_t
)cfname
, (caddr_t
)u
.u_dent
.d_name
,
(unsigned)(u
.u_dent
.d_namlen
+ 1));
getxfile(ip
, nc
+ (na
+4)*NBPW
, uid
, gid
);
for (c
= 0; c
< nc
; c
+= CLSIZE
*NBPG
) {
bp
= baddr(argdev
, bno
+ ctod(c
/ NBPG
), CLSIZE
*NBPG
);
bp
->b_flags
|= B_AGE
; /* throw away */
bp
->b_flags
&= ~B_DELWRI
; /* cancel io */
ucp
= USRSTACK
- nc
- NBPW
;
ap
= ucp
- na
*NBPW
- 3*NBPW
;
(void) suword((caddr_t
)ap
, na
-ne
);
(void) suword((caddr_t
)ap
, 0);
(void) suword((caddr_t
)ap
, ucp
);
if (nc
% (CLSIZE
*NBPG
) == 0) {
bp
= bread(argdev
, bno
+ ctod(nc
/ NBPG
),
bp
->b_flags
|= B_AGE
; /* throw away */
bp
->b_flags
&= ~B_DELWRI
; /* cancel io */
(void) subyte((caddr_t
)ucp
++, (c
= *cp
++));
(void) suword((caddr_t
)ap
, 0);
rmfree(argmap
, (long)ctod(clrnd((int) btoc(NCARGS
))), bno
);
* Read in and set up memory for executed file.
getxfile(ip
, nargc
, uid
, gid
)
register struct inode
*ip
;
register size_t ts
, ds
, ss
;
if (u
.u_exdata
.ux_mag
== 0413)
if (u
.u_exdata
.ux_tsize
!=0 && (ip
->i_flag
&ITEXT
)==0 &&
register struct file
*fp
;
for (fp
= file
; fp
< fileNFILE
; fp
++) {
if (fp
->f_type
== DTYPE_INODE
&&
(struct inode
*)fp
->f_data
== ip
&&
* Compute text and data sizes and make sure not too large.
ts
= clrnd(btoc(u
.u_exdata
.ux_tsize
));
ds
= clrnd(btoc((u
.u_exdata
.ux_dsize
+u
.u_exdata
.ux_bsize
)));
ss
= clrnd(SSIZE
+ btoc(nargc
));
if (chksize((unsigned)ts
, (unsigned)ds
, (unsigned)ss
))
* Make sure enough space to start process.
if (swpexpand(ds
, ss
, &u
.u_cdmap
, &u
.u_csmap
) == NULL
)
* At this point, committed to the new image!
* Release virtual memory resources of old process, and
* initialize the virtual memory of the new process.
* If we resulted from vfork(), instead wakeup our
* parent who will set SVFDONE when he has taken back
if ((u
.u_procp
->p_flag
& SVFORK
) == 0)
u
.u_procp
->p_flag
&= ~SVFORK
;
u
.u_procp
->p_flag
|= SKEEP
;
wakeup((caddr_t
)u
.u_procp
);
while ((u
.u_procp
->p_flag
& SVFDONE
) == 0)
sleep((caddr_t
)u
.u_procp
, PZERO
- 1);
u
.u_procp
->p_flag
&= ~(SVFDONE
|SKEEP
);
u
.u_procp
->p_flag
&= ~(SPAGI
|SSEQL
|SUANOM
|SOUSIG
);
u
.u_procp
->p_flag
|= pagi
;
(char *)ctob(dptov(u
.u_procp
, 0)),
(int)u
.u_exdata
.ux_dsize
,
(int)(sizeof(u
.u_exdata
)+u
.u_exdata
.ux_tsize
),
if (pagi
&& u
.u_procp
->p_textp
)
vinifod((struct fpte
*)dptopte(u
.u_procp
, 0),
PG_FTEXT
, u
.u_procp
->p_textp
->x_iptr
,
(long)(1 + ts
/CLSIZE
), (int)btoc(u
.u_exdata
.ux_dsize
));
/* THIS SHOULD BE DONE AT A LOWER LEVEL, IF AT ALL */
#include "../vax/mtpr.h" /* XXX */
swkill(u
.u_procp
, "i/o error mapping pages");
* set SUID/SGID protections, if no tracing
if ((u
.u_procp
->p_flag
&STRC
)==0) {
psignal(u
.u_procp
, SIGTRAP
);
* Clear registers on exec
register struct proc
*p
= u
.u_procp
;
* Reset caught signals. Held signals
* remain held through p_sigmask.
p
->p_sigcatch
&= ~(1 << (i
- 1));
/* should pass args to init on the stack */
for (rp
= &u
.u_ar0
[0]; rp
< &u
.u_ar0
[16];)
u
.u_ar0
[PC
] = u
.u_exdata
.ux_entloc
+2;
{ register struct regs
*r
= (struct regs
*)u
.u_ar0
;
for (i
= 0; i
< 8; i
++) {
if (&r
->r_areg
[i
] != &r
->r_sp
)
r
->r_pc
= u
.u_exdata
.ux_entloc
;
for (i
=0; i
<NOFILE
; i
++) {
if (u
.u_pofile
[i
]&UF_EXCLOSE
) {
u
.u_pofile
[i
] &= ~UF_MAPPED
;
* Remember file name for accounting.
bcopy((caddr_t
)u
.u_dent
.d_name
, (caddr_t
)u
.u_comm
,
(unsigned)(u
.u_dent
.d_namlen
+ 1));
u
.u_eosys
= REALLYRETURN
;