/** @brief New process send a startup signal We copy the startup cmdline to the process */ static void process_startup(struct sysreq_process_startup * req) { xstring __user cmdline = req->cmdline_buffer; if (req->func == SYSREQ_PROCESS_STARTUP_FUNC_START) { /* The user buffer can be written ? */ if (ke_validate_user_buffer(cmdline, SYSREQ_PROCESS_STARTUP_MAX_SIZE, true) == false) return; memcpy(cmdline, (void*)(kt_arch_get_sp0(kt_current()) - KT_ARCH_THREAD_CP0_STACK_SIZE), SYSREQ_PROCESS_STARTUP_MAX_SIZE); //printk("cmdline is %s.\n", cmdline); } else if (req->func == SYSREQ_PROCESS_STARTUP_FUNC_SET_PATH) { /* The user buffer can be written ? */ if (ke_validate_user_buffer(cmdline, SYSREQ_PROCESS_STARTUP_MAX_SIZE, false) == false) return; //printk("current dir = %s.\n", cmdline); kt_current()->current_dir = fss_open(NULL, cmdline); } else if (req->func == SYSREQ_PROCESS_STARTUP_FUNC_END) { /* Killing main thread will trigger the process destroying */ kt_delete_current(); } }
static struct ko_section *map_file(struct ko_process *to, xstring name, page_prot_t prot, size_t __out *size) { void *fp; size_t map_size; struct ko_section *map; //TODO: 此处应该使用to 的原始启动路径来做当前路径 if (NULL == (fp = fss_open(kt_current()->current_dir, name))) goto err0; map_size = fss_get_size(fp); if (NULL == (map = create_file_map(to, fp, map_size, prot))) goto err1; if (size) *size = map_size; return map; err1: fss_close(fp); err0: return NULL; }
static struct ko_section *map_file(struct ko_process *to, xstring name, page_prot_t prot, unsigned long *map_size) { struct ko_section *ks_file; unsigned long size; void *fp; fp = fss_open(kt_current()->current_dir, name); if (!fp) goto end; *map_size = size = fss_get_size(fp); ks_file = ks_create(to, KS_TYPE_FILE, NULL, size, prot); if (!ks_file) goto err1; ks_file->priv.file.file = fp; return ks_file; err1: fss_close(fp); end: return NULL; }