xref: /freebsd/include/ssp/strings.h (revision cf8e5289a110954600f135024d1515a77d0ae34d)
1be04fec4SKyle Evans /*	$NetBSD: strings.h,v 1.3 2008/04/28 20:22:54 martin Exp $	*/
2be04fec4SKyle Evans 
3be04fec4SKyle Evans /*-
4be04fec4SKyle Evans  *
5be04fec4SKyle Evans  * SPDX-License-Identifier: BSD-2-Clause
6be04fec4SKyle Evans  *
7be04fec4SKyle Evans  * Copyright (c) 2007 The NetBSD Foundation, Inc.
8be04fec4SKyle Evans  * All rights reserved.
9be04fec4SKyle Evans  *
10be04fec4SKyle Evans  * This code is derived from software contributed to The NetBSD Foundation
11be04fec4SKyle Evans  * by Christos Zoulas.
12be04fec4SKyle Evans  *
13be04fec4SKyle Evans  * Redistribution and use in source and binary forms, with or without
14be04fec4SKyle Evans  * modification, are permitted provided that the following conditions
15be04fec4SKyle Evans  * are met:
16be04fec4SKyle Evans  * 1. Redistributions of source code must retain the above copyright
17be04fec4SKyle Evans  *    notice, this list of conditions and the following disclaimer.
18be04fec4SKyle Evans  * 2. Redistributions in binary form must reproduce the above copyright
19be04fec4SKyle Evans  *    notice, this list of conditions and the following disclaimer in the
20be04fec4SKyle Evans  *    documentation and/or other materials provided with the distribution.
21be04fec4SKyle Evans  *
22be04fec4SKyle Evans  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23be04fec4SKyle Evans  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24be04fec4SKyle Evans  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25be04fec4SKyle Evans  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26be04fec4SKyle Evans  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27be04fec4SKyle Evans  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28be04fec4SKyle Evans  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29be04fec4SKyle Evans  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30be04fec4SKyle Evans  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31be04fec4SKyle Evans  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32be04fec4SKyle Evans  * POSSIBILITY OF SUCH DAMAGE.
33be04fec4SKyle Evans  */
34be04fec4SKyle Evans #ifndef _SSP_STRINGS_H_
35be04fec4SKyle Evans #define _SSP_STRINGS_H_
36be04fec4SKyle Evans 
37be04fec4SKyle Evans #include <ssp/ssp.h>
38be04fec4SKyle Evans #include <string.h>
39be04fec4SKyle Evans 
40be04fec4SKyle Evans #if __SSP_FORTIFY_LEVEL > 0
41be04fec4SKyle Evans 
425af6fbd7SKyle Evans #define _ssp_bcopy(srcvar, src, dstvar, dst, lenvar,  len) __extension__ ({ \
43be04fec4SKyle Evans     const void *srcvar = (src);			\
44be04fec4SKyle Evans     void *dstvar = (dst);			\
45be04fec4SKyle Evans     size_t lenvar = (len);			\
46be04fec4SKyle Evans     ((__ssp_bos0(dstvar) != (size_t)-1) ?	\
47be04fec4SKyle Evans     __builtin___memmove_chk(dstvar, srcvar, lenvar,	\
48be04fec4SKyle Evans         __ssp_bos0(dstvar)) :			\
49be04fec4SKyle Evans     __memmove_ichk(dstvar, srcvar, lenvar));	\
50be04fec4SKyle Evans })
51be04fec4SKyle Evans 
52be04fec4SKyle Evans #define	bcopy(src, dst, len)			\
53be04fec4SKyle Evans     _ssp_bcopy(__ssp_var(srcv), src, __ssp_var(dstv), dst, __ssp_var(lenv), len)
54be04fec4SKyle Evans 
555af6fbd7SKyle Evans #define _ssp_bzero(dstvar, dst, lenvar, len) __extension__ ({		\
56be04fec4SKyle Evans     void *dstvar = (dst);			\
57be04fec4SKyle Evans     size_t lenvar = (len);			\
58be04fec4SKyle Evans     ((__ssp_bos0(dstvar) != (size_t)-1) ?	\
59be04fec4SKyle Evans     __builtin___memset_chk(dstvar, 0, lenvar,	\
60be04fec4SKyle Evans         __ssp_bos0(dstvar)) : \
61be04fec4SKyle Evans     __memset_ichk(dstvar, 0, lenvar));		\
62be04fec4SKyle Evans })
63be04fec4SKyle Evans 
64be04fec4SKyle Evans #define	bzero(dst, len)	_ssp_bzero(__ssp_var(dstv), dst, __ssp_var(lenv), len)
65be04fec4SKyle Evans 
66*cf8e5289SKyle Evans __BEGIN_DECLS
67*cf8e5289SKyle Evans __ssp_redirect(void, explicit_bzero, (void *__buf, size_t __len),
68*cf8e5289SKyle Evans     (__buf, __len));
69*cf8e5289SKyle Evans __END_DECLS
70*cf8e5289SKyle Evans 
71be04fec4SKyle Evans #endif /* __SSP_FORTIFY_LEVEL > 0 */
72be04fec4SKyle Evans #endif /* _SSP_STRINGS_H_ */
73