forked from ariadne/libucontext
sh: add remaining port files
parent
a42fb86da0
commit
da3c8d170f
8
Makefile
8
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)
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright (c) 2020 Ariadne Conill <ariadne@dereferenced.org>
|
||||
*
|
||||
* 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 <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#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);
|
||||
}
|
Loading…
Reference in New Issue