1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 22:07:36 +00:00

Add clang-format file

Also run it across the whole tree to get everything using the One True Style.
We don't yet run this in an automated fashion as it's a little slow, but
there is a snippet to do so in makeall.sh.
This commit is contained in:
Robin Burchell 2019-05-28 11:53:16 +02:00 committed by Andreas Kling
parent c11351ac50
commit 0dc9af5f7e
286 changed files with 3244 additions and 2424 deletions

View file

@ -2,8 +2,8 @@
class Alarm {
public:
Alarm() { }
virtual ~Alarm() { }
Alarm() {}
virtual ~Alarm() {}
virtual bool is_ringing() const = 0;
};

View file

@ -1,17 +1,24 @@
#pragma once
#include <Kernel/kstdio.h>
#include <Kernel/i386.h>
#include <Kernel/kstdio.h>
#ifdef DEBUG
[[noreturn]] void __assertion_failed(const char* msg, const char* file, unsigned line, const char* func);
#define ASSERT(expr) (static_cast<bool>(expr) ? (void)0 : __assertion_failed(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__))
#define ASSERT_NOT_REACHED() ASSERT(false)
# define ASSERT(expr) (static_cast<bool>(expr) ? (void)0 : __assertion_failed(# expr, __FILE__, __LINE__, __PRETTY_FUNCTION__))
# define ASSERT_NOT_REACHED() ASSERT(false)
#else
#define ASSERT(expr)
#define ASSERT_NOT_REACHED() CRASH()
# define ASSERT(expr)
# define ASSERT_NOT_REACHED() CRASH()
#endif
#define CRASH() do { asm volatile("ud2"); } while(0)
#define RELEASE_ASSERT(x) do { if (!(x)) CRASH(); } while(0)
#define CRASH() \
do { \
asm volatile("ud2"); \
} while (0)
#define RELEASE_ASSERT(x) \
do { \
if (!(x)) \
CRASH(); \
} while (0)
#define ASSERT_INTERRUPTS_DISABLED() ASSERT(!(cpu_flags() & 0x200))
#define ASSERT_INTERRUPTS_ENABLED() ASSERT(cpu_flags() & 0x200)

View file

@ -35,4 +35,3 @@ private:
ConsoleImplementation* m_implementation { nullptr };
CircularQueue<char, 16384> m_logbuffer;
};

View file

@ -1,10 +1,10 @@
#pragma once
#include <AK/Types.h>
#include <AK/AKString.h>
#include <SharedGraphics/Size.h>
#include <Kernel/PhysicalAddress.h>
#include <AK/Types.h>
#include <Kernel/Devices/BlockDevice.h>
#include <Kernel/PhysicalAddress.h>
#include <SharedGraphics/Size.h>
class BXVGADevice final : public BlockDevice {
AK_MAKE_ETERNAL

View file

@ -10,7 +10,10 @@ public:
virtual bool is_seekable() const override { return true; }
protected:
BlockDevice(unsigned major, unsigned minor) : Device(major, minor) { }
BlockDevice(unsigned major, unsigned minor)
: Device(major, minor)
{
}
private:
virtual bool is_block_device() const final { return true; }

View file

@ -7,7 +7,10 @@ public:
virtual ~CharacterDevice() override;
protected:
CharacterDevice(unsigned major, unsigned minor) : Device(major, minor) { }
CharacterDevice(unsigned major, unsigned minor)
: Device(major, minor)
{
}
private:
virtual bool is_character_device() const final { return true; }

View file

@ -23,4 +23,3 @@ public:
protected:
DiskDevice();
};

View file

@ -1,9 +1,9 @@
#pragma once
#include <Kernel/Devices/DiskDevice.h>
#include <AK/RetainPtr.h>
#include <AK/AKString.h>
#include <AK/RetainPtr.h>
#include <AK/Types.h>
#include <Kernel/Devices/DiskDevice.h>
#include <stdio.h>
class FileBackedDiskDevice final : public DiskDevice {
@ -30,4 +30,3 @@ private:
DiskOffset m_file_length { 0 };
unsigned m_block_size { 0 };
};

View file

@ -16,4 +16,3 @@ private:
virtual bool can_write(FileDescriptor&) const override { return true; }
virtual const char* class_name() const override { return "FullDevice"; }
};

View file

@ -1,9 +1,9 @@
#pragma once
#include <Kernel/Lock.h>
#include <AK/RetainPtr.h>
#include <Kernel/Devices/DiskDevice.h>
#include <Kernel/IRQHandler.h>
#include <Kernel/Lock.h>
#include <Kernel/PCI.h>
#include <Kernel/PhysicalAddress.h>
#include <Kernel/VM/PhysicalPage.h>
@ -14,7 +14,8 @@ struct PhysicalRegionDescriptor {
word end_of_table { 0 };
};
class IDEDiskDevice final : public IRQHandler, public DiskDevice {
class IDEDiskDevice final : public IRQHandler
, public DiskDevice {
AK_MAKE_ETERNAL
public:
static Retained<IDEDiskDevice> create();
@ -58,4 +59,3 @@ private:
word m_bus_master_base { 0 };
Lockable<bool> m_dma_enabled;
};

View file

@ -1,15 +1,16 @@
#pragma once
#include <AK/Types.h>
#include <AK/DoublyLinkedList.h>
#include <AK/CircularQueue.h>
#include <Kernel/Devices/CharacterDevice.h>
#include "IRQHandler.h"
#include "KeyCode.h"
#include <AK/CircularQueue.h>
#include <AK/DoublyLinkedList.h>
#include <AK/Types.h>
#include <Kernel/Devices/CharacterDevice.h>
class KeyboardClient;
class KeyboardDevice final : public IRQHandler, public CharacterDevice {
class KeyboardDevice final : public IRQHandler
, public CharacterDevice {
AK_MAKE_ETERNAL
public:
using Event = KeyEvent;

View file

@ -18,4 +18,3 @@ private:
virtual bool can_read(FileDescriptor&) const override;
virtual const char* class_name() const override { return "NullDevice"; }
};

View file

@ -1,11 +1,12 @@
#pragma once
#include <Kernel/Devices/CharacterDevice.h>
#include <Kernel/MousePacket.h>
#include <Kernel/IRQHandler.h>
#include <AK/CircularQueue.h>
#include <Kernel/Devices/CharacterDevice.h>
#include <Kernel/IRQHandler.h>
#include <Kernel/MousePacket.h>
class PS2MouseDevice final : public IRQHandler, public CharacterDevice {
class PS2MouseDevice final : public IRQHandler
, public CharacterDevice {
public:
PS2MouseDevice();
virtual ~PS2MouseDevice() override;

View file

@ -18,4 +18,3 @@ private:
virtual bool can_write(FileDescriptor&) const override { return true; }
virtual const char* class_name() const override { return "RandomDevice"; }
};

View file

@ -16,4 +16,3 @@ private:
virtual bool can_write(FileDescriptor&) const override { return true; }
virtual const char* class_name() const override { return "ZeroDevice"; }
};

View file

@ -26,4 +26,3 @@ private:
HashTable<SlavePTY*> m_slave_ptys;
};

View file

@ -1,9 +1,9 @@
#pragma once
#include <Kernel/UnixTypes.h>
#include <Kernel/FileSystem/DiskBackedFileSystem.h>
#include <Kernel/FileSystem/Inode.h>
#include <Kernel/FileSystem/ext2_fs.h>
#include <Kernel/FileSystem/DiskBackedFileSystem.h>
#include <Kernel/UnixTypes.h>
struct ext2_group_desc;
struct ext2_inode;
@ -13,6 +13,7 @@ class Ext2FS;
class Ext2FSInode final : public Inode {
friend class Ext2FS;
public:
virtual ~Ext2FSInode() override;
@ -59,8 +60,9 @@ private:
class Ext2FS final : public DiskBackedFS {
friend class Ext2FSInode;
public:
static Retained <Ext2FS> create(Retained<DiskDevice>&&);
static Retained<Ext2FS> create(Retained<DiskDevice>&&);
virtual ~Ext2FS() override;
virtual bool initialize() override;

View file

@ -1,15 +1,18 @@
#pragma once
#include <Kernel/DoubleBuffer.h>
#include <Kernel/UnixTypes.h>
#include <Kernel/File.h>
#include <Kernel/UnixTypes.h>
class FileDescriptor;
class FIFO final : public File {
public:
enum class Direction : byte {
Neither, Reader, Writer
enum class Direction : byte
{
Neither,
Reader,
Writer
};
static RetainPtr<FIFO> from_fifo_id(dword);

View file

@ -1,14 +1,14 @@
#pragma once
#include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/FileSystem/InodeMetadata.h>
#include <Kernel/FileSystem/Inode.h>
#include <Kernel/FileSystem/FIFO.h>
#include <Kernel/LinearAddress.h>
#include <AK/Badge.h>
#include <AK/ByteBuffer.h>
#include <AK/CircularQueue.h>
#include <AK/Retainable.h>
#include <AK/Badge.h>
#include <Kernel/FileSystem/FIFO.h>
#include <Kernel/FileSystem/Inode.h>
#include <Kernel/FileSystem/InodeMetadata.h>
#include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/LinearAddress.h>
#include <Kernel/Net/Socket.h>
class File;
@ -119,4 +119,3 @@ private:
SocketRole m_socket_role { SocketRole::None };
FIFO::Direction m_fifo_direction { FIFO::Direction::Neither };
};

View file

@ -1,20 +1,20 @@
#pragma once
#include <Kernel/Devices/DiskDevice.h>
#include "InodeIdentifier.h"
#include "InodeMetadata.h"
#include "UnixTypes.h"
#include <AK/AKString.h>
#include <AK/ByteBuffer.h>
#include <AK/Function.h>
#include <AK/HashMap.h>
#include <AK/OwnPtr.h>
#include <AK/Retainable.h>
#include <AK/RetainPtr.h>
#include <AK/AKString.h>
#include <AK/Function.h>
#include <AK/kstdio.h>
#include <Kernel/Lock.h>
#include <AK/Retainable.h>
#include <AK/WeakPtr.h>
#include <AK/kstdio.h>
#include <Kernel/Devices/DiskDevice.h>
#include <Kernel/KResult.h>
#include <Kernel/Lock.h>
static const dword mepoch = 476763780;
@ -25,6 +25,7 @@ class VMObject;
class FS : public Retainable<FS> {
friend class Inode;
public:
virtual ~FS();
@ -57,7 +58,7 @@ public:
virtual RetainPtr<Inode> get_inode(InodeIdentifier) const = 0;
virtual void flush_writes() { }
virtual void flush_writes() {}
protected:
FS();
@ -93,4 +94,3 @@ struct Traits<InodeIdentifier> {
};
}

View file

@ -1,12 +1,12 @@
#pragma once
#include <AK/Retainable.h>
#include <AK/AKString.h>
#include <AK/Function.h>
#include <AK/Retainable.h>
#include <AK/WeakPtr.h>
#include <Kernel/FileSystem/FileSystem.h>
#include <Kernel/FileSystem/InodeIdentifier.h>
#include <Kernel/FileSystem/InodeMetadata.h>
#include <Kernel/FileSystem/FileSystem.h>
#include <Kernel/KResult.h>
#include <Kernel/Lock.h>
@ -17,10 +17,11 @@ class VMObject;
class Inode : public Retainable<Inode> {
friend class VFS;
friend class FS;
public:
virtual ~Inode();
virtual void one_retain_left() { }
virtual void one_retain_left() {}
FS& fs() { return m_fs; }
const FS& fs() const { return m_fs; }
@ -89,4 +90,3 @@ private:
RetainPtr<LocalSocket> m_socket;
bool m_metadata_dirty { false };
};

View file

@ -8,7 +8,7 @@ struct InodeMetadata;
class InodeIdentifier {
public:
InodeIdentifier() { }
InodeIdentifier() {}
InodeIdentifier(dword fsid, dword inode)
: m_fsid(fsid)
, m_index(inode)
@ -39,4 +39,3 @@ private:
dword m_fsid { 0 };
dword m_index { 0 };
};

View file

@ -84,5 +84,3 @@ struct InodeMetadata {
unsigned major_device { 0 };
unsigned minor_device { 0 };
};

View file

@ -1,9 +1,9 @@
#pragma once
#include <Kernel/Lock.h>
#include <AK/Types.h>
#include <Kernel/FileSystem/FileSystem.h>
#include <Kernel/FileSystem/Inode.h>
#include <Kernel/Lock.h>
class Process;
@ -11,6 +11,7 @@ class ProcFSInode;
class ProcFS final : public FS {
friend class ProcFSInode;
public:
[[gnu::pure]] static ProcFS& the();
@ -34,7 +35,7 @@ private:
ProcFS();
struct ProcFSDirectoryEntry {
ProcFSDirectoryEntry() { }
ProcFSDirectoryEntry() {}
ProcFSDirectoryEntry(const char* a_name, unsigned a_proc_file_type, Function<ByteBuffer(InodeIdentifier)>&& a_read_callback = nullptr, Function<ssize_t(InodeIdentifier, const ByteBuffer&)>&& a_write_callback = nullptr, RetainPtr<ProcFSInode>&& a_inode = nullptr)
: name(a_name)
, proc_file_type(a_proc_file_type)
@ -69,6 +70,7 @@ struct ProcFSInodeCustomData {
class ProcFSInode final : public Inode {
friend class ProcFS;
public:
virtual ~ProcFSInode() override;

View file

@ -1,9 +1,9 @@
#pragma once
#include <AK/HashMap.h>
#include <Kernel/FileSystem/FileSystem.h>
#include <Kernel/FileSystem/Inode.h>
#include <Kernel/UnixTypes.h>
#include <AK/HashMap.h>
class SynthFSInode;
@ -47,6 +47,7 @@ struct SynthFSInodeCustomData {
class SynthFSInode final : public Inode {
friend class SynthFS;
friend class DevPtsFS;
public:
virtual ~SynthFSInode() override;

View file

@ -1,14 +1,14 @@
#pragma once
#include "FileSystem.h"
#include "InodeIdentifier.h"
#include "InodeMetadata.h"
#include <AK/AKString.h>
#include <AK/Function.h>
#include <AK/HashMap.h>
#include <AK/OwnPtr.h>
#include <AK/RetainPtr.h>
#include <AK/AKString.h>
#include <AK/Vector.h>
#include <AK/Function.h>
#include "InodeIdentifier.h"
#include "InodeMetadata.h"
#include "FileSystem.h"
#include <Kernel/KResult.h>
#define O_RDONLY 0
@ -116,4 +116,3 @@ private:
Vector<OwnPtr<Mount>> m_mounts;
HashMap<dword, Device*> m_devices;
};

File diff suppressed because it is too large Load diff

View file

@ -3,140 +3,141 @@
* everything we need. (cross fingers) Other header files may have
* also defined the types that we need.
*/
#if (!defined(_LINUX_TYPES_H) && !defined(_BLKID_TYPES_H) && \
!defined(_EXT2_TYPES_H))
#define _EXT2_TYPES_H
#if (!defined(_LINUX_TYPES_H) && !defined(_BLKID_TYPES_H) && !defined(_EXT2_TYPES_H))
# define _EXT2_TYPES_H
#define __S8_TYPEDEF __signed__ char
#define __U8_TYPEDEF unsigned char
#define __S16_TYPEDEF __signed__ short
#define __U16_TYPEDEF unsigned short
#define __S32_TYPEDEF __signed__ int
#define __U32_TYPEDEF unsigned int
#define __S64_TYPEDEF __signed__ long long
#define __U64_TYPEDEF unsigned long long
# define __S8_TYPEDEF __signed__ char
# define __U8_TYPEDEF unsigned char
# define __S16_TYPEDEF __signed__ short
# define __U16_TYPEDEF unsigned short
# define __S32_TYPEDEF __signed__ int
# define __U32_TYPEDEF unsigned int
# define __S64_TYPEDEF __signed__ long long
# define __U64_TYPEDEF unsigned long long
#ifdef __U8_TYPEDEF
# ifdef __U8_TYPEDEF
typedef __U8_TYPEDEF __u8;
#else
# else
typedef unsigned char __u8;
#endif
# endif
#ifdef __S8_TYPEDEF
# ifdef __S8_TYPEDEF
typedef __S8_TYPEDEF __s8;
#else
# else
typedef signed char __s8;
#endif
# endif
#ifdef __U16_TYPEDEF
# ifdef __U16_TYPEDEF
typedef __U16_TYPEDEF __u16;
#else
#if (4 == 2)
typedef unsigned int __u16;
#else
#if (2 == 2)
typedef unsigned short __u16;
#else
?==error: undefined 16 bit type
#endif /* SIZEOF_SHORT == 2 */
#endif /* SIZEOF_INT == 2 */
#endif /* __U16_TYPEDEF */
# else
# if (4 == 2)
typedef unsigned int __u16;
# else
# if (2 == 2)
typedef unsigned short __u16;
# else
? == error : undefined 16 bit type
# endif /* SIZEOF_SHORT == 2 */
# endif /* SIZEOF_INT == 2 */
# endif /* __U16_TYPEDEF */
#ifdef __S16_TYPEDEF
# ifdef __S16_TYPEDEF
typedef __S16_TYPEDEF __s16;
#else
#if (4 == 2)
typedef int __s16;
#else
#if (2 == 2)
typedef short __s16;
#else
?==error: undefined 16 bit type
#endif /* SIZEOF_SHORT == 2 */
#endif /* SIZEOF_INT == 2 */
#endif /* __S16_TYPEDEF */
# else
# if (4 == 2)
typedef int __s16;
# else
# if (2 == 2)
typedef short __s16;
# else
? == error
: undefined 16 bit type
# endif /* SIZEOF_SHORT == 2 */
# endif /* SIZEOF_INT == 2 */
# endif /* __S16_TYPEDEF */
#ifdef __U32_TYPEDEF
# ifdef __U32_TYPEDEF
typedef __U32_TYPEDEF __u32;
#else
#if (4 == 4)
typedef unsigned int __u32;
#else
#if (4 == 4)
typedef unsigned long __u32;
#else
#if (2 == 4)
typedef unsigned short __u32;
#else
?== error: undefined 32 bit type
#endif /* SIZEOF_SHORT == 4 */
#endif /* SIZEOF_LONG == 4 */
#endif /* SIZEOF_INT == 4 */
#endif /* __U32_TYPEDEF */
# else
# if (4 == 4)
typedef unsigned int __u32;
# else
# if (4 == 4)
typedef unsigned long __u32;
# else
# if (2 == 4)
typedef unsigned short __u32;
# else
? == error
: undefined 32 bit type
# endif /* SIZEOF_SHORT == 4 */
# endif /* SIZEOF_LONG == 4 */
# endif /* SIZEOF_INT == 4 */
# endif /* __U32_TYPEDEF */
#ifdef __S32_TYPEDEF
# ifdef __S32_TYPEDEF
typedef __S32_TYPEDEF __s32;
#else
#if (4 == 4)
typedef int __s32;
#else
#if (4 == 4)
typedef long __s32;
#else
#if (2 == 4)
typedef short __s32;
#else
?== error: undefined 32 bit type
#endif /* SIZEOF_SHORT == 4 */
#endif /* SIZEOF_LONG == 4 */
#endif /* SIZEOF_INT == 4 */
#endif /* __S32_TYPEDEF */
# else
# if (4 == 4)
typedef int __s32;
# else
# if (4 == 4)
typedef long __s32;
# else
# if (2 == 4)
typedef short __s32;
# else
? == error
: undefined 32 bit type
# endif /* SIZEOF_SHORT == 4 */
# endif /* SIZEOF_LONG == 4 */
# endif /* SIZEOF_INT == 4 */
# endif /* __S32_TYPEDEF */
#ifdef __U64_TYPEDEF
# ifdef __U64_TYPEDEF
typedef __U64_TYPEDEF __u64;
#else
#if (4 == 8)
typedef unsigned int __u64;
#else
#if (4 == 8)
typedef unsigned long __u64;
#else
#if (8 == 8)
typedef unsigned long long __u64;
#endif /* SIZEOF_LONG_LONG == 8 */
#endif /* SIZEOF_LONG == 8 */
#endif /* SIZEOF_INT == 8 */
#endif /* __U64_TYPEDEF */
# else
# if (4 == 8)
typedef unsigned int __u64;
# else
# if (4 == 8)
typedef unsigned long __u64;
# else
# if (8 == 8)
typedef unsigned long long __u64;
# endif /* SIZEOF_LONG_LONG == 8 */
# endif /* SIZEOF_LONG == 8 */
# endif /* SIZEOF_INT == 8 */
# endif /* __U64_TYPEDEF */
#ifdef __S64_TYPEDEF
# ifdef __S64_TYPEDEF
typedef __S64_TYPEDEF __s64;
#else
#if (4 == 8)
typedef int __s64;
#else
#if (4 == 8)
typedef long __s64;
#else
#if (8 == 8)
#if defined(__GNUC__)
typedef __signed__ long long __s64;
#else
typedef signed long long __s64;
#endif /* __GNUC__ */
#endif /* SIZEOF_LONG_LONG == 8 */
#endif /* SIZEOF_LONG == 8 */
#endif /* SIZEOF_INT == 8 */
#endif /* __S64_TYPEDEF */
# else
# if (4 == 8)
typedef int __s64;
# else
# if (4 == 8)
typedef long __s64;
# else
# if (8 == 8)
# if defined(__GNUC__)
typedef __signed__ long long __s64;
# else
typedef signed long long __s64;
# endif /* __GNUC__ */
# endif /* SIZEOF_LONG_LONG == 8 */
# endif /* SIZEOF_LONG == 8 */
# endif /* SIZEOF_INT == 8 */
# endif /* __S64_TYPEDEF */
#undef __S8_TYPEDEF
#undef __U8_TYPEDEF
#undef __S16_TYPEDEF
#undef __U16_TYPEDEF
#undef __S32_TYPEDEF
#undef __U32_TYPEDEF
#undef __S64_TYPEDEF
#undef __U64_TYPEDEF
# undef __S8_TYPEDEF
# undef __U8_TYPEDEF
# undef __S16_TYPEDEF
# undef __U16_TYPEDEF
# undef __S32_TYPEDEF
# undef __U32_TYPEDEF
# undef __S64_TYPEDEF
# undef __U64_TYPEDEF
#endif /* _*_TYPES_H */

View file

@ -7,47 +7,58 @@ namespace IO {
inline byte in8(word port)
{
byte value;
asm volatile("inb %1, %0":"=a"(value):"Nd"(port));
asm volatile("inb %1, %0"
: "=a"(value)
: "Nd"(port));
return value;
}
inline word in16(word port)
{
word value;
asm volatile("inw %1, %0":"=a"(value):"Nd"(port));
asm volatile("inw %1, %0"
: "=a"(value)
: "Nd"(port));
return value;
}
inline dword in32(word port)
{
dword value;
asm volatile("inl %1, %0":"=a"(value):"Nd"(port));
asm volatile("inl %1, %0"
: "=a"(value)
: "Nd"(port));
return value;
}
inline void repeated_in16(word port, byte* buffer, int buffer_size)
{
asm volatile("rep insw" : "+D"(buffer), "+c"(buffer_size) : "d"(port) : "memory");
asm volatile("rep insw"
: "+D"(buffer), "+c"(buffer_size)
: "d"(port)
: "memory");
}
inline void out8(word port, byte value)
{
asm volatile("outb %0, %1"::"a"(value), "Nd"(port));
asm volatile("outb %0, %1" ::"a"(value), "Nd"(port));
}
inline void out16(word port, word value)
{
asm volatile("outw %0, %1"::"a"(value), "Nd"(port));
asm volatile("outw %0, %1" ::"a"(value), "Nd"(port));
}
inline void out32(word port, dword value)
{
asm volatile("outl %0, %1"::"a"(value), "Nd"(port));
asm volatile("outl %0, %1" ::"a"(value), "Nd"(port));
}
inline void repeated_out16(word port, const byte* data, int data_size)
{
asm volatile("rep outsw" : "+S"(data), "+c"(data_size) : "d"(port));
asm volatile("rep outsw"
: "+S"(data), "+c"(data_size)
: "d"(port));
}
}

View file

@ -18,4 +18,3 @@ protected:
private:
byte m_irq_number { 0 };
};

View file

@ -3,20 +3,31 @@
#include <AK/Assertions.h>
#include <LibC/errno_numbers.h>
enum KSuccessTag { KSuccess };
enum KSuccessTag
{
KSuccess
};
class KResult {
public:
explicit KResult(int negative_e) : m_error(negative_e) { ASSERT(negative_e <= 0); }
KResult(KSuccessTag) : m_error(0) { }
explicit KResult(int negative_e)
: m_error(negative_e)
{
ASSERT(negative_e <= 0);
}
KResult(KSuccessTag)
: m_error(0)
{
}
operator int() const { return m_error; }
bool is_success() const { return m_error == ESUCCESS; }
bool is_error() const { return !is_success(); }
private:
template<typename T> friend class KResultOr;
KResult() { }
template<typename T>
friend class KResultOr;
KResult() {}
int m_error { 0 };
};
@ -27,7 +38,8 @@ public:
KResultOr(KResult error)
: m_error(error)
, m_is_error(true)
{ }
{
}
KResultOr(T&& value)
{
@ -54,9 +66,21 @@ public:
}
bool is_error() const { return m_is_error; }
KResult error() const { ASSERT(m_is_error); return m_error; }
T& value() { ASSERT(!m_is_error); return *reinterpret_cast<T*>(&m_storage); }
const T& value() const { ASSERT(!m_is_error); return *reinterpret_cast<T*>(&m_storage); }
KResult error() const
{
ASSERT(m_is_error);
return m_error;
}
T& value()
{
ASSERT(!m_is_error);
return *reinterpret_cast<T*>(&m_storage);
}
const T& value() const
{
ASSERT(!m_is_error);
return *reinterpret_cast<T*>(&m_storage);
}
T release_value()
{
@ -71,4 +95,3 @@ private:
KResult m_error;
bool m_is_error { false };
};

View file

@ -2,7 +2,8 @@
#include <AK/Types.h>
enum KeyCode : byte {
enum KeyCode : byte
{
Key_Invalid = 0,
Key_Escape,
Key_Tab,
@ -113,7 +114,8 @@ enum KeyCode : byte {
Key_Shift = Key_LeftShift,
};
enum KeyModifier {
enum KeyModifier
{
Mod_None = 0x00,
Mod_Alt = 0x01,
Mod_Ctrl = 0x02,

View file

@ -4,8 +4,11 @@
class LinearAddress {
public:
LinearAddress() { }
explicit LinearAddress(dword address) : m_address(address) { }
LinearAddress() {}
explicit LinearAddress(dword address)
: m_address(address)
{
}
bool is_null() const { return m_address == 0; }

View file

@ -2,9 +2,9 @@
#include <AK/Assertions.h>
#include <AK/Types.h>
#include <Kernel/i386.h>
#include <Kernel/Scheduler.h>
#include <Kernel/KSyms.h>
#include <Kernel/Scheduler.h>
#include <Kernel/i386.h>
class Thread;
extern Thread* current;
@ -14,16 +14,19 @@ static inline dword CAS(volatile dword* mem, dword newval, dword oldval)
dword ret;
asm volatile(
"cmpxchgl %2, %1"
:"=a"(ret), "+m"(*mem)
:"r"(newval), "0"(oldval)
:"cc", "memory");
: "=a"(ret), "+m"(*mem)
: "r"(newval), "0"(oldval)
: "cc", "memory");
return ret;
}
class Lock {
public:
Lock(const char* name = nullptr) : m_name(name) { }
~Lock() { }
Lock(const char* name = nullptr)
: m_name(name)
{
}
~Lock() {}
void lock();
void unlock();
@ -40,7 +43,11 @@ private:
class Locker {
public:
[[gnu::always_inline]] inline explicit Locker(Lock& l) : m_lock(l) { lock(); }
[[gnu::always_inline]] inline explicit Locker(Lock& l)
: m_lock(l)
{
lock();
}
[[gnu::always_inline]] inline ~Locker() { unlock(); }
[[gnu::always_inline]] inline void unlock() { m_lock.unlock(); }
[[gnu::always_inline]] inline void lock() { m_lock.lock(); }
@ -123,8 +130,11 @@ inline bool Lock::unlock_if_locked()
template<typename T>
class Lockable {
public:
Lockable() { }
Lockable(T&& resource) : m_resource(move(resource)) { }
Lockable() {}
Lockable(T&& resource)
: m_resource(move(resource))
{
}
Lock& lock() { return m_lock; }
T& resource() { return m_resource; }
@ -138,4 +148,3 @@ private:
T m_resource;
Lock m_lock;
};

View file

@ -1,23 +1,26 @@
#pragma once
#include <Kernel/Net/MACAddress.h>
#include <Kernel/Net/IPv4.h>
#include <Kernel/Net/EtherType.h>
#include <Kernel/Net/IPv4.h>
#include <Kernel/Net/MACAddress.h>
struct ARPOperation {
enum : word {
Request = 1,
Response = 2,
};
enum : word
{
Request = 1,
Response = 2,
};
};
struct ARPHardwareType {
enum : word {
Ethernet = 1,
};
enum : word
{
Ethernet = 1,
};
};
class [[gnu::packed]] ARPPacket {
class [[gnu::packed]] ARPPacket
{
public:
word hardware_type() const { return ntohs(m_hardware_type); }
void set_hardware_type(word w) { m_hardware_type = htons(w); }

View file

@ -1,12 +1,13 @@
#pragma once
#include <AK/OwnPtr.h>
#include <Kernel/IRQHandler.h>
#include <Kernel/Net/NetworkAdapter.h>
#include <Kernel/PCI.h>
#include <Kernel/VM/MemoryManager.h>
#include <Kernel/IRQHandler.h>
#include <AK/OwnPtr.h>
class E1000NetworkAdapter final : public NetworkAdapter, public IRQHandler {
class E1000NetworkAdapter final : public NetworkAdapter
, public IRQHandler {
public:
static E1000NetworkAdapter* the();
@ -21,7 +22,8 @@ private:
virtual void handle_irq() override;
virtual const char* class_name() const override { return "E1000NetworkAdapter"; }
struct [[gnu::packed]] e1000_rx_desc {
struct [[gnu::packed]] e1000_rx_desc
{
volatile uint64_t addr { 0 };
volatile uint16_t length { 0 };
volatile uint16_t checksum { 0 };
@ -30,7 +32,8 @@ private:
volatile uint16_t special { 0 };
};
struct [[gnu::packed]] e1000_tx_desc {
struct [[gnu::packed]] e1000_tx_desc
{
volatile uint64_t addr { 0 };
volatile uint16_t length { 0 };
volatile uint8_t cso { 0 };

View file

@ -3,8 +3,9 @@
#include <AK/Types.h>
struct EtherType {
enum : word {
ARP = 0x0806,
IPv4 = 0x0800,
};
enum : word
{
ARP = 0x0806,
IPv4 = 0x0800,
};
};

View file

@ -1,12 +1,13 @@
#pragma once
#include <Kernel/Net/MACAddress.h>
#include <AK/NetworkOrdered.h>
#include <Kernel/Net/MACAddress.h>
class [[gnu::packed]] EthernetFrameHeader {
class [[gnu::packed]] EthernetFrameHeader
{
public:
EthernetFrameHeader() { }
~EthernetFrameHeader() { }
EthernetFrameHeader() {}
~EthernetFrameHeader() {}
MACAddress destination() const { return m_destination; }
void set_destination(const MACAddress& address) { m_destination = address; }
@ -28,4 +29,3 @@ private:
};
static_assert(sizeof(EthernetFrameHeader) == 14);

View file

@ -1,19 +1,21 @@
#pragma once
#include <Kernel/Net/MACAddress.h>
#include <Kernel/Net/IPv4.h>
#include <Kernel/Net/MACAddress.h>
struct ICMPType {
enum {
EchoReply = 0,
EchoRequest = 8,
};
enum
{
EchoReply = 0,
EchoRequest = 8,
};
};
class [[gnu::packed]] ICMPHeader {
class [[gnu::packed]] ICMPHeader
{
public:
ICMPHeader() { }
~ICMPHeader() { }
ICMPHeader() {}
~ICMPHeader() {}
byte type() const { return m_type; }
void set_type(byte b) { m_type = b; }
@ -36,7 +38,8 @@ private:
static_assert(sizeof(ICMPHeader) == 4);
struct [[gnu::packed]] ICMPEchoPacket {
struct [[gnu::packed]] ICMPEchoPacket
{
ICMPHeader header;
NetworkOrdered<word> identifier;
NetworkOrdered<word> sequence_number;

View file

@ -5,7 +5,8 @@
#include <AK/NetworkOrdered.h>
#include <AK/Types.h>
enum class IPv4Protocol : word {
enum class IPv4Protocol : word
{
ICMP = 1,
TCP = 6,
UDP = 17,
@ -13,9 +14,10 @@ enum class IPv4Protocol : word {
NetworkOrdered<word> internet_checksum(const void*, size_t);
class [[gnu::packed]] IPv4Address {
class [[gnu::packed]] IPv4Address
{
public:
IPv4Address() { }
IPv4Address() {}
IPv4Address(const byte data[4])
{
m_data[0] = data[0];
@ -64,7 +66,8 @@ struct Traits<IPv4Address> {
}
class [[gnu::packed]] IPv4Packet {
class [[gnu::packed]] IPv4Packet
{
public:
byte version() const { return (m_version_and_ihl >> 4) & 0xf; }
void set_version(byte version) { m_version_and_ihl = (m_version_and_ihl & 0x0f) | (version << 4); }

View file

@ -1,11 +1,11 @@
#pragma once
#include <Kernel/Net/Socket.h>
#include <Kernel/DoubleBuffer.h>
#include <Kernel/Net/IPv4.h>
#include <AK/HashMap.h>
#include <Kernel/Lock.h>
#include <AK/SinglyLinkedList.h>
#include <Kernel/DoubleBuffer.h>
#include <Kernel/Lock.h>
#include <Kernel/Net/IPv4.h>
#include <Kernel/Net/Socket.h>
class IPv4SocketHandle;
class TCPSocketHandle;
@ -86,7 +86,7 @@ private:
class IPv4SocketHandle : public SocketHandle {
public:
IPv4SocketHandle() { }
IPv4SocketHandle() {}
IPv4SocketHandle(RetainPtr<IPv4Socket>&& socket)
: SocketHandle(move(socket))

View file

@ -1,7 +1,7 @@
#pragma once
#include <Kernel/Net/Socket.h>
#include <Kernel/DoubleBuffer.h>
#include <Kernel/Net/Socket.h>
class FileDescriptor;
@ -39,4 +39,3 @@ private:
DoubleBuffer m_for_client;
DoubleBuffer m_for_server;
};

View file

@ -1,18 +1,19 @@
#pragma once
#include <AK/Assertions.h>
#include <AK/AKString.h>
#include <AK/Assertions.h>
#include <AK/Types.h>
#include <Kernel/StdLib.h>
class [[gnu::packed]] MACAddress {
class [[gnu::packed]] MACAddress
{
public:
MACAddress() { }
MACAddress() {}
MACAddress(const byte data[6])
{
memcpy(m_data, data, 6);
}
~MACAddress() { }
~MACAddress() {}
byte operator[](int i) const
{

View file

@ -3,19 +3,23 @@
#include <AK/ByteBuffer.h>
#include <AK/SinglyLinkedList.h>
#include <AK/Types.h>
#include <Kernel/Net/MACAddress.h>
#include <Kernel/Net/IPv4.h>
#include <Kernel/Alarm.h>
#include <Kernel/Net/ARP.h>
#include <Kernel/Net/ICMP.h>
#include <Kernel/Alarm.h>
#include <Kernel/Net/IPv4.h>
#include <Kernel/Net/MACAddress.h>
class NetworkAdapter;
class PacketQueueAlarm final : public Alarm {
public:
PacketQueueAlarm(NetworkAdapter& adapter) : m_adapter(adapter) { }
virtual ~PacketQueueAlarm() override { }
PacketQueueAlarm(NetworkAdapter& adapter)
: m_adapter(adapter)
{
}
virtual ~PacketQueueAlarm() override {}
virtual bool is_ringing() const override;
private:
NetworkAdapter& m_adapter;
};

View file

@ -1,16 +1,27 @@
#pragma once
#include <Kernel/Lock.h>
#include <AK/Retainable.h>
#include <AK/RetainPtr.h>
#include <AK/HashTable.h>
#include <AK/RetainPtr.h>
#include <AK/Retainable.h>
#include <AK/Vector.h>
#include <Kernel/File.h>
#include <Kernel/UnixTypes.h>
#include <Kernel/KResult.h>
#include <Kernel/Lock.h>
#include <Kernel/UnixTypes.h>
enum class SocketRole : byte { None, Listener, Accepted, Connected, Connecting };
enum class ShouldBlock { No = 0, Yes = 1 };
enum class SocketRole : byte
{
None,
Listener,
Accepted,
Connected,
Connecting
};
enum class ShouldBlock
{
No = 0,
Yes = 1
};
class FileDescriptor;
@ -85,7 +96,7 @@ private:
class SocketHandle {
public:
SocketHandle() { }
SocketHandle() {}
SocketHandle(RetainPtr<Socket>&& socket)
: m_socket(move(socket))

View file

@ -3,20 +3,22 @@
#include <Kernel/Net/IPv4.h>
struct TCPFlags {
enum : word {
FIN = 0x01,
SYN = 0x02,
RST = 0x04,
PUSH = 0x08,
ACK = 0x10,
URG = 0x20
};
enum : word
{
FIN = 0x01,
SYN = 0x02,
RST = 0x04,
PUSH = 0x08,
ACK = 0x10,
URG = 0x20
};
};
class [[gnu::packed]] TCPPacket {
class [[gnu::packed]] TCPPacket
{
public:
TCPPacket() { }
~TCPPacket() { }
TCPPacket() {}
~TCPPacket() {}
size_t header_size() const { return data_offset() * sizeof(dword); }

View file

@ -7,7 +7,8 @@ public:
static Retained<TCPSocket> create(int protocol);
virtual ~TCPSocket() override;
enum class State {
enum class State
{
Disconnected,
Connecting,
Connected,
@ -47,7 +48,7 @@ private:
class TCPSocketHandle : public SocketHandle {
public:
TCPSocketHandle() { }
TCPSocketHandle() {}
TCPSocketHandle(RetainPtr<TCPSocket>&& socket)
: SocketHandle(move(socket))

View file

@ -2,10 +2,11 @@
#include <Kernel/Net/IPv4.h>
class [[gnu::packed]] UDPPacket {
class [[gnu::packed]] UDPPacket
{
public:
UDPPacket() { }
~UDPPacket() { }
UDPPacket() {}
~UDPPacket() {}
word source_port() const { return m_source_port; }
void set_source_port(word port) { m_source_port = port; }

View file

@ -25,7 +25,7 @@ private:
class UDPSocketHandle : public SocketHandle {
public:
UDPSocketHandle() { }
UDPSocketHandle() {}
UDPSocketHandle(RetainPtr<UDPSocket>&& socket)
: SocketHandle(move(socket))
@ -46,4 +46,3 @@ public:
UDPSocket& socket() { return static_cast<UDPSocket&>(SocketHandle::socket()); }
const UDPSocket& socket() const { return static_cast<const UDPSocket&>(SocketHandle::socket()); }
};

View file

@ -18,8 +18,13 @@ struct ID {
};
struct Address {
Address() { }
Address(byte bus, byte slot, byte function) : m_bus(bus), m_slot(slot), m_function(function) { }
Address() {}
Address(byte bus, byte slot, byte function)
: m_bus(bus)
, m_slot(slot)
, m_function(function)
{
}
bool is_null() const { return !m_bus && !m_slot && !m_function; }
operator bool() const { return !is_null(); }

View file

@ -15,7 +15,10 @@ word get_irr();
class IRQHandlerScope {
public:
explicit IRQHandlerScope(byte irq) : m_irq(irq) { }
explicit IRQHandlerScope(byte irq)
: m_irq(irq)
{
}
~IRQHandlerScope() { PIC::eoi(m_irq); }
private:

View file

@ -2,8 +2,11 @@
class PhysicalAddress {
public:
PhysicalAddress() { }
explicit PhysicalAddress(dword address) : m_address(address) { }
PhysicalAddress() {}
explicit PhysicalAddress(dword address)
: m_address(address)
{
}
PhysicalAddress offset(dword o) const { return PhysicalAddress(m_address + o); }
dword get() const { return m_address; }
@ -22,4 +25,3 @@ public:
private:
dword m_address { 0 };
};

View file

@ -1,18 +1,18 @@
#pragma once
#include <AK/Types.h>
#include <AK/InlineLinkedList.h>
#include <AK/AKString.h>
#include <AK/InlineLinkedList.h>
#include <AK/Types.h>
#include <AK/Vector.h>
#include <AK/WeakPtr.h>
#include <AK/Weakable.h>
#include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/VM/RangeAllocator.h>
#include <Kernel/TTY/TTY.h>
#include <Kernel/Syscall.h>
#include <Kernel/UnixTypes.h>
#include <Kernel/Thread.h>
#include <Kernel/Lock.h>
#include <Kernel/Syscall.h>
#include <Kernel/TTY/TTY.h>
#include <Kernel/Thread.h>
#include <Kernel/UnixTypes.h>
#include <Kernel/VM/RangeAllocator.h>
#include <LibC/signal_numbers.h>
class ELFLoader;
@ -24,9 +24,11 @@ class ProcessTracer;
void kgettimeofday(timeval&);
class Process : public InlineLinkedListNode<Process>, public Weakable<Process> {
class Process : public InlineLinkedListNode<Process>
, public Weakable<Process> {
friend class InlineLinkedListNode<Process>;
friend class Thread;
public:
static Process* create_kernel_process(String&& name, void (*entry)());
static Process* create_user_process(const String& path, uid_t, gid_t, pid_t ppid, int& error, Vector<String>&& arguments = Vector<String>(), Vector<String>&& environment = Vector<String>(), TTY* = nullptr);
@ -35,14 +37,16 @@ public:
static Vector<pid_t> all_pids();
static Vector<Process*> all_processes();
enum Priority {
enum Priority
{
IdlePriority,
LowPriority,
NormalPriority,
HighPriority,
};
enum RingLevel {
enum RingLevel
{
Ring0 = 0,
Ring3 = 3,
};
@ -83,10 +87,14 @@ public:
FileDescriptor* file_descriptor(int fd);
const FileDescriptor* file_descriptor(int fd) const;
template<typename Callback> static void for_each(Callback);
template<typename Callback> static void for_each_in_pgrp(pid_t, Callback);
template<typename Callback> void for_each_child(Callback);
template<typename Callback> void for_each_thread(Callback) const;
template<typename Callback>
static void for_each(Callback);
template<typename Callback>
static void for_each_in_pgrp(pid_t, Callback);
template<typename Callback>
void for_each_child(Callback);
template<typename Callback>
void for_each_thread(Callback) const;
void die();
void finalize();
@ -179,7 +187,7 @@ public:
int sys$getsockname(int sockfd, sockaddr* addr, socklen_t* addrlen);
int sys$getpeername(int sockfd, sockaddr* addr, socklen_t* addrlen);
int sys$restore_signal_mask(dword mask);
int sys$create_thread(int(*)(void*), void*);
int sys$create_thread(int (*)(void*), void*);
void sys$exit_thread(int code);
int sys$rename(const char* oldpath, const char* newpath);
int sys$systrace(pid_t);
@ -216,8 +224,10 @@ public:
bool validate_read(const void*, ssize_t) const;
bool validate_write(void*, ssize_t) const;
bool validate_read_str(const char* str);
template<typename T> bool validate_read_typed(T* value, size_t count = 1) { return validate_read(value, sizeof(T) * count); }
template<typename T> bool validate_write_typed(T* value, size_t count = 1) { return validate_write(value, sizeof(T) * count); }
template<typename T>
bool validate_read_typed(T* value, size_t count = 1) { return validate_read(value, sizeof(T) * count); }
template<typename T>
bool validate_write_typed(T* value, size_t count = 1) { return validate_write(value, sizeof(T) * count); }
Inode& cwd_inode();
Inode* executable_inode() { return m_executable.ptr(); }
@ -365,6 +375,7 @@ public:
Process* operator->() { return &m_process; }
Process& operator*() { return m_process; }
private:
Process& m_process;
};

View file

@ -1,7 +1,7 @@
#pragma once
#include <Kernel/File.h>
#include <AK/CircularQueue.h>
#include <Kernel/File.h>
#include <Kernel/UnixTypes.h>
class ProcessTracer : public File {

View file

@ -10,4 +10,3 @@ time_t boot_time();
void read_registers(unsigned& year, unsigned& month, unsigned& day, unsigned& hour, unsigned& minute, unsigned& second);
}

View file

@ -26,6 +26,7 @@ public:
static Process* colonel();
static bool is_active();
static void beep();
private:
static void prepare_for_iret_to_new_process();
};

View file

@ -1,11 +1,11 @@
#pragma once
#include <AK/Retainable.h>
#include <AK/RetainPtr.h>
#include <AK/AKString.h>
#include <AK/RetainPtr.h>
#include <AK/Retainable.h>
#include <Kernel/File.h>
#include <Kernel/KResult.h>
#include <Kernel/UnixTypes.h>
#include <Kernel/File.h>
class VMObject;

View file

@ -12,12 +12,11 @@ char* strncpy(char*, const char*, size_t);
int strcmp(char const*, const char*);
size_t strlen(const char*);
void* memset(void*, int, size_t);
char *strdup(const char*);
char* strdup(const char*);
int memcmp(const void*, const void*, size_t);
char* strrchr(const char* str, int ch);
void* memmove(void* dest, const void* src, size_t n);
inline word ntohs(word w) { return (w & 0xff) << 8 | ((w >> 8) & 0xff); }
inline word htons(word w) { return (w & 0xff) << 8 | ((w >> 8) & 0xff); }
}

View file

@ -3,116 +3,116 @@
#include <AK/Types.h>
#include <LibC/fd_set.h>
#define ENUMERATE_SYSCALLS \
__ENUMERATE_SYSCALL(sleep) \
__ENUMERATE_SYSCALL(yield) \
__ENUMERATE_SYSCALL(putch) \
__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(waitpid) \
__ENUMERATE_SYSCALL(mmap) \
__ENUMERATE_SYSCALL(munmap) \
__ENUMERATE_SYSCALL(get_dir_entries) \
__ENUMERATE_SYSCALL(lstat) \
__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(isatty) \
__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(read_tsc) \
__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(get_shared_buffer) \
__ENUMERATE_SYSCALL(release_shared_buffer) \
__ENUMERATE_SYSCALL(link) \
__ENUMERATE_SYSCALL(chown) \
__ENUMERATE_SYSCALL(fchmod) \
__ENUMERATE_SYSCALL(symlink) \
__ENUMERATE_SYSCALL(restore_signal_mask) \
#define ENUMERATE_SYSCALLS \
__ENUMERATE_SYSCALL(sleep) \
__ENUMERATE_SYSCALL(yield) \
__ENUMERATE_SYSCALL(putch) \
__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(waitpid) \
__ENUMERATE_SYSCALL(mmap) \
__ENUMERATE_SYSCALL(munmap) \
__ENUMERATE_SYSCALL(get_dir_entries) \
__ENUMERATE_SYSCALL(lstat) \
__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(isatty) \
__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(read_tsc) \
__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(get_shared_buffer) \
__ENUMERATE_SYSCALL(release_shared_buffer) \
__ENUMERATE_SYSCALL(link) \
__ENUMERATE_SYSCALL(chown) \
__ENUMERATE_SYSCALL(fchmod) \
__ENUMERATE_SYSCALL(symlink) \
__ENUMERATE_SYSCALL(restore_signal_mask) \
__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(shm_open) \
__ENUMERATE_SYSCALL(shm_close) \
__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(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(shm_open) \
__ENUMERATE_SYSCALL(shm_close) \
__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)
namespace Syscall {
enum Function {
enum Function
{
#undef __ENUMERATE_SYSCALL
#define __ENUMERATE_SYSCALL(x) SC_ ##x ,
#define __ENUMERATE_SYSCALL(x) SC_##x,
ENUMERATE_SYSCALLS
#undef __ENUMERATE_SYSCALL
};
@ -121,8 +121,10 @@ inline constexpr const char* to_string(Function function)
{
switch (function) {
#undef __ENUMERATE_SYSCALL
#define __ENUMERATE_SYSCALL(x) case SC_ ##x: return #x;
ENUMERATE_SYSCALLS
#define __ENUMERATE_SYSCALL(x) \
case SC_##x: \
return #x;
ENUMERATE_SYSCALLS
#undef __ENUMERATE_SYSCALL
}
return "Unknown";
@ -152,7 +154,7 @@ struct SC_sendto_params {
const void* data;
size_t data_length;
int flags;
const void* addr; // const sockaddr*
const void* addr; // const sockaddr*
size_t addr_length; // socklen_t
};
@ -161,7 +163,7 @@ struct SC_recvfrom_params {
void* buffer;
size_t buffer_length;
int flags;
void* addr; // sockaddr*
void* addr; // sockaddr*
void* addr_length; // socklen_t*
};
@ -187,7 +189,10 @@ int sync();
inline dword invoke(Function function)
{
dword result;
asm volatile("int $0x82":"=a"(result):"a"(function):"memory");
asm volatile("int $0x82"
: "=a"(result)
: "a"(function)
: "memory");
return result;
}
@ -195,7 +200,10 @@ template<typename T1>
inline dword invoke(Function function, T1 arg1)
{
dword result;
asm volatile("int $0x82":"=a"(result):"a"(function),"d"((dword)arg1):"memory");
asm volatile("int $0x82"
: "=a"(result)
: "a"(function), "d"((dword)arg1)
: "memory");
return result;
}
@ -203,7 +211,10 @@ template<typename T1, typename T2>
inline dword invoke(Function function, T1 arg1, T2 arg2)
{
dword result;
asm volatile("int $0x82":"=a"(result):"a"(function),"d"((dword)arg1),"c"((dword)arg2):"memory");
asm volatile("int $0x82"
: "=a"(result)
: "a"(function), "d"((dword)arg1), "c"((dword)arg2)
: "memory");
return result;
}
@ -211,7 +222,10 @@ template<typename T1, typename T2, typename T3>
inline dword invoke(Function function, T1 arg1, T2 arg2, T3 arg3)
{
dword result;
asm volatile("int $0x82":"=a"(result):"a"(function),"d"((dword)arg1),"c"((dword)arg2),"b"((dword)arg3):"memory");
asm volatile("int $0x82"
: "=a"(result)
: "a"(function), "d"((dword)arg1), "c"((dword)arg2), "b"((dword)arg3)
: "memory");
return result;
}
#endif
@ -219,7 +233,7 @@ inline dword invoke(Function function, T1 arg1, T2 arg2, T3 arg3)
}
#undef __ENUMERATE_SYSCALL
#define __ENUMERATE_SYSCALL(x) using Syscall::SC_ ##x;
ENUMERATE_SYSCALLS
#define __ENUMERATE_SYSCALL(x) using Syscall::SC_##x;
ENUMERATE_SYSCALLS
#undef __ENUMERATE_SYSCALL
#define syscall Syscall::invoke

View file

@ -1,7 +1,7 @@
#pragma once
#include <Kernel/Devices/CharacterDevice.h>
#include <AK/Badge.h>
#include <Kernel/Devices/CharacterDevice.h>
#include <Kernel/Lock.h>
class MasterPTY;

View file

@ -35,4 +35,3 @@ private:
InodeIdentifier m_devpts_inode_id;
String m_tty_name;
};

View file

@ -52,4 +52,3 @@ private:
unsigned short m_rows { 0 };
unsigned short m_columns { 0 };
};

View file

@ -1,13 +1,19 @@
#pragma once
#include <Kernel/TTY/TTY.h>
#include <Kernel/Devices/KeyboardDevice.h>
#include "Console.h"
#include <Kernel/Devices/KeyboardDevice.h>
#include <Kernel/TTY/TTY.h>
class VirtualConsole final : public TTY, public KeyboardClient, public ConsoleImplementation {
class VirtualConsole final : public TTY
, public KeyboardClient
, public ConsoleImplementation {
AK_MAKE_ETERNAL
public:
enum InitialContents { Cleared, AdoptCurrentVGABuffer };
enum InitialContents
{
Cleared,
AdoptCurrentVGABuffer
};
VirtualConsole(unsigned index, InitialContents = Cleared);
virtual ~VirtualConsole() override;
@ -67,7 +73,8 @@ private:
void execute_escape_sequence(byte final);
enum EscapeState {
enum EscapeState
{
Normal,
ExpectBracket,
ExpectParameter,

View file

@ -1,15 +1,15 @@
#pragma once
#include <Kernel/i386.h>
#include <Kernel/KResult.h>
#include <Kernel/LinearAddress.h>
#include <Kernel/UnixTypes.h>
#include <Kernel/VM/Region.h>
#include <AK/AKString.h>
#include <AK/InlineLinkedList.h>
#include <AK/OwnPtr.h>
#include <AK/RetainPtr.h>
#include <AK/Vector.h>
#include <Kernel/KResult.h>
#include <Kernel/LinearAddress.h>
#include <Kernel/UnixTypes.h>
#include <Kernel/VM/Region.h>
#include <Kernel/i386.h>
class Alarm;
class FileDescriptor;
@ -17,7 +17,11 @@ class Process;
class Region;
class Thread;
enum class ShouldUnblockThread { No = 0, Yes };
enum class ShouldUnblockThread
{
No = 0,
Yes
};
struct SignalActionData {
LinearAddress handler_or_sigaction;
@ -31,6 +35,7 @@ extern InlineLinkedList<Thread>* g_nonrunnable_threads;
class Thread : public InlineLinkedListNode<Thread> {
friend class Process;
friend class Scheduler;
public:
explicit Thread(Process&);
~Thread();
@ -49,7 +54,8 @@ public:
void finalize();
enum State : byte {
enum State : byte
{
Invalid = 0,
Runnable,
Running,
@ -136,11 +142,16 @@ public:
InlineLinkedList<Thread>* thread_list() { return m_thread_list; }
void set_thread_list(InlineLinkedList<Thread>*);
template<typename Callback> static void for_each_in_state(State, Callback);
template<typename Callback> static void for_each_living(Callback);
template<typename Callback> static void for_each_runnable(Callback);
template<typename Callback> static void for_each_nonrunnable(Callback);
template<typename Callback> static void for_each(Callback);
template<typename Callback>
static void for_each_in_state(State, Callback);
template<typename Callback>
static void for_each_living(Callback);
template<typename Callback>
static void for_each_runnable(Callback);
template<typename Callback>
static void for_each_nonrunnable(Callback);
template<typename Callback>
static void for_each(Callback);
static bool is_runnable_state(Thread::State state)
{

View file

@ -56,160 +56,160 @@
#define VEOL2 16
/* c_iflag bits */
#define IGNBRK 0000001
#define BRKINT 0000002
#define IGNPAR 0000004
#define PARMRK 0000010
#define INPCK 0000020
#define ISTRIP 0000040
#define INLCR 0000100
#define IGNCR 0000200
#define ICRNL 0000400
#define IUCLC 0001000
#define IXON 0002000
#define IXANY 0004000
#define IXOFF 0010000
#define IMAXBEL 0020000
#define IUTF8 0040000
#define IGNBRK 0000001
#define BRKINT 0000002
#define IGNPAR 0000004
#define PARMRK 0000010
#define INPCK 0000020
#define ISTRIP 0000040
#define INLCR 0000100
#define IGNCR 0000200
#define ICRNL 0000400
#define IUCLC 0001000
#define IXON 0002000
#define IXANY 0004000
#define IXOFF 0010000
#define IMAXBEL 0020000
#define IUTF8 0040000
/* c_oflag bits */
#define OPOST 0000001
#define OLCUC 0000002
#define ONLCR 0000004
#define OCRNL 0000010
#define ONOCR 0000020
#define ONLRET 0000040
#define OFILL 0000100
#define OFDEL 0000200
#define OPOST 0000001
#define OLCUC 0000002
#define ONLCR 0000004
#define OCRNL 0000010
#define ONOCR 0000020
#define ONLRET 0000040
#define OFILL 0000100
#define OFDEL 0000200
#if defined __USE_MISC || defined __USE_XOPEN
# define NLDLY 0000400
# define NL0 0000000
# define NL1 0000400
# define CRDLY 0003000
# define CR0 0000000
# define CR1 0001000
# define CR2 0002000
# define CR3 0003000
# define TABDLY 0014000
# define TAB0 0000000
# define TAB1 0004000
# define TAB2 0010000
# define TAB3 0014000
# define BSDLY 0020000
# define BS0 0000000
# define BS1 0020000
# define FFDLY 0100000
# define FF0 0000000
# define FF1 0100000
# define NLDLY 0000400
# define NL0 0000000
# define NL1 0000400
# define CRDLY 0003000
# define CR0 0000000
# define CR1 0001000
# define CR2 0002000
# define CR3 0003000
# define TABDLY 0014000
# define TAB0 0000000
# define TAB1 0004000
# define TAB2 0010000
# define TAB3 0014000
# define BSDLY 0020000
# define BS0 0000000
# define BS1 0020000
# define FFDLY 0100000
# define FF0 0000000
# define FF1 0100000
#endif
#define VTDLY 0040000
#define VT0 0000000
#define VT1 0040000
#define VTDLY 0040000
#define VT0 0000000
#define VT1 0040000
#ifdef __USE_MISC
# define XTABS 0014000
# define XTABS 0014000
#endif
/* c_cflag bit meaning */
#ifdef __USE_MISC
# define CBAUD 0010017
# define CBAUD 0010017
#endif
#define B0 0000000 /* hang up */
#define B50 0000001
#define B75 0000002
#define B110 0000003
#define B134 0000004
#define B150 0000005
#define B200 0000006
#define B300 0000007
#define B600 0000010
#define B1200 0000011
#define B1800 0000012
#define B2400 0000013
#define B4800 0000014
#define B9600 0000015
#define B19200 0000016
#define B38400 0000017
#define B0 0000000 /* hang up */
#define B50 0000001
#define B75 0000002
#define B110 0000003
#define B134 0000004
#define B150 0000005
#define B200 0000006
#define B300 0000007
#define B600 0000010
#define B1200 0000011
#define B1800 0000012
#define B2400 0000013
#define B4800 0000014
#define B9600 0000015
#define B19200 0000016
#define B38400 0000017
#ifdef __USE_MISC
# define EXTA B19200
# define EXTB B38400
# define EXTA B19200
# define EXTB B38400
#endif
#define CSIZE 0000060
#define CS5 0000000
#define CS6 0000020
#define CS7 0000040
#define CS8 0000060
#define CSTOPB 0000100
#define CREAD 0000200
#define PARENB 0000400
#define PARODD 0001000
#define HUPCL 0002000
#define CLOCAL 0004000
#define CSIZE 0000060
#define CS5 0000000
#define CS6 0000020
#define CS7 0000040
#define CS8 0000060
#define CSTOPB 0000100
#define CREAD 0000200
#define PARENB 0000400
#define PARODD 0001000
#define HUPCL 0002000
#define CLOCAL 0004000
#ifdef __USE_MISC
# define CBAUDEX 0010000
# define CBAUDEX 0010000
#endif
#define B57600 0010001
#define B115200 0010002
#define B230400 0010003
#define B460800 0010004
#define B500000 0010005
#define B576000 0010006
#define B921600 0010007
#define B1000000 0010010
#define B1152000 0010011
#define B1500000 0010012
#define B2000000 0010013
#define B2500000 0010014
#define B3000000 0010015
#define B3500000 0010016
#define B4000000 0010017
#define B57600 0010001
#define B115200 0010002
#define B230400 0010003
#define B460800 0010004
#define B500000 0010005
#define B576000 0010006
#define B921600 0010007
#define B1000000 0010010
#define B1152000 0010011
#define B1500000 0010012
#define B2000000 0010013
#define B2500000 0010014
#define B3000000 0010015
#define B3500000 0010016
#define B4000000 0010017
#define __MAX_BAUD B4000000
#ifdef __USE_MISC
# define CIBAUD 002003600000 /* input baud rate (not used) */
# define CMSPAR 010000000000 /* mark or space (stick) parity */
# define CRTSCTS 020000000000 /* flow control */
# define CIBAUD 002003600000 /* input baud rate (not used) */
# define CMSPAR 010000000000 /* mark or space (stick) parity */
# define CRTSCTS 020000000000 /* flow control */
#endif
/* c_lflag bits */
#define ISIG 0000001
#define ICANON 0000002
#define ISIG 0000001
#define ICANON 0000002
#if defined __USE_MISC || (defined __USE_XOPEN && !defined __USE_XOPEN2K)
# define XCASE 0000004
# define XCASE 0000004
#endif
#define ECHO 0000010
#define ECHOE 0000020
#define ECHOK 0000040
#define ECHONL 0000100
#define NOFLSH 0000200
#define TOSTOP 0000400
#define ECHO 0000010
#define ECHOE 0000020
#define ECHOK 0000040
#define ECHONL 0000100
#define NOFLSH 0000200
#define TOSTOP 0000400
#ifdef __USE_MISC
# define ECHOCTL 0001000
# define ECHOPRT 0002000
# define ECHOKE 0004000
# define FLUSHO 0010000
# define PENDIN 0040000
# define ECHOCTL 0001000
# define ECHOPRT 0002000
# define ECHOKE 0004000
# define FLUSHO 0010000
# define PENDIN 0040000
#endif
#define IEXTEN 0100000
#define IEXTEN 0100000
#ifdef __USE_MISC
# define EXTPROC 0200000
# define EXTPROC 0200000
#endif
/* tcflow() and TCXONC use these */
#define TCOOFF 0
#define TCOON 1
#define TCIOFF 2
#define TCION 3
#define TCOOFF 0
#define TCOON 1
#define TCIOFF 2
#define TCION 3
/* tcflush() and TCFLSH use these */
#define TCIFLUSH 0
#define TCOFLUSH 1
#define TCIOFLUSH 2
#define TCIFLUSH 0
#define TCOFLUSH 1
#define TCIOFLUSH 2
/* tcsetattr uses these */
#define TCSANOW 0
#define TCSADRAIN 1
#define TCSAFLUSH 2
#define TCSANOW 0
#define TCSADRAIN 1
#define TCSAFLUSH 2
struct winsize {
unsigned short ws_row;
@ -281,36 +281,36 @@ struct termios {
tcflag_t c_oflag;
tcflag_t c_cflag;
tcflag_t c_lflag;
cc_t c_cc[NCCS];
speed_t c_ispeed;
speed_t c_ospeed;
cc_t c_cc[NCCS];
speed_t c_ispeed;
speed_t c_ospeed;
};
struct stat {
dev_t st_dev; /* ID of device containing file */
ino_t st_ino; /* inode number */
mode_t st_mode; /* protection */
nlink_t st_nlink; /* number of hard links */
uid_t st_uid; /* user ID of owner */
gid_t st_gid; /* group ID of owner */
dev_t st_rdev; /* device ID (if special file) */
off_t st_size; /* total size, in bytes */
dev_t st_dev; /* ID of device containing file */
ino_t st_ino; /* inode number */
mode_t st_mode; /* protection */
nlink_t st_nlink; /* number of hard links */
uid_t st_uid; /* user ID of owner */
gid_t st_gid; /* group ID of owner */
dev_t st_rdev; /* device ID (if special file) */
off_t st_size; /* total size, in bytes */
blksize_t st_blksize; /* blocksize for file system I/O */
blkcnt_t st_blocks; /* number of 512B blocks allocated */
time_t st_atime; /* time of last access */
time_t st_mtime; /* time of last modification */
time_t st_ctime; /* time of last status change */
blkcnt_t st_blocks; /* number of 512B blocks allocated */
time_t st_atime; /* time of last access */
time_t st_mtime; /* time of last modification */
time_t st_ctime; /* time of last status change */
};
#define POLLIN (1u << 0)
#define POLLPRI (1u << 2)
#define POLLOUT (1u << 3)
#define POLLERR (1u << 4)
#define POLLHUP (1u << 5)
#define POLLIN (1u << 0)
#define POLLPRI (1u << 2)
#define POLLOUT (1u << 3)
#define POLLERR (1u << 4)
#define POLLHUP (1u << 5)
#define POLLNVAL (1u << 6)
struct pollfd {
int fd;
int fd;
short events;
short revents;
};
@ -345,7 +345,7 @@ struct sockaddr {
char sa_data[14];
};
#define S_IFSOCK 0140000
#define S_IFSOCK 0140000
#define UNIX_PATH_MAX 108
struct sockaddr_un {
@ -388,7 +388,8 @@ struct utsname {
char machine[UTSNAME_ENTRY_LEN];
};
struct [[gnu::packed]] FarPtr {
struct [[gnu::packed]] FarPtr
{
dword offset { 0 };
word selector { 0 };
};

View file

@ -1,27 +1,28 @@
#pragma once
#include <AK/Types.h>
#include "i386.h"
#include <AK/Bitmap.h>
#include <AK/ByteBuffer.h>
#include <AK/Retainable.h>
#include <AK/RetainPtr.h>
#include <AK/Vector.h>
#include <AK/HashTable.h>
#include <AK/AKString.h>
#include <AK/Badge.h>
#include <AK/Bitmap.h>
#include <AK/ByteBuffer.h>
#include <AK/HashTable.h>
#include <AK/RetainPtr.h>
#include <AK/Retainable.h>
#include <AK/Types.h>
#include <AK/Vector.h>
#include <AK/Weakable.h>
#include <Kernel/FileSystem/InodeIdentifier.h>
#include <Kernel/LinearAddress.h>
#include <Kernel/VM/PhysicalPage.h>
#include <Kernel/VM/Region.h>
#include <Kernel/VM/VMObject.h>
#include <Kernel/FileSystem/InodeIdentifier.h>
#define PAGE_ROUND_UP(x) ((((dword)(x)) + PAGE_SIZE-1) & (~(PAGE_SIZE-1)))
#define PAGE_ROUND_UP(x) ((((dword)(x)) + PAGE_SIZE - 1) & (~(PAGE_SIZE - 1)))
class SynthFSInode;
enum class PageFaultResponse {
enum class PageFaultResponse
{
ShouldCrash,
Continue,
};
@ -36,6 +37,7 @@ class MemoryManager {
friend class VMObject;
friend ByteBuffer procfs$mm(InodeIdentifier);
friend ByteBuffer procfs$memstat(InodeIdentifier);
public:
[[gnu::pure]] static MemoryManager& the();
@ -54,7 +56,11 @@ public:
bool validate_user_read(const Process&, LinearAddress) const;
bool validate_user_write(const Process&, LinearAddress) const;
enum class ShouldZeroFill { No, Yes };
enum class ShouldZeroFill
{
No,
Yes
};
RetainPtr<PhysicalPage> allocate_physical_page(ShouldZeroFill);
RetainPtr<PhysicalPage> allocate_supervisor_physical_page();
@ -106,7 +112,10 @@ private:
PageDirectory& kernel_page_directory() { return *m_kernel_page_directory; }
struct PageDirectoryEntry {
explicit PageDirectoryEntry(dword* pde) : m_pde(pde) { }
explicit PageDirectoryEntry(dword* pde)
: m_pde(pde)
{
}
dword* page_table_base() { return reinterpret_cast<dword*>(raw() & 0xfffff000u); }
void set_page_table_base(dword value)
@ -118,7 +127,8 @@ private:
dword raw() const { return *m_pde; }
dword* ptr() { return m_pde; }
enum Flags {
enum Flags
{
Present = 1 << 0,
ReadWrite = 1 << 1,
UserSupervisor = 1 << 2,
@ -153,7 +163,10 @@ private:
};
struct PageTableEntry {
explicit PageTableEntry(dword* pte) : m_pte(pte) { }
explicit PageTableEntry(dword* pte)
: m_pte(pte)
{
}
dword* physical_page_base() { return reinterpret_cast<dword*>(raw() & 0xfffff000u); }
void set_physical_page_base(dword value)
@ -165,7 +178,8 @@ private:
dword raw() const { return *m_pte; }
dword* ptr() { return m_pte; }
enum Flags {
enum Flags
{
Present = 1 << 0,
ReadWrite = 1 << 1,
UserSupervisor = 1 << 2,

View file

@ -1,13 +1,14 @@
#pragma once
#include <AK/HashMap.h>
#include <AK/RetainPtr.h>
#include <AK/Retainable.h>
#include <Kernel/VM/PhysicalPage.h>
#include <Kernel/VM/RangeAllocator.h>
#include <AK/HashMap.h>
#include <AK/Retainable.h>
#include <AK/RetainPtr.h>
class PageDirectory : public Retainable<PageDirectory> {
friend class MemoryManager;
public:
static Retained<PageDirectory> create_for_userspace(const RangeAllocator* parent_range_allocator = nullptr) { return adopt(*new PageDirectory(parent_range_allocator)); }
static Retained<PageDirectory> create_at_fixed_address(PhysicalAddress paddr) { return adopt(*new PageDirectory(paddr)); }

View file

@ -1,13 +1,14 @@
#pragma once
#include <AK/Retained.h>
#include <Kernel/Assertions.h>
#include <Kernel/PhysicalAddress.h>
#include <AK/Retained.h>
class PhysicalPage {
friend class MemoryManager;
friend class PageDirectory;
friend class VMObject;
public:
PhysicalAddress paddr() const { return m_paddr; }
@ -35,7 +36,7 @@ public:
private:
PhysicalPage(PhysicalAddress paddr, bool supervisor, bool may_return_to_freelist = true);
~PhysicalPage() { }
~PhysicalPage() {}
void return_to_freelist();

View file

@ -1,12 +1,13 @@
#pragma once
#include <Kernel/LinearAddress.h>
#include <AK/Vector.h>
#include <Kernel/LinearAddress.h>
class Range {
friend class RangeAllocator;
public:
Range() { }
Range() {}
Range(LinearAddress base, size_t size)
: m_base(base)
, m_size(size)

View file

@ -10,6 +10,7 @@ class VMObject;
class Region : public Retainable<Region> {
friend class MemoryManager;
public:
Region(const Range&, String&&, bool r, bool w, bool cow = false);
Region(const Range&, Retained<VMObject>&&, size_t offset_in_vmo, String&&, bool r, bool w, bool cow = false);

View file

@ -1,11 +1,11 @@
#pragma once
#include <AK/Badge.h>
#include <AK/Retainable.h>
#include <AK/Weakable.h>
#include <AK/RetainPtr.h>
#include <AK/Vector.h>
#include <AK/AKString.h>
#include <AK/Badge.h>
#include <AK/RetainPtr.h>
#include <AK/Retainable.h>
#include <AK/Vector.h>
#include <AK/Weakable.h>
#include <Kernel/Lock.h>
#include <Kernel/PhysicalAddress.h>
#include <Kernel/UnixTypes.h>
@ -13,8 +13,10 @@
class Inode;
class PhysicalPage;
class VMObject : public Retainable<VMObject>, public Weakable<VMObject> {
class VMObject : public Retainable<VMObject>
, public Weakable<VMObject> {
friend class MemoryManager;
public:
static Retained<VMObject> create_file_backed(RetainPtr<Inode>&&);
static Retained<VMObject> create_anonymous(size_t);
@ -46,7 +48,8 @@ private:
explicit VMObject(size_t);
VMObject(PhysicalAddress, size_t);
template<typename Callback> void for_each_region(Callback);
template<typename Callback>
void for_each_region(Callback);
String m_name;
bool m_allow_cpu_caching { true };

View file

@ -1,12 +1,13 @@
#pragma once
#include <Kernel/kstdio.h>
#include <Kernel/LinearAddress.h>
#include <Kernel/kstdio.h>
#define PAGE_SIZE 4096
#define PAGE_MASK 0xfffff000
struct [[gnu::packed]] TSS32 {
struct [[gnu::packed]] TSS32
{
word backlink, __blh;
dword esp0;
word ss0, __ss0h;
@ -15,7 +16,7 @@ struct [[gnu::packed]] TSS32 {
dword esp2;
word ss2, __ss2h;
dword cr3, eip, eflags;
dword eax,ecx,edx,ebx,esp,ebp,esi,edi;
dword eax, ecx, edx, ebx, esp, ebp, esi, edi;
word es, __esh;
word cs, __csh;
word ss, __ssh;
@ -26,7 +27,8 @@ struct [[gnu::packed]] TSS32 {
word trace, iomapbase;
};
union [[gnu::packed]] Descriptor {
union [[gnu::packed]] Descriptor
{
struct {
word limit_lo;
word base_lo;
@ -47,7 +49,8 @@ union [[gnu::packed]] Descriptor {
dword high;
};
enum Type {
enum Type
{
Invalid = 0,
AvailableTSS_16bit = 0x1,
LDT = 0x2,
@ -65,7 +68,7 @@ union [[gnu::packed]] Descriptor {
void set_base(void* b)
{
base_lo = (dword)(b) & 0xffff;
base_lo = (dword)(b)&0xffff;
base_hi = ((dword)(b) >> 16) & 0xff;
base_hi2 = ((dword)(b) >> 24) & 0xff;
}
@ -97,22 +100,27 @@ void write_gdt_entry(word selector, Descriptor&);
[[noreturn]] static inline void hang()
{
asm volatile("cli; hlt");
for (;;) { }
for (;;) {
}
}
#define LSW(x) ((dword)(x) & 0xFFFF)
#define LSW(x) ((dword)(x)&0xFFFF)
#define MSW(x) (((dword)(x) >> 16) & 0xFFFF)
#define LSB(x) ((x) & 0xFF)
#define MSB(x) (((x)>>8) & 0xFF)
#define LSB(x) ((x)&0xFF)
#define MSB(x) (((x) >> 8) & 0xFF)
#define cli() asm volatile("cli" ::: "memory")
#define sti() asm volatile("sti" ::: "memory")
#define memory_barrier() asm volatile ("" ::: "memory")
#define cli() asm volatile("cli" :: \
: "memory")
#define sti() asm volatile("sti" :: \
: "memory")
#define memory_barrier() asm volatile("" :: \
: "memory")
inline dword cpu_cr3()
{
dword cr3;
asm volatile("movl %%cr3, %%eax":"=a"(cr3));
asm volatile("movl %%cr3, %%eax"
: "=a"(cr3));
return cr3;
}
@ -122,8 +130,7 @@ inline dword cpu_flags()
asm volatile(
"pushf\n"
"pop %0\n"
:"=rm"(flags)
::"memory");
: "=rm"(flags)::"memory");
return flags;
}
@ -173,15 +180,16 @@ private:
#define IRQ_VECTOR_BASE 0x50
struct PageFaultFlags {
enum Flags {
NotPresent = 0x00,
ProtectionViolation = 0x01,
Read = 0x00,
Write = 0x02,
UserMode = 0x04,
SupervisorMode = 0x00,
InstructionFetch = 0x08,
};
enum Flags
{
NotPresent = 0x00,
ProtectionViolation = 0x01,
Read = 0x00,
Write = 0x02,
UserMode = 0x04,
SupervisorMode = 0x00,
InstructionFetch = 0x08,
};
};
class PageFault {
@ -208,7 +216,8 @@ private:
LinearAddress m_laddr;
};
struct [[gnu::packed]] RegisterDump {
struct [[gnu::packed]] RegisterDump
{
word ss;
word gs;
word fs;
@ -230,7 +239,8 @@ struct [[gnu::packed]] RegisterDump {
word ss_if_crossRing;
};
struct [[gnu::packed]] RegisterDumpWithExceptionCode {
struct [[gnu::packed]] RegisterDumpWithExceptionCode
{
word ss;
word gs;
word fs;
@ -254,7 +264,8 @@ struct [[gnu::packed]] RegisterDumpWithExceptionCode {
word ss_if_crossRing;
};
struct [[gnu::aligned(16)]] FPUState {
struct [[gnu::aligned(16)]] FPUState
{
byte buffer[512];
};
@ -265,11 +276,14 @@ inline constexpr dword page_base_of(dword address)
class CPUID {
public:
CPUID(dword function) { asm volatile("cpuid" : "=a" (m_eax), "=b" (m_ebx), "=c" (m_ecx), "=d" (m_edx) : "a" (function), "c" (0)); }
CPUID(dword function) { asm volatile("cpuid"
: "=a"(m_eax), "=b"(m_ebx), "=c"(m_ecx), "=d"(m_edx)
: "a"(function), "c"(0)); }
dword eax() const { return m_eax; }
dword ebx() const { return m_ebx; }
dword ecx() const { return m_ecx; }
dword edx() const { return m_edx; }
private:
dword m_eax { 0xffffffff };
dword m_ebx { 0xffffffff };
@ -279,7 +293,8 @@ private:
inline void read_tsc(dword& lsw, dword& msw)
{
asm volatile("rdtsc":"=d"(msw),"=a"(lsw));
asm volatile("rdtsc"
: "=d"(msw), "=a"(lsw));
}
struct Stopwatch {
@ -290,6 +305,7 @@ struct Stopwatch {
};
uint64_t qw { 0 };
};
public:
Stopwatch(const char* name)
: m_name(name)

View file

@ -2,26 +2,26 @@
#include <AK/Types.h>
#define TICKS_PER_SECOND 1000
#define TICKS_PER_SECOND 1000
/* Timer related ports */
#define TIMER0_CTL 0x40
#define TIMER1_CTL 0x41
#define TIMER2_CTL 0x42
#define PIT_CTL 0x43
#define TIMER0_CTL 0x40
#define TIMER1_CTL 0x41
#define TIMER2_CTL 0x42
#define PIT_CTL 0x43
/* Building blocks for PIT_CTL */
#define TIMER0_SELECT 0x00
#define TIMER1_SELECT 0x40
#define TIMER2_SELECT 0x80
#define TIMER0_SELECT 0x00
#define TIMER1_SELECT 0x40
#define TIMER2_SELECT 0x80
#define MODE_COUNTDOWN 0x00
#define MODE_ONESHOT 0x02
#define MODE_RATE 0x04
#define MODE_SQUARE_WAVE 0x06
#define MODE_COUNTDOWN 0x00
#define MODE_ONESHOT 0x02
#define MODE_RATE 0x04
#define MODE_SQUARE_WAVE 0x06
#define WRITE_WORD 0x30
#define WRITE_WORD 0x30
#define BASE_FREQUENCY 1193182
#define BASE_FREQUENCY 1193182
namespace PIT {

View file

@ -1,11 +1,11 @@
#pragma once
extern "C" {
int dbgprintf(const char *fmt, ...);
int kprintf(const char *fmt, ...);
int ksprintf(char* buf, const char *fmt, ...);
int dbgprintf(const char* fmt, ...);
int kprintf(const char* fmt, ...);
int ksprintf(char* buf, const char* fmt, ...);
}
#ifndef USERLAND
#define printf dbgprintf
# define printf dbgprintf
#endif

View file

@ -38,6 +38,7 @@ build_targets="$build_targets ." # the kernel
for targ in $build_targets; do
echo "Building $targ"
#(cd "$targ" && find . -name "*.c" -o -name "*.cpp" -o -name "*.h" -exec clang-format -i {} \;)
$make_cmd -C "$targ" clean
$make_cmd -C "$targ"