On Fri, 6 Apr 2018, George Gaarder wrote:
I just tried -b to see whether I forgot to free something, and I found that
the memory and bounds checker will alert when I use the memory I mmap'd. Whi
le I was writing a demo for report, I found that the checker also reported o
ut of region when I accessed errno. I was to print errno to see if I really
opened the file to be mmap'd.
I think the warning for the mmap'd memory is not a problem, just needed to b
e pointed out in the document. But the errno one is quite strange.
Add these snippets to your program:
void __bound_new_region(void *p, size_t size);
int __bound_delete_region(void *p);
... somewhere early in main, before forking, and before accessing errno ...
__bound_new_region(&errno, sizeof (errno));
Keep in mind that errno is a thread local variable (which is also the
reason why it doesn't work out-of-box, like some other global vars like
stdout work), so you would have to register each new errno location after
you create a new thread. With the above two functions you can also write
a wrapper for mmap/munmap that suits you.
We could also register at least errno for the main thread at program start
(in __bounds_init), but it'd still not be a complete solution for
multi-threaded programs (let's ignore all other problems connected with
TCCs bound checking and multiple threads), so I'm split-mind about this.
Tinycc-devel mailing list