Compare commits

...

10 Commits

Author SHA1 Message Date
matoro be80075e95 meson: support building docs
ci/woodpecker/push/woodpecker Pipeline was successful Details
Toggleable with -Ddocs=(true|false), defaults to false.

Requires bumping minimum meson version to 0.59.0, or 0.61.0 to also
include symlinks.
2023-05-18 18:12:55 -07:00
Ariadne Conill 4c2cfc54ac libucontext.h: add C++ externs 2023-05-18 18:11:50 -07:00
L. Pereira 0f625a86ee Fix FREESTANDING install target
When installing a FREESTANDING build, the check for an empty variable
was not being honored because the empty string would evaluate to
nothing.  Put the variable expansion in quotes so that we have an empty
string instead.
2023-05-18 18:10:01 -07:00
Ismael Luceno 8e1397f5a2 Makefile: Make variables Automake-compatible
Also split libdir into shared and static variants to enable installing to
different locations.

Signed-off-by: Ismael Luceno <ismael@iodev.co.uk>
2023-05-18 18:08:07 -07:00
Ariadne Conill 33ff253d52 Merge pull request 'Fixed empty TYPE(__proc) causing linker issues on 32-bit arm' (#36) from rlcamp/libucontext:arm_linker_fix into master
Reviewed-on: ariadne/libucontext#36
2022-03-24 08:57:53 +00:00
Richard Campbell 3044c2b908 Fixed empty TYPE(__proc) causing linker issues on 32-bit arm 2022-03-23 15:18:39 -07:00
Ariadne Conill 128e4fdc4b Merge pull request 'arm_hard_float' (#35) from rlcamp/libucontext:arm_hard_float into master
Reviewed-on: ariadne/libucontext#35
2022-03-23 20:15:32 +00:00
Richard Campbell 5244775fb9 Added note to readme about floating point WIP 2022-03-04 10:41:54 -08:00
Richard Campbell 9abcd8afe0 Added passthrough of FORCE_SOFT_FLOAT and FORCE_HARD_FLOAT Makefile options 2022-03-04 10:40:30 -08:00
Richard Campbell 7bc3e90984 Added arm conditional vfp save/restore 2022-03-04 10:35:25 -08:00
12 changed files with 131 additions and 21 deletions

View File

@ -17,9 +17,13 @@ ifeq ($(ARCH),$(filter $(ARCH),arm64))
override ARCH = aarch64
endif
LIBDIR := /lib
INCLUDEDIR := /usr/include
PKGCONFIGDIR := /usr/lib/pkgconfig
prefix = /usr
libdir = ${prefix}/lib
shared_libdir = ${libdir}
static_libdir = ${libdir}
includedir = ${prefix}/include
pkgconfigdir = ${prefix}/lib/pkgconfig
CFLAGS ?= -ggdb3 -O2 -Wall
CPPFLAGS := -Iinclude -Iarch/${ARCH} -Iarch/common
ifneq ($(shell uname),Darwin)
@ -35,6 +39,18 @@ ifeq ($(FREESTANDING),yes)
EXPORT_UNPREFIXED = no
endif
FORCE_SOFT_FLOAT := no
ifeq ($(FORCE_SOFT_FLOAT),yes)
CPPFLAGS += -DFORCE_SOFT_FLOAT
endif
FORCE_HARD_FLOAT := no
ifeq ($(FORCE_HARD_FLOAT),yes)
CPPFLAGS += -DFORCE_HARD_FLOAT
endif
ifeq ($(EXPORT_UNPREFIXED),yes)
CPPFLAGS += -DEXPORT_UNPREFIXED
endif
@ -67,8 +83,8 @@ else
endif
LIBUCONTEXT_STATIC_NAME = libucontext.a
LIBUCONTEXT_PC = libucontext.pc
LIBUCONTEXT_PATH = ${LIBDIR}/${LIBUCONTEXT_SONAME}
LIBUCONTEXT_STATIC_PATH = ${LIBDIR}/${LIBUCONTEXT_STATIC_NAME}
LIBUCONTEXT_PATH = ${shared_libdir}/${LIBUCONTEXT_SONAME}
LIBUCONTEXT_STATIC_PATH = ${static_libdir}/${LIBUCONTEXT_STATIC_NAME}
LIBUCONTEXT_HEADERS = \
include/libucontext/libucontext.h \
include/libucontext/bits.h
@ -77,8 +93,8 @@ LIBUCONTEXT_EXAMPLES = \
LIBUCONTEXT_POSIX_STATIC_NAME = libucontext_posix.a
LIBUCONTEXT_POSIX_C_SRC = libucontext_posix.c
LIBUCONTEXT_POSIX_OBJ = ${LIBUCONTEXT_POSIX_C_SRC:.c=.o}
LIBUCONTEXT_POSIX_PATH = ${LIBDIR}/${LIBUCONTEXT_POSIX_SONAME}
LIBUCONTEXT_POSIX_STATIC_PATH = ${LIBDIR}/${LIBUCONTEXT_POSIX_STATIC_NAME}
LIBUCONTEXT_POSIX_PATH = ${shared_libdir}/${LIBUCONTEXT_POSIX_SONAME}
LIBUCONTEXT_POSIX_STATIC_PATH = ${static_libdir}/${LIBUCONTEXT_POSIX_STATIC_NAME}
ifeq ($(FREESTANDING),yes)
LIBUCONTEXT_POSIX_NAME =
@ -107,8 +123,9 @@ ${LIBUCONTEXT_SONAME}: ${LIBUCONTEXT_NAME}
${LIBUCONTEXT_PC}: libucontext.pc.in
sed -e s:@LIBUCONTEXT_VERSION@:${LIBUCONTEXT_VERSION}:g \
-e s:@LIBUCONTEXT_LIBDIR@:${LIBDIR}:g \
-e s:@LIBUCONTEXT_INCLUDEDIR@:${INCLUDEDIR}:g $< > $@
-e s:@LIBUCONTEXT_SHARED_LIBDIR@:${shared_libdir}:g \
-e s:@LIBUCONTEXT_STATIC_LIBDIR@:${static_libdir}:g \
-e s:@LIBUCONTEXT_INCLUDEDIR@:${includedir}:g $< > $@
MANPAGES_SYMLINKS_3 = \
libucontext_getcontext.3 \
@ -192,13 +209,13 @@ clean: docs_clean
install: all
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}
ln -sf ${LIBUCONTEXT_SONAME} ${DESTDIR}${shared_libdir}/${LIBUCONTEXT_NAME}
for i in ${LIBUCONTEXT_HEADERS}; do \
destfn=$$(echo $$i | sed s:include/::g); \
install -D -m644 $$i ${DESTDIR}${INCLUDEDIR}/$$destfn; \
install -D -m644 $$i ${DESTDIR}${includedir}/$$destfn; \
done
install -D -m644 ${LIBUCONTEXT_PC} ${DESTDIR}${PKGCONFIGDIR}/${LIBUCONTEXT_PC}
if [ -n ${LIBUCONTEXT_POSIX_NAME} ]; then \
install -D -m644 ${LIBUCONTEXT_PC} ${DESTDIR}${pkgconfigdir}/${LIBUCONTEXT_PC}
if [ -n "${LIBUCONTEXT_POSIX_NAME}" ]; then \
install -D -m755 ${LIBUCONTEXT_POSIX_NAME} ${DESTDIR}${LIBUCONTEXT_POSIX_PATH}; \
install -D -m644 ${LIBUCONTEXT_POSIX_STATIC_NAME} ${DESTDIR}${LIBUCONTEXT_POSIX_STATIC_PATH}; \
fi

View File

@ -101,4 +101,5 @@ ucontext functions:
save/restore FPU registers or vector registers may be added in a later release as a build-time
setting -- for now, we assume a soft-float ABI with no optional processor features. In practice, this
does not really matter, code using these functions are unlikely to be impacted by this design
assumption.
assumption. This is a work in progress, as newer compilers will spill even non-floating-point state
through floating point registers when allowed to do so.

View File

@ -2,8 +2,10 @@
#define REG_SZ (4)
#define MCONTEXT_GREGS (32)
#define VFP_MAGIC_OFFSET (232)
#define VFP_D8_OFFSET (304)
#define TYPE(__proc)
#define TYPE(__proc) .type __proc, %function;
#define FETCH_LINKPTR(dest) \
asm("movs %0, r4" : "=r" ((dest)))

View File

@ -22,6 +22,27 @@ FUNC(libucontext_getcontext)
str r13, [r0, #REG_OFFSET(13)]
str r14, [r0, #REG_OFFSET(15)]
#ifndef FORCE_SOFT_FLOAT
#ifndef FORCE_HARD_FLOAT
/* test for vfp, set kernel-defined magic number in uc_regspace */
push {r0-r1,fp,lr}
mov r0, #16
bl getauxval
tst r0, #64
pop {r0-r1,fp,lr}
moveq r2, #0
ldrne r2, =#0x56465001
str r2, [r0, #VFP_MAGIC_OFFSET]
beq 1f
#endif
/* if vfp detected, save d8-d15 */
.fpu vfp
add r1, r0, #VFP_D8_OFFSET
vstmia r1, {d8-d15}
.fpu softvfp
1:
#endif
/* return 0 */
mov r0, #0
mov pc, lr

View File

@ -23,6 +23,8 @@ typedef struct libucontext_ucontext {
struct libucontext_ucontext *uc_link;
libucontext_stack_t uc_stack;
libucontext_mcontext_t uc_mcontext;
unsigned long uc_sigmask[128 / sizeof(long)];
unsigned long long uc_regspace[64];
} libucontext_ucontext_t;
#endif

View File

@ -16,6 +16,22 @@ ALIAS(setcontext, libucontext_setcontext)
ALIAS(__setcontext, libucontext_setcontext)
FUNC(libucontext_setcontext)
#ifndef FORCE_SOFT_FLOAT
#ifndef FORCE_HARD_FLOAT
/* test for vfp magic number set by getcontext */
ldr r2, [r0, #VFP_MAGIC_OFFSET]
ldr r3, =#0x56465001
cmp r2, r3
bne 1f
#endif
/* if vfp in use, restore d8-d15 from uc_regspace */
.fpu vfp
add r14, r0, #VFP_D8_OFFSET
vldmia r14, {d8-d15}
.fpu softvfp
1:
#endif
/* copy all of the current registers into the ucontext structure */
add r14, r0, #REG_OFFSET(0)
ldmia r14, {r0-r12}

View File

@ -22,6 +22,26 @@ FUNC(libucontext_swapcontext)
str r13, [r0,#REG_OFFSET(13)]
str r14, [r0,#REG_OFFSET(15)]
#ifndef FORCE_SOFT_FLOAT
#ifndef FORCE_HARD_FLOAT
/* test for vfp magic number, copy to other ucontext */
ldr r3, [r1, #VFP_MAGIC_OFFSET]
ldr r4, =#0x56465001
str r3, [r0, #VFP_MAGIC_OFFSET]
cmp r3, r4
bne 1f
#endif
/* if vfp in use, save and restore d8-d15 */
.fpu vfp
add r2, r0, #VFP_D8_OFFSET
vstmia r2, {d8-d15}
add r14, r1, #VFP_D8_OFFSET
vldmia r14, {d8-d15}
.fpu softvfp
1:
#endif
/* load new registers from the second ucontext structure */
add r14, r1, #REG_OFFSET(0)
ldmia r14, {r0-r12}

21
doc/meson.build Normal file
View File

@ -0,0 +1,21 @@
scdoc = find_program('scdoc', required: true)
custom_target(
'libucontext.3',
output: 'libucontext.3',
input: 'libucontext.scd',
command: [ scdoc ],
feed: true,
capture: true,
install: true,
install_dir: get_option('mandir') / 'man3'
)
if meson.version().version_compare('>=0.61.0')
foreach link : [ 'get', 'make', 'set', 'swap' ]
install_symlink('libucontext_' + link + 'context.3',
pointing_to: 'libucontext.3',
install_dir: get_option('mandir') / 'man3'
)
endforeach
endif

View File

@ -4,9 +4,17 @@
#include <stddef.h>
#include <libucontext/bits.h>
#ifdef __cplusplus
extern "C" {
#endif
int libucontext_getcontext(libucontext_ucontext_t *);
void libucontext_makecontext(libucontext_ucontext_t *, void (*)(), int, ...);
int libucontext_setcontext(const libucontext_ucontext_t *);
int libucontext_swapcontext(libucontext_ucontext_t *, const libucontext_ucontext_t *);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,8 +1,9 @@
libdir=@LIBUCONTEXT_LIBDIR@
libdir=@LIBUCONTEXT_SHARED_LIBDIR@
static_libdir=@LIBUCONTEXT_STATIC_LIBDIR@
includedir=@LIBUCONTEXT_INCLUDEDIR@
Name: libucontext
Version: @LIBUCONTEXT_VERSION@
Description: ucontext library implementation (standalone)
Libs: -L${libdir} -lucontext
Libs: -L${libdir} -L${static_libdir} -lucontext
Cflags: -I${includedir}

View File

@ -1,7 +1,7 @@
project(
'libucontext',
'c',
meson_version : '>=0.55.0',
meson_version : '>=0.59.0',
default_options: ['c_std=gnu11', 'default_library=both'],
version : run_command('head', files('VERSION')).stdout()
)
@ -144,9 +144,8 @@ endif
# Docs
# ====
# TODO: meson.build for docs
if not meson.is_subproject()
#subdir('docs')
if not meson.is_subproject() and get_option('docs')
subdir('doc')
endif
# ==========

View File

@ -4,3 +4,5 @@ option('export_unprefixed', type : 'boolean', value : true,
description: 'Export POSIX 2004 ucontext names as alises')
option('cpu', type : 'string', value : '',
description: 'Target CPU architecture for cross compile')
option('docs', type : 'boolean', value : false,
description: 'Build and install man pages')