のねのBlog

パソコンの問題や、ソフトウェアの開発で起きた問題など書いていきます。よろしくお願いします^^。

RTCHECK

  3033 /* In gcc, use __builtin_expect to minimize impact of checks */
   3034 #if !INSECURE
   3035 #if defined(__GNUC__) && __GNUC__ >= 3
   3036 #define RTCHECK(e)  __builtin_expect(e, 1)
   3037 #else /* GNUC */
   3038 #define RTCHECK(e)  (e)
   3039 #endif /* GNUC */
   3040 #else /* !INSECURE */
   3041 #define RTCHECK(e)  (1)
   3042 #endif /* !INSECURE */

__builtin_expectの効力 - 初学者の箸置

   3009 #if !INSECURE
   3010 /* Check if address a is at least as high as any from MORECORE or MMAP */
   3011 #define ok_address(M, a) ((char*)(a) >= (M)->least_addr)
   3012 /* Check if address of next chunk n is higher than base chunk p */
   3013 #define ok_next(p, n)    ((char*)(p) < (char*)(n))
   3014 /* Check if p has inuse status */
   3015 #define ok_inuse(p)     is_inuse(p)
   3016 /* Check if p has its pinuse bit on */
   3017 #define ok_pinuse(p)     pinuse(p)
   3018 
   3019 #else /* !INSECURE */
   3020 #define ok_address(M, a) (1)
   3021 #define ok_next(b, n)    (1)
   3022 #define ok_inuse(p)      (1)
   3023 #define ok_pinuse(p)     (1)
   3024 #endif /* !INSECURE */
 2259 #define is_inuse(p)         (((p)->head & INUSE_BITS) != PINUSE_BIT)
   4702 /* ---------------------------- free --------------------------- */
   4703 
   4704 void dlfree(void* mem) {
   4705   /*
   4706      Consolidate freed chunks with preceeding or succeeding bordering
   4707      free chunks, if they exist, and then place in a bin.  Intermixed
   4708      with special cases for top, dv, mmapped chunks, and usage errors.
   4709   */
   4710 
   4711   if (mem != 0) {
   4712     mchunkptr p  = mem2chunk(mem);
   4713 #if FOOTERS
   4714     mstate fm = get_mstate_for(p);
   4715     if (!ok_magic(fm)) {
   4716       USAGE_ERROR_ACTION(fm, p);
   4717       return;
   4718     }
   4719 #else /* FOOTERS */
   4720 #define fm gm
   4721 #endif /* FOOTERS */
   4722     if (!PREACTION(fm)) {
   4723       check_inuse_chunk(fm, p);
 > 4724       if (RTCHECK(ok_address(fm, p) && ok_inuse(p))) { <=======================
   4725         size_t psize = chunksize(p);
   4726         mchunkptr next = chunk_plus_offset(p, psize);
   4727         if (!pinuse(p)) {
   4728           size_t prevsize = p->prev_foot;
   4729           if (is_mmapped(p)) {
   4730             psize += prevsize + MMAP_FOOT_PAD;
   4731             if (CALL_MUNMAP((char*)p - prevsize, psize) == 0)
   4732               fm->footprint -= psize;
   4733             goto postaction;
   4734           }