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 #include "hook_so.h"
17
18 #pragma clang optimize off
19
20 namespace {
21 constexpr int DATA_SIZE = 200;
22 using StaticSpace = struct {
23 int data[DATA_SIZE];
24 };
25 }
26
DepthMallocSo(int depth,int mallocSize)27 char *DepthMallocSo(int depth, int mallocSize)
28 {
29 if (mallocSize <= 0) {
30 return nullptr;
31 }
32 StaticSpace staticeData;
33 if (depth == 0) {
34 staticeData.data[0] = 1;
35 return new char[mallocSize];
36 }
37 return (DepthMallocSo(depth - 1, mallocSize));
38 }
39
DepthFreeSo(int depth,char * p)40 void DepthFreeSo(int depth, char *p)
41 {
42 StaticSpace staticeData;
43 if (depth == 0) {
44 staticeData.data[0] = 1;
45 delete []p;
46 return;
47 }
48 return (DepthFreeSo(depth - 1, p));
49 }
50
51 #pragma clang optimize on