Thanks for your reply! I just didn't know I can manually control the bounds.
George.
---Original---
From: "Michael Matz"<address@hidden>
Date: 2018/4/7 03:44:55
To: "tinycc-devel"<address@hidden>;
Subject: Re: [Tinycc-devel] The built-in memory and bounds checker cannothandle mmap'd memory and judges errno wrong
Hi,
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:
#ifdef __BOUNDS_CHECKING_ON
void __bound_new_region(void *p, size_t size);
int __bound_delete_region(void *p);
#endif
... somewhere early in main, before forking, and before accessing errno ...
#ifdef __BOUNDS_CHECKING_ON
__bound_new_region(&errno, sizeof (errno));
#endif
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.
Ciao,
Michael.
_______________________________________________
Tinycc-devel mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/tinycc-devel