Skip to content

Commit

Permalink
get page_size dynamically from sysconf
Browse files Browse the repository at this point in the history
  • Loading branch information
dmoody256 committed Jan 26, 2022
1 parent d859dcd commit 8e357e2
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/aarch64/Ginit.c
Expand Up @@ -25,10 +25,11 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */

#include <errno.h>
#include <stdatomic.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <stdatomic.h>
#include <unistd.h>

#include "unwind_i.h"

Expand Down Expand Up @@ -84,9 +85,9 @@ get_dyn_info_list_addr (unw_addr_space_t as, unw_word_t *dyn_info_list_addr,
return 0;
}

#define PAGE_SIZE 4096
#define PAGE_START(a) ((a) & ~(PAGE_SIZE-1))
#define PAGE_START(addr, page_size) ((addr) & ~(page_size - 1))

static int mem_page_size;
static int mem_validate_pipe[2] = {-1, -1};

#ifdef HAVE_PIPE2
Expand Down Expand Up @@ -194,13 +195,14 @@ HIDDEN void
tdep_init_mem_validate (void)
{
open_pipe ();
mem_page_size = sysconf(_SC_PAGESIZE);

#ifdef HAVE_MINCORE
unsigned char present = 1;
unw_word_t addr = PAGE_START((unw_word_t)&present);
unw_word_t addr = PAGE_START((unw_word_t)&present, mem_page_size);
unsigned char mvec[1];
int ret;
while ((ret = mincore ((void*)addr, PAGE_SIZE, (unsigned char *)mvec)) == -1 &&
while ((ret = mincore((void*)addr, mem_page_size, (unsigned char*)mvec)) == -1 &&
errno == EAGAIN) {}
if (ret == 0)
{
Expand Down Expand Up @@ -295,12 +297,9 @@ validate_mem (unw_word_t addr)
{
size_t len;

if (PAGE_START(addr + sizeof (unw_word_t) - 1) == PAGE_START(addr))
len = PAGE_SIZE;
else
len = PAGE_SIZE * 2;

addr = PAGE_START(addr);
len = mem_page_size;
addr = PAGE_START(addr, mem_page_size);

if (addr == 0)
return -1;
Expand Down

0 comments on commit 8e357e2

Please sign in to comment.