2 * Copyright 2010-2016 The OpenSSL Project Authors. All Rights Reserved.
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
10 #if defined( __VMS) && !defined( OPENSSL_NO_DECC_INIT) && \
11 defined( __DECC) && !defined( __VAX) && (__CRTL_VER >= 70301000)
12 # define USE_DECC_INIT 1
18 * ----------------------------------------------------------------------
19 * decc_init() On non-VAX systems, uses LIB$INITIALIZE to set a collection
20 * of C RTL features without using the DECC$* logical name method.
21 * ----------------------------------------------------------------------
32 /* Flag to sense if decc_init() was called. */
34 int decc_init_done = -1;
36 /* Structure to hold a DECC$* feature name and its desired value. */
44 * Array of DECC$* feature names and their desired values. Note:
45 * DECC$ARGV_PARSE_STYLE is the urgent one.
48 decc_feat_t decc_feat_array[] = {
49 /* Preserve command-line case with SET PROCESS/PARSE_STYLE=EXTENDED */
50 {"DECC$ARGV_PARSE_STYLE", 1},
52 /* Preserve case for file names on ODS5 disks. */
53 {"DECC$EFS_CASE_PRESERVE", 1},
56 * Enable multiple dots (and most characters) in ODS5 file names, while
57 * preserving VMS-ness of ";version".
59 {"DECC$EFS_CHARSET", 1},
61 /* List terminator. */
66 char **copy_argv(int *argc, char *argv[])
69 * The note below is for historical purpose. On VMS now we always
73 * If we have 32-bit pointers everywhere, then we're safe, and
74 * we bypass this mess, as on non-VMS systems.
75 * Problem 1: Compaq/HP C before V7.3 always used 32-bit
76 * pointers for argv[].
77 * Fix 1: For a 32-bit argv[], when we're using 64-bit pointers
78 * everywhere else, we always allocate and use a 64-bit
79 * duplicate of argv[].
80 * Problem 2: Compaq/HP C V7.3 (Alpha, IA64) before ECO1 failed
81 * to NULL-terminate a 64-bit argv[]. (As this was written, the
82 * compiler ECO was available only on IA64.)
83 * Fix 2: Unless advised not to (VMS_TRUST_ARGV), we test a
84 * 64-bit argv[argc] for NULL, and, if necessary, use a
85 * (properly) NULL-terminated (64-bit) duplicate of argv[].
86 * The same code is used in either case to duplicate argv[].
87 * Some of these decisions could be handled in preprocessing,
88 * but the code tends to get even uglier, and the penalty for
89 * deciding at compile- or run-time is tiny.
93 char **newargv = app_malloc(sizeof(*newargv) * (count + 1), "argv copy");
95 for (i = 0; i < count; i++)
102 /* LIB$INITIALIZE initialization function. */
104 static void decc_init(void)
106 char *openssl_debug_decc_init;
115 /* Get debug option. */
116 openssl_debug_decc_init = getenv("OPENSSL_DEBUG_DECC_INIT");
117 if (openssl_debug_decc_init != NULL) {
118 verbose = strtol(openssl_debug_decc_init, NULL, 10);
124 /* Set the global flag to indicate that LIB$INITIALIZE worked. */
127 /* Loop through all items in the decc_feat_array[]. */
129 for (i = 0; decc_feat_array[i].name != NULL; i++) {
130 /* Get the feature index. */
131 feat_index = decc$feature_get_index(decc_feat_array[i].name);
132 if (feat_index >= 0) {
133 /* Valid item. Collect its properties. */
134 feat_value = decc$feature_get_value(feat_index, 1);
135 feat_value_min = decc$feature_get_value(feat_index, 2);
136 feat_value_max = decc$feature_get_value(feat_index, 3);
138 /* Check the validity of our desired value. */
139 if ((decc_feat_array[i].value >= feat_value_min) &&
140 (decc_feat_array[i].value <= feat_value_max)) {
141 /* Valid value. Set it if necessary. */
142 if (feat_value != decc_feat_array[i].value) {
143 sts = decc$feature_set_value(feat_index,
144 1, decc_feat_array[i].value);
147 fprintf(stderr, " %s = %d, sts = %d.\n",
148 decc_feat_array[i].name,
149 decc_feat_array[i].value, sts);
153 /* Invalid DECC feature value. */
155 " INVALID DECC$FEATURE VALUE, %d: %d <= %s <= %d.\n",
157 feat_value_min, decc_feat_array[i].name,
161 /* Invalid DECC feature name. */
163 " UNKNOWN DECC$FEATURE: %s.\n", decc_feat_array[i].name);
168 fprintf(stderr, " DECC_INIT complete.\n");
172 /* Get "decc_init()" into a valid, loaded LIB$INITIALIZE PSECT. */
177 * Establish the LIB$INITIALIZE PSECTs, with proper alignment and other
178 * attributes. Note that "nopic" is significant only on VAX.
180 # pragma extern_model save
182 # if __INITIAL_POINTER_SIZE == 64
183 # define PSECT_ALIGN 3
185 # define PSECT_ALIGN 2
188 # pragma extern_model strict_refdef "LIB$INITIALIZ" PSECT_ALIGN, nopic, nowrt
189 const int spare[8] = { 0 };
191 # pragma extern_model strict_refdef "LIB$INITIALIZE" PSECT_ALIGN, nopic, nowrt
192 void (*const x_decc_init) () = decc_init;
194 # pragma extern_model restore
196 /* Fake reference to ensure loading the LIB$INITIALIZE PSECT. */
198 # pragma extern_model save
200 int LIB$INITIALIZE(void);
202 # pragma extern_model strict_refdef
203 int dmy_lib$initialize = (int)LIB$INITIALIZE;
205 # pragma extern_model restore
209 #else /* def USE_DECC_INIT */
211 /* Dummy code to avoid a %CC-W-EMPTYFILE complaint. */
212 int decc_init_dummy(void);
214 #endif /* def USE_DECC_INIT */