| 542 | } |
| 543 | |
| 544 | KThread* KProcess::startProcess(BString currentDirectory, const std::vector<BString>& argValues, const std::vector<BString>& envValues, int userId, int groupId, int effectiveUserId, int effectiveGroupId) { |
| 545 | std::shared_ptr<FsNode> node = Fs::getNodeFromLocalPath(currentDirectory, argValues[0], true); |
| 546 | |
| 547 | if (!node) { |
| 548 | kwarn_fmt("Could not find %s", argValues[0].c_str()); |
| 549 | return nullptr; |
| 550 | } |
| 551 | |
| 552 | BString interpreter; |
| 553 | BString loader; |
| 554 | std::vector<BString> interpreterArgs; |
| 555 | std::vector<BString> args; |
| 556 | std::vector<BString> env; |
| 557 | this->memory = KMemory::create(this); |
| 558 | KThread* thread = this->createThread(); |
| 559 | BString name; |
| 560 | |
| 561 | KThread::setCurrentThread(thread); |
| 562 | thread->setupStack(); |
| 563 | this->parentId = 1; |
| 564 | this->userId = userId; |
| 565 | this->effectiveUserId = effectiveUserId; |
| 566 | this->groupId = groupId; |
| 567 | this->effectiveGroupId = effectiveGroupId; |
| 568 | this->setupCommandlineNode(); |
| 569 | this->exe = argValues[0]; |
| 570 | this->name = Fs::getFileNameFromPath(this->exe); |
| 571 | |
| 572 | for (U32 i=0;i<argValues.size();i++) { |
| 573 | if (i>0) |
| 574 | this->commandLine+=" "; |
| 575 | this->commandLine+=argValues[i]; |
| 576 | } |
| 577 | |
| 578 | this->initStdio(); |
| 579 | FsOpenNode* openNode=ElfLoader::inspectNode(currentDirectory, node, loader, interpreter, interpreterArgs); |
| 580 | if (!openNode) { |
| 581 | return nullptr; |
| 582 | } |
| 583 | if (ElfLoader::loadProgram(thread, openNode, &thread->cpu->eip.u32)) { |
| 584 | // :TODO: why will it crash in strchr libc if I remove this |
| 585 | //syscall_mmap64(thread, ADDRESS_PROCESS_LOADER << PAGE_SHIFT, 4096, K_PROT_READ | K_PROT_WRITE, K_MAP_ANONYMOUS|K_MAP_PRIVATE, -1, 0); |
| 586 | |
| 587 | if (loader.length()) |
| 588 | args.push_back(loader); |
| 589 | if (interpreter.length()) { |
| 590 | exe = interpreter; |
| 591 | args.push_back(interpreter); |
| 592 | } |
| 593 | args.push_back(BString(Fs::getFullPath(currentDirectory, argValues[0]))); |
| 594 | for (U32 i=1;i<argValues.size();i++) { |
| 595 | args.push_back(argValues[i]); |
| 596 | } |
| 597 | for (U32 i=0;i<envValues.size();i++) { |
| 598 | env.push_back(envValues[i]); |
| 599 | } |
| 600 | setupThreadStack(thread, thread->cpu, this->name, args, env); |
| 601 |
no test coverage detected