mirror of
https://github.com/Zenithsiz/ftmemsim-valgrind.git
synced 2026-02-04 02:18:37 +00:00
Rename *ROUND* as VG_*ROUND* to be consistent with everything else. Also
make them tool-visible, so that Memcheck and Helgrind don't have to defined their own versions! git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3839
This commit is contained in:
parent
09980587a9
commit
fbcb21d4c4
@ -49,12 +49,6 @@
|
||||
/* Max length of a text fragment used to construct error messages. */
|
||||
#define VG_ERRTXT_LEN 4096
|
||||
|
||||
// 'a' -- the alignment -- must be a power of 2
|
||||
#define ROUNDDN(p, a) ((Addr)(p) & ~((Addr)(a)-1))
|
||||
#define ROUNDUP(p, a) ROUNDDN((p)+(a)-1, (a))
|
||||
#define PGROUNDDN(p) ROUNDDN(p, VKI_PAGE_SIZE)
|
||||
#define PGROUNDUP(p) ROUNDUP(p, VKI_PAGE_SIZE)
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
Environment variables
|
||||
------------------------------------------------------------------ */
|
||||
|
||||
@ -583,7 +583,7 @@ void VG_(unmap_range)(Addr addr, SizeT len)
|
||||
if (len == 0)
|
||||
return;
|
||||
|
||||
len = PGROUNDUP(len);
|
||||
len = VG_PGROUNDUP(len);
|
||||
|
||||
if (debug)
|
||||
VG_(printf)("unmap_range(%p, %lu)\n", addr, len);
|
||||
@ -705,7 +705,7 @@ VG_(map_file_segment)( Addr addr, SizeT len,
|
||||
|
||||
/* Everything must be page-aligned */
|
||||
vg_assert(VG_IS_PAGE_ALIGNED(addr));
|
||||
len = PGROUNDUP(len);
|
||||
len = VG_PGROUNDUP(len);
|
||||
|
||||
/* Nuke/truncate any existing segment(s) covering [addr,addr+len) */
|
||||
VG_(unmap_range)(addr, len);
|
||||
@ -816,7 +816,7 @@ void VG_(mprotect_range)(Addr a, SizeT len, UInt prot)
|
||||
|
||||
/* Everything must be page-aligned */
|
||||
vg_assert(VG_IS_PAGE_ALIGNED(a));
|
||||
len = PGROUNDUP(len);
|
||||
len = VG_PGROUNDUP(len);
|
||||
|
||||
split_segment(a);
|
||||
split_segment(a+len);
|
||||
@ -868,7 +868,7 @@ Addr VG_(find_map_space)(Addr addr, SizeT len, Bool for_client)
|
||||
|
||||
/* Everything must be page-aligned */
|
||||
vg_assert((addr & (VKI_PAGE_SIZE-1)) == 0);
|
||||
len = PGROUNDUP(len);
|
||||
len = VG_PGROUNDUP(len);
|
||||
|
||||
len += VKI_PAGE_SIZE * 2; /* leave redzone gaps before and after mapping */
|
||||
|
||||
@ -1158,8 +1158,8 @@ Bool VG_(is_addressable)(Addr p, SizeT size, UInt prot)
|
||||
if (size == 0)
|
||||
return True; /* isn't this a bit of a strange case? */
|
||||
|
||||
p = PGROUNDDN(p);
|
||||
size = PGROUNDUP(size);
|
||||
p = VG_PGROUNDDN(p);
|
||||
size = VG_PGROUNDUP(size);
|
||||
vg_assert(VG_IS_PAGE_ALIGNED(p));
|
||||
vg_assert(VG_IS_PAGE_ALIGNED(size));
|
||||
|
||||
@ -1184,7 +1184,7 @@ Bool VG_(is_addressable)(Addr p, SizeT size, UInt prot)
|
||||
Addr VG_(get_memory_from_mmap_for_client)
|
||||
(Addr addr, SizeT len, UInt prot, UInt sf_flags)
|
||||
{
|
||||
len = PGROUNDUP(len);
|
||||
len = VG_PGROUNDUP(len);
|
||||
|
||||
tl_assert(!(sf_flags & SF_FIXED));
|
||||
tl_assert(0 == addr);
|
||||
@ -1259,15 +1259,15 @@ vg_assert(0);
|
||||
vg_assert(VG_(needs).shadow_memory);
|
||||
vg_assert(VG_(tdict).track_init_shadow_page);
|
||||
|
||||
sz = PGROUNDUP(p+sz) - PGROUNDDN(p);
|
||||
p = PGROUNDDN(p);
|
||||
sz = VG_PGROUNDUP(p+sz) - VG_PGROUNDDN(p);
|
||||
p = VG_PGROUNDDN(p);
|
||||
|
||||
VG_(mprotect)((void *)p, sz, VKI_PROT_READ|VKI_PROT_WRITE);
|
||||
|
||||
if (call_init)
|
||||
while(sz) {
|
||||
/* ask the tool to initialize each page */
|
||||
VG_TRACK( init_shadow_page, PGROUNDDN(p) );
|
||||
VG_TRACK( init_shadow_page, VG_PGROUNDDN(p) );
|
||||
|
||||
p += VKI_PAGE_SIZE;
|
||||
sz -= VKI_PAGE_SIZE;
|
||||
@ -1285,7 +1285,7 @@ void *VG_(shadow_alloc)(UInt size)
|
||||
vg_assert(VG_(needs).shadow_memory);
|
||||
vg_assert(!VG_(tdict).track_init_shadow_page);
|
||||
|
||||
size = PGROUNDUP(size);
|
||||
size = VG_PGROUNDUP(size);
|
||||
|
||||
if (shadow_alloc == 0)
|
||||
shadow_alloc = VG_(shadow_base);
|
||||
|
||||
@ -1654,7 +1654,7 @@ Bool read_lib_symbols ( SegInfo* si )
|
||||
|
||||
/* Did we find a debuglink section? */
|
||||
if (debuglink != NULL) {
|
||||
UInt crc_offset = ROUNDUP(VG_(strlen)(debuglink)+1, 4);
|
||||
UInt crc_offset = VG_ROUNDUP(VG_(strlen)(debuglink)+1, 4);
|
||||
UInt crc;
|
||||
|
||||
vg_assert(crc_offset + sizeof(UInt) <= debuglink_sz);
|
||||
|
||||
@ -300,7 +300,7 @@ static int scan_auxv(void* init_sp)
|
||||
break;
|
||||
|
||||
case AT_PHDR:
|
||||
VG_(valgrind_base) = PGROUNDDN(auxv->u.a_val);
|
||||
VG_(valgrind_base) = VG_PGROUNDDN(auxv->u.a_val);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -328,20 +328,20 @@ static void layout_remaining_space(Addr argc_addr, float ratio)
|
||||
// VG_(valgrind_base) should have been set by scan_auxv, but if not,
|
||||
// this is a workable approximation
|
||||
if (VG_(valgrind_base) == 0) {
|
||||
VG_(valgrind_base) = PGROUNDDN(&_start);
|
||||
VG_(valgrind_base) = VG_PGROUNDDN(&_start);
|
||||
}
|
||||
|
||||
VG_(valgrind_last) = ROUNDUP(argc_addr, 0x10000) - 1; // stack
|
||||
VG_(valgrind_last) = VG_ROUNDUP(argc_addr, 0x10000) - 1; // stack
|
||||
|
||||
// This gives the client the largest possible address space while
|
||||
// taking into account the tool's shadow needs.
|
||||
client_size = ROUNDDN((VG_(valgrind_base)-REDZONE_SIZE) / (1.+ratio),
|
||||
client_size = VG_ROUNDDN((VG_(valgrind_base)-REDZONE_SIZE) / (1.+ratio),
|
||||
CLIENT_SIZE_MULTIPLE);
|
||||
VG_(client_base) = 0;
|
||||
VG_(client_end) = VG_(client_base) + client_size;
|
||||
/* where !FIXED mmap goes */
|
||||
VG_(client_mapbase) = VG_(client_base) +
|
||||
PGROUNDDN((Addr)(client_size * CLIENT_HEAP_PROPORTION));
|
||||
VG_PGROUNDDN((Addr)(client_size * CLIENT_HEAP_PROPORTION));
|
||||
|
||||
VG_(shadow_base) = VG_(client_end) + REDZONE_SIZE;
|
||||
VG_(shadow_end) = VG_(valgrind_base);
|
||||
@ -873,7 +873,7 @@ static Addr setup_client_stack(void* init_sp,
|
||||
sizeof(char **)*envc + /* envp */
|
||||
sizeof(char **) + /* terminal NULL */
|
||||
auxsize + /* auxv */
|
||||
ROUNDUP(stringsize, sizeof(Word)) +/* strings (aligned) */
|
||||
VG_ROUNDUP(stringsize, sizeof(Word)) +/* strings (aligned) */
|
||||
VKI_PAGE_SIZE; /* page for trampoline code */
|
||||
|
||||
if (0) VG_(printf)("stacksize = %d\n", stacksize);
|
||||
@ -885,13 +885,13 @@ static Addr setup_client_stack(void* init_sp,
|
||||
|
||||
/* cl_esp is the client's stack pointer */
|
||||
cl_esp = VG_(clstk_end) - stacksize;
|
||||
cl_esp = ROUNDDN(cl_esp, 16); /* make stack 16 byte aligned */
|
||||
cl_esp = VG_ROUNDDN(cl_esp, 16); /* make stack 16 byte aligned */
|
||||
|
||||
/* base of the string table (aligned) */
|
||||
stringbase = strtab = (char *)(VG_(client_trampoline_code)
|
||||
- ROUNDUP(stringsize, sizeof(int)));
|
||||
- VG_ROUNDUP(stringsize, sizeof(int)));
|
||||
|
||||
VG_(clstk_base) = PGROUNDDN(cl_esp);
|
||||
VG_(clstk_base) = VG_PGROUNDDN(cl_esp);
|
||||
|
||||
if (0)
|
||||
printf("stringsize=%d auxsize=%d stacksize=%d\n"
|
||||
@ -903,7 +903,8 @@ static Addr setup_client_stack(void* init_sp,
|
||||
/* ==================== allocate space ==================== */
|
||||
|
||||
/* allocate a stack - mmap enough space for the stack */
|
||||
res = mmap((void *)PGROUNDDN(cl_esp), VG_(clstk_end) - PGROUNDDN(cl_esp),
|
||||
res = mmap((void *)VG_PGROUNDDN(cl_esp),
|
||||
VG_(clstk_end) - VG_PGROUNDDN(cl_esp),
|
||||
PROT_READ | PROT_WRITE | PROT_EXEC,
|
||||
MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0);
|
||||
vg_assert((void*)-1 != res);
|
||||
|
||||
@ -442,7 +442,7 @@ static Addr build_rt_sigframe(ThreadState *tst,
|
||||
Int sigNo = siginfo->si_signo;
|
||||
|
||||
rsp -= sizeof(*frame);
|
||||
rsp = ROUNDDN(rsp, 16);
|
||||
rsp = VG_ROUNDDN(rsp, 16);
|
||||
frame = (struct rt_sigframe *)rsp;
|
||||
|
||||
if (!extend(tst, rsp, sizeof(*frame)))
|
||||
|
||||
@ -465,7 +465,7 @@ static Addr build_sigframe(ThreadState *tst,
|
||||
vg_assert((flags & VKI_SA_SIGINFO) == 0);
|
||||
|
||||
esp -= sizeof(*frame);
|
||||
esp = ROUNDDN(esp, 16);
|
||||
esp = VG_ROUNDDN(esp, 16);
|
||||
frame = (struct sigframe *)esp;
|
||||
|
||||
if (!extend(tst, esp, sizeof(*frame)))
|
||||
@ -512,7 +512,7 @@ static Addr build_rt_sigframe(ThreadState *tst,
|
||||
vg_assert((flags & VKI_SA_SIGINFO) != 0);
|
||||
|
||||
esp -= sizeof(*frame);
|
||||
esp = ROUNDDN(esp, 16);
|
||||
esp = VG_ROUNDDN(esp, 16);
|
||||
frame = (struct rt_sigframe *)esp;
|
||||
|
||||
if (!extend(tst, esp, sizeof(*frame)))
|
||||
|
||||
@ -943,15 +943,15 @@ struct note {
|
||||
|
||||
static UInt note_size(const struct note *n)
|
||||
{
|
||||
return sizeof(Elf32_Nhdr) + ROUNDUP(VG_(strlen)(n->name)+1, 4) + ROUNDUP(n->note.n_descsz, 4);
|
||||
return sizeof(Elf32_Nhdr) + VG_ROUNDUP(VG_(strlen)(n->name)+1, 4) + VG_ROUNDUP(n->note.n_descsz, 4);
|
||||
}
|
||||
|
||||
static void add_note(struct note **list, const Char *name, UInt type, const void *data, UInt datasz)
|
||||
{
|
||||
Int namelen = VG_(strlen)(name)+1;
|
||||
Int notelen = sizeof(struct note) +
|
||||
ROUNDUP(namelen, 4) +
|
||||
ROUNDUP(datasz, 4);
|
||||
VG_ROUNDUP(namelen, 4) +
|
||||
VG_ROUNDUP(datasz, 4);
|
||||
struct note *n = VG_(arena_malloc)(VG_AR_CORE, notelen);
|
||||
|
||||
VG_(memset)(n, 0, notelen);
|
||||
@ -964,7 +964,7 @@ static void add_note(struct note **list, const Char *name, UInt type, const void
|
||||
n->note.n_descsz = datasz;
|
||||
|
||||
VG_(memcpy)(n->name, name, namelen);
|
||||
VG_(memcpy)(n->name+ROUNDUP(namelen,4), data, datasz);
|
||||
VG_(memcpy)(n->name+VG_ROUNDUP(namelen,4), data, datasz);
|
||||
}
|
||||
|
||||
static void write_note(Int fd, const struct note *n)
|
||||
@ -1147,7 +1147,7 @@ static void make_coredump(ThreadId tid, const vki_siginfo_t *si, UInt max_size)
|
||||
|
||||
off += notesz;
|
||||
|
||||
off = PGROUNDUP(off);
|
||||
off = VG_PGROUNDUP(off);
|
||||
|
||||
for(seg = VG_(first_segment)(), idx = 1;
|
||||
seg != NULL;
|
||||
@ -1660,7 +1660,7 @@ Bool VG_(extend_stack)(Addr addr, UInt maxsize)
|
||||
vg_assert(seg->addr > addr);
|
||||
|
||||
/* Create the mapping */
|
||||
base = PGROUNDDN(addr);
|
||||
base = VG_PGROUNDDN(addr);
|
||||
newsize = seg->addr - base;
|
||||
|
||||
if (seg->len + newsize >= maxsize)
|
||||
@ -1810,11 +1810,11 @@ void sync_signalhandler ( Int sigNo, vki_siginfo_t *info, struct vki_ucontext *u
|
||||
nothing mapped there (as opposed to a permissions fault),
|
||||
then extend the stack segment.
|
||||
*/
|
||||
Addr base = PGROUNDDN(esp - VGA_STACK_REDZONE_SZB);
|
||||
Addr base = VG_PGROUNDDN(esp - VGA_STACK_REDZONE_SZB);
|
||||
if (VG_(extend_stack)(base, VG_(threads)[tid].client_stack_szB)) {
|
||||
if (VG_(clo_trace_signals))
|
||||
VG_(message)(Vg_DebugMsg,
|
||||
" -> extended stack base to %p", PGROUNDDN(fault));
|
||||
" -> extended stack base to %p", VG_PGROUNDDN(fault));
|
||||
return; // extension succeeded, restart instruction
|
||||
} else
|
||||
VG_(message)(Vg_UserMsg, "Stack overflow in thread %d: can't grow stack to %p",
|
||||
@ -1833,7 +1833,7 @@ void sync_signalhandler ( Int sigNo, vki_siginfo_t *info, struct vki_ucontext *u
|
||||
static Int recursion = 0;
|
||||
|
||||
if (recursion++ == 0) {
|
||||
VG_(init_shadow_range)(PGROUNDDN(fault), VKI_PAGE_SIZE, True);
|
||||
VG_(init_shadow_range)(VG_PGROUNDDN(fault), VKI_PAGE_SIZE, True);
|
||||
recursion--;
|
||||
return;
|
||||
} else {
|
||||
|
||||
@ -427,12 +427,12 @@ static Int do_clone(ThreadId ptid,
|
||||
only go down to the start of the mmaped segment. */
|
||||
seg = VG_(find_segment)((Addr)rsp);
|
||||
if (seg) {
|
||||
ctst->client_stack_highest_word = (Addr)PGROUNDUP(rsp);
|
||||
ctst->client_stack_highest_word = (Addr)VG_PGROUNDUP(rsp);
|
||||
ctst->client_stack_szB = ctst->client_stack_highest_word - seg->addr;
|
||||
|
||||
if (debug)
|
||||
VG_(printf)("tid %d: guessed client stack range %p-%p\n",
|
||||
ctid, seg->addr, PGROUNDUP(rsp));
|
||||
ctid, seg->addr, VG_PGROUNDUP(rsp));
|
||||
} else {
|
||||
VG_(message)(Vg_UserMsg, "!? New thread %d starts with RSP(%p) unmapped\n",
|
||||
ctid, rsp);
|
||||
|
||||
@ -596,8 +596,8 @@ PRE(sys_io_setup, Special)
|
||||
unsigned, nr_events, vki_aio_context_t *, ctxp);
|
||||
PRE_MEM_WRITE( "io_setup(ctxp)", ARG2, sizeof(vki_aio_context_t) );
|
||||
|
||||
size = PGROUNDUP(sizeof(struct vki_aio_ring) +
|
||||
ARG1*sizeof(struct vki_io_event));
|
||||
size = VG_PGROUNDUP(sizeof(struct vki_aio_ring) +
|
||||
ARG1*sizeof(struct vki_io_event));
|
||||
addr = VG_(find_map_space)(0, size, True);
|
||||
|
||||
if (addr == 0) {
|
||||
@ -645,8 +645,8 @@ PRE(sys_io_destroy, Special)
|
||||
// If we are going to seg fault (due to a bogus ARG1) do it as late as
|
||||
// possible...
|
||||
r = *(struct vki_aio_ring **)ARG1;
|
||||
size = PGROUNDUP(sizeof(struct vki_aio_ring) +
|
||||
r->nr*sizeof(struct vki_io_event));
|
||||
size = VG_PGROUNDUP(sizeof(struct vki_aio_ring) +
|
||||
r->nr*sizeof(struct vki_io_event));
|
||||
|
||||
SET_RESULT( VG_(do_syscall1)(SYSNO, ARG1) );
|
||||
|
||||
|
||||
@ -431,12 +431,12 @@ static Int do_clone(ThreadId ptid,
|
||||
only go down to the start of the mmaped segment. */
|
||||
seg = VG_(find_segment)((Addr)esp);
|
||||
if (seg) {
|
||||
ctst->client_stack_highest_word = (Addr)PGROUNDUP(esp);
|
||||
ctst->client_stack_highest_word = (Addr)VG_PGROUNDUP(esp);
|
||||
ctst->client_stack_szB = ctst->client_stack_highest_word - seg->addr;
|
||||
|
||||
if (debug)
|
||||
VG_(printf)("tid %d: guessed client stack range %p-%p\n",
|
||||
ctid, seg->addr, PGROUNDUP(esp));
|
||||
ctid, seg->addr, VG_PGROUNDUP(esp));
|
||||
} else {
|
||||
VG_(message)(Vg_UserMsg, "!? New thread %d starts with ESP(%p) unmapped\n",
|
||||
ctid, esp);
|
||||
|
||||
@ -173,8 +173,8 @@ void mash_addr_and_len( Addr* a, SizeT* len)
|
||||
{
|
||||
Addr ra;
|
||||
|
||||
ra = PGROUNDDN(*a);
|
||||
*len = PGROUNDUP(*a + *len) - ra;
|
||||
ra = VG_PGROUNDDN(*a);
|
||||
*len = VG_PGROUNDUP(*a + *len) - ra;
|
||||
*a = ra;
|
||||
}
|
||||
|
||||
@ -211,10 +211,10 @@ Addr mremap_segment ( Addr old_addr, SizeT old_size,
|
||||
Addr ret;
|
||||
Segment *seg, *next;
|
||||
|
||||
old_size = PGROUNDUP(old_size);
|
||||
new_size = PGROUNDUP(new_size);
|
||||
old_size = VG_PGROUNDUP(old_size);
|
||||
new_size = VG_PGROUNDUP(new_size);
|
||||
|
||||
if (PGROUNDDN(old_addr) != old_addr)
|
||||
if (VG_PGROUNDDN(old_addr) != old_addr)
|
||||
return -VKI_EINVAL;
|
||||
|
||||
if (!VG_(valid_client_addr)(old_addr, old_size, tid, "mremap(old_addr)"))
|
||||
@ -225,7 +225,7 @@ Addr mremap_segment ( Addr old_addr, SizeT old_size,
|
||||
flags &= ~(VKI_MREMAP_FIXED|VKI_MREMAP_MAYMOVE);
|
||||
|
||||
if (flags & VKI_MREMAP_FIXED) {
|
||||
if (PGROUNDDN(new_addr) != new_addr)
|
||||
if (VG_PGROUNDDN(new_addr) != new_addr)
|
||||
return -VKI_EINVAL;
|
||||
|
||||
if (!VG_(valid_client_addr)(new_addr, new_size, tid, "mremap(new_addr)"))
|
||||
@ -907,8 +907,8 @@ static Addr do_brk(Addr newbrk)
|
||||
if (seg != NULL && newbrk > seg->addr)
|
||||
return VG_(brk_limit);
|
||||
|
||||
current = PGROUNDUP(VG_(brk_limit));
|
||||
newaddr = PGROUNDUP(newbrk);
|
||||
current = VG_PGROUNDUP(VG_(brk_limit));
|
||||
newaddr = VG_PGROUNDUP(newbrk);
|
||||
if (newaddr != current) {
|
||||
|
||||
/* new brk in a new page - fix the mappings */
|
||||
|
||||
@ -265,15 +265,15 @@ static void main2(void)
|
||||
extern char _end;
|
||||
int *esp;
|
||||
char buf[strlen(valgrind_lib) + sizeof(stage2) + 16];
|
||||
info.exe_end = PGROUNDDN(init_sp);
|
||||
info.exe_end = VG_PGROUNDDN(init_sp);
|
||||
#ifdef HAVE_PIE
|
||||
info.exe_base = ROUNDDN(info.exe_end - 0x02000000, 0x10000000);
|
||||
assert(info.exe_base >= PGROUNDUP(&_end));
|
||||
info.exe_base = VG_ROUNDDN(info.exe_end - 0x02000000, 0x10000000);
|
||||
assert(info.exe_base >= VG_PGROUNDUP(&_end));
|
||||
info.map_base = info.exe_base + 0x01000000;
|
||||
#else
|
||||
// If this system doesn't have PIE (position-independent executables),
|
||||
// we have to choose a hardwired location for stage2.
|
||||
info.exe_base = PGROUNDUP(&_end);
|
||||
info.exe_base = VG_PGROUNDUP(&_end);
|
||||
info.map_base = KICKSTART_BASE + 0x01000000;
|
||||
#endif
|
||||
|
||||
|
||||
@ -251,22 +251,23 @@ ESZ(Addr) mapelf(struct elfinfo *e, ESZ(Addr) base)
|
||||
// use ph->p_align -- part of stage2's memory gets trashed somehow.)
|
||||
//
|
||||
// The condition handles the case of a zero-length segment.
|
||||
if (PGROUNDUP(bss)-PGROUNDDN(addr) > 0) {
|
||||
res = mmap((char *)PGROUNDDN(addr), PGROUNDUP(bss)-PGROUNDDN(addr),
|
||||
prot, MAP_FIXED|MAP_PRIVATE, e->fd, PGROUNDDN(off));
|
||||
check_mmap(res, (char*)PGROUNDDN(addr),
|
||||
PGROUNDUP(bss)-PGROUNDDN(addr));
|
||||
if (VG_PGROUNDUP(bss)-VG_PGROUNDDN(addr) > 0) {
|
||||
res = mmap((char *)VG_PGROUNDDN(addr),
|
||||
VG_PGROUNDUP(bss)-VG_PGROUNDDN(addr),
|
||||
prot, MAP_FIXED|MAP_PRIVATE, e->fd, VG_PGROUNDDN(off));
|
||||
check_mmap(res, (char*)VG_PGROUNDDN(addr),
|
||||
VG_PGROUNDUP(bss)-VG_PGROUNDDN(addr));
|
||||
}
|
||||
|
||||
// if memsz > filesz, fill the remainder with zeroed pages
|
||||
if (memsz > filesz) {
|
||||
UInt bytes;
|
||||
|
||||
bytes = PGROUNDUP(brkaddr)-PGROUNDUP(bss);
|
||||
bytes = VG_PGROUNDUP(brkaddr)-VG_PGROUNDUP(bss);
|
||||
if (bytes > 0) {
|
||||
res = mmap((char *)PGROUNDUP(bss), bytes,
|
||||
res = mmap((char *)VG_PGROUNDUP(bss), bytes,
|
||||
prot, MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
|
||||
check_mmap(res, (char*)PGROUNDUP(bss), bytes);
|
||||
check_mmap(res, (char*)VG_PGROUNDUP(bss), bytes);
|
||||
}
|
||||
|
||||
bytes = bss & (VKI_PAGE_SIZE - 1);
|
||||
@ -413,7 +414,7 @@ static int load_ELF(char *hdr, int len, int fd, const char *name,
|
||||
int flags = MAP_PRIVATE|MAP_ANONYMOUS;
|
||||
|
||||
if (info->map_base != 0) {
|
||||
base = (char *)ROUNDUP(info->map_base, interp_align);
|
||||
base = (char *)VG_ROUNDUP(info->map_base, interp_align);
|
||||
flags |= MAP_FIXED;
|
||||
}
|
||||
|
||||
|
||||
@ -77,12 +77,6 @@ static UInt n_lockorder_warnings = 0;
|
||||
/* Rotate an unsigned quantity left */
|
||||
#define ROTL(x, n) (((x) << (n)) | ((x) >> ((sizeof(x)*8)-(n))))
|
||||
|
||||
/* round a up to the next multiple of N. N must be a power of 2 */
|
||||
#define ROUNDUP(a, N) ((a + N - 1) & ~(N-1))
|
||||
|
||||
/* Round a down to the next multiple of N. N must be a power of 2 */
|
||||
#define ROUNDDN(a, N) ((a) & ~(N-1))
|
||||
|
||||
/*------------------------------------------------------------*/
|
||||
/*--- Command line options ---*/
|
||||
/*------------------------------------------------------------*/
|
||||
@ -1625,8 +1619,8 @@ void set_address_range_state ( Addr a, SizeT len /* in bytes */,
|
||||
* len/4+1 words. This works out which it is by aligning the block and
|
||||
* seeing if the end byte is in the same word as it is for the unaligned
|
||||
* block; if not, it's the awkward case. */
|
||||
end = ROUNDUP(a + len, 4);
|
||||
a = ROUNDDN(a, 4);
|
||||
end = VG_ROUNDUP(a + len, 4);
|
||||
a = VG_ROUNDDN(a, 4);
|
||||
|
||||
/* Do it ... */
|
||||
switch (status) {
|
||||
@ -3049,8 +3043,8 @@ static void hg_mem_read(Addr a, SizeT size, ThreadId tid)
|
||||
{
|
||||
Addr end;
|
||||
|
||||
end = ROUNDUP(a+size, 4);
|
||||
a = ROUNDDN(a, 4);
|
||||
end = VG_ROUNDUP(a+size, 4);
|
||||
a = VG_ROUNDDN(a, 4);
|
||||
|
||||
for ( ; a < end; a += 4)
|
||||
hg_mem_read_word(a, tid);
|
||||
@ -3154,8 +3148,8 @@ static void hg_mem_write(Addr a, SizeT size, ThreadId tid)
|
||||
{
|
||||
Addr end;
|
||||
|
||||
end = ROUNDUP(a+size, 4);
|
||||
a = ROUNDDN(a, 4);
|
||||
end = VG_ROUNDUP(a+size, 4);
|
||||
a = VG_ROUNDDN(a, 4);
|
||||
|
||||
for ( ; a < end; a += 4)
|
||||
hg_mem_write_word(a, tid);
|
||||
|
||||
@ -57,6 +57,12 @@
|
||||
/*=== Useful macros ===*/
|
||||
/*====================================================================*/
|
||||
|
||||
// 'a' -- the alignment -- must be a power of 2
|
||||
#define VG_ROUNDDN(p, a) ((Addr)(p) & ~((Addr)(a)-1))
|
||||
#define VG_ROUNDUP(p, a) VG_ROUNDDN((p)+(a)-1, (a))
|
||||
#define VG_PGROUNDDN(p) VG_ROUNDDN(p, VKI_PAGE_SIZE)
|
||||
#define VG_PGROUNDUP(p) VG_ROUNDUP(p, VKI_PAGE_SIZE)
|
||||
|
||||
/* No, really. I _am_ that strange. */
|
||||
#define OINK(nnn) VG_(message)(Vg_DebugMsg, "OINK %d",nnn)
|
||||
|
||||
|
||||
@ -38,11 +38,6 @@
|
||||
#define VG_DEBUG_LEAKCHECK 0
|
||||
#define VG_DEBUG_CLIQUE 0
|
||||
|
||||
#define ROUNDDN(p, a) ((Addr)(p) & ~((a)-1))
|
||||
#define ROUNDUP(p, a) ROUNDDN((p)+(a)-1, (a))
|
||||
#define PGROUNDDN(p) ROUNDDN(p, VKI_PAGE_SIZE)
|
||||
#define PGROUNDUP(p) ROUNDUP(p, VKI_PAGE_SIZE)
|
||||
|
||||
/*------------------------------------------------------------*/
|
||||
/*--- Low-level address-space scanning, for the leak ---*/
|
||||
/*--- detector. ---*/
|
||||
@ -371,8 +366,8 @@ static Int lc_markstack_pop(void)
|
||||
cliques, and clique is the index of the current clique leader. */
|
||||
static void _lc_scan_memory(Addr start, SizeT len, Int clique)
|
||||
{
|
||||
Addr ptr = ROUNDUP(start, sizeof(Addr));
|
||||
Addr end = ROUNDDN(start+len, sizeof(Addr));
|
||||
Addr ptr = VG_ROUNDUP(start, sizeof(Addr));
|
||||
Addr end = VG_ROUNDDN(start+len, sizeof(Addr));
|
||||
vki_sigset_t sigmask;
|
||||
|
||||
if (VG_DEBUG_LEAKCHECK)
|
||||
@ -384,14 +379,14 @@ static void _lc_scan_memory(Addr start, SizeT len, Int clique)
|
||||
|
||||
if (!VG_(is_client_addr)(ptr) ||
|
||||
!VG_(is_addressable)(ptr, sizeof(Addr), VKI_PROT_READ))
|
||||
ptr = PGROUNDUP(ptr+1); /* first page bad */
|
||||
ptr = VG_PGROUNDUP(ptr+1); /* first page bad */
|
||||
|
||||
while (ptr < end) {
|
||||
Addr addr;
|
||||
|
||||
/* Skip invalid chunks */
|
||||
if (!(*lc_is_within_valid_secondary)(ptr)) {
|
||||
ptr = ROUNDUP(ptr+1, SECONDARY_SIZE);
|
||||
ptr = VG_ROUNDUP(ptr+1, SECONDARY_SIZE);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -414,7 +409,7 @@ static void _lc_scan_memory(Addr start, SizeT len, Int clique)
|
||||
longjmped out of a signal handler. */
|
||||
VG_(sigprocmask)(VKI_SIG_SETMASK, &sigmask, NULL);
|
||||
|
||||
ptr = PGROUNDUP(ptr+1); /* bad page - skip it */
|
||||
ptr = VG_PGROUNDUP(ptr+1); /* bad page - skip it */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user