| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2011 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 #include <unistd.h> | 7 #include <unistd.h> |
| 8 | 8 |
| 9 #include "native_client/src/untrusted/nacl/nacl_irt.h" | 9 #include "native_client/src/untrusted/nacl/nacl_irt.h" |
| 10 #include "native_client/src/untrusted/nacl/nacl_thread.h" | 10 #include "native_client/src/untrusted/nacl/nacl_thread.h" |
| 11 #include "native_client/src/untrusted/nacl/tls.h" | 11 #include "native_client/src/untrusted/nacl/tls.h" |
| 12 | 12 |
| 13 /* | 13 /* |
| 14 * This initialization happens early in startup with or without libpthread. | 14 * This initialization happens early in startup with or without libpthread. |
| 15 * It must make it safe for vanilla newlib code to run. | 15 * It must make it safe for vanilla newlib code to run. |
| 16 */ | 16 */ |
| 17 int __pthread_initialize_minimal(size_t tdb_size) { | 17 int __pthread_initialize_minimal(size_t tdb_size) { |
| 18 /* | |
| 19 * TODO(mcgrathr): This ought to be called by the startup code before | |
| 20 * this. But there are too many variants of that code that would | |
| 21 * all need to be changed. | |
| 22 * See http://code.google.com/p/nativeclient/issues/detail?id=651 | |
| 23 */ | |
| 24 __libnacl_irt_init(); | |
| 25 | |
| 26 /* Adapt size for sbrk. */ | 18 /* Adapt size for sbrk. */ |
| 27 /* TODO(robertm): this is somewhat arbitrary - re-examine). */ | 19 /* TODO(robertm): this is somewhat arbitrary - re-examine). */ |
| 28 size_t combined_size = (__nacl_tls_combined_size(tdb_size) + 15) & ~15; | 20 size_t combined_size = (__nacl_tls_combined_size(tdb_size) + 15) & ~15; |
| 29 | 21 |
| 30 /* | 22 /* |
| 31 * Use sbrk not malloc here since the library is not initialized yet. | 23 * Use sbrk not malloc here since the library is not initialized yet. |
| 32 */ | 24 */ |
| 33 void *combined_area = sbrk(combined_size); | 25 void *combined_area = sbrk(combined_size); |
| 34 | 26 |
| 35 /* | 27 /* |
| 36 * Fill in that memory with its initializer data. | 28 * Fill in that memory with its initializer data. |
| 37 */ | 29 */ |
| 38 void *tdb = __nacl_tls_initialize_memory(combined_area, tdb_size); | 30 void *tdb = __nacl_tls_initialize_memory(combined_area, tdb_size); |
| 39 | 31 |
| 40 /* | 32 /* |
| 41 * Set %gs, r9, or equivalent platform-specific mechanism. Requires | 33 * Set %gs, r9, or equivalent platform-specific mechanism. Requires |
| 42 * a syscall since certain bitfields of these registers are trusted. | 34 * a syscall since certain bitfields of these registers are trusted. |
| 43 */ | 35 */ |
| 44 nacl_tls_init(tdb); | 36 nacl_tls_init(tdb); |
| 45 | 37 |
| 46 /* | 38 /* |
| 47 * Initialize newlib's thread-specific pointer. | 39 * Initialize newlib's thread-specific pointer. |
| 48 */ | 40 */ |
| 49 __newlib_thread_init(); | 41 __newlib_thread_init(); |
| 50 | 42 |
| 51 return 0; | 43 return 0; |
| 52 } | 44 } |
| OLD | NEW |