2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
6 #include "unix_hints.h"
8 #ifdef HOST_LONG_ALIGNED
16 #include <sys/types.h>
20 /* This prevents redefinition of struct timeval */
21 #define _AROS_TYPES_TIMEVAL_S_H_
23 #include <aros/debug.h>
24 #include <aros/symbolsets.h>
25 #include <dos/dosasl.h>
26 #include <utility/date.h>
27 #include <proto/dos.h>
28 #include <proto/exec.h>
29 #include <proto/hostlib.h>
30 #include <proto/oop.h>
31 #include <proto/utility.h>
33 #include "emul_intern.h"
34 #include "emul_unix.h"
36 #define NO_CASE_SENSITIVITY
38 #ifdef DEBUG_INTERFACE
39 #define DUMP_INTERFACE \
42 APTR *iface = (APTR *)emulbase->pdata.SysIFace; \
44 for (i = 0; libcSymbols[i]; i++) \
45 bug("%s\t\t0x%p\n", libcSymbols[i], iface[i]); \
48 #define DUMP_INTERFACE
51 static const char *libcSymbols
[] =
53 "open" UNIX2003_SUFFIX
,
54 "close" UNIX2003_SUFFIX
,
55 "closedir" UNIX2003_SUFFIX
,
56 "opendir" UNIX2003_SUFFIX
,
57 "readdir" INODE64_SUFFIX
,
58 "rewinddir" UNIX2003_SUFFIX
,
59 "read" UNIX2003_SUFFIX
,
60 "write" UNIX2003_SUFFIX
,
70 "chmod" UNIX2003_SUFFIX
,
75 "mktime" UNIX2003_SUFFIX
,
78 "poll" UNIX2003_SUFFIX
,
83 "stat" INODE64_SUFFIX
,
84 "lstat" INODE64_SUFFIX
,
86 #ifndef HOST_OS_android
87 "seekdir" UNIX2003_SUFFIX
,
88 "telldir" UNIX2003_SUFFIX
,
95 /*********************************************************************************************/
97 static inline struct filehandle
*CreateStdHandle(int fd
)
99 struct filehandle
*fh
;
101 fh
= AllocMem(sizeof(struct filehandle
), MEMF_PUBLIC
|MEMF_CLEAR
);
104 fh
->type
= FHD_FILE
|FHD_STDIO
;
105 fh
->fd
= (void *)(IPTR
)fd
;
111 static int host_startup(struct emulbase
*emulbase
)
115 OOPBase
= OpenLibrary("oop.library", 0);
119 UtilityBase
= OpenLibrary("utility.library", 0);
120 D(bug("[EmulHandler] UtilityBase = %p\n", UtilityBase
));
124 emulbase
->pdata
.em_UnixIOBase
= (struct UnixIOBase
*)OpenLibrary("unixio.hidd", 43);
125 if (!emulbase
->pdata
.em_UnixIOBase
)
128 emulbase
->pdata
.unixio
= OOP_NewObject(NULL
, CLID_Hidd_UnixIO
, NULL
);
129 if (!emulbase
->pdata
.unixio
)
132 emulbase
->pdata
.SysIFace
= (struct LibCInterface
*)HostLib_GetInterface(emulbase
->pdata
.em_UnixIOBase
->uio_LibcHandle
, libcSymbols
, &r
);
133 if (!emulbase
->pdata
.SysIFace
)
135 D(bug("[EmulHandler] Unable to get host-side library interface!\n"));
136 CloseLibrary(UtilityBase
);
140 D(bug("[EmulHandler] %lu unresolved symbols\n", r
));
144 CloseLibrary(UtilityBase
);
148 /* Cache errno pointer for faster access */
149 emulbase
->pdata
.errnoPtr
= emulbase
->pdata
.em_UnixIOBase
->uio_ErrnoPtr
;
151 /* Create handles for emergency console */
152 emulbase
->eb_stdin
= CreateStdHandle(STDIN_FILENO
);
153 emulbase
->eb_stdout
= CreateStdHandle(STDOUT_FILENO
);
154 emulbase
->eb_stderr
= CreateStdHandle(STDERR_FILENO
);
159 ADD2INITLIB(host_startup
, 0);
161 static int host_cleanup(struct emulbase
*emulbase
)
163 D(bug("[EmulHandler] Expunge\n"));
165 if (emulbase
->pdata
.SysIFace
)
166 HostLib_DropInterface((APTR
*)emulbase
->pdata
.SysIFace
);
168 /* UnixIO v42 object is a singletone, we don't need to dispose it */
170 CloseLibrary(OOPBase
);
171 CloseLibrary(&emulbase
->pdata
.em_UnixIOBase
->uio_Library
);
172 CloseLibrary(UtilityBase
);
177 ADD2EXPUNGELIB(host_cleanup
, 0);