From 367bb9e4eb365bc0a03fc9eba65ce411397b2e77 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 20 Mar 2019 17:14:48 +0100 Subject: [PATCH] Kernel: Remove ioctl for getting a socket peer's PID. Now that everything is nice and mature, the WindowServer can just use the client PID it receives in the Greeting message, and we can get rid of this hacky ioctl. :^) --- Kernel/Process.cpp | 7 ------- Servers/WindowServer/WSClientConnection.cpp | 10 ---------- Servers/WindowServer/WSClientConnection.h | 5 +++-- Servers/WindowServer/WSMessageLoop.cpp | 3 +++ 4 files changed, 6 insertions(+), 19 deletions(-) diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 995144d2a0..60f67afba2 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -1939,13 +1939,6 @@ int Process::sys$ioctl(int fd, unsigned request, unsigned arg) auto* descriptor = file_descriptor(fd); if (!descriptor) return -EBADF; - if (descriptor->is_socket() && request == 413) { - auto* pid = (pid_t*)arg; - if (!validate_write_typed(pid)) - return -EFAULT; - *pid = descriptor->socket()->origin_pid(); - return 0; - } if (!descriptor->is_device()) return -ENOTTY; return descriptor->device()->ioctl(*this, request, arg); diff --git a/Servers/WindowServer/WSClientConnection.cpp b/Servers/WindowServer/WSClientConnection.cpp index b3b9c9ac51..0c577897c0 100644 --- a/Servers/WindowServer/WSClientConnection.cpp +++ b/Servers/WindowServer/WSClientConnection.cpp @@ -40,9 +40,6 @@ WSClientConnection::WSClientConnection(int fd) static int s_next_client_id = 0; m_client_id = ++s_next_client_id; - int rc = ioctl(m_fd, 413, (int)&m_pid); - ASSERT(rc == 0); - if (!s_connections) s_connections = new HashMap; s_connections->set(m_client_id, this); @@ -86,13 +83,6 @@ void WSClientConnection::post_message(const WSAPI_ServerMessage& message) ASSERT(nwritten == sizeof(message)); } -RetainPtr WSClientConnection::create_shared_bitmap(GraphicsBitmap::Format format, const Size& size) -{ - auto shared_buffer = SharedBuffer::create(m_pid, size.area() * sizeof(RGBA32)); - ASSERT(shared_buffer); - return GraphicsBitmap::create_with_shared_buffer(format, *shared_buffer, size); -} - void WSClientConnection::on_message(WSMessage& message) { if (message.is_client_request()) { diff --git a/Servers/WindowServer/WSClientConnection.h b/Servers/WindowServer/WSClientConnection.h index 06e643ed37..ea8f2571d1 100644 --- a/Servers/WindowServer/WSClientConnection.h +++ b/Servers/WindowServer/WSClientConnection.h @@ -22,7 +22,6 @@ public: static void for_each_client(Function); void post_message(const WSAPI_ServerMessage&); - RetainPtr create_shared_bitmap(GraphicsBitmap::Format, const Size&); int client_id() const { return m_client_id; } WSMenuBar* app_menubar() { return m_app_menubar.ptr(); } @@ -32,6 +31,8 @@ public: bool is_showing_modal_window() const; + void set_client_pid(pid_t pid) { m_pid = pid; } + template void for_each_window_matching(Matching, Callback); template void for_each_window(Callback); @@ -66,7 +67,7 @@ private: int m_client_id { 0 }; int m_fd { -1 }; - pid_t m_pid { 0 }; + pid_t m_pid { -1 }; HashMap> m_windows; HashMap> m_menubars; diff --git a/Servers/WindowServer/WSMessageLoop.cpp b/Servers/WindowServer/WSMessageLoop.cpp index a774317ab7..7ef54a7945 100644 --- a/Servers/WindowServer/WSMessageLoop.cpp +++ b/Servers/WindowServer/WSMessageLoop.cpp @@ -257,6 +257,9 @@ void WSMessageLoop::on_receive_from_client(int client_id, const WSAPI_ClientMess WSClientConnection& client = *WSClientConnection::from_client_id(client_id); switch (message.type) { + case WSAPI_ClientMessage::Type::Greeting: + client.set_client_pid(message.greeting.client_pid); + break; case WSAPI_ClientMessage::Type::CreateMenubar: post_message(client, make(client_id)); break;