Skip to content

Commit d30a4fc

Browse files
committed
Don't have memcpy_c and friends duplicate their non-_c versions for purecap
In purecap code, both are equivalent (and should be identical implementations), so this is just a waste of space. Instead we can just define the explicit capability versions to the normal pointer versions. For convenience, like how we define __capability to nothing when CHERI is not available, also define them as aliases for their pointer versions when CHERI isn't available, meaning hybrid code can make use of CHERI features without needing so many #ifdef's. The kernel currently does this with memcpy_c for non-CHERI builds, too.
1 parent d1cc285 commit d30a4fc

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

bin/cheri_bench/cheri_bench.c

-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ struct cheri_object cheri_bench;
8080
#else
8181

8282
#define __capability
83-
#define memcpy_c memcpy
8483
#define cheri_ptr(c,l) c
8584

8685
// Manually assembled due to gcc/gas refusing to recognise custom rdhwr registers:

include/string.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ typedef __ssize_t ssize_t;
136136
void swab(const void * __restrict, void * __restrict, ssize_t);
137137
#endif /* _SWAB_DECLARED */
138138

139-
#if __has_feature(capabilities)
139+
#if __has_feature(capabilities) && !defined(__CHERI_PURE_CAPABILITY__)
140140
void * __capability
141141
memcpy_c(void * __capability __restrict,
142142
const void * __capability __restrict, size_t);
@@ -145,6 +145,10 @@ void * __capability
145145
const void * __capability __restrict, size_t);
146146
void * __capability
147147
memset_c(void * __capability, int, size_t);
148+
#else
149+
#define memcpy_c memcpy
150+
#define memmove_c memmove
151+
#define memset_c memset
148152
#endif
149153

150154
int timingsafe_bcmp(const void *, const void *, size_t);

lib/libc/mips/string/Makefile.inc

+3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ MDSRCS+= \
1515
.endif
1616

1717
.if ${MACHINE_CPU:Mcheri}
18+
.if !${MACHINE_ABI:Mpurecap}
1819
CHERI_MDSRCS= \
1920
memcpy_c.c \
2021
memmove_c.c \
2122
memset_c.c
23+
.endif
24+
2225
CHERI_MISRCS= \
2326
bcopy.c \
2427
memcpy.c \

lib/libc/string/Makefile.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ MISRCS+=bcmp.c bcopy.c bzero.c explicit_bzero.c \
2727
wmemcmp.c \
2828
wmemcpy.c wmemmove.c wmemset.c
2929

30-
.if ${MACHINE_CPU:Mcheri}
30+
.if ${MACHINE_CPU:Mcheri} && !${MACHINE_ABI:Mpurecap}
3131
MISRCS+=memcpy_c.c memmove_c.c memset_c.c
3232
.endif
3333

0 commit comments

Comments
 (0)