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 <pthread.h> | 5 #include <pthread.h> |
6 | 6 |
7 #include "native_client/src/include/nacl_assert.h" | 7 #include "native_client/src/include/nacl_assert.h" |
8 #include "native_client/src/untrusted/pll_loader/pll_loader.h" | 8 #include "native_client/src/untrusted/pll_loader/pll_loader.h" |
9 | 9 |
10 | 10 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 ModuleSet modset; | 51 ModuleSet modset; |
52 std::vector<std::string> search_path; | 52 std::vector<std::string> search_path; |
53 search_path.push_back(module_directory); | 53 search_path.push_back(module_directory); |
54 modset.SetSonameSearchPath(search_path); | 54 modset.SetSonameSearchPath(search_path); |
55 | 55 |
56 // "module_a_var" should only be resolvable after we load module A. | 56 // "module_a_var" should only be resolvable after we load module A. |
57 int *module_a_var = (int *) modset.GetSym("module_a_var"); | 57 int *module_a_var = (int *) modset.GetSym("module_a_var"); |
58 ASSERT_EQ(module_a_var, NULL); | 58 ASSERT_EQ(module_a_var, NULL); |
59 | 59 |
60 modset.AddBySoname(module_a_soname); | 60 ASSERT_NE(modset.AddBySoname(module_a_soname), NULL); |
61 module_a_var = (int *) modset.GetSym("module_a_var"); | 61 module_a_var = (int *) modset.GetSym("module_a_var"); |
62 ASSERT_NE(module_a_var, NULL); | 62 ASSERT_NE(module_a_var, NULL); |
63 ASSERT_EQ(*module_a_var, 2345); | 63 ASSERT_EQ(*module_a_var, 2345); |
64 | 64 |
65 modset.AddBySoname(module_b_soname); | 65 // Demonstrate that the same soname cannot be loaded multiple times. |
| 66 ASSERT_EQ(modset.AddBySoname(module_a_soname), NULL); |
| 67 |
| 68 ASSERT_NE(modset.AddBySoname(module_b_soname), NULL); |
66 int *module_b_var = (int *) modset.GetSym("module_b_var"); | 69 int *module_b_var = (int *) modset.GetSym("module_b_var"); |
67 ASSERT_NE(module_b_var, NULL); | 70 ASSERT_NE(module_b_var, NULL); |
68 ASSERT_EQ(*module_b_var, 1234); | 71 ASSERT_EQ(*module_b_var, 1234); |
69 | 72 |
70 modset.AddBySoname(module_tls_soname); | 73 ASSERT_NE(modset.AddBySoname(module_tls_soname), NULL); |
71 | 74 |
72 modset.ResolveRefs(); | 75 modset.ResolveRefs(); |
73 | 76 |
74 // Check that "addr_of_module_a_var" has been correctly relocated to | 77 // Check that "addr_of_module_a_var" has been correctly relocated to |
75 // point to the other module. | 78 // point to the other module. |
76 int **addr_of_module_a_var = (int **) modset.GetSym("addr_of_module_a_var"); | 79 int **addr_of_module_a_var = (int **) modset.GetSym("addr_of_module_a_var"); |
77 ASSERT_NE(addr_of_module_a_var, NULL); | 80 ASSERT_NE(addr_of_module_a_var, NULL); |
78 ASSERT_EQ(*addr_of_module_a_var, module_a_var); | 81 ASSERT_EQ(*addr_of_module_a_var, module_a_var); |
79 | 82 |
80 // Test that TLS variables are instantiated and aligned properly. | 83 // Test that TLS variables are instantiated and aligned properly. |
(...skipping 12 matching lines...) Expand all Loading... |
93 int err = pthread_create(&tid, NULL, ThreadFunc, &thread_args); | 96 int err = pthread_create(&tid, NULL, ThreadFunc, &thread_args); |
94 ASSERT_EQ(err, 0); | 97 ASSERT_EQ(err, 0); |
95 err = pthread_join(tid, NULL); | 98 err = pthread_join(tid, NULL); |
96 ASSERT_EQ(err, 0); | 99 ASSERT_EQ(err, 0); |
97 // Check that the TLS var is still given the same address. This | 100 // Check that the TLS var is still given the same address. This |
98 // should not have been affected by launching a child thread. | 101 // should not have been affected by launching a child thread. |
99 ASSERT_EQ(thread_args.tls_var_getter(), thread_args.tls_var_on_main_thread); | 102 ASSERT_EQ(thread_args.tls_var_getter(), thread_args.tls_var_on_main_thread); |
100 | 103 |
101 return 0; | 104 return 0; |
102 } | 105 } |
OLD | NEW |