2
0

async_posix.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. /* This must be the first #include file */
  10. #include "../async_locl.h"
  11. #ifdef ASYNC_POSIX
  12. # include <stddef.h>
  13. # include <unistd.h>
  14. #define STACKSIZE 32768
  15. int ASYNC_is_capable(void)
  16. {
  17. ucontext_t ctx;
  18. /*
  19. * Some platforms provide getcontext() but it does not work (notably
  20. * MacOSX PPC64). Check for a working getcontext();
  21. */
  22. return getcontext(&ctx) == 0;
  23. }
  24. void async_local_cleanup(void)
  25. {
  26. }
  27. int async_fibre_makecontext(async_fibre *fibre)
  28. {
  29. fibre->env_init = 0;
  30. if (getcontext(&fibre->fibre) == 0) {
  31. fibre->fibre.uc_stack.ss_sp = OPENSSL_malloc(STACKSIZE);
  32. if (fibre->fibre.uc_stack.ss_sp != NULL) {
  33. fibre->fibre.uc_stack.ss_size = STACKSIZE;
  34. fibre->fibre.uc_link = NULL;
  35. makecontext(&fibre->fibre, async_start_func, 0);
  36. return 1;
  37. }
  38. } else {
  39. fibre->fibre.uc_stack.ss_sp = NULL;
  40. }
  41. return 0;
  42. }
  43. void async_fibre_free(async_fibre *fibre)
  44. {
  45. OPENSSL_free(fibre->fibre.uc_stack.ss_sp);
  46. fibre->fibre.uc_stack.ss_sp = NULL;
  47. }
  48. #endif