[orbis-kernel] reduced log spam

fixed rmdir
This commit is contained in:
DH 2023-11-13 21:38:21 +03:00
parent d6a4d74d10
commit 0f86008b9b
8 changed files with 105 additions and 52 deletions

View File

@ -460,7 +460,7 @@ orbis::SysResult orbis::sys_osem_close(Thread *thread, sint id) {
} }
orbis::SysResult orbis::sys_osem_wait(Thread *thread, sint id, sint need, orbis::SysResult orbis::sys_osem_wait(Thread *thread, sint id, sint need,
ptr<uint> pTimeout) { ptr<uint> pTimeout) {
ORBIS_LOG_NOTICE(__FUNCTION__, thread, id, need, pTimeout); ORBIS_LOG_TRACE(__FUNCTION__, thread, id, need, pTimeout);
Ref<Semaphore> sem = thread->tproc->semMap.get(id); Ref<Semaphore> sem = thread->tproc->semMap.get(id);
if (need < 1 || need > sem->maxValue) if (need < 1 || need > sem->maxValue)
return ErrorCode::INVAL; return ErrorCode::INVAL;
@ -510,7 +510,7 @@ orbis::SysResult orbis::sys_osem_wait(Thread *thread, sint id, sint need,
} }
if (timedout) { if (timedout) {
return ErrorCode::TIMEDOUT; return SysResult::notAnError(ErrorCode::TIMEDOUT);
} }
return {}; return {};
} }
@ -863,8 +863,8 @@ struct mdbg_property {
orbis::SysResult orbis::sys_mdbg_service(Thread *thread, uint32_t op, orbis::SysResult orbis::sys_mdbg_service(Thread *thread, uint32_t op,
ptr<void> arg0, ptr<void> arg1) { ptr<void> arg0, ptr<void> arg1) {
ORBIS_LOG_NOTICE("sys_mdbg_service", thread->tid, op, arg0, arg1); // ORBIS_LOG_NOTICE("sys_mdbg_service", thread->tid, op, arg0, arg1);
thread->where(); // thread->where();
switch (op) { switch (op) {
case 1: { case 1: {

View File

@ -82,16 +82,24 @@ orbis::SysResult orbis::sys_clock_gettime(Thread *, clockid_t clock_id,
result = getHostClock(CLOCK_PROCESS_CPUTIME_ID); result = getHostClock(CLOCK_PROCESS_CPUTIME_ID);
break; break;
case ClockId::Network: case ClockId::Network:
ORBIS_LOG_ERROR("Unimplemented ClockId::Network\n"); // TODO
// ORBIS_LOG_ERROR("Unimplemented ClockId::Network");
result = getHostClock(CLOCK_PROCESS_CPUTIME_ID);
break; break;
case ClockId::DebugNetwork: case ClockId::DebugNetwork:
ORBIS_LOG_ERROR("Unimplemented ClockId::DebugNetwork\n"); // TODO
// ORBIS_LOG_ERROR("Unimplemented ClockId::DebugNetwork");
result = getHostClock(CLOCK_PROCESS_CPUTIME_ID);
break; break;
case ClockId::AdNetwork: case ClockId::AdNetwork:
ORBIS_LOG_ERROR("Unimplemented ClockId::AdNetwork\n"); // TODO
// ORBIS_LOG_ERROR("Unimplemented ClockId::AdNetwork");
result = getHostClock(CLOCK_PROCESS_CPUTIME_ID);
break; break;
case ClockId::RawNetwork: case ClockId::RawNetwork:
ORBIS_LOG_ERROR("Unimplemented ClockId::RawNetwork\n"); // TODO
// ORBIS_LOG_ERROR("Unimplemented ClockId::RawNetwork");
result = getHostClock(CLOCK_PROCESS_CPUTIME_ID);
break; break;
default: default:

View File

@ -8,30 +8,37 @@ namespace orbis::utils {
void shared_cv::impl_wait(shared_mutex &mutex, unsigned _val, void shared_cv::impl_wait(shared_mutex &mutex, unsigned _val,
std::uint64_t usec_timeout) noexcept { std::uint64_t usec_timeout) noexcept {
// Not supposed to fail // Not supposed to fail
if (!_val) if (!_val) {
std::abort(); std::abort();
}
// Wait with timeout // Wait with timeout
struct timespec timeout {}; struct timespec timeout {};
timeout.tv_nsec = (usec_timeout % 1000'000) * 1000; timeout.tv_nsec = (usec_timeout % 1000'000) * 1000;
timeout.tv_sec = (usec_timeout / 1000'000); timeout.tv_sec = (usec_timeout / 1000'000);
again:
while (true) {
auto result = syscall(SYS_futex, &m_value, FUTEX_WAIT, _val, auto result = syscall(SYS_futex, &m_value, FUTEX_WAIT, _val,
usec_timeout + 1 ? &timeout : nullptr, 0, 0); usec_timeout + 1 ? &timeout : nullptr, 0, 0);
if (result < 0) if (result < 0) {
result = errno; result = errno;
}
// Cleanup // Cleanup
const auto old = atomic_fetch_op(m_value, [&](unsigned &value) { const auto old = atomic_fetch_op(m_value, [&](unsigned &value) {
// Remove waiter if no signals // Remove waiter if no signals
if (!(value & ~c_waiter_mask) && result != EAGAIN) if (!(value & ~c_waiter_mask) && result != EAGAIN && result != EINTR) {
value -= 1; value -= 1;
}
// Try to remove signal // Try to remove signal
if (value & c_signal_mask) if (value & c_signal_mask) {
value -= c_signal_one; value -= c_signal_one;
if (value & c_locked_mask) }
if (value & c_locked_mask) {
value -= c_locked_mask; value -= c_locked_mask;
}
}); });
// Lock is already acquired // Lock is already acquired
@ -46,8 +53,11 @@ again:
} }
// Possibly spurious wakeup // Possibly spurious wakeup
if (result == EAGAIN) if (result != EAGAIN && result != EINTR) {
goto again; break;
}
}
mutex.lock(); mutex.lock();
} }

View File

@ -574,7 +574,7 @@ orbis::ErrorCode HostFsDevice::mkdir(const char *path, int mode,
} }
orbis::ErrorCode HostFsDevice::rmdir(const char *path, orbis::Thread *thread) { orbis::ErrorCode HostFsDevice::rmdir(const char *path, orbis::Thread *thread) {
std::error_code ec; std::error_code ec;
std::filesystem::remove(hostPath + "/" + path, ec); std::filesystem::remove_all(hostPath + "/" + path, ec);
return convertErrorCode(ec); return convertErrorCode(ec);
} }
orbis::ErrorCode HostFsDevice::rename(const char *from, const char *to, orbis::ErrorCode HostFsDevice::rename(const char *from, const char *to,

View File

@ -1,7 +1,10 @@
#include "io-device.hpp" #include "io-device.hpp"
#include "orbis/KernelAllocator.hpp" #include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp" #include "orbis/file.hpp"
#include "orbis/uio.hpp"
#include "orbis/utils/Logs.hpp" #include "orbis/utils/Logs.hpp"
#include <chrono>
#include <thread>
struct AoutFile : orbis::File {}; struct AoutFile : orbis::File {};
@ -9,11 +12,21 @@ static orbis::ErrorCode aout_ioctl(orbis::File *file, std::uint64_t request,
void *argp, orbis::Thread *thread) { void *argp, orbis::Thread *thread) {
ORBIS_LOG_FATAL("Unhandled aout ioctl", request); ORBIS_LOG_FATAL("Unhandled aout ioctl", request);
if (request == 0xc004500a) {
std::this_thread::sleep_for(std::chrono::days(1));
}
return {};
}
static orbis::ErrorCode aout_write(orbis::File *file, orbis::Uio *uio,
orbis::Thread *) {
uio->resid = 0;
return {}; return {};
} }
static const orbis::FileOps fileOps = { static const orbis::FileOps fileOps = {
.ioctl = aout_ioctl, .ioctl = aout_ioctl,
.write = aout_write,
}; };
struct AoutDevice : IoDevice { struct AoutDevice : IoDevice {

View File

@ -2,6 +2,7 @@
#include "orbis/KernelAllocator.hpp" #include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp" #include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp" #include "orbis/utils/Logs.hpp"
#include "orbis/thread/Thread.hpp"
struct GbaseFile : orbis::File {}; struct GbaseFile : orbis::File {};
@ -9,6 +10,7 @@ static orbis::ErrorCode gbase_ioctl(orbis::File *file, std::uint64_t request,
void *argp, orbis::Thread *thread) { void *argp, orbis::Thread *thread) {
ORBIS_LOG_FATAL("Unhandled gbase ioctl", request); ORBIS_LOG_FATAL("Unhandled gbase ioctl", request);
thread->where();
return {}; return {};
} }

View File

@ -53,8 +53,8 @@ static orbis::ErrorCode gc_ioctl(orbis::File *file, std::uint64_t request,
auto args = reinterpret_cast<Args *>(argp); auto args = reinterpret_cast<Args *>(argp);
flockfile(stderr); // flockfile(stderr);
ORBIS_LOG_ERROR("gc ioctl 0xc0108102", args->arg0, args->count, args->cmds); // ORBIS_LOG_ERROR("gc ioctl 0xc0108102", args->arg0, args->count, args->cmds);
for (unsigned i = 0; i < args->count; ++i) { for (unsigned i = 0; i < args->count; ++i) {
auto cmd = args->cmds + (i * 2); auto cmd = args->cmds + (i * 2);
@ -75,7 +75,7 @@ static orbis::ErrorCode gc_ioctl(orbis::File *file, std::uint64_t request,
rx::bridge.sendCommandBuffer(thread->tproc->pid, cmdId, address, size); rx::bridge.sendCommandBuffer(thread->tproc->pid, cmdId, address, size);
} }
funlockfile(stderr); // funlockfile(stderr);
break; break;
} }
@ -88,7 +88,7 @@ static orbis::ErrorCode gc_ioctl(orbis::File *file, std::uint64_t request,
auto args = reinterpret_cast<Args *>(argp); auto args = reinterpret_cast<Args *>(argp);
ORBIS_LOG_ERROR("gc ioctl 0xc0088101", args->arg0, args->arg1); // ORBIS_LOG_ERROR("gc ioctl 0xc0088101", args->arg0, args->arg1);
break; break;
} }
@ -257,9 +257,22 @@ static orbis::ErrorCode gc_ioctl(orbis::File *file, std::uint64_t request,
break; break;
} }
case 0xc0048113: {
// get client number
*(std::uint32_t *)argp = 0;
break;
}
case 0xc0048115: {
// is game closed
*(std::uint32_t *)argp = 0;
break;
}
default: default:
ORBIS_LOG_FATAL("Unhandled gc ioctl", request); ORBIS_LOG_FATAL("Unhandled gc ioctl", request);
std::fflush(stdout); std::fflush(stdout);
thread->where();
// __builtin_trap(); // __builtin_trap();
break; break;
} }

View File

@ -641,6 +641,7 @@ orbis::SysResult nmount(orbis::Thread *thread, orbis::ptr<orbis::IoVec> iovp,
orbis::SysResult exit(orbis::Thread *thread, orbis::sint status) { orbis::SysResult exit(orbis::Thread *thread, orbis::sint status) {
std::printf("Requested exit with status %d\n", status); std::printf("Requested exit with status %d\n", status);
thread->tproc->event.emit(orbis::kNoteExit, status);
std::exit(status); std::exit(status);
} }
@ -705,6 +706,7 @@ SysResult fork(Thread *thread, slong flags) {
kfree(flag, sizeof(*flag)); kfree(flag, sizeof(*flag));
thread->tproc->event.emit(orbis::kNoteFork, childPid);
thread->retval[0] = childPid; thread->retval[0] = childPid;
thread->retval[1] = 0; thread->retval[1] = 0;
return {}; return {};
@ -791,6 +793,20 @@ SysResult execve(Thread *thread, ptr<char> fname, ptr<ptr<char>> argv,
std::string path = getAbsolutePath(fname, thread); std::string path = getAbsolutePath(fname, thread);
ORBIS_LOG_ERROR(__FUNCTION__, path); ORBIS_LOG_ERROR(__FUNCTION__, path);
{
auto name = path;
if (auto slashP = name.rfind('/'); slashP != std::string::npos) {
name = name.substr(slashP + 1);
}
if (name.size() > 15) {
name.resize(15);
}
pthread_setname_np(pthread_self(), name.c_str());
}
std::printf("pid: %u\n", ::getpid());
{ {
orbis::Ref<File> file; orbis::Ref<File> file;
auto result = rx::vfs::open(path, kOpenFlagReadOnly, 0, &file, thread); auto result = rx::vfs::open(path, kOpenFlagReadOnly, 0, &file, thread);
@ -812,16 +828,7 @@ SysResult execve(Thread *thread, ptr<char> fname, ptr<ptr<char>> argv,
thread->tproc->processParam = executableModule->processParam; thread->tproc->processParam = executableModule->processParam;
thread->tproc->processParamSize = executableModule->processParamSize; thread->tproc->processParamSize = executableModule->processParamSize;
auto name = path; thread->tproc->event.emit(orbis::kNoteExec);
if (auto slashP = name.rfind('/'); slashP != std::string::npos) {
name = name.substr(slashP + 1);
}
if (name.size() > 15) {
name.resize(15);
}
pthread_setname_np(pthread_self(), name.c_str());
ORBIS_LOG_ERROR(__FUNCTION__, "done"); ORBIS_LOG_ERROR(__FUNCTION__, "done");
std::thread([&] { std::thread([&] {