OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The Native Client Authors. All rights reserved. | 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 | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 /* | 7 /* |
8 * This exercises the public interface of MinSFI. | 8 * This exercises the public interface of MinSFI. |
9 * | 9 * |
10 * Internally, we verify that running the Initialize function changes the | 10 * Internally, we verify that running the Initialize function changes the |
11 * active sandbox and sets the memory base for the sandboxed code. Destroying | 11 * active sandbox and sets the memory base for the sandboxed code. Destroying |
12 * the sandbox should reset both to NULL. | 12 * the sandbox should reset both to NULL. |
13 * | 13 * |
14 * For the public interface, we check that the Initialize, Invoke and Destroy | 14 * For the public interface, we check that the Initialize, Invoke and Destroy |
15 * functions behave correctly when called in the right context, and that they | 15 * functions behave correctly when called in the right context, and that they |
16 * do not crash the program otherwise. | 16 * do not crash the program otherwise. |
17 */ | 17 */ |
18 | 18 |
19 #include "native_client/src/include/minsfi.h" | 19 #include "native_client/src/include/minsfi.h" |
20 #include "native_client/src/include/minsfi_priv.h" | 20 #include "native_client/src/include/minsfi_priv.h" |
21 #include "native_client/src/include/nacl_assert.h" | 21 #include "native_client/src/include/nacl_assert.h" |
22 | 22 |
23 extern uint64_t __sfi_memory_base; | 23 extern uint64_t __sfi_memory_base; |
24 | 24 |
| 25 static int argc = 1; |
| 26 static char *argv[] = { "foo" }; |
| 27 |
25 void helper_initialize(void) { | 28 void helper_initialize(void) { |
26 ASSERT_EQ(true, MinsfiInitializeSandbox()); | 29 ASSERT_EQ(true, MinsfiInitializeSandbox()); |
27 ASSERT_NE(NULL, MinsfiGetActiveSandbox()); | 30 ASSERT_NE(NULL, MinsfiGetActiveSandbox()); |
28 ASSERT_NE(0, __sfi_memory_base); | 31 ASSERT_NE(0, __sfi_memory_base); |
29 ASSERT_EQ(__sfi_memory_base, (uintptr_t) MinsfiGetActiveSandbox()->mem_base); | 32 ASSERT_EQ(__sfi_memory_base, (uintptr_t) MinsfiGetActiveSandbox()->mem_base); |
30 } | 33 } |
31 | 34 |
32 void helper_invoke_success(void) { | 35 void helper_invoke_success(void) { |
33 ASSERT_EQ((int) 0xCAFEBABE, MinsfiInvokeSandbox()); | 36 ASSERT_EQ((int) 0xCAFEBABE, MinsfiInvokeSandbox(argc, argv)); |
34 } | 37 } |
35 | 38 |
36 void helper_invoke_error(void) { | 39 void helper_invoke_error(void) { |
37 ASSERT_EQ(EXIT_FAILURE, MinsfiInvokeSandbox()); | 40 ASSERT_EQ(EXIT_FAILURE, MinsfiInvokeSandbox(argc, argv)); |
38 } | 41 } |
39 | 42 |
40 void helper_destroy(void) { | 43 void helper_destroy(void) { |
41 ASSERT_EQ(true, MinsfiDestroySandbox()); | 44 ASSERT_EQ(true, MinsfiDestroySandbox()); |
42 ASSERT_EQ(NULL, MinsfiGetActiveSandbox()); | 45 ASSERT_EQ(NULL, MinsfiGetActiveSandbox()); |
43 ASSERT_EQ(0, __sfi_memory_base); | 46 ASSERT_EQ(0, __sfi_memory_base); |
44 } | 47 } |
45 | 48 |
46 int main(void) { | 49 int main(void) { |
47 int i; | 50 int i; |
(...skipping 24 matching lines...) Expand all Loading... |
72 helper_invoke_success(); | 75 helper_invoke_success(); |
73 } | 76 } |
74 | 77 |
75 /* Now try destroying it multiple times. */ | 78 /* Now try destroying it multiple times. */ |
76 for (i = 0; i < 3; i++) | 79 for (i = 0; i < 3; i++) |
77 helper_destroy(); | 80 helper_destroy(); |
78 | 81 |
79 /* Finally, invoking the sandbox after it's been destroyed should fail. */ | 82 /* Finally, invoking the sandbox after it's been destroyed should fail. */ |
80 helper_invoke_error(); | 83 helper_invoke_error(); |
81 } | 84 } |
OLD | NEW |