1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 10:17:35 +00:00

Add /proc/mm and a /bin/mm utility that just dumps it.

This shows some info about the MM. Right now it's just the zone count
and the number of free physical pages. Lots more can be added.

Also added "exit" to sh so we can nest shells and exit from them.

I also noticed that we were leaking all the physical pages, so fixed that.
This commit is contained in:
Andreas Kling 2018-10-28 10:26:07 +01:00
parent 0a6a2521e8
commit c76dc9a047
10 changed files with 115 additions and 21 deletions

1
Userland/.gitignore vendored
View file

@ -13,3 +13,4 @@ cat
uname
clear
tst
mm

View file

@ -12,7 +12,8 @@ OBJS = \
cat.o \
uname.o \
clear.o \
tst.o
tst.o \
mm.o
APPS = \
id \
@ -28,7 +29,8 @@ APPS = \
cat \
uname \
clear \
tst
tst \
mm
ARCH_FLAGS =
STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib
@ -90,6 +92,9 @@ clear: clear.o
tst: tst.o
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
mm: mm.o
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
.cpp.o:
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<

25
Userland/mm.cpp Normal file
View file

@ -0,0 +1,25 @@
#include <LibC/stdio.h>
#include <LibC/unistd.h>
int main(int c, char** v)
{
int fd = open("/proc/mm");
if (fd == -1) {
perror("failed to open /proc/mm");
return 1;
}
for (;;) {
char buf[128];
ssize_t nread = read(fd, buf, sizeof(buf));
if (nread == 0)
break;
if (nread < 0) {
perror("failed to read");
return 2;
}
for (ssize_t i = 0; i < nread; ++i) {
putchar(buf[i]);
}
}
return 0;
}

View file

@ -5,7 +5,7 @@ int main(int c, char** v)
{
int fd = open("/proc/summary");
if (fd == -1) {
printf("failed to open /proc/summary :(\n");
perror("failed to open /proc/summary");
return 1;
}
for (;;) {
@ -14,7 +14,7 @@ int main(int c, char** v)
if (nread == 0)
break;
if (nread < 0) {
printf("failed to read :(\n");
perror("failed to read");
return 2;
}
for (ssize_t i = 0; i < nread; ++i) {

View file

@ -26,6 +26,13 @@ static int sh_pwd(int, const char**)
return 0;
}
static int sh_exit(int, const char**)
{
printf("Good-bye!\n");
exit(0);
return 0;
}
static int sh_cd(int argc, const char** argv)
{
if (argc == 1) {
@ -77,6 +84,10 @@ static bool handle_builtin(int argc, const char** argv, int& retval)
retval = sh_pwd(argc, argv);
return true;
}
if (!strcmp(argv[0], "exit")) {
retval = sh_exit(argc, argv);
return true;
}
return false;
}