1 /*
2  * Copyright 2019 The Hafnium Authors.
3  *
4  * Use of this source code is governed by a BSD-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/BSD-3-Clause.
7  */
8 
9 #pragma once
10 
11 #include "hf/arch/std.h"
12 
13 #define MAX(x, y) (x > y ? x : y)
14 #define MIN(x, y) (x < y ? x : y)
15 
16 typedef size_t rsize_t;
17 
18 /**
19  * Restrict the maximum range for range checked functions so as to be more
20  * likely to catch errors. This may need to be relaxed if it proves to be overly
21  * restrictive.
22  */
23 #define RSIZE_MAX ((size_t)(128 * 1024 * 1024))
24 
25 /*
26  * Only the safer versions of these functions are exposed to reduce the chance
27  * of misusing the versions without bounds checking or null pointer checks.
28  *
29  * These functions don't return errno_t as per the specification and implicitly
30  * have a constraint handler that panics.
31  */
32 void memset_s(void *dest, rsize_t destsz, int ch, rsize_t count);
33 void memcpy_s(void *dest, rsize_t destsz, const void *src, rsize_t count);
34 void memmove_s(void *dest, rsize_t destsz, const void *src, rsize_t count);
35 
36 void *memchr(const void *ptr, int ch, size_t count);
37 
38 size_t strnlen_s(const char *str, size_t strsz);
39