libsmbios_c library
memory.h File Reference
#include "smbios_c/compat.h"
#include "smbios_c/types.h"
Include dependency graph for memory.h:

Go to the source code of this file.

Functions

LIBSMBIOS_C_DLL_SPEC int memory_read (void *buffer, u64 offset, size_t length)
 Read byte range from physical memory address.
 
LIBSMBIOS_C_DLL_SPEC int memory_write (void *buffer, u64 offset, size_t length)
 Write a buffer to a physical memory address.
 
LIBSMBIOS_C_DLL_SPEC s64 memory_search (const char *pat, size_t patlen, u64 start, u64 end, u64 stride)
 Search a range of physical addresses for a pattern.
 
LIBSMBIOS_C_DLL_SPEC void LIBSMBIOS_C_DLL_SPEC memory_suggest_leave_open ()
 Optimize memory device access - request memory device be kept open between calls.
 
LIBSMBIOS_C_DLL_SPEC void memory_suggest_close ()
 Optimize memory device access - request memory device be closed between calls.
 
LIBSMBIOS_C_DLL_SPEC const char * memory_strerror ()
 Returns string describing the last error condition.
 

Function Documentation

◆ memory_read()

LIBSMBIOS_C_DLL_SPEC int memory_read ( void * buffer,
u64 offset,
size_t length )

Read byte range from physical memory address.

This function will read a range of bytes from a physical memory address. Note that some OS have severe restrictions on which addresses may be read and written, as well as security restrictions on which security levels are allowed this access.

Parameters
bufferpointer to buffer were memory will be copied
offsetstarting memory offset
lengthhow many bytes of memory to copy
Returns
0 on success, < 0 on failure -1 general failure -5 bad memory_access_object (could not instantiate singleton?) -6 bad buffer pointer

◆ memory_search()

LIBSMBIOS_C_DLL_SPEC s64 memory_search ( const char * pat,
size_t patlen,
u64 start,
u64 end,
u64 stride )

Search a range of physical addresses for a pattern.

Note that some OS have severe restrictions on which addresses may be read and written, as well as security restrictions on which security levels are allowed this access.

Parameters
patbuffer containing byte pattern to search for
patlenlength of pattern
startphysical address offset to start search
endending physical address offset
stridesearch for pattern only where physical addresses % stride == 0
Returns
-1 on failure. offset of memory address where pattern found on success

◆ memory_strerror()

LIBSMBIOS_C_DLL_SPEC const char * memory_strerror ( )

Returns string describing the last error condition.

Can return 0. The buffer used is guaranteed to be valid until the next call to any memory_* function. Copy the contents if you need it longer.

◆ memory_suggest_close()

LIBSMBIOS_C_DLL_SPEC void memory_suggest_close ( )

Optimize memory device access - request memory device be closed between calls.

By default, the memory device is closed between subsequent calls to read/write. This is to prevent file descriptor leakage by the libsmbios library. At times, however, the overhead of reopening the memory device file on every access is simply too great. This happens, for example, on memory searches, and can add considerable overhead. This function cancels a previous request to leave the device open between calls. Must be properly nested with memory_suggest_leave_open().

No parameters, no return.

◆ memory_suggest_leave_open()

LIBSMBIOS_C_DLL_SPEC void LIBSMBIOS_C_DLL_SPEC memory_suggest_leave_open ( )

Optimize memory device access - request memory device be kept open between calls.

By default, the memory device is closed between subsequent calls to read/write. This is to prevent file descriptor leakage by the libsmbios library. At times, however, the overhead of reopening the memory device file on every access is simply too great. This happens, for example, on memory searches, and can add considerable overhead. This function requests that the memory subsystem leave the device open between calls. Must be properly nested with memory_suggest_close().

No parameters, no return.

◆ memory_write()

LIBSMBIOS_C_DLL_SPEC int memory_write ( void * buffer,
u64 offset,
size_t length )

Write a buffer to a physical memory address.

This function will write a range of bytes to a physical memory address. Note that some OS have severe restrictions on which addresses may be read and written, as well as security restrictions on which security levels are allowed this access.

Parameters
bufferpointer to buffer containing contents to write
offsetstarting memory offset
lengthhow many bytes of memory to copy
Returns
0 on success, < 0 on failure -1 general failure -5 bad memory_access_object (could not instantiate singleton?) -6 bad buffer pointer