浏览代码

LibCore+LibSystem: Move syscall wrappers from LibSystem to LibCore

With this change, System::foo() becomes Core::System::foo().

Since LibCore builds on other systems than SerenityOS, we now have to
make sure that wrappers work with just a standard C library underneath.
Andreas Kling 3 年之前
父节点
当前提交
21a5fb0fa2
共有 32 个文件被更改,包括 165 次插入173 次删除
  1. 8 8
      Userland/Applets/ResourceGraph/main.cpp
  2. 7 7
      Userland/Applications/3DFileViewer/main.cpp
  3. 9 9
      Userland/Applications/Browser/main.cpp
  4. 4 4
      Userland/Applications/FileManager/main.cpp
  5. 7 7
      Userland/Applications/Mail/main.cpp
  6. 4 4
      Userland/Applications/PDFViewer/main.cpp
  7. 2 2
      Userland/Applications/Piano/main.cpp
  8. 7 7
      Userland/Applications/PixelPaint/main.cpp
  9. 12 12
      Userland/Applications/Terminal/main.cpp
  10. 3 3
      Userland/Demos/Starfield/Starfield.cpp
  11. 4 4
      Userland/DevTools/HackStudio/LanguageServers/Cpp/main.cpp
  12. 4 4
      Userland/DevTools/HackStudio/LanguageServers/Shell/main.cpp
  13. 5 5
      Userland/Games/2048/main.cpp
  14. 5 5
      Userland/Games/Breakout/main.cpp
  15. 8 8
      Userland/Games/Chess/main.cpp
  16. 5 5
      Userland/Games/FlappyBug/main.cpp
  17. 5 5
      Userland/Games/Minesweeper/main.cpp
  18. 5 5
      Userland/Games/Spider/main.cpp
  19. 1 0
      Userland/Libraries/LibCore/CMakeLists.txt
  20. 7 11
      Userland/Libraries/LibCore/System.cpp
  21. 4 3
      Userland/Libraries/LibCore/System.h
  22. 0 6
      Userland/Libraries/LibSystem/CMakeLists.txt
  23. 2 2
      Userland/Services/FileSystemAccessServer/main.cpp
  24. 4 4
      Userland/Services/ImageDecoder/main.cpp
  25. 5 5
      Userland/Services/RequestServer/main.cpp
  26. 7 7
      Userland/Services/WebContent/main.cpp
  27. 5 5
      Userland/Services/WebSocket/main.cpp
  28. 10 10
      Userland/Services/WindowServer/main.cpp
  29. 5 5
      Userland/Utilities/id.cpp
  30. 2 2
      Userland/Utilities/js.cpp
  31. 2 2
      Userland/Utilities/nproc.cpp
  32. 7 7
      Userland/Utilities/w.cpp

+ 8 - 8
Userland/Applets/ResourceGraph/main.cpp

@@ -9,13 +9,13 @@
 #include <AK/JsonObject.h>
 #include <AK/JsonObject.h>
 #include <LibCore/ArgsParser.h>
 #include <LibCore/ArgsParser.h>
 #include <LibCore/File.h>
 #include <LibCore/File.h>
+#include <LibCore/System.h>
 #include <LibGUI/Application.h>
 #include <LibGUI/Application.h>
 #include <LibGUI/Frame.h>
 #include <LibGUI/Frame.h>
 #include <LibGUI/Painter.h>
 #include <LibGUI/Painter.h>
 #include <LibGUI/Window.h>
 #include <LibGUI/Window.h>
 #include <LibGfx/Palette.h>
 #include <LibGfx/Palette.h>
 #include <LibMain/Main.h>
 #include <LibMain/Main.h>
-#include <LibSystem/Wrappers.h>
 #include <serenity.h>
 #include <serenity.h>
 #include <spawn.h>
 #include <spawn.h>
 #include <stdio.h>
 #include <stdio.h>
@@ -185,11 +185,11 @@ private:
 
 
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 {
 {
-    TRY(System::pledge("stdio recvfd sendfd proc exec rpath unix", nullptr));
+    TRY(Core::System::pledge("stdio recvfd sendfd proc exec rpath unix", nullptr));
 
 
     auto app = GUI::Application::construct(arguments);
     auto app = GUI::Application::construct(arguments);
 
 
-    TRY(System::pledge("stdio recvfd sendfd proc exec rpath", nullptr));
+    TRY(Core::System::pledge("stdio recvfd sendfd proc exec rpath", nullptr));
 
 
     const char* cpu = nullptr;
     const char* cpu = nullptr;
     const char* memory = nullptr;
     const char* memory = nullptr;
@@ -231,11 +231,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
     if (memory)
     if (memory)
         create_applet(GraphType::Memory, memory);
         create_applet(GraphType::Memory, memory);
 
 
-    TRY(System::unveil("/res", "r"));
-    TRY(System::unveil("/proc/stat", "r"));
-    TRY(System::unveil("/proc/memstat", "r"));
-    TRY(System::unveil("/bin/SystemMonitor", "x"));
-    TRY(System::unveil(nullptr, nullptr));
+    TRY(Core::System::unveil("/res", "r"));
+    TRY(Core::System::unveil("/proc/stat", "r"));
+    TRY(Core::System::unveil("/proc/memstat", "r"));
+    TRY(Core::System::unveil("/bin/SystemMonitor", "x"));
+    TRY(Core::System::unveil(nullptr, nullptr));
 
 
     return app->exec();
     return app->exec();
 }
 }

+ 7 - 7
Userland/Applications/3DFileViewer/main.cpp

@@ -6,6 +6,7 @@
 
 
 #include <LibCore/ElapsedTimer.h>
 #include <LibCore/ElapsedTimer.h>
 #include <LibCore/File.h>
 #include <LibCore/File.h>
+#include <LibCore/System.h>
 #include <LibFileSystemAccessClient/Client.h>
 #include <LibFileSystemAccessClient/Client.h>
 #include <LibGL/GL/gl.h>
 #include <LibGL/GL/gl.h>
 #include <LibGL/GLContext.h>
 #include <LibGL/GLContext.h>
@@ -23,7 +24,6 @@
 #include <LibGfx/Bitmap.h>
 #include <LibGfx/Bitmap.h>
 #include <LibGfx/Palette.h>
 #include <LibGfx/Palette.h>
 #include <LibMain/Main.h>
 #include <LibMain/Main.h>
-#include <LibSystem/Wrappers.h>
 
 
 #include "Mesh.h"
 #include "Mesh.h"
 #include "WavefrontOBJLoader.h"
 #include "WavefrontOBJLoader.h"
@@ -286,13 +286,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
 {
 {
     auto app = GUI::Application::construct(arguments);
     auto app = GUI::Application::construct(arguments);
 
 
-    TRY(System::pledge("stdio thread recvfd sendfd rpath unix", nullptr));
+    TRY(Core::System::pledge("stdio thread recvfd sendfd rpath unix", nullptr));
 
 
-    TRY(System::unveil("/tmp/portal/filesystemaccess", "rw"));
-    TRY(System::unveil("/home/anon/Documents/3D Models/teapot.obj", "r"));
-    TRY(System::unveil("/home/anon/Documents/3D Models/teapot.bmp", "r"));
-    TRY(System::unveil("/res", "r"));
-    TRY(System::unveil(nullptr, nullptr));
+    TRY(Core::System::unveil("/tmp/portal/filesystemaccess", "rw"));
+    TRY(Core::System::unveil("/home/anon/Documents/3D Models/teapot.obj", "r"));
+    TRY(Core::System::unveil("/home/anon/Documents/3D Models/teapot.bmp", "r"));
+    TRY(Core::System::unveil("/res", "r"));
+    TRY(Core::System::unveil(nullptr, nullptr));
 
 
     // Construct the main window
     // Construct the main window
     auto window = GUI::Window::construct();
     auto window = GUI::Window::construct();

+ 9 - 9
Userland/Applications/Browser/main.cpp

@@ -14,13 +14,13 @@
 #include <LibCore/ArgsParser.h>
 #include <LibCore/ArgsParser.h>
 #include <LibCore/File.h>
 #include <LibCore/File.h>
 #include <LibCore/StandardPaths.h>
 #include <LibCore/StandardPaths.h>
+#include <LibCore/System.h>
 #include <LibDesktop/Launcher.h>
 #include <LibDesktop/Launcher.h>
 #include <LibGUI/Application.h>
 #include <LibGUI/Application.h>
 #include <LibGUI/BoxLayout.h>
 #include <LibGUI/BoxLayout.h>
 #include <LibGUI/Icon.h>
 #include <LibGUI/Icon.h>
 #include <LibGUI/TabWidget.h>
 #include <LibGUI/TabWidget.h>
 #include <LibMain/Main.h>
 #include <LibMain/Main.h>
-#include <LibSystem/Wrappers.h>
 #include <stdio.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <unistd.h>
 
 
@@ -39,7 +39,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
         return 1;
         return 1;
     }
     }
 
 
-    TRY(System::pledge("stdio recvfd sendfd unix cpath rpath wpath", nullptr));
+    TRY(Core::System::pledge("stdio recvfd sendfd unix cpath rpath wpath", nullptr));
 
 
     const char* specified_url = nullptr;
     const char* specified_url = nullptr;
 
 
@@ -60,13 +60,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
         return 1;
         return 1;
     }
     }
 
 
-    TRY(System::unveil("/home", "rwc"));
-    TRY(System::unveil("/res", "r"));
-    TRY(System::unveil("/etc/passwd", "r"));
-    TRY(System::unveil("/tmp/portal/image", "rw"));
-    TRY(System::unveil("/tmp/portal/webcontent", "rw"));
-    TRY(System::unveil("/tmp/portal/request", "rw"));
-    TRY(System::unveil(nullptr, nullptr));
+    TRY(Core::System::unveil("/home", "rwc"));
+    TRY(Core::System::unveil("/res", "r"));
+    TRY(Core::System::unveil("/etc/passwd", "r"));
+    TRY(Core::System::unveil("/tmp/portal/image", "rw"));
+    TRY(Core::System::unveil("/tmp/portal/webcontent", "rw"));
+    TRY(Core::System::unveil("/tmp/portal/request", "rw"));
+    TRY(Core::System::unveil(nullptr, nullptr));
 
 
     auto app_icon = GUI::Icon::default_icon("app-browser");
     auto app_icon = GUI::Icon::default_icon("app-browser");
 
 

+ 4 - 4
Userland/Applications/FileManager/main.cpp

@@ -19,6 +19,7 @@
 #include <LibCore/ArgsParser.h>
 #include <LibCore/ArgsParser.h>
 #include <LibCore/File.h>
 #include <LibCore/File.h>
 #include <LibCore/StandardPaths.h>
 #include <LibCore/StandardPaths.h>
+#include <LibCore/System.h>
 #include <LibDesktop/Launcher.h>
 #include <LibDesktop/Launcher.h>
 #include <LibGUI/Action.h>
 #include <LibGUI/Action.h>
 #include <LibGUI/ActionGroup.h>
 #include <LibGUI/ActionGroup.h>
@@ -43,7 +44,6 @@
 #include <LibGUI/Window.h>
 #include <LibGUI/Window.h>
 #include <LibGfx/Palette.h>
 #include <LibGfx/Palette.h>
 #include <LibMain/Main.h>
 #include <LibMain/Main.h>
-#include <LibSystem/Wrappers.h>
 #include <pthread.h>
 #include <pthread.h>
 #include <signal.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdio.h>
@@ -64,12 +64,12 @@ static bool add_launch_handler_actions_to_menu(RefPtr<GUI::Menu>& menu, Director
 
 
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 {
 {
-    TRY(System::pledge("stdio thread recvfd sendfd unix cpath rpath wpath fattr proc exec sigaction", nullptr));
+    TRY(Core::System::pledge("stdio thread recvfd sendfd unix cpath rpath wpath fattr proc exec sigaction", nullptr));
 
 
     struct sigaction act = {};
     struct sigaction act = {};
     act.sa_flags = SA_NOCLDWAIT;
     act.sa_flags = SA_NOCLDWAIT;
     act.sa_handler = SIG_IGN;
     act.sa_handler = SIG_IGN;
-    TRY(System::sigaction(SIGCHLD, &act, nullptr));
+    TRY(Core::System::sigaction(SIGCHLD, &act, nullptr));
 
 
     Core::ArgsParser args_parser;
     Core::ArgsParser args_parser;
     bool is_desktop_mode { false }, is_selection_mode { false }, ignore_path_resolution { false };
     bool is_desktop_mode { false }, is_selection_mode { false }, ignore_path_resolution { false };
@@ -82,7 +82,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
 
 
     auto app = GUI::Application::construct(arguments);
     auto app = GUI::Application::construct(arguments);
 
 
-    TRY(System::pledge("stdio thread recvfd sendfd cpath rpath wpath fattr proc exec unix", nullptr));
+    TRY(Core::System::pledge("stdio thread recvfd sendfd cpath rpath wpath fattr proc exec unix", nullptr));
 
 
     Config::pledge_domains({ "FileManager", "WindowManager" });
     Config::pledge_domains({ "FileManager", "WindowManager" });
     Config::monitor_domain("FileManager");
     Config::monitor_domain("FileManager");

+ 7 - 7
Userland/Applications/Mail/main.cpp

@@ -6,27 +6,27 @@
 
 
 #include "MailWidget.h"
 #include "MailWidget.h"
 #include <LibConfig/Client.h>
 #include <LibConfig/Client.h>
+#include <LibCore/System.h>
 #include <LibGUI/Application.h>
 #include <LibGUI/Application.h>
 #include <LibGUI/Icon.h>
 #include <LibGUI/Icon.h>
 #include <LibGUI/Menu.h>
 #include <LibGUI/Menu.h>
 #include <LibGUI/Menubar.h>
 #include <LibGUI/Menubar.h>
 #include <LibGUI/Window.h>
 #include <LibGUI/Window.h>
 #include <LibMain/Main.h>
 #include <LibMain/Main.h>
-#include <LibSystem/Wrappers.h>
 
 
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 {
 {
-    TRY(System::pledge("stdio recvfd sendfd rpath unix inet", nullptr));
+    TRY(Core::System::pledge("stdio recvfd sendfd rpath unix inet", nullptr));
 
 
     auto app = GUI::Application::construct(arguments);
     auto app = GUI::Application::construct(arguments);
 
 
     Config::pledge_domains("Mail");
     Config::pledge_domains("Mail");
 
 
-    TRY(System::unveil("/res", "r"));
-    TRY(System::unveil("/etc", "r"));
-    TRY(System::unveil("/tmp/portal/webcontent", "rw"));
-    TRY(System::unveil("/tmp/portal/lookup", "rw"));
-    TRY(System::unveil(nullptr, nullptr));
+    TRY(Core::System::unveil("/res", "r"));
+    TRY(Core::System::unveil("/etc", "r"));
+    TRY(Core::System::unveil("/tmp/portal/webcontent", "rw"));
+    TRY(Core::System::unveil("/tmp/portal/lookup", "rw"));
+    TRY(Core::System::unveil(nullptr, nullptr));
 
 
     auto window = GUI::Window::construct();
     auto window = GUI::Window::construct();
 
 

+ 4 - 4
Userland/Applications/PDFViewer/main.cpp

@@ -6,6 +6,7 @@
  */
  */
 
 
 #include "PDFViewerWidget.h"
 #include "PDFViewerWidget.h"
+#include <LibCore/System.h>
 #include <LibFileSystemAccessClient/Client.h>
 #include <LibFileSystemAccessClient/Client.h>
 #include <LibGUI/Application.h>
 #include <LibGUI/Application.h>
 #include <LibGUI/Icon.h>
 #include <LibGUI/Icon.h>
@@ -13,7 +14,6 @@
 #include <LibGUI/MessageBox.h>
 #include <LibGUI/MessageBox.h>
 #include <LibGUI/Window.h>
 #include <LibGUI/Window.h>
 #include <LibMain/Main.h>
 #include <LibMain/Main.h>
-#include <LibSystem/Wrappers.h>
 
 
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 {
 {
@@ -24,9 +24,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
     window->set_title("PDF Viewer");
     window->set_title("PDF Viewer");
     window->resize(640, 400);
     window->resize(640, 400);
 
 
-    TRY(System::unveil("/res", "r"));
-    TRY(System::unveil("/tmp/portal/filesystemaccess", "rw"));
-    TRY(System::unveil(nullptr, nullptr));
+    TRY(Core::System::unveil("/res", "r"));
+    TRY(Core::System::unveil("/tmp/portal/filesystemaccess", "rw"));
+    TRY(Core::System::unveil(nullptr, nullptr));
 
 
     auto& pdf_viewer_widget = window->set_main_widget<PDFViewerWidget>();
     auto& pdf_viewer_widget = window->set_main_widget<PDFViewerWidget>();
 
 

+ 2 - 2
Userland/Applications/Piano/main.cpp

@@ -15,6 +15,7 @@
 #include <LibAudio/ClientConnection.h>
 #include <LibAudio/ClientConnection.h>
 #include <LibAudio/WavWriter.h>
 #include <LibAudio/WavWriter.h>
 #include <LibCore/EventLoop.h>
 #include <LibCore/EventLoop.h>
+#include <LibCore/System.h>
 #include <LibGUI/Action.h>
 #include <LibGUI/Action.h>
 #include <LibGUI/Application.h>
 #include <LibGUI/Application.h>
 #include <LibGUI/FilePicker.h>
 #include <LibGUI/FilePicker.h>
@@ -23,11 +24,10 @@
 #include <LibGUI/MessageBox.h>
 #include <LibGUI/MessageBox.h>
 #include <LibGUI/Window.h>
 #include <LibGUI/Window.h>
 #include <LibMain/Main.h>
 #include <LibMain/Main.h>
-#include <LibSystem/Wrappers.h>
 
 
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 {
 {
-    TRY(System::pledge("stdio thread rpath cpath wpath recvfd sendfd unix", nullptr));
+    TRY(Core::System::pledge("stdio thread rpath cpath wpath recvfd sendfd unix", nullptr));
 
 
     auto app = GUI::Application::construct(arguments);
     auto app = GUI::Application::construct(arguments);
 
 

+ 7 - 7
Userland/Applications/PixelPaint/main.cpp

@@ -8,6 +8,7 @@
 #include "MainWidget.h"
 #include "MainWidget.h"
 #include <LibConfig/Client.h>
 #include <LibConfig/Client.h>
 #include <LibCore/ArgsParser.h>
 #include <LibCore/ArgsParser.h>
+#include <LibCore/System.h>
 #include <LibFileSystemAccessClient/Client.h>
 #include <LibFileSystemAccessClient/Client.h>
 #include <LibGUI/Action.h>
 #include <LibGUI/Action.h>
 #include <LibGUI/Application.h>
 #include <LibGUI/Application.h>
@@ -17,11 +18,10 @@
 #include <LibGUI/Window.h>
 #include <LibGUI/Window.h>
 #include <LibGfx/Painter.h>
 #include <LibGfx/Painter.h>
 #include <LibMain/Main.h>
 #include <LibMain/Main.h>
-#include <LibSystem/Wrappers.h>
 
 
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 {
 {
-    TRY(System::pledge("stdio thread recvfd sendfd rpath unix wpath cpath", nullptr));
+    TRY(Core::System::pledge("stdio thread recvfd sendfd rpath unix wpath cpath", nullptr));
 
 
     auto app = GUI::Application::construct(arguments);
     auto app = GUI::Application::construct(arguments);
     Config::pledge_domains("PixelPaint");
     Config::pledge_domains("PixelPaint");
@@ -31,11 +31,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
     args_parser.add_positional_argument(image_file, "Image file to open", "path", Core::ArgsParser::Required::No);
     args_parser.add_positional_argument(image_file, "Image file to open", "path", Core::ArgsParser::Required::No);
     args_parser.parse(arguments);
     args_parser.parse(arguments);
 
 
-    TRY(System::unveil("/res", "r"));
-    TRY(System::unveil("/tmp/portal/clipboard", "rw"));
-    TRY(System::unveil("/tmp/portal/filesystemaccess", "rw"));
-    TRY(System::unveil("/tmp/portal/image", "rw"));
-    TRY(System::unveil(nullptr, nullptr));
+    TRY(Core::System::unveil("/res", "r"));
+    TRY(Core::System::unveil("/tmp/portal/clipboard", "rw"));
+    TRY(Core::System::unveil("/tmp/portal/filesystemaccess", "rw"));
+    TRY(Core::System::unveil("/tmp/portal/image", "rw"));
+    TRY(Core::System::unveil(nullptr, nullptr));
 
 
     auto app_icon = GUI::Icon::default_icon("app-pixel-paint");
     auto app_icon = GUI::Icon::default_icon("app-pixel-paint");
 
 

+ 12 - 12
Userland/Applications/Terminal/main.cpp

@@ -11,6 +11,7 @@
 #include <LibCore/ArgsParser.h>
 #include <LibCore/ArgsParser.h>
 #include <LibCore/DirIterator.h>
 #include <LibCore/DirIterator.h>
 #include <LibCore/Process.h>
 #include <LibCore/Process.h>
+#include <LibCore/System.h>
 #include <LibDesktop/Launcher.h>
 #include <LibDesktop/Launcher.h>
 #include <LibGUI/Action.h>
 #include <LibGUI/Action.h>
 #include <LibGUI/ActionGroup.h>
 #include <LibGUI/ActionGroup.h>
@@ -33,7 +34,6 @@
 #include <LibGUI/Window.h>
 #include <LibGUI/Window.h>
 #include <LibGfx/Palette.h>
 #include <LibGfx/Palette.h>
 #include <LibMain/Main.h>
 #include <LibMain/Main.h>
-#include <LibSystem/Wrappers.h>
 #include <LibVT/TerminalWidget.h>
 #include <LibVT/TerminalWidget.h>
 #include <assert.h>
 #include <assert.h>
 #include <errno.h>
 #include <errno.h>
@@ -252,18 +252,18 @@ static RefPtr<GUI::Window> create_find_window(VT::TerminalWidget& terminal)
 
 
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 {
 {
-    TRY(System::pledge("stdio tty rpath cpath wpath recvfd sendfd proc exec unix sigaction", nullptr));
+    TRY(Core::System::pledge("stdio tty rpath cpath wpath recvfd sendfd proc exec unix sigaction", nullptr));
 
 
     struct sigaction act;
     struct sigaction act;
     memset(&act, 0, sizeof(act));
     memset(&act, 0, sizeof(act));
     act.sa_flags = SA_NOCLDWAIT;
     act.sa_flags = SA_NOCLDWAIT;
     act.sa_handler = SIG_IGN;
     act.sa_handler = SIG_IGN;
 
 
-    TRY(System::sigaction(SIGCHLD, &act, nullptr));
+    TRY(Core::System::sigaction(SIGCHLD, &act, nullptr));
 
 
     auto app = GUI::Application::construct(arguments);
     auto app = GUI::Application::construct(arguments);
 
 
-    TRY(System::pledge("stdio tty rpath cpath wpath recvfd sendfd proc exec unix", nullptr));
+    TRY(Core::System::pledge("stdio tty rpath cpath wpath recvfd sendfd proc exec unix", nullptr));
 
 
     Config::pledge_domains("Terminal");
     Config::pledge_domains("Terminal");
 
 
@@ -422,14 +422,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
             settings_window->close();
             settings_window->close();
     };
     };
 
 
-    TRY(System::unveil("/res", "r"));
-    TRY(System::unveil("/bin", "r"));
-    TRY(System::unveil("/bin/Terminal", "x"));
-    TRY(System::unveil("/bin/utmpupdate", "x"));
-    TRY(System::unveil("/etc/FileIconProvider.ini", "r"));
-    TRY(System::unveil("/tmp/portal/launch", "rw"));
-    TRY(System::unveil("/tmp/portal/config", "rw"));
-    TRY(System::unveil(nullptr, nullptr));
+    TRY(Core::System::unveil("/res", "r"));
+    TRY(Core::System::unveil("/bin", "r"));
+    TRY(Core::System::unveil("/bin/Terminal", "x"));
+    TRY(Core::System::unveil("/bin/utmpupdate", "x"));
+    TRY(Core::System::unveil("/etc/FileIconProvider.ini", "r"));
+    TRY(Core::System::unveil("/tmp/portal/launch", "rw"));
+    TRY(Core::System::unveil("/tmp/portal/config", "rw"));
+    TRY(Core::System::unveil(nullptr, nullptr));
 
 
     window->show();
     window->show();
     int result = app->exec();
     int result = app->exec();

+ 3 - 3
Userland/Demos/Starfield/Starfield.cpp

@@ -6,6 +6,7 @@
 
 
 #include <AK/Vector.h>
 #include <AK/Vector.h>
 #include <LibCore/ArgsParser.h>
 #include <LibCore/ArgsParser.h>
+#include <LibCore/System.h>
 #include <LibGUI/Application.h>
 #include <LibGUI/Application.h>
 #include <LibGUI/Event.h>
 #include <LibGUI/Event.h>
 #include <LibGUI/Icon.h>
 #include <LibGUI/Icon.h>
@@ -14,7 +15,6 @@
 #include <LibGUI/Window.h>
 #include <LibGUI/Window.h>
 #include <LibGfx/Bitmap.h>
 #include <LibGfx/Bitmap.h>
 #include <LibMain/Main.h>
 #include <LibMain/Main.h>
-#include <LibSystem/Wrappers.h>
 #include <stdio.h>
 #include <stdio.h>
 #include <time.h>
 #include <time.h>
 
 
@@ -149,7 +149,7 @@ void Starfield::draw()
 
 
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 {
 {
-    TRY(System::pledge("stdio recvfd sendfd rpath unix", nullptr));
+    TRY(Core::System::pledge("stdio recvfd sendfd rpath unix", nullptr));
 
 
     unsigned star_count = 1000;
     unsigned star_count = 1000;
     unsigned refresh_rate = 16;
     unsigned refresh_rate = 16;
@@ -164,7 +164,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
 
 
     auto app = GUI::Application::construct(arguments);
     auto app = GUI::Application::construct(arguments);
 
 
-    TRY(System::pledge("stdio recvfd sendfd rpath", nullptr));
+    TRY(Core::System::pledge("stdio recvfd sendfd rpath", nullptr));
 
 
     auto app_icon = GUI::Icon::default_icon("app-screensaver");
     auto app_icon = GUI::Icon::default_icon("app-screensaver");
     auto window = GUI::Window::construct();
     auto window = GUI::Window::construct();

+ 4 - 4
Userland/DevTools/HackStudio/LanguageServers/Cpp/main.cpp

@@ -10,9 +10,9 @@
 #include <LibCore/ArgsParser.h>
 #include <LibCore/ArgsParser.h>
 #include <LibCore/EventLoop.h>
 #include <LibCore/EventLoop.h>
 #include <LibCore/LocalServer.h>
 #include <LibCore/LocalServer.h>
+#include <LibCore/System.h>
 #include <LibIPC/ClientConnection.h>
 #include <LibIPC/ClientConnection.h>
 #include <LibMain/Main.h>
 #include <LibMain/Main.h>
-#include <LibSystem/Wrappers.h>
 #include <unistd.h>
 #include <unistd.h>
 
 
 static ErrorOr<int> mode_server();
 static ErrorOr<int> mode_server();
@@ -34,13 +34,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
 ErrorOr<int> mode_server()
 ErrorOr<int> mode_server()
 {
 {
     Core::EventLoop event_loop;
     Core::EventLoop event_loop;
-    TRY(System::pledge("stdio unix recvfd rpath ", nullptr));
+    TRY(Core::System::pledge("stdio unix recvfd rpath ", nullptr));
 
 
     auto socket = Core::LocalSocket::take_over_accepted_socket_from_system_server();
     auto socket = Core::LocalSocket::take_over_accepted_socket_from_system_server();
     IPC::new_client_connection<LanguageServers::Cpp::ClientConnection>(socket.release_nonnull(), 1);
     IPC::new_client_connection<LanguageServers::Cpp::ClientConnection>(socket.release_nonnull(), 1);
 
 
-    TRY(System::pledge("stdio recvfd rpath", nullptr));
-    TRY(System::unveil("/usr/include", "r"));
+    TRY(Core::System::pledge("stdio recvfd rpath", nullptr));
+    TRY(Core::System::unveil("/usr/include", "r"));
 
 
     // unveil will be sealed later, when we know the project's root path.
     // unveil will be sealed later, when we know the project's root path.
     return event_loop.exec();
     return event_loop.exec();

+ 4 - 4
Userland/DevTools/HackStudio/LanguageServers/Shell/main.cpp

@@ -7,19 +7,19 @@
 #include "ClientConnection.h"
 #include "ClientConnection.h"
 #include <LibCore/EventLoop.h>
 #include <LibCore/EventLoop.h>
 #include <LibCore/LocalServer.h>
 #include <LibCore/LocalServer.h>
+#include <LibCore/System.h>
 #include <LibIPC/ClientConnection.h>
 #include <LibIPC/ClientConnection.h>
 #include <LibMain/Main.h>
 #include <LibMain/Main.h>
-#include <LibSystem/Wrappers.h>
 
 
 ErrorOr<int> serenity_main(Main::Arguments)
 ErrorOr<int> serenity_main(Main::Arguments)
 {
 {
     Core::EventLoop event_loop;
     Core::EventLoop event_loop;
-    TRY(System::pledge("stdio unix rpath recvfd", nullptr));
+    TRY(Core::System::pledge("stdio unix rpath recvfd", nullptr));
 
 
     auto socket = Core::LocalSocket::take_over_accepted_socket_from_system_server();
     auto socket = Core::LocalSocket::take_over_accepted_socket_from_system_server();
     IPC::new_client_connection<LanguageServers::Shell::ClientConnection>(socket.release_nonnull(), 1);
     IPC::new_client_connection<LanguageServers::Shell::ClientConnection>(socket.release_nonnull(), 1);
-    TRY(System::pledge("stdio rpath recvfd", nullptr));
-    TRY(System::unveil("/etc/passwd", "r"));
+    TRY(Core::System::pledge("stdio rpath recvfd", nullptr));
+    TRY(Core::System::unveil("/etc/passwd", "r"));
 
 
     return event_loop.exec();
     return event_loop.exec();
 }
 }

+ 5 - 5
Userland/Games/2048/main.cpp

@@ -8,6 +8,7 @@
 #include "Game.h"
 #include "Game.h"
 #include "GameSizeDialog.h"
 #include "GameSizeDialog.h"
 #include <LibConfig/Client.h>
 #include <LibConfig/Client.h>
+#include <LibCore/System.h>
 #include <LibGUI/Action.h>
 #include <LibGUI/Action.h>
 #include <LibGUI/Application.h>
 #include <LibGUI/Application.h>
 #include <LibGUI/BoxLayout.h>
 #include <LibGUI/BoxLayout.h>
@@ -20,13 +21,12 @@
 #include <LibGUI/Window.h>
 #include <LibGUI/Window.h>
 #include <LibGfx/Painter.h>
 #include <LibGfx/Painter.h>
 #include <LibMain/Main.h>
 #include <LibMain/Main.h>
-#include <LibSystem/Wrappers.h>
 #include <stdio.h>
 #include <stdio.h>
 #include <time.h>
 #include <time.h>
 
 
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 {
 {
-    TRY(System::pledge("stdio rpath recvfd sendfd unix", nullptr));
+    TRY(Core::System::pledge("stdio rpath recvfd sendfd unix", nullptr));
 
 
     srand(time(nullptr));
     srand(time(nullptr));
 
 
@@ -37,10 +37,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
 
 
     Config::pledge_domains("2048");
     Config::pledge_domains("2048");
 
 
-    TRY(System::pledge("stdio rpath recvfd sendfd", nullptr));
+    TRY(Core::System::pledge("stdio rpath recvfd sendfd", nullptr));
 
 
-    TRY(System::unveil("/res", "r"));
-    TRY(System::unveil(nullptr, nullptr));
+    TRY(Core::System::unveil("/res", "r"));
+    TRY(Core::System::unveil(nullptr, nullptr));
 
 
     size_t board_size = Config::read_i32("2048", "", "board_size", 4);
     size_t board_size = Config::read_i32("2048", "", "board_size", 4);
     u32 target_tile = Config::read_i32("2048", "", "target_tile", 2048);
     u32 target_tile = Config::read_i32("2048", "", "target_tile", 2048);

+ 5 - 5
Userland/Games/Breakout/main.cpp

@@ -5,6 +5,7 @@
  */
  */
 
 
 #include "Game.h"
 #include "Game.h"
+#include <LibCore/System.h>
 #include <LibGUI/Application.h>
 #include <LibGUI/Application.h>
 #include <LibGUI/Icon.h>
 #include <LibGUI/Icon.h>
 #include <LibGUI/Menu.h>
 #include <LibGUI/Menu.h>
@@ -12,18 +13,17 @@
 #include <LibGUI/Window.h>
 #include <LibGUI/Window.h>
 #include <LibGfx/Bitmap.h>
 #include <LibGfx/Bitmap.h>
 #include <LibMain/Main.h>
 #include <LibMain/Main.h>
-#include <LibSystem/Wrappers.h>
 
 
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 {
 {
-    TRY(System::pledge("stdio recvfd sendfd rpath unix", nullptr));
+    TRY(Core::System::pledge("stdio recvfd sendfd rpath unix", nullptr));
 
 
     auto app = GUI::Application::construct(arguments);
     auto app = GUI::Application::construct(arguments);
 
 
-    TRY(System::pledge("stdio recvfd sendfd rpath", nullptr));
+    TRY(Core::System::pledge("stdio recvfd sendfd rpath", nullptr));
 
 
-    TRY(System::unveil("/res", "r"));
-    TRY(System::unveil(nullptr, nullptr));
+    TRY(Core::System::unveil("/res", "r"));
+    TRY(Core::System::unveil(nullptr, nullptr));
 
 
     auto window = GUI::Window::construct();
     auto window = GUI::Window::construct();
     window->resize(Breakout::Game::game_width, Breakout::Game::game_height);
     window->resize(Breakout::Game::game_width, Breakout::Game::game_height);

+ 8 - 8
Userland/Games/Chess/main.cpp

@@ -7,6 +7,7 @@
 #include "ChessWidget.h"
 #include "ChessWidget.h"
 #include <LibConfig/Client.h>
 #include <LibConfig/Client.h>
 #include <LibCore/DirIterator.h>
 #include <LibCore/DirIterator.h>
+#include <LibCore/System.h>
 #include <LibGUI/ActionGroup.h>
 #include <LibGUI/ActionGroup.h>
 #include <LibGUI/Application.h>
 #include <LibGUI/Application.h>
 #include <LibGUI/Clipboard.h>
 #include <LibGUI/Clipboard.h>
@@ -17,28 +18,27 @@
 #include <LibGUI/MessageBox.h>
 #include <LibGUI/MessageBox.h>
 #include <LibGUI/Window.h>
 #include <LibGUI/Window.h>
 #include <LibMain/Main.h>
 #include <LibMain/Main.h>
-#include <LibSystem/Wrappers.h>
 
 
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 {
 {
-    TRY(System::pledge("stdio rpath wpath cpath recvfd sendfd thread proc exec unix", nullptr));
+    TRY(Core::System::pledge("stdio rpath wpath cpath recvfd sendfd thread proc exec unix", nullptr));
 
 
     auto app = GUI::Application::construct(arguments);
     auto app = GUI::Application::construct(arguments);
 
 
     Config::pledge_domains("Chess");
     Config::pledge_domains("Chess");
 
 
-    TRY(System::pledge("stdio rpath wpath cpath recvfd sendfd thread proc exec", nullptr));
+    TRY(Core::System::pledge("stdio rpath wpath cpath recvfd sendfd thread proc exec", nullptr));
 
 
     auto app_icon = GUI::Icon::default_icon("app-chess");
     auto app_icon = GUI::Icon::default_icon("app-chess");
 
 
     auto window = GUI::Window::construct();
     auto window = GUI::Window::construct();
     auto& widget = window->set_main_widget<ChessWidget>();
     auto& widget = window->set_main_widget<ChessWidget>();
 
 
-    TRY(System::unveil("/res", "r"));
-    TRY(System::unveil("/bin/ChessEngine", "x"));
-    TRY(System::unveil("/etc/passwd", "r"));
-    TRY(System::unveil(Core::StandardPaths::home_directory().characters(), "wcbr"));
-    TRY(System::unveil(nullptr, nullptr));
+    TRY(Core::System::unveil("/res", "r"));
+    TRY(Core::System::unveil("/bin/ChessEngine", "x"));
+    TRY(Core::System::unveil("/etc/passwd", "r"));
+    TRY(Core::System::unveil(Core::StandardPaths::home_directory().characters(), "wcbr"));
+    TRY(Core::System::unveil(nullptr, nullptr));
 
 
     auto size = Config::read_i32("Chess", "Display", "size", 512);
     auto size = Config::read_i32("Chess", "Display", "size", 512);
     window->set_title("Chess");
     window->set_title("Chess");

+ 5 - 5
Userland/Games/FlappyBug/main.cpp

@@ -6,6 +6,7 @@
 
 
 #include "Game.h"
 #include "Game.h"
 #include <LibConfig/Client.h>
 #include <LibConfig/Client.h>
+#include <LibCore/System.h>
 #include <LibGUI/Application.h>
 #include <LibGUI/Application.h>
 #include <LibGUI/Icon.h>
 #include <LibGUI/Icon.h>
 #include <LibGUI/Menu.h>
 #include <LibGUI/Menu.h>
@@ -13,20 +14,19 @@
 #include <LibGUI/MessageBox.h>
 #include <LibGUI/MessageBox.h>
 #include <LibGUI/Window.h>
 #include <LibGUI/Window.h>
 #include <LibMain/Main.h>
 #include <LibMain/Main.h>
-#include <LibSystem/Wrappers.h>
 
 
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 {
 {
-    TRY(System::pledge("stdio rpath recvfd sendfd unix", nullptr));
+    TRY(Core::System::pledge("stdio rpath recvfd sendfd unix", nullptr));
 
 
     auto app = GUI::Application::construct(arguments.argc, arguments.argv);
     auto app = GUI::Application::construct(arguments.argc, arguments.argv);
 
 
     Config::pledge_domains("FlappyBug");
     Config::pledge_domains("FlappyBug");
 
 
-    TRY(System::pledge("stdio rpath recvfd sendfd", nullptr));
+    TRY(Core::System::pledge("stdio rpath recvfd sendfd", nullptr));
 
 
-    TRY(System::unveil("/res", "r"));
-    TRY(System::unveil(nullptr, nullptr));
+    TRY(Core::System::unveil("/res", "r"));
+    TRY(Core::System::unveil(nullptr, nullptr));
 
 
     u32 high_score = Config::read_i32("FlappyBug", "Game", "HighScore", 0);
     u32 high_score = Config::read_i32("FlappyBug", "Game", "HighScore", 0);
 
 

+ 5 - 5
Userland/Games/Minesweeper/main.cpp

@@ -7,6 +7,7 @@
 #include "CustomGameDialog.h"
 #include "CustomGameDialog.h"
 #include "Field.h"
 #include "Field.h"
 #include <LibConfig/Client.h>
 #include <LibConfig/Client.h>
+#include <LibCore/System.h>
 #include <LibGUI/Action.h>
 #include <LibGUI/Action.h>
 #include <LibGUI/ActionGroup.h>
 #include <LibGUI/ActionGroup.h>
 #include <LibGUI/Application.h>
 #include <LibGUI/Application.h>
@@ -19,21 +20,20 @@
 #include <LibGUI/SeparatorWidget.h>
 #include <LibGUI/SeparatorWidget.h>
 #include <LibGUI/Window.h>
 #include <LibGUI/Window.h>
 #include <LibMain/Main.h>
 #include <LibMain/Main.h>
-#include <LibSystem/Wrappers.h>
 #include <stdio.h>
 #include <stdio.h>
 
 
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 {
 {
-    TRY(System::pledge("stdio rpath recvfd sendfd unix", nullptr));
+    TRY(Core::System::pledge("stdio rpath recvfd sendfd unix", nullptr));
 
 
     auto app = GUI::Application::construct(arguments);
     auto app = GUI::Application::construct(arguments);
 
 
     Config::pledge_domains("Minesweeper");
     Config::pledge_domains("Minesweeper");
 
 
-    TRY(System::pledge("stdio rpath recvfd sendfd", nullptr));
+    TRY(Core::System::pledge("stdio rpath recvfd sendfd", nullptr));
 
 
-    TRY(System::unveil("/res", "r"));
-    TRY(System::unveil(nullptr, nullptr));
+    TRY(Core::System::unveil("/res", "r"));
+    TRY(Core::System::unveil(nullptr, nullptr));
 
 
     auto app_icon = GUI::Icon::default_icon("app-minesweeper");
     auto app_icon = GUI::Icon::default_icon("app-minesweeper");
 
 

+ 5 - 5
Userland/Games/Spider/main.cpp

@@ -8,6 +8,7 @@
 #include "Game.h"
 #include "Game.h"
 #include <Games/Spider/SpiderGML.h>
 #include <Games/Spider/SpiderGML.h>
 #include <LibConfig/Client.h>
 #include <LibConfig/Client.h>
+#include <LibCore/System.h>
 #include <LibCore/Timer.h>
 #include <LibCore/Timer.h>
 #include <LibGUI/Action.h>
 #include <LibGUI/Action.h>
 #include <LibGUI/ActionGroup.h>
 #include <LibGUI/ActionGroup.h>
@@ -19,7 +20,6 @@
 #include <LibGUI/Statusbar.h>
 #include <LibGUI/Statusbar.h>
 #include <LibGUI/Window.h>
 #include <LibGUI/Window.h>
 #include <LibMain/Main.h>
 #include <LibMain/Main.h>
-#include <LibSystem/Wrappers.h>
 #include <stdio.h>
 #include <stdio.h>
 
 
 enum class StatisticDisplay : u8 {
 enum class StatisticDisplay : u8 {
@@ -39,17 +39,17 @@ static String format_seconds(uint64_t seconds_elapsed)
 
 
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 {
 {
-    TRY(System::pledge("stdio recvfd sendfd rpath unix", nullptr));
+    TRY(Core::System::pledge("stdio recvfd sendfd rpath unix", nullptr));
 
 
     auto app = GUI::Application::construct(arguments.argc, arguments.argv);
     auto app = GUI::Application::construct(arguments.argc, arguments.argv);
     auto app_icon = GUI::Icon::default_icon("app-spider");
     auto app_icon = GUI::Icon::default_icon("app-spider");
 
 
     Config::pledge_domains("Spider");
     Config::pledge_domains("Spider");
 
 
-    TRY(System::pledge("stdio recvfd sendfd rpath", nullptr));
+    TRY(Core::System::pledge("stdio recvfd sendfd rpath", nullptr));
 
 
-    TRY(System::unveil("/res", "r"));
-    TRY(System::unveil(nullptr, nullptr));
+    TRY(Core::System::unveil("/res", "r"));
+    TRY(Core::System::unveil(nullptr, nullptr));
 
 
     auto window = GUI::Window::construct();
     auto window = GUI::Window::construct();
     window->set_title("Spider");
     window->set_title("Spider");

+ 1 - 0
Userland/Libraries/LibCore/CMakeLists.txt

@@ -27,6 +27,7 @@ set(SOURCES
     SecretString.cpp
     SecretString.cpp
     Socket.cpp
     Socket.cpp
     StandardPaths.cpp
     StandardPaths.cpp
+    System.cpp
     TCPServer.cpp
     TCPServer.cpp
     TCPSocket.cpp
     TCPSocket.cpp
     Timer.cpp
     Timer.cpp

+ 7 - 11
Userland/Libraries/LibSystem/Wrappers.cpp → Userland/Libraries/LibCore/System.cpp

@@ -4,7 +4,7 @@
  * SPDX-License-Identifier: BSD-2-Clause
  * SPDX-License-Identifier: BSD-2-Clause
  */
  */
 
 
-#include <LibSystem/Wrappers.h>
+#include <LibCore/System.h>
 #include <LibSystem/syscall.h>
 #include <LibSystem/syscall.h>
 
 
 #define HANDLE_SYSCALL_RETURN_VALUE(syscall_name, rc, success_value) \
 #define HANDLE_SYSCALL_RETURN_VALUE(syscall_name, rc, success_value) \
@@ -13,8 +13,9 @@
     }                                                                \
     }                                                                \
     return success_value;
     return success_value;
 
 
-namespace System {
+namespace Core::System {
 
 
+#ifdef __serenity__
 ErrorOr<void> pledge(StringView promises, StringView execpromises)
 ErrorOr<void> pledge(StringView promises, StringView execpromises)
 {
 {
     Syscall::SC_pledge_params params {
     Syscall::SC_pledge_params params {
@@ -34,18 +35,13 @@ ErrorOr<void> unveil(StringView path, StringView permissions)
     int rc = syscall(SC_unveil, &params);
     int rc = syscall(SC_unveil, &params);
     HANDLE_SYSCALL_RETURN_VALUE("unveil"sv, rc, {});
     HANDLE_SYSCALL_RETURN_VALUE("unveil"sv, rc, {});
 }
 }
+#endif
 
 
 ErrorOr<void> sigaction(int signal, struct sigaction const* action, struct sigaction* old_action)
 ErrorOr<void> sigaction(int signal, struct sigaction const* action, struct sigaction* old_action)
 {
 {
-    int rc = syscall(SC_sigaction, signal, action, old_action);
-    HANDLE_SYSCALL_RETURN_VALUE("sigaction"sv, rc, {});
-}
-
-ErrorOr<struct stat> fstat(int fd)
-{
-    struct stat st;
-    int rc = syscall(SC_fstat, fd, &st);
-    HANDLE_SYSCALL_RETURN_VALUE("fstat"sv, rc, st);
+    if (::sigaction(signal, action, old_action) < 0)
+        return Error::from_syscall("sigaction"sv, -errno);
+    return {};
 }
 }
 
 
 }
 }

+ 4 - 3
Userland/Libraries/LibSystem/Wrappers.h → Userland/Libraries/LibCore/System.h

@@ -8,13 +8,14 @@
 
 
 #include <AK/Error.h>
 #include <AK/Error.h>
 #include <signal.h>
 #include <signal.h>
-#include <sys/stat.h>
 
 
-namespace System {
+namespace Core::System {
 
 
+#ifdef __serenity__
 ErrorOr<void> pledge(StringView promises, StringView execpromises);
 ErrorOr<void> pledge(StringView promises, StringView execpromises);
 ErrorOr<void> unveil(StringView path, StringView permissions);
 ErrorOr<void> unveil(StringView path, StringView permissions);
+#endif
+
 ErrorOr<void> sigaction(int signal, struct sigaction const* action, struct sigaction* old_action);
 ErrorOr<void> sigaction(int signal, struct sigaction const* action, struct sigaction* old_action);
-ErrorOr<struct stat> fstat(int fd);
 
 
 }
 }

+ 0 - 6
Userland/Libraries/LibSystem/CMakeLists.txt

@@ -1,13 +1,7 @@
 set(SOURCES
 set(SOURCES
-    Wrappers.cpp
     syscall.cpp
     syscall.cpp
 )
 )
 
 
-# FIXME: This is a hack to avoid a circular dependency with LibC. Figure out a better way.
-if ("${SERENITY_ARCH}" STREQUAL "i686")
-    set_source_files_properties(${SOURCES} PROPERTIES COMPILE_FLAGS "-fno-stack-protector")
-endif()
-
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdlib")
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdlib")
 serenity_libc(LibSystem system)
 serenity_libc(LibSystem system)
 target_include_directories(LibSystem PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
 target_include_directories(LibSystem PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

+ 2 - 2
Userland/Services/FileSystemAccessServer/main.cpp

@@ -6,14 +6,14 @@
 
 
 #include <FileSystemAccessServer/ClientConnection.h>
 #include <FileSystemAccessServer/ClientConnection.h>
 #include <LibCore/LocalServer.h>
 #include <LibCore/LocalServer.h>
+#include <LibCore/System.h>
 #include <LibGUI/Application.h>
 #include <LibGUI/Application.h>
 #include <LibIPC/ClientConnection.h>
 #include <LibIPC/ClientConnection.h>
 #include <LibMain/Main.h>
 #include <LibMain/Main.h>
-#include <LibSystem/Wrappers.h>
 
 
 ErrorOr<int> serenity_main(Main::Arguments)
 ErrorOr<int> serenity_main(Main::Arguments)
 {
 {
-    TRY(System::pledge("stdio recvfd sendfd rpath cpath wpath unix thread", nullptr));
+    TRY(Core::System::pledge("stdio recvfd sendfd rpath cpath wpath unix thread", nullptr));
 
 
     auto app = GUI::Application::construct(0, nullptr);
     auto app = GUI::Application::construct(0, nullptr);
     app->set_quit_when_last_window_deleted(false);
     app->set_quit_when_last_window_deleted(false);

+ 4 - 4
Userland/Services/ImageDecoder/main.cpp

@@ -7,18 +7,18 @@
 #include <ImageDecoder/ClientConnection.h>
 #include <ImageDecoder/ClientConnection.h>
 #include <LibCore/EventLoop.h>
 #include <LibCore/EventLoop.h>
 #include <LibCore/LocalServer.h>
 #include <LibCore/LocalServer.h>
+#include <LibCore/System.h>
 #include <LibIPC/ClientConnection.h>
 #include <LibIPC/ClientConnection.h>
 #include <LibMain/Main.h>
 #include <LibMain/Main.h>
-#include <LibSystem/Wrappers.h>
 
 
 ErrorOr<int> serenity_main(Main::Arguments)
 ErrorOr<int> serenity_main(Main::Arguments)
 {
 {
     Core::EventLoop event_loop;
     Core::EventLoop event_loop;
-    TRY(System::pledge("stdio recvfd sendfd unix", nullptr));
-    TRY(System::unveil(nullptr, nullptr));
+    TRY(Core::System::pledge("stdio recvfd sendfd unix", nullptr));
+    TRY(Core::System::unveil(nullptr, nullptr));
 
 
     auto socket = Core::LocalSocket::take_over_accepted_socket_from_system_server();
     auto socket = Core::LocalSocket::take_over_accepted_socket_from_system_server();
     IPC::new_client_connection<ImageDecoder::ClientConnection>(socket.release_nonnull(), 1);
     IPC::new_client_connection<ImageDecoder::ClientConnection>(socket.release_nonnull(), 1);
-    TRY(System::pledge("stdio recvfd sendfd", nullptr));
+    TRY(Core::System::pledge("stdio recvfd sendfd", nullptr));
     return event_loop.exec();
     return event_loop.exec();
 }
 }

+ 5 - 5
Userland/Services/RequestServer/main.cpp

@@ -7,9 +7,9 @@
 #include <AK/OwnPtr.h>
 #include <AK/OwnPtr.h>
 #include <LibCore/EventLoop.h>
 #include <LibCore/EventLoop.h>
 #include <LibCore/LocalServer.h>
 #include <LibCore/LocalServer.h>
+#include <LibCore/System.h>
 #include <LibIPC/ClientConnection.h>
 #include <LibIPC/ClientConnection.h>
 #include <LibMain/Main.h>
 #include <LibMain/Main.h>
-#include <LibSystem/Wrappers.h>
 #include <LibTLS/Certificate.h>
 #include <LibTLS/Certificate.h>
 #include <RequestServer/ClientConnection.h>
 #include <RequestServer/ClientConnection.h>
 #include <RequestServer/GeminiProtocol.h>
 #include <RequestServer/GeminiProtocol.h>
@@ -19,7 +19,7 @@
 
 
 ErrorOr<int> serenity_main(Main::Arguments)
 ErrorOr<int> serenity_main(Main::Arguments)
 {
 {
-    TRY(System::pledge("stdio inet accept unix rpath sendfd recvfd sigaction", nullptr));
+    TRY(Core::System::pledge("stdio inet accept unix rpath sendfd recvfd sigaction", nullptr));
 
 
     signal(SIGINFO, [](int) { RequestServer::ConnectionCache::dump_jobs(); });
     signal(SIGINFO, [](int) { RequestServer::ConnectionCache::dump_jobs(); });
 
 
@@ -28,9 +28,9 @@ ErrorOr<int> serenity_main(Main::Arguments)
 
 
     Core::EventLoop event_loop;
     Core::EventLoop event_loop;
     // FIXME: Establish a connection to LookupServer and then drop "unix"?
     // FIXME: Establish a connection to LookupServer and then drop "unix"?
-    TRY(System::pledge("stdio inet accept unix sendfd recvfd", nullptr));
-    TRY(System::unveil("/tmp/portal/lookup", "rw"));
-    TRY(System::unveil(nullptr, nullptr));
+    TRY(Core::System::pledge("stdio inet accept unix sendfd recvfd", nullptr));
+    TRY(Core::System::unveil("/tmp/portal/lookup", "rw"));
+    TRY(Core::System::unveil(nullptr, nullptr));
 
 
     [[maybe_unused]] auto gemini = make<RequestServer::GeminiProtocol>();
     [[maybe_unused]] auto gemini = make<RequestServer::GeminiProtocol>();
     [[maybe_unused]] auto http = make<RequestServer::HttpProtocol>();
     [[maybe_unused]] auto http = make<RequestServer::HttpProtocol>();

+ 7 - 7
Userland/Services/WebContent/main.cpp

@@ -6,20 +6,20 @@
 
 
 #include <LibCore/EventLoop.h>
 #include <LibCore/EventLoop.h>
 #include <LibCore/LocalServer.h>
 #include <LibCore/LocalServer.h>
+#include <LibCore/System.h>
 #include <LibIPC/ClientConnection.h>
 #include <LibIPC/ClientConnection.h>
 #include <LibMain/Main.h>
 #include <LibMain/Main.h>
-#include <LibSystem/Wrappers.h>
 #include <WebContent/ClientConnection.h>
 #include <WebContent/ClientConnection.h>
 
 
 ErrorOr<int> serenity_main(Main::Arguments)
 ErrorOr<int> serenity_main(Main::Arguments)
 {
 {
     Core::EventLoop event_loop;
     Core::EventLoop event_loop;
-    TRY(System::pledge("stdio recvfd sendfd accept unix rpath", nullptr));
-    TRY(System::unveil("/res", "r"));
-    TRY(System::unveil("/tmp/portal/request", "rw"));
-    TRY(System::unveil("/tmp/portal/image", "rw"));
-    TRY(System::unveil("/tmp/portal/websocket", "rw"));
-    TRY(System::unveil(nullptr, nullptr));
+    TRY(Core::System::pledge("stdio recvfd sendfd accept unix rpath", nullptr));
+    TRY(Core::System::unveil("/res", "r"));
+    TRY(Core::System::unveil("/tmp/portal/request", "rw"));
+    TRY(Core::System::unveil("/tmp/portal/image", "rw"));
+    TRY(Core::System::unveil("/tmp/portal/websocket", "rw"));
+    TRY(Core::System::unveil(nullptr, nullptr));
 
 
     auto socket = Core::LocalSocket::take_over_accepted_socket_from_system_server();
     auto socket = Core::LocalSocket::take_over_accepted_socket_from_system_server();
     VERIFY(socket);
     VERIFY(socket);

+ 5 - 5
Userland/Services/WebSocket/main.cpp

@@ -6,24 +6,24 @@
 
 
 #include <LibCore/EventLoop.h>
 #include <LibCore/EventLoop.h>
 #include <LibCore/LocalServer.h>
 #include <LibCore/LocalServer.h>
+#include <LibCore/System.h>
 #include <LibIPC/ClientConnection.h>
 #include <LibIPC/ClientConnection.h>
 #include <LibMain/Main.h>
 #include <LibMain/Main.h>
-#include <LibSystem/Wrappers.h>
 #include <LibTLS/Certificate.h>
 #include <LibTLS/Certificate.h>
 #include <WebSocket/ClientConnection.h>
 #include <WebSocket/ClientConnection.h>
 
 
 ErrorOr<int> serenity_main(Main::Arguments)
 ErrorOr<int> serenity_main(Main::Arguments)
 {
 {
-    TRY(System::pledge("stdio inet unix rpath sendfd recvfd", nullptr));
+    TRY(Core::System::pledge("stdio inet unix rpath sendfd recvfd", nullptr));
 
 
     // Ensure the certificates are read out here.
     // Ensure the certificates are read out here.
     [[maybe_unused]] auto& certs = DefaultRootCACertificates::the();
     [[maybe_unused]] auto& certs = DefaultRootCACertificates::the();
 
 
     Core::EventLoop event_loop;
     Core::EventLoop event_loop;
     // FIXME: Establish a connection to LookupServer and then drop "unix"?
     // FIXME: Establish a connection to LookupServer and then drop "unix"?
-    TRY(System::pledge("stdio inet unix sendfd recvfd", nullptr));
-    TRY(System::unveil("/tmp/portal/lookup", "rw"));
-    TRY(System::unveil(nullptr, nullptr));
+    TRY(Core::System::pledge("stdio inet unix sendfd recvfd", nullptr));
+    TRY(Core::System::unveil("/tmp/portal/lookup", "rw"));
+    TRY(Core::System::unveil(nullptr, nullptr));
 
 
     auto socket = Core::LocalSocket::take_over_accepted_socket_from_system_server();
     auto socket = Core::LocalSocket::take_over_accepted_socket_from_system_server();
     VERIFY(socket);
     VERIFY(socket);

+ 10 - 10
Userland/Services/WindowServer/main.cpp

@@ -12,25 +12,25 @@
 #include <LibCore/ConfigFile.h>
 #include <LibCore/ConfigFile.h>
 #include <LibCore/DirIterator.h>
 #include <LibCore/DirIterator.h>
 #include <LibCore/File.h>
 #include <LibCore/File.h>
+#include <LibCore/System.h>
 #include <LibGfx/Palette.h>
 #include <LibGfx/Palette.h>
 #include <LibGfx/SystemTheme.h>
 #include <LibGfx/SystemTheme.h>
 #include <LibMain/Main.h>
 #include <LibMain/Main.h>
-#include <LibSystem/Wrappers.h>
 #include <signal.h>
 #include <signal.h>
 #include <string.h>
 #include <string.h>
 
 
 ErrorOr<int> serenity_main(Main::Arguments)
 ErrorOr<int> serenity_main(Main::Arguments)
 {
 {
-    TRY(System::pledge("stdio video thread sendfd recvfd accept rpath wpath cpath unix proc sigaction", nullptr));
-    TRY(System::unveil("/res", "r"));
-    TRY(System::unveil("/tmp", "cw"));
-    TRY(System::unveil("/etc/WindowServer.ini", "rwc"));
-    TRY(System::unveil("/dev", "rw"));
+    TRY(Core::System::pledge("stdio video thread sendfd recvfd accept rpath wpath cpath unix proc sigaction", nullptr));
+    TRY(Core::System::unveil("/res", "r"));
+    TRY(Core::System::unveil("/tmp", "cw"));
+    TRY(Core::System::unveil("/etc/WindowServer.ini", "rwc"));
+    TRY(Core::System::unveil("/dev", "rw"));
 
 
     struct sigaction act = {};
     struct sigaction act = {};
     act.sa_flags = SA_NOCLDWAIT;
     act.sa_flags = SA_NOCLDWAIT;
     act.sa_handler = SIG_IGN;
     act.sa_handler = SIG_IGN;
-    TRY(System::sigaction(SIGCHLD, &act, nullptr));
+    TRY(Core::System::sigaction(SIGCHLD, &act, nullptr));
 
 
     auto wm_config = Core::ConfigFile::open("/etc/WindowServer.ini");
     auto wm_config = Core::ConfigFile::open("/etc/WindowServer.ini");
     auto theme_name = wm_config->read_entry("Theme", "Name", "Default");
     auto theme_name = wm_config->read_entry("Theme", "Name", "Default");
@@ -48,7 +48,7 @@ ErrorOr<int> serenity_main(Main::Arguments)
 
 
     WindowServer::EventLoop loop;
     WindowServer::EventLoop loop;
 
 
-    TRY(System::pledge("stdio video thread sendfd recvfd accept rpath wpath cpath proc", nullptr));
+    TRY(Core::System::pledge("stdio video thread sendfd recvfd accept rpath wpath cpath proc", nullptr));
 
 
     // First check which screens are explicitly configured
     // First check which screens are explicitly configured
     {
     {
@@ -114,13 +114,13 @@ ErrorOr<int> serenity_main(Main::Arguments)
     auto am = WindowServer::AppletManager::construct();
     auto am = WindowServer::AppletManager::construct();
     auto mm = WindowServer::MenuManager::construct();
     auto mm = WindowServer::MenuManager::construct();
 
 
-    TRY(System::unveil("/tmp", ""));
+    TRY(Core::System::unveil("/tmp", ""));
 
 
     // NOTE: Because we dynamically need to be able to open new /dev/fb*
     // NOTE: Because we dynamically need to be able to open new /dev/fb*
     // devices we can't really unveil all of /dev unless we have some
     // devices we can't really unveil all of /dev unless we have some
     // other mechanism that can hand us file descriptors for these.
     // other mechanism that can hand us file descriptors for these.
 
 
-    TRY(System::unveil(nullptr, nullptr));
+    TRY(Core::System::unveil(nullptr, nullptr));
 
 
     dbgln("Entering WindowServer main loop");
     dbgln("Entering WindowServer main loop");
     loop.exec();
     loop.exec();

+ 5 - 5
Userland/Utilities/id.cpp

@@ -7,8 +7,8 @@
 #include <AK/StringUtils.h>
 #include <AK/StringUtils.h>
 #include <LibCore/Account.h>
 #include <LibCore/Account.h>
 #include <LibCore/ArgsParser.h>
 #include <LibCore/ArgsParser.h>
+#include <LibCore/System.h>
 #include <LibMain/Main.h>
 #include <LibMain/Main.h>
-#include <LibSystem/Wrappers.h>
 #include <alloca.h>
 #include <alloca.h>
 #include <grp.h>
 #include <grp.h>
 #include <pwd.h>
 #include <pwd.h>
@@ -25,10 +25,10 @@ static String user_str;
 
 
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 {
 {
-    TRY(System::unveil("/etc/passwd", "r"));
-    TRY(System::unveil("/etc/group", "r"));
-    TRY(System::unveil(nullptr, nullptr));
-    TRY(System::pledge("stdio rpath", nullptr));
+    TRY(Core::System::unveil("/etc/passwd", "r"));
+    TRY(Core::System::unveil("/etc/group", "r"));
+    TRY(Core::System::unveil(nullptr, nullptr));
+    TRY(Core::System::pledge("stdio rpath", nullptr));
 
 
     Core::ArgsParser args_parser;
     Core::ArgsParser args_parser;
     args_parser.add_option(flag_print_uid, "Print UID", nullptr, 'u');
     args_parser.add_option(flag_print_uid, "Print UID", nullptr, 'u');

+ 2 - 2
Userland/Utilities/js.cpp

@@ -13,6 +13,7 @@
 #include <LibCore/ArgsParser.h>
 #include <LibCore/ArgsParser.h>
 #include <LibCore/File.h>
 #include <LibCore/File.h>
 #include <LibCore/StandardPaths.h>
 #include <LibCore/StandardPaths.h>
+#include <LibCore/System.h>
 #include <LibJS/AST.h>
 #include <LibJS/AST.h>
 #include <LibJS/Bytecode/BasicBlock.h>
 #include <LibJS/Bytecode/BasicBlock.h>
 #include <LibJS/Bytecode/Generator.h>
 #include <LibJS/Bytecode/Generator.h>
@@ -61,7 +62,6 @@
 #include <LibJS/Runtime/Value.h>
 #include <LibJS/Runtime/Value.h>
 #include <LibLine/Editor.h>
 #include <LibLine/Editor.h>
 #include <LibMain/Main.h>
 #include <LibMain/Main.h>
-#include <LibSystem/Wrappers.h>
 #include <fcntl.h>
 #include <fcntl.h>
 #include <signal.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdio.h>
@@ -1107,7 +1107,7 @@ public:
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 {
 {
 #ifdef __serenity__
 #ifdef __serenity__
-    TRY(System::pledge("stdio rpath wpath cpath tty sigaction", nullptr));
+    TRY(Core::System::pledge("stdio rpath wpath cpath tty sigaction", nullptr));
 #endif
 #endif
 
 
     bool gc_on_every_allocation = false;
     bool gc_on_every_allocation = false;

+ 2 - 2
Userland/Utilities/nproc.cpp

@@ -6,12 +6,12 @@
 
 
 #include <AK/JsonObject.h>
 #include <AK/JsonObject.h>
 #include <LibCore/File.h>
 #include <LibCore/File.h>
+#include <LibCore/System.h>
 #include <LibMain/Main.h>
 #include <LibMain/Main.h>
-#include <LibSystem/Wrappers.h>
 
 
 ErrorOr<int> serenity_main(Main::Arguments)
 ErrorOr<int> serenity_main(Main::Arguments)
 {
 {
-    TRY(System::pledge("stdio rpath", nullptr));
+    TRY(Core::System::pledge("stdio rpath", nullptr));
     auto file = TRY(Core::File::open("/proc/cpuinfo", Core::OpenMode::ReadOnly));
     auto file = TRY(Core::File::open("/proc/cpuinfo", Core::OpenMode::ReadOnly));
 
 
     auto buffer = file->read_all();
     auto buffer = file->read_all();

+ 7 - 7
Userland/Utilities/w.cpp

@@ -9,20 +9,20 @@
 #include <LibCore/DateTime.h>
 #include <LibCore/DateTime.h>
 #include <LibCore/File.h>
 #include <LibCore/File.h>
 #include <LibCore/ProcessStatisticsReader.h>
 #include <LibCore/ProcessStatisticsReader.h>
+#include <LibCore/System.h>
 #include <LibMain/Main.h>
 #include <LibMain/Main.h>
-#include <LibSystem/Wrappers.h>
 #include <pwd.h>
 #include <pwd.h>
 #include <sys/stat.h>
 #include <sys/stat.h>
 #include <time.h>
 #include <time.h>
 
 
 ErrorOr<int> serenity_main(Main::Arguments)
 ErrorOr<int> serenity_main(Main::Arguments)
 {
 {
-    TRY(System::pledge("stdio rpath", nullptr));
-    TRY(System::unveil("/dev", "r"));
-    TRY(System::unveil("/etc/passwd", "r"));
-    TRY(System::unveil("/var/run/utmp", "r"));
-    TRY(System::unveil("/proc", "r"));
-    TRY(System::unveil(nullptr, nullptr));
+    TRY(Core::System::pledge("stdio rpath", nullptr));
+    TRY(Core::System::unveil("/dev", "r"));
+    TRY(Core::System::unveil("/etc/passwd", "r"));
+    TRY(Core::System::unveil("/var/run/utmp", "r"));
+    TRY(Core::System::unveil("/proc", "r"));
+    TRY(Core::System::unveil(nullptr, nullptr));
 
 
     auto file = TRY(Core::File::open("/var/run/utmp", Core::OpenMode::ReadOnly));
     auto file = TRY(Core::File::open("/var/run/utmp", Core::OpenMode::ReadOnly));
     auto json = TRY(JsonValue::from_string(file->read_all()));
     auto json = TRY(JsonValue::from_string(file->read_all()));