This patch adds 5 new glibc extension functions that are part of the
glibc binary standard and are needed to build OSv kernel on Ubuntu 22.04:

- __mbsnrtowcs_chk
- __mbsrtowcs_chk
- __wmemcpy_chk
- __wmemmove_chk
- __wmemset_chk

The functions are implemented to meet the specification defined
in here as an example - 
http://refspecs.linux-foundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/libc---wmemset-chk-1.html.

Signed-off-by: Waldemar Kozaczuk <jwkozac...@gmail.com>
---
 Makefile                               |  5 +++++
 exported_symbols/osv_libc.so.6.symbols |  5 +++++
 libc/multibyte/__mbsnrtowcs_chk.c      | 18 ++++++++++++++++++
 libc/multibyte/__mbsrtowcs_chk.c       | 18 ++++++++++++++++++
 libc/string/__wmemcpy_chk.c            | 17 +++++++++++++++++
 libc/string/__wmemmove_chk.c           | 17 +++++++++++++++++
 libc/string/__wmemset_chk.c            | 17 +++++++++++++++++
 7 files changed, 97 insertions(+)
 create mode 100644 libc/multibyte/__mbsnrtowcs_chk.c
 create mode 100644 libc/multibyte/__mbsrtowcs_chk.c
 create mode 100644 libc/string/__wmemcpy_chk.c
 create mode 100644 libc/string/__wmemmove_chk.c
 create mode 100644 libc/string/__wmemset_chk.c

diff --git a/Makefile b/Makefile
index c6dff37f..3e87a16d 100644
--- a/Makefile
+++ b/Makefile
@@ -1447,7 +1447,9 @@ musl += multibyte/mbrlen.o
 musl += multibyte/mbrtowc.o
 musl += multibyte/mbsinit.o
 musl += multibyte/mbsnrtowcs.o
+libc += multibyte/__mbsnrtowcs_chk.o
 musl += multibyte/mbsrtowcs.o
+libc += multibyte/__mbsrtowcs_chk.o
 musl += multibyte/mbstowcs.o
 musl += multibyte/mbtowc.o
 musl += multibyte/wcrtomb.o
@@ -1780,8 +1782,11 @@ musl += string/wcswcs.o
 musl += string/wmemchr.o
 musl += string/wmemcmp.o
 musl += string/wmemcpy.o
+libc += string/__wmemcpy_chk.o
 musl += string/wmemmove.o
+libc += string/__wmemmove_chk.o
 musl += string/wmemset.o
+libc += string/__wmemset_chk.o
 
 musl += temp/__randname.o
 musl += temp/mkdtemp.o
diff --git a/exported_symbols/osv_libc.so.6.symbols 
b/exported_symbols/osv_libc.so.6.symbols
index 39e79692..7bae56c4 100644
--- a/exported_symbols/osv_libc.so.6.symbols
+++ b/exported_symbols/osv_libc.so.6.symbols
@@ -508,7 +508,9 @@ mbrlen
 mbrtowc
 mbsinit
 mbsnrtowcs
+__mbsnrtowcs_chk
 mbsrtowcs
+__mbsrtowcs_chk
 mbstowcs
 mbtowc
 memalign
@@ -1040,8 +1042,11 @@ wcwidth
 wmemchr
 wmemcmp
 wmemcpy
+__wmemcpy_chk
 wmemmove
+__wmemmove_chk
 wmemset
+__wmemset_chk
 wprintf
 write
 writev
diff --git a/libc/multibyte/__mbsnrtowcs_chk.c 
b/libc/multibyte/__mbsnrtowcs_chk.c
new file mode 100644
index 00000000..45fcacf3
--- /dev/null
+++ b/libc/multibyte/__mbsnrtowcs_chk.c
@@ -0,0 +1,18 @@
+/*
+ * Copyright (C) 2022 Waldemar Kozaczuk
+ *
+ * This work is open source software, licensed under the terms of the
+ * BSD license as described in the LICENSE file in the top-level directory.
+ */
+
+#include <wchar.h>
+#include <locale.h>
+#include <libc/internal/libc.h>
+
+size_t __mbsnrtowcs_chk(wchar_t *dst, const char **src, size_t nmc, size_t 
len, mbstate_t *ps, size_t dstlen)
+{
+    if (len > dstlen) {
+        _chk_fail("mbsnrtowcs");
+    }
+    return mbsnrtowcs (dst, src, nmc, len, ps);
+}
diff --git a/libc/multibyte/__mbsrtowcs_chk.c b/libc/multibyte/__mbsrtowcs_chk.c
new file mode 100644
index 00000000..57194703
--- /dev/null
+++ b/libc/multibyte/__mbsrtowcs_chk.c
@@ -0,0 +1,18 @@
+/*
+ * Copyright (C) 2022 Waldemar Kozaczuk
+ *
+ * This work is open source software, licensed under the terms of the
+ * BSD license as described in the LICENSE file in the top-level directory.
+ */
+
+#include <wchar.h>
+#include <locale.h>
+#include <libc/internal/libc.h>
+
+size_t __mbsrtowcs_chk(wchar_t *dst, const char **src, size_t len, mbstate_t 
*ps, size_t dstlen)
+{
+    if (len > dstlen) {
+        _chk_fail("mbsrtowcs");
+    }
+    return mbsrtowcs(dst, src, len, ps);
+}
diff --git a/libc/string/__wmemcpy_chk.c b/libc/string/__wmemcpy_chk.c
new file mode 100644
index 00000000..a7b9e5e7
--- /dev/null
+++ b/libc/string/__wmemcpy_chk.c
@@ -0,0 +1,17 @@
+/*
+ * Copyright (C) 2022 Waldemar Kozaczuk
+ *
+ * This work is open source software, licensed under the terms of the
+ * BSD license as described in the LICENSE file in the top-level directory.
+ */
+
+#include <wchar.h>
+#include <libc/internal/libc.h>
+
+wchar_t * __wmemcpy_chk(wchar_t *restrict dest, const wchar_t *restrict src, 
size_t len, size_t destlen)
+{
+    if (len > destlen) {
+        _chk_fail("wmemcpy");
+    }
+    return wmemcpy(dest, src, len);
+}
diff --git a/libc/string/__wmemmove_chk.c b/libc/string/__wmemmove_chk.c
new file mode 100644
index 00000000..11ca9617
--- /dev/null
+++ b/libc/string/__wmemmove_chk.c
@@ -0,0 +1,17 @@
+/*
+ * Copyright (C) 2022 Waldemar Kozaczuk
+ *
+ * This work is open source software, licensed under the terms of the
+ * BSD license as described in the LICENSE file in the top-level directory.
+ */
+
+#include <wchar.h>
+#include <libc/internal/libc.h>
+
+wchar_t * __wmemmove_chk(wchar_t *restrict dest, const wchar_t *restrict src, 
size_t len, size_t destlen)
+{
+    if (len > destlen) {
+        _chk_fail("wmemmove");
+    }
+    return wmemmove(dest, src, len);
+}
diff --git a/libc/string/__wmemset_chk.c b/libc/string/__wmemset_chk.c
new file mode 100644
index 00000000..a51ae3e8
--- /dev/null
+++ b/libc/string/__wmemset_chk.c
@@ -0,0 +1,17 @@
+/*
+ * Copyright (C) 2022 Waldemar Kozaczuk
+ *
+ * This work is open source software, licensed under the terms of the
+ * BSD license as described in the LICENSE file in the top-level directory.
+ */
+
+#include <wchar.h>
+#include <libc/internal/libc.h>
+
+wchar_t *__wmemset_chk(wchar_t *dest, wchar_t c, size_t n, size_t destlen)
+{
+    if (n > destlen) {
+        _chk_fail("wmemset");
+    }
+    return wmemset(dest, c, n);
+}
-- 
2.34.1

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/20220510012837.5880-1-jwkozaczuk%40gmail.com.

Reply via email to