Wednesday 14 October 2009

Using WinCE APIs From Kernel OEM Routines

There are many occasions where you want to implement some functionality in a Kernel IOCTL or OEM kernel callback but you can't call the normal Windows CE API because you're in kernel space. So tasks such as setting or reading registry entries, creating events and signalling processes etc can't be done... or can they..?

Some of the basic API functions for this support are available but the functions have a prefix NK or K, for instance:

NKSleep()

NKRegCloseKey()
NKRegCreateKeyExW()
NKRegOpenKeyExW()
etc

Note that not all of these are documented, so for more information see:
\WINCE600\PUBLIC\COMMON\OAK\INC\nkexport.h

More advanced functions are available in:

\WINCE600\PRIVATE\WINCEOS\COREOS\NK\INC\syncobj.h

This is the publicly available Windows CE private kernel code, and includes event, Semaphores and even message queues!:

NKSetEvent
NKPulseEvent
NKResetEvent
NKCreateMsgQueue
etc!
So don't use flags and share memory, do it properly with some thread and process intercommunication! :)

4 comments:

Anonymous said...

It appears that the only things the kernel allows you to do from the OAL in CE6 are defined in nkglobal.h. Inter-process synchronization doesn't seem to be supported.

Have you personally used these functions from the OAL in CE6? I don't see a way to do it, but if you've done this I'd love to have more details.

GraemeW said...

You can definitely add your own routines in, the HALREBOOT is an example of something that did something very similar already in CE5.0. The routine is redirected to the power manager when then calls the kernel directly to ensure caches are flushed, take a look at the private code.

GraemeW said...

Ig anyone is having problems with using the kernel functions, try defining these:

extern PPROCESS g_pprcNK;

BOOL NKEventModify (PPROCESS pprc, HANDLE hEvent, DWORD type);

#define NKSetEvent(pprc, hEvt) NKEventModify (pprc, hEvt, EVENT_SET)

GraemeW said...

Ig anyone is having problems with using the kernel functions, try defining these:

extern PPROCESS g_pprcNK;

BOOL NKEventModify (PPROCESS pprc, HANDLE hEvent, DWORD type);

#define NKSetEvent(pprc, hEvt) NKEventModify (pprc, hEvt, EVENT_SET)