2 #include <l4/l4re_vfs/vfs.h>
3 #include <l4/sys/kdebug.h>
6 using namespace L4Re::Vfs;
9 #define L4RE_CALL(call...) \
10 extern "C" attribute_hidden call; \
11 extern "C" attribute_hidden call
13 extern "C" attribute_hidden int _dl_open(char const *path, int flags, int mode);
14 extern "C" attribute_hidden int _dl_close(int fd);
15 extern "C" attribute_hidden L4Re::Vfs::Ops *__rtld_l4re_env_posix_vfs_ops;
17 #define L4RE_VFS __rtld_l4re_env_posix_vfs_ops
21 _dl_convert_stat(struct stat *buf, struct stat64 const &s)
23 buf->st_dev = s.st_dev;
24 buf->st_ino = s.st_ino;
25 buf->st_mode = s.st_mode;
26 buf->st_nlink = s.st_nlink;
27 buf->st_uid = s.st_uid;
28 buf->st_gid = s.st_gid;
29 buf->st_size = s.st_size;
32 L4RE_CALL(int _dl_stat(const char *p, struct stat *buf))
35 int res = L4RE_VFS->get_root()->openat(p, 0, 0, &f);
46 _dl_convert_stat(buf, s);
51 L4RE_CALL(int _dl_fstat(int fd, struct stat *buf))
53 Ref_ptr<File> f = L4RE_VFS->get_file(fd);
59 int res = f->fstat64(&s);
64 _dl_convert_stat(buf, s);
69 L4RE_CALL(int _dl_read(int fd, void *buf, size_t len))
71 Ref_ptr<File> f = L4RE_VFS->get_file(fd);
80 outstring("### DL: read: "); outhex32(fd); outstring("\n");
82 int res = f->readv(&v, 1);
87 L4RE_CALL(int _dl_close(int fd))
89 Ref_ptr<File> f = L4RE_VFS->free_fd(fd);
93 f->unlock_all_locks();
98 L4RE_CALL(int _dl_open(char const *path, int flags, int mode))
99 { //outstring("### DL: open: '"); outstring(path); outstring ("'\n");
101 if (!_dl_init_auxvp())
103 return __rtld_l4re_env_posix_vfs_ops->open(path, flags, mode);
107 int res = L4RE_VFS->get_root()->openat(path, flags, mode, &f);
112 int fd = L4RE_VFS->alloc_fd(f);
117 L4RE_CALL(int _dl_write(int fd, char const *str, size_t len))
119 Ref_ptr<File> f = L4RE_VFS->get_file(fd);
126 v.iov_base = (char*)str;
131 int res = f->writev(&v, 1);
137 L4RE_CALL(int _dl_mprotect(void const *addr, size_t len, int prot))
139 return L4RE_VFS->mprotect((void *)addr, len, prot);
145 L4RE_CALL(int _dl_munmap(void *start, size_t len))
147 return L4RE_VFS->munmap(start, len);
150 L4RE_CALL(void *_dl_mmap(void *start, size_t len, int prot, int flags, int fd, off_t offset))
153 outstring("### DL: _dl_mmap(");
154 outhex32((int)start); outstring(", ");
155 outhex32((int)len); outstring(", ");
156 outhex32((int)prot); outstring(", ");
157 outhex32((int)flags); outstring(", ");
158 outhex32((int)fd); outstring(", ");
159 outhex32((int)offset); outstring("); from=");
160 outhex32((int)__builtin_return_address(0)); outstring("\n");
163 int res = L4RE_VFS->mmap2(start, len, prot, flags, fd, offset >> 12, &resptr);