1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef HOOK_COMMON_H 17 #define HOOK_COMMON_H 18 19 #include "register.h" 20 #include "utilities.h" 21 22 #define MAX_THREAD_NAME (16) 23 #define MAX_UNWIND_DEPTH (30) 24 25 namespace OHOS { 26 namespace Developtools { 27 namespace NativeDaemon { 28 const int STACK_DATA_SIZE = 40000; 29 const int SPEED_UP_THRESHOLD = STACK_DATA_SIZE / 2; 30 const int SLOW_DOWN_THRESHOLD = STACK_DATA_SIZE / 4; 31 } 32 } 33 } 34 35 constexpr size_t kMaxRegSize = sizeof(uint64_t) 36 * OHOS::Developtools::NativeDaemon::PERF_REG_ARM64_MAX; 37 38 enum { 39 MALLOCDISABLE = (1u << 0), 40 MMAPDISABLE = (1u << 1), 41 FREEMSGSTACK = (1u << 2), 42 MUNMAPMSGSTACK = (1u << 3), 43 FPUNWIND = (1u << 4), 44 BLOCKED = (1u << 5), 45 }; 46 47 enum { 48 MALLOC_MSG = 0, 49 FREE_MSG, 50 MMAP_MSG, 51 MUNMAP_MSG, 52 MEMORY_TAG, 53 PR_SET_VMA_MSG, 54 }; 55 56 typedef struct alignas(8) { 57 union { 58 char regs[kMaxRegSize]; 59 uint64_t ip[MAX_UNWIND_DEPTH + 1]; 60 }; 61 char tname[MAX_THREAD_NAME]; 62 struct timespec ts; 63 void* addr; 64 size_t mallocSize; 65 uint32_t pid; 66 uint32_t tid; 67 uint32_t type; 68 } StackRawData; 69 70 typedef struct { 71 uint32_t filterSize_; 72 bool mallocDisable_; 73 bool mmapDisable_; 74 bool freeStackData_; 75 bool munmapStackData_; 76 uint8_t maxStackDepth_; 77 bool fpunwind_; 78 bool isBlocked; 79 } ClientConfig; 80 81 #endif // HOOK_SERVICE_H 82