VirtualBox

Changeset 99755 in vbox


Ignore:
Timestamp:
May 11, 2023 7:18:48 PM (19 months ago)
Author:
vboxsync
Message:

include/iprt/cdefs.h: Avoid memory leak reports when running with parfait. For parfait any pointer != NULL is valid and using something AssertPtrReturn() after an allocation will result in a leak report, bugref:3409

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/cdefs.h

    r98103 r99755  
    44444444 * @param   ptr         The pointer.
    44454445 */
     4446#ifdef VBOX_WITH_PARFAIT
     4447/*
     4448 * Parfait will report memory leaks when something returns after a memory allocation
     4449 * using a check containing RT_VALID_PTR() (AssertPtrReturn and friends for example).
     4450 * To avoid those false positives the macro will just check for the pointer being != NULL.
     4451 */
     4452# define RT_VALID_PTR(ptr)       (ptr != NULL)
     4453#else
    44464454#if defined(RT_ARCH_AMD64)
    4447 # ifdef IN_RING3
    4448 if defined(RT_OS_DARWIN) /* first 4GB is reserved for legacy kernel. */
    4449 #   define RT_VALID_PTR(ptr)    (   (uintptr_t)(ptr) >= _4G \
     4455#  ifdef IN_RING3
     4456 if defined(RT_OS_DARWIN) /* first 4GB is reserved for legacy kernel. */
     4457#    define RT_VALID_PTR(ptr)    (   (uintptr_t)(ptr) >= _4G \
    44504458                                 && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
    4451 #  elif defined(RT_OS_SOLARIS) /* The kernel only used the top 2TB, but keep it simple. */
    4452 #   define RT_VALID_PTR(ptr)    (   (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
    4453                                  && (   ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
    4454                                      || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
    4455 #  elif defined(RT_OS_LINUX) /* May use 5-level paging  (see Documentation/x86/x86_64/mm.rst). */
    4456 #   define RT_VALID_PTR(ptr)    (   (uintptr_t)(ptr) >= 0x1000U /* one invalid page at the bottom */ \
    4457                                  && !((uintptr_t)(ptr) & 0xff00000000000000ULL) )
    4458 #  else
    4459 #   define RT_VALID_PTR(ptr)    (   (uintptr_t)(ptr) >= 0x1000U \
    4460                                  && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
    4461 #  endif
    4462 # else /* !IN_RING3 */
    4463 #  if defined(RT_OS_LINUX) /* May use 5-level paging (see Documentation/x86/x86_64/mm.rst). */
    4464 #   if 1 /* User address are no longer considered valid in kernel mode (SMAP, etc). */
    4465 #    define RT_VALID_PTR(ptr)   ((uintptr_t)(ptr) - 0xff00000000000000ULL < 0x00ffffffffe00000ULL) /* 2MB invalid space at the top */
     4459#   elif defined(RT_OS_SOLARIS) /* The kernel only used the top 2TB, but keep it simple. */
     4460#    define RT_VALID_PTR(ptr)    (   (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
     4461                                  && (   ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
     4462                                      || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
     4463#   elif defined(RT_OS_LINUX) /* May use 5-level paging  (see Documentation/x86/x86_64/mm.rst). */
     4464#    define RT_VALID_PTR(ptr)    (   (uintptr_t)(ptr) >= 0x1000U /* one invalid page at the bottom */ \
     4465                                  && !((uintptr_t)(ptr) & 0xff00000000000000ULL) )
    44664466#   else
    4467 #    define RT_VALID_PTR(ptr)   (   (uintptr_t)(ptr) + 0x200000 >= 0x201000U /* one invalid page at the bottom and 2MB at the top */ \
    4468                                  && (   ((uintptr_t)(ptr) & 0xff00000000000000ULL) == 0xff00000000000000ULL \
    4469                                      || ((uintptr_t)(ptr) & 0xff00000000000000ULL) == 0) )
     4467#    define RT_VALID_PTR(ptr)    (   (uintptr_t)(ptr) >= 0x1000U \
     4468                                  && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
    44704469#   endif
    4471 #  else
    4472 #   define RT_VALID_PTR(ptr)    (   (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
    4473                                  && (   ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
    4474                                      || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
    4475 #  endif
    4476 # endif /* !IN_RING3 */
    4477 
    4478 #elif defined(RT_ARCH_X86)
    4479 # define RT_VALID_PTR(ptr)      ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
    4480 
    4481 #elif defined(RT_ARCH_SPARC64)
    4482 # ifdef IN_RING3
    4483 #  if defined(RT_OS_SOLARIS)
     4470#  else /* !IN_RING3 */
     4471#   if defined(RT_OS_LINUX) /* May use 5-level paging (see Documentation/x86/x86_64/mm.rst). */
     4472#    if 1 /* User address are no longer considered valid in kernel mode (SMAP, etc). */
     4473#     define RT_VALID_PTR(ptr)   ((uintptr_t)(ptr) - 0xff00000000000000ULL < 0x00ffffffffe00000ULL) /* 2MB invalid space at the top */
     4474#    else
     4475#     define RT_VALID_PTR(ptr)   (   (uintptr_t)(ptr) + 0x200000 >= 0x201000U /* one invalid page at the bottom and 2MB at the top */ \
     4476                                  && (   ((uintptr_t)(ptr) & 0xff00000000000000ULL) == 0xff00000000000000ULL \
     4477                                      || ((uintptr_t)(ptr) & 0xff00000000000000ULL) == 0) )
     4478#    endif
     4479#   else
     4480#    define RT_VALID_PTR(ptr)    (   (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
     4481                                  && (   ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
     4482                                      || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
     4483#   endif
     4484#  endif /* !IN_RING3 */
     4485
     4486# elif defined(RT_ARCH_X86)
     4487#  define RT_VALID_PTR(ptr)      ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
     4488
     4489# elif defined(RT_ARCH_SPARC64)
     4490#  ifdef IN_RING3
     4491#   if defined(RT_OS_SOLARIS)
    44844492/** Sparc64 user mode: According to Figure 9.4 in solaris internals */
    44854493/** @todo #   define RT_VALID_PTR(ptr)    ( (uintptr_t)(ptr) + 0x80004000U >= 0x80004000U + 0x100000000ULL ) - figure this. */
    4486 #   define RT_VALID_PTR(ptr)    ( (uintptr_t)(ptr) + 0x80000000U >= 0x80000000U + 0x100000000ULL )
    4487 else
    4488 #   error "Port me"
    4489 endif
    4490 # else  /* !IN_RING3 */
    4491 if defined(RT_OS_SOLARIS)
     4494#    define RT_VALID_PTR(ptr)    ( (uintptr_t)(ptr) + 0x80000000U >= 0x80000000U + 0x100000000ULL )
     4495 else
     4496#    error "Port me"
     4497 endif
     4498#  else  /* !IN_RING3 */
     4499 if defined(RT_OS_SOLARIS)
    44924500/** @todo Sparc64 kernel mode: This is according to Figure 11.1 in solaris
    44934501 *        internals. Verify in sources. */
    4494 #   define RT_VALID_PTR(ptr)    ( (uintptr_t)(ptr) >= 0x01000000U )
    4495 else
    4496 #   error "Port me"
    4497 endif
    4498 # endif /* !IN_RING3 */
    4499 
    4500 #elif defined(RT_ARCH_SPARC)
    4501 # ifdef IN_RING3
    4502 ifdef RT_OS_SOLARIS
     4502#    define RT_VALID_PTR(ptr)    ( (uintptr_t)(ptr) >= 0x01000000U )
     4503 else
     4504#    error "Port me"
     4505 endif
     4506#  endif /* !IN_RING3 */
     4507
     4508# elif defined(RT_ARCH_SPARC)
     4509#  ifdef IN_RING3
     4510 ifdef RT_OS_SOLARIS
    45034511/** Sparc user mode: According to
    45044512 * http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/sun4/os/startup.c#510 */
    4505 #   define RT_VALID_PTR(ptr)    ( (uintptr_t)(ptr) + 0x400000U >= 0x400000U + 0x2000U )
    4506 
    4507 else
    4508 #   error "Port me"
    4509 endif
    4510 # else  /* !IN_RING3 */
    4511 ifdef RT_OS_SOLARIS
     4513#    define RT_VALID_PTR(ptr)    ( (uintptr_t)(ptr) + 0x400000U >= 0x400000U + 0x2000U )
     4514
     4515 else
     4516#    error "Port me"
     4517 endif
     4518#  else  /* !IN_RING3 */
     4519 ifdef RT_OS_SOLARIS
    45124520/** @todo Sparc kernel mode: Check the sources! */
    4513 #   define RT_VALID_PTR(ptr)    ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
    4514 else
    4515 #   error "Port me"
    4516 endif
    4517 # endif /* !IN_RING3 */
    4518 
    4519 #elif defined(RT_ARCH_ARM32) || defined(RT_ARCH_ARM64)
     4521#    define RT_VALID_PTR(ptr)    ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
     4522 else
     4523#    error "Port me"
     4524 endif
     4525#  endif /* !IN_RING3 */
     4526
     4527# elif defined(RT_ARCH_ARM32) || defined(RT_ARCH_ARM64)
    45204528/* ASSUMES that at least the last and first 4K are out of bounds. */
    4521 # define RT_VALID_PTR(ptr)      ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
    4522 
    4523 #else
    4524 # error "Architecture identifier missing / not implemented."
    4525 #endif
     4529#  define RT_VALID_PTR(ptr)      ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
     4530
     4531# else
     4532#  error "Architecture identifier missing / not implemented."
     4533# endif
     4534#endif /*!VBOX_WITH_PARFAIT*/
    45264535
    45274536/** @def RT_VALID_ALIGNED_PTR
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette