Revision 31e31b8a
b/COPYING.LIB | ||
---|---|---|
1 |
------------------------------------------------------------------------------ |
|
2 |
NOTE: |
|
3 |
Some code of the Twin package was modified for DOSEMU by the DOSEMU-team. |
|
4 |
The original is 'Copyright 1997 Willows Software, Inc.' and generously |
|
5 |
was put under the GNU Library General Public License. |
|
6 |
( for more information see http://www.willows.com/ ) |
|
7 |
|
|
8 |
We make use of section 3 of the GNU Library General Public License |
|
9 |
('...opt to apply the terms of the ordinary GNU General Public License...'), |
|
10 |
because the resulting product is an integrated part of DOSEMU and |
|
11 |
can not be considered to be a 'library' in the terms of Library License. |
|
12 |
|
|
13 |
Therefore, the below GNU LIBRARY GENERAL PUBLIC LICENSE applies only to the |
|
14 |
_unchanged_ Twin package from Willows. For the DOSEMU-changed parts the normal |
|
15 |
GNU GENERAL PUBLIC LICENSE applies. This GPL (file COPYING) can be found in |
|
16 |
the root directory of the DOSEMU distribution. |
|
17 |
|
|
18 |
The act of transformation to GPL was indicated to the maintainer of the Twin |
|
19 |
package (Rob Penrose <rob@Canopy.Com>) and he acknowledge agreement. |
|
20 |
|
|
21 |
Nov. 1 1997, The DOSEMU team. |
|
22 |
|
|
23 |
------------------------------------------------------------------------------ |
|
24 |
GNU LIBRARY GENERAL PUBLIC LICENSE |
|
25 |
Version 2, June 1991 |
|
26 |
|
|
27 |
Copyright (C) 1991 Free Software Foundation, Inc. |
|
28 |
675 Mass Ave, Cambridge, MA 02139, USA |
|
29 |
Everyone is permitted to copy and distribute verbatim copies |
|
30 |
of this license document, but changing it is not allowed. |
|
31 |
|
|
32 |
[This is the first released version of the library GPL. It is |
|
33 |
numbered 2 because it goes with version 2 of the ordinary GPL.] |
|
34 |
|
|
35 |
Preamble |
|
36 |
|
|
37 |
The licenses for most software are designed to take away your |
|
38 |
freedom to share and change it. By contrast, the GNU General Public |
|
39 |
Licenses are intended to guarantee your freedom to share and change |
|
40 |
free software--to make sure the software is free for all its users. |
|
41 |
|
|
42 |
This license, the Library General Public License, applies to some |
|
43 |
specially designated Free Software Foundation software, and to any |
|
44 |
other libraries whose authors decide to use it. You can use it for |
|
45 |
your libraries, too. |
|
46 |
|
|
47 |
When we speak of free software, we are referring to freedom, not |
|
48 |
price. Our General Public Licenses are designed to make sure that you |
|
49 |
have the freedom to distribute copies of free software (and charge for |
|
50 |
this service if you wish), that you receive source code or can get it |
|
51 |
if you want it, that you can change the software or use pieces of it |
|
52 |
in new free programs; and that you know you can do these things. |
|
53 |
|
|
54 |
To protect your rights, we need to make restrictions that forbid |
|
55 |
anyone to deny you these rights or to ask you to surrender the rights. |
|
56 |
These restrictions translate to certain responsibilities for you if |
|
57 |
you distribute copies of the library, or if you modify it. |
|
58 |
|
|
59 |
For example, if you distribute copies of the library, whether gratis |
|
60 |
or for a fee, you must give the recipients all the rights that we gave |
|
61 |
you. You must make sure that they, too, receive or can get the source |
|
62 |
code. If you link a program with the library, you must provide |
|
63 |
complete object files to the recipients so that they can relink them |
|
64 |
with the library, after making changes to the library and recompiling |
|
65 |
it. And you must show them these terms so they know their rights. |
|
66 |
|
|
67 |
Our method of protecting your rights has two steps: (1) copyright |
|
68 |
the library, and (2) offer you this license which gives you legal |
|
69 |
permission to copy, distribute and/or modify the library. |
|
70 |
|
|
71 |
Also, for each distributor's protection, we want to make certain |
|
72 |
that everyone understands that there is no warranty for this free |
|
73 |
library. If the library is modified by someone else and passed on, we |
|
74 |
want its recipients to know that what they have is not the original |
|
75 |
version, so that any problems introduced by others will not reflect on |
|
76 |
the original authors' reputations. |
|
77 |
|
|
78 |
Finally, any free program is threatened constantly by software |
|
79 |
patents. We wish to avoid the danger that companies distributing free |
|
80 |
software will individually obtain patent licenses, thus in effect |
|
81 |
transforming the program into proprietary software. To prevent this, |
|
82 |
we have made it clear that any patent must be licensed for everyone's |
|
83 |
free use or not licensed at all. |
|
84 |
|
|
85 |
Most GNU software, including some libraries, is covered by the ordinary |
|
86 |
GNU General Public License, which was designed for utility programs. This |
|
87 |
license, the GNU Library General Public License, applies to certain |
|
88 |
designated libraries. This license is quite different from the ordinary |
|
89 |
one; be sure to read it in full, and don't assume that anything in it is |
|
90 |
the same as in the ordinary license. |
|
91 |
|
|
92 |
The reason we have a separate public license for some libraries is that |
|
93 |
they blur the distinction we usually make between modifying or adding to a |
|
94 |
program and simply using it. Linking a program with a library, without |
|
95 |
changing the library, is in some sense simply using the library, and is |
|
96 |
analogous to running a utility program or application program. However, in |
|
97 |
a textual and legal sense, the linked executable is a combined work, a |
|
98 |
derivative of the original library, and the ordinary General Public License |
|
99 |
treats it as such. |
|
100 |
|
|
101 |
Because of this blurred distinction, using the ordinary General |
|
102 |
Public License for libraries did not effectively promote software |
|
103 |
sharing, because most developers did not use the libraries. We |
|
104 |
concluded that weaker conditions might promote sharing better. |
|
105 |
|
|
106 |
However, unrestricted linking of non-free programs would deprive the |
|
107 |
users of those programs of all benefit from the free status of the |
|
108 |
libraries themselves. This Library General Public License is intended to |
|
109 |
permit developers of non-free programs to use free libraries, while |
|
110 |
preserving your freedom as a user of such programs to change the free |
|
111 |
libraries that are incorporated in them. (We have not seen how to achieve |
|
112 |
this as regards changes in header files, but we have achieved it as regards |
|
113 |
changes in the actual functions of the Library.) The hope is that this |
|
114 |
will lead to faster development of free libraries. |
|
115 |
|
|
116 |
The precise terms and conditions for copying, distribution and |
|
117 |
modification follow. Pay close attention to the difference between a |
|
118 |
"work based on the library" and a "work that uses the library". The |
|
119 |
former contains code derived from the library, while the latter only |
|
120 |
works together with the library. |
|
121 |
|
|
122 |
Note that it is possible for a library to be covered by the ordinary |
|
123 |
General Public License rather than by this special one. |
|
124 |
|
|
125 |
GNU LIBRARY GENERAL PUBLIC LICENSE |
|
126 |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
|
127 |
|
|
128 |
0. This License Agreement applies to any software library which |
|
129 |
contains a notice placed by the copyright holder or other authorized |
|
130 |
party saying it may be distributed under the terms of this Library |
|
131 |
General Public License (also called "this License"). Each licensee is |
|
132 |
addressed as "you". |
|
133 |
|
|
134 |
A "library" means a collection of software functions and/or data |
|
135 |
prepared so as to be conveniently linked with application programs |
|
136 |
(which use some of those functions and data) to form executables. |
|
137 |
|
|
138 |
The "Library", below, refers to any such software library or work |
|
139 |
which has been distributed under these terms. A "work based on the |
|
140 |
Library" means either the Library or any derivative work under |
|
141 |
copyright law: that is to say, a work containing the Library or a |
|
142 |
portion of it, either verbatim or with modifications and/or translated |
|
143 |
straightforwardly into another language. (Hereinafter, translation is |
|
144 |
included without limitation in the term "modification".) |
|
145 |
|
|
146 |
"Source code" for a work means the preferred form of the work for |
|
147 |
making modifications to it. For a library, complete source code means |
|
148 |
all the source code for all modules it contains, plus any associated |
|
149 |
interface definition files, plus the scripts used to control compilation |
|
150 |
and installation of the library. |
|
151 |
|
|
152 |
Activities other than copying, distribution and modification are not |
|
153 |
covered by this License; they are outside its scope. The act of |
|
154 |
running a program using the Library is not restricted, and output from |
|
155 |
such a program is covered only if its contents constitute a work based |
|
156 |
on the Library (independent of the use of the Library in a tool for |
|
157 |
writing it). Whether that is true depends on what the Library does |
|
158 |
and what the program that uses the Library does. |
|
159 |
|
|
160 |
1. You may copy and distribute verbatim copies of the Library's |
|
161 |
complete source code as you receive it, in any medium, provided that |
|
162 |
you conspicuously and appropriately publish on each copy an |
|
163 |
appropriate copyright notice and disclaimer of warranty; keep intact |
|
164 |
all the notices that refer to this License and to the absence of any |
|
165 |
warranty; and distribute a copy of this License along with the |
|
166 |
Library. |
|
167 |
|
|
168 |
You may charge a fee for the physical act of transferring a copy, |
|
169 |
and you may at your option offer warranty protection in exchange for a |
|
170 |
fee. |
|
171 |
|
|
172 |
2. You may modify your copy or copies of the Library or any portion |
|
173 |
of it, thus forming a work based on the Library, and copy and |
|
174 |
distribute such modifications or work under the terms of Section 1 |
|
175 |
above, provided that you also meet all of these conditions: |
|
176 |
|
|
177 |
a) The modified work must itself be a software library. |
|
178 |
|
|
179 |
b) You must cause the files modified to carry prominent notices |
|
180 |
stating that you changed the files and the date of any change. |
|
181 |
|
|
182 |
c) You must cause the whole of the work to be licensed at no |
|
183 |
charge to all third parties under the terms of this License. |
|
184 |
|
|
185 |
d) If a facility in the modified Library refers to a function or a |
|
186 |
table of data to be supplied by an application program that uses |
|
187 |
the facility, other than as an argument passed when the facility |
|
188 |
is invoked, then you must make a good faith effort to ensure that, |
|
189 |
in the event an application does not supply such function or |
|
190 |
table, the facility still operates, and performs whatever part of |
|
191 |
its purpose remains meaningful. |
|
192 |
|
|
193 |
(For example, a function in a library to compute square roots has |
|
194 |
a purpose that is entirely well-defined independent of the |
|
195 |
application. Therefore, Subsection 2d requires that any |
|
196 |
application-supplied function or table used by this function must |
|
197 |
be optional: if the application does not supply it, the square |
|
198 |
root function must still compute square roots.) |
|
199 |
|
|
200 |
These requirements apply to the modified work as a whole. If |
|
201 |
identifiable sections of that work are not derived from the Library, |
|
202 |
and can be reasonably considered independent and separate works in |
|
203 |
themselves, then this License, and its terms, do not apply to those |
|
204 |
sections when you distribute them as separate works. But when you |
|
205 |
distribute the same sections as part of a whole which is a work based |
|
206 |
on the Library, the distribution of the whole must be on the terms of |
|
207 |
this License, whose permissions for other licensees extend to the |
|
208 |
entire whole, and thus to each and every part regardless of who wrote |
|
209 |
it. |
|
210 |
|
|
211 |
Thus, it is not the intent of this section to claim rights or contest |
|
212 |
your rights to work written entirely by you; rather, the intent is to |
|
213 |
exercise the right to control the distribution of derivative or |
|
214 |
collective works based on the Library. |
|
215 |
|
|
216 |
In addition, mere aggregation of another work not based on the Library |
|
217 |
with the Library (or with a work based on the Library) on a volume of |
|
218 |
a storage or distribution medium does not bring the other work under |
|
219 |
the scope of this License. |
|
220 |
|
|
221 |
3. You may opt to apply the terms of the ordinary GNU General Public |
|
222 |
License instead of this License to a given copy of the Library. To do |
|
223 |
this, you must alter all the notices that refer to this License, so |
|
224 |
that they refer to the ordinary GNU General Public License, version 2, |
|
225 |
instead of to this License. (If a newer version than version 2 of the |
|
226 |
ordinary GNU General Public License has appeared, then you can specify |
|
227 |
that version instead if you wish.) Do not make any other change in |
|
228 |
these notices. |
|
229 |
|
|
230 |
Once this change is made in a given copy, it is irreversible for |
|
231 |
that copy, so the ordinary GNU General Public License applies to all |
|
232 |
subsequent copies and derivative works made from that copy. |
|
233 |
|
|
234 |
This option is useful when you wish to copy part of the code of |
|
235 |
the Library into a program that is not a library. |
|
236 |
|
|
237 |
4. You may copy and distribute the Library (or a portion or |
|
238 |
derivative of it, under Section 2) in object code or executable form |
|
239 |
under the terms of Sections 1 and 2 above provided that you accompany |
|
240 |
it with the complete corresponding machine-readable source code, which |
|
241 |
must be distributed under the terms of Sections 1 and 2 above on a |
|
242 |
medium customarily used for software interchange. |
|
243 |
|
|
244 |
If distribution of object code is made by offering access to copy |
|
245 |
from a designated place, then offering equivalent access to copy the |
|
246 |
source code from the same place satisfies the requirement to |
|
247 |
distribute the source code, even though third parties are not |
|
248 |
compelled to copy the source along with the object code. |
|
249 |
|
|
250 |
5. A program that contains no derivative of any portion of the |
|
251 |
Library, but is designed to work with the Library by being compiled or |
|
252 |
linked with it, is called a "work that uses the Library". Such a |
|
253 |
work, in isolation, is not a derivative work of the Library, and |
|
254 |
therefore falls outside the scope of this License. |
|
255 |
|
|
256 |
However, linking a "work that uses the Library" with the Library |
|
257 |
creates an executable that is a derivative of the Library (because it |
|
258 |
contains portions of the Library), rather than a "work that uses the |
|
259 |
library". The executable is therefore covered by this License. |
|
260 |
Section 6 states terms for distribution of such executables. |
|
261 |
|
|
262 |
When a "work that uses the Library" uses material from a header file |
|
263 |
that is part of the Library, the object code for the work may be a |
|
264 |
derivative work of the Library even though the source code is not. |
|
265 |
Whether this is true is especially significant if the work can be |
|
266 |
linked without the Library, or if the work is itself a library. The |
|
267 |
threshold for this to be true is not precisely defined by law. |
|
268 |
|
|
269 |
If such an object file uses only numerical parameters, data |
|
270 |
structure layouts and accessors, and small macros and small inline |
|
271 |
functions (ten lines or less in length), then the use of the object |
|
272 |
file is unrestricted, regardless of whether it is legally a derivative |
|
273 |
work. (Executables containing this object code plus portions of the |
|
274 |
Library will still fall under Section 6.) |
|
275 |
|
|
276 |
Otherwise, if the work is a derivative of the Library, you may |
|
277 |
distribute the object code for the work under the terms of Section 6. |
|
278 |
Any executables containing that work also fall under Section 6, |
|
279 |
whether or not they are linked directly with the Library itself. |
|
280 |
|
|
281 |
6. As an exception to the Sections above, you may also compile or |
|
282 |
link a "work that uses the Library" with the Library to produce a |
|
283 |
work containing portions of the Library, and distribute that work |
|
284 |
under terms of your choice, provided that the terms permit |
|
285 |
modification of the work for the customer's own use and reverse |
|
286 |
engineering for debugging such modifications. |
|
287 |
|
|
288 |
You must give prominent notice with each copy of the work that the |
|
289 |
Library is used in it and that the Library and its use are covered by |
|
290 |
this License. You must supply a copy of this License. If the work |
|
291 |
during execution displays copyright notices, you must include the |
|
292 |
copyright notice for the Library among them, as well as a reference |
|
293 |
directing the user to the copy of this License. Also, you must do one |
|
294 |
of these things: |
|
295 |
|
|
296 |
a) Accompany the work with the complete corresponding |
|
297 |
machine-readable source code for the Library including whatever |
|
298 |
changes were used in the work (which must be distributed under |
|
299 |
Sections 1 and 2 above); and, if the work is an executable linked |
|
300 |
with the Library, with the complete machine-readable "work that |
|
301 |
uses the Library", as object code and/or source code, so that the |
|
302 |
user can modify the Library and then relink to produce a modified |
|
303 |
executable containing the modified Library. (It is understood |
|
304 |
that the user who changes the contents of definitions files in the |
|
305 |
Library will not necessarily be able to recompile the application |
|
306 |
to use the modified definitions.) |
|
307 |
|
|
308 |
b) Accompany the work with a written offer, valid for at |
|
309 |
least three years, to give the same user the materials |
|
310 |
specified in Subsection 6a, above, for a charge no more |
|
311 |
than the cost of performing this distribution. |
|
312 |
|
|
313 |
c) If distribution of the work is made by offering access to copy |
|
314 |
from a designated place, offer equivalent access to copy the above |
|
315 |
specified materials from the same place. |
|
316 |
|
|
317 |
d) Verify that the user has already received a copy of these |
|
318 |
materials or that you have already sent this user a copy. |
|
319 |
|
|
320 |
For an executable, the required form of the "work that uses the |
|
321 |
Library" must include any data and utility programs needed for |
|
322 |
reproducing the executable from it. However, as a special exception, |
|
323 |
the source code distributed need not include anything that is normally |
|
324 |
distributed (in either source or binary form) with the major |
|
325 |
components (compiler, kernel, and so on) of the operating system on |
|
326 |
which the executable runs, unless that component itself accompanies |
|
327 |
the executable. |
|
328 |
|
|
329 |
It may happen that this requirement contradicts the license |
|
330 |
restrictions of other proprietary libraries that do not normally |
|
331 |
accompany the operating system. Such a contradiction means you cannot |
|
332 |
use both them and the Library together in an executable that you |
|
333 |
distribute. |
|
334 |
|
|
335 |
7. You may place library facilities that are a work based on the |
|
336 |
Library side-by-side in a single library together with other library |
|
337 |
facilities not covered by this License, and distribute such a combined |
|
338 |
library, provided that the separate distribution of the work based on |
|
339 |
the Library and of the other library facilities is otherwise |
|
340 |
permitted, and provided that you do these two things: |
|
341 |
|
|
342 |
a) Accompany the combined library with a copy of the same work |
|
343 |
based on the Library, uncombined with any other library |
|
344 |
facilities. This must be distributed under the terms of the |
|
345 |
Sections above. |
|
346 |
|
|
347 |
b) Give prominent notice with the combined library of the fact |
|
348 |
that part of it is a work based on the Library, and explaining |
|
349 |
where to find the accompanying uncombined form of the same work. |
|
350 |
|
|
351 |
8. You may not copy, modify, sublicense, link with, or distribute |
|
352 |
the Library except as expressly provided under this License. Any |
|
353 |
attempt otherwise to copy, modify, sublicense, link with, or |
|
354 |
distribute the Library is void, and will automatically terminate your |
|
355 |
rights under this License. However, parties who have received copies, |
|
356 |
or rights, from you under this License will not have their licenses |
|
357 |
terminated so long as such parties remain in full compliance. |
|
358 |
|
|
359 |
9. You are not required to accept this License, since you have not |
|
360 |
signed it. However, nothing else grants you permission to modify or |
|
361 |
distribute the Library or its derivative works. These actions are |
|
362 |
prohibited by law if you do not accept this License. Therefore, by |
|
363 |
modifying or distributing the Library (or any work based on the |
|
364 |
Library), you indicate your acceptance of this License to do so, and |
|
365 |
all its terms and conditions for copying, distributing or modifying |
|
366 |
the Library or works based on it. |
|
367 |
|
|
368 |
10. Each time you redistribute the Library (or any work based on the |
|
369 |
Library), the recipient automatically receives a license from the |
|
370 |
original licensor to copy, distribute, link with or modify the Library |
|
371 |
subject to these terms and conditions. You may not impose any further |
|
372 |
restrictions on the recipients' exercise of the rights granted herein. |
|
373 |
You are not responsible for enforcing compliance by third parties to |
|
374 |
this License. |
|
375 |
|
|
376 |
11. If, as a consequence of a court judgment or allegation of patent |
|
377 |
infringement or for any other reason (not limited to patent issues), |
|
378 |
conditions are imposed on you (whether by court order, agreement or |
|
379 |
otherwise) that contradict the conditions of this License, they do not |
|
380 |
excuse you from the conditions of this License. If you cannot |
|
381 |
distribute so as to satisfy simultaneously your obligations under this |
|
382 |
License and any other pertinent obligations, then as a consequence you |
|
383 |
may not distribute the Library at all. For example, if a patent |
|
384 |
license would not permit royalty-free redistribution of the Library by |
|
385 |
all those who receive copies directly or indirectly through you, then |
|
386 |
the only way you could satisfy both it and this License would be to |
|
387 |
refrain entirely from distribution of the Library. |
|
388 |
|
|
389 |
If any portion of this section is held invalid or unenforceable under any |
|
390 |
particular circumstance, the balance of the section is intended to apply, |
|
391 |
and the section as a whole is intended to apply in other circumstances. |
|
392 |
|
|
393 |
It is not the purpose of this section to induce you to infringe any |
|
394 |
patents or other property right claims or to contest validity of any |
|
395 |
such claims; this section has the sole purpose of protecting the |
|
396 |
integrity of the free software distribution system which is |
|
397 |
implemented by public license practices. Many people have made |
|
398 |
generous contributions to the wide range of software distributed |
|
399 |
through that system in reliance on consistent application of that |
|
400 |
system; it is up to the author/donor to decide if he or she is willing |
|
401 |
to distribute software through any other system and a licensee cannot |
|
402 |
impose that choice. |
|
403 |
|
|
404 |
This section is intended to make thoroughly clear what is believed to |
|
405 |
be a consequence of the rest of this License. |
|
406 |
|
|
407 |
12. If the distribution and/or use of the Library is restricted in |
|
408 |
certain countries either by patents or by copyrighted interfaces, the |
|
409 |
original copyright holder who places the Library under this License may add |
|
410 |
an explicit geographical distribution limitation excluding those countries, |
|
411 |
so that distribution is permitted only in or among countries not thus |
|
412 |
excluded. In such case, this License incorporates the limitation as if |
|
413 |
written in the body of this License. |
|
414 |
|
|
415 |
13. The Free Software Foundation may publish revised and/or new |
|
416 |
versions of the Library General Public License from time to time. |
|
417 |
Such new versions will be similar in spirit to the present version, |
|
418 |
but may differ in detail to address new problems or concerns. |
|
419 |
|
|
420 |
Each version is given a distinguishing version number. If the Library |
|
421 |
specifies a version number of this License which applies to it and |
|
422 |
"any later version", you have the option of following the terms and |
|
423 |
conditions either of that version or of any later version published by |
|
424 |
the Free Software Foundation. If the Library does not specify a |
|
425 |
license version number, you may choose any version ever published by |
|
426 |
the Free Software Foundation. |
|
427 |
|
|
428 |
14. If you wish to incorporate parts of the Library into other free |
|
429 |
programs whose distribution conditions are incompatible with these, |
|
430 |
write to the author to ask for permission. For software which is |
|
431 |
copyrighted by the Free Software Foundation, write to the Free |
|
432 |
Software Foundation; we sometimes make exceptions for this. Our |
|
433 |
decision will be guided by the two goals of preserving the free status |
|
434 |
of all derivatives of our free software and of promoting the sharing |
|
435 |
and reuse of software generally. |
|
436 |
|
|
437 |
NO WARRANTY |
|
438 |
|
|
439 |
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO |
|
440 |
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. |
|
441 |
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR |
|
442 |
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY |
|
443 |
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE |
|
444 |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
445 |
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE |
|
446 |
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME |
|
447 |
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. |
|
448 |
|
|
449 |
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN |
|
450 |
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY |
|
451 |
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU |
|
452 |
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR |
|
453 |
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE |
|
454 |
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING |
|
455 |
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A |
|
456 |
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF |
|
457 |
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
|
458 |
DAMAGES. |
|
459 |
|
|
460 |
END OF TERMS AND CONDITIONS |
|
461 |
|
|
462 |
Appendix: How to Apply These Terms to Your New Libraries |
|
463 |
|
|
464 |
If you develop a new library, and you want it to be of the greatest |
|
465 |
possible use to the public, we recommend making it free software that |
|
466 |
everyone can redistribute and change. You can do so by permitting |
|
467 |
redistribution under these terms (or, alternatively, under the terms of the |
|
468 |
ordinary General Public License). |
|
469 |
|
|
470 |
To apply these terms, attach the following notices to the library. It is |
|
471 |
safest to attach them to the start of each source file to most effectively |
|
472 |
convey the exclusion of warranty; and each file should have at least the |
|
473 |
"copyright" line and a pointer to where the full notice is found. |
|
474 |
|
|
475 |
<one line to give the library's name and a brief idea of what it does.> |
|
476 |
Copyright (C) <year> <name of author> |
|
477 |
|
|
478 |
This library is free software; you can redistribute it and/or |
|
479 |
modify it under the terms of the GNU Library General Public |
|
480 |
License as published by the Free Software Foundation; either |
|
481 |
version 2 of the License, or (at your option) any later version. |
|
482 |
|
|
483 |
This library is distributed in the hope that it will be useful, |
|
484 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
485 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
486 |
Library General Public License for more details. |
|
487 |
|
|
488 |
You should have received a copy of the GNU Library General Public |
|
489 |
License along with this library; if not, write to the Free |
|
490 |
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
491 |
|
|
492 |
Also add information on how to contact you by electronic and paper mail. |
|
493 |
|
|
494 |
You should also get your employer (if you work as a programmer) or your |
|
495 |
school, if any, to sign a "copyright disclaimer" for the library, if |
|
496 |
necessary. Here is a sample; alter the names: |
|
497 |
|
|
498 |
Yoyodyne, Inc., hereby disclaims all copyright interest in the |
|
499 |
library `Frob' (a library for tweaking knobs) written by James Random Hacker. |
|
500 |
|
|
501 |
<signature of Ty Coon>, 1 April 1990 |
|
502 |
Ty Coon, President of Vice |
|
503 |
|
|
504 |
That's all there is to it! |
b/Makefile | ||
---|---|---|
1 |
CFLAGS=-Wall -O2 -g |
|
2 |
LDFLAGS=-g |
|
3 |
DEFINES=-D_GNU_SOURCE -DGEMU -DDOSEMU #-DNO_TRACE_MSGS |
|
4 |
|
|
5 |
OBJS= i386/fp87.o i386/interp_main.o i386/interp_modrm.o i386/interp_16_32.o \ |
|
6 |
i386/interp_32_16.o i386/interp_32_32.o i386/emu-utils.o \ |
|
7 |
i386/dis8086.o i386/emu-ldt.o |
|
8 |
OBJS+= elfload.o main.o thunk.o syscall.o |
|
9 |
|
|
10 |
SRCS = $(OBJS:.o=.c) |
|
11 |
|
|
12 |
all: gemu |
|
13 |
|
|
14 |
gemu: $(OBJS) |
|
15 |
$(CC) -Wl,-T,i386.ld $(LDFLAGS) -o $@ $(OBJS) |
|
16 |
|
|
17 |
depend: $(SRCS) |
|
18 |
$(CC) -MM $(CFLAGS) $^ 1>.depend |
|
19 |
|
|
20 |
%.o: %.c |
|
21 |
$(CC) $(CFLAGS) $(DEFINES) -c -o $@ $< |
|
22 |
|
|
23 |
clean: |
|
24 |
rm -f *.o *~ i386/*.o i386/*~ gemu hello test1 test2 TAGS |
|
25 |
|
|
26 |
hello: hello.c |
|
27 |
$(CC) -nostdlib $(CFLAGS) -static $(LDFLAGS) -o $@ $< |
|
28 |
|
|
29 |
test1: test1.c |
|
30 |
$(CC) $(CFLAGS) -static $(LDFLAGS) -o $@ $< |
|
31 |
|
|
32 |
test2: test2.c |
|
33 |
$(CC) $(CFLAGS) -static $(LDFLAGS) -o $@ $< |
|
34 |
|
|
35 |
ifneq ($(wildcard .depend),) |
|
36 |
include .depend |
|
37 |
endif |
b/TODO | ||
---|---|---|
1 |
- swap all elf paramters |
|
2 |
- fix printf for doubles (fp87.c bug ?) |
b/elf.h | ||
---|---|---|
1 |
/* |
|
2 |
* ELF register definitions.. |
|
3 |
*/ |
|
4 |
|
|
5 |
#include <inttypes.h> |
|
6 |
|
|
7 |
typedef uint32_t elf_greg_t; |
|
8 |
|
|
9 |
#define ELF_NGREG (sizeof (struct pt_regs) / sizeof(elf_greg_t)) |
|
10 |
typedef elf_greg_t elf_gregset_t[ELF_NGREG]; |
|
11 |
|
|
12 |
typedef struct user_i387_struct elf_fpregset_t; |
|
13 |
|
|
14 |
/* |
|
15 |
* This is used to ensure we don't load something for the wrong architecture. |
|
16 |
*/ |
|
17 |
#define elf_check_arch(x) ( ((x) == EM_386) || ((x) == EM_486) ) |
|
18 |
|
|
19 |
/* |
|
20 |
* These are used to set parameters in the core dumps. |
|
21 |
*/ |
|
22 |
#define ELF_CLASS ELFCLASS32 |
|
23 |
#define ELF_DATA ELFDATA2LSB; |
|
24 |
#define ELF_ARCH EM_386 |
|
25 |
|
|
26 |
/* SVR4/i386 ABI (pages 3-31, 3-32) says that when the program |
|
27 |
starts %edx contains a pointer to a function which might be |
|
28 |
registered using `atexit'. This provides a mean for the |
|
29 |
dynamic linker to call DT_FINI functions for shared libraries |
|
30 |
that have been loaded before the code runs. |
|
31 |
|
|
32 |
A value of 0 tells we have no such handler. */ |
|
33 |
#define ELF_PLAT_INIT(_r) _r->edx = 0 |
|
34 |
|
|
35 |
#define USE_ELF_CORE_DUMP |
|
36 |
#define ELF_EXEC_PAGESIZE 4096 |
|
37 |
|
|
38 |
|
|
39 |
typedef uint32_t Elf32_Addr; |
|
40 |
typedef uint16_t Elf32_Half; |
|
41 |
typedef uint32_t Elf32_Off; |
|
42 |
typedef int32_t Elf32_Sword; |
|
43 |
typedef uint32_t Elf32_Word; |
|
44 |
|
|
45 |
/* These constants are for the segment types stored in the image headers */ |
|
46 |
#define PT_NULL 0 |
|
47 |
#define PT_LOAD 1 |
|
48 |
#define PT_DYNAMIC 2 |
|
49 |
#define PT_INTERP 3 |
|
50 |
#define PT_NOTE 4 |
|
51 |
#define PT_SHLIB 5 |
|
52 |
#define PT_PHDR 6 |
|
53 |
#define PT_LOPROC 0x70000000 |
|
54 |
#define PT_HIPROC 0x7fffffff |
|
55 |
|
|
56 |
/* These constants define the different elf file types */ |
|
57 |
#define ET_NONE 0 |
|
58 |
#define ET_REL 1 |
|
59 |
#define ET_EXEC 2 |
|
60 |
#define ET_DYN 3 |
|
61 |
#define ET_CORE 4 |
|
62 |
#define ET_LOPROC 5 |
|
63 |
#define ET_HIPROC 6 |
|
64 |
|
|
65 |
/* These constants define the various ELF target machines */ |
|
66 |
#define EM_NONE 0 |
|
67 |
#define EM_M32 1 |
|
68 |
#define EM_SPARC 2 |
|
69 |
#define EM_386 3 |
|
70 |
#define EM_68K 4 |
|
71 |
#define EM_88K 5 |
|
72 |
#define EM_486 6 /* Perhaps disused */ |
|
73 |
#define EM_860 7 |
|
74 |
|
|
75 |
#define EM_MIPS 8 /* MIPS R3000 (officially, big-endian only) */ |
|
76 |
|
|
77 |
#define EM_MIPS_RS4_BE 10 /* MIPS R4000 big-endian */ |
|
78 |
|
|
79 |
#define EM_SPARC64 11 /* SPARC v9 (not official) 64-bit */ |
|
80 |
|
|
81 |
#define EM_PARISC 15 /* HPPA */ |
|
82 |
|
|
83 |
#define EM_SPARC32PLUS 18 /* Sun's "v8plus" */ |
|
84 |
|
|
85 |
#define EM_PPC 20 /* PowerPC */ |
|
86 |
|
|
87 |
/* |
|
88 |
* This is an interim value that we will use until the committee comes |
|
89 |
* up with a final number. |
|
90 |
*/ |
|
91 |
#define EM_ALPHA 0x9026 |
|
92 |
|
|
93 |
|
|
94 |
/* This is the info that is needed to parse the dynamic section of the file */ |
|
95 |
#define DT_NULL 0 |
|
96 |
#define DT_NEEDED 1 |
|
97 |
#define DT_PLTRELSZ 2 |
|
98 |
#define DT_PLTGOT 3 |
|
99 |
#define DT_HASH 4 |
|
100 |
#define DT_STRTAB 5 |
|
101 |
#define DT_SYMTAB 6 |
|
102 |
#define DT_RELA 7 |
|
103 |
#define DT_RELASZ 8 |
|
104 |
#define DT_RELAENT 9 |
|
105 |
#define DT_STRSZ 10 |
|
106 |
#define DT_SYMENT 11 |
|
107 |
#define DT_INIT 12 |
|
108 |
#define DT_FINI 13 |
|
109 |
#define DT_SONAME 14 |
|
110 |
#define DT_RPATH 15 |
|
111 |
#define DT_SYMBOLIC 16 |
|
112 |
#define DT_REL 17 |
|
113 |
#define DT_RELSZ 18 |
|
114 |
#define DT_RELENT 19 |
|
115 |
#define DT_PLTREL 20 |
|
116 |
#define DT_DEBUG 21 |
|
117 |
#define DT_TEXTREL 22 |
|
118 |
#define DT_JMPREL 23 |
|
119 |
#define DT_LOPROC 0x70000000 |
|
120 |
#define DT_HIPROC 0x7fffffff |
|
121 |
|
|
122 |
/* This info is needed when parsing the symbol table */ |
|
123 |
#define STB_LOCAL 0 |
|
124 |
#define STB_GLOBAL 1 |
|
125 |
#define STB_WEAK 2 |
|
126 |
|
|
127 |
#define STT_NOTYPE 0 |
|
128 |
#define STT_OBJECT 1 |
|
129 |
#define STT_FUNC 2 |
|
130 |
#define STT_SECTION 3 |
|
131 |
#define STT_FILE 4 |
|
132 |
|
|
133 |
#define ELF32_ST_BIND(x) ((x) >> 4) |
|
134 |
#define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf) |
|
135 |
|
|
136 |
/* Symbolic values for the entries in the auxiliary table |
|
137 |
put on the initial stack */ |
|
138 |
#define AT_NULL 0 /* end of vector */ |
|
139 |
#define AT_IGNORE 1 /* entry should be ignored */ |
|
140 |
#define AT_EXECFD 2 /* file descriptor of program */ |
|
141 |
#define AT_PHDR 3 /* program headers for program */ |
|
142 |
#define AT_PHENT 4 /* size of program header entry */ |
|
143 |
#define AT_PHNUM 5 /* number of program headers */ |
|
144 |
#define AT_PAGESZ 6 /* system page size */ |
|
145 |
#define AT_BASE 7 /* base address of interpreter */ |
|
146 |
#define AT_FLAGS 8 /* flags */ |
|
147 |
#define AT_ENTRY 9 /* entry point of program */ |
|
148 |
#define AT_NOTELF 10 /* program is not ELF */ |
|
149 |
#define AT_UID 11 /* real uid */ |
|
150 |
#define AT_EUID 12 /* effective uid */ |
|
151 |
#define AT_GID 13 /* real gid */ |
|
152 |
#define AT_EGID 14 /* effective gid */ |
|
153 |
|
|
154 |
|
|
155 |
typedef struct dynamic{ |
|
156 |
Elf32_Sword d_tag; |
|
157 |
union{ |
|
158 |
Elf32_Sword d_val; |
|
159 |
Elf32_Addr d_ptr; |
|
160 |
} d_un; |
|
161 |
} Elf32_Dyn; |
|
162 |
|
|
163 |
typedef struct { |
|
164 |
unsigned long long d_tag; /* entry tag value */ |
|
165 |
union { |
|
166 |
unsigned long long d_val; |
|
167 |
unsigned long long d_ptr; |
|
168 |
} d_un; |
|
169 |
} Elf64_Dyn; |
|
170 |
|
|
171 |
/* The following are used with relocations */ |
|
172 |
#define ELF32_R_SYM(x) ((x) >> 8) |
|
173 |
#define ELF32_R_TYPE(x) ((x) & 0xff) |
|
174 |
|
|
175 |
#define R_386_NONE 0 |
|
176 |
#define R_386_32 1 |
|
177 |
#define R_386_PC32 2 |
|
178 |
#define R_386_GOT32 3 |
|
179 |
#define R_386_PLT32 4 |
|
180 |
#define R_386_COPY 5 |
|
181 |
#define R_386_GLOB_DAT 6 |
|
182 |
#define R_386_JMP_SLOT 7 |
|
183 |
#define R_386_RELATIVE 8 |
|
184 |
#define R_386_GOTOFF 9 |
|
185 |
#define R_386_GOTPC 10 |
|
186 |
#define R_386_NUM 11 |
|
187 |
|
|
188 |
typedef struct elf32_rel { |
|
189 |
Elf32_Addr r_offset; |
|
190 |
Elf32_Word r_info; |
|
191 |
} Elf32_Rel; |
|
192 |
|
|
193 |
typedef struct elf64_rel { |
|
194 |
unsigned long long r_offset; /* Location at which to apply the action */ |
|
195 |
unsigned long long r_info; /* index and type of relocation */ |
|
196 |
} Elf64_Rel; |
|
197 |
|
|
198 |
typedef struct elf32_rela{ |
|
199 |
Elf32_Addr r_offset; |
|
200 |
Elf32_Word r_info; |
|
201 |
Elf32_Sword r_addend; |
|
202 |
} Elf32_Rela; |
|
203 |
|
|
204 |
typedef struct elf64_rela { |
|
205 |
unsigned long long r_offset; /* Location at which to apply the action */ |
|
206 |
unsigned long long r_info; /* index and type of relocation */ |
|
207 |
unsigned long long r_addend; /* Constant addend used to compute value */ |
|
208 |
} Elf64_Rela; |
|
209 |
|
|
210 |
typedef struct elf32_sym{ |
|
211 |
Elf32_Word st_name; |
|
212 |
Elf32_Addr st_value; |
|
213 |
Elf32_Word st_size; |
|
214 |
unsigned char st_info; |
|
215 |
unsigned char st_other; |
|
216 |
Elf32_Half st_shndx; |
|
217 |
} Elf32_Sym; |
|
218 |
|
|
219 |
typedef struct elf64_sym { |
|
220 |
unsigned int st_name; /* Symbol name, index in string tbl */ |
|
221 |
unsigned char st_info; /* Type and binding attributes */ |
|
222 |
unsigned char st_other; /* No defined meaning, 0 */ |
|
223 |
unsigned short st_shndx; /* Associated section index */ |
|
224 |
unsigned long long st_value; /* Value of the symbol */ |
|
225 |
unsigned long long st_size; /* Associated symbol size */ |
|
226 |
} Elf64_Sym; |
|
227 |
|
|
228 |
|
|
229 |
#define EI_NIDENT 16 |
|
230 |
|
|
231 |
typedef struct elf32_hdr{ |
|
232 |
unsigned char e_ident[EI_NIDENT]; |
|
233 |
Elf32_Half e_type; |
|
234 |
Elf32_Half e_machine; |
|
235 |
Elf32_Word e_version; |
|
236 |
Elf32_Addr e_entry; /* Entry point */ |
|
237 |
Elf32_Off e_phoff; |
|
238 |
Elf32_Off e_shoff; |
|
239 |
Elf32_Word e_flags; |
|
240 |
Elf32_Half e_ehsize; |
|
241 |
Elf32_Half e_phentsize; |
|
242 |
Elf32_Half e_phnum; |
|
243 |
Elf32_Half e_shentsize; |
|
244 |
Elf32_Half e_shnum; |
|
245 |
Elf32_Half e_shstrndx; |
|
246 |
} Elf32_Ehdr; |
|
247 |
|
|
248 |
typedef struct elf64_hdr { |
|
249 |
unsigned char e_ident[16]; /* ELF "magic number" */ |
|
250 |
short int e_type; |
|
251 |
short unsigned int e_machine; |
|
252 |
int e_version; |
|
253 |
unsigned long long e_entry; /* Entry point virtual address */ |
|
254 |
unsigned long long e_phoff; /* Program header table file offset */ |
|
255 |
unsigned long long e_shoff; /* Section header table file offset */ |
|
256 |
int e_flags; |
|
257 |
short int e_ehsize; |
|
258 |
short int e_phentsize; |
|
259 |
short int e_phnum; |
|
260 |
short int e_shentsize; |
|
261 |
short int e_shnum; |
|
262 |
short int e_shstrndx; |
|
263 |
} Elf64_Ehdr; |
|
264 |
|
|
265 |
/* These constants define the permissions on sections in the program |
|
266 |
header, p_flags. */ |
|
267 |
#define PF_R 0x4 |
|
268 |
#define PF_W 0x2 |
|
269 |
#define PF_X 0x1 |
|
270 |
|
|
271 |
typedef struct elf32_phdr{ |
|
272 |
Elf32_Word p_type; |
|
273 |
Elf32_Off p_offset; |
|
274 |
Elf32_Addr p_vaddr; |
|
275 |
Elf32_Addr p_paddr; |
|
276 |
Elf32_Word p_filesz; |
|
277 |
Elf32_Word p_memsz; |
|
278 |
Elf32_Word p_flags; |
|
279 |
Elf32_Word p_align; |
|
280 |
} Elf32_Phdr; |
|
281 |
|
|
282 |
typedef struct elf64_phdr { |
|
283 |
int p_type; |
|
284 |
int p_flags; |
|
285 |
unsigned long long p_offset; /* Segment file offset */ |
|
286 |
unsigned long long p_vaddr; /* Segment virtual address */ |
|
287 |
unsigned long long p_paddr; /* Segment physical address */ |
|
288 |
unsigned long long p_filesz; /* Segment size in file */ |
|
289 |
unsigned long long p_memsz; /* Segment size in memory */ |
|
290 |
unsigned long long p_align; /* Segment alignment, file & memory */ |
|
291 |
} Elf64_Phdr; |
|
292 |
|
|
293 |
/* sh_type */ |
|
294 |
#define SHT_NULL 0 |
|
295 |
#define SHT_PROGBITS 1 |
|
296 |
#define SHT_SYMTAB 2 |
|
297 |
#define SHT_STRTAB 3 |
|
298 |
#define SHT_RELA 4 |
|
299 |
#define SHT_HASH 5 |
|
300 |
#define SHT_DYNAMIC 6 |
|
301 |
#define SHT_NOTE 7 |
|
302 |
#define SHT_NOBITS 8 |
|
303 |
#define SHT_REL 9 |
|
304 |
#define SHT_SHLIB 10 |
|
305 |
#define SHT_DYNSYM 11 |
|
306 |
#define SHT_NUM 12 |
|
307 |
#define SHT_LOPROC 0x70000000 |
|
308 |
#define SHT_HIPROC 0x7fffffff |
|
309 |
#define SHT_LOUSER 0x80000000 |
|
310 |
#define SHT_HIUSER 0xffffffff |
|
311 |
|
|
312 |
/* sh_flags */ |
|
313 |
#define SHF_WRITE 0x1 |
|
314 |
#define SHF_ALLOC 0x2 |
|
315 |
#define SHF_EXECINSTR 0x4 |
|
316 |
#define SHF_MASKPROC 0xf0000000 |
|
317 |
|
|
318 |
/* special section indexes */ |
|
319 |
#define SHN_UNDEF 0 |
|
320 |
#define SHN_LORESERVE 0xff00 |
|
321 |
#define SHN_LOPROC 0xff00 |
|
322 |
#define SHN_HIPROC 0xff1f |
|
323 |
#define SHN_ABS 0xfff1 |
|
324 |
#define SHN_COMMON 0xfff2 |
|
325 |
#define SHN_HIRESERVE 0xffff |
|
326 |
|
|
327 |
typedef struct { |
|
328 |
Elf32_Word sh_name; |
|
329 |
Elf32_Word sh_type; |
|
330 |
Elf32_Word sh_flags; |
|
331 |
Elf32_Addr sh_addr; |
|
332 |
Elf32_Off sh_offset; |
|
333 |
Elf32_Word sh_size; |
|
334 |
Elf32_Word sh_link; |
|
335 |
Elf32_Word sh_info; |
|
336 |
Elf32_Word sh_addralign; |
|
337 |
Elf32_Word sh_entsize; |
|
338 |
} Elf32_Shdr; |
|
339 |
|
|
340 |
typedef struct elf64_shdr { |
|
341 |
unsigned int sh_name; /* Section name, index in string tbl */ |
|
342 |
unsigned int sh_type; /* Type of section */ |
|
343 |
unsigned long long sh_flags; /* Miscellaneous section attributes */ |
|
344 |
unsigned long long sh_addr; /* Section virtual addr at execution */ |
|
345 |
unsigned long long sh_offset; /* Section file offset */ |
|
346 |
unsigned long long sh_size; /* Size of section in bytes */ |
|
347 |
unsigned int sh_link; /* Index of another section */ |
|
348 |
unsigned int sh_info; /* Additional section information */ |
|
349 |
unsigned long long sh_addralign; /* Section alignment */ |
|
350 |
unsigned long long sh_entsize; /* Entry size if section holds table */ |
|
351 |
} Elf64_Shdr; |
|
352 |
|
|
353 |
#define EI_MAG0 0 /* e_ident[] indexes */ |
|
354 |
#define EI_MAG1 1 |
|
355 |
#define EI_MAG2 2 |
|
356 |
#define EI_MAG3 3 |
|
357 |
#define EI_CLASS 4 |
|
358 |
#define EI_DATA 5 |
|
359 |
#define EI_VERSION 6 |
|
360 |
#define EI_PAD 7 |
|
361 |
|
|
362 |
#define ELFMAG0 0x7f /* EI_MAG */ |
|
363 |
#define ELFMAG1 'E' |
|
364 |
#define ELFMAG2 'L' |
|
365 |
#define ELFMAG3 'F' |
|
366 |
#define ELFMAG "\177ELF" |
|
367 |
#define SELFMAG 4 |
|
368 |
|
|
369 |
#define ELFCLASSNONE 0 /* EI_CLASS */ |
|
370 |
#define ELFCLASS32 1 |
|
371 |
#define ELFCLASS64 2 |
|
372 |
#define ELFCLASSNUM 3 |
|
373 |
|
|
374 |
#define ELFDATANONE 0 /* e_ident[EI_DATA] */ |
|
375 |
#define ELFDATA2LSB 1 |
|
376 |
#define ELFDATA2MSB 2 |
|
377 |
|
|
378 |
#define EV_NONE 0 /* e_version, EI_VERSION */ |
|
379 |
#define EV_CURRENT 1 |
|
380 |
#define EV_NUM 2 |
|
381 |
|
|
382 |
/* Notes used in ET_CORE */ |
|
383 |
#define NT_PRSTATUS 1 |
|
384 |
#define NT_PRFPREG 2 |
|
385 |
#define NT_PRPSINFO 3 |
|
386 |
#define NT_TASKSTRUCT 4 |
|
387 |
|
|
388 |
/* Note header in a PT_NOTE section */ |
|
389 |
typedef struct elf32_note { |
|
390 |
Elf32_Word n_namesz; /* Name size */ |
|
391 |
Elf32_Word n_descsz; /* Content size */ |
|
392 |
Elf32_Word n_type; /* Content type */ |
|
393 |
} Elf32_Nhdr; |
|
394 |
|
|
395 |
/* Note header in a PT_NOTE section */ |
|
396 |
/* |
|
397 |
* For now we use the 32 bit version of the structure until we figure |
|
398 |
* out whether we need anything better. Note - on the Alpha, "unsigned int" |
|
399 |
* is only 32 bits. |
|
400 |
*/ |
|
401 |
typedef struct elf64_note { |
|
402 |
unsigned int n_namesz; /* Name size */ |
|
403 |
unsigned int n_descsz; /* Content size */ |
|
404 |
unsigned int n_type; /* Content type */ |
|
405 |
} Elf64_Nhdr; |
|
406 |
|
|
407 |
#define ELF_START_MMAP 0x80000000 |
|
408 |
|
|
409 |
#if ELF_CLASS == ELFCLASS32 |
|
410 |
|
|
411 |
extern Elf32_Dyn _DYNAMIC []; |
|
412 |
#define elfhdr elf32_hdr |
|
413 |
#define elf_phdr elf32_phdr |
|
414 |
#define elf_note elf32_note |
|
415 |
|
|
416 |
#else |
|
417 |
|
|
418 |
extern Elf64_Dyn _DYNAMIC []; |
|
419 |
#define elfhdr elf64_hdr |
|
420 |
#define elf_phdr elf64_phdr |
|
421 |
#define elf_note elf64_note |
|
422 |
|
|
423 |
#endif |
|
424 |
|
|
425 |
|
b/i386.ld | ||
---|---|---|
1 |
/* ld script to make i386 Linux kernel |
|
2 |
* Written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>; |
|
3 |
*/ |
|
4 |
OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") |
|
5 |
OUTPUT_ARCH(i386) |
|
6 |
SEARCH_DIR(/lib); SEARCH_DIR(/usr/lib); SEARCH_DIR(/usr/local/lib); SEARCH_DIR(/usr/alpha-unknown-linux-gnu/lib); |
|
7 |
ENTRY(_start) |
|
8 |
SECTIONS |
|
9 |
{ |
|
10 |
/* Read-only sections, merged into text segment: */ |
|
11 |
. = 0x60000000 + SIZEOF_HEADERS; |
|
12 |
.interp : { *(.interp) } |
|
13 |
.hash : { *(.hash) } |
|
14 |
.dynsym : { *(.dynsym) } |
|
15 |
.dynstr : { *(.dynstr) } |
|
16 |
.gnu.version : { *(.gnu.version) } |
|
17 |
.gnu.version_d : { *(.gnu.version_d) } |
|
18 |
.gnu.version_r : { *(.gnu.version_r) } |
|
19 |
.rel.text : |
|
20 |
{ *(.rel.text) *(.rel.gnu.linkonce.t*) } |
|
21 |
.rela.text : |
|
22 |
{ *(.rela.text) *(.rela.gnu.linkonce.t*) } |
|
23 |
.rel.data : |
|
24 |
{ *(.rel.data) *(.rel.gnu.linkonce.d*) } |
|
25 |
.rela.data : |
|
26 |
{ *(.rela.data) *(.rela.gnu.linkonce.d*) } |
|
27 |
.rel.rodata : |
|
28 |
{ *(.rel.rodata) *(.rel.gnu.linkonce.r*) } |
|
29 |
.rela.rodata : |
|
30 |
{ *(.rela.rodata) *(.rela.gnu.linkonce.r*) } |
|
31 |
.rel.got : { *(.rel.got) } |
|
32 |
.rela.got : { *(.rela.got) } |
|
33 |
.rel.ctors : { *(.rel.ctors) } |
|
34 |
.rela.ctors : { *(.rela.ctors) } |
|
35 |
.rel.dtors : { *(.rel.dtors) } |
|
36 |
.rela.dtors : { *(.rela.dtors) } |
|
37 |
.rel.init : { *(.rel.init) } |
|
38 |
.rela.init : { *(.rela.init) } |
|
39 |
.rel.fini : { *(.rel.fini) } |
|
40 |
.rela.fini : { *(.rela.fini) } |
|
41 |
.rel.bss : { *(.rel.bss) } |
|
42 |
.rela.bss : { *(.rela.bss) } |
|
43 |
.rel.plt : { *(.rel.plt) } |
|
44 |
.rela.plt : { *(.rela.plt) } |
|
45 |
.init : { *(.init) } =0x47ff041f |
|
46 |
.text : |
|
47 |
{ |
|
48 |
*(.text) |
|
49 |
/* .gnu.warning sections are handled specially by elf32.em. */ |
|
50 |
*(.gnu.warning) |
|
51 |
*(.gnu.linkonce.t*) |
|
52 |
} =0x47ff041f |
|
53 |
_etext = .; |
|
54 |
PROVIDE (etext = .); |
|
55 |
.fini : { *(.fini) } =0x47ff041f |
|
56 |
.rodata : { *(.rodata) *(.gnu.linkonce.r*) } |
|
57 |
.rodata1 : { *(.rodata1) } |
|
58 |
.reginfo : { *(.reginfo) } |
|
59 |
/* Adjust the address for the data segment. We want to adjust up to |
|
60 |
the same address within the page on the next page up. */ |
|
61 |
. = ALIGN(0x100000) + (. & (0x100000 - 1)); |
|
62 |
.data : |
|
63 |
{ |
|
64 |
*(.data) |
|
65 |
*(.gnu.linkonce.d*) |
|
66 |
CONSTRUCTORS |
|
67 |
} |
|
68 |
.data1 : { *(.data1) } |
|
69 |
.ctors : |
|
70 |
{ |
|
71 |
*(.ctors) |
|
72 |
} |
|
73 |
.dtors : |
|
74 |
{ |
|
75 |
*(.dtors) |
|
76 |
} |
|
77 |
.plt : { *(.plt) } |
|
78 |
.got : { *(.got.plt) *(.got) } |
|
79 |
.dynamic : { *(.dynamic) } |
|
80 |
/* We want the small data sections together, so single-instruction offsets |
|
81 |
can access them all, and initialized data all before uninitialized, so |
|
82 |
we can shorten the on-disk segment size. */ |
|
83 |
.sdata : { *(.sdata) } |
|
84 |
_edata = .; |
|
85 |
PROVIDE (edata = .); |
|
86 |
__bss_start = .; |
|
87 |
.sbss : { *(.sbss) *(.scommon) } |
|
88 |
.bss : |
|
89 |
{ |
|
90 |
*(.dynbss) |
|
91 |
*(.bss) |
|
92 |
*(COMMON) |
|
93 |
} |
|
94 |
_end = . ; |
|
95 |
PROVIDE (end = .); |
|
96 |
/* Stabs debugging sections. */ |
|
97 |
.stab 0 : { *(.stab) } |
|
98 |
.stabstr 0 : { *(.stabstr) } |
|
99 |
.stab.excl 0 : { *(.stab.excl) } |
|
100 |
.stab.exclstr 0 : { *(.stab.exclstr) } |
|
101 |
.stab.index 0 : { *(.stab.index) } |
|
102 |
.stab.indexstr 0 : { *(.stab.indexstr) } |
|
103 |
.comment 0 : { *(.comment) } |
|
104 |
/* DWARF debug sections. |
|
105 |
Symbols in the DWARF debugging sections are relative to the beginning |
|
106 |
of the section so we begin them at 0. */ |
|
107 |
/* DWARF 1 */ |
|
108 |
.debug 0 : { *(.debug) } |
|
109 |
.line 0 : { *(.line) } |
|
110 |
/* GNU DWARF 1 extensions */ |
|
111 |
.debug_srcinfo 0 : { *(.debug_srcinfo) } |
|
112 |
.debug_sfnames 0 : { *(.debug_sfnames) } |
|
113 |
/* DWARF 1.1 and DWARF 2 */ |
|
114 |
.debug_aranges 0 : { *(.debug_aranges) } |
|
115 |
.debug_pubnames 0 : { *(.debug_pubnames) } |
|
116 |
/* DWARF 2 */ |
|
117 |
.debug_info 0 : { *(.debug_info) } |
|
118 |
.debug_abbrev 0 : { *(.debug_abbrev) } |
|
119 |
.debug_line 0 : { *(.debug_line) } |
|
120 |
.debug_frame 0 : { *(.debug_frame) } |
|
121 |
.debug_str 0 : { *(.debug_str) } |
|
122 |
.debug_loc 0 : { *(.debug_loc) } |
|
123 |
.debug_macinfo 0 : { *(.debug_macinfo) } |
|
124 |
/* SGI/MIPS DWARF 2 extensions */ |
|
125 |
.debug_weaknames 0 : { *(.debug_weaknames) } |
|
126 |
.debug_funcnames 0 : { *(.debug_funcnames) } |
|
127 |
.debug_typenames 0 : { *(.debug_typenames) } |
|
128 |
.debug_varnames 0 : { *(.debug_varnames) } |
|
129 |
/* These must appear regardless of . */ |
|
130 |
} |
b/linux-user/elfload.c | ||
---|---|---|
1 |
/* This is the Linux kernel elf-loading code, ported into user space */ |
|
2 |
|
|
3 |
#include <stdio.h> |
|
4 |
#include <sys/types.h> |
|
5 |
#include <fcntl.h> |
|
6 |
#include <sys/stat.h> |
|
7 |
#include <errno.h> |
|
8 |
#include <unistd.h> |
|
9 |
#include <sys/mman.h> |
|
10 |
#include <stdlib.h> |
|
11 |
#include <string.h> |
|
12 |
|
|
13 |
#include "gemu.h" |
|
14 |
|
|
15 |
#include "linux_bin.h" |
|
16 |
#include "elf.h" |
|
17 |
#include "segment.h" |
|
18 |
|
|
19 |
/* Necessary parameters */ |
|
20 |
#define ALPHA_PAGE_SIZE 4096 |
|
21 |
#define X86_PAGE_SIZE 4096 |
|
22 |
|
|
23 |
#define ALPHA_PAGE_MASK (~(ALPHA_PAGE_SIZE-1)) |
|
24 |
#define X86_PAGE_MASK (~(X86_PAGE_SIZE-1)) |
|
25 |
|
|
26 |
#define ALPHA_PAGE_ALIGN(addr) ((((addr)+ALPHA_PAGE_SIZE)-1)&ALPHA_PAGE_MASK) |
|
27 |
#define X86_PAGE_ALIGN(addr) ((((addr)+X86_PAGE_SIZE)-1)&X86_PAGE_MASK) |
|
28 |
|
|
29 |
#define NGROUPS 32 |
|
30 |
|
|
31 |
#define X86_ELF_EXEC_PAGESIZE X86_PAGE_SIZE |
|
32 |
#define X86_ELF_PAGESTART(_v) ((_v) & ~(unsigned long)(X86_ELF_EXEC_PAGESIZE-1)) |
|
33 |
#define X86_ELF_PAGEOFFSET(_v) ((_v) & (X86_ELF_EXEC_PAGESIZE-1)) |
|
34 |
|
|
35 |
#define ALPHA_ELF_PAGESTART(_v) ((_v) & ~(unsigned long)(ALPHA_PAGE_SIZE-1)) |
|
36 |
#define ALPHA_ELF_PAGEOFFSET(_v) ((_v) & (ALPHA_PAGE_SIZE-1)) |
|
37 |
|
|
38 |
#define INTERPRETER_NONE 0 |
|
39 |
#define INTERPRETER_AOUT 1 |
|
40 |
#define INTERPRETER_ELF 2 |
|
41 |
|
|
42 |
#define DLINFO_ITEMS 12 |
|
43 |
|
|
44 |
/* Where we find X86 libraries... */ |
|
45 |
//#define X86_DEFAULT_LIB_DIR "/usr/x86/" |
|
46 |
#define X86_DEFAULT_LIB_DIR "/" |
|
47 |
|
|
48 |
//extern void * mmap4k(); |
|
49 |
#define mmap4k(a, b, c, d, e, f) mmap((void *)(a), b, c, d, e, f) |
|
50 |
|
|
51 |
extern unsigned long x86_stack_size; |
|
52 |
|
|
53 |
static int load_aout_interp(void * exptr, int interp_fd); |
|
54 |
|
|
55 |
#ifdef BSWAP_NEEDED |
|
56 |
static void bswap_ehdr(Elf32_Ehdr *ehdr) |
|
57 |
{ |
|
58 |
bswap16s(&ehdr->e_type); /* Object file type */ |
|
59 |
bswap16s(&ehdr->e_machine); /* Architecture */ |
|
60 |
bswap32s(&ehdr->e_version); /* Object file version */ |
|
61 |
bswap32s(&ehdr->e_entry); /* Entry point virtual address */ |
|
62 |
bswap32s(&ehdr->e_phoff); /* Program header table file offset */ |
|
63 |
bswap32s(&ehdr->e_shoff); /* Section header table file offset */ |
|
64 |
bswap32s(&ehdr->e_flags); /* Processor-specific flags */ |
|
65 |
bswap16s(&ehdr->e_ehsize); /* ELF header size in bytes */ |
|
66 |
bswap16s(&ehdr->e_phentsize); /* Program header table entry size */ |
|
67 |
bswap16s(&ehdr->e_phnum); /* Program header table entry count */ |
|
68 |
bswap16s(&ehdr->e_shentsize); /* Section header table entry size */ |
|
69 |
bswap16s(&ehdr->e_shnum); /* Section header table entry count */ |
|
70 |
bswap16s(&ehdr->e_shstrndx); /* Section header string table index */ |
|
71 |
} |
|
72 |
|
|
73 |
static void bswap_phdr(Elf32_Phdr *phdr) |
|
74 |
{ |
|
75 |
bswap32s(&phdr->p_type); /* Segment type */ |
|
76 |
bswap32s(&phdr->p_offset); /* Segment file offset */ |
|
77 |
bswap32s(&phdr->p_vaddr); /* Segment virtual address */ |
|
78 |
bswap32s(&phdr->p_paddr); /* Segment physical address */ |
|
79 |
bswap32s(&phdr->p_filesz); /* Segment size in file */ |
|
80 |
bswap32s(&phdr->p_memsz); /* Segment size in memory */ |
|
81 |
bswap32s(&phdr->p_flags); /* Segment flags */ |
|
82 |
bswap32s(&phdr->p_align); /* Segment alignment */ |
|
83 |
} |
|
84 |
#endif |
|
85 |
|
|
86 |
static void * get_free_page(void) |
|
87 |
{ |
|
88 |
void * retval; |
|
89 |
|
|
90 |
/* User-space version of kernel get_free_page. Returns a page-aligned |
|
91 |
* page-sized chunk of memory. |
|
92 |
*/ |
|
93 |
retval = mmap4k(0, ALPHA_PAGE_SIZE, PROT_READ|PROT_WRITE, |
|
94 |
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); |
|
95 |
|
|
96 |
if((long)retval == -1) { |
|
97 |
perror("get_free_page"); |
|
98 |
exit(-1); |
|
99 |
} |
|
100 |
else { |
|
101 |
return(retval); |
|
102 |
} |
|
103 |
} |
|
104 |
|
|
105 |
static void free_page(void * pageaddr) |
|
106 |
{ |
|
107 |
(void)munmap(pageaddr, ALPHA_PAGE_SIZE); |
|
108 |
} |
|
109 |
|
|
110 |
/* |
|
111 |
* 'copy_string()' copies argument/envelope strings from user |
|
112 |
* memory to free pages in kernel mem. These are in a format ready |
|
113 |
* to be put directly into the top of new user memory. |
|
114 |
* |
|
115 |
*/ |
|
116 |
static unsigned long copy_strings(int argc,char ** argv,unsigned long *page, |
|
117 |
unsigned long p) |
|
118 |
{ |
|
119 |
char *tmp, *tmp1, *pag = NULL; |
|
120 |
int len, offset = 0; |
|
121 |
|
|
122 |
if (!p) { |
|
123 |
return 0; /* bullet-proofing */ |
|
124 |
} |
|
125 |
while (argc-- > 0) { |
|
126 |
if (!(tmp1 = tmp = get_user(argv+argc))) { |
|
127 |
fprintf(stderr, "VFS: argc is wrong"); |
|
128 |
exit(-1); |
|
129 |
} |
|
130 |
while (get_user(tmp++)); |
|
131 |
len = tmp - tmp1; |
|
132 |
if (p < len) { /* this shouldn't happen - 128kB */ |
|
133 |
return 0; |
|
134 |
} |
|
135 |
while (len) { |
|
136 |
--p; --tmp; --len; |
|
137 |
if (--offset < 0) { |
|
138 |
offset = p % X86_PAGE_SIZE; |
|
139 |
if (!(pag = (char *) page[p/X86_PAGE_SIZE]) && |
|
140 |
!(pag = (char *) page[p/X86_PAGE_SIZE] = |
|
141 |
(unsigned long *) get_free_page())) { |
|
142 |
return 0; |
|
143 |
} |
|
144 |
} |
|
145 |
if (len == 0 || offset == 0) { |
|
146 |
*(pag + offset) = get_user(tmp); |
|
147 |
} |
|
148 |
else { |
|
149 |
int bytes_to_copy = (len > offset) ? offset : len; |
|
150 |
tmp -= bytes_to_copy; |
|
151 |
p -= bytes_to_copy; |
|
152 |
offset -= bytes_to_copy; |
|
153 |
len -= bytes_to_copy; |
|
154 |
memcpy_fromfs(pag + offset, tmp, bytes_to_copy + 1); |
|
155 |
} |
|
156 |
} |
|
157 |
} |
|
158 |
return p; |
|
159 |
} |
|
160 |
|
|
161 |
static int in_group_p(gid_t g) |
|
162 |
{ |
|
163 |
/* return TRUE if we're in the specified group, FALSE otherwise */ |
|
164 |
int ngroup; |
|
165 |
int i; |
|
166 |
gid_t grouplist[NGROUPS]; |
|
167 |
|
|
168 |
ngroup = getgroups(NGROUPS, grouplist); |
|
169 |
for(i = 0; i < ngroup; i++) { |
|
170 |
if(grouplist[i] == g) { |
|
171 |
return 1; |
|
172 |
} |
|
173 |
} |
|
174 |
return 0; |
|
175 |
} |
|
176 |
|
|
177 |
static int count(char ** vec) |
|
178 |
{ |
|
179 |
int i; |
|
180 |
|
|
181 |
for(i = 0; *vec; i++) { |
|
182 |
vec++; |
|
183 |
} |
|
184 |
|
|
185 |
return(i); |
|
186 |
} |
|
187 |
|
|
188 |
static int prepare_binprm(struct linux_binprm *bprm) |
|
189 |
{ |
|
190 |
struct stat st; |
|
191 |
int mode; |
|
192 |
int retval, id_change; |
|
193 |
|
|
194 |
if(fstat(bprm->fd, &st) < 0) { |
|
195 |
return(-errno); |
|
196 |
} |
|
197 |
|
|
198 |
mode = st.st_mode; |
|
199 |
if(!S_ISREG(mode)) { /* Must be regular file */ |
|
200 |
return(-EACCES); |
|
201 |
} |
|
202 |
if(!(mode & 0111)) { /* Must have at least one execute bit set */ |
|
203 |
return(-EACCES); |
|
204 |
} |
|
205 |
|
|
206 |
bprm->e_uid = geteuid(); |
|
207 |
bprm->e_gid = getegid(); |
|
208 |
id_change = 0; |
|
209 |
|
|
210 |
/* Set-uid? */ |
|
211 |
if(mode & S_ISUID) { |
|
212 |
bprm->e_uid = st.st_uid; |
|
213 |
if(bprm->e_uid != geteuid()) { |
|
214 |
id_change = 1; |
|
215 |
} |
|
216 |
} |
|
217 |
|
|
218 |
/* Set-gid? */ |
|
219 |
/* |
|
220 |
* If setgid is set but no group execute bit then this |
|
221 |
* is a candidate for mandatory locking, not a setgid |
|
222 |
* executable. |
|
223 |
*/ |
|
224 |
if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) { |
|
225 |
bprm->e_gid = st.st_gid; |
|
226 |
if (!in_group_p(bprm->e_gid)) { |
|
227 |
id_change = 1; |
|
228 |
} |
|
229 |
} |
|
230 |
|
|
231 |
memset(bprm->buf, 0, sizeof(bprm->buf)); |
|
232 |
retval = lseek(bprm->fd, 0L, SEEK_SET); |
|
233 |
if(retval >= 0) { |
|
234 |
retval = read(bprm->fd, bprm->buf, 128); |
|
235 |
} |
|
236 |
if(retval < 0) { |
|
237 |
perror("prepare_binprm"); |
|
238 |
exit(-1); |
|
239 |
/* return(-errno); */ |
|
240 |
} |
|
241 |
else { |
|
242 |
return(retval); |
|
243 |
} |
|
244 |
} |
|
245 |
|
|
246 |
unsigned long setup_arg_pages(unsigned long p, struct linux_binprm * bprm, |
|
247 |
struct image_info * info) |
|
248 |
{ |
|
249 |
unsigned long stack_base; |
|
250 |
int i; |
|
251 |
extern unsigned long stktop; |
|
252 |
|
|
253 |
stack_base = X86_STACK_TOP - MAX_ARG_PAGES*X86_PAGE_SIZE; |
|
254 |
|
|
255 |
p += stack_base; |
|
256 |
if (bprm->loader) { |
|
257 |
bprm->loader += stack_base; |
|
258 |
} |
|
259 |
bprm->exec += stack_base; |
|
260 |
|
|
261 |
/* Create enough stack to hold everything. If we don't use |
|
262 |
* it for args, we'll use it for something else... |
|
263 |
*/ |
|
264 |
if(x86_stack_size > MAX_ARG_PAGES*X86_PAGE_SIZE) { |
|
265 |
if((long)mmap4k((void *)(X86_STACK_TOP-x86_stack_size), x86_stack_size + X86_PAGE_SIZE, |
|
266 |
PROT_READ | PROT_WRITE, |
|
267 |
MAP_GROWSDOWN | MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0) == -1) { |
|
268 |
perror("stk mmap"); |
|
269 |
exit(-1); |
|
270 |
} |
|
271 |
} |
|
272 |
else { |
|
273 |
if((long)mmap4k((void *)stack_base, (MAX_ARG_PAGES+1)*X86_PAGE_SIZE, |
|
274 |
PROT_READ | PROT_WRITE, |
|
275 |
MAP_GROWSDOWN | MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0) == -1) { |
|
276 |
perror("stk mmap"); |
|
277 |
exit(-1); |
|
278 |
} |
|
279 |
} |
|
280 |
|
|
281 |
stktop = stack_base; |
|
282 |
|
|
283 |
for (i = 0 ; i < MAX_ARG_PAGES ; i++) { |
|
284 |
if (bprm->page[i]) { |
|
285 |
info->rss++; |
|
286 |
|
|
287 |
memcpy((void *)stack_base, (void *)bprm->page[i], X86_PAGE_SIZE); |
|
288 |
free_page((void *)bprm->page[i]); |
|
289 |
} |
|
290 |
stack_base += X86_PAGE_SIZE; |
|
291 |
} |
|
292 |
return p; |
|
293 |
} |
|
294 |
|
|
295 |
static void set_brk(unsigned long start, unsigned long end) |
|
296 |
{ |
|
297 |
/* page-align the start and end addresses... */ |
|
298 |
start = ALPHA_PAGE_ALIGN(start); |
|
299 |
end = ALPHA_PAGE_ALIGN(end); |
|
300 |
if (end <= start) |
|
301 |
return; |
|
302 |
if((long)mmap4k(start, end - start, |
|
303 |
PROT_READ | PROT_WRITE | PROT_EXEC, |
|
304 |
MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0) == -1) { |
|
305 |
perror("cannot mmap brk"); |
|
306 |
exit(-1); |
|
307 |
} |
|
308 |
} |
|
309 |
|
|
310 |
|
|
311 |
/* We need to explicitly zero any fractional pages |
|
312 |
after the data section (i.e. bss). This would |
|
313 |
contain the junk from the file that should not |
|
314 |
be in memory */ |
|
315 |
|
|
316 |
|
|
317 |
static void padzero(unsigned long elf_bss) |
|
318 |
{ |
|
319 |
unsigned long nbyte; |
|
320 |
char * fpnt; |
|
321 |
|
|
322 |
nbyte = elf_bss & (ALPHA_PAGE_SIZE-1); /* was X86_PAGE_SIZE - JRP */ |
|
323 |
if (nbyte) { |
|
324 |
nbyte = ALPHA_PAGE_SIZE - nbyte; |
|
325 |
fpnt = (char *) elf_bss; |
|
326 |
do { |
|
327 |
*fpnt++ = 0; |
|
328 |
} while (--nbyte); |
|
329 |
} |
|
330 |
} |
|
331 |
|
|
332 |
static unsigned int * create_elf_tables(char *p, int argc, int envc, |
|
333 |
struct elfhdr * exec, |
|
334 |
unsigned long load_addr, |
|
335 |
unsigned long interp_load_addr, int ibcs, |
|
336 |
struct image_info *info) |
|
337 |
{ |
|
338 |
unsigned int *argv, *envp, *dlinfo; |
|
339 |
unsigned int *sp; |
|
340 |
char **alpha_envp; |
|
341 |
|
|
342 |
/* |
|
343 |
* Force 16 byte alignment here for generality. |
|
344 |
*/ |
|
345 |
sp = (unsigned int *) (~15UL & (unsigned long) p); |
|
346 |
sp -= exec ? DLINFO_ITEMS*2 : 2; |
|
347 |
dlinfo = sp; |
|
348 |
sp -= envc+1; |
|
349 |
envp = sp; |
|
350 |
sp -= argc+1; |
|
351 |
argv = sp; |
|
352 |
if (!ibcs) { |
|
353 |
put_user(envp,--sp); |
|
354 |
put_user(argv,--sp); |
|
355 |
} |
|
356 |
alpha_envp = (char **)malloc((envc+1) * sizeof(char *)); |
|
357 |
|
Also available in: Unified diff