1 /* 2 * Copyright (c) 2024-2025 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 #ifndef STACK_UTILS_H 16 #define STACK_UTILS_H 17 18 #include <cstdio> 19 #include <csignal> 20 #include <cstring> 21 #include <memory> 22 23 namespace OHOS { 24 namespace HiviewDFX { 25 26 class StackUtils { 27 public: 28 static StackUtils& Instance(); 29 30 StackUtils(const StackUtils&) = delete; 31 StackUtils& operator=(const StackUtils&) = delete; 32 33 bool GetMainStackRange(uintptr_t& stackBottom, uintptr_t& stackTop) const; 34 bool GetArkStackRange(uintptr_t& start, uintptr_t& end) const; 35 static bool GetSelfStackRange(uintptr_t& stackBottom, uintptr_t& stackTop); 36 private: 37 struct MapRange { IsValidMapRange38 bool IsValid() const 39 { 40 return start != 0 && start < end; 41 } 42 uintptr_t start{0}; 43 uintptr_t end{0}; 44 }; 45 StackUtils(); 46 void ParseSelfMaps(); 47 MapRange mainStack_; 48 MapRange arkCode_; 49 }; 50 } // namespace HiviewDFX 51 } // namespace OHOS 52 #endif 53