process_builder/
util.rs

1// Copyright 2019 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use zx::system_get_page_size;
6
7/// Returns the starting address of the page that contains this address. For example, if page size
8/// is 0x1000, page_start(0x3001) == page_start(0x3FAB) == 0x3000.
9pub fn page_start(addr: usize) -> usize {
10    addr & !(system_get_page_size() as usize - 1)
11}
12
13/// Returns the offset of the address within its page. For example, if page size is 0x1000,
14/// page_offset(0x2ABC) == page_offset(0x5ABC) == 0xABC.
15pub fn page_offset(addr: usize) -> usize {
16    addr & (system_get_page_size() as usize - 1)
17}
18
19/// Returns starting address of the next page after the one that contains this address, unless
20/// address is already page aligned. For example, if page size is 0x1000, page_end(0x4001) ==
21/// page_end(0x4FFF) == 0x5000, but page_end(0x4000) == 0x4000.
22pub fn page_end(addr: usize) -> usize {
23    page_start(addr + (system_get_page_size() as usize) - 1)
24}