L4Re - L4 Runtime Environment
shared_cap
Go to the documentation of this file.
1 // vim:set ft=cpp: -*- Mode: C++ -*-
2 /**
3  * \file
4  * Shared_cap / Shared_del_cap
5  */
6 /*
7  * (c) 2018 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  * Shared capability that implements automatic free and unmap of the capability
32  * selector.
33  *
34  * \tparam T Type of the object the capability refers to.
35  *
36  * This shared capability implements a counted reference to a
37  * capability selector. The capability shall be unmapped and freed
38  * when the reference count in the allocator goes to zero.
39  *
40  * \note This type is intended for users who implement a custom capability
41  * allocator; otherwise use L4Re::Util::Shared_cap.
42  */
43 template< typename T >
44 using Shared_cap = L4::Detail::Shared_cap_impl<T, Smart_count_cap<L4_FP_ALL_SPACES>>;
45 /// \copydoc Shared_cap
46 template< typename T >
47 using shared_cap = L4::Detail::Shared_cap_impl<T, Smart_count_cap<L4_FP_ALL_SPACES>>;
48 
49 /**
50  * Allocate a capability slot and wrap it in a Shared_cap.
51  *
52  * \tparam T Type of the object the capability refers to.
53  * \param ca Capability allocator to use.
54  *
55  * \note This function is intended for users who implement a custom capability
56  * allocator; otherwise use L4Re::Util::make_shared_cap<T>().
57  */
58 template< typename T >
59 Shared_cap<T>
60 make_shared_cap(L4Re::Cap_alloc *ca)
61 { return Shared_cap<T>(ca->alloc<T>(), ca); }
62 
63 /**
64  * Shared capability that implements automatic free and unmap+delete of the
65  * capability selector.
66  *
67  * \tparam T Type of the object the capability refers to.
68  *
69  * This shared capability implements a counted reference to a capability
70  * selector. The capability shall be unmapped and freed when the reference
71  * count in the allocator goes to zero.
72  * The main difference to Shared_cap is that the unmap is done with the
73  * deletion flag enabled and this leads to the deletion of the object
74  * if the current task holds appropriate deletion rights.
75  *
76  * \note This type is intended for users who implement a custom capability
77  * allocator; otherwise use L4Re::Util::Shared_del_cap.
78  */
79 template< typename T >
80 using Shared_del_cap = L4::Detail::Shared_cap_impl<T, Smart_count_cap<L4_FP_DELETE_OBJ>>;
81 /// \copydoc Shared_del_cap
82 template<typename T>
83 using shared_del_cap = L4::Detail::Shared_cap_impl<T, Smart_count_cap<L4_FP_DELETE_OBJ>>;
84 
85 /**
86  * Allocate a capability slot and wrap it in a Shared_del_cap.
87  *
88  * \tparam T Type of the object the capability refers to.
89  * \param ca Capability allocator to use.
90  *
91  * \note This function is intended for users who implement a custom capability
92  * allocator; otherwise use L4Re::Util::make_shared_del_cap<T>().
93  */
94 template< typename T >
95 Shared_del_cap<T>
96 make_shared_del_cap(L4Re::Cap_alloc *ca)
97 { return Shared_del_cap<T>(ca->alloc<T>(), ca); }
98 
99 } // namespace L4Re