Kernel+LibC: Rename shared buffer syscalls to use a prefix

This feels a lot more consistent and Unixy:

    create_shared_buffer()   => shbuf_create()
    share_buffer_with()      => shbuf_allow_pid()
    share_buffer_globally()  => shbuf_allow_all()
    get_shared_buffer()      => shbuf_get()
    release_shared_buffer()  => shbuf_release()
    seal_shared_buffer()     => shbuf_seal()
    get_shared_buffer_size() => shbuf_get_size()

Also, "shared_buffer_id" is shortened to "shbuf_id" all around.
This commit is contained in:
Andreas Kling 2020-02-28 11:45:19 +01:00
parent 8460d02651
commit f72e5bbb17
36 changed files with 549 additions and 549 deletions

View file

@ -37,19 +37,19 @@ namespace AK {
RefPtr<SharedBuffer> SharedBuffer::create_with_size(int size)
{
void* data;
int shared_buffer_id = create_shared_buffer(size, &data);
if (shared_buffer_id < 0) {
perror("create_shared_buffer");
int shbuf_id = shbuf_create(size, &data);
if (shbuf_id < 0) {
perror("shbuf_create");
return nullptr;
}
return adopt(*new SharedBuffer(shared_buffer_id, size, data));
return adopt(*new SharedBuffer(shbuf_id, size, data));
}
bool SharedBuffer::share_with(pid_t peer)
{
int ret = share_buffer_with(shared_buffer_id(), peer);
int ret = shbuf_allow_pid(shbuf_id(), peer);
if (ret < 0) {
perror("share_buffer_with");
perror("shbuf_allow_pid");
return false;
}
return true;
@ -57,31 +57,31 @@ bool SharedBuffer::share_with(pid_t peer)
bool SharedBuffer::share_globally()
{
int ret = share_buffer_globally(shared_buffer_id());
int ret = shbuf_allow_all(shbuf_id());
if (ret < 0) {
perror("share_buffer_globally");
perror("shbuf_allow_all");
return false;
}
return true;
}
RefPtr<SharedBuffer> SharedBuffer::create_from_shared_buffer_id(int shared_buffer_id)
RefPtr<SharedBuffer> SharedBuffer::create_from_shbuf_id(int shbuf_id)
{
void* data = get_shared_buffer(shared_buffer_id);
void* data = shbuf_get(shbuf_id);
if (data == (void*)-1) {
perror("get_shared_buffer");
perror("shbuf_get");
return nullptr;
}
int size = get_shared_buffer_size(shared_buffer_id);
int size = shbuf_get_size(shbuf_id);
if (size < 0) {
perror("get_shared_buffer_size");
perror("shbuf_get_size");
return nullptr;
}
return adopt(*new SharedBuffer(shared_buffer_id, size, data));
return adopt(*new SharedBuffer(shbuf_id, size, data));
}
SharedBuffer::SharedBuffer(int shared_buffer_id, int size, void* data)
: m_shared_buffer_id(shared_buffer_id)
SharedBuffer::SharedBuffer(int shbuf_id, int size, void* data)
: m_shbuf_id(shbuf_id)
, m_size(size)
, m_data(data)
{
@ -89,32 +89,32 @@ SharedBuffer::SharedBuffer(int shared_buffer_id, int size, void* data)
SharedBuffer::~SharedBuffer()
{
if (m_shared_buffer_id >= 0) {
int rc = release_shared_buffer(m_shared_buffer_id);
if (m_shbuf_id >= 0) {
int rc = shbuf_release(m_shbuf_id);
if (rc < 0) {
perror("release_shared_buffer");
perror("shbuf_release");
}
}
}
void SharedBuffer::seal()
{
int rc = seal_shared_buffer(m_shared_buffer_id);
int rc = shbuf_seal(m_shbuf_id);
if (rc < 0) {
perror("seal_shared_buffer");
perror("shbuf_seal");
ASSERT_NOT_REACHED();
}
}
void SharedBuffer::set_volatile()
{
u32 rc = syscall(SC_set_shared_buffer_volatile, m_shared_buffer_id, true);
u32 rc = syscall(SC_shbuf_set_volatile, m_shbuf_id, true);
ASSERT(rc == 0);
}
bool SharedBuffer::set_nonvolatile()
{
u32 rc = syscall(SC_set_shared_buffer_volatile, m_shared_buffer_id, false);
u32 rc = syscall(SC_shbuf_set_volatile, m_shbuf_id, false);
if (rc == 0)
return true;
if (rc == 1)

View file

@ -36,12 +36,12 @@ namespace AK {
class SharedBuffer : public RefCounted<SharedBuffer> {
public:
static RefPtr<SharedBuffer> create_with_size(int);
static RefPtr<SharedBuffer> create_from_shared_buffer_id(int);
static RefPtr<SharedBuffer> create_from_shbuf_id(int);
~SharedBuffer();
bool share_globally();
bool share_with(pid_t);
int shared_buffer_id() const { return m_shared_buffer_id; }
int shbuf_id() const { return m_shbuf_id; }
void seal();
int size() const { return m_size; }
void* data() { return m_data; }
@ -50,9 +50,9 @@ public:
[[nodiscard]] bool set_nonvolatile();
private:
SharedBuffer(int shared_buffer_id, int size, void*);
SharedBuffer(int shbuf_id, int size, void*);
int m_shared_buffer_id { -1 };
int m_shbuf_id { -1 };
int m_size { 0 };
void* m_data;
};

View file

@ -103,14 +103,14 @@ void PlaybackManager::remove_dead_buffers()
int id = m_connection->get_playing_buffer();
int current_id = -1;
if (m_current_buffer)
current_id = m_current_buffer->shared_buffer_id();
current_id = m_current_buffer->shbuf_id();
if (id >= 0 && id != current_id) {
while (!m_buffers.is_empty()) {
--m_next_ptr;
auto buffer = m_buffers.take_first();
if (buffer->shared_buffer_id() == id) {
if (buffer->shbuf_id() == id) {
m_current_buffer = buffer;
break;
}

View file

@ -267,7 +267,7 @@ GUI::Variant ProcessModel::data(const GUI::ModelIndex& index, Role role) const
switch (index.column()) {
case Column::Icon:
if (thread.current_state.icon_id != -1) {
auto icon_buffer = SharedBuffer::create_from_shared_buffer_id(thread.current_state.icon_id);
auto icon_buffer = SharedBuffer::create_from_shbuf_id(thread.current_state.icon_id);
if (icon_buffer) {
auto icon_bitmap = Gfx::Bitmap::create_with_shared_buffer(Gfx::BitmapFormat::RGBA32, *icon_buffer, { 16, 16 });
if (icon_bitmap)

View file

@ -177,7 +177,7 @@ void TaskbarWindow::wm_event(GUI::WMEvent& event)
changed_event.icon_buffer_id());
#endif
if (auto* window = WindowList::the().window(identifier)) {
auto buffer = SharedBuffer::create_from_shared_buffer_id(changed_event.icon_buffer_id());
auto buffer = SharedBuffer::create_from_shbuf_id(changed_event.icon_buffer_id());
ASSERT(buffer);
window->button()->set_icon(Gfx::Bitmap::create_with_shared_buffer(Gfx::BitmapFormat::RGBA32, *buffer, changed_event.icon_size()));
}

View file

@ -1,27 +0,0 @@
## Name
create\_shared\_buffer - create a shareable memory buffer
## Synopsis
```**c++
#include <SharedBuffer.h>
int create_shared_buffer(int size, void** buffer);
```
## Description
Creates a new memory region that can be shared with other processes. The region is only accessible to the creating process by default.
## Return value
If a region is successfully created, `create_shared_buffer()` stores a pointer to the memory in `buffer` and returns a buffer ID. Otherwise, it returns -1 and sets `errno` to describe the error.
## Errors
* `EINVAL`: `size` is zero or negative.
* `EFAULT`: `buffer` is not a valid address.
## See also
* [`share_buffer_with`(2)](share_buffer_with.md)

View file

@ -1,17 +1,17 @@
## Name
share\_buffer\_with - allow another process to map a shareable buffer
shbuf\_allow\_pid - allow another process to map a shareable buffer
## Synopsis
```**c++
#include <SharedBuffer.h>
int share_buffer_with(int shared_buffer_id, pid_t peer_pid);
int shbuf_allow_pid(int shbuf_id, pid_t peer_pid);
```
## Description
Gives the process with PID `peer_pid` permission to map the shareable buffer with ID `shared_buffer_id`.
Gives the process with PID `peer_pid` permission to map the shareable buffer with ID `shbuf_id`.
## Return value
@ -19,10 +19,10 @@ On success, returns 0. Otherwise, returns -1 and `errno` is set.
## Errors
* `EINVAL`: `peer_pid` is invalid, or `shared_buffer_id` is not a valid ID.
* `EPERM`: The calling process does not have access to the buffer with `shared_buffer_id`.
* `EINVAL`: `peer_pid` is invalid, or `shbuf_id` is not a valid ID.
* `EPERM`: The calling process does not have access to the buffer with `shbuf_id`.
* `ESRCH`: No process with PID `peer_pid` is found.
## See also
* [`create_shared_buffer`(2)](create_shared_buffer.md)
* [`shbuf_create`(2)](shbuf_create.md)

View file

@ -0,0 +1,27 @@
## Name
shbuf\_create - create a shareable memory buffer
## Synopsis
```**c++
#include <SharedBuffer.h>
int shbuf_create(int size, void** buffer);
```
## Description
Creates a new memory region that can be shared with other processes. The region is only accessible to the calling process by default.
## Return value
If a region is successfully created, `shbuf_create()` stores a pointer to the memory in `buffer` and returns a buffer ID. Otherwise, it returns -1 and sets `errno` to describe the error.
## Errors
* `EINVAL`: `size` is zero or negative.
* `EFAULT`: `buffer` is not a valid address.
## See also
* [`shbuf_allow_pid`(2)](shbuf_allow_pid.md)

View file

@ -3555,7 +3555,7 @@ void Process::disown_all_shared_buffers()
shared_buffer->disown(m_pid);
}
int Process::sys$create_shared_buffer(int size, void** buffer)
int Process::sys$shbuf_create(int size, void** buffer)
{
REQUIRE_PROMISE(shared_buffer);
if (!size || size < 0)
@ -3565,29 +3565,29 @@ int Process::sys$create_shared_buffer(int size, void** buffer)
return -EFAULT;
LOCKER(shared_buffers().lock());
static int s_next_shared_buffer_id;
int shared_buffer_id = ++s_next_shared_buffer_id;
auto shared_buffer = make<SharedBuffer>(shared_buffer_id, size);
static int s_next_shbuf_id;
int shbuf_id = ++s_next_shbuf_id;
auto shared_buffer = make<SharedBuffer>(shbuf_id, size);
shared_buffer->share_with(m_pid);
void* address = shared_buffer->ref_for_process_and_get_address(*this);
copy_to_user(buffer, &address);
ASSERT((int)shared_buffer->size() >= size);
#ifdef SHARED_BUFFER_DEBUG
kprintf("%s(%u): Created shared buffer %d @ %p (%u bytes, vmobject is %u)\n", name().characters(), pid(), shared_buffer_id, buffer, size, shared_buffer->size());
kprintf("%s(%u): Created shared buffer %d @ %p (%u bytes, vmobject is %u)\n", name().characters(), pid(), shbuf_id, buffer, size, shared_buffer->size());
#endif
shared_buffers().resource().set(shared_buffer_id, move(shared_buffer));
shared_buffers().resource().set(shbuf_id, move(shared_buffer));
return shared_buffer_id;
return shbuf_id;
}
int Process::sys$share_buffer_with(int shared_buffer_id, pid_t peer_pid)
int Process::sys$shbuf_allow_pid(int shbuf_id, pid_t peer_pid)
{
REQUIRE_PROMISE(shared_buffer);
if (!peer_pid || peer_pid < 0 || peer_pid == m_pid)
return -EINVAL;
LOCKER(shared_buffers().lock());
auto it = shared_buffers().resource().find(shared_buffer_id);
auto it = shared_buffers().resource().find(shbuf_id);
if (it == shared_buffers().resource().end())
return -EINVAL;
auto& shared_buffer = *(*it).value;
@ -3603,11 +3603,11 @@ int Process::sys$share_buffer_with(int shared_buffer_id, pid_t peer_pid)
return 0;
}
int Process::sys$share_buffer_globally(int shared_buffer_id)
int Process::sys$shbuf_allow_all(int shbuf_id)
{
REQUIRE_PROMISE(shared_buffer);
LOCKER(shared_buffers().lock());
auto it = shared_buffers().resource().find(shared_buffer_id);
auto it = shared_buffers().resource().find(shbuf_id);
if (it == shared_buffers().resource().end())
return -EINVAL;
auto& shared_buffer = *(*it).value;
@ -3617,84 +3617,84 @@ int Process::sys$share_buffer_globally(int shared_buffer_id)
return 0;
}
int Process::sys$release_shared_buffer(int shared_buffer_id)
int Process::sys$shbuf_release(int shbuf_id)
{
REQUIRE_PROMISE(shared_buffer);
LOCKER(shared_buffers().lock());
auto it = shared_buffers().resource().find(shared_buffer_id);
auto it = shared_buffers().resource().find(shbuf_id);
if (it == shared_buffers().resource().end())
return -EINVAL;
auto& shared_buffer = *(*it).value;
if (!shared_buffer.is_shared_with(m_pid))
return -EPERM;
#ifdef SHARED_BUFFER_DEBUG
kprintf("%s(%u): Releasing shared buffer %d, buffer count: %u\n", name().characters(), pid(), shared_buffer_id, shared_buffers().resource().size());
kprintf("%s(%u): Releasing shared buffer %d, buffer count: %u\n", name().characters(), pid(), shbuf_id, shared_buffers().resource().size());
#endif
shared_buffer.deref_for_process(*this);
return 0;
}
void* Process::sys$get_shared_buffer(int shared_buffer_id)
void* Process::sys$shbuf_get(int shbuf_id)
{
REQUIRE_PROMISE(shared_buffer);
LOCKER(shared_buffers().lock());
auto it = shared_buffers().resource().find(shared_buffer_id);
auto it = shared_buffers().resource().find(shbuf_id);
if (it == shared_buffers().resource().end())
return (void*)-EINVAL;
auto& shared_buffer = *(*it).value;
if (!shared_buffer.is_shared_with(m_pid))
return (void*)-EPERM;
#ifdef SHARED_BUFFER_DEBUG
kprintf("%s(%u): Retaining shared buffer %d, buffer count: %u\n", name().characters(), pid(), shared_buffer_id, shared_buffers().resource().size());
kprintf("%s(%u): Retaining shared buffer %d, buffer count: %u\n", name().characters(), pid(), shbuf_id, shared_buffers().resource().size());
#endif
return shared_buffer.ref_for_process_and_get_address(*this);
}
int Process::sys$seal_shared_buffer(int shared_buffer_id)
int Process::sys$shbuf_seal(int shbuf_id)
{
REQUIRE_PROMISE(shared_buffer);
LOCKER(shared_buffers().lock());
auto it = shared_buffers().resource().find(shared_buffer_id);
auto it = shared_buffers().resource().find(shbuf_id);
if (it == shared_buffers().resource().end())
return -EINVAL;
auto& shared_buffer = *(*it).value;
if (!shared_buffer.is_shared_with(m_pid))
return -EPERM;
#ifdef SHARED_BUFFER_DEBUG
kprintf("%s(%u): Sealing shared buffer %d\n", name().characters(), pid(), shared_buffer_id);
kprintf("%s(%u): Sealing shared buffer %d\n", name().characters(), pid(), shbuf_id);
#endif
shared_buffer.seal();
return 0;
}
int Process::sys$get_shared_buffer_size(int shared_buffer_id)
int Process::sys$shbuf_get_size(int shbuf_id)
{
REQUIRE_PROMISE(shared_buffer);
LOCKER(shared_buffers().lock());
auto it = shared_buffers().resource().find(shared_buffer_id);
auto it = shared_buffers().resource().find(shbuf_id);
if (it == shared_buffers().resource().end())
return -EINVAL;
auto& shared_buffer = *(*it).value;
if (!shared_buffer.is_shared_with(m_pid))
return -EPERM;
#ifdef SHARED_BUFFER_DEBUG
kprintf("%s(%u): Get shared buffer %d size: %u\n", name().characters(), pid(), shared_buffer_id, shared_buffers().resource().size());
kprintf("%s(%u): Get shared buffer %d size: %u\n", name().characters(), pid(), shbuf_id, shared_buffers().resource().size());
#endif
return shared_buffer.size();
}
int Process::sys$set_shared_buffer_volatile(int shared_buffer_id, bool state)
int Process::sys$shbuf_set_volatile(int shbuf_id, bool state)
{
REQUIRE_PROMISE(shared_buffer);
LOCKER(shared_buffers().lock());
auto it = shared_buffers().resource().find(shared_buffer_id);
auto it = shared_buffers().resource().find(shbuf_id);
if (it == shared_buffers().resource().end())
return -EINVAL;
auto& shared_buffer = *(*it).value;
if (!shared_buffer.is_shared_with(m_pid))
return -EPERM;
#ifdef SHARED_BUFFER_DEBUG
kprintf("%s(%u): Set shared buffer %d volatile: %u\n", name().characters(), pid(), shared_buffer_id, state);
kprintf("%s(%u): Set shared buffer %d volatile: %u\n", name().characters(), pid(), shbuf_id, state);
#endif
if (!state) {
bool was_purged = shared_buffer.vmobject().was_purged();

View file

@ -273,14 +273,14 @@ public:
int sys$rename(const Syscall::SC_rename_params*);
int sys$systrace(pid_t);
int sys$mknod(const Syscall::SC_mknod_params*);
int sys$create_shared_buffer(int, void** buffer);
int sys$share_buffer_with(int, pid_t peer_pid);
int sys$share_buffer_globally(int);
void* sys$get_shared_buffer(int shared_buffer_id);
int sys$release_shared_buffer(int shared_buffer_id);
int sys$seal_shared_buffer(int shared_buffer_id);
int sys$get_shared_buffer_size(int shared_buffer_id);
int sys$set_shared_buffer_volatile(int shared_buffer_id, bool);
int sys$shbuf_create(int, void** buffer);
int sys$shbuf_allow_pid(int, pid_t peer_pid);
int sys$shbuf_allow_all(int);
void* sys$shbuf_get(int shbuf_id);
int sys$shbuf_release(int shbuf_id);
int sys$shbuf_seal(int shbuf_id);
int sys$shbuf_get_size(int shbuf_id);
int sys$shbuf_set_volatile(int shbuf_id, bool);
int sys$halt();
int sys$reboot();
int sys$set_process_icon(int icon_id);

View file

@ -46,7 +46,7 @@ void SharedBuffer::sanity_check(const char* what)
found_refs += ref.count;
if (found_refs != m_total_refs) {
dbg() << what << " sanity -- SharedBuffer{" << this << "} id: " << m_shared_buffer_id << " has total refs " << m_total_refs << " but we found " << found_refs;
dbg() << what << " sanity -- SharedBuffer{" << this << "} id: " << m_shbuf_id << " has total refs " << m_total_refs << " but we found " << found_refs;
for (const auto& ref : m_refs) {
dbg() << " ref from pid " << ref.pid << ": refcnt " << ref.count;
}
@ -109,7 +109,7 @@ void SharedBuffer::share_with(pid_t peer_pid)
return;
for (auto& ref : m_refs) {
if (ref.pid == peer_pid) {
// don't increment the reference count yet; let them get_shared_buffer it first.
// don't increment the reference count yet; let them shbuf_get it first.
sanity_check("share_with (old ref)");
return;
}
@ -129,12 +129,12 @@ void SharedBuffer::deref_for_process(Process& process)
m_total_refs--;
if (ref.count == 0) {
#ifdef SHARED_BUFFER_DEBUG
dbg() << "Releasing shared buffer reference on " << m_shared_buffer_id << " of size " << size() << " by PID " << process.pid();
dbg() << "Releasing shared buffer reference on " << m_shbuf_id << " of size " << size() << " by PID " << process.pid();
#endif
process.deallocate_region(*ref.region);
m_refs.unstable_remove(i);
#ifdef SHARED_BUFFER_DEBUG
dbg() << "Released shared buffer reference on " << m_shared_buffer_id << " of size " << size() << " by PID " << process.pid();
dbg() << "Released shared buffer reference on " << m_shbuf_id << " of size " << size() << " by PID " << process.pid();
#endif
sanity_check("deref_for_process");
destroy_if_unused();
@ -154,12 +154,12 @@ void SharedBuffer::disown(pid_t pid)
auto& ref = m_refs[i];
if (ref.pid == pid) {
#ifdef SHARED_BUFFER_DEBUG
dbg() << "Disowning shared buffer " << m_shared_buffer_id << " of size " << size() << " by PID " << pid;
dbg() << "Disowning shared buffer " << m_shbuf_id << " of size " << size() << " by PID " << pid;
#endif
m_total_refs -= ref.count;
m_refs.unstable_remove(i);
#ifdef SHARED_BUFFER_DEBUG
dbg() << "Disowned shared buffer " << m_shared_buffer_id << " of size " << size() << " by PID " << pid;
dbg() << "Disowned shared buffer " << m_shbuf_id << " of size " << size() << " by PID " << pid;
#endif
destroy_if_unused();
return;
@ -173,10 +173,10 @@ void SharedBuffer::destroy_if_unused()
sanity_check("destroy_if_unused");
if (m_total_refs == 0) {
#ifdef SHARED_BUFFER_DEBUG
kprintf("Destroying unused SharedBuffer{%p} id: %d\n", this, m_shared_buffer_id);
kprintf("Destroying unused SharedBuffer{%p} id: %d\n", this, m_shbuf_id);
#endif
auto count_before = shared_buffers().resource().size();
shared_buffers().resource().remove(m_shared_buffer_id);
shared_buffers().resource().remove(m_shbuf_id);
ASSERT(count_before != shared_buffers().resource().size());
}
}

View file

@ -48,18 +48,18 @@ private:
public:
SharedBuffer(int id, int size)
: m_shared_buffer_id(id)
: m_shbuf_id(id)
, m_vmobject(PurgeableVMObject::create_with_size(size))
{
#ifdef SHARED_BUFFER_DEBUG
dbg() << "Created shared buffer " << m_shared_buffer_id << " of size " << size;
dbg() << "Created shared buffer " << m_shbuf_id << " of size " << size;
#endif
}
~SharedBuffer()
{
#ifdef SHARED_BUFFER_DEBUG
dbg() << "Destroyed shared buffer " << m_shared_buffer_id << " of size " << size();
dbg() << "Destroyed shared buffer " << m_shbuf_id << " of size " << size();
#endif
}
@ -75,9 +75,9 @@ public:
void seal();
PurgeableVMObject& vmobject() { return m_vmobject; }
const PurgeableVMObject& vmobject() const { return m_vmobject; }
int id() const { return m_shared_buffer_id; }
int id() const { return m_shbuf_id; }
int m_shared_buffer_id { -1 };
int m_shbuf_id { -1 };
bool m_writable { true };
bool m_global { false };
NonnullRefPtr<PurgeableVMObject> m_vmobject;

View file

@ -42,161 +42,161 @@ typedef u32 socklen_t;
namespace Kernel {
#define ENUMERATE_SYSCALLS \
__ENUMERATE_SYSCALL(sleep) \
__ENUMERATE_SYSCALL(yield) \
__ENUMERATE_SYSCALL(open) \
__ENUMERATE_SYSCALL(close) \
__ENUMERATE_SYSCALL(read) \
__ENUMERATE_SYSCALL(lseek) \
__ENUMERATE_SYSCALL(kill) \
__ENUMERATE_SYSCALL(getuid) \
__ENUMERATE_SYSCALL(exit) \
__ENUMERATE_SYSCALL(getgid) \
__ENUMERATE_SYSCALL(getpid) \
__ENUMERATE_SYSCALL(waitid) \
__ENUMERATE_SYSCALL(mmap) \
__ENUMERATE_SYSCALL(munmap) \
__ENUMERATE_SYSCALL(get_dir_entries) \
__ENUMERATE_SYSCALL(getcwd) \
__ENUMERATE_SYSCALL(gettimeofday) \
__ENUMERATE_SYSCALL(gethostname) \
__ENUMERATE_SYSCALL(chdir) \
__ENUMERATE_SYSCALL(uname) \
__ENUMERATE_SYSCALL(set_mmap_name) \
__ENUMERATE_SYSCALL(readlink) \
__ENUMERATE_SYSCALL(write) \
__ENUMERATE_SYSCALL(ttyname_r) \
__ENUMERATE_SYSCALL(stat) \
__ENUMERATE_SYSCALL(getsid) \
__ENUMERATE_SYSCALL(setsid) \
__ENUMERATE_SYSCALL(getpgid) \
__ENUMERATE_SYSCALL(setpgid) \
__ENUMERATE_SYSCALL(getpgrp) \
__ENUMERATE_SYSCALL(fork) \
__ENUMERATE_SYSCALL(execve) \
__ENUMERATE_SYSCALL(geteuid) \
__ENUMERATE_SYSCALL(getegid) \
__ENUMERATE_SYSCALL(getdtablesize) \
__ENUMERATE_SYSCALL(dup) \
__ENUMERATE_SYSCALL(dup2) \
__ENUMERATE_SYSCALL(sigaction) \
__ENUMERATE_SYSCALL(getppid) \
__ENUMERATE_SYSCALL(umask) \
__ENUMERATE_SYSCALL(getgroups) \
__ENUMERATE_SYSCALL(setgroups) \
__ENUMERATE_SYSCALL(sigreturn) \
__ENUMERATE_SYSCALL(sigprocmask) \
__ENUMERATE_SYSCALL(sigpending) \
__ENUMERATE_SYSCALL(pipe) \
__ENUMERATE_SYSCALL(killpg) \
__ENUMERATE_SYSCALL(setuid) \
__ENUMERATE_SYSCALL(setgid) \
__ENUMERATE_SYSCALL(alarm) \
__ENUMERATE_SYSCALL(fstat) \
__ENUMERATE_SYSCALL(access) \
__ENUMERATE_SYSCALL(fcntl) \
__ENUMERATE_SYSCALL(ioctl) \
__ENUMERATE_SYSCALL(mkdir) \
__ENUMERATE_SYSCALL(times) \
__ENUMERATE_SYSCALL(utime) \
__ENUMERATE_SYSCALL(sync) \
__ENUMERATE_SYSCALL(ptsname_r) \
__ENUMERATE_SYSCALL(select) \
__ENUMERATE_SYSCALL(unlink) \
__ENUMERATE_SYSCALL(poll) \
__ENUMERATE_SYSCALL(rmdir) \
__ENUMERATE_SYSCALL(chmod) \
__ENUMERATE_SYSCALL(usleep) \
__ENUMERATE_SYSCALL(socket) \
__ENUMERATE_SYSCALL(bind) \
__ENUMERATE_SYSCALL(accept) \
__ENUMERATE_SYSCALL(listen) \
__ENUMERATE_SYSCALL(connect) \
__ENUMERATE_SYSCALL(create_shared_buffer) \
__ENUMERATE_SYSCALL(share_buffer_with) \
__ENUMERATE_SYSCALL(get_shared_buffer) \
__ENUMERATE_SYSCALL(release_shared_buffer) \
__ENUMERATE_SYSCALL(link) \
__ENUMERATE_SYSCALL(chown) \
__ENUMERATE_SYSCALL(fchmod) \
__ENUMERATE_SYSCALL(symlink) \
__ENUMERATE_SYSCALL(get_shared_buffer_size) \
__ENUMERATE_SYSCALL(seal_shared_buffer) \
__ENUMERATE_SYSCALL(sendto) \
__ENUMERATE_SYSCALL(recvfrom) \
__ENUMERATE_SYSCALL(getsockopt) \
__ENUMERATE_SYSCALL(setsockopt) \
__ENUMERATE_SYSCALL(create_thread) \
__ENUMERATE_SYSCALL(gettid) \
__ENUMERATE_SYSCALL(donate) \
__ENUMERATE_SYSCALL(rename) \
__ENUMERATE_SYSCALL(ftruncate) \
__ENUMERATE_SYSCALL(systrace) \
__ENUMERATE_SYSCALL(exit_thread) \
__ENUMERATE_SYSCALL(mknod) \
__ENUMERATE_SYSCALL(writev) \
__ENUMERATE_SYSCALL(beep) \
__ENUMERATE_SYSCALL(getsockname) \
__ENUMERATE_SYSCALL(getpeername) \
__ENUMERATE_SYSCALL(sched_setparam) \
__ENUMERATE_SYSCALL(sched_getparam) \
__ENUMERATE_SYSCALL(fchown) \
__ENUMERATE_SYSCALL(halt) \
__ENUMERATE_SYSCALL(reboot) \
__ENUMERATE_SYSCALL(mount) \
__ENUMERATE_SYSCALL(umount) \
__ENUMERATE_SYSCALL(dump_backtrace) \
__ENUMERATE_SYSCALL(dbgputch) \
__ENUMERATE_SYSCALL(dbgputstr) \
__ENUMERATE_SYSCALL(watch_file) \
__ENUMERATE_SYSCALL(share_buffer_globally) \
__ENUMERATE_SYSCALL(set_process_icon) \
__ENUMERATE_SYSCALL(mprotect) \
__ENUMERATE_SYSCALL(realpath) \
__ENUMERATE_SYSCALL(get_process_name) \
__ENUMERATE_SYSCALL(fchdir) \
__ENUMERATE_SYSCALL(getrandom) \
__ENUMERATE_SYSCALL(setkeymap) \
__ENUMERATE_SYSCALL(clock_gettime) \
__ENUMERATE_SYSCALL(clock_nanosleep) \
__ENUMERATE_SYSCALL(join_thread) \
__ENUMERATE_SYSCALL(module_load) \
__ENUMERATE_SYSCALL(module_unload) \
__ENUMERATE_SYSCALL(detach_thread) \
__ENUMERATE_SYSCALL(set_thread_name) \
__ENUMERATE_SYSCALL(get_thread_name) \
__ENUMERATE_SYSCALL(madvise) \
__ENUMERATE_SYSCALL(purge) \
__ENUMERATE_SYSCALL(set_shared_buffer_volatile) \
__ENUMERATE_SYSCALL(profiling_enable) \
__ENUMERATE_SYSCALL(profiling_disable) \
__ENUMERATE_SYSCALL(get_kernel_info_page) \
__ENUMERATE_SYSCALL(futex) \
__ENUMERATE_SYSCALL(set_thread_boost) \
__ENUMERATE_SYSCALL(set_process_boost) \
__ENUMERATE_SYSCALL(chroot) \
__ENUMERATE_SYSCALL(pledge) \
__ENUMERATE_SYSCALL(unveil) \
__ENUMERATE_SYSCALL(perf_event) \
#define ENUMERATE_SYSCALLS \
__ENUMERATE_SYSCALL(sleep) \
__ENUMERATE_SYSCALL(yield) \
__ENUMERATE_SYSCALL(open) \
__ENUMERATE_SYSCALL(close) \
__ENUMERATE_SYSCALL(read) \
__ENUMERATE_SYSCALL(lseek) \
__ENUMERATE_SYSCALL(kill) \
__ENUMERATE_SYSCALL(getuid) \
__ENUMERATE_SYSCALL(exit) \
__ENUMERATE_SYSCALL(getgid) \
__ENUMERATE_SYSCALL(getpid) \
__ENUMERATE_SYSCALL(waitid) \
__ENUMERATE_SYSCALL(mmap) \
__ENUMERATE_SYSCALL(munmap) \
__ENUMERATE_SYSCALL(get_dir_entries) \
__ENUMERATE_SYSCALL(getcwd) \
__ENUMERATE_SYSCALL(gettimeofday) \
__ENUMERATE_SYSCALL(gethostname) \
__ENUMERATE_SYSCALL(chdir) \
__ENUMERATE_SYSCALL(uname) \
__ENUMERATE_SYSCALL(set_mmap_name) \
__ENUMERATE_SYSCALL(readlink) \
__ENUMERATE_SYSCALL(write) \
__ENUMERATE_SYSCALL(ttyname_r) \
__ENUMERATE_SYSCALL(stat) \
__ENUMERATE_SYSCALL(getsid) \
__ENUMERATE_SYSCALL(setsid) \
__ENUMERATE_SYSCALL(getpgid) \
__ENUMERATE_SYSCALL(setpgid) \
__ENUMERATE_SYSCALL(getpgrp) \
__ENUMERATE_SYSCALL(fork) \
__ENUMERATE_SYSCALL(execve) \
__ENUMERATE_SYSCALL(geteuid) \
__ENUMERATE_SYSCALL(getegid) \
__ENUMERATE_SYSCALL(getdtablesize) \
__ENUMERATE_SYSCALL(dup) \
__ENUMERATE_SYSCALL(dup2) \
__ENUMERATE_SYSCALL(sigaction) \
__ENUMERATE_SYSCALL(getppid) \
__ENUMERATE_SYSCALL(umask) \
__ENUMERATE_SYSCALL(getgroups) \
__ENUMERATE_SYSCALL(setgroups) \
__ENUMERATE_SYSCALL(sigreturn) \
__ENUMERATE_SYSCALL(sigprocmask) \
__ENUMERATE_SYSCALL(sigpending) \
__ENUMERATE_SYSCALL(pipe) \
__ENUMERATE_SYSCALL(killpg) \
__ENUMERATE_SYSCALL(setuid) \
__ENUMERATE_SYSCALL(setgid) \
__ENUMERATE_SYSCALL(alarm) \
__ENUMERATE_SYSCALL(fstat) \
__ENUMERATE_SYSCALL(access) \
__ENUMERATE_SYSCALL(fcntl) \
__ENUMERATE_SYSCALL(ioctl) \
__ENUMERATE_SYSCALL(mkdir) \
__ENUMERATE_SYSCALL(times) \
__ENUMERATE_SYSCALL(utime) \
__ENUMERATE_SYSCALL(sync) \
__ENUMERATE_SYSCALL(ptsname_r) \
__ENUMERATE_SYSCALL(select) \
__ENUMERATE_SYSCALL(unlink) \
__ENUMERATE_SYSCALL(poll) \
__ENUMERATE_SYSCALL(rmdir) \
__ENUMERATE_SYSCALL(chmod) \
__ENUMERATE_SYSCALL(usleep) \
__ENUMERATE_SYSCALL(socket) \
__ENUMERATE_SYSCALL(bind) \
__ENUMERATE_SYSCALL(accept) \
__ENUMERATE_SYSCALL(listen) \
__ENUMERATE_SYSCALL(connect) \
__ENUMERATE_SYSCALL(shbuf_create) \
__ENUMERATE_SYSCALL(shbuf_allow_pid) \
__ENUMERATE_SYSCALL(shbuf_get) \
__ENUMERATE_SYSCALL(shbuf_release) \
__ENUMERATE_SYSCALL(link) \
__ENUMERATE_SYSCALL(chown) \
__ENUMERATE_SYSCALL(fchmod) \
__ENUMERATE_SYSCALL(symlink) \
__ENUMERATE_SYSCALL(shbuf_get_size) \
__ENUMERATE_SYSCALL(shbuf_seal) \
__ENUMERATE_SYSCALL(sendto) \
__ENUMERATE_SYSCALL(recvfrom) \
__ENUMERATE_SYSCALL(getsockopt) \
__ENUMERATE_SYSCALL(setsockopt) \
__ENUMERATE_SYSCALL(create_thread) \
__ENUMERATE_SYSCALL(gettid) \
__ENUMERATE_SYSCALL(donate) \
__ENUMERATE_SYSCALL(rename) \
__ENUMERATE_SYSCALL(ftruncate) \
__ENUMERATE_SYSCALL(systrace) \
__ENUMERATE_SYSCALL(exit_thread) \
__ENUMERATE_SYSCALL(mknod) \
__ENUMERATE_SYSCALL(writev) \
__ENUMERATE_SYSCALL(beep) \
__ENUMERATE_SYSCALL(getsockname) \
__ENUMERATE_SYSCALL(getpeername) \
__ENUMERATE_SYSCALL(sched_setparam) \
__ENUMERATE_SYSCALL(sched_getparam) \
__ENUMERATE_SYSCALL(fchown) \
__ENUMERATE_SYSCALL(halt) \
__ENUMERATE_SYSCALL(reboot) \
__ENUMERATE_SYSCALL(mount) \
__ENUMERATE_SYSCALL(umount) \
__ENUMERATE_SYSCALL(dump_backtrace) \
__ENUMERATE_SYSCALL(dbgputch) \
__ENUMERATE_SYSCALL(dbgputstr) \
__ENUMERATE_SYSCALL(watch_file) \
__ENUMERATE_SYSCALL(shbuf_allow_all) \
__ENUMERATE_SYSCALL(set_process_icon) \
__ENUMERATE_SYSCALL(mprotect) \
__ENUMERATE_SYSCALL(realpath) \
__ENUMERATE_SYSCALL(get_process_name) \
__ENUMERATE_SYSCALL(fchdir) \
__ENUMERATE_SYSCALL(getrandom) \
__ENUMERATE_SYSCALL(setkeymap) \
__ENUMERATE_SYSCALL(clock_gettime) \
__ENUMERATE_SYSCALL(clock_nanosleep) \
__ENUMERATE_SYSCALL(join_thread) \
__ENUMERATE_SYSCALL(module_load) \
__ENUMERATE_SYSCALL(module_unload) \
__ENUMERATE_SYSCALL(detach_thread) \
__ENUMERATE_SYSCALL(set_thread_name) \
__ENUMERATE_SYSCALL(get_thread_name) \
__ENUMERATE_SYSCALL(madvise) \
__ENUMERATE_SYSCALL(purge) \
__ENUMERATE_SYSCALL(shbuf_set_volatile) \
__ENUMERATE_SYSCALL(profiling_enable) \
__ENUMERATE_SYSCALL(profiling_disable) \
__ENUMERATE_SYSCALL(get_kernel_info_page) \
__ENUMERATE_SYSCALL(futex) \
__ENUMERATE_SYSCALL(set_thread_boost) \
__ENUMERATE_SYSCALL(set_process_boost) \
__ENUMERATE_SYSCALL(chroot) \
__ENUMERATE_SYSCALL(pledge) \
__ENUMERATE_SYSCALL(unveil) \
__ENUMERATE_SYSCALL(perf_event) \
__ENUMERATE_SYSCALL(shutdown)
namespace Syscall {
enum Function {
enum Function {
#undef __ENUMERATE_SYSCALL
#undef __ENUMERATE_REMOVED_SYSCALL
#define __ENUMERATE_REMOVED_SYSCALL(x) SC_##x,
#define __ENUMERATE_SYSCALL(x) SC_##x,
ENUMERATE_SYSCALLS
ENUMERATE_SYSCALLS
#undef __ENUMERATE_SYSCALL
#undef __ENUMERATE_REMOVED_SYSCALL
__Count
};
__Count
};
inline constexpr const char* to_string(Function function)
{
switch (function) {
inline constexpr const char* to_string(Function function)
{
switch (function) {
#undef __ENUMERATE_SYSCALL
#undef __ENUMERATE_REMOVED_SYSCALL
#define __ENUMERATE_REMOVED_SYSCALL(x) \
@ -205,267 +205,267 @@ inline constexpr const char* to_string(Function function)
#define __ENUMERATE_SYSCALL(x) \
case SC_##x: \
return #x;
ENUMERATE_SYSCALLS
ENUMERATE_SYSCALLS
#undef __ENUMERATE_SYSCALL
#undef __ENUMERATE_REMOVED_SYSCALL
default:
break;
default:
break;
}
return "Unknown";
}
return "Unknown";
}
#ifdef __serenity__
struct StringArgument {
const char* characters { nullptr };
size_t length { 0 };
};
struct StringArgument {
const char* characters { nullptr };
size_t length { 0 };
};
template<typename DataType, typename SizeType>
struct MutableBufferArgument {
DataType* data { nullptr };
SizeType size { 0 };
};
template<typename DataType, typename SizeType>
struct MutableBufferArgument {
DataType* data { nullptr };
SizeType size { 0 };
};
template<typename DataType, typename SizeType>
struct ImmutableBufferArgument {
const DataType* data { nullptr };
SizeType size { 0 };
};
template<typename DataType, typename SizeType>
struct ImmutableBufferArgument {
const DataType* data { nullptr };
SizeType size { 0 };
};
struct StringListArgument {
StringArgument* strings { nullptr };
size_t length { 0 };
};
struct StringListArgument {
StringArgument* strings { nullptr };
size_t length { 0 };
};
struct SC_mmap_params {
uint32_t addr;
uint32_t size;
uint32_t alignment;
int32_t prot;
int32_t flags;
int32_t fd;
int32_t offset; // FIXME: 64-bit off_t?
StringArgument name;
};
struct SC_mmap_params {
uint32_t addr;
uint32_t size;
uint32_t alignment;
int32_t prot;
int32_t flags;
int32_t fd;
int32_t offset; // FIXME: 64-bit off_t?
StringArgument name;
};
struct SC_open_params {
int dirfd;
StringArgument path;
int options;
u16 mode;
};
struct SC_open_params {
int dirfd;
StringArgument path;
int options;
u16 mode;
};
struct SC_select_params {
int nfds;
fd_set* readfds;
fd_set* writefds;
fd_set* exceptfds;
struct timeval* timeout;
};
struct SC_select_params {
int nfds;
fd_set* readfds;
fd_set* writefds;
fd_set* exceptfds;
struct timeval* timeout;
};
struct SC_clock_nanosleep_params {
int clock_id;
int flags;
const struct timespec* requested_sleep;
struct timespec* remaining_sleep;
};
struct SC_clock_nanosleep_params {
int clock_id;
int flags;
const struct timespec* requested_sleep;
struct timespec* remaining_sleep;
};
struct SC_sendto_params {
int sockfd;
ImmutableBufferArgument<void, size_t> data;
int flags;
const sockaddr* addr;
socklen_t addr_length;
};
struct SC_sendto_params {
int sockfd;
ImmutableBufferArgument<void, size_t> data;
int flags;
const sockaddr* addr;
socklen_t addr_length;
};
struct SC_recvfrom_params {
int sockfd;
MutableBufferArgument<void, size_t> buffer;
int flags;
sockaddr* addr;
socklen_t* addr_length;
};
struct SC_recvfrom_params {
int sockfd;
MutableBufferArgument<void, size_t> buffer;
int flags;
sockaddr* addr;
socklen_t* addr_length;
};
struct SC_getsockopt_params {
int sockfd;
int level;
int option;
void* value;
socklen_t* value_size;
};
struct SC_getsockopt_params {
int sockfd;
int level;
int option;
void* value;
socklen_t* value_size;
};
struct SC_setsockopt_params {
int sockfd;
int level;
int option;
const void* value;
socklen_t value_size;
};
struct SC_setsockopt_params {
int sockfd;
int level;
int option;
const void* value;
socklen_t value_size;
};
struct SC_getsockname_params {
int sockfd;
sockaddr* addr;
socklen_t* addrlen;
};
struct SC_getsockname_params {
int sockfd;
sockaddr* addr;
socklen_t* addrlen;
};
struct SC_getpeername_params {
int sockfd;
sockaddr* addr;
socklen_t* addrlen;
};
struct SC_getpeername_params {
int sockfd;
sockaddr* addr;
socklen_t* addrlen;
};
struct SC_futex_params {
i32* userspace_address;
int futex_op;
i32 val;
const timespec* timeout;
};
struct SC_futex_params {
i32* userspace_address;
int futex_op;
i32 val;
const timespec* timeout;
};
struct SC_setkeymap_params {
const char* map;
const char* shift_map;
const char* alt_map;
const char* altgr_map;
};
struct SC_setkeymap_params {
const char* map;
const char* shift_map;
const char* alt_map;
const char* altgr_map;
};
struct SC_create_thread_params {
unsigned int m_detach_state = 0; // JOINABLE or DETACHED
int m_schedule_priority = 30; // THREAD_PRIORITY_NORMAL
// FIXME: Implment guard pages in create_thread (unreadable pages at "overflow" end of stack)
// "If an implementation rounds up the value of guardsize to a multiple of {PAGESIZE},
// a call to pthread_attr_getguardsize() specifying attr shall store in the guardsize
// parameter the guard size specified by the previous pthread_attr_setguardsize() function call"
// ... ok, if you say so posix. Guess we get to lie to people about guard page size
unsigned int m_guard_page_size = 0; // Rounded up to PAGE_SIZE
unsigned int m_reported_guard_page_size = 0; // The lie we tell callers
unsigned int m_stack_size = 4 * MB; // Default PTHREAD_STACK_MIN
void* m_stack_location = nullptr; // nullptr means any, o.w. process virtual address
};
struct SC_create_thread_params {
unsigned int m_detach_state = 0; // JOINABLE or DETACHED
int m_schedule_priority = 30; // THREAD_PRIORITY_NORMAL
// FIXME: Implment guard pages in create_thread (unreadable pages at "overflow" end of stack)
// "If an implementation rounds up the value of guardsize to a multiple of {PAGESIZE},
// a call to pthread_attr_getguardsize() specifying attr shall store in the guardsize
// parameter the guard size specified by the previous pthread_attr_setguardsize() function call"
// ... ok, if you say so posix. Guess we get to lie to people about guard page size
unsigned int m_guard_page_size = 0; // Rounded up to PAGE_SIZE
unsigned int m_reported_guard_page_size = 0; // The lie we tell callers
unsigned int m_stack_size = 4 * MB; // Default PTHREAD_STACK_MIN
void* m_stack_location = nullptr; // nullptr means any, o.w. process virtual address
};
struct SC_realpath_params {
StringArgument path;
MutableBufferArgument<char, size_t> buffer;
};
struct SC_realpath_params {
StringArgument path;
MutableBufferArgument<char, size_t> buffer;
};
struct SC_set_mmap_name_params {
void* addr;
size_t size;
StringArgument name;
};
struct SC_set_mmap_name_params {
void* addr;
size_t size;
StringArgument name;
};
struct SC_execve_params {
StringArgument path;
StringListArgument arguments;
StringListArgument environment;
};
struct SC_execve_params {
StringArgument path;
StringListArgument arguments;
StringListArgument environment;
};
struct SC_readlink_params {
StringArgument path;
MutableBufferArgument<char, size_t> buffer;
};
struct SC_readlink_params {
StringArgument path;
MutableBufferArgument<char, size_t> buffer;
};
struct SC_link_params {
StringArgument old_path;
StringArgument new_path;
};
struct SC_link_params {
StringArgument old_path;
StringArgument new_path;
};
struct SC_chown_params {
StringArgument path;
u32 uid;
u32 gid;
};
struct SC_chown_params {
StringArgument path;
u32 uid;
u32 gid;
};
struct SC_mknod_params {
StringArgument path;
u16 mode;
u32 dev;
};
struct SC_mknod_params {
StringArgument path;
u16 mode;
u32 dev;
};
struct SC_symlink_params {
StringArgument target;
StringArgument linkpath;
};
struct SC_symlink_params {
StringArgument target;
StringArgument linkpath;
};
struct SC_rename_params {
StringArgument old_path;
StringArgument new_path;
};
struct SC_rename_params {
StringArgument old_path;
StringArgument new_path;
};
struct SC_mount_params {
StringArgument source;
StringArgument target;
StringArgument fs_type;
int flags;
};
struct SC_mount_params {
StringArgument source;
StringArgument target;
StringArgument fs_type;
int flags;
};
struct SC_pledge_params {
StringArgument promises;
StringArgument execpromises;
};
struct SC_pledge_params {
StringArgument promises;
StringArgument execpromises;
};
struct SC_unveil_params {
StringArgument path;
StringArgument permissions;
};
struct SC_unveil_params {
StringArgument path;
StringArgument permissions;
};
struct SC_waitid_params {
int idtype;
int id;
struct siginfo* infop;
int options;
};
struct SC_waitid_params {
int idtype;
int id;
struct siginfo* infop;
int options;
};
struct SC_stat_params {
StringArgument path;
struct stat* statbuf;
bool follow_symlinks;
};
struct SC_stat_params {
StringArgument path;
struct stat* statbuf;
bool follow_symlinks;
};
void initialize();
int sync();
void initialize();
int sync();
inline u32 invoke(Function function)
{
u32 result;
asm volatile("int $0x82"
: "=a"(result)
: "a"(function)
: "memory");
return result;
}
inline u32 invoke(Function function)
{
u32 result;
asm volatile("int $0x82"
: "=a"(result)
: "a"(function)
: "memory");
return result;
}
template<typename T1>
inline u32 invoke(Function function, T1 arg1)
{
u32 result;
asm volatile("int $0x82"
: "=a"(result)
: "a"(function), "d"((u32)arg1)
: "memory");
return result;
}
template<typename T1>
inline u32 invoke(Function function, T1 arg1)
{
u32 result;
asm volatile("int $0x82"
: "=a"(result)
: "a"(function), "d"((u32)arg1)
: "memory");
return result;
}
template<typename T1, typename T2>
inline u32 invoke(Function function, T1 arg1, T2 arg2)
{
u32 result;
asm volatile("int $0x82"
: "=a"(result)
: "a"(function), "d"((u32)arg1), "c"((u32)arg2)
: "memory");
return result;
}
template<typename T1, typename T2>
inline u32 invoke(Function function, T1 arg1, T2 arg2)
{
u32 result;
asm volatile("int $0x82"
: "=a"(result)
: "a"(function), "d"((u32)arg1), "c"((u32)arg2)
: "memory");
return result;
}
template<typename T1, typename T2, typename T3>
inline u32 invoke(Function function, T1 arg1, T2 arg2, T3 arg3)
{
u32 result;
asm volatile("int $0x82"
: "=a"(result)
: "a"(function), "d"((u32)arg1), "c"((u32)arg2), "b"((u32)arg3)
: "memory");
return result;
}
template<typename T1, typename T2, typename T3>
inline u32 invoke(Function function, T1 arg1, T2 arg2, T3 arg3)
{
u32 result;
asm volatile("int $0x82"
: "=a"(result)
: "a"(function), "d"((u32)arg1), "c"((u32)arg2), "b"((u32)arg3)
: "memory");
return result;
}
#endif
}

View file

@ -121,7 +121,7 @@ public:
int sample_count() const { return m_sample_count; }
const void* data() const { return m_buffer->data(); }
int size_in_bytes() const { return m_sample_count * (int)sizeof(Sample); }
int shared_buffer_id() const { return m_buffer->shared_buffer_id(); }
int shbuf_id() const { return m_buffer->shbuf_id(); }
SharedBuffer& shared_buffer() { return *m_buffer; }
private:

View file

@ -45,7 +45,7 @@ void ClientConnection::enqueue(const Buffer& buffer)
{
for (;;) {
const_cast<Buffer&>(buffer).shared_buffer().share_with(server_pid());
auto response = send_sync<Messages::AudioServer::EnqueueBuffer>(buffer.shared_buffer_id(), buffer.sample_count());
auto response = send_sync<Messages::AudioServer::EnqueueBuffer>(buffer.shbuf_id(), buffer.sample_count());
if (response->success())
break;
sleep(1);
@ -55,7 +55,7 @@ void ClientConnection::enqueue(const Buffer& buffer)
bool ClientConnection::try_enqueue(const Buffer& buffer)
{
const_cast<Buffer&>(buffer).shared_buffer().share_with(server_pid());
auto response = send_sync<Messages::AudioServer::EnqueueBuffer>(buffer.shared_buffer_id(), buffer.sample_count());
auto response = send_sync<Messages::AudioServer::EnqueueBuffer>(buffer.shbuf_id(), buffer.sample_count());
return response->success();
}

View file

@ -529,21 +529,21 @@ void sync()
syscall(SC_sync);
}
int create_shared_buffer(int size, void** buffer)
int shbuf_create(int size, void** buffer)
{
int rc = syscall(SC_create_shared_buffer, size, buffer);
int rc = syscall(SC_shbuf_create, size, buffer);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int share_buffer_with(int shared_buffer_id, pid_t peer_pid)
int shbuf_allow_pid(int shbuf_id, pid_t peer_pid)
{
int rc = syscall(SC_share_buffer_with, shared_buffer_id, peer_pid);
int rc = syscall(SC_shbuf_allow_pid, shbuf_id, peer_pid);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int share_buffer_globally(int shared_buffer_id)
int shbuf_allow_all(int shbuf_id)
{
int rc = syscall(SC_share_buffer_globally, shared_buffer_id);
int rc = syscall(SC_shbuf_allow_all, shbuf_id);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
@ -553,9 +553,9 @@ int set_process_icon(int icon_id)
__RETURN_WITH_ERRNO(rc, rc, -1);
}
void* get_shared_buffer(int shared_buffer_id)
void* shbuf_get(int shbuf_id)
{
int rc = syscall(SC_get_shared_buffer, shared_buffer_id);
int rc = syscall(SC_shbuf_get, shbuf_id);
if (rc < 0 && -rc < EMAXERRNO) {
errno = -rc;
return (void*)-1;
@ -563,21 +563,21 @@ void* get_shared_buffer(int shared_buffer_id)
return (void*)rc;
}
int release_shared_buffer(int shared_buffer_id)
int shbuf_release(int shbuf_id)
{
int rc = syscall(SC_release_shared_buffer, shared_buffer_id);
int rc = syscall(SC_shbuf_release, shbuf_id);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int get_shared_buffer_size(int shared_buffer_id)
int shbuf_get_size(int shbuf_id)
{
int rc = syscall(SC_get_shared_buffer_size, shared_buffer_id);
int rc = syscall(SC_shbuf_get_size, shbuf_id);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int seal_shared_buffer(int shared_buffer_id)
int shbuf_seal(int shbuf_id)
{
int rc = syscall(SC_seal_shared_buffer, shared_buffer_id);
int rc = syscall(SC_shbuf_seal, shbuf_id);
__RETURN_WITH_ERRNO(rc, rc, -1);
}

View file

@ -61,13 +61,13 @@ void sysbeep();
int systrace(pid_t);
int gettid();
int donate(int tid);
int create_shared_buffer(int, void** buffer);
int share_buffer_with(int, pid_t peer_pid);
int share_buffer_globally(int);
void* get_shared_buffer(int shared_buffer_id);
int release_shared_buffer(int shared_buffer_id);
int seal_shared_buffer(int shared_buffer_id);
int get_shared_buffer_size(int shared_buffer_id);
int shbuf_create(int, void** buffer);
int shbuf_allow_pid(int, pid_t peer_pid);
int shbuf_allow_all(int);
void* shbuf_get(int shbuf_id);
int shbuf_release(int shbuf_id);
int shbuf_seal(int shbuf_id);
int shbuf_get_size(int shbuf_id);
int set_process_icon(int icon_id);
inline int getpagesize() { return 4096; }
pid_t fork();

View file

@ -46,9 +46,9 @@ Clipboard::Clipboard()
Clipboard::DataAndType Clipboard::data_and_type() const
{
auto response = WindowServerConnection::the().send_sync<Messages::WindowServer::GetClipboardContents>();
if (response->shared_buffer_id() < 0)
if (response->shbuf_id() < 0)
return {};
auto shared_buffer = SharedBuffer::create_from_shared_buffer_id(response->shared_buffer_id());
auto shared_buffer = SharedBuffer::create_from_shbuf_id(response->shbuf_id());
if (!shared_buffer) {
dbgprintf("GUI::Clipboard::data() failed to attach to the shared buffer\n");
return {};
@ -76,7 +76,7 @@ void Clipboard::set_data(const StringView& data, const String& type)
shared_buffer->seal();
shared_buffer->share_with(WindowServerConnection::the().server_pid());
WindowServerConnection::the().send_sync<Messages::WindowServer::SetClipboardContents>(shared_buffer->shared_buffer_id(), data.length(), type);
WindowServerConnection::the().send_sync<Messages::WindowServer::SetClipboardContents>(shared_buffer->shbuf_id(), data.length(), type);
}
void Clipboard::did_receive_clipboard_contents_changed(Badge<WindowServerConnection>, const String& data_type)

View file

@ -55,7 +55,7 @@ DragOperation::Outcome DragOperation::exec()
if (m_bitmap) {
shared_bitmap = m_bitmap->to_shareable_bitmap();
shared_bitmap->shared_buffer()->share_with(WindowServerConnection::the().server_pid());
bitmap_id = shared_bitmap->shared_buffer_id();
bitmap_id = shared_bitmap->shbuf_id();
bitmap_size = shared_bitmap->size();
}

View file

@ -128,7 +128,7 @@ int Menu::realize_menu()
if (action.icon()) {
ASSERT(action.icon()->format() == Gfx::BitmapFormat::RGBA32);
ASSERT(action.icon()->size() == Gfx::Size(16, 16));
if (action.icon()->shared_buffer_id() == -1) {
if (action.icon()->shbuf_id() == -1) {
auto shared_buffer = SharedBuffer::create_with_size(action.icon()->size_in_bytes());
ASSERT(shared_buffer);
auto shared_icon = Gfx::Bitmap::create_with_shared_buffer(Gfx::BitmapFormat::RGBA32, *shared_buffer, action.icon()->size());
@ -137,7 +137,7 @@ int Menu::realize_menu()
shared_buffer->share_with(WindowServerConnection::the().server_pid());
action.set_icon(shared_icon);
}
icon_buffer_id = action.icon()->shared_buffer_id();
icon_buffer_id = action.icon()->shbuf_id();
}
auto shortcut_text = action.shortcut().is_valid() ? action.shortcut().to_string() : String();
bool exclusive = action.group() && action.group()->is_exclusive() && action.is_checkable();

View file

@ -477,7 +477,7 @@ void Window::set_hovered_widget(Widget* widget)
void Window::set_current_backing_bitmap(Gfx::Bitmap& bitmap, bool flush_immediately)
{
WindowServerConnection::the().send_sync<Messages::WindowServer::SetWindowBackingStore>(m_window_id, 32, bitmap.pitch(), bitmap.shared_buffer_id(), bitmap.has_alpha_channel(), bitmap.size(), flush_immediately);
WindowServerConnection::the().send_sync<Messages::WindowServer::SetWindowBackingStore>(m_window_id, 32, bitmap.pitch(), bitmap.shbuf_id(), bitmap.has_alpha_channel(), bitmap.size(), flush_immediately);
}
void Window::flip(const Vector<Gfx::Rect, 32>& dirty_rects)
@ -551,17 +551,17 @@ void Window::apply_icon()
if (!m_window_id)
return;
int rc = seal_shared_buffer(m_icon->shared_buffer_id());
int rc = shbuf_seal(m_icon->shbuf_id());
ASSERT(rc == 0);
rc = share_buffer_globally(m_icon->shared_buffer_id());
rc = shbuf_allow_all(m_icon->shbuf_id());
ASSERT(rc == 0);
static bool has_set_process_icon;
if (!has_set_process_icon)
set_process_icon(m_icon->shared_buffer_id());
set_process_icon(m_icon->shbuf_id());
WindowServerConnection::the().send_sync<Messages::WindowServer::SetWindowIconBitmap>(m_window_id, m_icon->shared_buffer_id(), m_icon->size());
WindowServerConnection::the().send_sync<Messages::WindowServer::SetWindowIconBitmap>(m_window_id, m_icon->shbuf_id(), m_icon->size());
}
void Window::start_wm_resize()

View file

@ -53,9 +53,9 @@ WindowServerConnection& WindowServerConnection::the()
return *s_connection;
}
static void set_system_theme_from_shared_buffer_id(int id)
static void set_system_theme_from_shbuf_id(int id)
{
auto system_theme = SharedBuffer::create_from_shared_buffer_id(id);
auto system_theme = SharedBuffer::create_from_shbuf_id(id);
ASSERT(system_theme);
Gfx::set_system_theme(*system_theme);
Application::the().set_system_palette(*system_theme);
@ -65,13 +65,13 @@ void WindowServerConnection::handshake()
{
auto response = send_sync<Messages::WindowServer::Greet>();
set_my_client_id(response->client_id());
set_system_theme_from_shared_buffer_id(response->system_theme_buffer_id());
set_system_theme_from_shbuf_id(response->system_theme_buffer_id());
Desktop::the().did_receive_screen_rect({}, response->screen_rect());
}
void WindowServerConnection::handle(const Messages::WindowClient::UpdateSystemTheme& message)
{
set_system_theme_from_shared_buffer_id(message.system_theme_buffer_id());
set_system_theme_from_shbuf_id(message.system_theme_buffer_id());
Window::update_all_windows({});
}

View file

@ -158,9 +158,9 @@ void Bitmap::set_volatile()
return rc == 0;
}
int Bitmap::shared_buffer_id() const
int Bitmap::shbuf_id() const
{
return m_shared_buffer ? m_shared_buffer->shared_buffer_id() : -1;
return m_shared_buffer ? m_shared_buffer->shbuf_id() : -1;
}
}

View file

@ -64,7 +64,7 @@ public:
int width() const { return m_size.width(); }
int height() const { return m_size.height(); }
size_t pitch() const { return m_pitch; }
int shared_buffer_id() const;
int shbuf_id() const;
SharedBuffer* shared_buffer() { return m_shared_buffer.ptr(); }
const SharedBuffer* shared_buffer() const { return m_shared_buffer.ptr(); }

View file

@ -43,7 +43,7 @@ const SystemTheme& current_system_theme()
int current_system_theme_buffer_id()
{
ASSERT(theme_buffer);
return theme_buffer->shared_buffer_id();
return theme_buffer->shbuf_id();
}
void set_system_theme(SharedBuffer& buffer)

View file

@ -66,9 +66,9 @@ void Client::handle(const Messages::ProtocolClient::DownloadFinished& message)
{
RefPtr<Download> download;
if ((download = m_downloads.get(message.download_id()).value_or(nullptr))) {
download->did_finish({}, message.success(), message.total_size(), message.shared_buffer_id());
download->did_finish({}, message.success(), message.total_size(), message.shbuf_id());
}
send_sync<Messages::ProtocolServer::DisownSharedBuffer>(message.shared_buffer_id());
send_sync<Messages::ProtocolServer::DisownSharedBuffer>(message.shbuf_id());
m_downloads.remove(message.download_id());
}

View file

@ -41,15 +41,15 @@ bool Download::stop()
return m_client->stop_download({}, *this);
}
void Download::did_finish(Badge<Client>, bool success, u32 total_size, i32 shared_buffer_id)
void Download::did_finish(Badge<Client>, bool success, u32 total_size, i32 shbuf_id)
{
if (!on_finish)
return;
ByteBuffer payload;
RefPtr<SharedBuffer> shared_buffer;
if (success && shared_buffer_id != -1) {
shared_buffer = SharedBuffer::create_from_shared_buffer_id(shared_buffer_id);
if (success && shbuf_id != -1) {
shared_buffer = SharedBuffer::create_from_shbuf_id(shbuf_id);
payload = ByteBuffer::wrap(shared_buffer->data(), total_size);
}
on_finish(success, payload, move(shared_buffer));

View file

@ -49,7 +49,7 @@ public:
Function<void(bool success, const ByteBuffer& payload, RefPtr<SharedBuffer> payload_storage)> on_finish;
Function<void(u32 total_size, u32 downloaded_size)> on_progress;
void did_finish(Badge<Client>, bool success, u32 total_size, i32 shared_buffer_id);
void did_finish(Badge<Client>, bool success, u32 total_size, i32 shbuf_id);
void did_progress(Badge<Client>, u32 total_size, u32 downloaded_size);
private:

View file

@ -92,7 +92,7 @@ OwnPtr<Messages::AudioServer::SetMainMixVolumeResponse> ASClientConnection::hand
OwnPtr<Messages::AudioServer::EnqueueBufferResponse> ASClientConnection::handle(const Messages::AudioServer::EnqueueBuffer& message)
{
auto shared_buffer = SharedBuffer::create_from_shared_buffer_id(message.buffer_id());
auto shared_buffer = SharedBuffer::create_from_shbuf_id(message.buffer_id());
if (!shared_buffer) {
// FIXME: The shared buffer should have been retrieved for us already.
// We don't want to do IPC error checking at this layer.

View file

@ -64,7 +64,7 @@ public:
++m_played_samples;
if (m_position >= m_current->sample_count()) {
m_client->did_finish_playing_buffer({}, m_current->shared_buffer_id());
m_client->did_finish_playing_buffer({}, m_current->shbuf_id());
m_current = nullptr;
m_position = 0;
}
@ -93,7 +93,7 @@ public:
int get_playing_buffer() const
{
if (m_current)
return m_current->shared_buffer_id();
return m_current->shbuf_id();
return -1;
}

View file

@ -82,9 +82,9 @@ void PSClientConnection::did_finish_download(Badge<Download>, Download& download
memcpy(buffer->data(), download.payload().data(), download.payload().size());
buffer->seal();
buffer->share_with(client_pid());
m_shared_buffers.set(buffer->shared_buffer_id(), buffer);
m_shared_buffers.set(buffer->shbuf_id(), buffer);
}
post_message(Messages::ProtocolClient::DownloadFinished(download.id(), success, download.total_size(), buffer ? buffer->shared_buffer_id() : -1));
post_message(Messages::ProtocolClient::DownloadFinished(download.id(), success, download.total_size(), buffer ? buffer->shbuf_id() : -1));
}
void PSClientConnection::did_progress_download(Badge<Download>, Download& download)
@ -99,6 +99,6 @@ OwnPtr<Messages::ProtocolServer::GreetResponse> PSClientConnection::handle(const
OwnPtr<Messages::ProtocolServer::DisownSharedBufferResponse> PSClientConnection::handle(const Messages::ProtocolServer::DisownSharedBuffer& message)
{
m_shared_buffers.remove(message.shared_buffer_id());
m_shared_buffers.remove(message.shbuf_id());
return make<Messages::ProtocolServer::DisownSharedBufferResponse>();
}

View file

@ -2,5 +2,5 @@ endpoint ProtocolClient = 13
{
// Download notifications
DownloadProgress(i32 download_id, u32 total_size, u32 downloaded_size) =|
DownloadFinished(i32 download_id, bool success, u32 total_size, i32 shared_buffer_id) =|
DownloadFinished(i32 download_id, bool success, u32 total_size, i32 shbuf_id) =|
}

View file

@ -4,7 +4,7 @@ endpoint ProtocolServer = 9
Greet() => (i32 client_id)
// FIXME: It would be nice if the kernel provided a way to avoid this
DisownSharedBuffer(i32 shared_buffer_id) => ()
DisownSharedBuffer(i32 shbuf_id) => ()
// Test if a specific protocol is supported, e.g "http"
IsSupportedProtocol(String protocol) => (bool supported)

View file

@ -193,7 +193,7 @@ OwnPtr<Messages::WindowServer::AddMenuItemResponse> ClientConnection::handle(con
auto& menu = *(*it).value;
auto menu_item = make<MenuItem>(menu, identifier, message.text(), message.shortcut(), message.enabled(), message.checkable(), message.checked());
if (message.icon_buffer_id() != -1) {
auto icon_buffer = SharedBuffer::create_from_shared_buffer_id(message.icon_buffer_id());
auto icon_buffer = SharedBuffer::create_from_shbuf_id(message.icon_buffer_id());
if (!icon_buffer)
return nullptr;
// FIXME: Verify that the icon buffer can accomodate a 16x16 bitmap view.
@ -349,7 +349,7 @@ OwnPtr<Messages::WindowServer::SetWindowIconBitmapResponse> ClientConnection::ha
}
auto& window = *(*it).value;
auto icon_buffer = SharedBuffer::create_from_shared_buffer_id(message.icon_buffer_id());
auto icon_buffer = SharedBuffer::create_from_shbuf_id(message.icon_buffer_id());
if (!icon_buffer) {
window.set_default_icon();
@ -393,7 +393,7 @@ OwnPtr<Messages::WindowServer::GetWindowRectResponse> ClientConnection::handle(c
OwnPtr<Messages::WindowServer::SetClipboardContentsResponse> ClientConnection::handle(const Messages::WindowServer::SetClipboardContents& message)
{
auto shared_buffer = SharedBuffer::create_from_shared_buffer_id(message.shared_buffer_id());
auto shared_buffer = SharedBuffer::create_from_shbuf_id(message.shbuf_id());
if (!shared_buffer) {
did_misbehave("SetClipboardContents: Bad shared buffer ID");
return nullptr;
@ -406,7 +406,7 @@ OwnPtr<Messages::WindowServer::GetClipboardContentsResponse> ClientConnection::h
{
auto& clipboard = Clipboard::the();
i32 shared_buffer_id = -1;
i32 shbuf_id = -1;
if (clipboard.size()) {
// FIXME: Optimize case where an app is copy/pasting within itself.
// We can just reuse the SharedBuffer then, since it will have the same peer PID.
@ -416,13 +416,13 @@ OwnPtr<Messages::WindowServer::GetClipboardContentsResponse> ClientConnection::h
memcpy(shared_buffer->data(), clipboard.data(), clipboard.size());
shared_buffer->seal();
shared_buffer->share_with(client_pid());
shared_buffer_id = shared_buffer->shared_buffer_id();
shbuf_id = shared_buffer->shbuf_id();
// FIXME: This is a workaround for the fact that SharedBuffers will go away if neither side is retaining them.
// After we respond to GetClipboardContents, we have to wait for the client to ref the buffer on his side.
m_last_sent_clipboard_content = move(shared_buffer);
}
return make<Messages::WindowServer::GetClipboardContentsResponse>(shared_buffer_id, clipboard.size(), clipboard.data_type());
return make<Messages::WindowServer::GetClipboardContentsResponse>(shbuf_id, clipboard.size(), clipboard.data_type());
}
OwnPtr<Messages::WindowServer::CreateWindowResponse> ClientConnection::handle(const Messages::WindowServer::CreateWindow& message)
@ -509,10 +509,10 @@ OwnPtr<Messages::WindowServer::SetWindowBackingStoreResponse> ClientConnection::
return nullptr;
}
auto& window = *(*it).value;
if (window.last_backing_store() && window.last_backing_store()->shared_buffer_id() == message.shared_buffer_id()) {
if (window.last_backing_store() && window.last_backing_store()->shbuf_id() == message.shbuf_id()) {
window.swap_backing_stores();
} else {
auto shared_buffer = SharedBuffer::create_from_shared_buffer_id(message.shared_buffer_id());
auto shared_buffer = SharedBuffer::create_from_shbuf_id(message.shbuf_id());
if (!shared_buffer)
return make<Messages::WindowServer::SetWindowBackingStoreResponse>();
auto backing_store = Gfx::Bitmap::create_with_shared_buffer(
@ -669,7 +669,7 @@ OwnPtr<Messages::WindowServer::StartDragResponse> ClientConnection::handle(const
RefPtr<Gfx::Bitmap> bitmap;
if (message.bitmap_id() != -1) {
auto shared_buffer = SharedBuffer::create_from_shared_buffer_id(message.bitmap_id());
auto shared_buffer = SharedBuffer::create_from_shbuf_id(message.bitmap_id());
ssize_t size_in_bytes = message.bitmap_size().area() * sizeof(Gfx::RGBA32);
if (size_in_bytes > shared_buffer->size()) {
did_misbehave("SetAppletBackingStore: Shared buffer is too small for applet size");

View file

@ -252,13 +252,13 @@ void WindowManager::tell_wm_listener_about_window_icon(Window& listener, Window&
return;
if (window.is_internal())
return;
if (window.icon().shared_buffer_id() == -1)
if (window.icon().shbuf_id() == -1)
return;
dbg() << "WindowServer: Sharing icon buffer " << window.icon().shared_buffer_id() << " with PID " << listener.client()->client_pid();
if (share_buffer_with(window.icon().shared_buffer_id(), listener.client()->client_pid()) < 0) {
dbg() << "WindowServer: Sharing icon buffer " << window.icon().shbuf_id() << " with PID " << listener.client()->client_pid();
if (shbuf_allow_pid(window.icon().shbuf_id(), listener.client()->client_pid()) < 0) {
ASSERT_NOT_REACHED();
}
listener.client()->post_message(Messages::WindowClient::WM_WindowIconBitmapChanged(listener.window_id(), window.client_id(), window.window_id(), window.icon().shared_buffer_id(), window.icon().size()));
listener.client()->post_message(Messages::WindowClient::WM_WindowIconBitmapChanged(listener.window_id(), window.client_id(), window.window_id(), window.icon().shbuf_id(), window.icon().size()));
}
void WindowManager::tell_wm_listeners_window_state_changed(Window& window)

View file

@ -57,9 +57,9 @@ endpoint WindowServer = 2
SetGlobalCursorTracking(i32 window_id, bool enabled) => ()
SetWindowOpacity(i32 window_id, float opacity) => ()
SetWindowBackingStore(i32 window_id, i32 bpp, i32 pitch, i32 shared_buffer_id, bool has_alpha_channel, Gfx::Size size, bool flush_immediately) => ()
GetClipboardContents() => (i32 shared_buffer_id, i32 content_size, String content_type)
SetClipboardContents(i32 shared_buffer_id, i32 content_size, String content_type) => ()
SetWindowBackingStore(i32 window_id, i32 bpp, i32 pitch, i32 shbuf_id, bool has_alpha_channel, Gfx::Size size, bool flush_immediately) => ()
GetClipboardContents() => (i32 shbuf_id, i32 content_size, String content_type)
SetClipboardContents(i32 shbuf_id, i32 content_size, String content_type) => ()
WM_SetActiveWindow(i32 client_id, i32 window_id) =|
WM_SetWindowMinimized(i32 client_id, i32 window_id, bool minimized) =|