[Windows Phone 7 Development and Hacking] spavlin:
CreateFile (Windows Embedded CE 6.0)

http://msdn.microsoft.com/en-us/library/ee490417(v=winembedded.60).aspx

---------- Post added at 11:30 PM ---------- Previous post was at 11:22 PM ----------

Windows CE 6.0: User Mode KernelIoControl

Created by samphung on 11/20/2010 10:54:27 PM

Windows CE 6.0 introduces some new security features including new meaning for User Mode and Kernel...

Windows CE 6.0 introduces some new security features including new meaning for User Mode and Kernel Mode. Loosely speaking, Kernel Mode has access to the system’s resources and User Mode is greatly restricted. One of the new restrictions on User Mode code is that calls to KernelIoControl are limited to the following OEMIoControl IOCTLs:

IOCTL_HAL_GET_CACHE_INFO

IOCTL_HAL_GET_DEVICE_INFO

IOCTL_HAL_GET_DEVICEID

IOCTL_HAL_GET_UUID

IOCTL_PROCESSOR_INFORMATION

As an OEM you can change this to allow access to other IOCTLs. The default restriction makes a lot of sense for consumer devices, but for closed systems or systems that the OEM wants to provide more functionality, there is a need to provide more IOCTLs for use from User Mode code.

User Mode code accesses these IOCTLS through a new oalioctl.dll. The code for oalioctl.dll is available in %_WINCEROOT%\Public\Common\Oak\Oalioctl, so I won’t publish the code here. But basically it has an IoControl function that has a switch statement which limits access to OEMIoControl(). So to add more IOCTLs, we need to clone the code and change the switch statement.

Buffered IO methods or named file mapping objects can be used; however, for simple device drivers the standard DeviceIoControl METHOD_ accesses are sufficient.

METHOD_IN_DIRECT: The buffer address is verified to be readable by the user mode caller.

METHOD_OUT_DIRECT: The buffer address is verified to be writable by the user mode caller.

METHOD_NEITHER: User mode virtual addresses are passed to the driver without mapping or validation.

METHOD_BUFFERED: IO Manager controlled shared buffers are used to move data to and from user mode.

OEM Adaptation Layer (Windows Embedded CE 6.0)

An OEM adaptation layer (OAL) is a layer of code that logically resides between the Windows Embedded CE kernel and the hardware of your target device. Physically, the OAL is linked with the kernel libraries to create the kernel executable file.

The OAL facilitates communication between your operating system (OS) and your target device and includes code to handle interrupts, timers, power management, bus abstraction, generic I/O control codes (IOCTLs), and so on.

Creating the OAL is one of the more complex tasks in the process of getting a Windows Embedded CE–based OS to run on a new hardware platform. In general, the easiest way to create an OAL is to copy the OAL implementation from a working OS design, and then modify it to suit the specific requirements of your hardware platform.

If you must create an OAL from the beginning, the task can be greatly simplified by approaching the development process in stages. Each stage adds a little more functionality than the previous one and provides a convenient separation point where new functionality can be fixed and validated before proceeding to the next step.

How to Develop an OEM Adaptation Layer (Windows Embedded CE 6.0)

http://msdn.microsoft.com/en-us/library/ee479387(v=winembedded.60).aspx

OEMIoControl (Windows Embedded CE 6.0)

http://msdn.microsoft.com/en-us/library/ee478941(v=winembedded.60).aspx

In Windows Embedded CE 6.0, calls to OEMIoControl go through a kernel mode component (oalioctl.dll). This component has a list of user-accessible OAL IOCTL codes. If the call from user application is for one of the IOCTLs listed in this module, then the call is forwarded to the OAL code. Otherwise the calls form user mode applications are rejected. This does not impact calls to OEMIoControl from kernel mode drivers.

OEM can add or delete an IOCTL code from this list by updating the following source file: %_WINCEROOT%\public\common\oak\oalioctl\oalioctl.cpp.

By default only the following OAL IOCTL codes are allowed from user mode applications:

IOCTL_HAL_GET_CACHE_INFO

IOCTL_HAL_GET_DEVICE_INFO

IOCTL_HAL_GET_DEVICEID

IOCTL_HAL_GET_UUID

IOCTL_PROCESSOR_INFORMATION

Starting with Windows Embedded CE 6.0, IOCTL_HAL_GET_DEVICEID and IOCTL_HAL_GET_UUID are deprecated. They have been functionally replaced by new SPI_* codes in IOCTL_HAL_GET_DEVICE_INFO.

Device Information IOCTL Unification (Windows Embedded CE 6.0)

http://msdn.microsoft.com/en-us/library/ee478557(v=winembedded.60).aspx

-------------------

original wp7 8773 \windows\OALIOCTL.dll DllMain IOControl View attachment 1033383