blob: ca540e1378805fc44348d058aa0579d801a3bca1 [file] [log] [blame]
Andrew Scull8d9e1212019-04-05 13:52:55 +01001/*
2 * Copyright 2019 The Hafnium Authors.
3 *
Andrew Walbrane959ec12020-06-17 15:01:09 +01004 * 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 Scull8d9e1212019-04-05 13:52:55 +01007 */
8
9#pragma once
10
11#include "hf/arch/std.h"
Andrew Scull2b5fbad2019-04-05 13:55:56 +010012
Raghu Krishnamurthybefdcc82023-02-24 06:41:56 -080013#define MAX(x, y) (x > y ? x : y)
14#define MIN(x, y) (x < y ? x : y)
15
Andrew Scull2b5fbad2019-04-05 13:55:56 +010016typedef size_t rsize_t;
17
Andrew Scull25635522019-05-20 11:46:07 +010018/**
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-Alves715d6232023-02-16 16:33:28 +000023#define RSIZE_MAX ((size_t)(128 * 1024 * 1024))
Andrew Scull2b5fbad2019-04-05 13:55:56 +010024
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 Brazdil2246abe2019-08-23 12:21:06 +010029 * These functions don't return errno_t as per the specification and implicitly
Andrew Scull2b5fbad2019-04-05 13:55:56 +010030 * have a constraint handler that panics.
31 */
32void memset_s(void *dest, rsize_t destsz, int ch, rsize_t count);
Andrew Sculla1aa2ba2019-04-05 11:49:02 +010033void memcpy_s(void *dest, rsize_t destsz, const void *src, rsize_t count);
Andrew Scull8fbd7ee2019-04-05 14:36:34 +010034void memmove_s(void *dest, rsize_t destsz, const void *src, rsize_t count);
Andrew Scull55baca62019-04-05 14:56:20 +010035
David Brazdil74e9c3b2019-08-28 11:09:08 +010036void *memchr(const void *ptr, int ch, size_t count);
37
Andrew Scull55baca62019-04-05 14:56:20 +010038size_t strnlen_s(const char *str, size_t strsz);