I've used 2 machine debugging and got some clue that kext is getting unloaded automatically on a separate thread. Here is the Panic log and thread info. There seems to race condition scenario , kext is releasing memory and and trying to access it.
(gdb) paniclog
panic(cpu 1 caller 0x001A7BED): Kernel trap at 0x3463df78, type 14=page fault, registers:
CR0: 0x8001003b, CR2: 0x3487da00, CR3: 0x01015000, CR4: 0x00000660
EAX: 0x3487da00, EBX: 0x3487da00, ECX: 0x00508444, EDX: 0xffffffff
CR2: 0x3487da00, EBP: 0x2e5a7228, ESI: 0x00000000, EDI: 0x3466efa0
EFL: 0x00010206, EIP: 0x3463df78, CS: 0x00000008, DS: 0x00000010
Error code: 0x00000000
Backtrace, Format - Frame : Return Address (4 potential args on stack)
0x2e5a7038 : 0x12b0e1 (0x455670 0x2e5a706c 0x133238 0x0)
0x2e5a7088 : 0x1a7bed (0x45ea20 0x3463df78 0xe 0x45e1d4)
0x2e5a7168 : 0x19e517 (0x2e5a7180 0x5881554 0x2e5a7228 0x3463df78)
0x2e5a7178 : 0x3463df78 (0xe 0x48 0x10 0x1a0010)
0x2e5a7228 : 0x3463e13d (0x3487da00 0x0 0x5fa9f 0x2e5a725c)
0x2e5a7248 : 0x3463ecb2 (0x3487da00 0x0 0x3465d6cc 0x3465d684)
0x2e5a7298 : 0x3464a5ab (0x3488ca58 0x348b7400 0x0 0x1)
0x2e5a7328 : 0x3464aca7 (0x18000 0x0 0x34660a28 0x3488ca18)
0x2e5a7398 : 0x3464812d (0x348d4600 0xb 0x3465ff60 0x3465c3d0)
0x2e5a73c8 : 0x3463a68e (0x2e5a7a28 0x2e5a7a5c 0x3465c298 0x3465c284)
0x2e5a7418 : 0x3463d3f2 (0x2e5a7a5c 0x2e5a7944 0x4da4964 0x0)
0x2e5a7a78 : 0x1f0f56 (0x2e5a7d4c 0x1 0xffffffff 0x31bd8c)
0x2e5a7d78 : 0x1f38d1 (0x50101b0 0x2e5a7e6c 0x4da4964 0x2e5a7ed0)
0x2e5a7dd8 : 0x3713db (0x50101b0 0x2e5a7e6c 0x4da4964 0x0)
0x2e5a7f78 : 0x3da847 (0x45494d0 0x4da4860 0x4da48a4 0x0)
0x2e5a7fc8 : 0x19ea34 (0x5f89960 0x0 0x1a10b5 0x5f89960)
Backtrace continues...
Kernel loadable modules in backtrace (with dependencies):
com.yourcompany.kext.genericDriver(1.0.0d1)@0x34639000->0x34679fff
BSD process name corresponding to current thread: mdworker
Mac OS version:
9B18
---- One of Thread Calls--
#11 0x3463debc in cleanup_module () at /Users/janakiram/Desktop/MyApp/trunk/platforms/darwin/host/fp.c:1687
#12 0x3463df57 in genericDriver_stop (ki=0x4bb4d00, d=0x0) at /Users/janakiram/Desktop/MyApp/trunk/platforms/darwin/host/fp.c:1951
#13 0x0041918c in IOCatalogue::unloadModule (this=0x3d6c1e0, moduleName=0x4bda020) at /SourceCache/xnu/xnu-
1228.0.2/iokit/Kernel/IOCatalogue.cpp:1254
#14 0x00419705 in IOCatalogue::terminateDriversForModule (this=0x1743f78, moduleName=0x4bda020, unload=true) at /SourceCache/xnu/xnu-1228.0.2/iokit/Kernel/IOCatalogue.cpp:1392
#15 0x00419769 in IOCatalogue::terminateDriversForModule (this=0x3d6c1e0, moduleName=0x1 <Address 0x1 out of bounds>, unload=false) at /SourceCache/xnu/xnu-1228.0.2/iokit/Kernel/IOCatalogue.cpp:1413
#16 0x0018a38a in _Xio_catalog_terminate (InHeadP=0xe00002c2, OutHeadP=0x0) at device/device_server.c:7313
#17 0x0012d165 in ipc_kobject_server (request=0x5166800) at /SourceCache/xnu/xnu-1228.0.2/osfmk/kern/ipc_kobject.c:331
#18 0x00126247 in mach_msg_overwrite_trap (args=0x1) at /SourceCache/xnu/xnu-
1228.0.2/osfmk/ipc/mach_msg.c:1623
#19 0x00196afc in mach_call_munger (state=0x485dee0) at /SourceCache/xnu/xnu-1228.0.2/osfmk/i386/bsd_i386.c:709
#20 0x0019eb34 in lo_mach_scall () at pmap.h:176
When does a kext will be unloaded automatically ? What could be the reasons ?
Is there any way i can avoid my kext unload after waking it from sleep ? . Do i need to handle system sleep/wake up from my Kext ?.
Please help me to solve this. Thanks in Advance.
-JanakiRam.