Re: IOKit KEXT Won't Load If Start Code Tries to Attach and Register?
Re: IOKit KEXT Won't Load If Start Code Tries to Attach and Register?
- Subject: Re: IOKit KEXT Won't Load If Start Code Tries to Attach and Register?
- From: Godfrey van der Linden <email@hidden>
- Date: Wed, 13 Jun 2007 12:14:13 +1000
As Mike surmised you may be tripping over a recursive match. You are
probably going to match on your self as you are publishing an IOMedia
object and matching on them too, I can't see anyway of breaking out
of the recursion (except for the Physical.* tags in the matching
dictionary, but I'm not familiar with IOMedia matching so an expert
will need to comment).
A way to prove that you have gone into an infinite loop is to print a
short log message and go to sleep for 10 milliseconds on entry to
your start routine. This will give the kernel logger enough runtime
to send data to the system log.
Good luck
Godfrey
On 12/06/2007, at 16:01 , Chase Colman wrote:
I am working on an IOKit KEXT that blocks external USB drives that
are not
writable. When I try to load the KEXT my computer locks up with
everything
except for mouse movement, but this is only when it has the code that
attaches the media object and registers service. When I remove the
code that
attaches the media and registers the service the KEXT loads fine,
but blocks
all drives including the read-only ones that I want.
The code I will give is heavily based off of the SampleFilterScheme
example.
The attachMediaObjectToDeviceTree function is exactly the same as
the one
from the SampleFilterScheme example.
Declarations:
IOMedia* _childMedia;
UInt32 _partitionCount;
Code:
bool com_ChangeLater_driver_TouchDrives::start(IOService* provider) {
IOMedia* media = OSDynamicCast(IOMedia, provider);
assert(media);
if (super::start(provider)==false) return false;
IOMedia* childMedia = new IOMedia;
if (childMedia) {
if (childMedia->init(0,
media->getSize(),
media->getPreferredBlockSize(),
media->isEjectable(),
false,
false //Don't allow any write access.
)) {
_partitionCount++;
char name[24];
sprintf(name,"ChangeLater_External%ld",_partitionCount);
childMedia->setName(name);
char location[12];
sprintf(location,"%ld",_partitionCount);
childMedia->setLocation(location);
_childMedia=childMedia;
childMedia->attach(this);
if (media->isWritable()==false) {
DEBUG_LOG("about to attach");
(void) attachMediaObjectToDeviceTree(childMedia);
DEBUG_LOG("attached, about to register");
childMedia->registerService();
}
DEBUG_LOG("passed attach®");
return true;
} else {
childMedia->release();
childMedia=0;
}
}
return false;
}
Here is the IOKitPersonalities:
<key>CFBundleIdentifier</key>
<string>com.ChangeLater.driver.TouchDrives</string>
<key>IOClass</key>
<string>com_ChangeLater_driver_TouchDrives</string>
<key>IOProviderClass</key>
<string>IOMedia</string>
<key>Physical Interconnect</key>
<string>USB</string>
<key>Physical Interconnect Location</key>
<string>External</string>
<key>IOMatchCategory</key>
<string>IOStorage</string>
If anyone could help me figure out why it is locking up my system
instead of
attaching and registering, I would be very appreciative. A fix
would be good
too.
Thanks,
Chase
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden