• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2019, The Linux Foundation. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *    * Redistributions of source code must retain the above copyright
8  *      notice, this list of conditions and the following disclaimer.
9  *    * Redistributions in binary form must reproduce the above
10  *      copyright notice, this list of conditions and the following
11  *      disclaimer in the documentation and/or other materials provided
12  *      with the distribution.
13  *    * Neither the name of The Linux Foundation nor the names of its
14  *      contributors may be used to endorse or promote products derived
15  *      from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 /*
31 =======================================================================
32 
33 FILE:         std_mem.c
34 
35 SERVICES:     apiOne std lib memory operations stuff
36 
37 */
38 
39 #include <string.h>
40 #include "AEEstd.h"
41 #include "AEEStdErr.h"
42 
43 #if defined __hexagon__
44 #include "stringl/stringl.h"
45 
46 //Add a weak reference so shared objects work with older images
47 #pragma weak memscpy
48 #pragma weak memsmove
49 #endif /*__hexagon__*/
50 
std_memset(void * p,int c,int nLen)51 void* std_memset(void* p, int c, int nLen)
52 {
53    if (nLen < 0) {
54       return p;
55    }
56    return memset(p, c, (size_t)nLen);
57 }
58 
std_memmove(void * pTo,const void * cpFrom,int nLen)59 void* std_memmove(void* pTo, const void* cpFrom, int nLen)
60 {
61    if (nLen <= 0) {
62       return pTo;
63    }
64 #ifdef __hexagon__
65    std_memsmove(pTo, (size_t)nLen, cpFrom, (size_t)nLen);
66    return pTo;
67 #else
68    return memmove(pTo, cpFrom, (size_t)nLen);
69 #endif
70 }
71 
std_memscpy(void * dst,int dst_size,const void * src,int src_size)72 int std_memscpy(void *dst, int dst_size, const void *src, int src_size){
73     size_t copy_size = 0;
74 
75     if(dst_size <0 || src_size <0){
76         return AEE_EBADSIZE;
77     }
78 
79 #if defined (__hexagon__)
80     if (memscpy){
81         return memscpy(dst,dst_size,src,src_size);
82     }
83 #endif
84 
85     copy_size = (dst_size <= src_size)? dst_size : src_size;
86     memcpy(dst, src, copy_size);
87     return copy_size;
88 }
89 
std_memsmove(void * dst,int dst_size,const void * src,int src_size)90 int std_memsmove(void *dst, int dst_size, const void *src, int src_size){
91     size_t copy_size = 0;
92 
93     if(dst_size <0 || src_size <0){
94         return AEE_EBADSIZE;
95     }
96 
97 #if defined (__hexagon__)
98     if (memsmove){
99         return memsmove(dst,dst_size,src,src_size);
100     }
101 #endif
102 
103     copy_size = (dst_size <= src_size)? dst_size : src_size;
104     memmove(dst, src, copy_size);
105     return copy_size;
106 }
107 
108