diff --git a/userspace/libraries/LibC/include/unistd.h b/userspace/libraries/LibC/include/unistd.h index e628a913..71c7a25e 100644 --- a/userspace/libraries/LibC/include/unistd.h +++ b/userspace/libraries/LibC/include/unistd.h @@ -494,6 +494,10 @@ enum #define _SC_XOPEN_UUCP _SC_XOPEN_UUCP _SC_XOPEN_VERSION, #define _SC_XOPEN_VERSION _SC_XOPEN_VERSION + _SC_PHYS_PAGES, +#define _SC_PHYS_PAGES _SC_PHYS_PAGES + _SC_AVPHYS_PAGES, +#define _SC_AVPHYS_PAGES _SC_AVPHYS_PAGES }; #define F_OK 0x01 diff --git a/userspace/libraries/LibC/unistd.cpp b/userspace/libraries/LibC/unistd.cpp index edd6a5b1..ba7da6bf 100644 --- a/userspace/libraries/LibC/unistd.cpp +++ b/userspace/libraries/LibC/unistd.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -1180,6 +1181,25 @@ long sysconf(int name) case _SC_GETGR_R_SIZE_MAX: return 1024; case _SC_GETPW_R_SIZE_MAX: return 1024; case _SC_THREAD_STACK_MIN: return PTHREAD_STACK_MIN; + + case _SC_PHYS_PAGES: + case _SC_AVPHYS_PAGES: + { + int fd = open("/proc/meminfo", O_RDONLY); + if (fd == -1) + return -1; + + full_meminfo_t meminfo; + const size_t nread = read(fd, &meminfo, sizeof(meminfo)); + close(fd); + + if (nread != sizeof(meminfo)) + return -1; + if (name == _SC_PHYS_PAGES) + return meminfo.free_pages + meminfo.used_pages; + if (name == _SC_AVPHYS_PAGES) + return meminfo.free_pages; + } } errno = EINVAL;