OLD | NEW |
1 // Copyright 2016 The Native Client Authors. All rights reserved. | 1 // Copyright 2016 The Native Client Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "native_client/src/include/nacl_assert.h" | 5 #include "native_client/src/include/nacl_assert.h" |
6 #include "native_client/src/untrusted/pll_loader/pll_loader.h" | 6 #include "native_client/src/untrusted/pll_loader/pll_loader.h" |
7 | 7 |
8 | 8 |
9 namespace { | 9 namespace { |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 ModuleSet modset; | 35 ModuleSet modset; |
36 std::vector<std::string> search_path; | 36 std::vector<std::string> search_path; |
37 search_path.push_back(module_directory); | 37 search_path.push_back(module_directory); |
38 modset.SetSonameSearchPath(search_path); | 38 modset.SetSonameSearchPath(search_path); |
39 | 39 |
40 // "module_a_var" should only be resolvable after we load module A. | 40 // "module_a_var" should only be resolvable after we load module A. |
41 int *module_a_var = (int *) modset.GetSym("module_a_var"); | 41 int *module_a_var = (int *) modset.GetSym("module_a_var"); |
42 ASSERT_EQ(module_a_var, NULL); | 42 ASSERT_EQ(module_a_var, NULL); |
43 | 43 |
44 modset.AddBySoname(module_a_soname); | 44 ASSERT_NE(modset.AddBySoname(module_a_soname), NULL); |
45 module_a_var = (int *) modset.GetSym("module_a_var"); | 45 module_a_var = (int *) modset.GetSym("module_a_var"); |
46 ASSERT_NE(module_a_var, NULL); | 46 ASSERT_NE(module_a_var, NULL); |
47 ASSERT_EQ(*module_a_var, 2345); | 47 ASSERT_EQ(*module_a_var, 2345); |
48 | 48 |
49 modset.AddBySoname(module_b_soname); | 49 // Demonstrate that the same soname cannot be loaded multiple times. |
| 50 ASSERT_EQ(modset.AddBySoname(module_a_soname), NULL); |
| 51 |
| 52 ASSERT_NE(modset.AddBySoname(module_b_soname), NULL); |
50 int *module_b_var = (int *) modset.GetSym("module_b_var"); | 53 int *module_b_var = (int *) modset.GetSym("module_b_var"); |
51 ASSERT_NE(module_b_var, NULL); | 54 ASSERT_NE(module_b_var, NULL); |
52 ASSERT_EQ(*module_b_var, 1234); | 55 ASSERT_EQ(*module_b_var, 1234); |
53 | 56 |
54 modset.AddBySoname(module_tls_soname); | 57 ASSERT_NE(modset.AddBySoname(module_tls_soname), NULL); |
55 | 58 |
56 modset.ResolveRefs(); | 59 modset.ResolveRefs(); |
57 | 60 |
58 // Check that "addr_of_module_a_var" has been correctly relocated to | 61 // Check that "addr_of_module_a_var" has been correctly relocated to |
59 // point to the other module. | 62 // point to the other module. |
60 int **addr_of_module_a_var = (int **) modset.GetSym("addr_of_module_a_var"); | 63 int **addr_of_module_a_var = (int **) modset.GetSym("addr_of_module_a_var"); |
61 ASSERT_NE(addr_of_module_a_var, NULL); | 64 ASSERT_NE(addr_of_module_a_var, NULL); |
62 ASSERT_EQ(*addr_of_module_a_var, module_a_var); | 65 ASSERT_EQ(*addr_of_module_a_var, module_a_var); |
63 | 66 |
64 // Test that TLS variables are instantiated and aligned properly. | 67 // Test that TLS variables are instantiated and aligned properly. |
65 CheckTlsVar<int>(&modset, "get_tls_var1", sizeof(int), 123); | 68 CheckTlsVar<int>(&modset, "get_tls_var1", sizeof(int), 123); |
66 CheckTlsVar<int *>(&modset, "get_tls_var2", sizeof(int), module_a_var); | 69 CheckTlsVar<int *>(&modset, "get_tls_var2", sizeof(int), module_a_var); |
67 CheckTlsVar<int>(&modset, "get_tls_var_aligned", 256, 345); | 70 CheckTlsVar<int>(&modset, "get_tls_var_aligned", 256, 345); |
68 CheckTlsVar<int>(&modset, "get_tls_bss_var1", sizeof(int), 0); | 71 CheckTlsVar<int>(&modset, "get_tls_bss_var1", sizeof(int), 0); |
69 CheckTlsVar<int>(&modset, "get_tls_bss_var_aligned", 256, 0); | 72 CheckTlsVar<int>(&modset, "get_tls_bss_var_aligned", 256, 0); |
70 | 73 |
71 return 0; | 74 return 0; |
72 } | 75 } |
OLD | NEW |