2 Copyright © 1995-2015, 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
,
84 "stat" INODE64_SUFFIX
,
85 "lstat" INODE64_SUFFIX
,
86 "fstat" INODE64_SUFFIX
,
88 #ifndef HOST_OS_android
89 "seekdir" UNIX2003_SUFFIX
,
90 "telldir" UNIX2003_SUFFIX
,
97 /*********************************************************************************************/
99 static inline struct filehandle
*CreateStdHandle(int fd
)
101 struct filehandle
*fh
;
103 fh
= AllocMem(sizeof(struct filehandle
), MEMF_PUBLIC
|MEMF_CLEAR
);
106 fh
->type
= FHD_FILE
|FHD_STDIO
;
107 fh
->fd
= (void *)(IPTR
)fd
;
113 static int host_startup(struct emulbase
*emulbase
)
117 OOPBase
= OpenLibrary("oop.library", 0);
121 UtilityBase
= OpenLibrary("utility.library", 0);
122 D(bug("[EmulHandler] UtilityBase = %p\n", UtilityBase
));
126 emulbase
->pdata
.em_UnixIOBase
= (struct UnixIOBase
*)OpenLibrary("unixio.hidd", 43);
127 if (!emulbase
->pdata
.em_UnixIOBase
)
130 emulbase
->pdata
.unixio
= OOP_NewObject(NULL
, CLID_Hidd_UnixIO
, NULL
);
131 if (!emulbase
->pdata
.unixio
)
134 emulbase
->pdata
.SysIFace
= (struct LibCInterface
*)HostLib_GetInterface(emulbase
->pdata
.em_UnixIOBase
->uio_LibcHandle
, libcSymbols
, &r
);
135 if (!emulbase
->pdata
.SysIFace
)
137 D(bug("[EmulHandler] Unable to get host-side library interface!\n"));
138 CloseLibrary(UtilityBase
);
142 D(bug("[EmulHandler] %lu unresolved symbols\n", r
));
146 CloseLibrary(UtilityBase
);
150 /* Cache errno pointer for faster access */
151 emulbase
->pdata
.errnoPtr
= emulbase
->pdata
.em_UnixIOBase
->uio_ErrnoPtr
;
153 /* Create handles for emergency console */
154 emulbase
->eb_stdin
= CreateStdHandle(STDIN_FILENO
);
155 emulbase
->eb_stdout
= CreateStdHandle(STDOUT_FILENO
);
156 emulbase
->eb_stderr
= CreateStdHandle(STDERR_FILENO
);
161 ADD2INITLIB(host_startup
, 0);
163 static int host_cleanup(struct emulbase
*emulbase
)
165 D(bug("[EmulHandler] Expunge\n"));
167 if (emulbase
->pdata
.SysIFace
)
168 HostLib_DropInterface((APTR
*)emulbase
->pdata
.SysIFace
);
170 /* UnixIO v42 object is a singletone, we don't need to dispose it */
172 CloseLibrary(OOPBase
);
173 CloseLibrary(&emulbase
->pdata
.em_UnixIOBase
->uio_Library
);
174 CloseLibrary(UtilityBase
);
179 ADD2EXPUNGELIB(host_cleanup
, 0);