Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: util/mach/mach_message.h

Issue 773943002: Add MachMessageWithDeadline() and supporting characters (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@mach_message_util_move
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | util/mach/mach_message.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
20
21 #include <limits>
19 22
20 namespace crashpad { 23 namespace crashpad {
21 24
25 //! \brief The time before which a MachMessageWithDeadline() call should
26 //! complete.
27 //!
28 //! A value of this type may be one of the special constants
29 //! #kMachMessageNonblocking or #kMachMessageWaitIndefinitely. Any other values
30 //! should be produced by calling MachMessageDeadlineFromTimeout().
31 //!
32 //! Internally, these are currently specified on the same time base as
33 //! ClockMonotonicNanoseconds(), although this is an implementation detail.
34 using MachMessageDeadline = uint64_t;
35
36 //! \brief Special constants used as \ref MachMessageDeadline values.
37 enum : MachMessageDeadline {
38 //! \brief MachMessageWithDeadline() should not block at all in its operation.
39 kMachMessageNonblocking = 0,
40
41 //! \brief MachMessageWithDeadline() should wait indefinitely for the
42 //! requested operation to complete.
43 kMachMessageWaitIndefinitely =
44 std::numeric_limits<MachMessageDeadline>::max(),
45 };
46
47 //! \brief Computes the deadline for a specified timeout value.
48 //!
49 //! While deadlines exist on an absolute time scale, timeouts are relative. This
50 //! function calculates the deadline as \a timeout_ms milliseconds after it
51 //! executes.
52 //!
53 //! If \a timeout_ms is `0`, this function will return #kMachMessageNonblocking.
54 MachMessageDeadline MachMessageDeadlineFromTimeout(
55 mach_msg_timeout_t timeout_ms);
56
57 //! \brief Runs `mach_msg()` with a deadline, as opposed to a timeout.
58 //!
59 //! This function is similar to `mach_msg()`, with the following differences:
60 //! - The `timeout` parameter has been replaced by \a deadline. The deadline
61 //! applies uniformly to a call that is requested to both send and receive
62 //! a message.
63 //! - The `MACH_SEND_TIMEOUT` and `MACH_RCV_TIMEOUT` bits in \a options are
64 //! not used. Timeouts are specified by the \a deadline argument.
65 //! - The `send_size` parameter has been removed. Its value is implied by
66 //! \a message when \a options contains `MACH_SEND_MSG`.
67 //! - The \a run_even_if_expired parameter has been added.
68 //!
69 //! Like the `mach_msg()` wrapper in `libsyscall`, this function will retry
70 //! operations when experiencing `MACH_SEND_INTERRUPTED` and
71 //! `MACH_RCV_INTERRUPTED`, unless \a options contains `MACH_SEND_INTERRUPT` or
72 //! `MACH_RCV_INTERRUPT`. Unlike `mach_msg()`, which restarts the call with the
73 //! full timeout when this occurs, this function continues enforcing the
74 //! user-specified \a deadline.
75 //!
76 //! Except as noted, the parameters and return value are identical to those of
77 //! `mach_msg()`.
78 //!
79 //! \param[in] deadline The time by which this call should complete. If the
80 //! deadline is exceeded, this call will return `MACH_SEND_TIMED_OUT` or
81 //! `MACH_RCV_TIMED_OUT`.
82 //! \param[in] run_even_if_expired If `true`, a deadline that is expired when
83 //! this function is called will be treated as though a deadline of
84 //! #kMachMessageNonblocking had been specified. When `false`, an expired
85 //! deadline will result in a `MACH_SEND_TIMED_OUT` or `MACH_RCV_TIMED_OUT`
86 //! return value, even if the deadline is already expired when the function
87 //! is called.
88 mach_msg_return_t MachMessageWithDeadline(mach_msg_header_t* message,
89 mach_msg_option_t options,
90 mach_msg_size_t receive_size,
91 mach_port_name_t receive_port,
92 MachMessageDeadline deadline,
93 mach_port_name_t notify_port,
94 bool run_even_if_expired);
95
22 //! \brief Initializes a reply message for a MIG server routine based on its 96 //! \brief Initializes a reply message for a MIG server routine based on its
23 //! corresponding request. 97 //! corresponding request.
24 //! 98 //!
25 //! If a request is handled by a server routine, it may be necessary to revise 99 //! If a request is handled by a server routine, it may be necessary to revise
26 //! some of the fields set by this function, such as `msgh_size` and any fields 100 //! some of the fields set by this function, such as `msgh_size` and any fields
27 //! defined in a routine’s reply structure type. 101 //! defined in a routine’s reply structure type.
28 //! 102 //!
29 //! \param[in] in_header The request message to base the reply on. 103 //! \param[in] in_header The request message to base the reply on.
30 //! \param[out] out_header The reply message to initialize. \a out_header will 104 //! \param[out] out_header The reply message to initialize. \a out_header will
31 //! be treated as a `mig_reply_error_t*` and all of its fields will be set 105 //! be treated as a `mig_reply_error_t*` and all of its fields will be set
(...skipping 26 matching lines...) Expand all
58 //! 132 //!
59 //! \return A pointer to the trailer following the received Mach message’s body. 133 //! \return A pointer to the trailer following the received Mach message’s body.
60 //! The contents of the trailer depend on the options provided to 134 //! The contents of the trailer depend on the options provided to
61 //! `mach_msg()` or a similar function when the message was received. 135 //! `mach_msg()` or a similar function when the message was received.
62 const mach_msg_trailer_t* MachMessageTrailerFromHeader( 136 const mach_msg_trailer_t* MachMessageTrailerFromHeader(
63 const mach_msg_header_t* header); 137 const mach_msg_header_t* header);
64 138
65 } // namespace crashpad 139 } // namespace crashpad
66 140
67 #endif // CRASHPAD_UTIL_MACH_MACH_MESSAGE_H_ 141 #endif // CRASHPAD_UTIL_MACH_MACH_MESSAGE_H_
OLDNEW
« no previous file with comments | « no previous file | util/mach/mach_message.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698