/* * DEFS.H * * (c)Copyright 1993-2015, Matthew Dillon, All Rights Reserved. See the * COPYRIGHT file at the base of the distribution. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* * libruntime only depends on librune. It does not depend on * libgen. */ #include #include "export.h" /* * libruntime has no link dependencies on libgen */ #define LIBGEN_NOPROTOS #include /* for structures */ #if 1 #define refassert(cond) dassert(cond) #else #define refassert(cond) #endif #if 0 #define refprintf printf #else #define refprintf(ctl, ...) #endif #define BOUNDSCHECK(ps, bytes) _boundscheck(ps, bytes, __func__) #define STRBOUNDSCHECK(ps, maxbytes) _strboundscheck(ps, maxbytes, __func__) void runehashinit(void); void threadEventInterrupt(void); int threadPollEvent(int block); void eventIntrSig(int sigNo); void threadSidebandInit(void); void threadEventInit(void); #if 0 static __inline void _boundscheck(ReferenceStor *ps, urunesize_t bytes, const char *fname) { uintptr_t wrap; PointerInfo *info; info = ps->s_Info; wrap = (uintptr_t) ps->s_Addr + bytes; if (info->in_RefStor && (ps->s_Addr < info->in_Beg || wrap > (uintptr_t)info->in_End || wrap < (uintptr_t)ps->s_Addr)) { dpanic("Boundscheck in %s failed: %p,%zd (%p,%p)", fname, ps->s_Addr, bytes, info->in_Beg, info->in_End); } } static __inline char * _strboundscheck(ReferenceStor *ps, urunesize_t maxbytes, const char *fname) { char *base; char *str; PointerInfo *info; base = ps->s_Addr; info = ps->s_Info; if (info->in_RefStor && ((uintptr_t)base < (uintptr_t)info->in_Beg || (uintptr_t)base >= (uintptr_t)info->in_End)) { dpanic("StringBoundscheck in %s failed: %p (%p,%p)", fname, base, info->in_Beg, info->in_End); } base = ps->s_Addr; for (str = base; str < info->in_End; ++str) { if (*str == 0) { if ((urunesize_t)(str - base) >= maxbytes) { dpanic("StringBoundscheck in %s failed: " "len %zd > %zd (too long)", (urunesize_t)(str - base), maxbytes); } return base; } } dpanic("StringBoundscheck in %s failed: %p (%p,%p) (unterminated)", fname, base, info->in_Beg, info->in_End); /* NOT REACHED */ return NULL; } #endif