- Timestamp:
- Jan 24, 2024 1:05:51 AM (8 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
include/iprt/asm-mem.h (modified) (2 diffs)
-
src/VBox/Runtime/testcase/tstRTInlineAsm.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/asm-mem.h
r103014 r103017 72 72 * @{ 73 73 */ 74 75 #if defined(DOXYGEN_RUNNING) || defined(RT_ASM_INCLUDE_PAGE_SIZE)76 /** @def RT_ASM_PAGE_SIZE77 * We try avoid dragging in iprt/param.h here.78 * @internal79 */80 # if defined(RT_ARCH_SPARC64)81 # define RT_ASM_PAGE_SIZE 0x200082 # if defined(PAGE_SIZE) && !defined(NT_INCLUDED)83 # if PAGE_SIZE != 0x200084 # error "PAGE_SIZE is not 0x2000!"85 # endif86 # endif87 # elif defined(RT_ARCH_ARM64) && defined(RT_OS_DARWIN)88 # define RT_ASM_PAGE_SIZE 0x400089 # if defined(PAGE_SIZE) && !defined(NT_INCLUDED) && !defined(_MACH_ARM_VM_PARAM_H_)90 # if PAGE_SIZE != 0x400091 # error "PAGE_SIZE is not 0x4000!"92 # endif93 # endif94 # else95 # define RT_ASM_PAGE_SIZE 0x100096 # if defined(PAGE_SIZE) && !defined(NT_INCLUDED) && !defined(RT_OS_LINUX) && !defined(RT_ARCH_ARM64)97 # if PAGE_SIZE != 0x100098 # error "PAGE_SIZE is not 0x1000!"99 # endif100 # endif101 # endif102 #endif103 104 74 105 75 /** … … 371 341 #endif 372 342 373 #ifdef RT_ASM_PAGE_SIZE374 /**375 * Probes a buffer for read access page by page.376 *377 * While the function will fault if the buffer is not fully read378 * accessible, the idea is to do this in a safe place like before379 * acquiring locks and such like.380 *381 * Also, this functions guarantees that an eager compiler is not going382 * to optimize the probing away.383 *384 * @param pvBuf Pointer to the buffer.385 * @param cbBuf The size of the buffer in bytes. Must be >= 1.386 */387 DECLINLINE(void) ASMProbeReadBuffer(const void RT_FAR *pvBuf, size_t cbBuf) RT_NOTHROW_DEF388 {389 /** @todo verify that the compiler actually doesn't optimize this away. (intel & gcc) */390 /* the first byte */391 const uint8_t RT_FAR *pu8 = (const uint8_t RT_FAR *)pvBuf;392 ASMProbeReadByte(pu8);393 394 /* the pages in between pages. */395 while (cbBuf > RT_ASM_PAGE_SIZE)396 {397 ASMProbeReadByte(pu8);398 cbBuf -= RT_ASM_PAGE_SIZE;399 pu8 += RT_ASM_PAGE_SIZE;400 }401 402 /* the last byte */403 ASMProbeReadByte(pu8 + cbBuf - 1);404 }405 #endif406 407 343 /** @} */ 408 344 -
trunk/src/VBox/Runtime/testcase/tstRTInlineAsm.cpp
r103014 r103017 39 39 * Header Files * 40 40 *********************************************************************************************************************************/ 41 #define RT_ASM_INCLUDE_PAGE_SIZE42 41 #include <iprt/asm-mem.h> 43 42 #include <iprt/asm.h> … … 2652 2651 static void tstASMProbe(RTTEST hTest) 2653 2652 { 2654 RTTestSub(hTest, "ASMProbeReadByte /Buffer");2653 RTTestSub(hTest, "ASMProbeReadByte"); 2655 2654 2656 2655 uint8_t b = 42; 2657 2656 RTTESTI_CHECK(ASMProbeReadByte(&b) == 42); 2658 ASMProbeReadBuffer(&b, sizeof(b));2659 2657 2660 2658 for (uint32_t cPages = 1; cPages < 16; cPages++) … … 2671 2669 RTTESTI_CHECK(ASMProbeReadByte(&pbBuf1[0]) == 0xf6); 2672 2670 RTTESTI_CHECK(ASMProbeReadByte(&pbBuf2[0]) == 0x42); 2673 2674 ASMProbeReadBuffer(pbBuf1, cPages * PAGE_SIZE);2675 ASMProbeReadBuffer(pbBuf2, cPages * PAGE_SIZE);2676 2671 } 2677 2672 }
Note:
See TracChangeset
for help on using the changeset viewer.

