#include "internal.h"
void *
dispatch_mach_msg_get_context(mach_msg_header_t *msg)
{
mach_msg_context_trailer_t *tp;
void *context = NULL;
tp = (mach_msg_context_trailer_t *)((uint8_t *)msg + round_msg(msg->msgh_size));
if (tp->msgh_trailer_size >= (mach_msg_size_t)sizeof(mach_msg_context_trailer_t)) {
context = (void *)(uintptr_t)tp->msgh_context;
}
return context;
}
boolean_t
_dispatch_machport_callback(mach_msg_header_t *msg, mach_msg_header_t *reply,
void (*callback)(mach_msg_header_t *))
{
mig_reply_setup(msg, reply);
((mig_reply_error_t*)reply)->RetCode = MIG_NO_REPLY;
callback(msg);
return TRUE;
}
boolean_t
_dispatch_CFMachPortCallBack(mach_msg_header_t *msg, mach_msg_header_t *reply,
void (*callback)(struct __CFMachPort *, void *msg, signed long size, void *))
{
mig_reply_setup(msg, reply);
((mig_reply_error_t*)reply)->RetCode = MIG_NO_REPLY;
callback(NULL, msg, msg->msgh_size, dispatch_mach_msg_get_context(msg));
return TRUE;
}