9ae234012de6e765554100d33817cfdacfaa1e99
[platform/framework/web/crosswalk.git] / src / native_client / src / untrusted / nacl / nacl_read_tp.c
1 /*
2  * Copyright (c) 2012 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/untrusted/nacl/nacl_irt.h"
8 #include "native_client/src/untrusted/nacl/nacl_thread.h"
9 #include "native_client/src/untrusted/nacl/tls.h"
10
11 /*
12  * The compiler generates calls to __nacl_read_tp() for TLS accesses.
13  * This is primarily used for x86-64.  See src/untrusted/nacl/tls.h.
14  *
15  * __nacl_read_tp() is also used on x86-32 when compiling with
16  * "-mtls-use-call".  This is for when TLS accesses need to be
17  * virtualised -- specifically, for object files that might get linked
18  * into the integrated runtime (IRT) library.
19  *
20  * NOTE: In the glibc build, this is defined in ld.so rather than here.
21  */
22 void *__nacl_read_tp(void) {
23 #if defined(__i386__)
24   /*
25    * Calling nacl_tls_get() works on x86-32, but reading %gs:0 is a
26    * lot faster.
27    */
28   void *result;
29   __asm__("mov %%gs:0, %0" : "=r"(result));
30   return result;
31 #else
32   return nacl_tls_get();
33 #endif
34 }