1 /******************************************************************************
3 * Copyright (c) 2021 Intel.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 *******************************************************************************/
20 * @file This file defines all the functions used for
25 #include "nr5g_fapi_memory.h"
27 #include <rte_memcpy.h>
29 #include "nr5g_fapi_wls.h"
31 inline uint8_t nr5g_fapi_memcpy_bound_check(
37 // Memory block size and destination/source boundary check
38 if ((n >= (MSG_MAXSIZE)) || (n > x)) {
40 ("[MEMCPY FAILED] %s : %d : max block size: %d, memcpy dst size: %ld, memcpy src size: %ld\n",
41 __func__, __LINE__, MSG_MAXSIZE, x, n);
44 // Overlap check: source pointer overruns destination pointer
45 if ((char *)s < (char *)d) {
46 if ((((char *)s + x) >= (char *)d) || (((char *)s + n) >= (char *)d)) {
47 printf("[MEMCPY FAILED] %s : %d : max block size: %d, \
48 memcpy dst size: %ld, strcpy src size: %ld, \
49 Source pointer %p overlaps into destination pointer %p\n", __func__, __LINE__, MSG_MAXSIZE, x, n, s, d);
53 // Overlap check: destination pointer overruns source pointer
54 if ((char *)d < (char *)s) {
55 if ((((char *)d + x) >= (char *)s) || (((char *)d + n) >= (char *)s)) {
56 printf("[MEMCPY FAILED] %s : %d : max block size: %d, \
57 memcpy dst size: %ld, strcpy src size: %ld, \
58 Destination pointer %p overlaps into source pointer %p\n", __func__, __LINE__, MSG_MAXSIZE, x, n, d, s);
66 inline uint8_t nr5g_fapi_memset_bound_check(
72 // Memory block size and destination/source boundary check
73 if ((n >= MSG_MAXSIZE) || (n > x)) {
75 ("[MEMSET FAILED] %s : %d : max block size: %d, memset dst size: %ld, memset src size: %ld\n",
76 __func__, __LINE__, MSG_MAXSIZE, x, n);
83 inline uint8_t nr5g_fapi_strcpy_bound_check(
89 // Memory block size and destination/source boundary check
90 if ((n >= MSG_MAXSIZE) || (n > x)) {
91 printf("[STRNCPY FAILED] %s : %d : max block size: %d, \
92 strcpy dst size: %ld, strcpy src size: %ld\n", __func__, __LINE__, MSG_MAXSIZE, x, n);
95 // Overlap check: source pointer overruns destination pointer
96 if ((char *)s < (char *)d) {
97 if ((((char *)s + x) >= (char *)d) || (((char *)s + n) >= (char *)d)) {
98 printf("[STRNCPY FAILED] %s : %d : max block size: %d, \
99 strcpy dst size: %ld, strcpy src size: %ld, \
100 Source pointer %p overlaps into destination pointer %p\n", __func__, __LINE__, MSG_MAXSIZE, x, n, s, d);
104 // Overlap check: destination pointer overruns source pointer
105 if ((char *)d < (char *)s) {
106 if ((((char *)d + x) >= (char *)s) || (((char *)d + n) >= (char *)s)) {
107 printf("[STRNCPY FAILED] %s : %d : max block size: %d, \
108 strcpy dst size: %ld, strcpy src size: %ld, \
109 Destination pointer %p overlaps into source pointer %p\n", __func__, __LINE__, MSG_MAXSIZE, x, n, d, s);