execve(): clear host user-space PTEs before context switching
This commit is contained in:
@ -1217,18 +1217,57 @@ int main_loop(int fd, int cpu, pthread_mutex_t *lock)
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
struct program_load_desc *desc;
|
struct program_load_desc *desc;
|
||||||
struct remote_transfer trans;
|
struct remote_transfer trans;
|
||||||
|
FILE *fp;
|
||||||
|
int status;
|
||||||
|
char path[2048];
|
||||||
|
char *filename;
|
||||||
|
|
||||||
/* Load descriptor phase */
|
/* Load descriptor phase */
|
||||||
case 1:
|
case 1:
|
||||||
if (load_elf_desc((char *)w.sr.args[1], &desc) != 0) {
|
|
||||||
|
filename = (char *)w.sr.args[1];
|
||||||
|
|
||||||
|
/* Is filename without path? */
|
||||||
|
if (0 && strncmp(filename, "/", 1)
|
||||||
|
//&& strncmp(filename, ".", 1)
|
||||||
|
) {
|
||||||
|
|
||||||
|
char *PATH = getenv("PATH");
|
||||||
|
fprintf(stderr, "PATH: %s\n", PATH);
|
||||||
|
|
||||||
|
/* Open command for reading. */
|
||||||
|
sprintf(path, "/usr/bin/which %s", filename);
|
||||||
|
fp = popen(path, "r");
|
||||||
|
if (fp == NULL) {
|
||||||
|
fprintf(stderr, "execve(): failed to run which\n" );
|
||||||
|
goto return_execve1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Read the output a line at a time - output it. */
|
||||||
|
if (fgets(path, sizeof(path)-1, fp) == NULL) {
|
||||||
|
fprintf(stderr, "execve(): failed to read which\n" );
|
||||||
|
pclose(fp);
|
||||||
|
goto return_execve1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* close */
|
||||||
|
pclose(fp);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sprintf(path, "%s", filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
__dprintf("execve: filename: %s\n", filename);
|
||||||
|
__dprintf("execve: LD_LIBRARY_PATH: %s\n", getenv("LD_LIBRARY_PATH") ? getenv("LD_LIBRARY_PATH") : "(empty)");
|
||||||
|
|
||||||
|
if (load_elf_desc(path, &desc) != 0) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"execve(): error loading ELF for file %s\n",
|
"execve(): error loading ELF for file %s\n", path);
|
||||||
(char *)w.sr.args[1]);
|
|
||||||
goto return_execve1;
|
goto return_execve1;
|
||||||
}
|
}
|
||||||
|
|
||||||
__dprintf("execve(): load_elf_desc() for %s OK, num sections: %d\n",
|
__dprintf("execve(): load_elf_desc() for %s OK, num sections: %d\n",
|
||||||
w.sr.args[1], desc->num_sections);
|
path, desc->num_sections);
|
||||||
|
|
||||||
/* Copy descriptor to co-kernel side */
|
/* Copy descriptor to co-kernel side */
|
||||||
trans.userp = (void*)desc;
|
trans.userp = (void*)desc;
|
||||||
@ -1246,7 +1285,7 @@ int main_loop(int fd, int cpu, pthread_mutex_t *lock)
|
|||||||
}
|
}
|
||||||
|
|
||||||
__dprintf("execve(): load_elf_desc() for %s OK\n",
|
__dprintf("execve(): load_elf_desc() for %s OK\n",
|
||||||
w.sr.args[1]);
|
path);
|
||||||
|
|
||||||
/* We can't be sure next phase will succeed */
|
/* We can't be sure next phase will succeed */
|
||||||
/* TODO: what shall we do with fp in desc?? */
|
/* TODO: what shall we do with fp in desc?? */
|
||||||
@ -1279,7 +1318,7 @@ return_execve1:
|
|||||||
goto return_execve1;
|
goto return_execve1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("execve(): transfer ELF desc OK\n");
|
__dprintf("execve(): transfer ELF desc OK\n");
|
||||||
|
|
||||||
transfer_image(fd, desc);
|
transfer_image(fd, desc);
|
||||||
__dprintf("execve(): image transferred\n");
|
__dprintf("execve(): image transferred\n");
|
||||||
|
|||||||
@ -84,6 +84,9 @@
|
|||||||
//#define USE_LARGE_PAGES
|
//#define USE_LARGE_PAGES
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define USER_STACK_NR_PAGES 8192
|
||||||
|
#define KERNEL_STACK_NR_PAGES 25
|
||||||
|
|
||||||
#include <waitq.h>
|
#include <waitq.h>
|
||||||
#include <futex.h>
|
#include <futex.h>
|
||||||
#include <rlimit.h>
|
#include <rlimit.h>
|
||||||
|
|||||||
@ -43,9 +43,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define USER_STACK_NR_PAGES 8192
|
|
||||||
#define KERNEL_STACK_NR_PAGES 25
|
|
||||||
|
|
||||||
extern long do_arch_prctl(unsigned long code, unsigned long address);
|
extern long do_arch_prctl(unsigned long code, unsigned long address);
|
||||||
static void insert_vm_range_list(struct process_vm *vm,
|
static void insert_vm_range_list(struct process_vm *vm,
|
||||||
struct vm_range *newrange);
|
struct vm_range *newrange);
|
||||||
|
|||||||
@ -1228,6 +1228,11 @@ SYSCALL_DECLARE(execve)
|
|||||||
/* Unmap all memory areas of the process, userspace will be gone */
|
/* Unmap all memory areas of the process, userspace will be gone */
|
||||||
free_process_memory_ranges(cpu_local_var(current));
|
free_process_memory_ranges(cpu_local_var(current));
|
||||||
|
|
||||||
|
ihk_mc_init_user_process(&cpu_local_var(current)->ctx,
|
||||||
|
&cpu_local_var(current)->uctx,
|
||||||
|
((char *)cpu_local_var(current)) +
|
||||||
|
KERNEL_STACK_NR_PAGES * PAGE_SIZE, desc->entry, 0);
|
||||||
|
|
||||||
/* Create virtual memory ranges and update args/envs */
|
/* Create virtual memory ranges and update args/envs */
|
||||||
if (prepare_process_ranges_args_envs(cpu_local_var(current), desc, desc,
|
if (prepare_process_ranges_args_envs(cpu_local_var(current), desc, desc,
|
||||||
PTATTR_NO_EXECUTE | PTATTR_WRITABLE | PTATTR_FOR_USER,
|
PTATTR_NO_EXECUTE | PTATTR_WRITABLE | PTATTR_FOR_USER,
|
||||||
@ -1236,6 +1241,18 @@ SYSCALL_DECLARE(execve)
|
|||||||
panic("");
|
panic("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Clear host user space PTEs */
|
||||||
|
request.number = __NR_munmap;
|
||||||
|
request.args[0] = cpu_local_var(current)->vm->region.user_start;
|
||||||
|
request.args[1] = cpu_local_var(current)->vm->region.user_end -
|
||||||
|
cpu_local_var(current)->vm->region.user_start;
|
||||||
|
dkprintf("execve(): requesting host PTE clear\n");
|
||||||
|
|
||||||
|
if (do_syscall(&request, ctx, ihk_mc_get_processor_id(), 0)) {
|
||||||
|
kprintf("execve(): ERROR: clearing PTEs in host process\n");
|
||||||
|
panic("");
|
||||||
|
}
|
||||||
|
|
||||||
/* Request host to transfer ELF image */
|
/* Request host to transfer ELF image */
|
||||||
request.number = __NR_execve;
|
request.number = __NR_execve;
|
||||||
request.args[0] = 2; /* 2nd phase - transfer ELF image */
|
request.args[0] = 2; /* 2nd phase - transfer ELF image */
|
||||||
@ -1250,8 +1267,13 @@ SYSCALL_DECLARE(execve)
|
|||||||
panic("");
|
panic("");
|
||||||
}
|
}
|
||||||
|
|
||||||
dkprintf("execve(): returning to new process\n");
|
/* Switch to new execution context */
|
||||||
|
dkprintf("execve(): switching to new process\n");
|
||||||
|
|
||||||
|
ihk_mc_switch_context(NULL, &cpu_local_var(current)->ctx,
|
||||||
|
cpu_local_var(current));
|
||||||
|
|
||||||
|
/* Never reach here */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user