Skip to content

Commit

Permalink
[rpcsx-os] implement sys_execve
Browse files Browse the repository at this point in the history
  • Loading branch information
DHrpcs3 committed Oct 31, 2023
1 parent fd14659 commit 9fe1fb8
Show file tree
Hide file tree
Showing 13 changed files with 342 additions and 141 deletions.
21 changes: 21 additions & 0 deletions orbis-kernel/include/orbis/AppInfo.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include "orbis-config.hpp"

namespace orbis {
struct AppInfo {
uint32_t appId;
uint32_t unk0;
uint32_t unk1;
uint32_t appType;
char titleId[10];
uint16_t unk2;
uint32_t unk3;
slong unk4;
slong unk5;
slong unk6;
slong unk7;
slong unk8;
};
static_assert(sizeof(AppInfo) == 72);
} // namespace orbis
2 changes: 0 additions & 2 deletions orbis-kernel/include/orbis/evf.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#pragma once
#include "KernelAllocator.hpp"
#include "thread/Thread.hpp"
#include "utils/SharedCV.hpp"
#include "utils/SharedMutex.hpp"
#include <atomic>
#include <condition_variable>

namespace orbis {
enum {
Expand Down
3 changes: 2 additions & 1 deletion orbis-kernel/include/orbis/thread/Process.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "../thread/Thread.hpp"
#include "../thread/types.hpp"
#include "ProcessState.hpp"
#include "orbis/AppInfo.hpp"
#include "orbis/file.hpp"
#include "orbis/module/Module.hpp"
#include "orbis/utils/IdMap.hpp"
Expand Down Expand Up @@ -53,10 +54,10 @@ struct Process final {
ptr<void> processParam = nullptr;
uint64_t processParamSize = 0;
const ProcessOps *ops = nullptr;
AppInfo appInfo{};

std::uint64_t nextTlsSlot = 1;
std::uint64_t lastTlsOffset = 0;
bool isSystem = false;

utils::RcIdMap<EventFlag, sint, 4097, 1> evfMap;
utils::RcIdMap<Semaphore, sint, 4097, 1> semMap;
Expand Down
2 changes: 2 additions & 0 deletions orbis-kernel/include/orbis/thread/ProcessOps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ struct ProcessOps {
SysResult (*thr_set_name)(Thread *thread, slong id, ptr<const char> name);

SysResult (*fork)(Thread *thread, slong status);
SysResult (*execve)(Thread *thread, ptr<char> fname, ptr<ptr<char>> argv,
ptr<ptr<char>> envv);
SysResult (*exit)(Thread *thread, sint status);

SysResult (*processNeeded)(Thread *thread);
Expand Down
9 changes: 8 additions & 1 deletion orbis-kernel/src/sys/sys_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
#include "thread/Process.hpp"
#include "utils/Logs.hpp"
#include "utils/SharedMutex.hpp"
#include <chrono>
#include <list>
#include <span>
#include <thread>

namespace orbis {
struct KEvent {
Expand Down Expand Up @@ -110,7 +112,6 @@ orbis::SysResult orbis::sys_kevent(Thread *thread, sint fd,
return orbis::ErrorCode::BADF;
}


if (nchanges != 0) {
for (auto change : std::span(changelist, nchanges)) {
ORBIS_LOG_TODO(__FUNCTION__, change.ident, change.filter, change.flags,
Expand Down Expand Up @@ -148,6 +149,12 @@ orbis::SysResult orbis::sys_kevent(Thread *thread, sint fd,
if (note.event.filter == kEvFiltDisplay || note.event.filter == kEvFiltGraphicsCore) {
result.push_back(note.event);
}
if (note.event.filter == kEvFiltProc) {
// TODO
std::this_thread::sleep_for(std::chrono::milliseconds(500));
note.event.data = 0;
result.push_back(note.event);
}
}

std::memcpy(eventlist, result.data(), result.size() * sizeof(KEvent));
Expand Down
4 changes: 4 additions & 0 deletions orbis-kernel/src/sys/sys_exec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

orbis::SysResult orbis::sys_execve(Thread *thread, ptr<char> fname,
ptr<ptr<char>> argv, ptr<ptr<char>> envv) {
if (auto execve = thread->tproc->ops->execve) {
return execve(thread, fname, argv, envv);
}

return ErrorCode::NOSYS;
}
orbis::SysResult orbis::sys_fexecve(Thread *thread, sint fd,
Expand Down
8 changes: 6 additions & 2 deletions orbis-kernel/src/sys/sys_pipe.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#include "sys/sysproto.hpp"
#include "utils/Logs.hpp"
#include <pipe.hpp>

orbis::SysResult orbis::sys_pipe(Thread *thread) {
auto pipe = createPipe();
thread->retval[0] = thread->tproc->fileDescriptors.insert(pipe);
thread->retval[1] = thread->tproc->fileDescriptors.insert(pipe);
auto fd0 = thread->tproc->fileDescriptors.insert(pipe);
auto fd1 = thread->tproc->fileDescriptors.insert(pipe);
ORBIS_LOG_ERROR(__FUNCTION__, fd0, fd1);
thread->retval[0] = fd0;
thread->retval[1] = fd1;
return {};
}
Loading

0 comments on commit 9fe1fb8

Please sign in to comment.