~aleteoryx/muditaos

0a6799579e6932b3d2203b5fe30caee68883a642 — Dawid Wojtas 3 years ago 022b633
[MOS-534] Pure simulator crashes on startup fix

Fix missing syscall used by std::filesystem and update glibc version.txt
file.
M board/linux/libiosyscalls/src/syscalls_posix_dirent.cpp => board/linux/libiosyscalls/src/syscalls_posix_dirent.cpp +29 -3
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "iosyscalls-internal.hpp"


@@ 7,6 7,8 @@
#include <errno.h>
#include <cstring>
#include <sys/stat.h>
#include <fcntl.h>
#include <bits/fcntl2.h>

#include "syscalls_real.hpp"



@@ 24,6 26,7 @@ namespace
    namespace real
    {
        __REAL_DECL(opendir);
        __REAL_DECL(__openat_2);
        __REAL_DECL(closedir);
        __REAL_DECL(readdir);
#pragma GCC diagnostic push


@@ 38,6 41,7 @@ namespace
    void __attribute__((constructor)) _lib_posix_dirent_initialize()
    {
        __REAL_DLSYM(opendir);
        __REAL_DLSYM(__openat_2);
        __REAL_DLSYM(closedir);
        __REAL_DLSYM(readdir);
        __REAL_DLSYM(readdir_r);


@@ 45,8 49,8 @@ namespace
        __REAL_DLSYM(seekdir);
        __REAL_DLSYM(telldir);

        if (!(real::opendir && real::closedir && real::readdir && real::readdir_r && real::rewinddir && real::seekdir &&
              real::telldir)) {
        if (!(real::opendir && real::__openat_2 && real::closedir && real::readdir && real::readdir_r &&
              real::rewinddir && real::seekdir && real::telldir)) {
            abort();
        }
    }


@@ 105,6 109,28 @@ extern "C"
    }
    __asm__(".symver _iosys_opendir,opendir@GLIBC_2.2.5");

    int _iosys__openat_2(int fd, const char *dirname, int flags)
    {
        int ret;
        if (!dirname) {
            TRACE_SYSCALLN("(%p) invalid argument", dirname);
            errno = EINVAL;
            return -1;
        }
        if (vfs::redirect_to_image(dirname)) {
            std::cerr << "Unsupported syscall " << __PRETTY_FUNCTION__ << std::endl;
        }
        else {
            char tmp[PATH_MAX];
            const auto newpath = vfs::npath_translate(dirname, tmp);
            TRACE_SYSCALLN("(%s) -> (%s) linux fs", dirname, newpath);
            ret = real::__openat_2(fd, newpath, flags);
        }
        TRACE_SYSCALLN("(%s)=%p errno=%i", dirname, ret, errno);
        return ret;
    }
    __asm__(".symver _iosys__openat_2,__openat_2@GLIBC_2.7");

    int _iosys_closedir(DIR *dirp)
    {
        int ret{};

M board/linux/libiosyscalls/version.txt => board/linux/libiosyscalls/version.txt +4 -0
@@ 85,6 85,10 @@ GLIBC_2.4 {
                __fxstatat;
                __fxstatat64;
};
GLIBC_2.7 {
        global:
                __openat_2;             
};
GLIBC_2.33 {
        global:
                stat;