Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: src/nonsfi/irt/irt_interfaces.c

Issue 1222753005: Non-SFI mode: Use clone() instead of pthread_create() (Closed) Base URL: https://chromium.googlesource.com/native_client/src/native_client.git@master
Patch Set: Addressed feedback Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/nonsfi/linux/linux_pthread_private.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The Native Client Authors. All rights reserved. 2 * Copyright (c) 2013 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 "native_client/src/nonsfi/irt/irt_interfaces.h" 7 #include "native_client/src/nonsfi/irt/irt_interfaces.h"
8 8
9 #include <assert.h> 9 #include <assert.h>
10 #include <errno.h> 10 #include <errno.h>
(...skipping 25 matching lines...) Expand all
36 #include "native_client/src/trusted/service_runtime/include/sys/unistd.h" 36 #include "native_client/src/trusted/service_runtime/include/sys/unistd.h"
37 #include "native_client/src/untrusted/irt/irt.h" 37 #include "native_client/src/untrusted/irt/irt.h"
38 #include "native_client/src/untrusted/irt/irt_dev.h" 38 #include "native_client/src/untrusted/irt/irt_dev.h"
39 #include "native_client/src/untrusted/irt/irt_interfaces.h" 39 #include "native_client/src/untrusted/irt/irt_interfaces.h"
40 #include "native_client/src/untrusted/nacl/nacl_random.h" 40 #include "native_client/src/untrusted/nacl/nacl_random.h"
41 41
42 #if defined(__native_client__) && defined(__arm__) 42 #if defined(__native_client__) && defined(__arm__)
43 #include "native_client/src/nonsfi/irt/irt_icache.h" 43 #include "native_client/src/nonsfi/irt/irt_icache.h"
44 #endif 44 #endif
45 45
46 #if defined(__native_client__)
47 # include "native_client/src/nonsfi/linux/linux_pthread_private.h"
48 #endif
49
46 /* 50 /*
47 * This is an implementation of NaCl's IRT interfaces that runs 51 * This is an implementation of NaCl's IRT interfaces that runs
48 * outside of the NaCl sandbox. 52 * outside of the NaCl sandbox.
49 * 53 *
50 * This allows PNaCl to be used as a portability layer without the 54 * This allows PNaCl to be used as a portability layer without the
51 * SFI-based sandboxing. PNaCl pexes can be translated to 55 * SFI-based sandboxing. PNaCl pexes can be translated to
52 * non-SFI-sandboxed native code and linked against this IRT 56 * non-SFI-sandboxed native code and linked against this IRT
53 * implementation. 57 * implementation.
54 */ 58 */
55 59
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 static void *start_thread(void *arg) { 351 static void *start_thread(void *arg) {
348 struct thread_args args = *(struct thread_args *) arg; 352 struct thread_args args = *(struct thread_args *) arg;
349 free(arg); 353 free(arg);
350 g_tls_value = args.thread_ptr; 354 g_tls_value = args.thread_ptr;
351 args.start_func(); 355 args.start_func();
352 abort(); 356 abort();
353 } 357 }
354 358
355 static int thread_create(void (*start_func)(void), void *stack, 359 static int thread_create(void (*start_func)(void), void *stack,
356 void *thread_ptr) { 360 void *thread_ptr) {
361 #if defined(__native_client__)
362 struct thread_args *args = malloc(sizeof(struct thread_args));
363 if (args == NULL) {
364 return ENOMEM;
365 }
366 args->start_func = start_func;
367 args->thread_ptr = thread_ptr;
368 /* In Linux, it is possible to use the provided stack directly. */
369 int error = nacl_user_thread_create(start_thread, stack, args);
370 if (error != 0)
371 free(args);
372 return error;
373 #else
357 /* 374 /*
358 * For now, we ignore the stack that user code provides and just use 375 * For now, we ignore the stack that user code provides and just use
359 * the stack that the host libpthread allocates. 376 * the stack that the host libpthread allocates.
360 */ 377 */
361 pthread_attr_t attr; 378 pthread_attr_t attr;
362 int error = pthread_attr_init(&attr); 379 int error = pthread_attr_init(&attr);
363 if (error != 0) 380 if (error != 0)
364 return error; 381 return error;
365 error = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); 382 error = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
366 if (error != 0) 383 if (error != 0)
367 return error; 384 return error;
368 struct thread_args *args = malloc(sizeof(struct thread_args)); 385 struct thread_args *args = malloc(sizeof(struct thread_args));
369 if (args == NULL) { 386 if (args == NULL) {
370 error = ENOMEM; 387 error = ENOMEM;
371 goto cleanup; 388 goto cleanup;
372 } 389 }
373 args->start_func = start_func; 390 args->start_func = start_func;
374 args->thread_ptr = thread_ptr; 391 args->thread_ptr = thread_ptr;
375 pthread_t tid; 392 pthread_t tid;
376 error = pthread_create(&tid, &attr, start_thread, args); 393 error = pthread_create(&tid, &attr, start_thread, args);
377 if (error != 0) 394 if (error != 0)
378 free(args); 395 free(args);
379 cleanup: 396 cleanup:
380 pthread_attr_destroy(&attr); 397 pthread_attr_destroy(&attr);
381 return error; 398 return error;
399 #endif
382 } 400 }
383 401
384 static void thread_exit(int32_t *stack_flag) { 402 static void thread_exit(int32_t *stack_flag) {
403 #if defined(__native_client__)
404 nacl_user_thread_exit(stack_flag);
405 #else
385 *stack_flag = 0; /* Indicate that the user code's stack can be freed. */ 406 *stack_flag = 0; /* Indicate that the user code's stack can be freed. */
386 pthread_exit(NULL); 407 pthread_exit(NULL);
408 #endif
387 } 409 }
388 410
389 static int thread_nice(const int nice) { 411 static int thread_nice(const int nice) {
390 return 0; 412 return 0;
391 } 413 }
392 414
393 /* 415 /*
394 * Mac OS X does not provide futexes or clock_gettime()/getres() natively. 416 * Mac OS X does not provide futexes or clock_gettime()/getres() natively.
395 * TODO(mseaborn): Make threads and clock_gettime() work on Mac OS X. 417 * TODO(mseaborn): Make threads and clock_gettime() work on Mac OS X.
396 */ 418 */
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 nacl_entry_func_t entry_func = 775 nacl_entry_func_t entry_func =
754 #if defined(__APPLE__) 776 #if defined(__APPLE__)
755 _start; 777 _start;
756 #else 778 #else
757 _user_start; 779 _user_start;
758 #endif 780 #endif
759 781
760 return nacl_irt_nonsfi_entry(argc, argv, environ, entry_func); 782 return nacl_irt_nonsfi_entry(argc, argv, environ, entry_func);
761 } 783 }
762 #endif 784 #endif
OLDNEW
« no previous file with comments | « no previous file | src/nonsfi/linux/linux_pthread_private.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698