[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Kernel Extensions and Device Support Programming Concepts

Accessing User-Mode Data While in Kernel Mode

Kernel extensions must use a set of kernel services to access data that is in the user-mode protection domain. These services ensure that the caller has the authority to perform the desired operation at the time of data access and also prevent system crashes in a system call when accessing user-mode data. These services can be called only when running in the process environment of the process that contains the user-mode data. For more information on user-mode protection, see User Protection Domain. For more information on the process environment, see Process Environment.

Data Transfer Services

The following list shows user-mode data access kernel services (primitives):

Kernel Service Purpose
suword, suword64 Stores a word of data in user memory.
fubyte, fubyte64 Fetches, or retrieves, a byte of data from user memory.
fuword, fuword64 Fetches, or retrieves, a word of data from user memory.
copyin, copyin64 Copies data between user and kernel memory.
copyout, copyout64 Copies data between user and kernel memory.
copyinstr, copyinstr64 Copies a character string (including the terminating null character) from user to kernel space.

Additional kernel services allow data transfer between user mode and kernel mode when a uio structure is used, thereby describing the user-mode data area to be accessed. All addresses on the 32-bit kernel, with the exception of addresses ending in "64", passed into these services must be remapped. Following is a list of services that typically are used between the file system and device drivers to perform device I/O:

Kernel Service Purpose
uiomove Moves a block of data between kernel space and a space defined by a uio structure.
ureadc Writes a character to a buffer described by a uio structure.
uwritec Retrieves a character from a buffer described by a uio structure.

The services ending in "64" are not supported in the 64-bit kernel, since all pointers are already 64-bits wide. The services without the "64" can be used instead. To allow common source code to be used, macros are provided in the sys/uio.h header file that redefine these special services to their general counterparts when compiling in 64-bit mode.

Using Cross-Memory Kernel Services

Occasionally, access to user-mode data is required when not in the environment of the user-mode process that has addressability to the data. Such cases occur when the data is to be accessed asynchronously. Examples of asynchronous accessing include:

In these circumstances, the kernel cross-memory services are required to provide the necessary access. The xmattach and xmattach64 kernel services allow a cross-memory descriptor to be obtained for the data area to be accessed. These services must be called in the process environment of the process containing the data area.

Note
xmattach64 is not supported on the 64-bit kernel.

After a cross-memory descriptor has been obtained, the xmemin and xmemout kernel services can be used to access the data area outside the process environment containing the data. When access to the data area is no longer required, the access must be removed by calling the xmdetach kernel service. Kernel extensions should use these services only when absolutely necessary. Because of the machine dependencies of cross-memory operations, using them increases the difficulty of porting the kernel extension to other machine platforms.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]