Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(570)

Side by Side Diff: tests/irt_ext/mem_calls.c

Issue 511253005: Added irt extension support for supplying the nacl_irt_memory interface. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Moved size declaration down Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/irt_ext/mem_calls.h ('k') | tests/irt_ext/nacl.scons » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2014 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6
7 #include "native_client/src/include/nacl_assert.h"
8 #include "native_client/src/untrusted/irt/irt.h"
9 #include "native_client/src/untrusted/irt/irt_extension.h"
10 #include "native_client/tests/irt_ext/mem_calls.h"
11
12 static struct mem_calls_environment *g_activated_env = NULL;
13 static const struct mem_calls_environment g_empty_env = { 0 };
14 static struct nacl_irt_memory g_irt_memory = { NULL };
15
16 static int my_mmap(void **addr, size_t len, int prot, int flags, int fd,
17 nacl_irt_off_t off) {
18 if (g_activated_env) {
19 g_activated_env->num_mmap_calls++;
20 }
21
22 return g_irt_memory.mmap(addr, len, prot, flags, fd, off);
23 }
24
25 static int my_munmap(void *addr, size_t len) {
26 if (g_activated_env) {
27 g_activated_env->num_munmap_calls++;
28 }
29
30 return g_irt_memory.munmap(addr, len);
31 }
32
33 static int my_mprotect(void *addr, size_t len, int prot) {
34 if (g_activated_env) {
35 g_activated_env->num_mprotect_calls++;
36 }
37
38 return g_irt_memory.mprotect(addr, len, prot);
39 }
40
41 void init_mem_calls_module(void) {
42 size_t bytes = nacl_interface_query(NACL_IRT_MEMORY_v0_3,
43 &g_irt_memory, sizeof(g_irt_memory));
44 ASSERT_EQ(bytes, sizeof(g_irt_memory));
45
46 struct nacl_irt_memory mem = {
47 my_mmap,
48 my_munmap,
49 my_mprotect
50 };
51
52 bytes = nacl_interface_ext_supply(NACL_IRT_MEMORY_v0_3, &mem,
53 sizeof(mem));
54 ASSERT_EQ(bytes, sizeof(mem));
55 }
56
57 void init_mem_calls_environment(struct mem_calls_environment *env) {
58 *env = g_empty_env;
59 }
60
61 void activate_mem_calls_env(struct mem_calls_environment *env) {
62 g_activated_env = env;
63 }
64
65 void deactivate_mem_calls_env(void) {
66 g_activated_env = NULL;
67 }
OLDNEW
« no previous file with comments | « tests/irt_ext/mem_calls.h ('k') | tests/irt_ext/nacl.scons » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698