L4Re - L4 Runtime Environment
unique_cap
Go to the documentation of this file.
1 // vim:set ft=cpp: -*- Mode: C++ -*-
2 /**
3  * \file
4  * Unique_cap / Unique_del_cap
5  */
6 /*
7  * (c) 2017 Alexander Warg <alexander.warg@kernkonzept.com>
8  *
9  * This file is part of TUD:OS and distributed under the terms of the
10  * GNU General Public License 2.
11  * Please see the COPYING-GPL-2 file for details.
12  *
13  * As a special exception, you may use this file as part of a free software
14  * library without restriction. Specifically, if other files instantiate
15  * templates or use macros or inline functions from this file, or you compile
16  * this file and link it with other files to produce an executable, this
17  * file does not by itself cause the resulting executable to be covered by
18  * the GNU General Public License. This exception does not however
19  * invalidate any other reasons why the executable file might be covered by
20  * the GNU General Public License.
21  */
22 
23 #pragma once
24 
25 #include <l4/re/cap_alloc>
26 #include <l4/sys/cxx/smart_capability_1x>
27 
28 namespace L4Re {
29 
30 /**
31  * Unique capability that implements automatic free and unmap of the
32  * capability selector.
33  *
34  * \tparam T Type of the object the capability refers to.
35  *
36  * The ownership of the capability is managed in the same way as unique_ptr.
37  *
38  * \note This type is intended for users who implement a custom capability
39  * allocator; otherwise use L4Re::Util::Unique_cap.
40  */
41 template< typename T >
42 using Unique_cap = L4::Detail::Unique_cap_impl<T, Smart_cap_auto<L4_FP_ALL_SPACES>>;
43 /// \copydoc Unique_cap
44 template< typename T >
45 using unique_cap = L4::Detail::Unique_cap_impl<T, Smart_cap_auto<L4_FP_ALL_SPACES>>;
46 
47 /**
48  * Allocate a capability slot and wrap it in an Unique_cap.
49  *
50  * \tparam T Type of the object the capability refers to.
51  * \param ca Capability allocator to use.
52  *
53  * \note This function is intended for users who implement a custom capability
54  * allocator; otherwise use L4Re::Util::make_unique_cap<T>().
55  */
56 template< typename T >
57 Unique_cap<T>
58 make_unique_cap(L4Re::Cap_alloc *ca)
59 { return Unique_cap<T>(ca->alloc<T>(), ca); }
60 
61 /**
62  * Unique capability that implements automatic free and unmap+delete of the
63  * capability selector.
64  *
65  * \tparam T Type of the object the capability refers to.
66  *
67  * The main difference to Unique_cap is that the unmap is done with the
68  * deletion flag enabled and this leads to the deletion of the object
69  * if the current task holds appropriate deletion rights.
70  *
71  * \note This type is intended for users who implement a custom capability
72  * allocator; otherwise use L4Re::Util::Unique_del_cap.
73  */
74 template< typename T >
75 using Unique_del_cap = L4::Detail::Unique_cap_impl<T, Smart_cap_auto<L4_FP_DELETE_OBJ>>;
76 /// \copydoc Unique_del_cap
77 template<typename T>
78 using unique_del_cap = L4::Detail::Unique_cap_impl<T, Smart_cap_auto<L4_FP_DELETE_OBJ>>;
79 
80 /**
81  * Allocate a capability slot and wrap it in an Unique_del_cap.
82  *
83  * \tparam T Type of the object the capability refers to.
84  * \param ca Capability allocator to use.
85  *
86  * \note This function is intended for users who implement a custom capability
87  * allocator; otherwise use L4Re::Util::make_unique_del_cap<T>().
88  */
89 template< typename T >
90 Unique_del_cap<T>
91 make_unique_del_cap(L4Re::Cap_alloc *ca)
92 { return Unique_del_cap<T>(ca->alloc<T>(), ca); }
93 
94 }