port.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Wine portability routines
  3. *
  4. * Copyright 2000 Alexandre Julliard
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  19. */
  20. #include "config.h"
  21. #include "wine/port.h"
  22. #include "wine/asm.h"
  23. #ifdef __ASM_OBSOLETE
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include <sys/types.h>
  27. #include <stdarg.h>
  28. #include <windef.h>
  29. /* no longer used, for backwards compatibility only */
  30. struct wine_pthread_functions;
  31. static void *pthread_functions[8];
  32. /***********************************************************************
  33. * wine_pthread_get_functions
  34. */
  35. void wine_pthread_get_functions_obsolete( struct wine_pthread_functions *functions, size_t size )
  36. {
  37. memcpy( functions, &pthread_functions, min( size, sizeof(pthread_functions) ));
  38. }
  39. /***********************************************************************
  40. * wine_pthread_set_functions
  41. */
  42. void wine_pthread_set_functions_obsolete( const struct wine_pthread_functions *functions, size_t size )
  43. {
  44. memcpy( &pthread_functions, functions, min( size, sizeof(pthread_functions) ));
  45. }
  46. /***********************************************************************
  47. * wine_call_on_stack
  48. *
  49. * Switch to the specified stack to call the function and return.
  50. */
  51. extern int wine_call_on_stack_obsolete( int (*func)(void *), void *arg, void *stack );
  52. #if defined(__i386__) && defined(__GNUC__)
  53. __ASM_GLOBAL_FUNC( wine_call_on_stack_obsolete,
  54. "pushl %ebp\n\t"
  55. __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
  56. __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
  57. "pushl %esi\n\t"
  58. __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
  59. __ASM_CFI(".cfi_rel_offset %esi,0\n\t")
  60. "movl %esp,%esi\n\t"
  61. __ASM_CFI(".cfi_def_cfa_register %esi\n\t")
  62. "movl 12(%esp),%ecx\n\t" /* func */
  63. "movl 16(%esp),%edx\n\t" /* arg */
  64. "movl 20(%esp),%eax\n\t" /* stack */
  65. "andl $~15,%eax\n\t"
  66. "subl $12,%eax\n\t"
  67. "movl %eax,%esp\n\t"
  68. "pushl %edx\n\t"
  69. "xorl %ebp,%ebp\n\t"
  70. "call *%ecx\n\t"
  71. "movl %esi,%esp\n\t"
  72. "popl %esi\n\t"
  73. __ASM_CFI(".cfi_adjust_cfa_offset -4\n\t")
  74. __ASM_CFI(".cfi_same_value %esi\n\t")
  75. "popl %ebp\n\t"
  76. __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
  77. __ASM_CFI(".cfi_same_value %ebp\n\t")
  78. "ret" )
  79. #elif defined(__x86_64__) && defined(__GNUC__)
  80. __ASM_GLOBAL_FUNC( wine_call_on_stack_obsolete,
  81. "pushq %rbp\n\t"
  82. __ASM_CFI(".cfi_adjust_cfa_offset 8\n\t")
  83. __ASM_CFI(".cfi_rel_offset %rbp,0\n\t")
  84. "movq %rsp,%rbp\n\t"
  85. __ASM_CFI(".cfi_def_cfa_register %rbp\n\t")
  86. "movq %rdi,%rax\n\t" /* func */
  87. "movq %rsi,%rdi\n\t" /* arg */
  88. "andq $~15,%rdx\n\t" /* stack */
  89. "movq %rdx,%rsp\n\t"
  90. "callq *%rax\n\t" /* call func */
  91. "movq %rbp,%rsp\n\t"
  92. __ASM_CFI(".cfi_def_cfa_register %rsp\n\t")
  93. "popq %rbp\n\t"
  94. __ASM_CFI(".cfi_adjust_cfa_offset -8\n\t")
  95. __ASM_CFI(".cfi_same_value %rbp\n\t")
  96. "ret")
  97. #endif
  98. /***********************************************************************
  99. * wine_switch_to_stack
  100. *
  101. * Switch to the specified stack and call the function.
  102. */
  103. void DECLSPEC_NORETURN wine_switch_to_stack_obsolete( void (*func)(void *), void *arg, void *stack )
  104. {
  105. wine_call_on_stack_obsolete( (int (*)(void *))func, arg, stack );
  106. abort();
  107. }
  108. __ASM_OBSOLETE(wine_pthread_get_functions);
  109. __ASM_OBSOLETE(wine_pthread_set_functions);
  110. __ASM_OBSOLETE(wine_call_on_stack);
  111. __ASM_OBSOLETE(wine_switch_to_stack);
  112. #endif /* __ASM_OBSOLETE */