Page 1 of 1

mach message

PostPosted: Wed May 16, 2018 2:23 pm
by liorh
I am debugging a service that sends mach message to my application. The message is sent using mach_msg api, and when I checked the port number using procexp, I saw that the port is connected to my app. But, when I debug the app, the message doesn't arrive to any variant of mach_msg api. It eventually arrives functions in libdispatch, like _dispatch_kevent_mach_msg_recv.
Are you familiar with this situation?

Thanks, Haim

Re: mach message

PostPosted: Wed May 16, 2018 5:30 pm
by Siguza
That's the same thing.

Quoting libdispatch, src/event/event_kevent.c:
Code: Select all
kr = mach_msg(hdr, options, 0, siz, name, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
    _dispatch_kevent_mach_msg_recv(du, flags, hdr);
    goto out;

So what exactly is your issue?

Re: mach message

PostPosted: Thu May 17, 2018 5:47 am
by liorh
I am trying to find the first place that this message arrives my application.
The message does exist in the function you mentioned (_dispatch_kevent_mach_msg_drain), but the lines you specified are not being executed. The function calls _dispatch_kevent_mach_msg_recv from an earlier line, and then returns, so the mach_msg api is not called.

However, the function _dispatch_kevent_mach_msg_drain receives the message as a parameter (as part of the dispatch_kevent_t), and I want to find out how the application received this message at the first place. What is the system call that actually received it from the service.

Re: mach message

PostPosted: Thu May 17, 2018 11:53 am
by morpheus
Messages are commonly sent/received by the underlying Mach Traps (not BSD sys calls, but done through the same mechanism) of mach_msg (#31) or mach_msg_overwrite (#32). Either is used for both send and receive.

Dispatch queues work a bit differently, though. The kevent gets fired when a message is available, and the event filter gets prepopulated. See
filt_machport in XNU's /osfmk/ipc/ipc_pset.c.

Re: mach message

PostPosted: Thu May 17, 2018 1:18 pm
by liorh
Thanks :)