OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 #ifndef CRASHPAD_UTIL_MACH_MACH_MESSAGE_H_ | 15 #ifndef CRASHPAD_UTIL_MACH_MACH_MESSAGE_H_ |
16 #define CRASHPAD_UTIL_MACH_MACH_MESSAGE_H_ | 16 #define CRASHPAD_UTIL_MACH_MACH_MESSAGE_H_ |
17 | 17 |
18 #include <mach/mach.h> | 18 #include <mach/mach.h> |
19 #include <stdint.h> | 19 #include <stdint.h> |
20 | 20 |
21 namespace crashpad { | 21 namespace crashpad { |
22 | 22 |
| 23 //! \brief Special constants used as `mach_msg_timeout_t` values. |
| 24 enum : mach_msg_timeout_t { |
| 25 //! \brief When passed to MachMessageDeadlineFromTimeout(), that function will |
| 26 //! return #kMachMessageDeadlineNonblocking. |
| 27 kMachMessageTimeoutNonblocking = 0, |
| 28 |
| 29 //! \brief When passed to MachMessageDeadlineFromTimeout(), that function will |
| 30 //! return #kMachMessageDeadlineWaitIndefinitely. |
| 31 kMachMessageTimeoutWaitIndefinitely = 0xffffffff, |
| 32 }; |
| 33 |
23 //! \brief The time before which a MachMessageWithDeadline() call should | 34 //! \brief The time before which a MachMessageWithDeadline() call should |
24 //! complete. | 35 //! complete. |
25 //! | 36 //! |
26 //! A value of this type may be one of the special constants | 37 //! A value of this type may be one of the special constants |
27 //! #kMachMessageNonblocking or #kMachMessageWaitIndefinitely. Any other values | 38 //! #kMachMessageDeadlineNonblocking or #kMachMessageDeadlineWaitIndefinitely. |
28 //! should be produced by calling MachMessageDeadlineFromTimeout(). | 39 //! Any other values should be produced by calling |
| 40 //! MachMessageDeadlineFromTimeout(). |
29 //! | 41 //! |
30 //! Internally, these are currently specified on the same time base as | 42 //! Internally, these are currently specified on the same time base as |
31 //! ClockMonotonicNanoseconds(), although this is an implementation detail. | 43 //! ClockMonotonicNanoseconds(), although this is an implementation detail. |
32 using MachMessageDeadline = uint64_t; | 44 using MachMessageDeadline = uint64_t; |
33 | 45 |
34 //! \brief Special constants used as \ref MachMessageDeadline values. | 46 //! \brief Special constants used as \ref MachMessageDeadline values. |
35 enum : MachMessageDeadline { | 47 enum : MachMessageDeadline { |
36 //! \brief MachMessageWithDeadline() should not block at all in its operation. | 48 //! \brief MachMessageWithDeadline() should not block at all in its operation. |
37 kMachMessageNonblocking = 0, | 49 kMachMessageDeadlineNonblocking = 0, |
38 | 50 |
39 //! \brief MachMessageWithDeadline() should wait indefinitely for the | 51 //! \brief MachMessageWithDeadline() should wait indefinitely for the |
40 //! requested operation to complete. | 52 //! requested operation to complete. |
41 kMachMessageWaitIndefinitely = 0xffffffffffffffff, | 53 kMachMessageDeadlineWaitIndefinitely = 0xffffffffffffffff, |
42 }; | 54 }; |
43 | 55 |
44 //! \brief Computes the deadline for a specified timeout value. | 56 //! \brief Computes the deadline for a specified timeout value. |
45 //! | 57 //! |
46 //! While deadlines exist on an absolute time scale, timeouts are relative. This | 58 //! While deadlines exist on an absolute time scale, timeouts are relative. This |
47 //! function calculates the deadline as \a timeout_ms milliseconds after it | 59 //! function calculates the deadline as \a timeout_ms milliseconds after it |
48 //! executes. | 60 //! executes. |
49 //! | 61 //! |
50 //! If \a timeout_ms is `0`, this function will return #kMachMessageNonblocking. | 62 //! If \a timeout_ms is #kMachMessageDeadlineNonblocking, this function will |
| 63 //! return #kMachMessageDeadlineNonblocking. If \a timeout_ms is |
| 64 //! #kMachMessageTimeoutWaitIndefinitely, this function will return |
| 65 //! #kMachMessageDeadlineWaitIndefinitely. |
51 MachMessageDeadline MachMessageDeadlineFromTimeout( | 66 MachMessageDeadline MachMessageDeadlineFromTimeout( |
52 mach_msg_timeout_t timeout_ms); | 67 mach_msg_timeout_t timeout_ms); |
53 | 68 |
54 //! \brief Runs `mach_msg()` with a deadline, as opposed to a timeout. | 69 //! \brief Runs `mach_msg()` with a deadline, as opposed to a timeout. |
55 //! | 70 //! |
56 //! This function is similar to `mach_msg()`, with the following differences: | 71 //! This function is similar to `mach_msg()`, with the following differences: |
57 //! - The `timeout` parameter has been replaced by \a deadline. The deadline | 72 //! - The `timeout` parameter has been replaced by \a deadline. The deadline |
58 //! applies uniformly to a call that is requested to both send and receive | 73 //! applies uniformly to a call that is requested to both send and receive |
59 //! a message. | 74 //! a message. |
60 //! - The `MACH_SEND_TIMEOUT` and `MACH_RCV_TIMEOUT` bits in \a options are | 75 //! - The `MACH_SEND_TIMEOUT` and `MACH_RCV_TIMEOUT` bits in \a options are |
(...skipping 10 matching lines...) Expand all Loading... |
71 //! user-specified \a deadline. | 86 //! user-specified \a deadline. |
72 //! | 87 //! |
73 //! Except as noted, the parameters and return value are identical to those of | 88 //! Except as noted, the parameters and return value are identical to those of |
74 //! `mach_msg()`. | 89 //! `mach_msg()`. |
75 //! | 90 //! |
76 //! \param[in] deadline The time by which this call should complete. If the | 91 //! \param[in] deadline The time by which this call should complete. If the |
77 //! deadline is exceeded, this call will return `MACH_SEND_TIMED_OUT` or | 92 //! deadline is exceeded, this call will return `MACH_SEND_TIMED_OUT` or |
78 //! `MACH_RCV_TIMED_OUT`. | 93 //! `MACH_RCV_TIMED_OUT`. |
79 //! \param[in] run_even_if_expired If `true`, a deadline that is expired when | 94 //! \param[in] run_even_if_expired If `true`, a deadline that is expired when |
80 //! this function is called will be treated as though a deadline of | 95 //! this function is called will be treated as though a deadline of |
81 //! #kMachMessageNonblocking had been specified. When `false`, an expired | 96 //! #kMachMessageDeadlineNonblocking had been specified. When `false`, an |
82 //! deadline will result in a `MACH_SEND_TIMED_OUT` or `MACH_RCV_TIMED_OUT` | 97 //! expired deadline will result in a `MACH_SEND_TIMED_OUT` or |
83 //! return value, even if the deadline is already expired when the function | 98 //! `MACH_RCV_TIMED_OUT` return value, even if the deadline is already |
84 //! is called. | 99 //! expired when the function is called. |
85 mach_msg_return_t MachMessageWithDeadline(mach_msg_header_t* message, | 100 mach_msg_return_t MachMessageWithDeadline(mach_msg_header_t* message, |
86 mach_msg_option_t options, | 101 mach_msg_option_t options, |
87 mach_msg_size_t receive_size, | 102 mach_msg_size_t receive_size, |
88 mach_port_name_t receive_port, | 103 mach_port_name_t receive_port, |
89 MachMessageDeadline deadline, | 104 MachMessageDeadline deadline, |
90 mach_port_name_t notify_port, | 105 mach_port_name_t notify_port, |
91 bool run_even_if_expired); | 106 bool run_even_if_expired); |
92 | 107 |
93 //! \brief Initializes a reply message for a MIG server routine based on its | 108 //! \brief Initializes a reply message for a MIG server routine based on its |
94 //! corresponding request. | 109 //! corresponding request. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 //! | 144 //! |
130 //! \return A pointer to the trailer following the received Mach message’s body. | 145 //! \return A pointer to the trailer following the received Mach message’s body. |
131 //! The contents of the trailer depend on the options provided to | 146 //! The contents of the trailer depend on the options provided to |
132 //! `mach_msg()` or a similar function when the message was received. | 147 //! `mach_msg()` or a similar function when the message was received. |
133 const mach_msg_trailer_t* MachMessageTrailerFromHeader( | 148 const mach_msg_trailer_t* MachMessageTrailerFromHeader( |
134 const mach_msg_header_t* header); | 149 const mach_msg_header_t* header); |
135 | 150 |
136 } // namespace crashpad | 151 } // namespace crashpad |
137 | 152 |
138 #endif // CRASHPAD_UTIL_MACH_MACH_MESSAGE_H_ | 153 #endif // CRASHPAD_UTIL_MACH_MACH_MESSAGE_H_ |
OLD | NEW |