⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 info.c

📁 debug source code under unix platform.
💻 C
📖 第 1 页 / 共 4 页
字号:
 */MP_GLOBALvoid__mp_checkinfo(infohead *h, loginfo *v){    allocnode *n;    infonode *m;    void *b, *p;    size_t l, s;    for (n = (allocnode *) h->alloc.list.head; n->lnode.next != NULL;         n = (allocnode *) n->lnode.next)    {        if ((m = (infonode *) n->info) == NULL)            /* Check that all free blocks are filled with the free byte, but             * only if all allocations are not pages since they will be read             * and write protected in that case.             */            if (!(h->alloc.flags & FLG_PAGEALLOC) &&                (p = __mp_memcheck(n->block, h->alloc.fbyte, n->size)))            {                __mp_log(h, v);                __mp_printsummary(h);                __mp_diag("\n");                __mp_error(ET_FRECOR, AT_MAX, v->file, v->line, NULL, p);                if ((l = (char *) n->block + n->size - (char *) p) > 256)                    __mp_printmemory(p, 256);                else                    __mp_printmemory(p, l);                h->fini = 1;                __mp_abort();            }            else                continue;        if ((m->data.flags & FLG_FREED) && !(h->alloc.flags & FLG_PAGEALLOC) &&            !(h->alloc.flags & FLG_PRESERVE))            /* Check that all freed blocks are filled with the free byte, but             * only if all allocations are not pages and the original contents             * were not preserved.             */            if (p = __mp_memcheck(n->block, h->alloc.fbyte, n->size))            {                __mp_log(h, v);                __mp_printsummary(h);                __mp_diag("\n");                __mp_error(ET_FRDCOR, AT_MAX, v->file, v->line, NULL, n->block,                           p);                if ((l = (char *) n->block + n->size - (char *) p) > 256)                    __mp_printmemory(p, 256);                else                    __mp_printmemory(p, l);                __mp_diag("\n");                __mp_printalloc(&h->syms, n);                h->fini = 1;                __mp_abort();            }        if (h->alloc.flags & FLG_OFLOWWATCH)            /* If we have watch areas on every overflow buffer then we don't             * need to perform the following checks.             */            continue;        if ((h->alloc.flags & FLG_PAGEALLOC) && !(m->data.flags & FLG_FREED))        {            /* Check that all allocated blocks have overflow buffers filled with             * the overflow byte, but only if all allocations are pages as this             * check examines the overflow buffers within the page boundaries.             * This does not have to be done for freed allocations as their             * overflow buffers will be at least read-only.             */            b = (void *) __mp_rounddown((unsigned long) n->block,                                        h->alloc.heap.memory.page);            s = (char *) n->block - (char *) b;            l = __mp_roundup(n->size + s, h->alloc.heap.memory.page);            if ((p = __mp_memcheck(b, h->alloc.obyte, s)) ||                (p = __mp_memcheck((char *) n->block + n->size, h->alloc.obyte,                  l - n->size - s)))            {                __mp_log(h, v);                __mp_printsummary(h);                __mp_diag("\n");                if (m->data.flags & FLG_FREED)                    __mp_error(ET_FRDOVF, AT_MAX, v->file, v->line, NULL,                               n->block, p);                else                    __mp_error(ET_ALLOVF, AT_MAX, v->file, v->line, NULL,                               n->block, p);                if (p < n->block)                    __mp_printmemory(b, s);                else                    __mp_printmemory((char *) n->block + n->size,                                     l - n->size - s);                __mp_diag("\n");                __mp_printalloc(&h->syms, n);                h->fini = 1;                __mp_abort();            }        }        if (!(h->alloc.flags & FLG_PAGEALLOC) && ((l = h->alloc.oflow) > 0))            /* Check that all allocated and freed blocks have overflow buffers             * filled with the overflow byte, but only if all allocations are             * not pages and the overflow buffer size is greater than zero.             */            if ((p = __mp_memcheck((char *) n->block - l, h->alloc.obyte, l)) ||                (p = __mp_memcheck((char *) n->block + n->size, h->alloc.obyte,                  l)))            {                __mp_log(h, v);                __mp_printsummary(h);                __mp_diag("\n");                if (m->data.flags & FLG_FREED)                    __mp_error(ET_FRDOVF, AT_MAX, v->file, v->line, NULL,                               n->block, p);                else                    __mp_error(ET_ALLOVF, AT_MAX, v->file, v->line, NULL,                               n->block, p);                if (p < n->block)                    __mp_printmemory((char *) n->block - l, l);                else                    __mp_printmemory((char *) n->block + n->size, l);                __mp_diag("\n");                __mp_printalloc(&h->syms, n);                h->fini = 1;                __mp_abort();            }    }}/* Check that a memory operation does not overflow the boundaries of a * memory block. */MP_GLOBALint__mp_checkrange(infohead *h, void *p, size_t s, loginfo *v){    allocnode *n;    infonode *m;    void *b;    size_t l;    int e;    if (p == NULL)    {        if ((s > 0) || (h->flags & FLG_CHECKMEMORY))        {            __mp_log(h, v);            __mp_error(ET_NULOPN, v->type, v->file, v->line, NULL);        }        return 0;    }    e = 1;    if (s == 0)        s = 1;    if (n = __mp_findnode(&h->alloc, p, s))        if ((m = (infonode *) n->info) == NULL)        {            __mp_log(h, v);            __mp_error(ET_FREOPN, v->type, v->file, v->line, NULL);            e = 0;        }        else if (m->data.flags & FLG_FREED)        {            __mp_log(h, v);            __mp_error(ET_FRDOPN, v->type, v->file, v->line, NULL);            __mp_printalloc(&h->syms, n);            __mp_diag("\n");            e = 0;        }        else if ((p < n->block) ||                 ((char *) p + s > (char *) n->block + n->size))        {            if (h->alloc.flags & FLG_PAGEALLOC)            {                b = (void *) __mp_rounddown((unsigned long) n->block,                                            h->alloc.heap.memory.page);                l = __mp_roundup(n->size + ((char *) n->block - (char *) b),                                 h->alloc.heap.memory.page);            }            else            {                b = n->block;                l = n->size;            }            b = (char *) b - h->alloc.oflow;            l += h->alloc.oflow << 1;            __mp_log(h, v);            if (h->flags & FLG_ALLOWOFLOW)                __mp_warn(ET_RNGOVF, v->type, v->file, v->line, NULL, p,                          (char *) p + s - 1, b, (char *) b + l - 1);            else                __mp_error(ET_RNGOVF, v->type, v->file, v->line, NULL, p,                           (char *) p + s - 1, b, (char *) b + l - 1);            __mp_printalloc(&h->syms, n);            __mp_diag("\n");            e = ((h->flags & FLG_ALLOWOFLOW) != 0);        }    return e;}/* Check that a string does not overflow the boundaries of a memory block and * then return the length of the string. */MP_GLOBALint__mp_checkstring(infohead *h, char *p, size_t *s, loginfo *v, int g){    allocnode *n;    infonode *m;    treenode *t;    void *b;    char *c, *u;    size_t l;    int e;    if (g == 1)        u = p + *s;    else        u = NULL;    *s = 0;    if (p == NULL)    {        if ((g == 0) || (u > p) || (h->flags & FLG_CHECKMEMORY))        {            __mp_log(h, v);            __mp_error(ET_NULOPN, v->type, v->file, v->line, NULL);        }        return 0;    }    e = 0;    if ((n = __mp_findnode(&h->alloc, p, 1)) == NULL)    {        if ((t = __mp_searchhigher(h->alloc.atree.root, (unsigned long) p)) ||            (t = __mp_searchhigher(h->alloc.gtree.root, (unsigned long) p)))        {            n = (allocnode *) ((char *) t - offsetof(allocnode, tnode));            if (h->alloc.flags & FLG_PAGEALLOC)                b = (void *) __mp_rounddown((unsigned long) n->block,                                            h->alloc.heap.memory.page);            else                b = n->block;            b = (char *) b - h->alloc.oflow;            if (g == 1)            {                for (c = p; (c < u) && (c < (char *) b) && (*c != '\0'); c++);                if (u > (char *) b)                    if (c == b)                        e = 1;                    else if (!(h->flags & FLG_ALLOWOFLOW))                        e = 2;            }            else            {                for (c = p; (c < (char *) b) && (*c != '\0'); c++);                if (c == b)                    e = 1;            }        }        else if (g == 1)            for (c = p; (c < u) && (*c != '\0'); c++);        else            for (c = p; *c != '\0'; c++);        *s = (size_t) (c - p);    }    else if ((m = (infonode *) n->info) == NULL)    {        __mp_log(h, v);        __mp_error(ET_FREOPN, v->type, v->file, v->line, NULL);        return 0;    }    else if (m->data.flags & FLG_FREED)    {        __mp_log(h, v);        __mp_error(ET_FRDOPN, v->type, v->file, v->line, NULL);        __mp_printalloc(&h->syms, n);        __mp_diag("\n");        return 0;    }    else if ((p >= (char *) n->block) && (p < (char *) n->block + n->size))    {        b = (char *) n->block + n->size;        if (g == 1)        {            for (c = p; (c < u) && (c < (char *) b) && (*c != '\0'); c++);            if (u > (char *) b)                if (c == b)                    e = 1;                else if (!(h->flags & FLG_ALLOWOFLOW))                    e = 2;        }        else        {            for (c = p; (c < (char *) b) && (*c != '\0'); c++);            if (c == b)                e = 1;        }        *s = (size_t) (c - p);    }    else        e = 1;    if (e != 0)    {        if (h->alloc.flags & FLG_PAGEALLOC)        {            b = (void *) __mp_rounddown((unsigned long) n->block,                                        h->alloc.heap.memory.page);            l = __mp_roundup(n->size + ((char *) n->block - (char *) b),                             h->alloc.heap.memory.page);        }        else        {            b = n->block;            l = n->size;        }        b = (char *) b - h->alloc.oflow;        l += h->alloc.oflow << 1;        __mp_log(h, v);        if (e == 1)            __mp_error(ET_STROVF, v->type, v->file, v->line, NULL, p, b,                       (char *) b + l - 1);        else            __mp_warn(ET_RNGOVF, v->type, v->file, v->line, NULL, p, u - 1, b,                      (char *) b + l - 1);        __mp_printalloc(&h->syms, n);        __mp_diag("\n");        return (e == 2);    }    return 1;}/* Fix the alignment required by a specified allocation function. */MP_GLOBALsize_t__mp_fixalign(infohead *h, alloctype f, size_t a){    size_t r;    if ((f == AT_VALLOC) || (f == AT_PVALLOC))        r = h->alloc.heap.memory.page;    else    {        r = a;        if (f == AT_MEMALIGN)        {            if (r > h->alloc.heap.memory.page)                r = h->alloc.heap.memory.page;            else if (!__mp_ispoweroftwo(r))                r = __mp_poweroftwo(r);        }        if (r == 0)            r = h->alloc.heap.memory.align;    }    return r;}#ifdef __cplusplus}#endif /* __cplusplus */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -