clang-format
This commit is contained in:
@@ -51,59 +51,56 @@
|
||||
*
|
||||
* Calls vfs_open on progname and thus may destroy it.
|
||||
*/
|
||||
int
|
||||
runprogram(char *progname)
|
||||
{
|
||||
struct addrspace *as;
|
||||
struct vnode *v;
|
||||
vaddr_t entrypoint, stackptr;
|
||||
int result;
|
||||
int runprogram(char *progname) {
|
||||
struct addrspace *as;
|
||||
struct vnode *v;
|
||||
vaddr_t entrypoint, stackptr;
|
||||
int result;
|
||||
|
||||
/* Open the file. */
|
||||
result = vfs_open(progname, O_RDONLY, 0, &v);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
/* Open the file. */
|
||||
result = vfs_open(progname, O_RDONLY, 0, &v);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
/* We should be a new process. */
|
||||
KASSERT(proc_getas() == NULL);
|
||||
/* We should be a new process. */
|
||||
KASSERT(proc_getas() == NULL);
|
||||
|
||||
/* Create a new address space. */
|
||||
as = as_create();
|
||||
if (as == NULL) {
|
||||
vfs_close(v);
|
||||
return ENOMEM;
|
||||
}
|
||||
/* Create a new address space. */
|
||||
as = as_create();
|
||||
if (as == NULL) {
|
||||
vfs_close(v);
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
/* Switch to it and activate it. */
|
||||
proc_setas(as);
|
||||
as_activate();
|
||||
/* Switch to it and activate it. */
|
||||
proc_setas(as);
|
||||
as_activate();
|
||||
|
||||
/* Load the executable. */
|
||||
result = load_elf(v, &entrypoint);
|
||||
if (result) {
|
||||
/* p_addrspace will go away when curproc is destroyed */
|
||||
vfs_close(v);
|
||||
return result;
|
||||
}
|
||||
/* Load the executable. */
|
||||
result = load_elf(v, &entrypoint);
|
||||
if (result) {
|
||||
/* p_addrspace will go away when curproc is destroyed */
|
||||
vfs_close(v);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Done with the file now. */
|
||||
vfs_close(v);
|
||||
/* Done with the file now. */
|
||||
vfs_close(v);
|
||||
|
||||
/* Define the user stack in the address space */
|
||||
result = as_define_stack(as, &stackptr);
|
||||
if (result) {
|
||||
/* p_addrspace will go away when curproc is destroyed */
|
||||
return result;
|
||||
}
|
||||
/* Define the user stack in the address space */
|
||||
result = as_define_stack(as, &stackptr);
|
||||
if (result) {
|
||||
/* p_addrspace will go away when curproc is destroyed */
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Warp to user mode. */
|
||||
enter_new_process(0 /*argc*/, NULL /*userspace addr of argv*/,
|
||||
NULL /*userspace addr of environment*/,
|
||||
stackptr, entrypoint);
|
||||
/* Warp to user mode. */
|
||||
enter_new_process(0 /*argc*/, NULL /*userspace addr of argv*/,
|
||||
NULL /*userspace addr of environment*/, stackptr,
|
||||
entrypoint);
|
||||
|
||||
/* enter_new_process does not return. */
|
||||
panic("enter_new_process returned\n");
|
||||
return EINVAL;
|
||||
/* enter_new_process does not return. */
|
||||
panic("enter_new_process returned\n");
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user