Browse Source

LibC+Userland: Add a proper syscall wrapper for purge()

Andreas Kling 5 năm trước cách đây
mục cha
commit
907b090ddf
3 tập tin đã thay đổi với 17 bổ sung4 xóa
  1. 6 0
      Libraries/LibC/serenity.cpp
  2. 5 0
      Libraries/LibC/serenity.h
  3. 6 4
      Userland/purge.cpp

+ 6 - 0
Libraries/LibC/serenity.cpp

@@ -47,4 +47,10 @@ int futex(int32_t* userspace_address, int futex_op, int32_t value, const struct
     __RETURN_WITH_ERRNO(rc, rc, -1);
 }
 
+int purge(int mode)
+{
+    int rc = syscall(SC_purge, mode);
+    __RETURN_WITH_ERRNO(rc, rc, -1);
+}
+
 }

+ 5 - 0
Libraries/LibC/serenity.h

@@ -58,4 +58,9 @@ int set_process_boost(pid_t, int amount);
 
 int futex(int32_t* userspace_address, int futex_op, int32_t value, const struct timespec* timeout);
 
+#define PURGE_ALL_VOLATILE 0x1
+#define PURGE_ALL_CLEAN_INODE 0x2
+
+int purge(int mode);
+
 __END_DECLS

+ 6 - 4
Userland/purge.cpp

@@ -1,10 +1,8 @@
 #include <Kernel/Syscall.h>
+#include <serenity.h>
 #include <stdio.h>
 #include <string.h>
 
-#define PURGE_ALL_VOLATILE 0x1
-#define PURGE_ALL_CLEAN_INODE 0x2
-
 int main(int argc, char** argv)
 {
     int mode = 0;
@@ -20,7 +18,11 @@ int main(int argc, char** argv)
             return 1;
         }
     }
-    int purged_page_count = syscall(SC_purge, mode);
+    int purged_page_count = purge(mode);
+    if (purged_page_count < 0) {
+        perror("purge");
+        return 1;
+    }
     printf("Purged page count: %d\n", purged_page_count);
     return 0;
 }