ssym = addr; bcopy(&x.a_syms, addr, sizeof(x.a_syms)); addr += sizeof(x.a_syms); printf("+[%ld", x.a_syms); if (read(io, addr, x.a_syms) != x.a_syms) goto shread; addr += x.a_syms;
if(x.a_syms){ ssym = addr; bcopy(&x.a_syms, addr, sizeof(x.a_syms)); addr += sizeof(x.a_syms); printf("+[%ld", x.a_syms); if (read(io, addr, x.a_syms) != x.a_syms) goto shread; addr += x.a_syms;
exec(path, loadaddr, howto)	char *path;	void *loadaddr;	int howto;{	register int io;#ifndef INSECURE	struct stat sb;#endif	struct exec x;	int i;	register char *addr;#ifdef EXEC_DEBUG	char *daddr, *etxt;#endif	io = open(path, 0);	if (io < 0)		return;#ifndef INSECURE	(void) fstat(io, &sb);	if (sb.st_uid || (sb.st_mode & 2)) {		printf("non-secure file, will not load\n");		close(io);		errno = EPERM;		return;	}#endif	i = read(io, (char *)&x, sizeof(x));	if (i != sizeof(x) ||	    N_BADMAG(x)) {		errno = EFTYPE;		return;	}#ifdef EXEC_DEBUG	printf("\nstruct exec {%lx, %lx, %lx, %lx, %lx, %lx, %lx, %lx}\n",		x.a_midmag, x.a_text, x.a_data, x.a_bss, x.a_syms,		x.a_entry, x.a_trsize, x.a_drsize);#endif        /* Text */	printf("%ld", x.a_text);	addr = loadaddr;	i = x.a_text;	if (N_GETMAGIC(x) == ZMAGIC) {		bcopy((char *)&x, addr, sizeof x);		addr += sizeof x;		i -= sizeof x;	}	if (read(io, (char *)addr, i) != i)		goto shread;	addr += i;#ifdef EXEC_DEBUG	printf("\ntext {%x, %x, %x, %x}\n",		addr[0], addr[1], addr[2], addr[3]);	etxt = addr;#endif	if (N_GETMAGIC(x) == NMAGIC)		while ((long)addr & (N_PAGSIZ(x) - 1))			*addr++ = 0;        /* Data */#ifdef EXEC_DEBUG	daddr = addr;#endif	printf("+%ld", x.a_data);	if (read(io, addr, x.a_data) != x.a_data)		goto shread;	addr += x.a_data;        /* Bss */	printf("+%ld", x.a_bss);	for (i = 0; i < x.a_bss; i++)		*addr++ = 0;        /* Symbols */	ssym = addr;	bcopy(&x.a_syms, addr, sizeof(x.a_syms));	addr += sizeof(x.a_syms);	printf("+[%ld", x.a_syms);	if (read(io, addr, x.a_syms) != x.a_syms)		goto shread;	addr += x.a_syms;	if (read(io, &i, sizeof(int)) != sizeof(int))		goto shread;	bcopy(&i, addr, sizeof(int));	if (i) {		i -= sizeof(int);		addr += sizeof(int);		if (read(io, addr, i) != i)                	goto shread;		addr += i;	}	/* and that many bytes of string table */	printf("+%d]", i);	close(io);#define	round_to_size(x) \	(((int)(x) + sizeof(int) - 1) & ~(sizeof(int) - 1))        esym = (char *)round_to_size(addr - (char *)loadaddr);#undef round_to_size	/* and note the end address of all this	*/	printf(" total=0x%lx", (u_long)addr);/* XXX - Hack alert!   This is no good, loadaddr is passed into   machdep_start(), and it should do whatever   is needed.	x.a_entry += (long)loadaddr;*/	printf(" start=0x%lx\n", x.a_entry);#ifdef EXEC_DEBUG        printf("loadaddr=%p etxt=%p daddr=%p ssym=%p esym=%p\n",	    	loadaddr, etxt, daddr, ssym, esym);        printf("\n\nReturn to boot...\n");        getchar();#endif	machdep_start((char *)x.a_entry, howto, loadaddr, ssym, esym);	/* exec failed */	errno = ENOEXEC;	return;shread:	close(io);	errno = EIO;	return;}