• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <FontUtils.h>
18 #include <unistd.h>
19 #include "../includes/common.h"
20 #include "../includes/memutils.h"
21 
22 using namespace minikin;
23 
24 char enable_selective_overload = ENABLE_NONE;
25 
26 bool isTestInProgress = false;
27 
28 struct sigaction new_action, old_action;
29 
sigsegv_handler(int signum,siginfo_t * info,void * context)30 void sigsegv_handler(int signum, siginfo_t *info, void* context) {
31     if (isTestInProgress && info->si_signo == SIGSEGV) {
32         (*old_action.sa_sigaction)(signum, info, context);
33         return;
34     }
35     _exit (EXIT_FAILURE);
36 }
37 
main()38 int main() {
39     sigemptyset(&new_action.sa_mask);
40     new_action.sa_flags = SA_SIGINFO;
41     new_action.sa_sigaction = sigsegv_handler;
42     sigaction(SIGSEGV, &new_action, &old_action);
43 
44     uint8_t majorVersion = 1;
45     uint8_t minorVersion = 0;
46     uint8_t axisOffset = 0x10;
47     uint8_t axisCount = 0xFF;
48     uint8_t axisSize = 0x14;
49 
50     size_t allocatedSize = sizeof(uint8_t) * 16;
51     enable_selective_overload = ENABLE_ALL;
52     uint8_t* fvarData = (uint8_t*) malloc(allocatedSize);
53     enable_selective_overload = ENABLE_FREE_CHECK | ENABLE_REALLOC_CHECK;
54     FAIL_CHECK(fvarData);
55     memset(fvarData, 0x0, allocatedSize);
56 
57     fvarData[1] = majorVersion;
58     fvarData[3] = minorVersion;
59     fvarData[5] = axisOffset;
60     fvarData[8] = axisCount;
61     fvarData[9] = axisCount;
62     fvarData[11] = axisSize;
63 
64     size_t fvarSize = axisOffset + axisOffset * ((axisCount << 8) | axisCount);
65     std::unordered_set < uint32_t > axes;
66     isTestInProgress = true;
67     analyzeAxes(fvarData, fvarSize, &axes);
68     isTestInProgress = false;
69     free(fvarData);
70     return EXIT_SUCCESS;
71 }
72