Skip to content

Commit bad6d50

Browse files
bgianfoawesomekling
authored andcommitted
Kernel: Use Process::require_promise() instead of REQUIRE_PROMISE()
This change lays the foundation for making the require_promise return an error hand handling the process abort outside of the syscall implementations, to avoid cases where we would leak resources. It also has the advantage that it makes removes a gs pointer read to look up the current thread, then process for every syscall. We can instead go through the Process this pointer in most cases.
1 parent c4f6084 commit bad6d50

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+133
-132
lines changed

Kernel/Graphics/FramebufferDevice.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ NonnullRefPtr<FramebufferDevice> FramebufferDevice::create(const GenericGraphics
2929

3030
ErrorOr<Memory::Region*> FramebufferDevice::mmap(Process& process, OpenFileDescription&, Memory::VirtualRange const& range, u64 offset, int prot, bool shared)
3131
{
32+
process.require_promise(Pledge::video);
3233
SpinlockLocker lock(m_activation_lock);
33-
REQUIRE_PROMISE(video);
3434
if (!shared)
3535
return ENODEV;
3636
if (offset != 0)

Kernel/Graphics/GenericFramebufferDevice.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ ErrorOr<void> GenericFramebufferDevice::verify_head_index(int head_index) const
3333

3434
ErrorOr<void> GenericFramebufferDevice::ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg)
3535
{
36-
REQUIRE_PROMISE(video);
36+
Process::current().require_promise(Pledge::video);
3737
switch (request) {
3838
case FB_IOCTL_GET_PROPERTIES: {
3939
auto user_properties = static_ptr_cast<FBProperties*>(arg);

Kernel/Graphics/VirtIOGPU/FramebufferDevice.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ void FramebufferDevice::set_buffer(int buffer_index)
257257

258258
ErrorOr<Memory::Region*> FramebufferDevice::mmap(Process& process, OpenFileDescription&, Memory::VirtualRange const& range, u64 offset, int prot, bool shared)
259259
{
260-
REQUIRE_PROMISE(video);
260+
process.require_promise(Pledge::video);
261261
if (!shared)
262262
return ENODEV;
263263
if (offset != 0 || !m_framebuffer)

Kernel/Net/IPv4Socket.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ ErrorOr<void> IPv4Socket::getsockopt(OpenFileDescription& description, int level
607607

608608
ErrorOr<void> IPv4Socket::ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg)
609609
{
610-
REQUIRE_PROMISE(inet);
610+
Process::current().require_promise(Pledge::inet);
611611

612612
auto ioctl_route = [request, arg]() -> ErrorOr<void> {
613613
auto user_route = static_ptr_cast<rtentry*>(arg);

Kernel/Syscalls/access.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Kernel {
1313
ErrorOr<FlatPtr> Process::sys$access(Userspace<const char*> user_path, size_t path_length, int mode)
1414
{
1515
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
16-
REQUIRE_PROMISE(rpath);
16+
require_promise(Pledge::rpath);
1717
auto path = TRY(get_syscall_path_argument(user_path, path_length));
1818
TRY(VirtualFileSystem::the().access(path->view(), mode, current_directory()));
1919
return 0;

Kernel/Syscalls/alarm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Kernel {
1212
ErrorOr<FlatPtr> Process::sys$alarm(unsigned seconds)
1313
{
1414
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
15-
REQUIRE_PROMISE(stdio);
15+
require_promise(Pledge::stdio);
1616
unsigned previous_alarm_remaining = 0;
1717
if (m_alarm_timer) {
1818
bool was_in_use = false;

Kernel/Syscalls/anon_create.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Kernel {
1414
ErrorOr<FlatPtr> Process::sys$anon_create(size_t size, int options)
1515
{
1616
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
17-
REQUIRE_PROMISE(stdio);
17+
require_promise(Pledge::stdio);
1818

1919
if (!size)
2020
return EINVAL;

Kernel/Syscalls/chdir.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Kernel {
1313
ErrorOr<FlatPtr> Process::sys$chdir(Userspace<const char*> user_path, size_t path_length)
1414
{
1515
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
16-
REQUIRE_PROMISE(rpath);
16+
require_promise(Pledge::rpath);
1717
auto path = TRY(get_syscall_path_argument(user_path, path_length));
1818
m_cwd = TRY(VirtualFileSystem::the().open_directory(path->view(), current_directory()));
1919
return 0;
@@ -22,7 +22,7 @@ ErrorOr<FlatPtr> Process::sys$chdir(Userspace<const char*> user_path, size_t pat
2222
ErrorOr<FlatPtr> Process::sys$fchdir(int fd)
2323
{
2424
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
25-
REQUIRE_PROMISE(stdio);
25+
require_promise(Pledge::stdio);
2626
auto description = TRY(fds().open_file_description(fd));
2727
if (!description->is_directory())
2828
return ENOTDIR;
@@ -35,7 +35,7 @@ ErrorOr<FlatPtr> Process::sys$fchdir(int fd)
3535
ErrorOr<FlatPtr> Process::sys$getcwd(Userspace<char*> buffer, size_t size)
3636
{
3737
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
38-
REQUIRE_PROMISE(rpath);
38+
require_promise(Pledge::rpath);
3939

4040
if (size > NumericLimits<ssize_t>::max())
4141
return EINVAL;

Kernel/Syscalls/chmod.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Kernel {
1313
ErrorOr<FlatPtr> Process::sys$chmod(Userspace<const char*> user_path, size_t path_length, mode_t mode)
1414
{
1515
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
16-
REQUIRE_PROMISE(fattr);
16+
require_promise(Pledge::fattr);
1717
auto path = TRY(get_syscall_path_argument(user_path, path_length));
1818
TRY(VirtualFileSystem::the().chmod(path->view(), mode, current_directory()));
1919
return 0;
@@ -22,7 +22,7 @@ ErrorOr<FlatPtr> Process::sys$chmod(Userspace<const char*> user_path, size_t pat
2222
ErrorOr<FlatPtr> Process::sys$fchmod(int fd, mode_t mode)
2323
{
2424
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
25-
REQUIRE_PROMISE(fattr);
25+
require_promise(Pledge::fattr);
2626
auto description = TRY(fds().open_file_description(fd));
2727
TRY(description->chmod(mode));
2828
return 0;

Kernel/Syscalls/chown.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Kernel {
1212
ErrorOr<FlatPtr> Process::sys$fchown(int fd, UserID uid, GroupID gid)
1313
{
1414
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
15-
REQUIRE_PROMISE(chown);
15+
require_promise(Pledge::chown);
1616
auto description = TRY(fds().open_file_description(fd));
1717
TRY(description->chown(uid, gid));
1818
return 0;
@@ -21,7 +21,7 @@ ErrorOr<FlatPtr> Process::sys$fchown(int fd, UserID uid, GroupID gid)
2121
ErrorOr<FlatPtr> Process::sys$chown(Userspace<const Syscall::SC_chown_params*> user_params)
2222
{
2323
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
24-
REQUIRE_PROMISE(chown);
24+
require_promise(Pledge::chown);
2525
auto params = TRY(copy_typed_from_user(user_params));
2626
auto path = TRY(get_syscall_path_argument(params.path));
2727
TRY(VirtualFileSystem::the().chown(path->view(), params.uid, params.gid, current_directory()));

0 commit comments

Comments
 (0)