2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
5 Desc: DOS function LoadSeg()
9 #include <aros/asmcall.h>
10 #include <aros/config.h>
12 #include <dos/stdio.h>
13 #include <proto/dos.h>
14 #include <aros/debug.h>
15 #include "dos_intern.h"
17 static AROS_UFH4(LONG
, ReadFunc
,
18 AROS_UFHA(BPTR
, file
, D1
),
19 AROS_UFHA(APTR
, buffer
, D2
),
20 AROS_UFHA(LONG
, length
, D3
),
21 AROS_UFHA(struct DosLibrary
*, DOSBase
, A6
)
26 return FRead(file
, buffer
, 1, length
);
31 static AROS_UFH4(LONG
, SeekFunc
,
32 AROS_UFHA(BPTR
, file
, D1
),
33 AROS_UFHA(LONG
, pos
, D2
),
34 AROS_UFHA(LONG
, mode
, D3
),
35 AROS_UFHA(struct DosLibrary
*, DOSBase
, A6
)
40 return Seek(file
, pos
, mode
);
46 static AROS_UFH3(APTR
, AllocFunc
,
47 AROS_UFHA(ULONG
, length
, D0
),
48 AROS_UFHA(ULONG
, flags
, D1
),
49 AROS_UFHA(struct ExecBase
*, SysBase
, A6
)
54 return AllocMem(length
, flags
);
59 static AROS_UFH3(void, FreeFunc
,
60 AROS_UFHA(APTR
, buffer
, A1
),
61 AROS_UFHA(ULONG
, length
, D0
),
62 AROS_UFHA(struct ExecBase
*, SysBase
, A6
)
67 FreeMem(buffer
, length
);
72 /*****************************************************************************
75 #include <proto/dos.h>
77 AROS_LH1(BPTR
, LoadSeg
,
80 AROS_LHA(CONST_STRPTR
, name
, D1
),
83 struct DosLibrary
*, DOSBase
, 25, Dos
)
86 Loads an executable file into memory. Each hunk of the loadfile
87 is loaded into its own memory section and a handle on all of them
88 is returned. The segments can be freed with UnLoadSeg().
91 name - NUL terminated name of the file.
94 Handle to the loaded executable or NULL if the load failed.
95 IoErr() gives additional information in that case.
98 This function is built on top of InternalLoadSeg()
109 *****************************************************************************/
115 LONG_FUNC FunctionArray
[] = {
117 (LONG_FUNC
)AllocFunc
,
119 (LONG_FUNC
)SeekFunc
, /* Only needed for ELF */
123 D(bug("[LoadSeg] Opening '%s'...\n", name
));
124 file
= Open (name
, MODE_OLDFILE
);
128 D(bug("[LoadSeg] Loading '%s'...\n", name
));
130 SetVBuf(file
, NULL
, BUF_FULL
, 4096);
131 segs
= InternalLoadSeg(file
, BNULL
, FunctionArray
, NULL
);
132 /* We cache the IoErr(), since Close() will alter it */
136 bug("[LoadSeg] Failed to load '%s'\n", name
));
137 #if (AROS_FLAVOUR & AROS_FLAVOUR_BINCOMPAT)
138 /* overlayed executables return -segs and handle must not be closed */
142 segs
= (BPTR
)-((LONG
)segs
);
149 D(bug("[LoadSeg] Returns '%p', IoErr=%d\n", segs
, IoErr()));