The mmap callable service establishes a mapping between a process's address space and a HFS file.
Operation | Environment |
---|---|
Authorization: | Supervisor state or problem state, PSW Key 2 or PSW Key 8 |
Dispatchable unit mode: | Task |
Cross memory mode: | PASN = HASN |
AMODE (BPX1MMP): | 31-bit |
AMODE (BPX4MMP): | 64-bit |
ASC mode: | Primary address space control (ASC) mode |
Interrupt status: | Enabled for interrupts |
Locks: | Unlocked |
Control parameters: | All parameters must be addressable by the caller and in the primary address space. |
|
|
The name of a fullword (doubleword) field that contains zero, or the address of an area within the address space at which the system is to attempt to map the requested file.
If the value of map_address is zero, the system has complete freedom in selecting the location within the address space at which the requested file is mapped.
If the value of map_address is not zero, the value that is specified is taken to be a suggestion of an address near which the mapping is to be placed. For non-MAP_FIXED requests, the system attempts to create the mapping at the address specified by map_address. The address is truncated to the nearest page boundary when a map type of MAP_SHARED or MAP_PRIVATE is specified, and to the nearest segment or megabyte boundary when a map type of MAP_MEGA is specified. If it is unsuccessful, it proceeds as if a map_address value of zero were specified.
For MAP_FIXED requests, the value of map_address must be a multiple of the page size when MAP_PRIVATE or MAP_SHARED is specified, and a multiple of the segment size when MAP_MEGA is specified. (If MAP_MEGA is specified, the value that is specified in map_address must be equal to zero or equal to or greater than 16 megabytes, or the request is failed with EINVAL.) The MAP_FIXED request fails with an EINVAL if any portion of the requested range is already in use for any reason (including a previous mapping).
The map_address supplied by the caller cannot be above the 31-bit addressability bar (X'7FFFFFFF'), or the request will fail (EINVAL).
The name of a fullword (doublword) field that contains the size (in bytes) of the memory mapping that is to be created. The length that is specified must be less than or equal to the size of the file, and must not cause the address space REGION to be exceeded. Mapping operations are performed over whole pages, or whole segments when MAP_MEGA is specified. If the length is not a multiple of the page size or segment size, the entire trailing portion of the page or segment (up to the end of the file) is also mapped into the user storage. The trailing portion of the page or segment in which an end of file occurs contains binary zeros.
The name of the fullword that contains the value of the memory access protection flags. The protect_options parameter indicates whether read, write, execute, or some combination of accesses are permitted to the mapped data. It can be set to either PROT_NONE, or a combination (using, for example, an inclusive OR) of one or more of the other access protection flags. The constant values for these flags are defined in the BPXYCONS macro. (See BPXYCONS — Constants used by services.) For MAP_MEGA mappings, the value that is specified for protect_options has a global effect on all current maps to the same file-offset range. For example, if PROT_READ is specified, all active maps have their protection for the same file-offset range changed to a protection of read.
Constant | Description |
---|---|
PROT_READ | Mapped data can be read. The file descriptor must have been previously opened with at least read access. |
PROT_WRITE | Mapped data can be written and read. To select the PROT_WRITE option, if a map_type of MAP_SHARED is specified, the file descriptor must have been previously opened with Read/Write access. If MAP_PRIVATE is specified, the file descriptor only needs to have been opened with read access. |
PROT_EXEC | Mapped data can be executed. This option is treated as if PROT_READ has been specified. |
PROT_NONE | Mapped data cannot be accessed. |
Constant | Description |
---|---|
MAP_SHARED | All changes to the mapped data are shared. Modifications to the mapped data are visible to all other processes that map the same file-offset range. |
MAP_PRIVATE | All changes to the mapped data are private. Modifications to the mapped data are visible only to the calling process, and do not change the underlying file. To use this option, the hardware must provide the suppression-on-protection support. |
MAP_MEGA | All changes to the mapped data are shared. Modifications to the mapped data are visible to all other processes that map the same file-offset range. The protection attributes of file-offset ranges are common among all active maps. Changes to the protection option of a file-offset range are global, and immediately affect all active maps. |
MAP_FIXED | The mapping must be placed at exactly the location specified by the map_address parameter. |
The name of a fullword that contains the file descriptor of an open file that is to be mapped to process storage. The file descriptor is returned by open (BPX1OPN, BPX4OPN) — Open a file. You can only specify the file descriptor of a regular file.
For a MAP_MEGA mapping, if this is the first map to the file that is represented by the specified file descriptor, the protect_options that can be specified for this file by this map request (and by all future map or mprotect requests, by this or any other process mapping to the same file) are determined by whether the file was opened for read or for read and write. If the file was opened for read but not write, only PROT_READ, PROT_EXEC, or PROT_NONE are allowed. If the file was opened for write, any of the protection options are accepted. Once PROT_WRITE is allowed for a file, all map requests must provide a file descriptor that was opened for write, or the map request is failed.
The name of a doubleword that defines which part of the file is to be mapped. It contains the offset into the file at which the map_length is to begin. The value of file_offset must be a multiple of the page size when MAP_PRIVATE or MAP_SHARED is specified, and a multiple of the segment size when MAP_MEGA is specified. The offset plus the map_length must fall within the current size of the file.
The name of a doubleword in which the mmap service returns the 64-bit address where the mapping was placed, if the request is successful.
The name of a fullword in which the mmap service returns the 31-bit address at which the mapping was placed, if the request is successful; or -1, if it is not successful. In AMODE 64, if mmap is successful, 0 is returned in this field and the 64-bit address is returned in the Returned_map_address parameter.
Upon successful completion, the mmap service has established a mapping between the process's address space, at an address returned in the Return_value parameter, for map_length bytes, to the file that is represented by the file_descriptor, at the specified file_offset, for a length of map_length bytes. The specified access protections and mapping type are set for the mapped range.
The name of a fullword in which the mmap service stores the return code. The mmap service returns Return_code only if Return_value is -1. See z/OS UNIX System Services Messages and Codes for a complete list of possible return code values.
Return_code | Explanation |
---|---|
EACCES | One of the following conditions occurred:
|
EAGAIN | The caller is not running in either PSW Key 2 or PSW Key 8. (JRUnsupportedKey) |
EBADF | One of the following conditions occurred:
|
EINVAL | One of the following conditions occurred:
|
EMFILE | The number of mapped regions would exceed a system limit:
|
ENODEV | The file descriptor refers to a file for which mmap is not supported (for example, a terminal). (JRNotSupportedForFileType) |
ENOMEM | One of the following conditions occurred:
|
ENOSYS | MAP_PRIVATE was specified, but the required suppression-on-protection hardware support was not available. (JRHardware) |
ENXIO | The addresses in the range (file_offset, file_offset + map_length) are not valid for the specified file descriptor. (JRMmapFileAddress) |
The name of a fullword in which the mmap service stores the reason code. The mmap service returns Reason_code only if Return_value is -1. Reason_code further qualifies the Return_code value. For the reason codes, see z/OS UNIX System Services Messages and Codes.
fd = open(...)
lseek(fd, file_offset)
read(fd, buffer, length)
/* ...(use data in buffer) ... */
becomes
fd = open(...)
address = mmap (0, length, PROT_READ, MAP_PRIVATE, fd, file_offset)
/* ...(use data at address) ... */
For an example using this callable service, see BPX1MMP (mmap) example.