2018-01-31 05:58:26 +00:00
|
|
|
ARCH := $(shell uname -m)
|
2019-09-18 14:54:53 +00:00
|
|
|
ifeq ($(ARCH),$(filter $(ARCH),i386 i686))
|
|
|
|
override ARCH = x86
|
|
|
|
endif
|
2018-01-30 03:41:02 +00:00
|
|
|
|
2020-03-30 08:21:20 +00:00
|
|
|
LIBDIR := /lib
|
2020-12-04 01:24:08 +00:00
|
|
|
CFLAGS := -ggdb3 -O2 -Wall
|
|
|
|
CPPFLAGS := -Iarch/${ARCH} -Iarch/common
|
2020-12-06 08:54:01 +00:00
|
|
|
EXPORT_UNPREFIXED := yes
|
2020-12-06 09:08:14 +00:00
|
|
|
FREESTANDING := no
|
|
|
|
|
|
|
|
ifeq ($(FREESTANDING),yes)
|
|
|
|
CFLAGS += -DFREESTANDING -isystem arch/${ARCH}/freestanding
|
|
|
|
EXPORT_UNPREFIXED = no
|
|
|
|
endif
|
2020-12-06 08:54:01 +00:00
|
|
|
|
|
|
|
ifeq ($(EXPORT_UNPREFIXED),yes)
|
|
|
|
CFLAGS += -DEXPORT_UNPREFIXED
|
|
|
|
endif
|
2018-01-30 03:41:02 +00:00
|
|
|
|
ppc32/64: rewrite get/set/swapcontext in assembly
getcontext cannot be correctly implemented in C.
If this calls another function, as it does to call syscall, it needs to
first spill its return address to the stack. If, after getcontext returns,
its caller then calls other functions, this saved return address can be
clobbered. When the context saved by getcontext is later restored, the
(now clobbered) return address will be reloaded from the stack, and the
second return from getcontext will return to the wrong location.
Because the powerpc swapcontext syscall allows either the old context or
new context pointers to be null, it is usable for implementing all of
get/set/swapcontext.
We therefore rewrite swapcontext in assembly, and get/setcontext as simple
assembly function wrappers around swapcontext.
The one piece we keep in C is the code to check the return value of the
system call and to set errno. This code was actually unnecessary before --
libc does this within syscall. However, now that the system call is made
directly in assembly, bypassing libc, it is truly necessary. Because errno
is thread-local and the details of how to set it can vary by libc, this
code remains written in C.
2019-02-23 23:12:37 +00:00
|
|
|
LIBUCONTEXT_C_SRC = $(wildcard arch/${ARCH}/*.c)
|
|
|
|
LIBUCONTEXT_S_SRC = $(wildcard arch/${ARCH}/*.S)
|
2018-01-29 21:50:49 +00:00
|
|
|
|
|
|
|
LIBUCONTEXT_OBJ = ${LIBUCONTEXT_C_SRC:.c=.o} ${LIBUCONTEXT_S_SRC:.S=.o}
|
|
|
|
LIBUCONTEXT_SOVERSION = 0
|
2018-01-30 03:53:04 +00:00
|
|
|
LIBUCONTEXT_NAME = libucontext.so
|
2019-04-09 13:07:39 +00:00
|
|
|
LIBUCONTEXT_STATIC_NAME = libucontext.a
|
2018-01-30 03:53:04 +00:00
|
|
|
LIBUCONTEXT_SONAME = libucontext.so.${LIBUCONTEXT_SOVERSION}
|
2020-03-30 08:21:20 +00:00
|
|
|
LIBUCONTEXT_PATH = ${LIBDIR}/${LIBUCONTEXT_SONAME}
|
|
|
|
LIBUCONTEXT_STATIC_PATH = ${LIBDIR}/${LIBUCONTEXT_STATIC_NAME}
|
2018-01-29 21:50:49 +00:00
|
|
|
|
2019-04-09 13:07:39 +00:00
|
|
|
all: ${LIBUCONTEXT_SONAME} ${LIBUCONTEXT_STATIC_NAME}
|
|
|
|
|
|
|
|
${LIBUCONTEXT_STATIC_NAME}: ${LIBUCONTEXT_OBJ}
|
|
|
|
$(AR) rcs ${LIBUCONTEXT_STATIC_NAME} ${LIBUCONTEXT_OBJ}
|
2018-01-29 21:50:49 +00:00
|
|
|
|
|
|
|
${LIBUCONTEXT_NAME}: ${LIBUCONTEXT_OBJ}
|
2018-01-30 03:53:04 +00:00
|
|
|
$(CC) -o ${LIBUCONTEXT_NAME} -Wl,-soname,${LIBUCONTEXT_SONAME} \
|
2019-11-25 23:26:55 +00:00
|
|
|
-shared ${LIBUCONTEXT_OBJ} ${LDFLAGS}
|
2018-01-29 21:50:49 +00:00
|
|
|
|
2018-01-30 03:53:04 +00:00
|
|
|
${LIBUCONTEXT_SONAME}: ${LIBUCONTEXT_NAME}
|
|
|
|
ln -sf ${LIBUCONTEXT_NAME} ${LIBUCONTEXT_SONAME}
|
2018-01-29 21:50:49 +00:00
|
|
|
|
|
|
|
.c.o:
|
|
|
|
$(CC) -std=c99 -D_BSD_SOURCE -fPIC -DPIC ${CFLAGS} ${CPPFLAGS} -c -o $@ $<
|
|
|
|
|
|
|
|
.S.o:
|
|
|
|
$(CC) -fPIC -DPIC ${CFLAGS} ${CPPFLAGS} -c -o $@ $<
|
|
|
|
|
|
|
|
clean:
|
2019-04-12 07:48:24 +00:00
|
|
|
rm -f ${LIBUCONTEXT_NAME} ${LIBUCONTEXT_SONAME} ${LIBUCONTEXT_STATIC_NAME} \
|
|
|
|
${LIBUCONTEXT_OBJ} test_libucontext
|
2018-01-29 21:50:49 +00:00
|
|
|
|
|
|
|
install: all
|
2020-03-30 08:21:20 +00:00
|
|
|
install -D -m755 ${LIBUCONTEXT_NAME} ${DESTDIR}${LIBUCONTEXT_PATH}
|
|
|
|
install -D -m664 ${LIBUCONTEXT_STATIC_NAME} ${DESTDIR}${LIBUCONTEXT_STATIC_PATH}
|
|
|
|
ln -sf ${LIBUCONTEXT_SONAME} ${DESTDIR}${LIBDIR}/${LIBUCONTEXT_NAME}
|
2018-01-30 03:53:04 +00:00
|
|
|
|
|
|
|
check: test_libucontext ${LIBUCONTEXT_SONAME}
|
2018-02-14 03:30:50 +00:00
|
|
|
env LD_LIBRARY_PATH=$(shell pwd) ./test_libucontext
|
2018-01-30 03:53:04 +00:00
|
|
|
|
2018-02-01 01:27:13 +00:00
|
|
|
test_libucontext: test_libucontext.c ${LIBUCONTEXT_NAME}
|
2018-02-15 04:41:22 +00:00
|
|
|
$(CC) -std=c99 -D_BSD_SOURCE ${CFLAGS} ${CPPFLAGS} $@.c -o $@ -L. -lucontext
|
2018-01-30 03:53:04 +00:00
|
|
|
|
|
|
|
.PHONY: check
|