summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-02-15 12:30:48 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-02-15 12:30:48 +0100
commit022f7790db45ba61740b41a4807d9b7d2a732916 (patch)
tree1fc8e5883e6beaac1e4d3d3bda1a22b94bd1e792
parentfbcc8ab840aaa212934da0082a039038c8a81e53 (diff)
downloadserenity-022f7790db45ba61740b41a4807d9b7d2a732916.zip
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.
-rw-r--r--AK/Compiler.h11
-rw-r--r--AK/Lock.h8
-rw-r--r--AK/RetainPtr.h1
-rw-r--r--AK/StdLibExtras.h4
-rw-r--r--AK/kmalloc.h9
-rw-r--r--AK/printf.cpp14
-rw-r--r--Applications/Terminal/Terminal.cpp7
-rw-r--r--Kernel/Console.h3
-rw-r--r--Kernel/DevPtsFS.h2
-rw-r--r--Kernel/KSyms.cpp4
-rw-r--r--Kernel/KSyms.h2
-rw-r--r--Kernel/Keyboard.h2
-rw-r--r--Kernel/MemoryManager.h2
-rw-r--r--Kernel/ProcFS.h2
-rw-r--r--Kernel/Process.h8
-rw-r--r--Kernel/StdLib.cpp3
-rw-r--r--Kernel/TSS.h4
-rw-r--r--Kernel/VirtualFileSystem.h2
-rw-r--r--Kernel/i386.cpp14
-rw-r--r--Kernel/i386.h19
-rw-r--r--Kernel/init.cpp9
-rw-r--r--Kernel/kassert.h2
-rw-r--r--Kernel/kmalloc.cpp12
-rw-r--r--Kernel/kmalloc.h12
-rw-r--r--Kernel/kprintf.h2
-rw-r--r--Kernel/types.h8
-rw-r--r--LibC/assert.h2
-rw-r--r--LibC/ctype.h14
-rw-r--r--LibC/dirent.cpp4
-rw-r--r--LibC/entry.cpp15
-rw-r--r--LibC/stdlib.h10
-rw-r--r--LibC/sys/cdefs.h4
-rw-r--r--SharedGraphics/Font.cpp4
-rw-r--r--SharedGraphics/Painter.cpp4
34 files changed, 99 insertions, 124 deletions
diff --git a/AK/Compiler.h b/AK/Compiler.h
deleted file mode 100644
index 78e43498e7..0000000000
--- 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 da5a2e1de9..d5ebaf6041 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 b98278ccee..4a831276e3 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 b5e7515d29..d4a03a95d5 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 3c8102c0fd..f02e591dfd 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 b40ee07ca7..831ab41169 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<typename PutChFunc>
-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<typename PutChFunc>
-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<typename PutChFunc>
-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<typename PutChFunc>
-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<typename PutChFunc>
-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<typename PutChFunc>
-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 3e169505f4..97b6ea5e6f 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 4ef6a4684e..2d3cc77009 100644
--- a/Kernel/Console.h
+++ b/Kernel/Console.h
@@ -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;
diff --git a/Kernel/DevPtsFS.h b/Kernel/DevPtsFS.h
index 94587e0031..33a08f0c70 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<DevPtsFS> create();
diff --git a/Kernel/KSyms.cpp b/Kernel/KSyms.cpp
index 9bc26ddb8b..b5913b582c 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 d0551c5307..a7f8c33fa3 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 6cf580b801..35bda98164 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 a7243d5b97..4cf90b3df8 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 9c5591bff0..c57e08fdd1 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<ProcFS> create();
diff --git a/Kernel/Process.h b/Kernel/Process.h
index f030acdf24..66c7528966 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 87e1df0506..03c02e0ae9 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 676750e454..f3e370439e 100644
--- a/Kernel/TSS.h
+++ b/Kernel/TSS.h
@@ -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;
+};
diff --git a/Kernel/VirtualFileSystem.h b/Kernel/VirtualFileSystem.h
index 6c3fe71c40..7887005c73 100644
--- a/Kernel/VirtualFileSystem.h
+++ b/Kernel/VirtualFileSystem.h
@@ -54,7 +54,7 @@ public:
RetainPtr<FS> 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 1336b8aa11..ccf27c9f33 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 bede94a97c..4dc56620d4 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 632c00b2f4..2c68fc80bd 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 f799f90c72..774afe2a62 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<bool>(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 a61a1b48a0..2447914459 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 82c47e3354..19e9fb9644 100644
--- a/Kernel/kmalloc.h
+++ b/Kernel/kmalloc.h
@@ -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.
diff --git a/Kernel/kprintf.h b/Kernel/kprintf.h
index 2406b9c07d..29c2d15bd4 100644
--- a/Kernel/kprintf.h
+++ b/Kernel/kprintf.h
@@ -1,7 +1,5 @@
#pragma once
-#include <AK/Compiler.h>
-
extern "C" {
int dbgprintf(const char *fmt, ...);
int kprintf(const char *fmt, ...);
diff --git a/Kernel/types.h b/Kernel/types.h
index 45cd0bb45d..efa5a31977 100644
--- a/Kernel/types.h
+++ b/Kernel/types.h
@@ -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:
diff --git a/LibC/assert.h b/LibC/assert.h
index 25ea654db6..36be4b57f0 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 41178f5cb4..f3ac9d2218 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 c511b9dad6..ef1ec33bc2 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 ec610296f9..591c85a969 100644
--- a/LibC/entry.cpp
+++ b/LibC/entry.cpp
@@ -3,15 +3,17 @@
#include <Kernel/Syscall.h>
#include <AK/StringImpl.h>
-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 bc673b0a02..a07477008f 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 e26352ee82..9fcd9b1682 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 f5b29d5d04..7191ae0d30 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 e65ecbcbad..1150fb50c3 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();