Skip to content

Commit

Permalink
c18n: Remove unnecessary check for purecap ABI
Browse files Browse the repository at this point in the history
CHERI_LIB_C18N is only ever defined under the purecap ABI, so there is
no need to separately check for the purecap ABI.
  • Loading branch information
dpgao committed Aug 22, 2024
1 parent 07be96c commit 40a7a13
Show file tree
Hide file tree
Showing 19 changed files with 79 additions and 79 deletions.
10 changes: 5 additions & 5 deletions lib/libc/aarch64/gen/_setjmp.S
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ ENTRY(_setjmp)
#endif

/* Return value */
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
mov c1, c0
#endif
mov x0, #0
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
/*
* Tail-call to save Executive mode state
*/
Expand All @@ -81,7 +81,7 @@ ENTRY(_longjmp)

/* Restore the stack pointer */
ldr REG(8), [REG(0)], #(REG_WIDTH)
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
mov c2, c8
#else
mov REGN(sp), REG(8)
Expand All @@ -104,12 +104,12 @@ ENTRY(_longjmp)
#endif

/* Load the return value */
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
mov c3, c0
#endif
cmp x1, #0
csinc x0, x1, xzr, ne
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
/*
* Tail-call to restore Executive mode state
*/
Expand Down
12 changes: 6 additions & 6 deletions lib/libc/aarch64/gen/setjmp.S
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include <machine/setjmp.h>
#include <sys/elf_common.h>

#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
.weak _rtld_setjmp
.weak _rtld_longjmp
#endif
Expand Down Expand Up @@ -70,11 +70,11 @@ ENTRY(setjmp)
stp d14, d15, [REG(0)], #16

/* Return value */
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
mov c1, c0
#endif
mov x0, #0
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
/*
* Tail-call to save Executive mode state
*/
Expand Down Expand Up @@ -110,7 +110,7 @@ ENTRY(longjmp)

/* Restore the stack pointer */
ldr REG(8), [REG(0)], #(REG_WIDTH)
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
mov c2, c8
#else
mov REGN(sp), REG(8)
Expand All @@ -131,12 +131,12 @@ ENTRY(longjmp)
ldp d14, d15, [REG(0)], #16

/* Load the return value */
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
mov c3, c0
#endif
cmp x1, #0
csinc x0, x1, xzr, ne
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
/*
* Tail-call to restore Executive mode state
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/libc/gen/posix_spawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ do_posix_spawn(pid_t *pid, const char *path,
p = rfork_thread(RFSPAWN, stack + stacksz, _posix_spawn_thr, &psa);
free(stack);
#else
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
p = __sys_rfork(RFSPAWN);
#else
p = rfork(RFSPAWN);
Expand Down
2 changes: 1 addition & 1 deletion lib/libc/include/libc_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ struct __nl_cat_d *__catopen_l(const char *name, int type,
int __strerror_rl(int errnum, char *strerrbuf, size_t buflen,
struct _xlocale *locale);

#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
__pid_t __sys_rfork(int);
int sigaction_c18n(int, const struct sigaction *, struct sigaction *);
#endif
Expand Down
2 changes: 1 addition & 1 deletion lib/libc/sys/sigaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

__weak_reference(__sys_sigaction, __sigaction);
__weak_reference(sigaction, __libc_sigaction);
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
/*
* This weak symbol will always be resolved at runtime.
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/libsys/interposing_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static interpos_func_t __libsys_interposing[INTERPOS_MAX] = {
SLOT(sendmsg, __sys_sendmsg),
SLOT(sendto, __sys_sendto),
SLOT(setcontext, __sys_setcontext),
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
SLOT(sigaction, sigaction_c18n),
#else
SLOT(sigaction, __sys_sigaction),
Expand Down
8 changes: 4 additions & 4 deletions lib/libthr/thread/thr_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

static int create_stack(struct pthread_attr *pattr);
static void thread_start(struct pthread *curthread) __used;
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
#pragma weak _thread_start = thread_start

/*
Expand Down Expand Up @@ -151,7 +151,7 @@ _pthread_create(pthread_t * __restrict thread,
new_thread->flags = THR_FLAGS_NEED_SUSPEND;
create_suspended = 1;
} else {
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
/*
* c18n: Always block all signals when creating a new thread to
* allow RTLD to set up the environment to handle signals.
Expand Down Expand Up @@ -187,7 +187,7 @@ _pthread_create(pthread_t * __restrict thread,
locked = 1;
} else
locked = 0;
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
param.start_func = (void (*)(void *)) _rtld_thread_start;
#else
param.start_func = (void (*)(void *)) thread_start;
Expand Down Expand Up @@ -298,7 +298,7 @@ thread_start(struct pthread *curthread)
sigset_t set;
bool restore_sigmask;

#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
/*
* At this point, curthread->tcb contains a fake wrapper TCB created by
* RTLD when the thread was created. The real TCB has now been installed
Expand Down
4 changes: 2 additions & 2 deletions lib/libthr/thread/thr_rtld.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static void _thr_rtld_rlock_acquire(void *);
static int _thr_rtld_set_flag(int);
static void _thr_rtld_wlock_acquire(void *);

#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
void _thread_start(struct pthread *);
void _thr_sighandler(int, siginfo_t *, void *);

Expand Down Expand Up @@ -291,7 +291,7 @@ _thr_rtld_init(void)
/* mask signals, also force to resolve __sys_sigprocmask PLT */
_thr_signal_block(curthread);
_rtld_thread_init(&li);
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
_rtld_thread_start_init(_thread_start);
_rtld_sighandler_init(_thr_sighandler);
#endif
Expand Down
16 changes: 8 additions & 8 deletions lib/libthr/thread/thr_sig.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static void handle_signal(struct sigaction *, int, siginfo_t *, ucontext_t *);
static void check_deferred_signal(struct pthread *);
static void check_suspend(struct pthread *);
static void check_cancel(struct pthread *curthread, ucontext_t *ucp);
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
#pragma weak _thr_sighandler = thr_sighandler

/*
Expand Down Expand Up @@ -296,7 +296,7 @@ handle_signal(struct sigaction *actp, int sig, siginfo_t *info, ucontext_t *ucp)
if (!cancel_async)
curthread->cancel_enable = 0;

#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
(void)sigfunc;
#else
/* restore correct mask before calling user handler */
Expand All @@ -313,7 +313,7 @@ handle_signal(struct sigaction *actp, int sig, siginfo_t *info, ucontext_t *ucp)
* so after setjmps() returns once more, the user code may need to
* re-set cancel_enable flag by calling pthread_setcancelstate().
*/
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
_rtld_siginvoke(sig, info, ucp, actp);
#else
if ((actp->sa_flags & SA_SIGINFO) != 0) {
Expand All @@ -336,7 +336,7 @@ handle_signal(struct sigaction *actp, int sig, siginfo_t *info, ucontext_t *ucp)
/* reschedule cancellation */
check_cancel(curthread, &uc2);
errno = err;
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
/*
* Calling sigreturn outside of sigcode does not work with
* compartmentalisation. Hence we set the user context and let the
Expand Down Expand Up @@ -432,7 +432,7 @@ check_deferred_signal(struct pthread *curthread)
/* remove signal */
curthread->deferred_siginfo.si_signo = 0;
handle_signal(&act, info.si_signo, &info, uc);
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
setcontext(uc);
#endif
}
Expand Down Expand Up @@ -500,7 +500,7 @@ _thr_signal_init(int dlopened)
for (sig = 1; sig <= _SIG_MAXSIG; sig++) {
if (sig == SIGCANCEL)
continue;
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
error = _rtld_sigaction(sig, NULL, &oact);
#else
error = __sys_sigaction(sig, NULL, &oact);
Expand All @@ -514,7 +514,7 @@ _thr_signal_init(int dlopened)
remove_thr_signals(&usa->sigact.sa_mask);
nact.sa_flags &= ~SA_NODEFER;
nact.sa_flags |= SA_SIGINFO;
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
/* XXX: Ignore sigaltstack for now */
nact.sa_flags &= ~SA_ONSTACK;
nact.sa_sigaction = _rtld_sighandler;
Expand Down Expand Up @@ -650,7 +650,7 @@ __thr_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
remove_thr_signals(&usa->sigact.sa_mask);
newact.sa_flags &= ~SA_NODEFER;
newact.sa_flags |= SA_SIGINFO;
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
/* XXX: Ignore sigaltstack for now */
newact.sa_flags &= ~SA_ONSTACK;
newact.sa_sigaction = _rtld_sighandler;
Expand Down
12 changes: 6 additions & 6 deletions libexec/rtld-elf/aarch64/reloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

#include "debug.h"
#include "rtld.h"
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
#include "rtld_c18n.h"
#endif
#include "rtld_printf.h"
Expand Down Expand Up @@ -112,14 +112,14 @@ init_pltgot(Obj_Entry *obj)
{

if (obj->pltgot != NULL) {
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
if (C18N_ENABLED)
obj->pltgot[1] = (uintptr_t)cheri_seal(obj,
sealer_pltgot);
else
#endif
obj->pltgot[1] = (uintptr_t)obj;
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
if (C18N_ENABLED)
obj->pltgot[2] = (uintptr_t)&_rtld_bind_start_c18n;
else
Expand Down Expand Up @@ -510,7 +510,7 @@ reloc_jmpslots(Obj_Entry *obj, int flags, RtldLockState *lockstate)
continue;
}
target = (uintptr_t)make_function_pointer(def, defobj);
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
target = (uintptr_t)tramp_intern(obj, &(struct tramp_data) {
.target = (void *)target,
.defobj = defobj,
Expand Down Expand Up @@ -572,7 +572,7 @@ reloc_iresolve_one(Obj_Entry *obj, const Elf_Rela *rela,
ptr = (uintptr_t)(obj->relocbase + rela->r_addend);
#endif
lock_release(rtld_bind_lock, lockstate);
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
ptr = (uintptr_t)tramp_intern(NULL, &(struct tramp_data) {
.target = (void *)ptr,
.defobj = obj,
Expand Down Expand Up @@ -663,7 +663,7 @@ reloc_gnu_ifunc(Obj_Entry *obj, int flags,
continue;
lock_release(rtld_bind_lock, lockstate);
target = (uintptr_t)rtld_resolve_ifunc(defobj, def);
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
target = (uintptr_t)tramp_intern(obj, &(struct tramp_data) {
.target = (void *)target,
.defobj = defobj,
Expand Down
6 changes: 3 additions & 3 deletions libexec/rtld-elf/aarch64/rtld_start.S
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ END(.rtld_start)
* x17 = &_rtld_bind_start
*/
ENTRY(C18N_SYM(_rtld_bind_start))
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
/*
* Get the caller's current stack top.
*/
Expand Down Expand Up @@ -205,7 +205,7 @@ ENTRY(C18N_SYM(_rtld_bind_start))
/* Restore frame pointer */
ldp PTR(29), PTR(zr), [PTRN(sp)], #(PTR_WIDTH * 2)

#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
/*
* Load caller's old stack top.
*/
Expand Down Expand Up @@ -246,7 +246,7 @@ ENTRY(C18N_SYM(_rtld_bind_start))
/* Call into the correct function */
#if defined(__ARM_MORELLO_PURECAP_BENCHMARK_ABI)
br x16
#elif defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#elif defined(CHERI_LIB_C18N)
brr PTR(16)
#else
br PTR(16)
Expand Down
2 changes: 1 addition & 1 deletion libexec/rtld-elf/cheri/cheri_reloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

#include "debug.h"
#include "rtld.h"
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
#include "rtld_c18n.h"
#endif

Expand Down
4 changes: 2 additions & 2 deletions libexec/rtld-elf/map_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

#include "debug.h"
#include "rtld.h"
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
#include "rtld_c18n.h"
#endif

Expand Down Expand Up @@ -278,7 +278,7 @@ map_object(int fd, const char *path, const struct stat *sb, const char* main_pat
base_addr, mapsize, PROT_NONE | PROT_MAX(_PROT_ALL), base_flags);
mapbase = mmap(base_addr, mapsize, PROT_NONE | PROT_MAX(_PROT_ALL),
base_flags, -1, 0);
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
mapbase = cheri_clearperm(mapbase, c18n_code_perm_clear);
#endif
if (mapbase == MAP_FAILED) {
Expand Down
2 changes: 1 addition & 1 deletion libexec/rtld-elf/rtld-libc/rtld_libc.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int __sys___getcwd(char *, size_t);
int __sys_sigprocmask(int, const sigset_t *, sigset_t *);
int __sys_thr_kill(long, int);
int __sys_thr_self(long *);
#if defined(__CHERI_PURE_CAPABILITY__) && defined(CHERI_LIB_C18N)
#ifdef CHERI_LIB_C18N
void __sys_thr_exit(long *);
struct sigaction;
int __sys_sigaction(int, const struct sigaction *, struct sigaction *);
Expand Down
Loading

0 comments on commit 40a7a13

Please sign in to comment.