2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
5 Desc: DOS function LoadSeg()
10 #include <aros/asmcall.h>
11 #include <aros/config.h>
13 #include <dos/dosextens.h>
14 #include <dos/stdio.h>
15 #include <proto/dos.h>
16 #include <aros/debug.h>
17 #include "dos_intern.h"
19 static AROS_UFH4(LONG
, ReadFunc
,
20 AROS_UFHA(BPTR
, file
, D1
),
21 AROS_UFHA(APTR
, buffer
, D2
),
22 AROS_UFHA(LONG
, length
, D3
),
23 AROS_UFHA(struct DosLibrary
*, DOSBase
, A6
)
28 return FRead(file
, buffer
, 1, length
);
33 static AROS_UFH4(LONG
, SeekFunc
,
34 AROS_UFHA(BPTR
, file
, D1
),
35 AROS_UFHA(LONG
, pos
, D2
),
36 AROS_UFHA(LONG
, mode
, D3
),
37 AROS_UFHA(struct DosLibrary
*, DOSBase
, A6
)
42 return Seek(file
, pos
, mode
);
48 static AROS_UFH3(APTR
, AllocFunc
,
49 AROS_UFHA(ULONG
, length
, D0
),
50 AROS_UFHA(ULONG
, flags
, D1
),
51 AROS_UFHA(struct ExecBase
*, SysBase
, A6
)
56 return AllocMem(length
, flags
);
61 static AROS_UFH3(void, FreeFunc
,
62 AROS_UFHA(APTR
, buffer
, A1
),
63 AROS_UFHA(ULONG
, length
, D0
),
64 AROS_UFHA(struct ExecBase
*, SysBase
, A6
)
69 FreeMem(buffer
, length
);
75 static AROS_ENTRY(LONG
, SetPatch_noop
,
76 AROS_UFHA(char *, argstr
, A0
),
77 AROS_UFHA(ULONG
, argsize
, D0
),
78 struct ExecBase
*, SysBase
)
82 APTR DOSBase
= TaggedOpenLibrary(TAGGEDOPEN_DOS
);
85 struct CommandLineInterface
*cli
= Cli();
86 if (cli
&& cli
->cli_Interactive
) {
87 Printf("SetPatch is a reserved program name.\n");
89 CloseLibrary(DOSBase
);
98 /*****************************************************************************
101 #include <proto/dos.h>
103 AROS_LH1(BPTR
, LoadSeg
,
106 AROS_LHA(CONST_STRPTR
, name
, D1
),
109 struct DosLibrary
*, DOSBase
, 25, Dos
)
112 Loads an executable file into memory. Each hunk of the loadfile
113 is loaded into its own memory section and a handle on all of them
114 is returned. The segments can be freed with UnLoadSeg().
117 name - NUL terminated name of the file.
120 Handle to the loaded executable or NULL if the load failed.
121 IoErr() gives additional information in that case.
124 This function is built on top of InternalLoadSeg()
135 *****************************************************************************/
141 LONG_FUNC FunctionArray
[] = {
143 (LONG_FUNC
)AllocFunc
,
145 (LONG_FUNC
)SeekFunc
, /* Only needed for ELF */
149 /* On m68k, we map SetPatch to a no-op seglist,
150 * due to the fact that OS 3.x and higher's SetPatch
151 * blindly patches without checking OS versions.
153 if (Stricmp(FilePart(name
),"SetPatch") == 0)
154 return CreateSegList(SetPatch_noop
);
158 D(bug("[LoadSeg] Opening '%s'...\n", name
));
159 file
= Open (name
, MODE_OLDFILE
);
163 D(bug("[LoadSeg] Loading '%s'...\n", name
));
165 SetVBuf(file
, NULL
, BUF_FULL
, 4096);
166 segs
= InternalLoadSeg(file
, BNULL
, FunctionArray
, NULL
);
167 /* We cache the IoErr(), since Close() will alter it */
171 bug("[LoadSeg] Failed to load '%s'\n", name
));
172 #if (AROS_FLAVOUR & AROS_FLAVOUR_BINCOMPAT)
173 /* overlayed executables return -segs and handle must not be closed */
177 segs
= (BPTR
)-((LONG
)segs
);
184 bug("[LoadSeg] Failed to open '%s'\n", name
));