Half Assed, Noisy Valgrind Support: Patch.
[Thread Prev] | [Thread Next]
- Subject: Half Assed, Noisy Valgrind Support: Patch.
- From: Ori Bernstein <ori@xxxxxxxxxxxxxx>
- Date: Wed, 27 Jan 2016 01:04:44 -0800
- To: myrddin-dev@xxxxxxxxxxxxxx
If you're playing with this, and manage to get some use out of it, good for you. Note that most of the errors it spews seem to be spurious, but if you have a giant leak, it will probably be able to find it. It doesn't seem to know about any global variables, and seems to report some spurious leaks. If anyone has time to mess with this and get it into useful shape, though, I will owe you all the beers. -- Ori Bernstein
commit 7df5f1a520dd1a639d3476d85b8990d0a40b0ebf Author: Ori Bernstein <ori@xxxxxxxxxxxxxx> Date: Wed Jan 27 00:15:44 2016 -0800 Add broken valgrind hooks. diff --git a/lib/std/alloc.myr b/lib/std/alloc.myr index dc7f9d1..94196fe 100644 --- a/lib/std/alloc.myr +++ b/lib/std/alloc.myr @@ -40,8 +40,6 @@ pkg std = const bytealloc : (sz:size -> byte#) const zbytealloc : (sz:size -> byte#) const bytefree : (m:byte#, sz:size -> void) - - ;; /* null pointers. only used internally. */ @@ -54,6 +52,10 @@ const Bktmax = 32*KiB /* Slabsz / 8; a balance. */ const Pagesz = 4*KiB const Align = 16 /* minimum allocation alignment */ +extern const vgmarkalloc : (ptr : byte#, len : size -> void) +extern const vgmarkresize : (ptr : byte#, olen : size, nlen : size -> void) +extern const vgmarkfree : (ptr : byte# -> void) + var buckets : bucket[32] /* excessive */ type slheader = struct @@ -166,6 +168,7 @@ generic slgrow = {sl : @a[:], len /* if the slice doesn't need a bigger bucket, we don't need to realloc. */ if sl.len > 0 && slcap(sl castto(byte#)) >= allocsz(len*sizeof(@a)) + vgmarkresize(new castto(byte#), sl.len * sizeof(@a), len * sizeof(@a)) -> (sl castto(@a#))[:len] ;; @@ -222,6 +225,7 @@ const bytealloc = {sz die("could not get memory\n") ;; ;; + vgmarkalloc(p, sz) -> p } @@ -236,6 +240,7 @@ const bytefree = {p, sz else freemem(p, sz) ;; + vgmarkfree(p) } /* Sets up a single empty bucket */ diff --git a/lib/std/bld.sub b/lib/std/bld.sub index 3101471..e516460 100644 --- a/lib/std/bld.sub +++ b/lib/std/bld.sub @@ -88,6 +88,7 @@ lib std {inc=.} = dial+plan9.myr resolve+posixy.myr resolve+plan9.myr + valgrindhooks+posixy-x64.s # relatively generic syscall wrappers syswrap+plan9.myr diff --git a/lib/std/valgrindhooks+posixy-x64.s b/lib/std/valgrindhooks+posixy-x64.s new file mode 100644 index 0000000..d332b9b --- /dev/null +++ b/lib/std/valgrindhooks+posixy-x64.s @@ -0,0 +1,72 @@ +/* std.vgmarkalloc : (ptr : byte#, sz : size -> void) */ +.globl std$vgmarkalloc +std$vgmarkalloc: + pushq %rbp + movq %rsp, %rbp + /* a nop sequence that valgrind recognizes as marking an alloc */ + movq $4865, -48(%rbp) + movq %rdi, -40(%rbp) + movq %rsi, -32(%rbp) + movq $0, -24(%rbp) + movq $0, -16(%rbp) + movq $0, -8(%rbp) + leaq -48(%rbp), %rax + xorl %edx, %edx + rolq $3, %rdi + rolq $13, %rdi + rolq $61, %rdi + rolq $51, %rdi + xchgq %rbx,%rbx + movq %rdx, -56(%rbp) + movq -56(%rbp), %rax + popq %rbp + ret + +/* std.vgmarkresize : (ptr : byte#, osz : size, nsz : size -> void) */ +.globl std$vgmarkresize +std$vgmarkresize: + pushq %rbp + movq %rsp, %rbp + /* a nop sequence that valgrind recognizes as marking an block growth */ + movq $4875, -48(%rbp) + movq %rdi, -40(%rbp) + movq %rsi, -32(%rbp) + movq %rdx, -24(%rbp) + movq $0, -16(%rbp) + movq $0, -8(%rbp) + leaq -48(%rbp), %rax + xorl %edx, %edx + rolq $3, %rdi + rolq $13, %rdi + rolq $61, %rdi + rolq $51, %rdi + xchgq %rbx,%rbx + movq %rdx, -56(%rbp) + movq -56(%rbp), %rax + popq %rbp + ret + + +/* std.vgmarkfree : (ptr : byte# -> void) */ +.globl std$vgmarkfree +std$vgmarkfree: + pushq %rbp + movq %rsp, %rbp + /* a nop sequence that valgrind recognizes as marking a free */ + movq $4866, -48(%rbp) + movq %rdi, -40(%rbp) + movq $0, -32(%rbp) + movq $0, -24(%rbp) + movq $0, -16(%rbp) + movq $0, -8(%rbp) + leaq -48(%rbp), %rax + xorl %edx, %edx + rolq $3, %rdi + rolq $13, %rdi + rolq $61, %rdi + rolq $51, %rdi + xchgq %rbx,%rbx + movq %rdx, -56(%rbp) + movq -56(%rbp), %rax + popq %rbp + ret
Re: Half Assed, Noisy Valgrind Support: Patch. | Ryan Gonzalez <rymg19@xxxxxxxxx> |
- Prev by Date: Re: C Binding Generation: Request for Comments
- Next by Date: Re: Half Assed, Noisy Valgrind Support: Patch.
- Previous by thread: Re: C Binding Generation: Request for Comments
- Next by thread: Re: Half Assed, Noisy Valgrind Support: Patch.
- Index(es):