Ver código fonte

LibC: Add a wrapper for the getrusage syscall

Lucas CHOLLET 3 anos atrás
pai
commit
8a9a9fac4d
1 arquivos alterados com 7 adições e 4 exclusões
  1. 7 4
      Userland/Libraries/LibC/ulimit.cpp

+ 7 - 4
Userland/Libraries/LibC/ulimit.cpp

@@ -1,5 +1,6 @@
 /*
 /*
  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2022, Lucas Chollet <lucas.chollet@free.fr>
  *
  *
  * SPDX-License-Identifier: BSD-2-Clause
  * SPDX-License-Identifier: BSD-2-Clause
  */
  */
@@ -7,21 +8,23 @@
 #include <AK/Format.h>
 #include <AK/Format.h>
 #include <assert.h>
 #include <assert.h>
 #include <sys/resource.h>
 #include <sys/resource.h>
+#include <syscall.h>
 #include <ulimit.h>
 #include <ulimit.h>
 
 
 extern "C" {
 extern "C" {
 
 
 long ulimit([[maybe_unused]] int cmd, [[maybe_unused]] long newlimit)
 long ulimit([[maybe_unused]] int cmd, [[maybe_unused]] long newlimit)
 {
 {
-    dbgln("FIXME: Implement getrusage()");
+    dbgln("FIXME: Implement ulimit()");
     TODO();
     TODO();
     return -1;
     return -1;
 }
 }
 
 
-int getrusage([[maybe_unused]] int who, [[maybe_unused]] struct rusage* usage)
+// https://pubs.opengroup.org/onlinepubs/009696699/functions/getrusage.html
+int getrusage(int who, struct rusage* usage)
 {
 {
-    dbgln("FIXME: Implement getrusage()");
-    return -1;
+    int rc = syscall(SC_getrusage, who, usage);
+    __RETURN_WITH_ERRNO(rc, rc, -1);
 }
 }
 
 
 int getrlimit([[maybe_unused]] int resource, rlimit* rl)
 int getrlimit([[maybe_unused]] int resource, rlimit* rl)