Andrew Scull | 8d9e121 | 2019-04-05 13:52:55 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 The Hafnium Authors. |
| 3 | * |
Andrew Walbran | e959ec1 | 2020-06-17 15:01:09 +0100 | [diff] [blame] | 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. |
Andrew Scull | 8d9e121 | 2019-04-05 13:52:55 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #pragma once |
| 10 | |
| 11 | #include "hf/arch/std.h" |
Andrew Scull | 2b5fbad | 2019-04-05 13:55:56 +0100 | [diff] [blame] | 12 | |
Raghu Krishnamurthy | befdcc8 | 2023-02-24 06:41:56 -0800 | [diff] [blame^] | 13 | #define MAX(x, y) (x > y ? x : y) |
| 14 | #define MIN(x, y) (x < y ? x : y) |
| 15 | |
Andrew Scull | 2b5fbad | 2019-04-05 13:55:56 +0100 | [diff] [blame] | 16 | typedef size_t rsize_t; |
| 17 | |
Andrew Scull | 2563552 | 2019-05-20 11:46:07 +0100 | [diff] [blame] | 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 | */ |
J-Alves | 715d623 | 2023-02-16 16:33:28 +0000 | [diff] [blame] | 23 | #define RSIZE_MAX ((size_t)(128 * 1024 * 1024)) |
Andrew Scull | 2b5fbad | 2019-04-05 13:55:56 +0100 | [diff] [blame] | 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 | * |
David Brazdil | 2246abe | 2019-08-23 12:21:06 +0100 | [diff] [blame] | 29 | * These functions don't return errno_t as per the specification and implicitly |
Andrew Scull | 2b5fbad | 2019-04-05 13:55:56 +0100 | [diff] [blame] | 30 | * have a constraint handler that panics. |
| 31 | */ |
| 32 | void memset_s(void *dest, rsize_t destsz, int ch, rsize_t count); |
Andrew Scull | a1aa2ba | 2019-04-05 11:49:02 +0100 | [diff] [blame] | 33 | void memcpy_s(void *dest, rsize_t destsz, const void *src, rsize_t count); |
Andrew Scull | 8fbd7ee | 2019-04-05 14:36:34 +0100 | [diff] [blame] | 34 | void memmove_s(void *dest, rsize_t destsz, const void *src, rsize_t count); |
Andrew Scull | 55baca6 | 2019-04-05 14:56:20 +0100 | [diff] [blame] | 35 | |
David Brazdil | 74e9c3b | 2019-08-28 11:09:08 +0100 | [diff] [blame] | 36 | void *memchr(const void *ptr, int ch, size_t count); |
| 37 | |
Andrew Scull | 55baca6 | 2019-04-05 14:56:20 +0100 | [diff] [blame] | 38 | size_t strnlen_s(const char *str, size_t strsz); |