diff options
Diffstat (limited to 'Libraries/LibC')
-rw-r--r-- | Libraries/LibC/SharedBuffer.cpp | 14 | ||||
-rw-r--r-- | Libraries/LibC/SharedBuffer.h | 3 | ||||
-rw-r--r-- | Libraries/LibC/unistd.cpp | 10 | ||||
-rw-r--r-- | Libraries/LibC/unistd.h | 3 |
4 files changed, 24 insertions, 6 deletions
diff --git a/Libraries/LibC/SharedBuffer.cpp b/Libraries/LibC/SharedBuffer.cpp index ef7e31e621..1a0c3a9701 100644 --- a/Libraries/LibC/SharedBuffer.cpp +++ b/Libraries/LibC/SharedBuffer.cpp @@ -3,10 +3,10 @@ #include <stdio.h> #include <unistd.h> -RefPtr<SharedBuffer> SharedBuffer::create(pid_t peer, int size) +RefPtr<SharedBuffer> SharedBuffer::create_with_size(int size) { void* data; - int shared_buffer_id = create_shared_buffer(peer, size, &data); + int shared_buffer_id = create_shared_buffer(size, &data); if (shared_buffer_id < 0) { perror("create_shared_buffer"); return nullptr; @@ -14,6 +14,16 @@ RefPtr<SharedBuffer> SharedBuffer::create(pid_t peer, int size) return adopt(*new SharedBuffer(shared_buffer_id, size, data)); } +bool SharedBuffer::share_with(pid_t peer) +{ + int ret = share_buffer_with(shared_buffer_id(), peer); + if (ret < 0) { + perror("share_buffer_with"); + return false; + } + return true; +} + RefPtr<SharedBuffer> SharedBuffer::create_from_shared_buffer_id(int shared_buffer_id) { void* data = get_shared_buffer(shared_buffer_id); diff --git a/Libraries/LibC/SharedBuffer.h b/Libraries/LibC/SharedBuffer.h index aec7ab3047..2d1cdfc423 100644 --- a/Libraries/LibC/SharedBuffer.h +++ b/Libraries/LibC/SharedBuffer.h @@ -5,10 +5,11 @@ class SharedBuffer : public RefCounted<SharedBuffer> { public: - static RefPtr<SharedBuffer> create(pid_t peer, int); + static RefPtr<SharedBuffer> create_with_size(int); static RefPtr<SharedBuffer> create_from_shared_buffer_id(int); ~SharedBuffer(); + bool share_with(pid_t); int shared_buffer_id() const { return m_shared_buffer_id; } void seal(); int size() const { return m_size; } diff --git a/Libraries/LibC/unistd.cpp b/Libraries/LibC/unistd.cpp index d4622bba1f..b2307f1f7c 100644 --- a/Libraries/LibC/unistd.cpp +++ b/Libraries/LibC/unistd.cpp @@ -423,9 +423,15 @@ int read_tsc(unsigned* lsw, unsigned* msw) __RETURN_WITH_ERRNO(rc, rc, -1); } -int create_shared_buffer(pid_t peer_pid, int size, void** buffer) +int create_shared_buffer(int size, void** buffer) { - int rc = syscall(SC_create_shared_buffer, peer_pid, size, buffer); + int rc = syscall(SC_create_shared_buffer, size, buffer); + __RETURN_WITH_ERRNO(rc, rc, -1); +} + +int share_buffer_with(int shared_buffer_id, pid_t peer_pid) +{ + int rc = syscall(SC_share_buffer_with, shared_buffer_id, peer_pid); __RETURN_WITH_ERRNO(rc, rc, -1); } diff --git a/Libraries/LibC/unistd.h b/Libraries/LibC/unistd.h index 42235b0e63..806efbebe0 100644 --- a/Libraries/LibC/unistd.h +++ b/Libraries/LibC/unistd.h @@ -21,7 +21,8 @@ int gettid(); int donate(int tid); int create_thread(int (*)(void*), void*); void exit_thread(int); -int create_shared_buffer(pid_t peer_pid, int, void** buffer); +int create_shared_buffer(int, void** buffer); +int share_buffer_with(int, pid_t peer_pid); void* get_shared_buffer(int shared_buffer_id); int release_shared_buffer(int shared_buffer_id); int seal_shared_buffer(int shared_buffer_id); |