MOS Source Code
Loading...
Searching...
No Matches
mos_global.h File Reference
#include <mos/compiler.h>
#include <stddef.h>
+ Include dependency graph for mos_global.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MOS_STATIC_ASSERT   _Static_assert
 
#define __BEGIN_DECLS
 
#define __END_DECLS
 
#define __aligned(x)
 
#define __malloc   __attribute__((__malloc__))
 
#define __packed   __attribute__((__packed__))
 
#define __printf(a, b)
 
#define __pure   __attribute__((__pure__))
 
#define __section(S)
 
#define __maybe_unused   __attribute__((__unused__))
 
#define __used   __attribute__((__used__))
 
#define __nodiscard   __attribute__((__warn_unused_result__))
 
#define should_inline   __maybe_unused static inline
 
#define likely(x)
 
#define unlikely(x)
 
#define __types_compatible(a, b)
 
#define do_container_of(ptr, type, member)
 
#define container_of(ptr, type, member)
 
#define cast_to(value, valtype, desttype)
 
#define is_aligned(ptr, alignment)
 
#define GET_BIT(x, n)
 
#define MASK_BITS(value, width)
 
#define SET_BITS(bit, width, value)
 
#define MOS_STRINGIFY2(x)
 
#define MOS_STRINGIFY(x)
 
#define MOS_UNUSED(x)
 
#define MOS_CONCAT_INNER(a, b)
 
#define MOS_CONCAT(a, b)
 
#define MOS_WARNING_PUSH   MOS_PRAGMA(diagnostic push)
 
#define MOS_WARNING_POP   MOS_PRAGMA(diagnostic pop)
 
#define MOS_WARNING_DISABLE(text)
 
#define ALIGN_UP(addr, size)
 
#define ALIGN_DOWN(addr, size)
 
#define ALIGN_UP_TO_PAGE(addr)
 
#define ALIGN_DOWN_TO_PAGE(addr)
 
#define MOS_IN_RANGE(addr, start, end)
 
#define MOS_FOURCC(a, b, c, d)
 
#define MOS_ARRAY_SIZE(x)
 
#define MOS_MAX_VADDR   ((ptr_t) ~0)
 
#define READ_ONCE(x)
 
#define KB   * 1024
 
#define MB   * 1024 KB
 
#define GB   * (u64) 1024 MB
 
#define TB   * (u64) 1024 GB
 
#define statement_expr(type, ...)
 
#define __NO_OP(...)
 
#define BIT(x)
 
#define MOSAPI   extern
 
#define MOS_CONFIG(feat)
 
#define MOS_DEBUG_FEATURE(feat)
 
#define once()
 Returns true for the first call, false for all subsequent calls.
 
#define MOS_PUT_IN_SECTION(_section, _struct, _var, ...)
 
#define IS_ERR_VALUE(x)
 
#define MOS_STUB_IMPL(...)
 
#define MOS_ENUM_OPERATORS(_enum)
 

Functions

 __attribute__ ((__warn_unused_result__)) __attribute__((__unused__)) static inlinevoid *ERR_PTR(long error)
 
 __attribute__ ((__deprecated__("reconsider if a NULL check is really required"))) __attribute__((__warn_unused_result__)) __attribute__((__unused__)) static inlinebool IS_ERR_OR_NULL(const void *ptr)
 

Macro Definition Documentation

◆ MOS_STATIC_ASSERT

#define MOS_STATIC_ASSERT   _Static_assert

Definition at line 14 of file mos_global.h.

◆ __BEGIN_DECLS

#define __BEGIN_DECLS

Definition at line 22 of file mos_global.h.

◆ __END_DECLS

#define __END_DECLS

Definition at line 23 of file mos_global.h.

◆ __aligned

#define __aligned ( x)
Value:
__attribute__((__aligned__(x)))
__attribute__((__warn_unused_result__)) __attribute__((__unused__)) static inlinevoid *ERR_PTR(long error)
Definition mos_global.h:128

Definition at line 27 of file mos_global.h.

◆ __malloc

#define __malloc   __attribute__((__malloc__))

Definition at line 28 of file mos_global.h.

◆ __packed

#define __packed   __attribute__((__packed__))

◆ __printf

#define __printf ( a,
b )
Value:
__attribute__((__format__(__printf__, a, b)))

Definition at line 30 of file mos_global.h.

◆ __pure

#define __pure   __attribute__((__pure__))

Definition at line 31 of file mos_global.h.

◆ __section

#define __section ( S)
Value:
__attribute__((__section__(S)))
#define S(x)

Definition at line 32 of file mos_global.h.

◆ __maybe_unused

#define __maybe_unused   __attribute__((__unused__))

Definition at line 33 of file mos_global.h.

◆ __used

#define __used   __attribute__((__used__))

Definition at line 34 of file mos_global.h.

◆ __nodiscard

#define __nodiscard   __attribute__((__warn_unused_result__))

Definition at line 35 of file mos_global.h.

◆ should_inline

#define should_inline   __maybe_unused static inline

Definition at line 37 of file mos_global.h.

◆ likely

#define likely ( x)
Value:
__builtin_expect(!!(x), 1)

Definition at line 39 of file mos_global.h.

Referenced by enter_scheduler(), mm_replace_page_locked(), process_allocate(), reschedule(), slab_alloc(), and userfs_ensure_connected().

◆ unlikely

◆ __types_compatible

#define __types_compatible ( a,
b )
Value:
__builtin_types_compatible_p(__typeof(a), __typeof(b))

Definition at line 42 of file mos_global.h.

◆ do_container_of

#define do_container_of ( ptr,
type,
member )
Value:
__extension__({ \
void *real_ptr = (void *) (ptr); \
_Static_assert(__types_compatible(*(ptr), ((type *) 0)->member) | __types_compatible(*(ptr), void), "type mismatch: (" #type ") vs (" #ptr "->" #member ")"); \
((type *) (real_ptr - offsetof(type, member))); \
})
#define __types_compatible(a, b)
Definition mos_global.h:42
#define offsetof(st, m)
Definition pb_syshdr.h:43

Definition at line 43 of file mos_global.h.

◆ container_of

◆ cast_to

◆ is_aligned

#define is_aligned ( ptr,
alignment )
Value:
(((ptr_t) ptr & (alignment - 1)) == 0)
unsigned long ptr_t
Definition types.h:25

Definition at line 55 of file mos_global.h.

Referenced by __ubsan_handle_type_mismatch(), platform_dump_stack(), slab_free(), and slab_realloc().

◆ GET_BIT

#define GET_BIT ( x,
n )
Value:
(((x) >> (n)) & 1)

Definition at line 57 of file mos_global.h.

◆ MASK_BITS

#define MASK_BITS ( value,
width )
Value:
((value) & ((1 << (width)) - 1))

Definition at line 58 of file mos_global.h.

Referenced by gdt_set_entry().

◆ SET_BITS

#define SET_BITS ( bit,
width,
value )
Value:
(MASK_BITS(value, width) << (bit))
#define MASK_BITS(value, width)
Definition mos_global.h:58

Definition at line 59 of file mos_global.h.

Referenced by lapic_interrupt_full().

◆ MOS_STRINGIFY2

#define MOS_STRINGIFY2 ( x)
Value:
#x

Definition at line 61 of file mos_global.h.

◆ MOS_STRINGIFY

#define MOS_STRINGIFY ( x)
Value:
#define MOS_STRINGIFY2(x)
Definition mos_global.h:61

Definition at line 62 of file mos_global.h.

◆ MOS_UNUSED

#define MOS_UNUSED ( x)
Value:
(void) (x)
MOSAPI void(1, 2) fatal_abort(const char *fmt

Definition at line 64 of file mos_global.h.

Referenced by __cxa_atexit(), _process_do_print(), _thread_do_print(), acpi_sysfs_munmap(), cmdline_dynamic_array_insert(), cow_zod_fault_handler(), create_idle_task(), dispatch_syscall(), dmabuf_free(), elf_determine_loadbias(), elf_do_fill_process(), get_ansi_color(), idle_task(), invalid_page_fault(), io_pselect(), ipc_dump_name_waitlist(), ipc_sysfs_create_server(), ipc_sysfs_list_ipcs(), ipc_sysfs_lookup_ipc(), mmstat_sysfs_phyframe_stat_store(), mmstat_sysfs_store_pid(), mos_test_engine_run_tests(), mutex_release(), operator delete(), operator delete[](), platform_ap_entry(), platform_arch_syscall(), platform_context_cleanup(), platform_dump_regs(), platform_dump_stack(), platform_dump_thread_kernel_stack(), platform_get_time(), platform_invalidate_tlb(), platform_ipi_send(), platform_jump_to_signal_handler(), platform_pml2e_set_pml1(), platform_pml2e_set_pml1(), platform_pml3e_set_pml2(), platform_pml3e_set_pml2(), platform_pml4e_set_pml3(), platform_pml4e_set_pml3(), platform_restore_from_signal_handler(), platform_syscall_setup_restart_context(), platform_syscall_store_retval(), pml1e_do_copy_callback(), pml1e_do_flag_callback(), pml1e_do_map_callback(), pml1e_do_mask_callback(), pml1e_do_unmap_callback(), pml2e_do_copy_callback(), pml2e_do_flag_callback(), pml2e_do_map_callback(), pml2e_do_unmap_callback(), pml3_entry(), pml3e_do_copy_callback(), pml3e_do_flag_callback(), pml3e_do_map_callback(), pml3e_do_unmap_callback(), pml4_entry(), pml4e_do_copy_callback(), pml4e_do_flag_callback(), pml4e_do_map_callback(), pml4e_do_unmap_callback(), pml5_entry(), pml5e_is_present(), process_do_execveat(), reschedule(), rtc_irq_handler(), sbi_console_clear(), sbi_console_get_color(), sbi_console_set_color(), sbi_console_write(), serial_console_irq_handler(), simple_flush_page_discard_data(), simple_page_write_begin(), simple_page_write_end(), stat_receiver(), sys_mem_mmap(), sys_mem_munmap(), sysfs_fops_mmap(), sysfs_fops_open(), test_foreach_function(), test_foreach_stop_at_quux(), thread_wait_for_tid(), timer_do_wakeup(), tmpfs_fill_cache(), tmpfs_i_hardlink(), tmpfs_i_rename(), tmpfs_i_rmdir(), tmpfs_i_unlink(), userfs_fop_open(), userfs_iop_hardlink(), userfs_iop_mkdir(), userfs_iop_mknode(), userfs_iop_rename(), userfs_iop_rmdir(), userfs_iop_symlink(), userfs_manager_server_exec(), vfs_do_open_dentry(), vfs_flusher_entry(), vfs_generic_inode_drop(), vfs_ipc_file_read(), vfs_ipc_file_write(), vfs_open_ipc(), vfs_simple_write_begin(), vfs_verify_permissions(), x86_keyboard_handler(), and x86_pit_timer_handler().

◆ MOS_CONCAT_INNER

#define MOS_CONCAT_INNER ( a,
b )
Value:
a##b

Definition at line 66 of file mos_global.h.

◆ MOS_CONCAT

#define MOS_CONCAT ( a,
b )
Value:
#define MOS_CONCAT_INNER(a, b)
Definition mos_global.h:66

Definition at line 67 of file mos_global.h.

◆ MOS_WARNING_PUSH

#define MOS_WARNING_PUSH   MOS_PRAGMA(diagnostic push)

Definition at line 69 of file mos_global.h.

Referenced by MOS_TEST_CASE(), MOS_TEST_CASE(), and MOS_TEST_CASE().

◆ MOS_WARNING_POP

#define MOS_WARNING_POP   MOS_PRAGMA(diagnostic pop)

Definition at line 70 of file mos_global.h.

Referenced by MOS_TEST_CASE(), MOS_TEST_CASE(), and MOS_TEST_CASE().

◆ MOS_WARNING_DISABLE

#define MOS_WARNING_DISABLE ( text)
Value:
MOS_PRAGMA(diagnostic ignored text)

Definition at line 71 of file mos_global.h.

Referenced by MOS_TEST_CASE(), MOS_TEST_CASE(), and MOS_TEST_CASE().

◆ ALIGN_UP

#define ALIGN_UP ( addr,
size )
Value:
(((addr) + (size - 1)) & ~(size - 1))
size_t size
Definition slab.c:30

Definition at line 73 of file mos_global.h.

Referenced by cpio_i_iterate_dir(), elf_setup_main_thread(), platform_startup_setup_kernel_mm(), slab_allocate_mem(), and x86_setup_direct_map().

◆ ALIGN_DOWN

#define ALIGN_DOWN ( addr,
size )
Value:
((addr) & ~(size - 1))

Definition at line 74 of file mos_global.h.

◆ ALIGN_UP_TO_PAGE

◆ ALIGN_DOWN_TO_PAGE

#define ALIGN_DOWN_TO_PAGE ( addr)

◆ MOS_IN_RANGE

#define MOS_IN_RANGE ( addr,
start,
end )
Value:
((addr) >= (start) && (addr) < (end))

Definition at line 78 of file mos_global.h.

Referenced by elf_do_fill_process(), mm_handle_fault(), and x86_handle_exception().

◆ MOS_FOURCC

#define MOS_FOURCC ( a,
b,
c,
d )
Value:
((u32) (a) | ((u32) (b) << 8) | ((u32) (c) << 16) | ((u32) (d) << 24))
unsigned int u32
Definition types.h:21

Definition at line 80 of file mos_global.h.

◆ MOS_ARRAY_SIZE

#define MOS_ARRAY_SIZE ( x)

◆ MOS_MAX_VADDR

#define MOS_MAX_VADDR   ((ptr_t) ~0)

Definition at line 83 of file mos_global.h.

◆ READ_ONCE

#define READ_ONCE ( x)
Value:
(*(volatile typeof(x) *) &(x))
typeof(x86_cpu_descriptor)
Definition descriptors.c:10

Definition at line 85 of file mos_global.h.

Referenced by riscv64_serial_read_register().

◆ KB

#define KB   * 1024

Definition at line 88 of file mos_global.h.

Referenced by invalid_page_fault(), limine_entry(), and x86_dump_stack_at().

◆ MB

#define MB   * 1024 KB

◆ GB

#define GB   * (u64) 1024 MB

Definition at line 90 of file mos_global.h.

Referenced by platform_startup_setup_kernel_mm(), and x86_setup_direct_map().

◆ TB

#define TB   * (u64) 1024 GB

Definition at line 91 of file mos_global.h.

◆ statement_expr

#define statement_expr ( type,
... )
Value:
__extension__({ type retval; __VA_ARGS__; retval; })

Definition at line 92 of file mos_global.h.

Referenced by dentry_resolve_to_parent(), pipeio_io_close(), platform_switch_to_thread(), and reschedule().

◆ __NO_OP

#define __NO_OP ( ...)

Definition at line 95 of file mos_global.h.

◆ BIT

#define BIT ( x)
Value:
(1ull << (x))

Definition at line 97 of file mos_global.h.

Referenced by lapic_wait_sent(), riscv64_trap_handler(), x86_cpu_initialise_caps(), and x86_cpu_setup_xsave_area().

◆ MOSAPI

#define MOSAPI   extern

Definition at line 102 of file mos_global.h.

◆ MOS_CONFIG

#define MOS_CONFIG ( feat)
Value:
(1 / feat == 1)

Definition at line 107 of file mos_global.h.

◆ MOS_DEBUG_FEATURE

#define MOS_DEBUG_FEATURE ( feat)
Value:
MOS_CONFIG(MOS_CONCAT(MOS_DEBUG_, feat))
#define MOS_CONCAT(a, b)
Definition mos_global.h:67
#define MOS_CONFIG(feat)
Definition mos_global.h:107

Definition at line 109 of file mos_global.h.

◆ once

#define once ( )
Value:
__extension__({ \
static bool __seen = false; \
bool ret = false; \
if (__seen) \
ret = false; \
else \
__seen = true, ret = true; \
ret; \
})

Returns true for the first call, false for all subsequent calls.

Definition at line 114 of file mos_global.h.

Referenced by lapic_enable(), print_to_console(), and try_handle_kernel_panics_at().

◆ MOS_PUT_IN_SECTION

#define MOS_PUT_IN_SECTION ( _section,
_struct,
_var,
... )
Value:
static const _struct _var __used __section(_section) = __VA_ARGS__
#define __used
Definition mos_global.h:34
#define __section(S)
Definition mos_global.h:32

Definition at line 125 of file mos_global.h.

◆ IS_ERR_VALUE

#define IS_ERR_VALUE ( x)

◆ MOS_STUB_IMPL

#define MOS_STUB_IMPL ( ...)
Value:
MOS_WARNING_PUSH \
MOS_WARNING_DISABLE("-Wunused-parameter") \
__VA_ARGS__ \
{ \
MOS_UNREACHABLE_X("unimplemented: file %s, line %d", __FILE__, __LINE__); \
} \
#define MOS_WARNING_POP
Definition mos_global.h:70

Definition at line 153 of file mos_global.h.

◆ MOS_ENUM_OPERATORS

#define MOS_ENUM_OPERATORS ( _enum)

Definition at line 173 of file mos_global.h.

Function Documentation

◆ __attribute__() [1/2]

__attribute__ ( (__warn_unused_result__) )

Definition at line 128 of file mos_global.h.

◆ __attribute__() [2/2]

__attribute__ ( (__deprecated__("reconsider if a NULL check is really required")) ) const

Definition at line 148 of file mos_global.h.