1 /** 2 * Copyright (c) 2023 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 <assert.h> 17 #include <stdint.h> 18 #include <stdio.h> 19 #include <stdlib.h> 20 21 static size_t g_count = 0; 22 static uint64_t g_type_id = 0; 23 static void *g_address = NULL; 24 static void *g_diag = NULL; 25 26 // Make sure the library crosses at least one kLibraryAlignment(=256KB) boundary. 27 char buf[1024 * 1024]; 28 29 // Mock a CFI-enabled library without relying on the compiler. __cfi_check(uint64_t call_site_type_id,void * target_addr,void * diag)30__attribute__((aligned(4096))) void __cfi_check(uint64_t call_site_type_id, 31 void *target_addr, void *diag) { 32 ++g_count; 33 g_type_id = call_site_type_id; 34 g_address = target_addr; 35 g_diag = diag; 36 } 37 get_count()38size_t get_count() { 39 return g_count; 40 } 41 get_type_id()42uint64_t get_type_id() { 43 return g_type_id; 44 } 45 get_address()46void *get_address() { 47 return g_address; 48 } 49 get_diag()50void *get_diag() { 51 return g_diag; 52 } 53 get_global_address()54void *get_global_address() { 55 return &g_count; 56 } 57