2020-07-30 23:38:15 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-07-30 23:38:15 +02:00
|
|
|
*/
|
|
|
|
|
2021-10-11 21:47:21 +08:00
|
|
|
#include <AK/Userspace.h>
|
2023-01-07 13:52:06 -07:00
|
|
|
#include <Kernel/API/Ioctl.h>
|
2021-09-07 13:39:11 +02:00
|
|
|
#include <Kernel/FileSystem/OpenFileDescription.h>
|
2023-02-24 19:45:37 +02:00
|
|
|
#include <Kernel/Tasks/Process.h>
|
2020-07-30 23:38:15 +02:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2021-11-08 00:51:39 +01:00
|
|
|
ErrorOr<FlatPtr> Process::sys$ioctl(int fd, unsigned request, FlatPtr arg)
|
2020-07-30 23:38:15 +02:00
|
|
|
{
|
2022-08-17 21:03:04 +01:00
|
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
2022-01-29 01:22:28 +01:00
|
|
|
auto description = TRY(open_file_description(fd));
|
2021-03-29 08:57:11 +02:00
|
|
|
if (request == FIONBIO) {
|
2021-12-17 09:12:20 +01:00
|
|
|
description->set_blocking(TRY(copy_typed_from_user(Userspace<int const*>(arg))) == 0);
|
2021-11-08 00:51:39 +01:00
|
|
|
return 0;
|
2021-03-28 17:50:08 +02:00
|
|
|
}
|
2022-04-26 14:32:12 +02:00
|
|
|
if (request == FIOCLEX) {
|
|
|
|
m_fds.with_exclusive([&](auto& fds) {
|
|
|
|
fds[fd].set_flags(fds[fd].flags() | FD_CLOEXEC);
|
|
|
|
});
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (request == FIONCLEX) {
|
|
|
|
m_fds.with_exclusive([&](auto& fds) {
|
|
|
|
fds[fd].set_flags(fds[fd].flags() & ~FD_CLOEXEC);
|
|
|
|
});
|
|
|
|
return 0;
|
|
|
|
}
|
2021-11-08 00:51:39 +01:00
|
|
|
TRY(description->file().ioctl(*description, request, arg));
|
|
|
|
return 0;
|
2020-07-30 23:38:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|