1 /******************************************************************************
3 * Copyright (c) 2019 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 <rte_memcpy.h>
27 #include "nr5g_fapi_wls.h"
29 inline uint8_t nr5g_fapi_memcpy_bound_check(
35 // Memory block size and destination/source boundary check
36 if ((n >= (MSG_MAXSIZE)) || (n > x)) {
38 ("[MEMCPY FAILED] %s : %d : max block size: %d, memcpy dst size: %ld, memcpy src size: %ld\n",
39 __func__, __LINE__, MSG_MAXSIZE, x, n);
42 // Overlap check: source pointer overruns destination pointer
43 if ((char *)s < (char *)d) {
44 if ((((char *)s + x) >= (char *)d) || (((char *)s + n) >= (char *)d)) {
45 printf("[MEMCPY FAILED] %s : %d : max block size: %d, \
46 memcpy dst size: %ld, strcpy src size: %ld, \
47 Source pointer %p overlaps into destination pointer %p\n", __func__, __LINE__, MSG_MAXSIZE, x, n, s, d);
51 // Overlap check: destination pointer overruns source pointer
52 if ((char *)d < (char *)s) {
53 if ((((char *)d + x) >= (char *)s) || (((char *)d + n) >= (char *)s)) {
54 printf("[MEMCPY FAILED] %s : %d : max block size: %d, \
55 memcpy dst size: %ld, strcpy src size: %ld, \
56 Destination pointer %p overlaps into source pointer %p\n", __func__, __LINE__, MSG_MAXSIZE, x, n, d, s);
64 inline uint8_t nr5g_fapi_memset_bound_check(
70 // Memory block size and destination/source boundary check
71 if ((n >= MSG_MAXSIZE) || (n > x)) {
73 ("[MEMSET FAILED] %s : %d : max block size: %d, memset dst size: %ld, memset src size: %ld\n",
74 __func__, __LINE__, MSG_MAXSIZE, x, n);
81 inline uint8_t nr5g_fapi_strcpy_bound_check(
87 // Memory block size and destination/source boundary check
88 if ((n >= MSG_MAXSIZE) || (n > x)) {
89 printf("[STRNCPY FAILED] %s : %d : max block size: %d, \
90 strcpy dst size: %ld, strcpy src size: %ld\n", __func__, __LINE__, MSG_MAXSIZE, x, n);
93 // Overlap check: source pointer overruns destination pointer
94 if ((char *)s < (char *)d) {
95 if ((((char *)s + x) >= (char *)d) || (((char *)s + n) >= (char *)d)) {
96 printf("[STRNCPY FAILED] %s : %d : max block size: %d, \
97 strcpy dst size: %ld, strcpy src size: %ld, \
98 Source pointer %p overlaps into destination pointer %p\n", __func__, __LINE__, MSG_MAXSIZE, x, n, s, d);
102 // Overlap check: destination pointer overruns source pointer
103 if ((char *)d < (char *)s) {
104 if ((((char *)d + x) >= (char *)s) || (((char *)d + n) >= (char *)s)) {
105 printf("[STRNCPY FAILED] %s : %d : max block size: %d, \
106 strcpy dst size: %ld, strcpy src size: %ld, \
107 Destination pointer %p overlaps into source pointer %p\n", __func__, __LINE__, MSG_MAXSIZE, x, n, d, s);