mach message

Questions and Answers about all things *OS (macOS, iOS, tvOS, watchOS)

mach message

Postby liorh » Wed May 16, 2018 2:23 pm

Hi,
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
liorh
 
Posts: 5
Joined: Wed May 16, 2018 2:03 pm

Re: mach message

Postby Siguza » Wed May 16, 2018 5:30 pm

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);
if(likely(!kr))
{
    _dispatch_kevent_mach_msg_recv(du, flags, hdr);
    goto out;
}

So what exactly is your issue?
User avatar
Siguza
Unicorn
 
Posts: 202
Joined: Thu Jan 28, 2016 10:38 am

Re: mach message

Postby liorh » Thu May 17, 2018 5:47 am

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.
Thanks
liorh
 
Posts: 5
Joined: Wed May 16, 2018 2:03 pm

Re: mach message

Postby morpheus » Thu May 17, 2018 11:53 am

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.
morpheus
Site Admin
 
Posts: 697
Joined: Thu Apr 11, 2013 6:24 pm

Re: mach message

Postby liorh » Thu May 17, 2018 1:18 pm

Thanks :)
liorh
 
Posts: 5
Joined: Wed May 16, 2018 2:03 pm


Return to Questions and Answers

Who is online

Users browsing this forum: No registered users and 7 guests