From: Waldemar Kozaczuk <[email protected]> Committer: Nadav Har'El <[email protected]> Branch: master
libc: add number of glibc _chk extension functions 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 <[email protected]> Message-Id: <[email protected]> --- diff --git a/Makefile b/Makefile --- 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 --- 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 --- a/libc/multibyte/__mbsnrtowcs_chk.c +++ 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 --- a/libc/multibyte/__mbsrtowcs_chk.c +++ 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 --- a/libc/string/__wmemcpy_chk.c +++ 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 --- a/libc/string/__wmemmove_chk.c +++ 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 --- a/libc/string/__wmemset_chk.c +++ 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); +} -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/osv-dev/0000000000002a4dfe05dea4c9c3%40google.com.
