From 022f7790db45ba61740b41a4807d9b7d2a732916 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 15 Feb 2019 12:30:48 +0100 Subject: [PATCH] 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. --- AK/Compiler.h | 11 ----------- AK/Lock.h | 8 ++++---- AK/RetainPtr.h | 1 - AK/StdLibExtras.h | 4 ++-- AK/kmalloc.h | 9 +++------ AK/printf.cpp | 14 +++++++------- Applications/Terminal/Terminal.cpp | 7 +++---- Kernel/Console.h | 3 +-- Kernel/DevPtsFS.h | 2 +- Kernel/KSyms.cpp | 4 ++-- Kernel/KSyms.h | 2 +- Kernel/Keyboard.h | 2 +- Kernel/MemoryManager.h | 2 +- Kernel/ProcFS.h | 2 +- Kernel/Process.h | 8 ++++---- Kernel/StdLib.cpp | 3 +-- Kernel/TSS.h | 4 ++-- Kernel/VirtualFileSystem.h | 2 +- Kernel/i386.cpp | 14 +++++++------- Kernel/i386.h | 19 ++++++++++++------- Kernel/init.cpp | 9 +++------ Kernel/kassert.h | 2 +- Kernel/kmalloc.cpp | 12 ++++-------- Kernel/kmalloc.h | 12 +++++++----- Kernel/kprintf.h | 2 -- Kernel/types.h | 8 ++------ LibC/assert.h | 2 +- LibC/ctype.h | 14 +++++++------- LibC/dirent.cpp | 4 ++-- LibC/entry.cpp | 15 +++++++++------ LibC/stdlib.h | 10 +++++----- LibC/sys/cdefs.h | 4 ---- SharedGraphics/Font.cpp | 4 ++-- SharedGraphics/Painter.cpp | 4 ++-- 34 files changed, 99 insertions(+), 124 deletions(-) delete mode 100644 AK/Compiler.h diff --git a/AK/Compiler.h b/AK/Compiler.h deleted file mode 100644 index 78e43498e76..00000000000 --- a/AK/Compiler.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#define PACKED __attribute__ ((packed)) -#define NORETURN __attribute__ ((noreturn)) -#define FLATTEN __attribute__ ((flatten)) -#undef ALWAYS_INLINE -#define ALWAYS_INLINE inline __attribute__ ((always_inline)) -#define NEVER_INLINE __attribute__ ((noinline)) -#define MALLOC_ATTR __attribute__ ((malloc)) -#define PURE __attribute__ ((pure)) -#define WARN_UNUSED_RESULT __attribute__ ((warn_unused_result)) diff --git a/AK/Lock.h b/AK/Lock.h index da5a2e1de99..d5ebaf6041e 100644 --- a/AK/Lock.h +++ b/AK/Lock.h @@ -44,10 +44,10 @@ private: class Locker { public: - ALWAYS_INLINE explicit Locker(Lock& l) : m_lock(l) { lock(); } - ALWAYS_INLINE ~Locker() { unlock(); } - ALWAYS_INLINE void unlock() { m_lock.unlock(); } - ALWAYS_INLINE void lock() { m_lock.lock(); } + [[gnu::always_inline]] explicit Locker(Lock& l) : m_lock(l) { lock(); } + [[gnu::always_inline]] ~Locker() { unlock(); } + [[gnu::always_inline]] void unlock() { m_lock.unlock(); } + [[gnu::always_inline]] void lock() { m_lock.lock(); } private: Lock& m_lock; diff --git a/AK/RetainPtr.h b/AK/RetainPtr.h index b98278ccee2..4a831276e3a 100644 --- a/AK/RetainPtr.h +++ b/AK/RetainPtr.h @@ -1,6 +1,5 @@ #pragma once -#include "Compiler.h" #include "Types.h" namespace AK { diff --git a/AK/StdLibExtras.h b/AK/StdLibExtras.h index b5e7515d291..d4a03a95d51 100644 --- a/AK/StdLibExtras.h +++ b/AK/StdLibExtras.h @@ -11,7 +11,7 @@ void* mmx_memcpy(void* to, const void* from, size_t); -ALWAYS_INLINE void fast_dword_copy(dword* dest, const dword* src, size_t count) +[[gnu::always_inline]] inline void fast_dword_copy(dword* dest, const dword* src, size_t count) { if (count >= 256) { mmx_memcpy(dest, src, count * sizeof(count)); @@ -25,7 +25,7 @@ ALWAYS_INLINE void fast_dword_copy(dword* dest, const dword* src, size_t count) ); } -ALWAYS_INLINE void fast_dword_fill(dword* dest, dword value, size_t count) +[[gnu::always_inline]] inline void fast_dword_fill(dword* dest, dword value, size_t count) { asm volatile( "rep stosl\n" diff --git a/AK/kmalloc.h b/AK/kmalloc.h index 3c8102c0fd4..f02e591dfdf 100644 --- a/AK/kmalloc.h +++ b/AK/kmalloc.h @@ -1,7 +1,5 @@ #pragma once -#include "Compiler.h" - #if defined(SERENITY) && defined(KERNEL) #define AK_MAKE_ETERNAL \ public: \ @@ -18,11 +16,10 @@ private: extern "C" { -void* kcalloc(size_t nmemb, size_t size); -void* kmalloc(size_t size) MALLOC_ATTR; +[[gnu::malloc, gnu::returns_nonnull]] void* kmalloc(size_t size); +[[gnu::malloc, gnu::returns_nonnull]] void* kmalloc_eternal(size_t); +[[gnu::returns_nonnull]] void* krealloc(void* ptr, size_t size); void kfree(void* ptr); -void* krealloc(void* ptr, size_t size); -void* kmalloc_eternal(size_t) MALLOC_ATTR; } diff --git a/AK/printf.cpp b/AK/printf.cpp index b40ee07ca7c..831ab411694 100644 --- a/AK/printf.cpp +++ b/AK/printf.cpp @@ -2,7 +2,7 @@ typedef unsigned char byte; typedef unsigned short word; typedef unsigned int dword; -ALWAYS_INLINE size_t strlen(const char* str) +[[gnu::always_inline]] inline size_t strlen(const char* str) { size_t len = 0; while (*(str++)) @@ -13,7 +13,7 @@ ALWAYS_INLINE size_t strlen(const char* str) static constexpr const char* h = "0123456789abcdef"; template -ALWAYS_INLINE int print_hex(PutChFunc putch, char*& bufptr, dword number, byte fields) +[[gnu::always_inline]] int print_hex(PutChFunc putch, char*& bufptr, dword number, byte fields) { int ret = 0; byte shr_count = fields * 4; @@ -26,7 +26,7 @@ ALWAYS_INLINE int print_hex(PutChFunc putch, char*& bufptr, dword number, byte f } template -ALWAYS_INLINE int print_number(PutChFunc putch, char*& bufptr, dword number, bool leftPad, bool zeroPad, dword fieldWidth) +[[gnu::always_inline]] int print_number(PutChFunc putch, char*& bufptr, dword number, bool leftPad, bool zeroPad, dword fieldWidth) { dword divisor = 1000000000; char ch; @@ -67,7 +67,7 @@ ALWAYS_INLINE int print_number(PutChFunc putch, char*& bufptr, dword number, boo } template -ALWAYS_INLINE int print_octal_number(PutChFunc putch, char*& bufptr, dword number, bool leftPad, bool zeroPad, dword fieldWidth) +[[gnu::always_inline]] int print_octal_number(PutChFunc putch, char*& bufptr, dword number, bool leftPad, bool zeroPad, dword fieldWidth) { dword divisor = 134217728; char ch; @@ -108,7 +108,7 @@ ALWAYS_INLINE int print_octal_number(PutChFunc putch, char*& bufptr, dword numbe } template -ALWAYS_INLINE int print_string(PutChFunc putch, char*& bufptr, const char* str, bool leftPad, dword fieldWidth) +[[gnu::always_inline]] int print_string(PutChFunc putch, char*& bufptr, const char* str, bool leftPad, dword fieldWidth) { size_t len = strlen(str); if (!fieldWidth || fieldWidth < len) @@ -129,7 +129,7 @@ ALWAYS_INLINE int print_string(PutChFunc putch, char*& bufptr, const char* str, template -ALWAYS_INLINE int print_signed_number(PutChFunc putch, char*& bufptr, int number, bool leftPad, bool zeroPad, dword fieldWidth) +[[gnu::always_inline]] int print_signed_number(PutChFunc putch, char*& bufptr, int number, bool leftPad, bool zeroPad, dword fieldWidth) { if (number < 0) { putch(bufptr, '-'); @@ -139,7 +139,7 @@ ALWAYS_INLINE int print_signed_number(PutChFunc putch, char*& bufptr, int number } template -ALWAYS_INLINE int printf_internal(PutChFunc putch, char* buffer, const char*& fmt, char*& ap) +[[gnu::always_inline]] int printf_internal(PutChFunc putch, char* buffer, const char*& fmt, char*& ap) { const char *p; diff --git a/Applications/Terminal/Terminal.cpp b/Applications/Terminal/Terminal.cpp index 3e169505f46..97b6ea5e6fc 100644 --- a/Applications/Terminal/Terminal.cpp +++ b/Applications/Terminal/Terminal.cpp @@ -481,27 +481,26 @@ void Terminal::on_char(byte ch) return; } m_escape_state = ExpectXtermFinal; - // fall through + [[fallthrough]]; case ExpectXtermFinal: m_escape_state = Normal; if (ch == '\007') execute_xterm_command(); return; - case ExpectParameter: if (is_valid_parameter_character(ch)) { m_parameters.append(ch); return; } m_escape_state = ExpectIntermediate; - // fall through + [[fallthrough]]; case ExpectIntermediate: if (is_valid_intermediate_character(ch)) { m_intermediates.append(ch); return; } m_escape_state = ExpectFinal; - // fall through + [[fallthrough]]; case ExpectFinal: if (is_valid_final_character(ch)) { m_escape_state = Normal; diff --git a/Kernel/Console.h b/Kernel/Console.h index 4ef6a4684e4..2d3cc770098 100644 --- a/Kernel/Console.h +++ b/Kernel/Console.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include @@ -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; diff --git a/Kernel/DevPtsFS.h b/Kernel/DevPtsFS.h index 94587e00311..33a08f0c70c 100644 --- a/Kernel/DevPtsFS.h +++ b/Kernel/DevPtsFS.h @@ -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 create(); diff --git a/Kernel/KSyms.cpp b/Kernel/KSyms.cpp index 9bc26ddb8be..b5913b582c5 100644 --- a/Kernel/KSyms.cpp +++ b/Kernel/KSyms.cpp @@ -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 { diff --git a/Kernel/KSyms.h b/Kernel/KSyms.h index d0551c5307d..a7f8c33fa3b 100644 --- a/Kernel/KSyms.h +++ b/Kernel/KSyms.h @@ -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(); diff --git a/Kernel/Keyboard.h b/Kernel/Keyboard.h index 6cf580b8012..35bda981644 100644 --- a/Kernel/Keyboard.h +++ b/Kernel/Keyboard.h @@ -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(); diff --git a/Kernel/MemoryManager.h b/Kernel/MemoryManager.h index a7243d5b977..4cf90b3df87 100644 --- a/Kernel/MemoryManager.h +++ b/Kernel/MemoryManager.h @@ -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(); diff --git a/Kernel/ProcFS.h b/Kernel/ProcFS.h index 9c5591bff00..c57e08fdd15 100644 --- a/Kernel/ProcFS.h +++ b/Kernel/ProcFS.h @@ -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 create(); diff --git a/Kernel/Process.h b/Kernel/Process.h index f030acdf24a..66c75289667 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -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; } diff --git a/Kernel/StdLib.cpp b/Kernel/StdLib.cpp index 87e1df05066..03c02e0ae92 100644 --- a/Kernel/StdLib.cpp +++ b/Kernel/StdLib.cpp @@ -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(); } diff --git a/Kernel/TSS.h b/Kernel/TSS.h index 676750e454b..f3e370439e7 100644 --- a/Kernel/TSS.h +++ b/Kernel/TSS.h @@ -2,7 +2,7 @@ #include -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; +}; diff --git a/Kernel/VirtualFileSystem.h b/Kernel/VirtualFileSystem.h index 6c3fe71c408..7887005c735 100644 --- a/Kernel/VirtualFileSystem.h +++ b/Kernel/VirtualFileSystem.h @@ -54,7 +54,7 @@ public: RetainPtr m_guest_fs; }; - static VFS& the() PURE; + [[gnu::pure]] static VFS& the(); VFS(); ~VFS(); diff --git a/Kernel/i386.cpp b/Kernel/i386.cpp index 1336b8aa11d..ccf27c9f331 100644 --- a/Kernel/i386.cpp +++ b/Kernel/i386.cpp @@ -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) diff --git a/Kernel/i386.h b/Kernel/i386.h index bede94a97cc..4dc56620d4a 100644 --- a/Kernel/i386.h +++ b/Kernel/i386.h @@ -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; diff --git a/Kernel/init.cpp b/Kernel/init.cpp index 632c00b2f41..2c68fc80bdd 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -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(); diff --git a/Kernel/kassert.h b/Kernel/kassert.h index f799f90c727..774afe2a629 100644 --- a/Kernel/kassert.h +++ b/Kernel/kassert.h @@ -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(expr) ? (void)0 : __assertion_failed(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__)) #define CRASH() do { asm volatile("ud2"); } while(0) diff --git a/Kernel/kmalloc.cpp b/Kernel/kmalloc.cpp index a61a1b48a0e..24479144590 100644 --- a/Kernel/kmalloc.cpp +++ b/Kernel/kmalloc.cpp @@ -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) diff --git a/Kernel/kmalloc.h b/Kernel/kmalloc.h index 82c47e33543..19e9fb96446 100644 --- a/Kernel/kmalloc.h +++ b/Kernel/kmalloc.h @@ -1,12 +1,14 @@ #pragma once +#include + //#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. diff --git a/Kernel/kprintf.h b/Kernel/kprintf.h index 2406b9c07dc..29c2d15bd4d 100644 --- a/Kernel/kprintf.h +++ b/Kernel/kprintf.h @@ -1,7 +1,5 @@ #pragma once -#include - extern "C" { int dbgprintf(const char *fmt, ...); int kprintf(const char *fmt, ...); diff --git a/Kernel/types.h b/Kernel/types.h index 45cd0bb45d0..efa5a319777 100644 --- a/Kernel/types.h +++ b/Kernel/types.h @@ -1,11 +1,7 @@ #pragma once -#include #include -#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: diff --git a/LibC/assert.h b/LibC/assert.h index 25ea654db61..36be4b57f02 100644 --- a/LibC/assert.h +++ b/LibC/assert.h @@ -4,7 +4,7 @@ __BEGIN_DECLS -void __assertion_failed(const char* msg, const char* file, unsigned line, const char* func) __attribute__ ((noreturn)); +[[noreturn]] void __assertion_failed(const char* msg, const char* file, unsigned line, const char* func); #define assert(expr) ((expr) ? (void)0 : __assertion_failed(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__)) #define CRASH() do { asm volatile("ud2"); } while(0) diff --git a/LibC/ctype.h b/LibC/ctype.h index 41178f5cb4a..f3ac9d22183 100644 --- a/LibC/ctype.h +++ b/LibC/ctype.h @@ -4,41 +4,41 @@ __BEGIN_DECLS -ALWAYS_INLINE int isascii(int ch) +[[gnu::always_inline]] inline int isascii(int ch) { return (ch & ~0x7f) == 0; } -ALWAYS_INLINE int isspace(int ch) +[[gnu::always_inline]] inline int isspace(int ch) { return ch == ' ' || ch == '\f' || ch == '\n' || ch == '\r' || ch == '\t' || ch == '\v'; } -ALWAYS_INLINE int islower(int c) +[[gnu::always_inline]] inline int islower(int c) { return c >= 'a' && c <= 'z'; } -ALWAYS_INLINE int isupper(int c) +[[gnu::always_inline]] inline int isupper(int c) { return c >= 'A' && c <= 'Z'; } -ALWAYS_INLINE int tolower(int c) +[[gnu::always_inline]] inline int tolower(int c) { if (isupper(c)) return c | 0x20; return c; } -ALWAYS_INLINE int toupper(int c) +[[gnu::always_inline]] inline int toupper(int c) { if (islower(c)) return c & ~0x20; return c; } -ALWAYS_INLINE int isdigit(int c) +[[gnu::always_inline]] inline int isdigit(int c) { return c >= '0' && c <= '9'; } diff --git a/LibC/dirent.cpp b/LibC/dirent.cpp index c511b9dad6d..ef1ec33bc21 100644 --- a/LibC/dirent.cpp +++ b/LibC/dirent.cpp @@ -35,7 +35,7 @@ int closedir(DIR* dirp) return rc; } -struct sys_dirent { +struct [[gnu::packed]] sys_dirent { ino_t ino; byte file_type; size_t namelen; @@ -44,7 +44,7 @@ struct sys_dirent { { return sizeof(ino_t) + sizeof(byte) + sizeof(size_t) + sizeof(char) * namelen; } -} __attribute__ ((packed)); +}; dirent* readdir(DIR* dirp) { diff --git a/LibC/entry.cpp b/LibC/entry.cpp index ec610296f98..591c85a9692 100644 --- a/LibC/entry.cpp +++ b/LibC/entry.cpp @@ -3,15 +3,17 @@ #include #include -extern "C" int main(int, char**); +extern "C" { + +int main(int, char**); int errno; char** environ; -extern "C" void __malloc_init(); -extern "C" void __stdio_init(); +void __malloc_init(); +void __stdio_init(); -extern "C" int _start() +int _start() { errno = 0; @@ -39,8 +41,9 @@ epilogue: return 20150614; } -extern "C" void __cxa_pure_virtual() NORETURN; -extern "C" void __cxa_pure_virtual() +[[noreturn]] void __cxa_pure_virtual() { ASSERT_NOT_REACHED(); } + +} diff --git a/LibC/stdlib.h b/LibC/stdlib.h index bc673b0a023..a07477008f5 100644 --- a/LibC/stdlib.h +++ b/LibC/stdlib.h @@ -9,16 +9,16 @@ __BEGIN_DECLS #define EXIT_FAILURE 1 #define MB_CUR_MAX 1 -void* malloc(size_t) __MALLOC; +[[gnu::malloc, gnu::returns_nonnull, gnu::alloc_size(1)]] void* malloc(size_t); +[[gnu::malloc, gnu::returns_nonnull, gnu::alloc_size(1, 2)]] void* calloc(size_t nmemb, size_t); void free(void*); -void* calloc(size_t nmemb, size_t); -void* realloc(void *ptr, size_t); +[[gnu::returns_nonnull]] void* realloc(void *ptr, size_t); char* getenv(const char* name); int atoi(const char*); long atol(const char*); void qsort(void* base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)); -void exit(int status) __NORETURN; -void abort() __NORETURN; +[[noreturn]] void exit(int status); +[[noreturn]] void abort(); char* ptsname(int fd); int ptsname_r(int fd, char* buffer, size_t); int abs(int); diff --git a/LibC/sys/cdefs.h b/LibC/sys/cdefs.h index e26352ee82e..9fcd9b16825 100644 --- a/LibC/sys/cdefs.h +++ b/LibC/sys/cdefs.h @@ -2,10 +2,6 @@ #define _POSIX_VERSION 200809L -#define ALWAYS_INLINE inline __attribute__ ((always_inline)) -#define __NORETURN __attribute__ ((noreturn)) -#define __MALLOC __attribute__ ((malloc)) - #ifdef __cplusplus #define __BEGIN_DECLS extern "C" { #define __END_DECLS } diff --git a/SharedGraphics/Font.cpp b/SharedGraphics/Font.cpp index f5b29d5d040..7191ae0d305 100644 --- a/SharedGraphics/Font.cpp +++ b/SharedGraphics/Font.cpp @@ -36,14 +36,14 @@ static constexpr const char* error_glyph { static Font* s_default_font; static Font* s_default_bold_font; -struct FontFileHeader { +struct [[gnu::packed]] FontFileHeader { char magic[4]; byte glyph_width; byte glyph_height; byte type; byte unused[7]; char name[64]; -} PACKED; +}; static inline constexpr size_t font_file_size(unsigned glyph_height) { diff --git a/SharedGraphics/Painter.cpp b/SharedGraphics/Painter.cpp index e65ecbcbad6..1150fb50c31 100644 --- a/SharedGraphics/Painter.cpp +++ b/SharedGraphics/Painter.cpp @@ -291,7 +291,7 @@ void Painter::blit(const Point& position, const GraphicsBitmap& source, const Re } } -FLATTEN void Painter::draw_glyph(const Point& point, char ch, Color color) +[[gnu::flatten]] void Painter::draw_glyph(const Point& point, char ch, Color color) { draw_bitmap(point, font().glyph_bitmap(ch), color); } @@ -332,7 +332,7 @@ void Painter::set_pixel(const Point& p, Color color) m_target->scanline(point.y())[point.x()] = color.value(); } -ALWAYS_INLINE void Painter::set_pixel_with_draw_op(dword& pixel, const Color& color) +[[gnu::always_inline]] void Painter::set_pixel_with_draw_op(dword& pixel, const Color& color) { if (m_draw_op == DrawOp::Copy) pixel = color.value();