Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
IOServiceAddInterestNotification and messageClients - doc clarifications needed
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

IOServiceAddInterestNotification and messageClients - doc clarifications needed



Hi!

Having just spent half a day trying to figure out what was going on with my
code, I would like to request that whoever is responsible for documenting
the IOKit at Apple to add a couple of notes in either or both of:

IOService::messageClients()
IOServiceAddInterestNotification() (in IOKitLib)

...as well as the overall general interest Notification discussions in
IOKit.

The specific clarifications I would like to see regards passing arguments in
the messageClients() arg/argSize parameters. Very little is mentioned about
the argSize parameter anywhere, and I could find NOTHING, other than through
analysis of the IOKit and IOKitLib code itself, which would tell me about
the following behavior.

The documentation needs to make the following clear: If, on the sending
side, argSize is given as non-zero, but less than or equal to sizeof(void
*), then on the receiving side it is NOT sent as a pointer to the data -
instead the data is given as the pointer value. See
(IODispatchCalloutFromCFMessage() in IOKitLib.c for where this happens...)

Thus, if a driver calls:

unsigned long fred = 12345;
messageClients(kSomeTypeValue, &fred, sizeof(unsigned long));

...then for a user level callback declared as:

void myCallback(void *refcon, io_service_t service,
natural_t type, void *arg)

...then arg will be the value 12345, not a pointer to an unsigned long of
12345.


If a driver sends more than sizeof(void *), ie:

struct demo
{
long a, b, c, d, e;
} fred;
...
messageClients(kSomeTypeValue, &fred, sizeof(fred));

...then the callback will have arg be a pointer to a struct fred.


From looking at IOUserClient.cpp, it's also noteworthy that the maximum
length you can pass is kIOUserNotifyMaxMessageSize (ie, 64 bytes). Anything
past that is chopped off unceremoniously.


Finally, also from IOUserClient.cpp, if the same driver called:

messageClients(kSomeTypeValue, (void *)12345, 0);

...then the callback will once again have the value 12345, because an
argSize of zero causes the arg pointer to be used as a data value of length
sizeof(void *).


Hopefully this will save other people from banging their head against a wall
when they first try passing argument data from a driver to a user client...

-->Steve Bennett
_______________________________________________
darwin-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-development
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.