Skip to content

Commit 4bc1d75

Browse files
committed
Add support for arm64 architecture
1 parent 4700f99 commit 4bc1d75

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

lfs_ffi.lua

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,49 @@ if OS == 'Linux' then
909909
lstat_syscall_num = IS_64_BIT and 4107 or 4214
910910
end
911911

912-
if stat_syscall_num then
912+
if ARCH == 'arm64' then
913+
ffi.cdef([[
914+
typedef struct {
915+
unsigned long st_dev;
916+
unsigned long st_ino;
917+
unsigned int st_mode;
918+
unsigned int st_nlink;
919+
unsigned int st_uid;
920+
unsigned int st_gid;
921+
unsigned long st_rdev;
922+
unsigned long __pad1;
923+
long st_size;
924+
int st_blksize;
925+
int __pad2;
926+
long st_blocks;
927+
long st_atime;
928+
unsigned long st_atime_nsec;
929+
long st_mtime;
930+
unsigned long st_mtime_nsec;
931+
long st_ctime;
932+
unsigned long st_ctime_nsec;
933+
unsigned int __unused4;
934+
unsigned int __unused5;
935+
} stat;
936+
]])
937+
938+
local STAT = {
939+
_AT_FDCWD = -0x64,
940+
_AT_REMOVEDIR = 0x200,
941+
_AT_SYMLINK_NOFOLLOW = 0x100,
942+
_AT_EACCESS = 0x200,
943+
}
944+
945+
-- On arm64 stat and lstat do not exist as syscall, so use newfstatat instead
946+
-- int newfstatat(int dirfd, const char *filename, struct stat *statbuf, int flags)
947+
stat_func = function(filepath, buf)
948+
return lib.syscall(79, STAT._AT_FDCWD, filepath, buf, 0)
949+
end
950+
lstat_func = function(filepath, buf)
951+
return lib.syscall(79, STAT._AT_FDCWD, filepath, buf, STAT._AT_SYMLINK_NOFOLLOW)
952+
end
953+
954+
elseif stat_syscall_num then
913955
stat_func = function(filepath, buf)
914956
return lib.syscall(stat_syscall_num, filepath, buf)
915957
end

0 commit comments

Comments
 (0)