1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 11:27:35 +00:00

Use modern C++ attributes instead of __attribute__ voodoo.

This is quite nice, although I wish [[gnu::always_inline]] implied inline.
Also "gnu::" is kind of a wart, but whatcha gonna do.
This commit is contained in:
Andreas Kling 2019-02-15 12:30:48 +01:00
parent fbcc8ab840
commit 022f7790db
34 changed files with 99 additions and 124 deletions

View file

@ -1,7 +1,6 @@
#pragma once
#include <AK/CircularQueue.h>
#include <AK/Compiler.h>
#include <AK/Vector.h>
#include <Kernel/CharacterDevice.h>
@ -14,7 +13,7 @@ public:
class Console final : public CharacterDevice {
AK_MAKE_ETERNAL
public:
static Console& the() PURE;
static Console& the();
Console();
virtual ~Console() override;

View file

@ -8,7 +8,7 @@ class SlavePTY;
class DevPtsFS final : public SynthFS {
public:
static DevPtsFS& the() PURE;
[[gnu::pure]] static DevPtsFS& the();
virtual ~DevPtsFS() override;
static RetainPtr<DevPtsFS> create();

View file

@ -74,11 +74,11 @@ static void load_ksyms_from_data(const ByteBuffer& buffer)
void dump_backtrace(bool use_ksyms)
{
if (!current) {
HANG;
hang();
return;
}
if (use_ksyms && !ksyms_ready) {
HANG;
hang();
return;
}
struct RecognizedSymbol {

View file

@ -8,7 +8,7 @@ struct KSym {
const char* name;
};
const KSym* ksymbolicate(dword address) PURE;
const KSym* ksymbolicate(dword address);
void load_ksyms();
void init_ksyms();

View file

@ -29,7 +29,7 @@ public:
bool is_press() const { return flags & Is_Press; }
};
static Keyboard& the() PURE;
[[gnu::pure]] static Keyboard& the();
virtual ~Keyboard() override;
Keyboard();

View file

@ -217,7 +217,7 @@ class MemoryManager {
friend class VMObject;
friend ByteBuffer procfs$mm(InodeIdentifier);
public:
static MemoryManager& the() PURE;
[[gnu::pure]] static MemoryManager& the();
static void initialize();

View file

@ -11,7 +11,7 @@ class ProcFSInode;
class ProcFS final : public FS {
friend class ProcFSInode;
public:
static ProcFS& the() PURE;
[[gnu::pure]] static ProcFS& the();
virtual ~ProcFS() override;
static RetainPtr<ProcFS> create();

View file

@ -171,8 +171,8 @@ public:
int sys$lseek(int fd, off_t, int whence);
int sys$kill(pid_t pid, int sig);
int sys$geterror() { return m_error; }
void sys$exit(int status) NORETURN;
void sys$sigreturn() NORETURN;
[[noreturn]] void sys$exit(int status);
[[noreturn]] void sys$sigreturn();
pid_t sys$waitpid(pid_t, int* wstatus, int options);
void* sys$mmap(const Syscall::SC_mmap_params*);
int sys$munmap(void*, size_t size);
@ -230,8 +230,8 @@ public:
static void initialize();
void crash() NORETURN;
static int reap(Process&) WARN_UNUSED_RESULT;
[[noreturn]] void crash();
[[nodiscard]] static int reap(Process&);
const TTY* tty() const { return m_tty; }
void set_tty(TTY* tty) { m_tty = tty; }

View file

@ -125,8 +125,7 @@ int memcmp(const void* v1, const void* v2, size_t n)
return 0;
}
void __cxa_pure_virtual() NORETURN;
void __cxa_pure_virtual()
[[noreturn]] void __cxa_pure_virtual()
{
ASSERT_NOT_REACHED();
}

View file

@ -2,7 +2,7 @@
#include <AK/Types.h>
struct TSS32 {
struct [[gnu::packed]] TSS32 {
word backlink, __blh;
dword esp0;
word ss0, __ss0h;
@ -20,4 +20,4 @@ struct TSS32 {
word gs, __gsh;
word ldt, __ldth;
word trace, iomapbase;
} PACKED;
};

View file

@ -54,7 +54,7 @@ public:
RetainPtr<FS> m_guest_fs;
};
static VFS& the() PURE;
[[gnu::pure]] static VFS& the();
VFS();
~VFS();

View file

@ -10,10 +10,10 @@
//#define PAGE_FAULT_DEBUG
struct DescriptorTablePointer {
struct [[gnu::packed]] DescriptorTablePointer {
word size;
void* address;
} PACKED;
};
static DescriptorTablePointer s_idtr;
static DescriptorTablePointer s_gdtr;
@ -144,9 +144,9 @@ void exception_6_handler(RegisterDump& regs)
if (current->is_ring0()) {
kprintf("Oh shit, we've crashed in ring 0 :(\n");
HANG;
hang();
}
HANG;
hang();
current->crash();
}
@ -219,7 +219,7 @@ void exception_13_handler(RegisterDumpWithExceptionCode& regs)
if (current->is_ring0()) {
kprintf("Oh shit, we've crashed in ring 0 :(\n");
HANG;
hang();
}
current->crash();
@ -313,7 +313,7 @@ void exception_14_handler(RegisterDumpWithExceptionCode& regs)
asm ("movl %%cr3, %%eax":"=a"(cr3)); \
asm ("movl %%cr4, %%eax":"=a"(cr4)); \
kprintf("CR0=%x CR2=%x CR3=%x CR4=%x\n", cr0, cr2, cr3, cr4); \
HANG; \
hang(); \
}
EH(0, "Divide error")
@ -385,7 +385,7 @@ void gdt_init()
static void unimp_trap()
{
kprintf("Unhandled IRQ.");
HANG;
hang();
}
void register_irq_handler(byte irq, IRQHandler& handler)

View file

@ -6,7 +6,7 @@
#define PAGE_SIZE 4096
#define PAGE_MASK 0xfffff000
union Descriptor {
union [[gnu::packed]] Descriptor {
struct {
word limit_lo;
word base_lo;
@ -55,7 +55,7 @@ union Descriptor {
limit_lo = (dword)l & 0xffff;
limit_hi = ((dword)l >> 16) & 0xff;
}
} PACKED;
};
class IRQHandler;
@ -73,7 +73,12 @@ void gdt_free_entry(word);
Descriptor& get_gdt_entry(word selector);
void write_gdt_entry(word selector, Descriptor&);
#define HANG asm volatile( "cli; hlt" );
[[noreturn]] static inline void hang()
{
asm volatile("cli; hlt");
for (;;) { }
}
#define LSW(x) ((dword)(x) & 0xFFFF)
#define MSW(x) (((dword)(x) >> 16) & 0xFFFF)
#define LSB(x) ((x) & 0xFF)
@ -182,7 +187,7 @@ private:
LinearAddress m_laddr;
};
struct RegisterDump {
struct [[gnu::packed]] RegisterDump {
word ss;
word gs;
word fs;
@ -202,9 +207,9 @@ struct RegisterDump {
dword eflags;
dword esp_if_crossRing;
word ss_if_crossRing;
} PACKED;
};
struct RegisterDumpWithExceptionCode {
struct [[gnu::packed]] RegisterDumpWithExceptionCode {
word ss;
word gs;
word fs;
@ -226,7 +231,7 @@ struct RegisterDumpWithExceptionCode {
dword eflags;
dword esp_if_crossRing;
word ss_if_crossRing;
} PACKED;
};
struct FPUState {
dword cwd;

View file

@ -44,8 +44,7 @@ NullDevice* dev_null;
VFS* vfs;
#ifdef STRESS_TEST_SPAWNING
static void spawn_stress() NORETURN;
static void spawn_stress()
[[noreturn]] static void spawn_stress()
{
dword last_sum_alloc = sum_alloc;
@ -62,8 +61,7 @@ static void spawn_stress()
}
#endif
static void init_stage2() NORETURN;
static void init_stage2()
[[noreturn]] static void init_stage2()
{
Syscall::initialize();
@ -135,8 +133,7 @@ static void init_stage2()
ASSERT_NOT_REACHED();
}
void init() NORETURN;
void init()
[[noreturn]] void init()
{
cli();

View file

@ -3,7 +3,7 @@
#include "kprintf.h"
#include "i386.h"
void __assertion_failed(const char* msg, const char* file, unsigned line, const char* func) NORETURN;
[[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 CRASH() do { asm volatile("ud2"); } while(0)

View file

@ -14,11 +14,10 @@
#define SANITIZE_KMALLOC
typedef struct
{
struct [[gnu::packed]] allocation_t {
dword start;
dword nchunk;
} PACKED allocation_t;
};
#define CHUNK_SIZE 128
#define POOL_SIZE (1024 * 1024)
@ -103,8 +102,7 @@ void* kmalloc_impl(dword size)
if (sum_free < real_size) {
kprintf("%s<%u> kmalloc(): PANIC! Out of memory (sucks, dude)\nsum_free=%u, real_size=%x\n", current->name().characters(), current->pid(), sum_free, real_size);
HANG;
return 0L;
hang();
}
chunks_needed = real_size / CHUNK_SIZE;
@ -164,9 +162,7 @@ void* kmalloc_impl(dword size)
}
kprintf("%s<%u> kmalloc(): PANIC! Out of memory (no suitable block for size %u)\n", current->name().characters(), current->pid(), size);
HANG;
return nullptr;
hang();
}
void kfree(void *ptr)

View file

@ -1,12 +1,14 @@
#pragma once
#include <AK/Types.h>
//#define KMALLOC_DEBUG_LARGE_ALLOCATIONS
void kmalloc_init();
void* kmalloc_impl(dword size) __attribute__ ((malloc));
void* kmalloc_eternal(size_t) __attribute__ ((malloc));
void* kmalloc_page_aligned(size_t) __attribute__ ((malloc));
void* kmalloc_aligned(size_t, size_t alignment) __attribute__ ((malloc));
[[gnu::malloc, gnu::returns_nonnull, gnu::alloc_size(1)]] void* kmalloc_impl(size_t);
[[gnu::malloc, gnu::returns_nonnull, gnu::alloc_size(1)]] void* kmalloc_eternal(size_t);
[[gnu::malloc, gnu::returns_nonnull, gnu::alloc_size(1)]] void* kmalloc_page_aligned(size_t);
[[gnu::malloc, gnu::returns_nonnull, gnu::alloc_size(1)]] void* kmalloc_aligned(size_t, size_t alignment);
void kfree(void*);
void kfree_aligned(void*);
@ -20,7 +22,7 @@ extern volatile size_t kmalloc_sum_page_aligned;
inline void* operator new(size_t, void* p) { return p; }
inline void* operator new[](size_t, void* p) { return p; }
ALWAYS_INLINE void* kmalloc(size_t size)
[[gnu::always_inline]] inline void* kmalloc(size_t size)
{
#ifdef KMALLOC_DEBUG_LARGE_ALLOCATIONS
// Any kernel allocation >= 1M is 99.9% a bug.

View file

@ -1,7 +1,5 @@
#pragma once
#include <AK/Compiler.h>
extern "C" {
int dbgprintf(const char *fmt, ...);
int kprintf(const char *fmt, ...);

View file

@ -1,11 +1,7 @@
#pragma once
#include <AK/Compiler.h>
#include <AK/Types.h>
#define PACKED __attribute__ ((packed))
#define PURE __attribute__ ((pure))
typedef dword __u32;
typedef word __u16;
typedef byte __u8;
@ -43,10 +39,10 @@ typedef dword nlink_t;
typedef dword blksize_t;
typedef dword blkcnt_t;
struct FarPtr {
struct [[gnu::packed]] FarPtr {
dword offset { 0 };
word selector { 0 };
} PACKED;
};
class PhysicalAddress {
public: