vms_decc_init.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*
  2. * Written by sms and contributed to the OpenSSL project.
  3. */
  4. /* ====================================================================
  5. * Copyright (c) 2010 The OpenSSL Project. All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * 3. All advertising materials mentioning features or use of this
  20. * software must display the following acknowledgment:
  21. * "This product includes software developed by the OpenSSL Project
  22. * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
  23. *
  24. * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
  25. * endorse or promote products derived from this software without
  26. * prior written permission. For written permission, please contact
  27. * licensing@OpenSSL.org.
  28. *
  29. * 5. Products derived from this software may not be called "OpenSSL"
  30. * nor may "OpenSSL" appear in their names without prior written
  31. * permission of the OpenSSL Project.
  32. *
  33. * 6. Redistributions of any form whatsoever must retain the following
  34. * acknowledgment:
  35. * "This product includes software developed by the OpenSSL Project
  36. * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
  37. *
  38. * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
  39. * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  40. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  41. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
  42. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  43. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  44. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  45. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  46. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  47. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  48. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  49. * OF THE POSSIBILITY OF SUCH DAMAGE.
  50. * ====================================================================
  51. */
  52. #if defined( __VMS) && !defined( OPENSSL_NO_DECC_INIT) && \
  53. defined( __DECC) && !defined( __VAX) && (__CRTL_VER >= 70301000)
  54. # define USE_DECC_INIT 1
  55. #endif
  56. #ifdef USE_DECC_INIT
  57. /*
  58. * ----------------------------------------------------------------------
  59. * decc_init() On non-VAX systems, uses LIB$INITIALIZE to set a collection
  60. * of C RTL features without using the DECC$* logical name method.
  61. * ----------------------------------------------------------------------
  62. */
  63. # include <stdio.h>
  64. # include <stdlib.h>
  65. # include <unixlib.h>
  66. # include "apps.h"
  67. /* Global storage. */
  68. /* Flag to sense if decc_init() was called. */
  69. int decc_init_done = -1;
  70. /* Structure to hold a DECC$* feature name and its desired value. */
  71. typedef struct {
  72. char *name;
  73. int value;
  74. } decc_feat_t;
  75. /*
  76. * Array of DECC$* feature names and their desired values. Note:
  77. * DECC$ARGV_PARSE_STYLE is the urgent one.
  78. */
  79. decc_feat_t decc_feat_array[] = {
  80. /* Preserve command-line case with SET PROCESS/PARSE_STYLE=EXTENDED */
  81. {"DECC$ARGV_PARSE_STYLE", 1},
  82. /* Preserve case for file names on ODS5 disks. */
  83. {"DECC$EFS_CASE_PRESERVE", 1},
  84. /*
  85. * Enable multiple dots (and most characters) in ODS5 file names, while
  86. * preserving VMS-ness of ";version".
  87. */
  88. {"DECC$EFS_CHARSET", 1},
  89. /* List terminator. */
  90. {(char *)NULL, 0}
  91. };
  92. char **copy_argv(int *argc, char *argv[])
  93. {
  94. /*-
  95. * The note below is for historical purpose. On VMS now we always
  96. * copy argv "safely."
  97. *
  98. * 2011-03-22 SMS.
  99. * If we have 32-bit pointers everywhere, then we're safe, and
  100. * we bypass this mess, as on non-VMS systems.
  101. * Problem 1: Compaq/HP C before V7.3 always used 32-bit
  102. * pointers for argv[].
  103. * Fix 1: For a 32-bit argv[], when we're using 64-bit pointers
  104. * everywhere else, we always allocate and use a 64-bit
  105. * duplicate of argv[].
  106. * Problem 2: Compaq/HP C V7.3 (Alpha, IA64) before ECO1 failed
  107. * to NULL-terminate a 64-bit argv[]. (As this was written, the
  108. * compiler ECO was available only on IA64.)
  109. * Fix 2: Unless advised not to (VMS_TRUST_ARGV), we test a
  110. * 64-bit argv[argc] for NULL, and, if necessary, use a
  111. * (properly) NULL-terminated (64-bit) duplicate of argv[].
  112. * The same code is used in either case to duplicate argv[].
  113. * Some of these decisions could be handled in preprocessing,
  114. * but the code tends to get even uglier, and the penalty for
  115. * deciding at compile- or run-time is tiny.
  116. */
  117. int i, count = *argc;
  118. char **newargv = app_malloc(sizeof(*newargv) * (count + 1), "argv copy");
  119. for (i = 0; i < count; i++)
  120. newargv[i] = argv[i];
  121. newargv[i] = NULL;
  122. *argc = i;
  123. return newargv;
  124. }
  125. /* LIB$INITIALIZE initialization function. */
  126. static void decc_init(void)
  127. {
  128. char *openssl_debug_decc_init;
  129. int verbose = 0;
  130. int feat_index;
  131. int feat_value;
  132. int feat_value_max;
  133. int feat_value_min;
  134. int i;
  135. int sts;
  136. /* Get debug option. */
  137. openssl_debug_decc_init = getenv("OPENSSL_DEBUG_DECC_INIT");
  138. if (openssl_debug_decc_init != NULL) {
  139. verbose = strtol(openssl_debug_decc_init, NULL, 10);
  140. if (verbose <= 0) {
  141. verbose = 1;
  142. }
  143. }
  144. /* Set the global flag to indicate that LIB$INITIALIZE worked. */
  145. decc_init_done = 1;
  146. /* Loop through all items in the decc_feat_array[]. */
  147. for (i = 0; decc_feat_array[i].name != NULL; i++) {
  148. /* Get the feature index. */
  149. feat_index = decc$feature_get_index(decc_feat_array[i].name);
  150. if (feat_index >= 0) {
  151. /* Valid item. Collect its properties. */
  152. feat_value = decc$feature_get_value(feat_index, 1);
  153. feat_value_min = decc$feature_get_value(feat_index, 2);
  154. feat_value_max = decc$feature_get_value(feat_index, 3);
  155. /* Check the validity of our desired value. */
  156. if ((decc_feat_array[i].value >= feat_value_min) &&
  157. (decc_feat_array[i].value <= feat_value_max)) {
  158. /* Valid value. Set it if necessary. */
  159. if (feat_value != decc_feat_array[i].value) {
  160. sts = decc$feature_set_value(feat_index,
  161. 1, decc_feat_array[i].value);
  162. if (verbose > 1) {
  163. fprintf(stderr, " %s = %d, sts = %d.\n",
  164. decc_feat_array[i].name,
  165. decc_feat_array[i].value, sts);
  166. }
  167. }
  168. } else {
  169. /* Invalid DECC feature value. */
  170. fprintf(stderr,
  171. " INVALID DECC$FEATURE VALUE, %d: %d <= %s <= %d.\n",
  172. feat_value,
  173. feat_value_min, decc_feat_array[i].name,
  174. feat_value_max);
  175. }
  176. } else {
  177. /* Invalid DECC feature name. */
  178. fprintf(stderr,
  179. " UNKNOWN DECC$FEATURE: %s.\n", decc_feat_array[i].name);
  180. }
  181. }
  182. if (verbose > 0) {
  183. fprintf(stderr, " DECC_INIT complete.\n");
  184. }
  185. }
  186. /* Get "decc_init()" into a valid, loaded LIB$INITIALIZE PSECT. */
  187. # pragma nostandard
  188. /*
  189. * Establish the LIB$INITIALIZE PSECTs, with proper alignment and other
  190. * attributes. Note that "nopic" is significant only on VAX.
  191. */
  192. # pragma extern_model save
  193. # if __INITIAL_POINTER_SIZE == 64
  194. # define PSECT_ALIGN 3
  195. # else
  196. # define PSECT_ALIGN 2
  197. # endif
  198. # pragma extern_model strict_refdef "LIB$INITIALIZ" PSECT_ALIGN, nopic, nowrt
  199. const int spare[8] = { 0 };
  200. # pragma extern_model strict_refdef "LIB$INITIALIZE" PSECT_ALIGN, nopic, nowrt
  201. void (*const x_decc_init) () = decc_init;
  202. # pragma extern_model restore
  203. /* Fake reference to ensure loading the LIB$INITIALIZE PSECT. */
  204. # pragma extern_model save
  205. int LIB$INITIALIZE(void);
  206. # pragma extern_model strict_refdef
  207. int dmy_lib$initialize = (int)LIB$INITIALIZE;
  208. # pragma extern_model restore
  209. # pragma standard
  210. #else /* def USE_DECC_INIT */
  211. /* Dummy code to avoid a %CC-W-EMPTYFILE complaint. */
  212. int decc_init_dummy(void);
  213. #endif /* def USE_DECC_INIT */