#include <sys/exec_elf.h>
-/* a.out routines */
-int read_header_aout(const char *exec_hdr, size_t exec_len, int *sep_id,
- vir_bytes *text_bytes, vir_bytes *data_bytes,
- vir_bytes *bss_bytes, phys_bytes *tot_bytes, vir_bytes *pc,
- int *hdrlenp);
-
/* ELF routines */
int read_header_elf(const char *exec_hdr, int hdr_len,
vir_bytes *text_vaddr, phys_bytes *text_paddr,
static int exec_restart(int proc_e, int result, vir_bytes pc);
static int read_seg(struct exec_info *execi, off_t off,
int proc_e, int seg, vir_bytes seg_addr, phys_bytes seg_bytes);
-static int load_aout(struct exec_info *execi);
static int load_elf(struct exec_info *execi);
/* Array of loaders for different object formats */
static struct exec_loaders {
int (*load_object)(struct exec_info *);
} const exec_loaders[] = {
- { load_aout },
{ load_elf },
{ NULL }
};
return exec_restart(proc_e, OK, execi.pc);
}
-static int load_aout(struct exec_info *execi)
-{
- int r;
- int hdrlen, sep_id, load_text, allow_setuid;
- vir_bytes text_bytes, data_bytes, bss_bytes;
- phys_bytes tot_bytes;
- off_t off;
- uid_t new_uid;
- gid_t new_gid;
- int proc_e;
-
- assert(execi != NULL);
- assert(execi->image != NULL);
-
- proc_e = execi->proc_e;
-
- /* Read the file header and extract the segment sizes. */
- r = read_header_aout(execi->image, execi->image_len, &sep_id,
- &text_bytes, &data_bytes, &bss_bytes,
- &tot_bytes, &execi->pc, &hdrlen);
- if (r != OK)
- {
- return r;
- }
-
- new_uid= getuid();
- new_gid= getgid();
- allow_setuid = 0;
-
- /* XXX what should we use to identify the executable? */
- r= exec_newmem(proc_e, 0 /*text_addr*/, text_bytes,
- 0 /*data_addr*/, data_bytes + bss_bytes, tot_bytes,
- execi->frame_len, sep_id, 0 /*is_elf*/, 0 /*dev*/, proc_e /*inum*/, 0 /*ctime*/,
- execi->progname, new_uid, new_gid, &execi->stack_top, &load_text,
- &allow_setuid);
- if (r != OK)
- {
- printf("RS: load_aout: exec_newmem failed: %d\n", r);
- exec_restart(proc_e, r, execi->pc);
- return r;
- }
-
- off = hdrlen;
-
- /* Read in text and data segments. */
- if (load_text) {
- r= read_seg(execi, off, proc_e, T, 0, text_bytes);
- if (r != OK)
- {
- printf("RS: load_aout: read_seg failed: %d\n", r);
- exec_restart(proc_e, r, execi->pc);
- return r;
- }
- }
- else
- printf("RS: load_aout: not loading text segment\n");
-
- off += text_bytes;
- r= read_seg(execi, off, proc_e, D, 0, data_bytes);
- if (r != OK)
- {
- printf("RS: load_aout: read_seg failed: %d\n", r);
- exec_restart(proc_e, r, execi->pc);
- return r;
- }
-
- return OK;
-}
-
static int load_elf(struct exec_info *execi)
{
int r;
static void clo_exec(struct fproc *rfp);
static int read_seg(struct vnode *vp, off_t off, int proc_e, int seg,
vir_bytes seg_addr, phys_bytes seg_bytes);
-static int load_aout(struct exec_info *execi);
static int load_elf(struct exec_info *execi);
static int stack_prepare_elf(struct exec_info *execi,
char *curstack, size_t *frame_len, vir_bytes *vsp, int *extrabase);
};
static const struct exec_loaders exec_loaders[] = {
- { load_aout, NULL },
{ load_elf, stack_prepare_elf },
{ NULL, NULL }
};
return(r);
}
-/*===========================================================================*
- * load_aout *
- *===========================================================================*/
-static int load_aout(struct exec_info *execi)
-{
- int r;
- struct vnode *vp;
- int proc_e;
- off_t off;
- int hdrlen;
- int sep_id;
- vir_bytes text_bytes, data_bytes, bss_bytes;
- phys_bytes tot_bytes; /* total space for program, including gap */
-
- assert(execi != NULL);
- assert(execi->hdr != NULL);
- assert(execi->vp != NULL);
-
- proc_e = execi->proc_e;
- vp = execi->vp;
-
- /* Read the file header and extract the segment sizes. */
- r = read_header_aout(execi->hdr, execi->vp->v_size, &sep_id,
- &text_bytes, &data_bytes, &bss_bytes,
- &tot_bytes, &execi->pc, &hdrlen);
- if (r != OK) return(r);
-
- r = exec_newmem(proc_e, 0 /* text_addr */, text_bytes,
- 0 /* data_addr */, data_bytes + bss_bytes, tot_bytes,
- execi->frame_len, sep_id, 0 /* is_elf */, vp->v_dev,
- vp->v_inode_nr, execi->sb.st_ctime, execi->progname,
- execi->new_uid, execi->new_gid,
- &execi->stack_top, &execi->load_text, &execi->setugid);
-
- if (r != OK) {
- printf("VFS: load_aout: exec_newmem failed: %d\n", r);
- return(r);
- }
-
- off = hdrlen;
-
- /* Read in text and data segments. */
- if (execi->load_text)
- r = read_seg(vp, off, proc_e, T, 0, text_bytes);
- off += text_bytes;
- if (r == OK)
- r = read_seg(vp, off, proc_e, D, 0, data_bytes);
-
- return(r);
-}
-
static int stack_prepare_elf(struct exec_info *execi, char *frame, size_t *framelen,
vir_bytes *newsp, int *extrabase)
{