[ Previous | Next | Contents | Home | Search ]
AIX Version 4.3 Kernel Extensions and Device Support Programming Concepts

Accessing User-Mode Data While in Kernel Mode

Kernel extensions 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. These services also prevent system crashes in a system call when accessing user-mode data. These services can only be called when running in the process environment of the process that contains the user-mode data.

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, describes the user-mode data area to be accessed. (Note that this only works for 32-bit processes or with remapped addresses for 64-bit processes.) 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.

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 or xmattach64 kernel services allow a cross-memory descriptor to be obtained for the data area to be accessed. This service must be called in the process environment of the process containing the data area.

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.

Related Information

Understanding Locking.

Understanding Exception Handling.

The i_init kernel service, subyte kernel service, suword kernel service, fubyte kernel service, fuword kernel service, xmemin kernel service, xmemout kernel service, xmattach kernel service, xmdetach kernel service, copyin kernel service, copyout kernel service, copyinstr kernel service, uiomove kernel service, ureadc kernel service, and uwritec kernel service.

The uio structure.


[ Previous | Next | Contents | Home | Search ]