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

Files Reference


mem or kmem Special File

Purpose

Provides privileged virtual memory read and write access.

Description

Attention: When incorrect access to virtual memory is made through these files, process termination, a system crash, or loss of system data integrity can result.

The /dev/mem and /dev/kmem character special files provide access to a pseudo device driver that allows read and write access to system memory or I/O address space. Typically, these special files are used by operating system utilities and commands (such as sar, iostat, and vmstat) to obtain status and statistical information about the system.

Note: Programs accessing these special files must have appropriate privilege. Commercial application programs should avoid using the /dev/mem and /dev/kmem files, since the virtual memory image is quite specific to the operating system level and machine platform. Use of these special files thus seriously affects the portability of the application program to other systems.

Usage Considerations

kmem Special File Access

The kmem special file provides access to the virtual memory address space for the current process, as it is seen by the kernel. The seek offset, set by the lseek subroutine, is used to specify the virtual address targeted for the read or write. The kmem pseudo-device driver only supports the open, close, read, readx, writex, and write subroutines.

The knlist system subroutine is typically used to obtain the addresses of kernel symbols to read or write through access provided by the kmem special file.

Before issuing a read or write operation, the lseek subroutine must be used to designate the relevant starting address in virtual memory. If this address is within the first two gigabytes of address space, then the read or write subroutine calls can be used. However, if the upper two gigabytes of address space are to be accessed, the readx and writex form of the subroutine calls must be used. In this case, the ext (extension) parameter must be set to a value of True. This causes the lseek offset to be interpreted relative to the upper 2 gigabytes of address space.

Note: On the POWER-based platform, the process address space is defined as shown in the Implementation Specifics section. This address space layout can vary on other machine platforms and versions of the operating system.

mem Special File Access

Attention: Use of this special file by application programs should be strictly avoided, as it is provided for diagnostic and problem determination procedures only.

The mem special file access is specific to the system on which the operating system is running.

Please refer to the Implementation Specifics section for details on the function provided by this special file.

Implementation Specifics

The kmem special file is part of Base Operating System (BOS) Runtime.

Process Address Space Regions for the /dev/kmem Special File

The "Process Address Space Map" illustrates the layout of process address space regions as accessed through the /dev/kmem special file on this system.

Lower 2 gigabytyes of address space: Use read or write subrourines Upper 4 bits of lseek offset Process Address Space Regions
0 Primary Kernel Region
1 User Text Region
2 Process Private Region
3 Attached Data Mapped Files Region
4
5
6
7
Upper 2 gigabytyes of address space: Use readx or writex subroutines with ext parameter = TRUE. 0
1
2
3
4
5 Shared Library Text Region
6 Secondary Kernel Region
7 Shared Data Region

Implementation of mem Special File Access

The mem special file has traditionally provided direct access to physical memory. This capability and its interface requirements are machine-specific. However, for this operating system this function is indirectly provided by using the ext (extension) parameter on the readx and writex subroutine calls. When a readx or writex subroutine call associated with the /dev/mem special file is issued, the ext parameter must contain a valid segment register value as defined in the POWERstation and POWERserver Hardware Technical Reference - General Information documentation for the platform types(s) on which the program will be run. This allows the program to access all physical memory mapped by the page table as well as the platform-specific I/O (T=1) segments.

The seek offset set by the lseek subroutine call is used to specify the address offset within the segment described by the ext parameter. The upper four bits of the offset are not used. The pseudo-device driver only supports the open, close, read, readx, write, and writex subroutine calls. The lseek subroutine call must also be used before the readx or writex subroutine calls are issued, in order to specify the address offset.

If a read or write subroutine call is used with this special file, the access to memory is identical to that provided by the /dev/kmem special file.

The mem special file is part of Base Operating System (BOS) Runtime.

Files


/dev/mem Provides privileged virtual memory read and write access.
/dev/kmem Provides privileged virtual memory read and write access.

Related Information

The iostat command, sar command, vmstat command.

The close subroutine, ioctl subroutine, knlist subroutine, lseek subroutine, open subroutine, poll subroutine, read subroutine, select subroutine, write subroutine.

Special Files Overview .


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