Skip to content

Commit

Permalink
[WIP] sysdeps/managarm: implement sys_sysconf
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectrodeYT committed Oct 12, 2023
1 parent 7047232 commit b2ee39b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions options/linux/generic/sys-sysinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <mlibc/linux-sysdeps.hpp>

int sysinfo(struct sysinfo *info) {
mlibc::infoLogger() << "mlibc: sysinfo top" << frg::endlog;
MLIBC_CHECK_OR_ENOSYS(mlibc::sys_sysinfo, -1);
if(int e = mlibc::sys_sysinfo(info); e) {
errno = e;
Expand Down
3 changes: 2 additions & 1 deletion sysdeps/managarm/generic/sched.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include <bits/ensure.h>
#include <unistd.h>
#include <pwd.h>

#include <hel.h>
#include <hel-syscalls.h>
#include <mlibc/debug.hpp>
#include <mlibc/allocator.hpp>
// #include <mlibc/arch-defs.hpp>
#include <mlibc/posix-pipe.hpp>
#include <mlibc/posix-sysdeps.hpp>

Expand Down Expand Up @@ -94,5 +96,4 @@ int sys_setthreadaffinity(pid_t tid, size_t cpusetsize, const cpu_set_t *mask) {
return 0;
}


}
33 changes: 33 additions & 0 deletions sysdeps/managarm/generic/sysinfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <unistd.h>

#include <hel.h>
#include <hel-syscalls.h>
#include <mlibc/debug.hpp>
#include <mlibc/allocator.hpp>
#include <mlibc/linux-sysdeps.hpp>
#include <mlibc/posix-sysdeps.hpp>

int sys_sysinfo(struct sysinfo *info) {
mlibc::infoLogger() << "mlibc: sys_sysinfo top" << frg::endlog;
// TODO: fill in missing fields
uint64_t uptimeNanos;
HEL_CHECK(helGetSystemInformation(&uptimeNanos));

info->uptime = uptimeNanos / 1'000'000'000;
return 0;
}

int sys_sysconf(int num, long *ret) {
mlibc::infoLogger() << "mlibc: sys_sysconf top" << frg::endlog;
switch(num) {
case _SC_NPROCESSORS_ONLN:
case _SC_NPROCESSORS_CONF:
*ret = 0;
mlibc::infoLogger() << "mlibc: ret = " << ret << ", *ret = " << *ret << frg::endlog;
HEL_CHECK(helGetCpuInformation((uint32_t*)ret));
mlibc::infoLogger() << "mlibc: ret = " << ret << ", *ret = " << *ret << frg::endlog;
return 0;
default:
return EINVAL;
}
}
1 change: 1 addition & 0 deletions sysdeps/managarm/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ libc_sources += files(
'generic/sched.cpp',
'generic/signals.cpp',
'generic/socket.cpp',
'generic/sysinfo.cpp',
'generic/time.cpp'
)
libc_sources += [
Expand Down

0 comments on commit b2ee39b

Please sign in to comment.