1 /* 2 * Copyright 2022, Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Copyright 2022, Jérôme Duval, jerome.duval@gmail.com 7 */ 8 9 10 #include <fcntl.h> 11 12 #include "strace.h" 13 #include "Syscall.h" 14 #include "TypeHandler.h" 15 16 17 struct fcntl_info { 18 unsigned int index; 19 const char *name; 20 TypeHandler *handler; 21 }; 22 23 #define FCNTL_INFO_ENTRY(name) \ 24 { name, #name, NULL } 25 26 #define FCNTL_INFO_ENTRY_TYPE(name, type) \ 27 { name, #name, TypeHandlerFactory<type>::Create() } 28 29 static const fcntl_info kFcntls[] = { 30 FCNTL_INFO_ENTRY_TYPE(F_DUPFD, int), 31 FCNTL_INFO_ENTRY(F_GETFD), 32 FCNTL_INFO_ENTRY_TYPE(F_SETFD, int), 33 FCNTL_INFO_ENTRY(F_GETFL), 34 FCNTL_INFO_ENTRY_TYPE(F_SETFL, int), 35 FCNTL_INFO_ENTRY_TYPE(F_GETLK, struct flock*), 36 FCNTL_INFO_ENTRY_TYPE(F_SETLK, struct flock*), 37 FCNTL_INFO_ENTRY_TYPE(F_SETLKW, struct flock*), 38 { 0, NULL, NULL } 39 }; 40 41 static EnumTypeHandler::EnumMap kFcntlNames; 42 static TypeHandlerSelector::SelectMap kFcntlTypeHandlers; 43 44 void 45 patch_fcntl() 46 { 47 for (int i = 0; kFcntls[i].name != NULL; i++) { 48 kFcntlNames[kFcntls[i].index] = kFcntls[i].name; 49 if (kFcntls[i].handler != NULL) 50 kFcntlTypeHandlers[kFcntls[i].index] = kFcntls[i].handler; 51 } 52 53 Syscall *fcntl = get_syscall("_kern_fcntl"); 54 55 fcntl->GetParameter("op")->SetHandler( 56 new EnumTypeHandler(kFcntlNames)); 57 fcntl->GetParameter("argument")->SetHandler( 58 new TypeHandlerSelector(kFcntlTypeHandlers, 59 1, TypeHandlerFactory<void *>::Create())); 60 } 61 62