Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F160210524
D57662.id180057.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
7 KB
Referenced Files
None
Subscribers
None
D57662.id180057.diff
View Options
diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile
--- a/share/man/man9/Makefile
+++ b/share/man/man9/Makefile
@@ -504,6 +504,7 @@
atomic.9 atomic_testandclear.9 \
atomic.9 atomic_testandset.9 \
atomic.9 atomic_thread_fence.9
+MLINKS+=bcopy.9 bcopy_data.9
MLINKS+=bhnd.9 BHND_MATCH_BOARD_TYPE.9 \
bhnd.9 BHND_MATCH_BOARD_VENDOR.9 \
bhnd.9 BHND_MATCH_CHIP_ID.9 \
@@ -1615,6 +1616,8 @@
mdchain.9 md_get_uio.9 \
mdchain.9 md_initm.9 \
mdchain.9 md_next_record.9
+MLINKS+=memcpy.9 memcpy_data.9
+MLINKS+=memmove.9 memmove_data.9
MLINKS+=microtime.9 bintime.9 \
microtime.9 getbintime.9 \
microtime.9 getmicrotime.9 \
diff --git a/share/man/man9/bcopy.9 b/share/man/man9/bcopy.9
--- a/share/man/man9/bcopy.9
+++ b/share/man/man9/bcopy.9
@@ -38,6 +38,8 @@
.In sys/systm.h
.Ft void
.Fn bcopy "const void *src" "void *dst" "size_t len"
+.Ft void
+.Fn bcopy_data "const void *src" "void *dst" "size_t len"
.Sh DESCRIPTION
The
.Fn bcopy
@@ -51,9 +53,15 @@
If
.Fa len
is zero, no bytes are copied.
+The
+.Fn bcopy_data
+function does the same except that it does not perserve pointer
+provenance.
.Sh SEE ALSO
.Xr memcpy 9 ,
-.Xr memmove 9
+.Xr memcpy_data 9 ,
+.Xr memmove 9 ,
+.Xr memmove_data 9
.Sh HISTORY
A
.Fn bcopy
@@ -88,3 +96,7 @@
.Fn memmove
since
.Fx 12.0 .
+The
+.Fn bcopy_data
+function first appeared in
+.Fx 16.0 .
diff --git a/share/man/man9/memcpy.9 b/share/man/man9/memcpy.9
--- a/share/man/man9/memcpy.9
+++ b/share/man/man9/memcpy.9
@@ -33,12 +33,15 @@
.Dt MEMCPY 9
.Os
.Sh NAME
-.Nm memcpy
+.Nm memcpy ,
+.Nm memcpy_data
.Nd copy byte string
.Sh SYNOPSIS
.In sys/systm.h
.Ft void *
.Fn memcpy "void *dst" "const void *src" "size_t len"
+.Ft void *
+.Fn memcpy_data "void *dst" "const void *src" "size_t len"
.Sh DESCRIPTION
The
.Fn memcpy
@@ -47,22 +50,30 @@
bytes from string
.Fa src
to string
-.Fa dst .
+.Fa dst
+in a manner that preserves pointer provenance.
If
.Fa src
and
.Fa dst
overlap, the results are not defined.
+The
+.Fn memcpy_data
+function does the same except that it does not perserve pointer
+provenance.
.Sh RETURN VALUES
The
.Fn memcpy
-function
-returns the original value of
+and
+.Fn memcpy_data
+functions return the original value of
.Fa dst .
.Pp
.Sh SEE ALSO
.Xr bcopy 9 ,
-.Xr memmove 9
+.Xr bcopy_data 9 ,
+.Xr memmove 9 ,
+.Xr memmove_data 9
.Sh STANDARDS
The
.Fn memcpy
@@ -76,3 +87,7 @@
.At V
and was reimplemented for
.Bx 4.3 Tahoe .
+The
+.Fn memcpy_data
+function fairst appeared in
+.Fx 16.0 .
diff --git a/share/man/man9/memmove.9 b/share/man/man9/memmove.9
--- a/share/man/man9/memmove.9
+++ b/share/man/man9/memmove.9
@@ -34,11 +34,14 @@
.Os
.Sh NAME
.Nm memmove
+.Nm memmove_data
.Nd copy byte string
.Sh SYNOPSIS
.In sys/systm.h
.Ft void *
.Fn memmove "void *dst" "const void *src" "size_t len"
+.Ft void *
+.Fn memmove_data "void *dst" "const void *src" "size_t len"
.Sh DESCRIPTION
The
.Fn memmove
@@ -50,17 +53,30 @@
.Fa dst .
The two strings may overlap;
the copy is always done in a non-destructive manner.
+The
+.Fn memcpy_data
+function does the same except that it does not perserve pointer
+provenance.
.Sh RETURN VALUES
The
.Fn memmove
-function returns the original value of
+and
+.Fn memmove_data
+functions return the original value of
.Fa dst .
.Sh SEE ALSO
.Xr bcopy 9 ,
-.Xr memcpy 9
+.Xr bcopy_data 9 ,
+.Xr memcpy 9 ,
+.Xr memcpy_data 9
.Sh STANDARDS
The
.Fn memmove
function
conforms to
.St -isoC .
+.Sh HISTORY
+The
+.Fn memmove_data
+function first appeared in
+.Fx 16.0 .
diff --git a/sys/libkern/bcopy.c b/sys/libkern/bcopy.c
--- a/sys/libkern/bcopy.c
+++ b/sys/libkern/bcopy.c
@@ -35,10 +35,16 @@
#include <sys/param.h>
#ifdef _KERNEL
#include <sys/systm.h>
+#include <sys/stddef.h>
#else
+#include <stddef.h>
#include <string.h>
#endif
+#ifdef __CHERI__
+#include <cheriintrin.h>
+#endif
+
#undef memcpy
#undef memmove
@@ -46,7 +52,7 @@
* sizeof(word) MUST BE A POWER OF TWO
* SO THAT wmask BELOW IS ALL ONES
*/
-typedef long word; /* "word" used for optimal copy speed */
+typedef uintptr_t word; /* "word" used for optimal copy speed */
#define wsize sizeof(word)
#define wmask (wsize - 1)
@@ -56,8 +62,8 @@
* This is the routine that actually implements
* (the portable versions of) bcopy, memcpy, and memmove.
*/
-void *
-memcpy(void *dst0, const void *src0, size_t length)
+static void *
+_memcpy(void *dst0, const void *src0, size_t length, bool keeptags)
{
char *dst;
const char *src;
@@ -82,12 +88,12 @@
*/
t = (size_t)src; /* only need low bits */
- if ((t | (uintptr_t)dst) & wmask) {
+ if ((t | (ptraddr_t)dst) & wmask) {
/*
* Try to align operands. This cannot be done
* unless the low bits match.
*/
- if ((t ^ (uintptr_t)dst) & wmask || length < wsize) {
+ if ((t ^ (ptraddr_t)dst) & wmask || length < wsize) {
t = length;
} else {
t = wsize - (t & wmask);
@@ -100,8 +106,15 @@
* Copy whole words, then mop up any trailing bytes.
*/
t = length / wsize;
- TLOOP(*(word *)dst = *(const word *)src; src += wsize;
- dst += wsize);
+#ifdef __CHERI__
+ if (!keeptags) {
+ TLOOP(*(word *)dst = (word)cheri_tag_clear(
+ (void *)*(const word *)src);
+ src += wsize; dst += wsize);
+ } else
+#endif
+ TLOOP(*(word *)dst = *(const word *)src; src += wsize;
+ dst += wsize);
t = length & wmask;
TLOOP(*dst++ = *src++);
} else {
@@ -112,10 +125,10 @@
*/
src += length;
dst += length;
- t = (uintptr_t)src;
+ t = (size_t)src;
- if ((t | (uintptr_t)dst) & wmask) {
- if ((t ^ (uintptr_t)dst) & wmask || length <= wsize) {
+ if ((t | (ptraddr_t)dst) & wmask) {
+ if ((t ^ (ptraddr_t)dst) & wmask || length <= wsize) {
t = length;
} else {
t &= wmask;
@@ -125,8 +138,15 @@
TLOOP1(*--dst = *--src);
}
t = length / wsize;
- TLOOP(src -= wsize; dst -= wsize;
- *(word *)dst = *(const word *)src);
+#ifdef __CHERI__
+ if (!keeptags) {
+ TLOOP(src -= wsize; dst -= wsize;
+ *(word *)dst = (word)cheri_tag_clear(
+ (void *)*(const word *)src));
+ } else
+#endif
+ TLOOP(src -= wsize; dst -= wsize;
+ *(word *)dst = *(const word *)src);
t = length & wmask;
TLOOP(*--dst = *--src);
}
@@ -134,4 +154,20 @@
return (dst0);
}
+void *
+memcpy(void *dst0, const void *src0, size_t length)
+{
+ return _memcpy(dst0, src0, length, true);
+}
+
__strong_reference(memcpy, memmove);
+
+#ifdef __CHERI__
+void *
+memcpy_data(void *dst0, const void *src0, size_t length)
+{
+ return _memcpy(dst0, src0, length, false);
+}
+
+__strong_reference(memcpy_data, memmove_data);
+#endif
diff --git a/sys/sys/systm.h b/sys/sys/systm.h
--- a/sys/sys/systm.h
+++ b/sys/sys/systm.h
@@ -256,6 +256,15 @@
void *memcpy(void * _Nonnull to, const void * _Nonnull from, size_t len);
void *memmove(void * _Nonnull dest, const void * _Nonnull src, size_t n);
int memcmp(const void *b1, const void *b2, size_t len);
+#ifdef __CHERI__
+void *memcpy_data(void * _Nonnull to, const void * _Nonnull from,
+ size_t len);
+void *memmove_data(void * _Nonnull dest, const void * _Nonnull src,
+ size_t n);
+#else
+#define memcpy_data memcpy
+#define memmove_data memmove
+#endif
#ifdef SAN_NEEDS_INTERCEPTORS
#define SAN_INTERCEPTOR(func) \
@@ -283,6 +292,8 @@
#define memcmp(b1, b2, len) __builtin_memcmp((b1), (b2), (len))
#endif /* SAN_NEEDS_INTERCEPTORS */
+#define bcopy_data(from, to, len) memmove_data((to), (from), (len))
+
void *memset_early(void * _Nonnull buf, int c, size_t len);
#define bzero_early(buf, len) memset_early((buf), 0, (len))
void *memcpy_early(void * _Nonnull to, const void * _Nonnull from, size_t len);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Jun 23, 5:19 AM (3 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34231732
Default Alt Text
D57662.id180057.diff (7 KB)
Attached To
Mode
D57662: CHERI: add mem{cpy,move}_data
Attached
Detach File
Event Timeline
Log In to Comment