1 /* Copyright (c) 2014. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
13 #include "mc_private.h"
15 /** @brief How many memory pages are necessary to store size bytes?
17 * @param size Byte size
18 * @return Number of memory pages
20 static inline size_t mc_page_count(size_t size)
22 size_t page_count = size >> xbt_pagebits;
23 if (size & (xbt_pagesize-1)) {
29 /** @brief Get the virtual memory page number of a given address
31 * @param address Address
32 * @return Virtual memory page number of the given address
34 static inline size_t mc_page_number(void* base, void* address)
36 xbt_assert(address>=base, "The address is not in the range");
37 return ((uintptr_t) address - (uintptr_t) base) >> xbt_pagebits;
40 /** @brief Get the offset of an address within a memory page
42 * @param address Address
43 * @return Offset within the memory page
45 static inline size_t mc_page_offset(void* address)
47 return ((uintptr_t) address) & (xbt_pagesize-1);
50 /** @brief Get the virtual address of a virtual memory page
52 * @param base Address of the first page
53 * @param page Index of the page
55 static inline void* mc_page_from_number(void* base, size_t page)
57 return (void*) ((char*)base + (page << xbt_pagebits));
60 static inline bool mc_same_page(void* a, void* b)
62 return mc_page_number(NULL, a) == mc_page_number(NULL, b);