dmi_memory_load

Synopsis

#include <opendmi/utils.h>

bool dmi_memory_load(
        dmi_buffer_t *buffer,
        const char   *path,
        uint64_t      base,
        size_t        length);

Description

The dmi_memory_load function opens path, maps length bytes starting at physical offset base into memory using mmap(2), copies the data into buffer, then unmaps the region. Page alignment is handled internally.

The data the buffer held before is dropped, and so is whatever has been read when the reading fails.

This is what the backends reading a table or an entry point out of physical memory fill the buffer they are given with, see dmi_backend_t.

Parameters

buffer

Buffer to read the region into.

path

Path to the device or file to read (e.g. /dev/mem).

base

Physical byte offset to start reading from. It is 64-bit on every system, so that the address of an SMBIOS 3.0 table is passed as is; the one the system cannot address is rejected.

length

Number of bytes to read; must be greater than zero.

Return value

true on success, false otherwise.

Errors

DMI_ERROR_ARGUMENT_NULL

Path is nullptr.

DMI_ERROR_ARGUMENT_INVALID

Length is zero, or the process runs as root and path is not a character device, so that root is not tricked into mapping a file it is given.

DMI_ERROR_FILE_OPEN_FAILED

Device cannot be opened.

DMI_ERROR_FILE_STAT_FAILED

Device cannot be examined.

DMI_ERROR_FILE_MAP_FAILED

Region cannot be mapped, lies beyond the end of path if it is a regular file, or lies beyond the range the system can address.

DMI_ERROR_OUT_OF_MEMORY

Buffer cannot hold the data.

Notes

Errors are raised on the context of the buffer, see dmi_buffer_context.

This function is not available on Windows.