vms-gcc_shell_handler.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* Static condition handler for Alpha/VMS.
  2. Copyright (C) 2005-2022 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 3, or (at your
  7. option) any later version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  11. License for more details.
  12. Under Section 7 of GPL version 3, you are granted additional
  13. permissions described in the GCC Runtime Library Exception, version
  14. 3.1, as published by the Free Software Foundation.
  15. You should have received a copy of the GNU General Public License and
  16. a copy of the GCC Runtime Library Exception along with this program;
  17. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  18. <http://www.gnu.org/licenses/>. */
  19. /* This file implements __gcc_shell_handler, the static VMS condition handler
  20. used as the indirection wrapper around user level handlers installed with
  21. establish_vms_condition_handler GCC builtin.
  22. [ABI] in comments refers to the "HP OpenVMS calling standard" document
  23. dated January 2005. */
  24. #include <vms/chfdef.h>
  25. #include <vms/pdscdef.h>
  26. #include <vms/ssdef.h>
  27. typedef void * ADDR;
  28. typedef unsigned long long REG;
  29. #define REG_AT(addr) (*(REG *)(addr))
  30. /* Compute pointer to procedure descriptor (Procedure Value) from Frame
  31. Pointer FP, according to the rules in [ABI-3.5.1 Current Procedure]. */
  32. #define PV_FOR(FP) \
  33. (((FP) != 0) \
  34. ? (((REG_AT (FP) & 0x7) == 0) ? *(PDSCDEF **)(FP) : (PDSCDEF *)(FP)) : 0)
  35. long
  36. __gcc_shell_handler (struct chf$signal_array *sig_arr,
  37. struct chf$mech_array *mech_arr);
  38. /* Helper for __gcc_shell_handler. Fetch the pointer to procedure currently
  39. registered as the VMS condition handler for the live function with a frame
  40. pointer FP. */
  41. static ADDR
  42. get_dyn_handler_pointer (REG fp)
  43. {
  44. /* From the frame pointer we find the procedure descriptor, and fetch
  45. the handler_data field from there. This field contains the offset
  46. from FP at which the address of the currently installed handler is
  47. to be found. */
  48. PDSCDEF * pd = PV_FOR (fp);
  49. /* Procedure descriptor pointer for the live subprogram with FP as the frame
  50. pointer, and to which _gcc_shell_handler is attached as a condition
  51. handler. */
  52. REG handler_slot_offset;
  53. /* Offset from FP at which the address of the currently established real
  54. condition handler is to be found. This offset is available from the
  55. handler_data field of the procedure descriptor. */
  56. REG handler_data_offset;
  57. /* The handler_data field position in the procedure descriptor, which
  58. depends on the kind of procedure at hand. */
  59. switch (pd->pdsc$w_flags & 0xf)
  60. {
  61. case PDSC$K_KIND_FP_STACK: /* [3.4.2 PD for stack frame procedures] */
  62. handler_data_offset = 40;
  63. break;
  64. case PDSC$K_KIND_FP_REGISTER: /* [3.4.5 PD for reg frame procedures] */
  65. handler_data_offset = 32;
  66. break;
  67. default:
  68. handler_data_offset = 0;
  69. break;
  70. }
  71. /* If we couldn't determine the handler_data field position, give up. */
  72. if (handler_data_offset == 0)
  73. return 0;
  74. /* Otherwise, fetch the fp offset at which the real handler address is to be
  75. found, then fetch and return the latter in turn. */
  76. handler_slot_offset = REG_AT ((REG)pd + handler_data_offset);
  77. return (ADDR) REG_AT (fp + handler_slot_offset);
  78. }
  79. /* The static VMS condition handler for GCC code. Fetch the address of the
  80. currently established condition handler, then resignal if there is none or
  81. call the handler with the VMS condition arguments. */
  82. long
  83. __gcc_shell_handler (struct chf$signal_array *sig_arr,
  84. struct chf$mech_array *mech_arr)
  85. {
  86. long ret;
  87. long (*user_handler) (struct chf$signal_array *, struct chf$mech_array *);
  88. user_handler = get_dyn_handler_pointer (mech_arr->chf$q_mch_frame);
  89. if (!user_handler)
  90. ret = SS$_RESIGNAL;
  91. else
  92. ret = user_handler (sig_arr, mech_arr);
  93. return ret;
  94. }