]> git.saurik.com Git - apple/libdispatch.git/blob - src/shims.c
libdispatch-84.5.tar.gz
[apple/libdispatch.git] / src / shims.c
1 /*
2 * Copyright (c) 2008-2009 Apple Inc. All rights reserved.
3 *
4 * @APPLE_APACHE_LICENSE_HEADER_START@
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * @APPLE_APACHE_LICENSE_HEADER_END@
19 */
20
21 #include "internal.h"
22
23 void *
24 dispatch_mach_msg_get_context(mach_msg_header_t *msg)
25 {
26 mach_msg_context_trailer_t *tp;
27 void *context = NULL;
28
29 tp = (mach_msg_context_trailer_t *)((uint8_t *)msg + round_msg(msg->msgh_size));
30 if (tp->msgh_trailer_size >= (mach_msg_size_t)sizeof(mach_msg_context_trailer_t)) {
31 context = (void *)(uintptr_t)tp->msgh_context;
32 }
33
34 return context;
35 }
36
37 /*
38 * Raw Mach message support
39 */
40 boolean_t
41 _dispatch_machport_callback(mach_msg_header_t *msg, mach_msg_header_t *reply,
42 void (*callback)(mach_msg_header_t *))
43 {
44 mig_reply_setup(msg, reply);
45 ((mig_reply_error_t*)reply)->RetCode = MIG_NO_REPLY;
46
47 callback(msg);
48
49 return TRUE;
50 }
51
52 /*
53 * CFMachPort compatibility
54 */
55 boolean_t
56 _dispatch_CFMachPortCallBack(mach_msg_header_t *msg, mach_msg_header_t *reply,
57 void (*callback)(struct __CFMachPort *, void *msg, signed long size, void *))
58 {
59 mig_reply_setup(msg, reply);
60 ((mig_reply_error_t*)reply)->RetCode = MIG_NO_REPLY;
61
62 callback(NULL, msg, msg->msgh_size, dispatch_mach_msg_get_context(msg));
63
64 return TRUE;
65 }