blob: be3b168bc2d8a84ae87aa60a8a9c8c4adf54bf51 [file] [log] [blame]
Andrew Scull8d9e1212019-04-05 13:52:55 +01001/*
2 * Copyright 2019 The Hafnium Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include "hf/arch/std.h"
Andrew Scull2b5fbad2019-04-05 13:55:56 +010020
21typedef size_t rsize_t;
22
Andrew Scull25635522019-05-20 11:46:07 +010023/**
24 * Restrict the maximum range for range checked functions so as to be more
25 * likely to catch errors. This may need to be relaxed if it proves to be overly
26 * restrictive.
27 */
28#define RSIZE_MAX (128 * 1024 * 1024)
Andrew Scull2b5fbad2019-04-05 13:55:56 +010029
30/*
31 * Only the safer versions of these functions are exposed to reduce the chance
32 * of misusing the versions without bounds checking or null pointer checks.
33 *
34 * These functions don't return errno_t as per the specification and implicity
35 * have a constraint handler that panics.
36 */
37void memset_s(void *dest, rsize_t destsz, int ch, rsize_t count);
Andrew Sculla1aa2ba2019-04-05 11:49:02 +010038void memcpy_s(void *dest, rsize_t destsz, const void *src, rsize_t count);
Andrew Scull8fbd7ee2019-04-05 14:36:34 +010039void memmove_s(void *dest, rsize_t destsz, const void *src, rsize_t count);
Andrew Scull55baca62019-04-05 14:56:20 +010040
41size_t strnlen_s(const char *str, size_t strsz);