1 : /*
2 : * Copyright 2010 The Native Client Authors. All rights reserved.
3 : * Use of this source code is governed by a BSD-style license that can
4 : * be found in the LICENSE file.
5 : */
6 :
7 : #include <stdio.h>
8 : #include <stdint.h>
9 : #include <sys/mman.h>
10 : #include <sys/types.h>
11 :
12 : #include "native_client/src/shared/platform/nacl_find_addrsp.h"
13 :
14 : #include "native_client/src/include/portability.h"
15 : #include "native_client/src/include/nacl_platform.h"
16 : #include "native_client/src/shared/platform/nacl_log.h"
17 :
18 : /* bool */
19 8 : int NaClFindAddressSpace(uintptr_t *addr, size_t memory_size) {
20 : void *map_addr;
21 :
22 8 : NaClLog(4,
23 : "NaClFindAddressSpace: looking for %"NACL_PRIxS" bytes\n",
24 : memory_size);
25 8 : map_addr = mmap(NULL, memory_size,
26 : PROT_READ | PROT_WRITE,
27 : MAP_ANONYMOUS | MAP_NORESERVE | MAP_PRIVATE,
28 : 0,
29 : 0);
30 8 : if (MAP_FAILED == map_addr) {
31 0 : return 0;
32 : }
33 8 : NaClLog(4,
34 : "NaClFindAddressSpace: got addr %"NACL_PRIxPTR"\n",
35 : (uintptr_t) map_addr);
36 8 : *addr = (uintptr_t) map_addr;
37 8 : return 1;
38 : }
|