Move some utility functions to linker_utils
Also adds unit-tests for page_start, page_offset, and safe_add Change-Id: Ia1325b4682d367328a01599a19848e4ffcd2c0ea
This commit is contained in:

committed by
Dimitry Ivanov

parent
a1ab0d8ed1
commit
84bab5a955
@@ -105,3 +105,23 @@ bool parse_zip_path(const char* input_path, std::string* zip_path, std::string*
|
||||
return true;
|
||||
}
|
||||
|
||||
constexpr off64_t kPageMask = ~static_cast<off64_t>(PAGE_SIZE-1);
|
||||
|
||||
off64_t page_start(off64_t offset) {
|
||||
return offset & kPageMask;
|
||||
}
|
||||
|
||||
bool safe_add(off64_t* out, off64_t a, size_t b) {
|
||||
CHECK(a >= 0);
|
||||
if (static_cast<uint64_t>(INT64_MAX - a) < b) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*out = a + b;
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t page_offset(off64_t offset) {
|
||||
return static_cast<size_t>(offset & (PAGE_SIZE-1));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user