Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ endif()

set(cflags)
set(priv_cflags)
set(warn_suppress)
set(defines)
set(ldflags)
set(asm_lang "ASM")
Expand All @@ -52,6 +53,23 @@ if(CMU_COMP_GNUC)
endif()
endif()

if(CMU_COMP_CLANG)
# applied after CMU_FLAGS_W4 (which enables -Weverything), warnings that do
# not apply to this code base:
list(
APPEND warn_suppress
# keep -Wno-* below working on clang versions that lack them
-Wno-unknown-warning-option
# we target C99, mixing declarations and code is intentional
-Wno-declaration-after-statement
# implementing fibers means doing raw pointer arithmetic on stacks
-Wno-unsafe-buffer-usage
# C++ compatibility warning triggered by hu_cxx_static_cast(), this
# translation unit is always compiled as C
-Wno-implicit-void-ptr-cast
)
endif()

if(FIBER_ASM_CHECK_ALIGNMENT)
list(APPEND defines "-DFIBER_ASM_CHECK_ALIGNMENT=1")
endif()
Expand Down Expand Up @@ -133,7 +151,8 @@ if(FIBER_LTO)
endif()

target_compile_options(fiber PUBLIC ${cflags})
target_compile_options(fiber PRIVATE ${priv_cflags} ${CMU_FLAGS_W4})
target_compile_options(fiber PRIVATE ${priv_cflags} ${CMU_FLAGS_W4}
${warn_suppress})

if(ldflags)
cmu_target_link_options(fiber PUBLIC ${ldflags})
Expand Down
2 changes: 1 addition & 1 deletion include/fiber/fiber_mach.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
void *lr; /* r30 */ \
void *fp; /* r29 */ \
void *r[10]; /* r19 - r28 */ \
double d[8]; /* d8 - d15 */
double d[8] /* d8 - d15 */

#elif HU_ARCH_RISCV_P && HU_OS_POSIX_P
# define FIBER_TARGET_RISCV_ELF 1
Expand Down
22 changes: 13 additions & 9 deletions src/fiber.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,21 @@ stack_align_n(char *sp, size_t n)
return (char *) ((uintptr_t) sp & ~(uintptr_t) (n - 1));
}

HU_MAYBE_UNUSED
bool
#ifndef NDEBUG
/* only used in assertions */
static inline bool
is_stack_aligned(void *sp)
{
return ((uintptr_t) sp & (STACK_ALIGNMENT - 1)) == 0;
}
#endif

static inline void
push(char **sp, void *val)
{
*sp -= WORD_SIZE;
*(void **) *sp = val;
/* sp is kept word aligned, cast via void * to silence -Wcast-align */
*(void **) (void *) *sp = val;
}

typedef struct
Expand Down Expand Up @@ -147,7 +150,7 @@ free_pages(void *p)

HU_CONST_FN
static size_t
get_page_size()
get_page_size(void)
{
static size_t PAGE_SIZE = 0;
size_t pgsz = PAGE_SIZE;
Expand Down Expand Up @@ -285,10 +288,10 @@ fiber_switch(Fiber *from, Fiber *to)
#if hu_has_attribute(weak)
# define HAVE_probe_stack_weak_dummy
__attribute__((weak)) void
_probe_stack_weak_dummy(volatile char *sp, size_t sz);
fiber_probe_stack_weak_dummy(volatile char *sp, size_t sz);

__attribute__((weak)) void
_probe_stack_weak_dummy(volatile char *sp, size_t sz)
fiber_probe_stack_weak_dummy(volatile char *sp, size_t sz)
{
(void) sp;
(void) sz;
Expand All @@ -305,13 +308,14 @@ probe_stack(volatile char *sp0, size_t sz, size_t pgsz)
#endif
size_t i = 0;
while (i < sz) {
*(volatile uintptr_t *) sp |= (uintptr_t) 0;
/* sp is page aligned, cast via void * to silence -Wcast-align */
*(volatile uintptr_t *) (volatile void *) sp |= (uintptr_t) 0;
i += pgsz;
sp -= pgsz;
}

#ifdef HAVE_probe_stack_weak_dummy
_probe_stack_weak_dummy(sp0, sz);
fiber_probe_stack_weak_dummy(sp0, sz);
#endif
}

Expand Down Expand Up @@ -368,7 +372,7 @@ fiber_exec_on(Fiber *active, Fiber *temp, FiberFunc f, void *args)
}

size_t
fiber_stack_alignment()
fiber_stack_alignment(void)
{
return STACK_ALIGNMENT;
}
Expand Down