Site icon EfmSoft

What does Windows error code 1132 (ERROR_MAPPED_ALIGNMENT) mean?

 
Previous Next
ERROR_POSSIBLE_DEADLOCK ERROR_SET_POWER_STATE_VETOED

ERROR_MAPPED_ALIGNMENT

The base address or the file offset specified does not have the proper alignment.

ERROR_MAPPED_ALIGNMENT has decimal value 1132 (0x46C). It is returned when a file-mapping request uses a base address or file offset that does not meet the alignment rules required by the mapping API. For ordinary mapped views, the file offset must be a multiple of the system allocation granularity, which is not necessarily the same as the memory page size.

Typical programming mistakes

The usual solution is to map from an earlier aligned file offset and then add a delta inside the returned view. The mapped length must include that delta so the desired data range remains covered.

Values to log

Formatting only the low 32 bits of an offset can conceal overflow or incorrect high-part calculation. Diagnostics should print offsets and sizes as full-width unsigned values.

Correct mapping calculation

Let the requested file position be offset and the allocation granularity be granularity. Compute an aligned start as offset - (offset % granularity). The delta is offset - aligned_start. Map delta + requested_length bytes from the aligned start, then access the desired data at mapped_base + delta.

Validate arithmetic for overflow, especially when the requested range approaches the end of a large file. Also verify that the underlying file is long enough and that the mapping protection agrees with the requested view access.

Handling and testing

Mapped-file code should store offsets in the file rather than absolute process pointers. A view can be placed at different virtual addresses each time, even when the file offset is valid.

Related failures

ERROR_INVALID_PARAMETER can cover other invalid mapping combinations. ERROR_NOT_ENOUGH_MEMORY concerns address-space or allocation resources. Error 1132 specifically identifies alignment of the base address or file offset.

Example

An index reader wants 4 KB beginning at file offset 100,000 and maps exactly from that offset. On a system with 64 KB allocation granularity, the call fails with 1132. Mapping from 65,536, requesting enough bytes for the 34,464-byte delta plus the record, and then adding the delta produces a valid view.

References


Looking for a different code? Search another status or error code.

Exit mobile version