Skip to content

Commit

Permalink
Kernel: Make ProcessTracer inherit from File.
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed Apr 28, 2019
1 parent 7ec1f6a commit e886337
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 182 deletions.
2 changes: 1 addition & 1 deletion Kernel/Devices/BXVGADevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ dword BXVGADevice::find_framebuffer_address()
return framebuffer_address;
}

Region* BXVGADevice::mmap(Process& process, LinearAddress preferred_laddr, size_t offset, size_t size)
KResultOr<Region*> BXVGADevice::mmap(Process& process, LinearAddress preferred_laddr, size_t offset, size_t size)
{
ASSERT(offset == 0);
ASSERT(size == framebuffer_size_in_bytes());
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Devices/BXVGADevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class BXVGADevice final : public BlockDevice {
void set_y_offset(int);

virtual int ioctl(Process&, unsigned request, unsigned arg) override;
virtual Region* mmap(Process&, LinearAddress preferred_laddr, size_t offset, size_t) override;
virtual KResultOr<Region*> mmap(Process&, LinearAddress preferred_laddr, size_t offset, size_t) override;

size_t framebuffer_size_in_bytes() const { return m_framebuffer_size.area() * sizeof(dword) * 2; }
Size framebuffer_size() const { return m_framebuffer_size; }
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Devices/BlockDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class BlockDevice : public Device {
public:
virtual ~BlockDevice() override;

virtual Region* mmap(Process&, LinearAddress preferred_laddr, size_t offset, size_t size) = 0;
virtual bool is_seekable() const override { return true; }

protected:
BlockDevice(unsigned major, unsigned minor) : Device(major, minor) { }
Expand Down
14 changes: 2 additions & 12 deletions Kernel/Devices/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,7 @@ Device::~Device()
VFS::the().unregister_device(*this);
}

KResultOr<Retained<FileDescriptor>> Device::open(int options)
String Device::absolute_path() const
{
UNUSED_PARAM(options);
return FileDescriptor::create(this);
}

void Device::close()
{
}

int Device::ioctl(Process&, unsigned, unsigned)
{
return -ENOTTY;
return String::format("device:%u,%u (%s)", m_major, m_minor, class_name());
}
31 changes: 5 additions & 26 deletions Kernel/Devices/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,21 @@
// - Subclasses should take care to validate incoming addresses before dereferencing.
//

#include <AK/Retainable.h>
#include <AK/Types.h>
#include <Kernel/FileSystem/FileDescriptor.h>
#include <Kernel/File.h>

class Process;

class Device : public Retainable<Device> {
class Device : public File {
public:
virtual ~Device();

InodeMetadata metadata() const { return { }; }

virtual KResultOr<Retained<FileDescriptor>> open(int options);
virtual void close();

virtual bool can_read(Process&) const = 0;
virtual bool can_write(Process&) const = 0;

virtual ssize_t read(Process&, byte*, ssize_t) = 0;
virtual ssize_t write(Process&, const byte*, ssize_t) = 0;
virtual ~Device() override;

unsigned major() const { return m_major; }
unsigned minor() const { return m_minor; }

virtual bool is_tty() const { return false; }
virtual bool is_master_pty() const { return false; }

virtual int ioctl(Process&, unsigned request, unsigned arg);

virtual const char* class_name() const = 0;
virtual String absolute_path() const override;

uid_t uid() const { return m_uid; }
uid_t gid() const { return m_gid; }

virtual bool is_block_device() const { return false; }
virtual bool is_character_device() const { return false; }
virtual bool is_device() const override { return true; }

protected:
Device(unsigned major, unsigned minor);
Expand Down
2 changes: 2 additions & 0 deletions Kernel/File.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once

#include <AK/Retainable.h>
#include <AK/Types.h>
#include <Kernel/FileSystem/FileDescriptor.h>
Expand Down
Loading

0 comments on commit e886337

Please sign in to comment.