kupl_hbw_verify
Check whether the memory space from addr to addr+size is within the OPM.
Interface Definition
int kupl_hbw_verify(void *addr, size_t size, int flags);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
addr |
void* |
Start address of the memory to be checked. |
Input |
size |
size_t |
Size of the memory to be checked. |
Input |
flags |
int |
Additional flag information, which may affect the function behavior. Currently, this parameter can be set to KUPL_HBW_TOUCH_PAGES or 0 (no additional processing is performed). |
Input |
KUPL_HBW_TOUCH_PAGES indicates that each page within the memory space under verification will be touched (read and written) based on the OS pages before verification. This operation forces the OS to allocate memory space and establish page mapping for the verified address. flags needs to be specified if you cannot determine whether the virtual memory to be verified has been mapped to physical pages.
Return Value
- If the entire memory is in the OPM, KUPL_IS_HBW_MEMORY is returned.
- If the specified memory space contains a part that does not belong to the OPM, KUPL_IS_NOT_HBW_MEMORY is returned.
- If an error occurs during the processing, KUPL_HBW_VERIFY_ERROR is returned.
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include <stdio.h> #include <stdlib.h> #include <assert.h> #include "kupl.h" int main() { int len = 1024; char *data = (char *)kupl_hbw_malloc(len); if (data == nullptr) { return 0; } int ret = kupl_hbw_verify(data, 1024, KUPL_HBW_TOUCH_PAGES); assert(ret == KUPL_IS_HBW_MEMORY); kupl_hbw_free(data); return 0; } |
- The preceding example illustrates how to allocate OPM and verify its placement.
- The start address of the pointer verified by kupl_hbw_verify is the start address obtained by calling kupl_hbw_malloc. The verification length is also consistent with the allocated size.
- After HBW_TOUCH_PAGES is set, kupl_hbw_verify reads and writes each page in the memory space before verification.