liblog: remove faulty logic in __android_logger_valid_buffer_size

In testing, I saw that the 'main' and 'events' log buffers were set to
incorrect sizes when they were intended to be >= 4MB.  The bug is
tracked down to an invalid line in
__android_logger_valid_buffer_size():

  /* maximum memory impact a somewhat arbitrary ~3% */
  pages = (pages + 31) / 32;

There are two issues with this line:
1) That is not the right calculation for 3%.
2) `pages` is a static variable, so it repeatedly is decremented until
   reaching 1.

The consequence is that this function gives invalid results for the
first few calls, then returns true as long as the input is between
LOG_BUFFER_MIN_SIZE and LOG_BUFFER_MAX_SIZE.  That check is enough, so
the rest of this logic is removed.

Test: buffers are set to the right sizes.
Change-Id: I4d19b1d0fdbd83843d2d61a484ac083d571ef37b
This commit is contained in:
Tom Cherry 2020-07-09 20:39:17 -07:00
parent 69b513ce09
commit 0315b29497
1 changed files with 1 additions and 30 deletions

View File

@ -474,36 +474,7 @@ bool __android_logger_property_get_bool(const char* key, int flag) {
}
bool __android_logger_valid_buffer_size(unsigned long value) {
static long pages, pagesize;
unsigned long maximum;
if ((value < LOG_BUFFER_MIN_SIZE) || (LOG_BUFFER_MAX_SIZE < value)) {
return false;
}
if (!pages) {
pages = sysconf(_SC_PHYS_PAGES);
}
if (pages < 1) {
return true;
}
if (!pagesize) {
pagesize = sysconf(_SC_PAGESIZE);
if (pagesize <= 1) {
pagesize = PAGE_SIZE;
}
}
/* maximum memory impact a somewhat arbitrary ~3% */
pages = (pages + 31) / 32;
maximum = pages * pagesize;
if ((maximum < LOG_BUFFER_MIN_SIZE) || (LOG_BUFFER_MAX_SIZE < maximum)) {
return true;
}
return value <= maximum;
return LOG_BUFFER_MIN_SIZE <= value && value <= LOG_BUFFER_MAX_SIZE;
}
struct cache2_property_size {