mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-14 01:04:38 +03: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:
parent
fbcc8ab840
commit
022f7790db
Notes:
sideshowbarker
2024-07-19 15:42:33 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/022f7790db4
@ -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))
|
@ -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;
|
||||
|
@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "Compiler.h"
|
||||
#include "Types.h"
|
||||
|
||||
namespace AK {
|
||||
|
@ -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"
|
||||
|
@ -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;
|
||||
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -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 {
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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; }
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -54,7 +54,7 @@ public:
|
||||
RetainPtr<FS> m_guest_fs;
|
||||
};
|
||||
|
||||
static VFS& the() PURE;
|
||||
[[gnu::pure]] static VFS& the();
|
||||
|
||||
VFS();
|
||||
~VFS();
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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.
|
||||
|
@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <AK/Compiler.h>
|
||||
|
||||
extern "C" {
|
||||
int dbgprintf(const char *fmt, ...);
|
||||
int kprintf(const char *fmt, ...);
|
||||
|
@ -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:
|
||||
|
@ -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)
|
||||
|
14
LibC/ctype.h
14
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';
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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 }
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user