mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05:00
9a04f53a0f
It's easy to forget the responsibility of validating and safely copying kernel parameters in code that is far away from syscalls. ioctl's are one such example, and bugs there are just as dangerous as at the root syscall level. To avoid this case, utilize the AK::Userspace<T> template in the ioctl kernel interface so that implementors have no choice but to properly validate and copy ioctl pointer arguments.
58 lines
1 KiB
C++
58 lines
1 KiB
C++
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/StringView.h>
|
|
#include <AK/Userspace.h>
|
|
#include <Kernel/FileSystem/File.h>
|
|
#include <Kernel/FileSystem/FileDescription.h>
|
|
#include <Kernel/Process.h>
|
|
|
|
namespace Kernel {
|
|
|
|
File::File()
|
|
{
|
|
}
|
|
|
|
File::~File()
|
|
{
|
|
}
|
|
|
|
KResultOr<NonnullRefPtr<FileDescription>> File::open(int options)
|
|
{
|
|
auto description = FileDescription::create(*this);
|
|
if (!description.is_error()) {
|
|
description.value()->set_rw_mode(options);
|
|
description.value()->set_file_flags(options);
|
|
}
|
|
return description;
|
|
}
|
|
|
|
KResult File::close()
|
|
{
|
|
return KSuccess;
|
|
}
|
|
|
|
int File::ioctl(FileDescription&, unsigned, Userspace<void*>)
|
|
{
|
|
return -ENOTTY;
|
|
}
|
|
|
|
KResultOr<Region*> File::mmap(Process&, FileDescription&, const Range&, u64, int, bool)
|
|
{
|
|
return ENODEV;
|
|
}
|
|
|
|
KResult File::attach(FileDescription&)
|
|
{
|
|
m_attach_count++;
|
|
return KSuccess;
|
|
}
|
|
|
|
void File::detach(FileDescription&)
|
|
{
|
|
m_attach_count--;
|
|
}
|
|
}
|