aboutsummaryrefslogtreecommitdiff
path: root/libs/libc/mem.c
diff options
context:
space:
mode:
authorMarvin Borner2021-04-03 14:04:23 +0200
committerMarvin Borner2021-04-03 14:04:23 +0200
commit394ee169ea6eb4dd5c8fa778d1c2769e26e52f01 (patch)
tree70440fb0d9eeb09e1aeec7eba6f2319d34b4918c /libs/libc/mem.c
parentce98400f8a9ebd4e62e76b9e292b7598d0d66cc0 (diff)
Enabled SMAP/SMEP protections
Diffstat (limited to 'libs/libc/mem.c')
-rw-r--r--libs/libc/mem.c42
1 files changed, 40 insertions, 2 deletions
diff --git a/libs/libc/mem.c b/libs/libc/mem.c
index ad691ed..babec3a 100644
--- a/libs/libc/mem.c
+++ b/libs/libc/mem.c
@@ -102,7 +102,7 @@ void *memchr(void *src, char c, u32 n)
return NULL;
}
-int memcmp(const void *s1, const void *s2, u32 n)
+s32 memcmp(const void *s1, const void *s2, u32 n)
{
const u8 *a = (const u8 *)s1;
const u8 *b = (const u8 *)s2;
@@ -115,7 +115,45 @@ int memcmp(const void *s1, const void *s2, u32 n)
return 0;
}
-int mememp(const u8 *buf, u32 n)
+u8 mememp(const u8 *buf, u32 n)
{
return buf[0] == 0 && !memcmp(buf, buf + 1, n - 1);
}
+
+#ifdef KERNEL
+
+#include <cpu.h>
+
+void *memcpy_user(void *dest, const void *src, u32 n)
+{
+ stac();
+ void *ret = memcpy(dest, src, n);
+ clac();
+ return ret;
+}
+
+void *memset_user(void *dest, u32 val, u32 n)
+{
+ stac();
+ void *ret = memset(dest, val, n);
+ clac();
+ return ret;
+}
+
+void *memchr_user(void *src, char c, u32 n)
+{
+ stac();
+ void *ret = memchr(src, c, n);
+ clac();
+ return ret;
+}
+
+s32 memcmp_user(const void *s1, const void *s2, u32 n)
+{
+ stac();
+ s32 ret = memcmp(s1, s2, n);
+ clac();
+ return ret;
+}
+
+#endif