Skip to content

Commit 384cb9a

Browse files
committed
Fix compilation issue with loongarch64-linux-gnu
Support loongaarch64 architecture
1 parent 4b983ce commit 384cb9a

File tree

2 files changed

+34
-21
lines changed

2 files changed

+34
-21
lines changed

include/fast_io_hosted/filesystem/posix_at.h

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ namespace posix
88
extern int libc_faccessat(int dirfd,char const* pathname,int mode, int flags) noexcept __asm__("faccessat");
99
extern int libc_renameat(int olddirfd,char const* oldpath,int newdirfd, char const* newpath) noexcept __asm__("renameat");
1010
extern int libc_linkat(int olddirfd,char const* oldpath,int newdirfd, char const* newpath,int flags) noexcept __asm__("linkat");
11-
extern int libc_symlinkat(char const* oldpath, int newdirfd, char const *newpath) noexcept __asm__("symlinkat");
12-
extern int libc_fchmodat(int dirfd, char const *pathname, mode_t mode, int flags) noexcept __asm__("fchmodat");
13-
extern int libc_utimensat(int dirfd, char const *pathname,struct timespec const* times, int flags) noexcept __asm__("utimensat");
14-
extern int libc_fchownat(int dirfd, char const *pathname,uid_t owner, gid_t group, int flags) noexcept __asm__("fchownat");
15-
extern int libc_fstatat(int dirfd, char const *pathname, struct stat *buf,int flags) noexcept __asm__("fstatat");
11+
extern int libc_symlinkat(char const* oldpath, int newdirfd, char const* newpath) noexcept __asm__("symlinkat");
12+
extern int libc_fchmodat(int dirfd, char const* pathname, mode_t mode, int flags) noexcept __asm__("fchmodat");
13+
extern int libc_utimensat(int dirfd, char const* pathname,struct timespec const* times, int flags) noexcept __asm__("utimensat");
14+
extern int libc_fchownat(int dirfd, char const* pathname,uid_t owner, gid_t group, int flags) noexcept __asm__("fchownat");
15+
extern int libc_fstatat(int dirfd, char const* pathname, struct stat *buf,int flags) noexcept __asm__("fstatat");
1616
extern int libc_mkdirat(int dirfd, char const* pathname, mode_t mode) noexcept __asm__("mkdirat");
1717
extern int libc_mknodat(int dirfd, char const* pathname, mode_t mode, dev_t dev) noexcept __asm__("mknodat");
1818
extern int libc_unlinkat(int dirfd, char const*pathname, int flags) noexcept __asm__("unlinkat");
19-
extern int libc_readlinkat(int dirfd, char const *pathname,char *buf, std::size_t bufsiz) noexcept __asm__("readlinkat");
19+
extern int libc_readlinkat(int dirfd, char const* pathname,char *buf, std::size_t bufsiz) noexcept __asm__("readlinkat");
2020
}
2121

2222
namespace details
@@ -76,7 +76,7 @@ inline auto posix12_api_dispatcher(char const* oldpath,
7676
}
7777
}
7878

79-
inline void posix_faccessat_impl(int dirfd, char const *pathname, int mode, int flags)
79+
inline void posix_faccessat_impl(int dirfd, char const* pathname, int mode, int flags)
8080
{
8181
system_call_throw_error(
8282
#if defined(__linux__) && defined(__NR_faccessat2)
@@ -90,12 +90,12 @@ inline void posix_faccessat_impl(int dirfd, char const *pathname, int mode, int
9090
}
9191

9292
#if defined(__wasi__) && !defined(__wasilibc_unmodified_upstream)
93-
inline void posix_fchownat_impl(int, const char *, uintmax_t, uintmax_t, int)
93+
inline void posix_fchownat_impl(int, char const* , uintmax_t, uintmax_t, int)
9494
{
9595
throw_posix_error(ENOTSUP);
9696
}
9797
#else
98-
inline void posix_fchownat_impl(int dirfd, const char *pathname, uintmax_t owner, uintmax_t group, int flags)
98+
inline void posix_fchownat_impl(int dirfd, char const* pathname, uintmax_t owner, uintmax_t group, int flags)
9999
{
100100
if constexpr(sizeof(uintmax_t)>sizeof(uid_t))
101101
{
@@ -120,12 +120,12 @@ inline void posix_fchownat_impl(int dirfd, const char *pathname, uintmax_t owner
120120
#endif
121121

122122
#if defined(__wasi__) && !defined(__wasilibc_unmodified_upstream)
123-
inline void posix_fchmodat_impl(int, const char *, mode_t, int)
123+
inline void posix_fchmodat_impl(int, char const* , mode_t, int)
124124
{
125125
throw_posix_error(ENOTSUP);
126126
}
127127
#else
128-
inline void posix_fchmodat_impl(int dirfd, const char *pathname, mode_t mode, int flags)
128+
inline void posix_fchmodat_impl(int dirfd, char const* pathname, mode_t mode, int flags)
129129
{
130130
system_call_throw_error(
131131
#if defined(__linux__)
@@ -137,30 +137,42 @@ inline void posix_fchmodat_impl(int dirfd, const char *pathname, mode_t mode, in
137137
}
138138
#endif
139139

140-
inline posix_file_status posix_fstatat_impl(int dirfd, const char *pathname, int flags)
140+
inline posix_file_status posix_fstatat_impl(int dirfd, char const* pathname, int flags)
141141
{
142-
#if defined(__linux__) && !defined(__MLIBC_O_CLOEXEC)
142+
#if defined(__linux__)
143+
144+
#if !defined(__MLIBC_O_CLOEXEC) && (defined(__NR_newfstatat) || defined(__NR_fstatat64))
143145
struct stat64 buf;
144146
#else
145147
struct stat buf;
146148
#endif
149+
#if defined(__NR_newfstatat) || defined(__NR_fstatat64) || defined(__NR_fstatat)
147150
system_call_throw_error(
148-
#if defined(__linux__)
149151
system_call<
150152
#if defined(__NR_newfstatat)
151153
__NR_newfstatat
152-
#else
154+
#elif defined(__NR_fstatat64)
153155
__NR_fstatat64
156+
#else
157+
__NR_fstatat
154158
#endif
155-
,int>
159+
,int>(dirfd,pathname,__builtin_addressof(buf),flags));
160+
156161
#else
157-
::fast_io::posix::libc_fstatat
162+
if((::fast_io::posix::libc_fstatat(dirfd,pathname,__builtin_addressof(buf),flags)) < 0)
163+
{
164+
throw_posix_error();
165+
}
166+
#endif
167+
168+
#else
169+
struct stat buf;
170+
system_call_throw_error(::fast_io::posix::libc_fstatat(dirfd,pathname,__builtin_addressof(buf),flags));
158171
#endif
159-
(dirfd,pathname,__builtin_addressof(buf),flags));
160172
return struct_stat_to_posix_file_status(buf);
161173
}
162174

163-
inline void posix_mkdirat_impl(int dirfd, const char *pathname, mode_t mode)
175+
inline void posix_mkdirat_impl(int dirfd, char const* pathname, mode_t mode)
164176
{
165177
system_call_throw_error(
166178
#if defined(__linux__)
@@ -174,13 +186,13 @@ inline void posix_mkdirat_impl(int dirfd, const char *pathname, mode_t mode)
174186
}
175187
#if 0
176188
#if (defined(__wasi__) && !defined(__wasilibc_unmodified_upstream)) || defined(__DARWIN_C_LEVEL)
177-
inline void posix_mknodat_impl(int, const char *, mode_t,std::uintmax_t)
189+
inline void posix_mknodat_impl(int, char const* , mode_t,std::uintmax_t)
178190
{
179191
throw_posix_error(ENOTSUP);
180192
}
181193
#else
182194

183-
inline void posix_mknodat_impl(int dirfd, const char *pathname, mode_t mode,std::uintmax_t dev)
195+
inline void posix_mknodat_impl(int dirfd, char const* pathname, mode_t mode,std::uintmax_t dev)
184196
{
185197
if constexpr(sizeof(std::uintmax_t)>sizeof(dev_t))
186198
{

support.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- mips-abi64
2525
- avr
2626
- ia64
27+
- loongarch64
2728
- All other architectures should work, they just aren't tested due to time not being infinite.
2829

2930
## Platform Support

0 commit comments

Comments
 (0)