xref: /aosp_15_r20/external/libchrome/mojo/public/c/system/quota.h (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1*635a8641SAndroid Build Coastguard Worker // Copyright 2018 The Chromium Authors. All rights reserved.
2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file.
4*635a8641SAndroid Build Coastguard Worker 
5*635a8641SAndroid Build Coastguard Worker #ifndef MOJO_PUBLIC_C_SYSTEM_QUOTA_H_
6*635a8641SAndroid Build Coastguard Worker #define MOJO_PUBLIC_C_SYSTEM_QUOTA_H_
7*635a8641SAndroid Build Coastguard Worker 
8*635a8641SAndroid Build Coastguard Worker #include <stdint.h>
9*635a8641SAndroid Build Coastguard Worker 
10*635a8641SAndroid Build Coastguard Worker #include "mojo/public/c/system/macros.h"
11*635a8641SAndroid Build Coastguard Worker #include "mojo/public/c/system/system_export.h"
12*635a8641SAndroid Build Coastguard Worker #include "mojo/public/c/system/types.h"
13*635a8641SAndroid Build Coastguard Worker 
14*635a8641SAndroid Build Coastguard Worker // Flags passed to |MojoSetQuota| via |MojoSetQuotaOptions|.
15*635a8641SAndroid Build Coastguard Worker typedef uint32_t MojoSetQuotaFlags;
16*635a8641SAndroid Build Coastguard Worker 
17*635a8641SAndroid Build Coastguard Worker // No flags.
18*635a8641SAndroid Build Coastguard Worker #define MOJO_SET_QUOTA_FLAG_NONE ((MojoSetQuotaFlags)0)
19*635a8641SAndroid Build Coastguard Worker 
20*635a8641SAndroid Build Coastguard Worker // Options passed to |MojoSetQuota()|.
21*635a8641SAndroid Build Coastguard Worker struct MOJO_ALIGNAS(8) MojoSetQuotaOptions {
22*635a8641SAndroid Build Coastguard Worker   // The size of this structure, used for versioning.
23*635a8641SAndroid Build Coastguard Worker   uint32_t struct_size;
24*635a8641SAndroid Build Coastguard Worker 
25*635a8641SAndroid Build Coastguard Worker   // See |MojoSetQuotaFlags| above.
26*635a8641SAndroid Build Coastguard Worker   MojoSetQuotaFlags flags;
27*635a8641SAndroid Build Coastguard Worker };
28*635a8641SAndroid Build Coastguard Worker MOJO_STATIC_ASSERT(sizeof(MojoSetQuotaOptions) == 8,
29*635a8641SAndroid Build Coastguard Worker                    "MojoSetQuotaOptions has wrong size.");
30*635a8641SAndroid Build Coastguard Worker 
31*635a8641SAndroid Build Coastguard Worker // Flags passed to |MojoQueryQuota| via |MojoQueryQuotaOptions|.
32*635a8641SAndroid Build Coastguard Worker typedef uint32_t MojoQueryQuotaFlags;
33*635a8641SAndroid Build Coastguard Worker 
34*635a8641SAndroid Build Coastguard Worker // No flags.
35*635a8641SAndroid Build Coastguard Worker #define MOJO_QUERY_QUOTA_FLAG_NONE ((MojoQueryQuotaFlags)0)
36*635a8641SAndroid Build Coastguard Worker 
37*635a8641SAndroid Build Coastguard Worker // Options passed to |MojoQueryQuota()|.
38*635a8641SAndroid Build Coastguard Worker struct MOJO_ALIGNAS(8) MojoQueryQuotaOptions {
39*635a8641SAndroid Build Coastguard Worker   // The size of this structure, used for versioning.
40*635a8641SAndroid Build Coastguard Worker   uint32_t struct_size;
41*635a8641SAndroid Build Coastguard Worker 
42*635a8641SAndroid Build Coastguard Worker   // See |MojoQueryQuotaFlags| above.
43*635a8641SAndroid Build Coastguard Worker   MojoQueryQuotaFlags flags;
44*635a8641SAndroid Build Coastguard Worker };
45*635a8641SAndroid Build Coastguard Worker MOJO_STATIC_ASSERT(sizeof(MojoQueryQuotaOptions) == 8,
46*635a8641SAndroid Build Coastguard Worker                    "MojoQueryQuotaOptions has wrong size.");
47*635a8641SAndroid Build Coastguard Worker 
48*635a8641SAndroid Build Coastguard Worker // The maximum value any quota can be set to. Effectively means "no quota".
49*635a8641SAndroid Build Coastguard Worker #define MOJO_QUOTA_LIMIT_NONE ((uint64_t)0xffffffffffffffff)
50*635a8641SAndroid Build Coastguard Worker 
51*635a8641SAndroid Build Coastguard Worker // An enumeration of different types of quotas that can be set on a handle.
52*635a8641SAndroid Build Coastguard Worker typedef uint32_t MojoQuotaType;
53*635a8641SAndroid Build Coastguard Worker 
54*635a8641SAndroid Build Coastguard Worker // Limits the number of unread messages which can be queued on a message pipe
55*635a8641SAndroid Build Coastguard Worker // endpoint before raising a |MOJO_HANDLE_SIGNAL_QUOTA_EXCEEDED| signal on that
56*635a8641SAndroid Build Coastguard Worker // endpoint. May only be set on message pipe handles.
57*635a8641SAndroid Build Coastguard Worker #define MOJO_QUOTA_TYPE_RECEIVE_QUEUE_LENGTH ((MojoQuotaType)0)
58*635a8641SAndroid Build Coastguard Worker 
59*635a8641SAndroid Build Coastguard Worker // Limits the total size (in bytes) of unread messages which can be queued on a
60*635a8641SAndroid Build Coastguard Worker // message pipe endpoint before raising a |MOJO_HANDLE_SIGNAL_QUOTA_EXCEEDED|
61*635a8641SAndroid Build Coastguard Worker // signal on that endpoint. May only be set on message pipe handles.
62*635a8641SAndroid Build Coastguard Worker #define MOJO_QUOTA_TYPE_RECEIVE_QUEUE_MEMORY_SIZE ((MojoQuotaType)1)
63*635a8641SAndroid Build Coastguard Worker 
64*635a8641SAndroid Build Coastguard Worker #ifdef __cplusplus
65*635a8641SAndroid Build Coastguard Worker extern "C" {
66*635a8641SAndroid Build Coastguard Worker #endif
67*635a8641SAndroid Build Coastguard Worker 
68*635a8641SAndroid Build Coastguard Worker // Sets a quota on a given handle which will cause that handle to raise the
69*635a8641SAndroid Build Coastguard Worker // |MOJO_HANDLE_SIGNAL_QUOTA_EXCEEDED| signal if the quota is exceeded. Signals
70*635a8641SAndroid Build Coastguard Worker // can be trapped using |MojoCreateTrap()| and related APIs (see trap.h).
71*635a8641SAndroid Build Coastguard Worker //
72*635a8641SAndroid Build Coastguard Worker // All quota limits on a handle default to |MOJO_QUOTA_LIMIT_NONE|, meaning that
73*635a8641SAndroid Build Coastguard Worker // the resource is unlimited.
74*635a8641SAndroid Build Coastguard Worker //
75*635a8641SAndroid Build Coastguard Worker // NOTE: A handle's quota is only enforced as long as the handle remains within
76*635a8641SAndroid Build Coastguard Worker // the process which set the quota.
77*635a8641SAndroid Build Coastguard Worker //
78*635a8641SAndroid Build Coastguard Worker // Parameters:
79*635a8641SAndroid Build Coastguard Worker //   |handle|: The handle on which a quota should be set.
80*635a8641SAndroid Build Coastguard Worker //   |type|: The type of quota to set. Certain types of quotas may only be set
81*635a8641SAndroid Build Coastguard Worker //       on certain types of handles. See notes on individual quota type
82*635a8641SAndroid Build Coastguard Worker //       definitions above for meaning and restrictions.
83*635a8641SAndroid Build Coastguard Worker //   |limit|: The limiting value of the quota. The meaning of this is determined
84*635a8641SAndroid Build Coastguard Worker //       by |type|. See notes on individual quota type definitions above.
85*635a8641SAndroid Build Coastguard Worker //   |options|: Additional options; may be null.
86*635a8641SAndroid Build Coastguard Worker //
87*635a8641SAndroid Build Coastguard Worker //  Returns:
88*635a8641SAndroid Build Coastguard Worker //    |MOJO_RESULT_OK| if the quota was successfully set.
89*635a8641SAndroid Build Coastguard Worker //    |MOJO_RESULT_INVALID_ARGUMENT| if |handle| is not a valid handle value,
90*635a8641SAndroid Build Coastguard Worker //        |type| is not a known quota type, |options| is non-null but
91*635a8641SAndroid Build Coastguard Worker //        |*options| is malformed, or the quota |type| cannot be set on |handle|
92*635a8641SAndroid Build Coastguard Worker //        because the quota does not apply to that type of handle.
93*635a8641SAndroid Build Coastguard Worker MOJO_SYSTEM_EXPORT MojoResult
94*635a8641SAndroid Build Coastguard Worker MojoSetQuota(MojoHandle handle,
95*635a8641SAndroid Build Coastguard Worker              MojoQuotaType type,
96*635a8641SAndroid Build Coastguard Worker              uint64_t limit,
97*635a8641SAndroid Build Coastguard Worker              const struct MojoSetQuotaOptions* options);
98*635a8641SAndroid Build Coastguard Worker 
99*635a8641SAndroid Build Coastguard Worker // Queries a handle for information about a specific quota.
100*635a8641SAndroid Build Coastguard Worker //
101*635a8641SAndroid Build Coastguard Worker // Parameters:
102*635a8641SAndroid Build Coastguard Worker //   |handle|: The handle to query.
103*635a8641SAndroid Build Coastguard Worker //   |type|: The type of quota to query.
104*635a8641SAndroid Build Coastguard Worker //   |limit|: Receives the quota's currently set limit if non-null.
105*635a8641SAndroid Build Coastguard Worker //   |usage|: Receives the quota's current usage if non-null.
106*635a8641SAndroid Build Coastguard Worker //
107*635a8641SAndroid Build Coastguard Worker // Returns:
108*635a8641SAndroid Build Coastguard Worker //   |MOJO_RESULT_OK| if the quota was successfully queried on |handle|. Upon
109*635a8641SAndroid Build Coastguard Worker //       return, |*limit| contains the quota's current limit if |limit| is
110*635a8641SAndroid Build Coastguard Worker //       non-null, and |*usage| contains the quota's current usage if |usage| is
111*635a8641SAndroid Build Coastguard Worker //       non-null.
112*635a8641SAndroid Build Coastguard Worker //   |MOJO_RESULT_INVALID_ARGUMENT| if |handle| is not a valid handle value or
113*635a8641SAndroid Build Coastguard Worker //       quota |type| does not apply to the type of object referenced by
114*635a8641SAndroid Build Coastguard Worker //       |handle|.
115*635a8641SAndroid Build Coastguard Worker MOJO_SYSTEM_EXPORT MojoResult
116*635a8641SAndroid Build Coastguard Worker MojoQueryQuota(MojoHandle handle,
117*635a8641SAndroid Build Coastguard Worker                MojoQuotaType type,
118*635a8641SAndroid Build Coastguard Worker                const struct MojoQueryQuotaOptions* options,
119*635a8641SAndroid Build Coastguard Worker                uint64_t* limit,
120*635a8641SAndroid Build Coastguard Worker                uint64_t* usage);
121*635a8641SAndroid Build Coastguard Worker 
122*635a8641SAndroid Build Coastguard Worker #ifdef __cplusplus
123*635a8641SAndroid Build Coastguard Worker }  // extern "C"
124*635a8641SAndroid Build Coastguard Worker #endif
125*635a8641SAndroid Build Coastguard Worker 
126*635a8641SAndroid Build Coastguard Worker #endif  // MOJO_PUBLIC_C_SYSTEM_QUOTA_H_
127