1 /* 2 * Copyright 2020, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _AUTO_DELETER_DRIVERS_H 6 #define _AUTO_DELETER_DRIVERS_H 7 8 9 #include <AutoDeleter.h> 10 #include <driver_settings.h> 11 12 #if defined(_KERNEL_MODE) && !defined(_BOOT_MODE) 13 #include <vfs.h> 14 #include <fs/fd.h> 15 #include <vm/VMAddressSpace.h> 16 #include <device_manager.h> 17 #endif 18 19 20 namespace BPrivate { 21 22 23 typedef CObjectDeleter<void, status_t, unload_driver_settings> 24 DriverSettingsUnloader; 25 26 #if defined(_KERNEL_MODE) && !defined(_BOOT_MODE) 27 28 typedef CObjectDeleter<struct vnode, void, vfs_put_vnode> VnodePutter; 29 typedef CObjectDeleter<file_descriptor, void, put_fd> FileDescriptorPutter; 30 typedef MethodDeleter<VMAddressSpace, void, &VMAddressSpace::Put> 31 VMAddressSpacePutter; 32 33 #if __GNUC__ >= 4 34 35 template <device_manager_info **deviceManager> 36 using DeviceNodePutter = MethodObjectDeleter<device_node, device_manager_info, 37 deviceManager, void, &device_manager_info::put_node>; 38 39 #else 40 41 template <device_manager_info **deviceManager> 42 struct DeviceNodePutter : MethodObjectDeleter<device_node, device_manager_info, 43 deviceManager, void, &device_manager_info::put_node> 44 { 45 typedef MethodObjectDeleter<device_node, device_manager_info, 46 deviceManager, void, &device_manager_info::put_node> Base; 47 48 DeviceNodePutter() : Base() {} 49 DeviceNodePutter(device_node* object) : Base(object) {} 50 }; 51 52 #endif 53 54 #endif 55 56 57 } 58 59 60 using ::BPrivate::DriverSettingsUnloader; 61 62 #if defined(_KERNEL_MODE) && !defined(_BOOT_MODE) 63 64 using ::BPrivate::VnodePutter; 65 using ::BPrivate::FileDescriptorPutter; 66 using ::BPrivate::VMAddressSpacePutter; 67 using ::BPrivate::DeviceNodePutter; 68 69 #endif 70 71 72 #endif // _AUTO_DELETER_DRIVERS_H 73