Fix dlmalloc horror bug - mman_map overwrites application code
This commit is contained in:
@ -2,8 +2,7 @@
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include "bitmap.h"
|
||||
|
||||
#define DIV_ROUNDUP(num, div) ((num + div - 1) / div)
|
||||
#include "util/util.h"
|
||||
|
||||
void *bitmap_toptr(BitMap *bm, size_t block) {
|
||||
uint8_t *ptr = (uint8_t *)(bm->mem_start + (block * BITMAP_BLOCK_SIZE));
|
||||
@ -17,12 +16,12 @@ size_t bitmap_toblock(BitMap *bm, void *ptr) {
|
||||
|
||||
size_t bitmap_toblock_roundup(BitMap *bm, void *ptr) {
|
||||
uint8_t *p = ptr;
|
||||
return (size_t)DIV_ROUNDUP((size_t)(p - bm->mem_start), BITMAP_BLOCK_SIZE);
|
||||
return (size_t)_DIV_ROUNDUP((size_t)(p - bm->mem_start), BITMAP_BLOCK_SIZE);
|
||||
}
|
||||
|
||||
size_t bitmap_calcsize(size_t total) {
|
||||
size_t nblocks = DIV_ROUNDUP(total, BITMAP_BLOCK_SIZE);
|
||||
size_t nbytes = DIV_ROUNDUP(nblocks, 8);
|
||||
size_t nblocks = _DIV_ROUNDUP(total, BITMAP_BLOCK_SIZE);
|
||||
size_t nbytes = _DIV_ROUNDUP(nblocks, 8);
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
@ -59,7 +58,7 @@ void bitmap_markregion(BitMap *bm, void *baseptr, size_t size, bool is_used) {
|
||||
|
||||
if (is_used) {
|
||||
base = bitmap_toblock(bm, baseptr);
|
||||
size1 = DIV_ROUNDUP(size, BITMAP_BLOCK_SIZE);
|
||||
size1 = _DIV_ROUNDUP(size, BITMAP_BLOCK_SIZE);
|
||||
} else {
|
||||
base = bitmap_toblock(bm, baseptr);
|
||||
size1 = size / BITMAP_BLOCK_SIZE;
|
||||
|
Reference in New Issue
Block a user