1 /* 2 * Copyright (c) 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 TEST_WRAPPER_H 16 #define TEST_WRAPPER_H 17 #include <stdarg.h> 18 #include <stdint.h> 19 #include <stdio.h> 20 #include <stdlib.h> 21 #include <sys/stat.h> 22 #include <linux/fs.h> 23 #include <errno.h> 24 #ifdef __cplusplus 25 #if __cplusplus 26 extern "C" { 27 #endif 28 #endif 29 30 // for wrapper strdup; 31 char* __real_strdup(const char* string); 32 typedef char* (*StrdupFunc)(const char* string); 33 void UpdateStrdupFunc(StrdupFunc func); 34 35 // for wrapper malloc; 36 void* __real_malloc(size_t size); 37 typedef void* (*MallocFunc)(size_t size); 38 void UpdateMallocFunc(MallocFunc func); 39 40 // for wrapper strncat_s; 41 int __real_strncat_s(char *strDest, size_t destMax, const char *strSrc, size_t count); 42 typedef int (*StrncatSFunc)(char *strDest, size_t destMax, const char *strSrc, size_t count); 43 void UpdateStrncatSFunc(StrncatSFunc func); 44 45 // for wrapper mkdir; 46 int __real_mkdir(const char *path, mode_t mode); 47 typedef int (*MkdirFunc)(const char *path, mode_t mode); 48 void UpdateMkdirFunc(MkdirFunc func); 49 50 // for wrapper mount; 51 int __real_mount(const char *source, const char *target, const char *fsType, unsigned long flags, const void *data); 52 typedef int (*MountFunc)(const char *source, const char *target, 53 const char *fsType, unsigned long flags, const void *data); 54 void UpdateMountFunc(MountFunc func); 55 56 // for wrapper stat; 57 int __real_stat(const char *pathname, struct stat *buf); 58 typedef int (*StatFunc)(const char *pathname, struct stat *buf); 59 void UpdateStatFunc(StatFunc func); 60 61 // for wrapper snprintf_s; 62 typedef size_t (*SnprintfSFunc)(char *strDest, size_t destMax, size_t count, const char *format, va_list args); 63 void UpdateSnprintfSFunc(SnprintfSFunc func); 64 65 // for wrapper open; 66 int __real_open(const char *pathname, int flag); 67 typedef int (*OpenFunc)(const char *pathname, int flag); 68 void UpdateOpenFunc(OpenFunc func); 69 70 // for wrapper close; 71 int __real_close(int fd); 72 typedef int (*CloseFunc)(int fd); 73 void UpdateCloseFunc(CloseFunc func); 74 75 // for wrapper strcpy_s; 76 int __real_strcpy_s(char *dest, size_t destMax, const char *src); 77 typedef int (*StrcpySFunc)(char *dest, size_t destMax, const char *src); 78 void UpdateStrcpySFunc(StrcpySFunc func); 79 80 // for wrapper ioctl; 81 int __real_ioctl(int fd, int req, ...); 82 typedef int (*IoctlFunc)(int fd, int req, va_list args); 83 void UpdateIoctlFunc(IoctlFunc func); 84 85 // for wrapper calloc; 86 void* __real_calloc(size_t m, size_t n); 87 typedef void* (*CallocFunc)(size_t m, size_t n); 88 void UpdateCallocFunc(CallocFunc func); 89 90 // for wrapper minor; 91 int __real_minor(dev_t dev); 92 typedef int (*MinorFunc)(dev_t dev); 93 void UpdateMinorFunc(MinorFunc func); 94 95 // for wrapper memset_s; 96 int __real_memset_s(void *dest, size_t destMax, int c, size_t count); 97 typedef int (*MemsetSFunc)(void *dest, size_t destMax, int c, size_t count); 98 void UpdateMemsetSFunc(MemsetSFunc func); 99 100 // for wrapper memcpy_s; 101 int __real_memcpy_s(void *dest, size_t destMax, const void *src, size_t count); 102 typedef int (*MemcpySFunc)(void *dest, size_t destMax, const void *src, size_t count); 103 void UpdateMemcpySFunc(MemcpySFunc func); 104 105 #ifdef __cplusplus 106 #if __cplusplus 107 } 108 #endif 109 #endif 110 #endif // TEST_WRAPPER_H