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:
Dmitriy Ivanov
2015-11-20 13:34:11 -08:00
committed by Dimitry Ivanov
parent a1ab0d8ed1
commit 84bab5a955
4 changed files with 46 additions and 20 deletions

View File

@@ -16,32 +16,13 @@
#include "linker_mapped_file_fragment.h"
#include "linker_debug.h"
#include "linker_utils.h"
#include <inttypes.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <unistd.h>
constexpr off64_t kPageMask = ~static_cast<off64_t>(PAGE_SIZE-1);
static off64_t page_start(off64_t offset) {
return offset & kPageMask;
}
static 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;
}
static size_t page_offset(off64_t offset) {
return static_cast<size_t>(offset & (PAGE_SIZE-1));
}
MappedFileFragment::MappedFileFragment() : map_start_(nullptr), map_size_(0),
data_(nullptr), size_ (0)
{ }