1 {{+bindTo:partials.standard_nacl_article}}
3 <section id=
"pnacl-c-c-language-support">
4 <h1 id=
"pnacl-c-c-language-support">PNaCl C/C++ Language Support
</h1>
5 <div class=
"contents local" id=
"contents" style=
"display: none">
7 <li><p class=
"first"><a class=
"reference internal" href=
"#source-language-support" id=
"id3">Source language support
</a></p>
9 <li><a class=
"reference internal" href=
"#versions" id=
"id4">Versions
</a></li>
10 <li><a class=
"reference internal" href=
"#preprocessor-definitions" id=
"id5">Preprocessor definitions
</a></li>
13 <li><p class=
"first"><a class=
"reference internal" href=
"#memory-model-and-atomics" id=
"id6">Memory Model and Atomics
</a></p>
14 <ul class=
"small-gap">
15 <li><a class=
"reference internal" href=
"#memory-model-for-concurrent-operations" id=
"id7">Memory Model for Concurrent Operations
</a></li>
16 <li><a class=
"reference internal" href=
"#atomic-memory-ordering-constraints" id=
"id8">Atomic Memory Ordering Constraints
</a></li>
17 <li><a class=
"reference internal" href=
"#volatile-memory-accesses" id=
"id9">Volatile Memory Accesses
</a></li>
20 <li><a class=
"reference internal" href=
"#threading" id=
"id10">Threading
</a></li>
21 <li><a class=
"reference internal" href=
"#setjmp-and-longjmp" id=
"id11"><code>setjmp
</code> and
<code>longjmp
</code></a></li>
22 <li><a class=
"reference internal" href=
"#c-exception-handling" id=
"id12">C++ Exception Handling
</a></li>
23 <li><a class=
"reference internal" href=
"#inline-assembly" id=
"id13">Inline Assembly
</a></li>
24 <li><p class=
"first"><a class=
"reference internal" href=
"#portable-simd-vectors" id=
"id14">Portable SIMD Vectors
</a></p>
25 <ul class=
"small-gap">
26 <li><a class=
"reference internal" href=
"#hand-coding-vector-extensions" id=
"id15">Hand-Coding Vector Extensions
</a></li>
27 <li><a class=
"reference internal" href=
"#auto-vectorization" id=
"id16">Auto-Vectorization
</a></li>
30 <li><a class=
"reference internal" href=
"#undefined-behavior" id=
"id17">Undefined Behavior
</a></li>
31 <li><a class=
"reference internal" href=
"#floating-point" id=
"id18">Floating-Point
</a></li>
32 <li><a class=
"reference internal" href=
"#computed-goto" id=
"id19">Computed
<code>goto
</code></a></li>
33 <li><p class=
"first"><a class=
"reference internal" href=
"#future-directions" id=
"id20">Future Directions
</a></p>
34 <ul class=
"small-gap">
35 <li><a class=
"reference internal" href=
"#inter-process-communication" id=
"id21">Inter-Process Communication
</a></li>
36 <li><a class=
"reference internal" href=
"#posix-style-signal-handling" id=
"id22">POSIX-style Signal Handling
</a></li>
41 </div><section id=
"source-language-support">
42 <h2 id=
"source-language-support">Source language support
</h2>
43 <p>The currently supported languages are C and C++. The PNaCl toolchain is
44 based on recent Clang, which fully supports C++
11 and most of C11. A
45 detailed status of the language support is available
<a class=
"reference external" href=
"http://clang.llvm.org/cxx_status.html">here
</a>.
</p>
46 <p>For information on using languages other than C/C++, see the
<a class=
"reference internal" href=
"/native-client/faq.html#other-languages"><em>FAQ
47 section on other languages
</em></a>.
</p>
48 <p>As for the standard libraries, the PNaCl toolchain is currently based on
49 <code>libc++
</code>, and the
<code>newlib
</code> standard C library.
<code>libstdc++
</code> is also
50 supported but its use is discouraged; see
<a class=
"reference internal" href=
"/native-client/devguide/devcycle/building.html#building-cpp-libraries"><em>C++ standard libraries
</em></a>
52 <section id=
"versions">
53 <h3 id=
"versions">Versions
</h3>
54 <p>Version information can be obtained:
</p>
55 <ul class=
"small-gap">
56 <li>Clang/LLVM: run
<code>pnacl-clang -v
</code>.
</li>
57 <li><code>newlib
</code>: use the
<code>_NEWLIB_VERSION
</code> macro.
</li>
58 <li><code>libc++
</code>: use the
<code>_LIBCPP_VERSION
</code> macro.
</li>
59 <li><code>libstdc++
</code>: use the
<code>_GLIBCXX_VERSION
</code> macro.
</li>
61 </section><section id=
"preprocessor-definitions">
62 <h3 id=
"preprocessor-definitions">Preprocessor definitions
</h3>
63 <p>When compiling C/C++ code, the PNaCl toolchain defines the
<code>__pnacl__
</code>
64 macro. In addition,
<code>__native_client__
</code> is defined for compatibility
65 with other NaCl toolchains.
</p>
66 </section></section><section id=
"memory-model-and-atomics">
67 <span id=
"id1"></span><h2 id=
"memory-model-and-atomics"><span id=
"id1"></span>Memory Model and Atomics
</h2>
68 <section id=
"memory-model-for-concurrent-operations">
69 <h3 id=
"memory-model-for-concurrent-operations">Memory Model for Concurrent Operations
</h3>
70 <p>The memory model offered by PNaCl relies on the same coding guidelines
71 as the C11/C++
11 one: concurrent accesses must always occur through
72 atomic primitives (offered by
<a class=
"reference external" href=
"PNaClLangRef.html#atomicintrinsics">atomic intrinsics
</a>), and these accesses must always
73 occur with the same size for the same memory location. Visibility of
74 stores is provided on a happens-before basis that relates memory
75 locations to each other as the C11/C++
11 standards do.
</p>
76 <p>Non-atomic memory accesses may be reordered, separated, elided or fused
77 according to C and C++
’s memory model before the pexe is created as well
78 as after its creation. Accessing atomic memory location through
79 non-atomic primitives is
<a class=
"reference internal" href=
"/native-client/reference/pnacl-undefined-behavior.html#undefined-behavior"><em>Undefined Behavior
</em></a>.
</p>
80 <p>As in C11/C++
11 some atomic accesses may be implemented with locks on
81 certain platforms. The
<code>ATOMIC_*_LOCK_FREE
</code> macros will always be
82 <code>1</code>, signifying that all types are sometimes lock-free. The
83 <code>is_lock_free
</code> methods and
<code>atomic_is_lock_free
</code> will return the
84 current platform
’s implementation at translation time. These macros,
85 methods and functions are in the C11 header
<code><stdatomic.h
></code> and the
86 C++
11 header
<code><atomic
></code>.
</p>
87 <p>The PNaCl toolchain supports concurrent memory accesses through legacy
88 GCC-style
<code>__sync_*
</code> builtins, as well as through C11/C++
11 atomic
89 primitives and the underlying
<a class=
"reference external" href=
"http://gcc.gnu.org/wiki/Atomic/GCCMM">GCCMM
</a> <code>__atomic_*
</code>
90 primitives.
<code>volatile
</code> memory accesses can also be used, though these
91 are discouraged. See
<a class=
"reference internal" href=
"#volatile-memory-accesses">Volatile Memory Accesses
</a>.
</p>
92 <p>PNaCl supports concurrency and parallelism with some restrictions:
</p>
93 <ul class=
"small-gap">
94 <li>Threading is explicitly supported and has no restrictions over what
95 prevalent implementations offer. See
<a class=
"reference internal" href=
"#threading">Threading
</a>.
</li>
96 <li><code>volatile
</code> and atomic operations are address-free (operations on the
97 same memory location via two different addresses work atomically), as
98 intended by the C11/C++
11 standards. This is critical in supporting
99 synchronous
“external modifications
” such as mapping underlying memory
100 at multiple locations.
</li>
101 <li>Inter-process communication through shared memory is currently not
102 supported. See
<a class=
"reference internal" href=
"#future-directions">Future Directions
</a>.
</li>
103 <li>Signal handling isn
’t supported, PNaCl therefore promotes all
104 primitives to cross-thread (instead of single-thread). This may change
105 at a later date. Note that using atomic operations which aren
’t
106 lock-free may lead to deadlocks when handling asynchronous
107 signals. See
<a class=
"reference internal" href=
"#future-directions">Future Directions
</a>.
</li>
108 <li>Direct interaction with device memory isn
’t supported, and there is no
109 intent to support it. The embedding sandbox
’s runtime can offer APIs
110 to indirectly access devices.
</li>
112 <p>Setting up the above mechanisms requires assistance from the embedding
113 sandbox
’s runtime (e.g. NaCl
’s Pepper APIs), but using them once setup
114 can be done through regular C/C++ code.
</p>
115 </section><section id=
"atomic-memory-ordering-constraints">
116 <h3 id=
"atomic-memory-ordering-constraints">Atomic Memory Ordering Constraints
</h3>
117 <p>Atomics follow the same ordering constraints as in regular C11/C++
11,
118 but all accesses are promoted to sequential consistency (the strongest
119 memory ordering) at pexe creation time. We plan to support more of the
120 C11/C++
11 memory orderings in the future.
</p>
121 <p>Some additional restrictions, following the C11/C++
11 standards:
</p>
122 <ul class=
"small-gap">
123 <li>Atomic accesses must at least be naturally aligned.
</li>
124 <li>Some accesses may not actually be atomic on certain platforms,
125 requiring an implementation that uses global locks.
</li>
126 <li>An atomic memory location must always be accessed with atomic
127 primitives, and these primitives must always be of the same bit size
128 for that location.
</li>
129 <li>Not all memory orderings are valid for all atomic operations.
</li>
131 </section><section id=
"volatile-memory-accesses">
132 <h3 id=
"volatile-memory-accesses">Volatile Memory Accesses
</h3>
133 <p>The C11/C++
11 standards mandate that
<code>volatile
</code> accesses execute in
134 program order (but are not fences, so other memory operations can
135 reorder around them), are not necessarily atomic, and can’t be
136 elided. They can be separated into smaller width accesses.
</p>
137 <p>Before any optimizations occur, the PNaCl toolchain transforms
138 <code>volatile
</code> loads and stores into sequentially consistent
<code>volatile
</code>
139 atomic loads and stores, and applies regular compiler optimizations
140 along the above guidelines. This orders
<code>volatiles
</code> according to the
141 atomic rules, and means that fences (including
<code>__sync_synchronize
</code>)
142 act in a better-defined manner. Regular memory accesses still do not
143 have ordering guarantees with
<code>volatile
</code> and atomic accesses, though
144 the internal representation of
<code>__sync_synchronize
</code> attempts to
145 prevent reordering of memory accesses to objects which may escape.
</p>
146 <p>Relaxed ordering could be used instead, but for the first release it is
147 more conservative to apply sequential consistency. Future releases may
148 change what happens at compile-time, but already-released pexes will
149 continue using sequential consistency.
</p>
150 <p>The PNaCl toolchain also requires that
<code>volatile
</code> accesses be at least
151 naturally aligned, and tries to guarantee this alignment.
</p>
152 <p>The above guarantees ease the support of legacy (i.e. non-C11/C++
11)
153 code, and combined with builtin fences these programs can do meaningful
154 cross-thread communication without changing code. They also better
155 reflect the original code
’s intent and guarantee better portability.
</p>
156 </section></section><section id=
"threading">
157 <span id=
"language-support-threading"></span><h2 id=
"threading"><span id=
"language-support-threading"></span>Threading
</h2>
158 <p>Threading is explicitly supported through C11/C++
11’s threading
159 libraries as well as POSIX threads.
</p>
160 <p>Communication between threads should use atomic primitives as described
161 in
<a class=
"reference internal" href=
"#id1">Memory Model and Atomics
</a>.
</p>
162 </section><section id=
"setjmp-and-longjmp">
163 <h2 id=
"setjmp-and-longjmp"><code>setjmp
</code> and
<code>longjmp
</code></h2>
164 <p>PNaCl and NaCl support
<code>setjmp
</code> and
<code>longjmp
</code> without any
165 restrictions beyond C
’s.
</p>
166 </section><section id=
"c-exception-handling">
167 <h2 id=
"c-exception-handling">C++ Exception Handling
</h2>
168 <p>PNaCl currently supports C++ exception handling through
<code>setjmp()
</code> and
169 <code>longjmp()
</code>, which can be enabled with the
<code>--pnacl-exceptions=sjlj
</code>
170 linker flag. Exceptions are disabled by default so that faster and
171 smaller code is generated, and
<code>throw
</code> statements are replaced with
172 calls to
<code>abort()
</code>. The usual
<code>-fno-exceptions
</code> flag is also
173 supported. PNaCl will support full zero-cost exception handling in the
175 <p>NaCl supports full zero-cost C++ exception handling.
</p>
176 </section><section id=
"inline-assembly">
177 <h2 id=
"inline-assembly">Inline Assembly
</h2>
178 <p>Inline assembly isn
’t supported by PNaCl because it isn
’t portable. The
179 one current exception is the common compiler barrier idiom
180 <code>asm(
"":::
"memory
")
</code>, which gets transformed to a sequentially
181 consistent memory barrier (equivalent to
<code>__sync_synchronize()
</code>). In
182 PNaCl this barrier is only guaranteed to order
<code>volatile
</code> and atomic
183 memory accesses, though in practice the implementation attempts to also
184 prevent reordering of memory accesses to objects which may escape.
</p>
185 <p>PNaCl supports
<a class=
"reference internal" href=
"#portable-simd-vectors"><em>Portable SIMD Vectors
</em></a>,
186 which are traditionally expressed through target-specific intrinsics or
188 <p>NaCl supports a fairly wide subset of inline assembly through GCC
’s
189 inline assembly syntax, with the restriction that the sandboxing model
190 for the target architecture has to be respected.
</p>
191 </section><section id=
"portable-simd-vectors">
192 <span id=
"id2"></span><h2 id=
"portable-simd-vectors"><span id=
"id2"></span>Portable SIMD Vectors
</h2>
193 <p>SIMD vectors aren
’t part of the C/C++ standards and are traditionally
194 very hardware-specific. Portable Native Client offers a portable version
195 of SIMD vector datatypes and operations which map well to modern
196 architectures and offer performance which matches or approaches
197 hardware-specific uses.
</p>
198 <p>SIMD vector support was added to Portable Native Client for version
37
199 of Chrome and more features, including performance enhancements, are
200 expected to be added in subsequent releases.
</p>
201 <section id=
"hand-coding-vector-extensions">
202 <h3 id=
"hand-coding-vector-extensions">Hand-Coding Vector Extensions
</h3>
203 <p>The initial vector support in Portable Native Client adds
<a class=
"reference external" href=
"http://clang.llvm.org/docs/LanguageExtensions.html#vectors-and-extended-vectors">LLVM vectors
</a>
204 and
<a class=
"reference external" href=
"http://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html">GCC vectors
</a> since these
205 are well supported by different hardware platforms and don
’t require any
206 new compiler intrinsics.
</p>
207 <p>Vector types can be used through the
<code>vector_size
</code> attribute:
</p>
208 <pre class=
"prettyprint">
209 #define VECTOR_BYTES
16
210 typedef int v4s __attribute__((vector_size(VECTOR_BYTES)));
214 c = a + b; /* c = {
6,
8,
10,
12} */
215 d = b
>> a; /* d = {
2,
1,
0,
0} */
217 <p>Vector comparisons are represented as a bitmask as wide as the compared
218 elements of all
<code>0</code> or all
<code>1</code>:
</p>
219 <pre class=
"prettyprint">
220 typedef int v4s __attribute__((vector_size(
16)));
222 v4s limit = {
32,
64,
128,
256};
223 v4s mask = in
> limit;
224 v4s ret = in
& mask;
228 <p>Vector datatypes are currently expected to be
128-bit wide with one of
229 the following element types:
</p>
230 <table border=
"1" class=
"docutils">
233 <thead valign=
"bottom">
234 <tr class=
"row-odd"><th class=
"head">Type
</th>
235 <th class=
"head">Num Elements
</th>
236 <th class=
"head">Vector Bit Width
</th>
240 <tr class=
"row-even"><td><code>uint8_t
</code></td>
244 <tr class=
"row-odd"><td><code>int8_t
</code></td>
248 <tr class=
"row-even"><td><code>uint16_t
</code></td>
252 <tr class=
"row-odd"><td><code>int16_t
</code></td>
256 <tr class=
"row-even"><td><code>uint32_t
</code></td>
260 <tr class=
"row-odd"><td><code>int32_t
</code></td>
264 <tr class=
"row-even"><td><code>float
</code></td>
270 <p>64-bit integers and double-precision floating point will be supported in
271 a future release, as will
256-bit and
512-bit vectors.
</p>
272 <p>The following operators are supported on vectors:
</p>
273 <table border=
"1" class=
"docutils">
277 <tr class=
"row-odd"><td>unary
<code>+
</code>,
<code>-
</code></td>
279 <tr class=
"row-even"><td><code>++
</code>,
<code>--
</code></td>
281 <tr class=
"row-odd"><td><code>+
</code>,
<code>-
</code>,
<code>*
</code>,
<code>/
</code>,
<code>%
</code></td>
283 <tr class=
"row-even"><td><code>&</code>,
<code>|
</code>,
<code>^
</code>,
<code>~
</code></td>
285 <tr class=
"row-odd"><td><code>>></code>,
<code><<</code></td>
287 <tr class=
"row-even"><td><code>!
</code>,
<code>&&</code>,
<code>||
</code></td>
289 <tr class=
"row-odd"><td><code>==
</code>,
<code>!=
</code>,
<code>></code>,
<code><</code>,
<code>>=
</code>,
<code><=
</code></td>
291 <tr class=
"row-even"><td><code>=
</code></td>
295 <p>C-style casts can be used to convert one vector type to another without
296 modifying the underlying bits.
<code>__builtin_convertvector
</code> can be used
297 to convert from one type to another provided both types have the same
298 number of elements, truncating when converting from floating-point to
300 <pre class=
"prettyprint">
301 typedef unsigned v4u __attribute__((vector_size(
16)));
302 typedef float v4f __attribute__((vector_size(
16)));
303 v4u a = {
0x3f19999a,
0x40000000,
0x40490fdb,
0x66ff0c30};
304 v4f b = (v4f) a; /* b = {
0.6,
2,
3.14159,
6.02214e+23} */
305 v4u c = __builtin_convertvector(b, v4u); /* c = {
0,
2,
3,
0} */
307 <p>It is also possible to use array-style indexing into vectors to extract
308 individual elements using
<code>[]
</code>.
</p>
309 <pre class=
"prettyprint">
310 typedef unsigned v4u __attribute__((vector_size(
16)));
311 template
<typename T
>
312 void print(const T v) {
313 for (size_t i =
0; i != sizeof(v) / sizeof(v[
0]); ++i)
314 std::cout
<< v[i]
<< ' ';
315 std::cout
<< std::endl;
318 <p>Vector shuffles (often called permutation or swizzle) operations are
319 supported through
<code>__builtin_shufflevector
</code>. The builtin has two
320 vector arguments of the same element type, followed by a list of
321 constant integers that specify the element indices of the first two
322 vectors that should be extracted and returned in a new vector. These
323 element indices are numbered sequentially starting with the first
324 vector, continuing into the second vector. Thus, if
<code>vec1
</code> is a
325 4-element vector, index
<code>5</code> would refer to the second element of
326 <code>vec2
</code>. An index of
<code>-
1</code> can be used to indicate that the
327 corresponding element in the returned vector is a don’t care and can be
328 optimized by the backend.
</p>
329 <p>The result of
<code>__builtin_shufflevector
</code> is a vector with the same
330 element type as
<code>vec1
</code> /
<code>vec2
</code> but that has an element count equal
331 to the number of indices specified.
</p>
332 <pre class=
"prettyprint">
333 // identity operation - return
4-element vector v1.
334 __builtin_shufflevector(v1, v1,
0,
1,
2,
3)
336 //
"Splat
" element
0 of v1 into a
4-element result.
337 __builtin_shufflevector(v1, v1,
0,
0,
0,
0)
339 // Reverse
4-element vector v1.
340 __builtin_shufflevector(v1, v1,
3,
2,
1,
0)
342 // Concatenate every other element of
4-element vectors v1 and v2.
343 __builtin_shufflevector(v1, v2,
0,
2,
4,
6)
345 // Concatenate every other element of
8-element vectors v1 and v2.
346 __builtin_shufflevector(v1, v2,
0,
2,
4,
6,
8,
10,
12,
14)
348 // Shuffle v1 with some elements being undefined
349 __builtin_shufflevector(v1, v1,
3, -
1,
1, -
1)
351 <p>One common use of
<code>__builtin_shufflevector
</code> is to perform
352 vector-scalar operations:
</p>
353 <pre class=
"prettyprint">
354 typedef int v4s __attribute__((vector_size(
16)));
355 v4s shift_right_by(v4s shift_me, int shift_amount) {
356 v4s tmp = {shift_amount};
357 return shift_me
>> __builtin_shuffle_vector(tmp, tmp,
0,
0,
0,
0);
360 </section><section id=
"auto-vectorization">
361 <h3 id=
"auto-vectorization">Auto-Vectorization
</h3>
362 <p>Auto-vectorization is currently not enabled for Portable Native Client,
363 but will be in a future release.
</p>
364 </section></section><section id=
"undefined-behavior">
365 <h2 id=
"undefined-behavior">Undefined Behavior
</h2>
366 <p>The C and C++ languages expose some undefined behavior which is
367 discussed in
<a class=
"reference internal" href=
"/native-client/reference/pnacl-undefined-behavior.html#undefined-behavior"><em>PNaCl Undefined Behavior
</em></a>.
</p>
368 </section><section id=
"floating-point">
369 <h2 id=
"floating-point">Floating-Point
</h2>
370 <p>PNaCl exposes
32-bit and
64-bit floating point operations which are
371 mostly IEEE-
754 compliant. There are a few caveats:
</p>
372 <ul class=
"small-gap">
373 <li>Some
<a class=
"reference internal" href=
"/native-client/reference/pnacl-undefined-behavior.html#undefined-behavior-fp"><em>floating-point behavior is currently left as undefined
</em></a>.
</li>
374 <li>The default rounding mode is round-to-nearest and other rounding modes
375 are currently not usable, which isn
’t IEEE-
754 compliant. PNaCl could
376 support switching modes (the
4 modes exposed by C99
<code>FLT_ROUNDS
</code>
378 <li>Signaling
<code>NaN
</code> never fault.
</li>
379 <li><p class=
"first">Fast-math optimizations are currently supported before
<em>pexe
</em> creation
380 time. A
<em>pexe
</em> loses all fast-math information when it is
381 created. Fast-math translation could be enabled at a later date,
382 potentially at a perf-function granularity. This wouldn
’t affect
383 already-existing
<em>pexe
</em>; it would be an opt-in feature.
</p>
384 <ul class=
"small-gap">
385 <li>Fused-multiply-add have higher precision and often execute faster;
386 PNaCl currently disallows them in the
<em>pexe
</em> because they aren
’t
387 supported on all platforms and can
’t realistically be
388 emulated. PNaCl could (but currently doesn
’t) only generate them in
389 the backend if fast-math were specified and the hardware supports
391 <li>Transcendentals aren
’t exposed by PNaCl
’s ABI; they are part of the
392 math library that is included in the
<em>pexe
</em>. PNaCl could, but
393 currently doesn
’t, use hardware support if fast-math were provided
394 in the
<em>pexe
</em>.
</li>
398 </section><section id=
"computed-goto">
399 <h2 id=
"computed-goto">Computed
<code>goto
</code></h2>
400 <p>PNaCl supports computed
<code>goto
</code>, a non-standard GCC extension to C used
401 by some interpreters, by lowering them to
<code>switch
</code> statements. The
402 resulting use of
<code>switch
</code> might not be as fast as the original
403 indirect branches. If you are compiling a program that has a
404 compile-time option for using computed
<code>goto
</code>, it
’s possible that the
405 program will run faster with the option turned off (e.g., if the program
406 does extra work to take advantage of computed
<code>goto
</code>).
</p>
407 <p>NaCl supports computed
<code>goto
</code> without any transformation.
</p>
408 </section><section id=
"future-directions">
409 <h2 id=
"future-directions">Future Directions
</h2>
410 <section id=
"inter-process-communication">
411 <h3 id=
"inter-process-communication">Inter-Process Communication
</h3>
412 <p>Inter-process communication through shared memory is currently not
413 supported by PNaCl/NaCl. When implemented, it may be limited to
414 operations which are lock-free on the current platform (
<code>is_lock_free
</code>
415 methods). It will rely on the address-free properly discussed in
<a class=
"reference internal" href=
"#memory-model-for-concurrent-operations">Memory
416 Model for Concurrent Operations
</a>.
</p>
417 </section><section id=
"posix-style-signal-handling">
418 <h3 id=
"posix-style-signal-handling">POSIX-style Signal Handling
</h3>
419 <p>POSIX-style signal handling really consists of two different features:
</p>
420 <ul class=
"small-gap">
421 <li><p class=
"first"><strong>Hardware exception handling
</strong> (synchronous signals): The ability
422 to catch hardware exceptions (such as memory access faults and
423 division by zero) using a signal handler.
</p>
424 <p>PNaCl currently doesn
’t support hardware exception handling.
</p>
425 <p>NaCl supports hardware exception handling via the
426 <code><nacl/nacl_exception.h
></code> interface.
</p>
428 <li><p class=
"first"><strong>Asynchronous interruption of threads
</strong> (asynchronous signals): The
429 ability to asynchronously interrupt the execution of a thread,
430 forcing the thread to run a signal handler.
</p>
431 <p>A similar feature is
<strong>thread suspension
</strong>: The ability to
432 asynchronously suspend and resume a thread and inspect or modify its
433 execution state (such as register state).
</p>
434 <p>Neither PNaCl nor NaCl currently support asynchronous interruption
435 or suspension of threads.
</p>
438 <p>If PNaCl were to support either of these, the interaction of
439 <code>volatile
</code> and atomics with same-thread signal handling would need
440 to be carefully detailed.
</p>
441 </section></section></section>
443 {{/partials.standard_nacl_article}}