• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3  * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this list of
9  *    conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12  *    of conditions and the following disclaimer in the documentation and/or other materials
13  *    provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16  *    to endorse or promote products derived from this software without specific prior written
17  *    permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _LOS_LMS_PRI_H
33 #define _LOS_LMS_PRI_H
34 
35 #include "los_lms.h"
36 #include "los_compiler.h"
37 #include "los_list.h"
38 #include "securec.h"
39 
40 #ifdef __cplusplus
41 #if __cplusplus
42 extern "C" {
43 #endif /* __cplusplus */
44 #endif /* __cplusplus */
45 
46 #define COMMON_ERRMODE  3
47 #define FREE_ERRORMODE  2
48 #define STORE_ERRMODE   1
49 #define LOAD_ERRMODE    0
50 
51 #define SANITIZER_INTERFACE_ATTRIBUTE
52 #define ATTRIBUTE_NO_SANITIZE_ADDRESS   __attribute__((no_sanitize_address))
53 
54 #define LMS_SHADOW_BITS_PER_CELL       2
55 #define LMS_MEM_BYTES_PER_SHADOW_CELL  4
56 #define LMS_SHADOW_U8_CELL_NUM         4
57 #define LMS_SHADOW_U8_REFER_BYTES      16
58 
59 #define LMS_POOL_RESIZE(size)          ((size) / (LMS_SHADOW_U8_REFER_BYTES + 1) * LMS_SHADOW_U8_REFER_BYTES)
60 #define LMS_ADDR_ALIGN(p)              (((UINTPTR)(p) + sizeof(UINTPTR) - 1) & ~((UINTPTR)(sizeof(UINTPTR) - 1)))
61 
62 #define LMS_SHADOW_ACCESSIBLE          0x00
63 #define LMS_SHADOW_AFTERFREE           0x03
64 #define LMS_SHADOW_REDZONE             0x02
65 #define LMS_SHADOW_PAINT               0x01
66 #define LMS_SHADOW_MASK                0x03
67 
68 #define LMS_SHADOW_ACCESSIBLE_U8       0x00
69 #define LMS_SHADOW_AFTERFREE_U8        0xFF
70 #define LMS_SHADOW_REDZONE_U8          0xAA
71 #define LMS_SHADOW_MASK_U8             0xFF
72 #define LMS_SHADOW_PAINT_U8            0x55
73 
74 #define MEM_REGION_SIZE_1              1
75 #define MEM_REGION_SIZE_2              2
76 #define MEM_REGION_SIZE_4              4
77 #define MEM_REGION_SIZE_8              8
78 #define MEM_REGION_SIZE_16             16
79 
80 typedef struct {
81     LOS_DL_LIST node;
82     UINT32 used;
83     UINTPTR poolAddr;
84     UINT32 poolSize;
85     UINTPTR shadowStart;
86     UINT32 shadowSize;
87 } LmsMemListNode;
88 
89 typedef struct {
90     UINTPTR memAddr;
91     UINTPTR shadowAddr;
92     UINT32 shadowOffset;
93     UINT32 shadowValue;
94 } LmsAddrInfo;
95 
96 typedef struct {
97     UINT32 (*init)(const VOID *pool, UINT32 size);
98     VOID (*deInit)(const VOID *pool);
99     VOID (*mallocMark)(const VOID *curNodeStart, const VOID *nextNodeStart, UINT32 nodeHeadSize);
100     VOID (*freeMark)(const VOID *curNodeStart, const VOID *nextNodeStart, UINT32 nodeHeadSize);
101     VOID (*simpleMark)(UINTPTR startAddr, UINTPTR endAddr, UINT32 value);
102     VOID (*check)(UINTPTR checkAddr, BOOL isFreeCheck);
103 } LmsHook;
104 extern LmsHook* g_lms;
105 
106 VOID OsLmsInit(VOID);
107 VOID OsLmsCheckValid(UINTPTR checkAddr, BOOL isFreeCheck);
108 VOID OsLmsLosMallocMark(const VOID *curNodeStart, const VOID *nextNodeStart, UINT32 nodeHeadSize);
109 VOID OsLmsLosFreeMark(const VOID *curNodeStart, const VOID *nextNodeStart, UINT32 nodeHeadSize);
110 VOID OsLmsSimpleMark(UINTPTR startAddr, UINTPTR endAddr, UINT32 value);
111 
112 VOID OsLmsPrintPoolListInfo(VOID);
113 VOID OsLmsReportError(UINTPTR p, UINT32 size, UINT32 errMod);
114 
115 VOID CheckValid(const CHAR *dest, const CHAR *src);
116 
117 extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_store1_noabort(UINTPTR p);
118 extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_store4_noabort(UINTPTR p);
119 extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_load4_noabort(UINTPTR p);
120 extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_load1_noabort(UINTPTR p);
121 extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_loadN_noabort(UINTPTR p, UINT32 size);
122 extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_storeN_noabort(UINTPTR p, UINT32 size);
123 extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_store2_noabort(UINTPTR p);
124 extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_load2_noabort(UINTPTR p);
125 extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_store8_noabort(UINTPTR p);
126 extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_load8_noabort(UINTPTR p);
127 extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_load16_noabort(UINTPTR p);
128 extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_store16_noabort(UINTPTR p);
129 extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_handle_no_return(VOID);
130 
131 #ifdef __cplusplus
132 #if __cplusplus
133 }
134 #endif /* __cplusplus */
135 #endif /* __cplusplus */
136 
137 #endif /* _LOS_LMS_PRI_H */
138