diff --git a/Makefile b/Makefile index fde3019..8df3f4e 100644 --- a/Makefile +++ b/Makefile @@ -99,7 +99,7 @@ MANPAGES = ${MANPAGES_3} docs: ${MANPAGES} .c.o: - $(CC) -std=c99 -D_BSD_SOURCE -fPIC -DPIC ${CFLAGS} ${CPPFLAGS} -c -o $@ $< + $(CC) -std=gnu99 -D_BSD_SOURCE -fPIC -DPIC ${CFLAGS} ${CPPFLAGS} -c -o $@ $< .S.o: $(CC) -fPIC -DPIC -DLIBUCONTEXT_ASSEMBLY ${CFLAGS} ${CPPFLAGS} -c -o $@ $< @@ -181,18 +181,18 @@ check_libucontext_posix: test_libucontext_posix ${LIBUCONTEXT_POSIX_SONAME} env LD_LIBRARY_PATH=$(shell pwd) ./test_libucontext_posix test_libucontext_posix: test_libucontext_posix.c ${LIBUCONTEXT_POSIX_NAME} - $(CC) -std=c99 -D_BSD_SOURCE ${CFLAGS} ${CPPFLAGS} $@.c -o $@ -L. -lucontext + $(CC) -std=gnu99 -D_BSD_SOURCE ${CFLAGS} ${CPPFLAGS} $@.c -o $@ -L. -lucontext endif check: test_libucontext ${LIBUCONTEXT_SONAME} env LD_LIBRARY_PATH=$(shell pwd) ./test_libucontext test_libucontext: test_libucontext.c ${LIBUCONTEXT_NAME} - $(CC) -std=c99 -D_BSD_SOURCE ${CFLAGS} ${CPPFLAGS} $@.c -o $@ -L. -lucontext + $(CC) -std=gnu99 -D_BSD_SOURCE ${CFLAGS} ${CPPFLAGS} $@.c -o $@ -L. -lucontext examples: ${LIBUCONTEXT_EXAMPLES} examples/cooperative_threading: examples/cooperative_threading.c ${LIBUCONTEXT_NAME} - $(CC) -std=c99 -D_BSD_SOURCE ${CFLAGS} ${CPPFLAGS} $@.c -o $@ -L. -lucontext + $(CC) -std=gnu99 -D_BSD_SOURCE ${CFLAGS} ${CPPFLAGS} $@.c -o $@ -L. -lucontext ifeq ($(FREESTANDING),no) diff --git a/arch/sh/makecontext.c b/arch/sh/makecontext.c index b10665c..dafc1f9 100644 --- a/arch/sh/makecontext.c +++ b/arch/sh/makecontext.c @@ -37,12 +37,15 @@ libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(void), int arg ucp->uc_mcontext.sr = (libucontext_greg_t) sp; ucp->uc_mcontext.pr = (libucontext_greg_t) libucontext_trampoline; ucp->uc_mcontext.pc = (libucontext_greg_t) func; + ucp->uc_mcontext.gregs[8] = (libucontext_greg_t) ucp->uc_link; /* pass up to four args in r4-r7, rest on stack */ va_start(va, argc); + regp = &ucp->uc_mcontext.gregs[4]; + for (i = 0; i < argc && i < 4; i++) - ucp->uc_mcontext.gregs[4 + i] = va_arg(va, libucontext_greg_t); + *regp++ = va_arg(va, libucontext_greg_t); for (; i < argc; i++) *sp++ = va_arg(va, libucontext_greg_t); diff --git a/arch/sh/trampoline.c b/arch/sh/trampoline.c new file mode 100644 index 0000000..cd1b863 --- /dev/null +++ b/arch/sh/trampoline.c @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2020 Ariadne Conill + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * This software is provided 'as is' and without any warranty, express or + * implied. In no event shall the authors be liable for any damages arising + * from the use of this software. + */ + +#include +#include +#include "defs.h" + +void +libucontext_trampoline(void) +{ + libucontext_ucontext_t *uc_link; + + asm("mov r8, %0" : "=r" (uc_link)); + + if (uc_link == NULL) + exit(0); + + libucontext_setcontext(uc_link); +}