WinCE6下的kernelIoControl使用方法
WinCE6下的kernelIoControl可不是誰都可以調的。
這個可能很多人曾經知道,但是老是忘記,比如我,哈哈。
kerneliocontrol以前在CE5下面耍慣了,用這個接口,AP簡直可以無法無天啊,動不動就reset你,哼!who怕who(AP不要 kernelicontrol還是可以無法無天,fullkernel啊,哈哈)
最近加了一個CE6下的kerneliocontrol,這種事情不曉得做過多少啦,所以信手拈來。
1.加IOCTL的code定義
2.加ioctl_tab.h里面的table里面code和function的關聯
3.加ioctl.c里面function的實現。
4.在AP里面調用kerneliocontrol,參數是code,試圖訪問這個function
結果發現,AP每次調用kerneliocontrol都是fail,但是參數全部正確啊,暈。
NND,毛了,在function里面加了一堆debug信息,重新出image,哼看你出不出來!
結果發現,壓根沒進function。
暈again!第一反應是哪里沒有加全或者有代碼修改了但是build不到位。
check了n遍,還是不行,開始懷疑自己老年癡呆了!?
迷茫中突然想到CE6之前不是有篇文章說過,AP不能隨便調用kerneliocontrol的。
逐翻出此文。發現果然有門道在其中,但是那篇文章不夠詳細,沒有告訴我怎么才能改變權限。
翻了翻BSP(CSP),果然找到真的有那么一個地方來決定哪些IOCTL的code是允許被AP call的。
PFN_Ioctl g_pfnExtOALIoctl;
//------------------------------------------------------------------------------
// Function: IOControl
//
// Arguments: Same signature as KernelIoControl
//??? DWORD dwIoControlCode: io control code
//??? PBYTE pInBuf: pointer to input buffer
//??? DWORD nInBufSize: length of input buffer in bytes
//??? PBYTE pOutBuf: pointer to out buffer
//??? DWORD nOutBufSize: length of output buffer in bytes
//??? PDWORD pBytesReturned: number of bytes returned in output buffer
//
// Return Values:
// If the function call is successful, TRUE is returned from this API call.
// If the function call is not successful, FALSE is returned from this API
// call and the last error is set to:
// a) ERROR_INVALID_PARAMETER: any of the input arguments are invalid
// b) ERROR_NOT_SUPPORTED: given ioctl is not supported
// c) any other ioctl set by OAL code
//
// Abstract:
// This is called by kernel whenever a user mode thread makes a call to
// KernelIoControl or KernelLibIoControl with io control code being an OAL
// io control code. OEMs can override what ioctls a user mode thread can call
// by enabling or disabling ioctl codes in this function.
//
//------------------------------------------------------------------------------
EXTERN_C
BOOL
IOControl(
??? DWORD dwIoControlCode,
??? PBYTE pInBuf,
??? DWORD nInBufSize,
??? PBYTE pOutBuf,
??? DWORD nOutBufSize,
??? PDWORD pBytesReturned
)
{
??? BOOL fRet = FALSE;
??? //
??? // By default the following ioctls are supported for user mode threads.
??? // If a new ioctl is being added to this list, make sure the corresponding
??? // data associated with that ioctl is marshalled properly to the OAL
??? // ioctl implementation. In normal cases, one doesn't need any
??? // marshaling as first level user specified buffers are already validated
??? // by kernel that:
??? // -- the buffers are within the user process space
??? // Check out IsValidUsrPtr() function in vmlayout.h for details on kernel
??? // validation of user specified buffers. Kernel doesn't validate that the
??? // buffers are accessible; it only checks that the buffer start and end
??? // addresses are within the user process space.
??? //
?
??? switch (dwIoControlCode)
??? {
??????? case IOCTL_HAL_GET_CACHE_INFO:
??????? case IOCTL_HAL_GET_DEVICE_INFO:
??????? case IOCTL_HAL_GET_DEVICEID:
??????? case IOCTL_HAL_GET_UUID:
??????? case IOCTL_PROCESSOR_INFORMATION:
??????? case IOCTL_SET_RTC_WAKEUP_TIME:
??????? case IOCTL_HAL_GET_SYS_CLOCK_INFO:
??????? case IOCTL_HAL_GET_BTMACADDR:
??????? case IOCTL_HAL_GET_CUSTOMERNUM:
??????? case IOCTL_HAL_GET_FURTURENUM:
??????? case IOCTL_HAL_GET_OEMVALUE:
??????? case IOCTL_HAL_REBOOT:
??????????? // request is to service the ioctl - forward the call to OAL code
??????????? // OAL code will set the last error if there is a failure
??????????? fRet = (*g_pfnExtOALIoctl)(dwIoControlCode, pInBuf, nInBufSize, pOutBuf, nOutBufSize, pBytesReturned);
??????????? break;
??????? default:
??????????? SetLastError(ERROR_NOT_SUPPORTED);
??????????? break;
??? }
??? return fRet;
}
在 case里面的IOCTL是運行被AP調用的,比如上面的 IOCTL_HAL_REBOOT。
里面還有一段英文注釋,意思大概是,AP調用的kerneliocontrol都會先到這里來集合,通過這里的switch case決定是否允許調用到正真的function.只要把你的IOCTL的code加到case里面,它才能被上層AP訪問。
kernel模式的驅動要call kerneliocontrol的話應該是直接調用到真正的ioctl,不需要跑到這個鬼地方來.?
?
總結
以上是生活随笔為你收集整理的WinCE6下的kernelIoControl使用方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 交行永达汽车信用卡使用指南:白送你洗车服
- 下一篇: 让S3c2410里拥有HIVE注册表的