Skip to content

Commit

Permalink
LibC+Userland: Add a proper syscall wrapper for purge()
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed Jan 2, 2020
1 parent c01f766 commit 907b090
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Libraries/LibC/serenity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 5 additions & 0 deletions Libraries/LibC/serenity.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 6 additions & 4 deletions Userland/purge.cpp
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}

0 comments on commit 907b090

Please sign in to comment.