0
|
1 /* VMS mapping of data and alloc arena for XEmacs.
|
|
2 Copyright (C) 1986, 1987 Free Software Foundation, Inc.
|
|
3
|
|
4 This file is part of XEmacs.
|
|
5
|
|
6 XEmacs is free software; you can redistribute it and/or modify it
|
|
7 under the terms of the GNU General Public License as published by the
|
|
8 Free Software Foundation; either version 2, or (at your option) any
|
|
9 later version.
|
|
10
|
|
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with XEmacs; see the file COPYING. If not, write to
|
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 Boston, MA 02111-1307, USA. */
|
|
20
|
|
21 /* Synched up with: Not synched with FSF. */
|
|
22
|
|
23 /* Written by Mukesh Prasad. */
|
|
24
|
|
25 #ifdef VMS
|
|
26
|
|
27 #include <config.h>
|
|
28 #include "lisp.h"
|
|
29 #include <rab.h>
|
|
30 #include <fab.h>
|
|
31 #include <rmsdef.h>
|
|
32 #include <secdef.h>
|
|
33
|
|
34 /* RMS block size */
|
|
35 #define BLOCKSIZE 512
|
|
36
|
|
37 /* Maximum number of bytes to be written in one RMS write.
|
|
38 * Must be a multiple of BLOCKSIZE.
|
|
39 */
|
|
40 #define MAXWRITE (BLOCKSIZE * 30)
|
|
41
|
|
42 /* This funniness is to ensure that sdata occurs alphabetically BEFORE the
|
|
43 $DATA psect and that edata occurs after ALL Emacs psects. This is
|
|
44 because the VMS linker sorts all psects in a cluster alphabetically
|
|
45 during the linking, unless you use the cluster_psect command. Emacs
|
|
46 uses the cluster command to group all Emacs psects into one cluster;
|
|
47 this keeps the dumped data separate from any loaded libraries. */
|
|
48
|
|
49 globaldef {"$D$ATA"} char sdata[512]; /* Start of saved data area */
|
|
50 globaldef {"__DATA"} char edata[512]; /* End of saved data area */
|
|
51
|
|
52 /* Structure to write into first block of map file.
|
|
53 */
|
|
54
|
|
55 struct map_data
|
|
56 {
|
|
57 char * sdata; /* Start of data area */
|
|
58 char * edata; /* End of data area */
|
|
59 int datablk; /* Block in file to map data area from/to */
|
|
60 };
|
|
61
|
|
62 static void fill_fab (), fill_rab ();
|
|
63 static int write_data ();
|
|
64
|
|
65 extern char *start_of_data ();
|
|
66 extern int vms_out_initial; /* Defined in malloc.c */
|
|
67
|
|
68 /* Maps in the data and alloc area from the map file.
|
|
69 */
|
|
70
|
|
71 int
|
|
72 mapin_data (name)
|
|
73 char * name;
|
|
74 {
|
|
75 struct FAB fab;
|
|
76 struct RAB rab;
|
|
77 int status, size;
|
|
78 int inadr[2];
|
|
79 struct map_data map_data;
|
|
80
|
|
81 /* Open map file. */
|
|
82 fab = cc$rms_fab;
|
|
83 fab.fab$b_fac = FAB$M_BIO|FAB$M_GET;
|
|
84 fab.fab$l_fna = name;
|
|
85 fab.fab$b_fns = strlen (name);
|
|
86 status = sys$open (&fab);
|
|
87 if (status != RMS$_NORMAL)
|
|
88 {
|
|
89 printf ("Map file not available, running bare Emacs....\n");
|
|
90 return 0; /* Map file not available */
|
|
91 }
|
|
92 /* Connect the RAB block */
|
|
93 rab = cc$rms_rab;
|
|
94 rab.rab$l_fab = &fab;
|
|
95 rab.rab$b_rac = RAB$C_SEQ;
|
|
96 rab.rab$l_rop = RAB$M_BIO;
|
|
97 status = sys$connect (&rab);
|
|
98 if (status != RMS$_NORMAL)
|
|
99 lib$stop (status);
|
|
100 /* Read the header data */
|
|
101 rab.rab$l_ubf = &map_data;
|
|
102 rab.rab$w_usz = sizeof (map_data);
|
|
103 rab.rab$l_bkt = 0;
|
|
104 status = sys$read (&rab);
|
|
105 if (status != RMS$_NORMAL)
|
|
106 lib$stop (status);
|
|
107 status = sys$close (&fab);
|
|
108 if (status != RMS$_NORMAL)
|
|
109 lib$stop (status);
|
|
110 if (map_data.sdata != start_of_data ())
|
|
111 {
|
|
112 printf ("Start of data area has moved: cannot map in data.\n");
|
|
113 return 0;
|
|
114 }
|
|
115 if (map_data.edata != edata)
|
|
116 {
|
|
117 printf ("End of data area has moved: cannot map in data.\n");
|
|
118 return 0;
|
|
119 }
|
|
120 fab.fab$l_fop |= FAB$M_UFO;
|
|
121 status = sys$open (&fab);
|
|
122 if (status != RMS$_NORMAL)
|
|
123 lib$stop (status);
|
|
124 /* Map data area. */
|
|
125 inadr[0] = map_data.sdata;
|
|
126 inadr[1] = map_data.edata;
|
|
127 status = sys$crmpsc (inadr, 0, 0, SEC$M_CRF | SEC$M_WRT, 0, 0, 0,
|
|
128 fab.fab$l_stv, 0, map_data.datablk, 0, 0);
|
|
129 if (! (status & 1))
|
|
130 lib$stop (status);
|
|
131 }
|
|
132
|
|
133 /* Writes the data and alloc area to the map file.
|
|
134 */
|
|
135 mapout_data (into)
|
|
136 char * into;
|
|
137 {
|
|
138 struct FAB fab;
|
|
139 struct RAB rab;
|
|
140 int status;
|
|
141 struct map_data map_data;
|
|
142 int datasize, msize;
|
|
143
|
|
144 if (vms_out_initial)
|
|
145 {
|
|
146 error ("Out of initial allocation. Must rebuild emacs with more memory (VMS_ALLOCATION_SIZE).");
|
|
147 return 0;
|
|
148 }
|
|
149 map_data.sdata = start_of_data ();
|
|
150 map_data.edata = edata;
|
|
151 datasize = map_data.edata - map_data.sdata + 1;
|
|
152 map_data.datablk = 2 + (sizeof (map_data) + BLOCKSIZE - 1) / BLOCKSIZE;
|
|
153 /* Create map file. */
|
|
154 fab = cc$rms_fab;
|
|
155 fab.fab$b_fac = FAB$M_BIO|FAB$M_PUT;
|
|
156 fab.fab$l_fna = into;
|
|
157 fab.fab$b_fns = strlen (into);
|
|
158 fab.fab$l_fop = FAB$M_CBT;
|
|
159 fab.fab$b_org = FAB$C_SEQ;
|
|
160 fab.fab$b_rat = 0;
|
|
161 fab.fab$b_rfm = FAB$C_VAR;
|
|
162 fab.fab$l_alq = 1 + map_data.datablk +
|
|
163 ((datasize + BLOCKSIZE - 1) / BLOCKSIZE);
|
|
164 status = sys$create (&fab);
|
|
165 if (status != RMS$_NORMAL)
|
|
166 {
|
|
167 error ("Could not create map file");
|
|
168 return 0;
|
|
169 }
|
|
170 /* Connect the RAB block */
|
|
171 rab = cc$rms_rab;
|
|
172 rab.rab$l_fab = &fab;
|
|
173 rab.rab$b_rac = RAB$C_SEQ;
|
|
174 rab.rab$l_rop = RAB$M_BIO;
|
|
175 status = sys$connect (&rab);
|
|
176 if (status != RMS$_NORMAL)
|
|
177 {
|
|
178 error ("RMS connect to map file failed");
|
|
179 return 0;
|
|
180 }
|
|
181 /* Write the header */
|
|
182 rab.rab$l_rbf = &map_data;
|
|
183 rab.rab$w_rsz = sizeof (map_data);
|
|
184 status = sys$write (&rab);
|
|
185 if (status != RMS$_NORMAL)
|
|
186 {
|
|
187 error ("RMS write (header) to map file failed");
|
|
188 return 0;
|
|
189 }
|
|
190 if (! write_data (&rab, map_data.datablk, map_data.sdata, datasize))
|
|
191 return 0;
|
|
192 status = sys$close (&fab);
|
|
193 if (status != RMS$_NORMAL)
|
|
194 {
|
|
195 error ("RMS close on map file failed");
|
|
196 return 0;
|
|
197 }
|
|
198 return 1;
|
|
199 }
|
|
200
|
|
201 static int
|
|
202 write_data (rab, firstblock, data, length)
|
|
203 struct RAB * rab;
|
|
204 char * data;
|
|
205 {
|
|
206 int status;
|
|
207
|
|
208 rab->rab$l_bkt = firstblock;
|
|
209 while (length > 0)
|
|
210 {
|
|
211 rab->rab$l_rbf = data;
|
|
212 rab->rab$w_rsz = length > MAXWRITE ? MAXWRITE : length;
|
|
213 status = sys$write (rab, 0, 0);
|
|
214 if (status != RMS$_NORMAL)
|
|
215 {
|
|
216 error ("RMS write to map file failed");
|
|
217 return 0;
|
|
218 }
|
|
219 data = &data[MAXWRITE];
|
|
220 length -= MAXWRITE;
|
|
221 rab->rab$l_bkt = 0;
|
|
222 }
|
|
223 return 1;
|
|
224 } /* write_data */
|
|
225
|
|
226 #endif /* VMS */
|
|
227
|