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

  • passing an arbitrary record offset directly to MapViewOfFile or MapViewOfFileEx
  • rounding to the page size instead of SYSTEM_INFO.dwAllocationGranularity
  • splitting a 64-bit file offset incorrectly between high and low DWORD values
  • requesting a fixed base address that is not suitably aligned or is already occupied
  • using large-page mapping without satisfying the additional large-page alignment and size rules

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

  • mapping API and flags, requested access, and mapping-object protection
  • full 64-bit file offset, requested view size, and optional base address
  • system allocation granularity and page size obtained from GetSystemInfo
  • aligned offset, in-view delta, and final address used by the application
  • whether the mapping uses ordinary pages, large pages, a file, or the paging file

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

  • treat 1132 as a deterministic parameter error rather than a transient resource condition
  • do not retry until the alignment calculation or base-address request changes
  • test offsets just below, at, and just above granularity boundaries
  • include files larger than 4 GB to exercise high-offset handling
  • avoid requiring a fixed base address unless the design truly depends on it

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.