Move some utility functions to linker_utils
Also adds unit-tests for page_start, page_offset, and safe_add
Change-Id: Ia1325b4682d367328a01599a19848e4ffcd2c0ea
diff --git a/linker/linker_mapped_file_fragment.cpp b/linker/linker_mapped_file_fragment.cpp
index 6a500ef..27c1c69 100644
--- a/linker/linker_mapped_file_fragment.cpp
+++ b/linker/linker_mapped_file_fragment.cpp
@@ -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)
{ }