blob: 3e37c3a741193c61c226165cec49414e2f7d37b6 [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
13typedef size_t rsize_t;
14
Andrew Scull25635522019-05-20 11:46:07 +010015/**
16 * Restrict the maximum range for range checked functions so as to be more
17 * likely to catch errors. This may need to be relaxed if it proves to be overly
18 * restrictive.
19 */
J-Alves715d6232023-02-16 16:33:28 +000020#define RSIZE_MAX ((size_t)(128 * 1024 * 1024))
Andrew Scull2b5fbad2019-04-05 13:55:56 +010021
22/*
23 * Only the safer versions of these functions are exposed to reduce the chance
24 * of misusing the versions without bounds checking or null pointer checks.
25 *
David Brazdil2246abe2019-08-23 12:21:06 +010026 * These functions don't return errno_t as per the specification and implicitly
Andrew Scull2b5fbad2019-04-05 13:55:56 +010027 * have a constraint handler that panics.
28 */
29void memset_s(void *dest, rsize_t destsz, int ch, rsize_t count);
Andrew Sculla1aa2ba2019-04-05 11:49:02 +010030void memcpy_s(void *dest, rsize_t destsz, const void *src, rsize_t count);
Andrew Scull8fbd7ee2019-04-05 14:36:34 +010031void memmove_s(void *dest, rsize_t destsz, const void *src, rsize_t count);
Andrew Scull55baca62019-04-05 14:56:20 +010032
David Brazdil74e9c3b2019-08-28 11:09:08 +010033void *memchr(const void *ptr, int ch, size_t count);
34
Andrew Scull55baca62019-04-05 14:56:20 +010035size_t strnlen_s(const char *str, size_t strsz);