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. */
12 #include "mc_private.h"
14 /** @brief How many memory pages are necessary to store size bytes?
16 * @param size Byte size
17 * @return Number of memory pages
19 static inline size_t mc_page_count(size_t size)
21 size_t page_count = size >> xbt_pagebits;
22 if (size & (xbt_pagesize-1)) {
28 /** @brief Get the virtual memory page number of a given address
30 * @param address Address
31 * @return Virtual memory page number of the given address
33 static inline size_t mc_page_number(void* address)
35 return ((uintptr_t) address) >> xbt_pagebits;
38 /** @brief Get the offset of an address within a memory page
40 * @param address Address
41 * @return Offset within the memory page
43 static inline size_t mc_page_offset(void* address)
45 return ((uintptr_t) address) & (xbt_pagesize-1);
48 /** @brief Get the virtual address of a virtual memory page
50 * @param base Address of the first page
51 * @param page Index of the page
53 static inline void* mc_page_from_number(void* base, size_t page)
55 return (void*) ((char*)base + (page << xbt_pagebits));