Skip to content

Commit c67c538

Browse files
committed
Add LinuxRISCVStat
1 parent 208eddd commit c67c538

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

qiling/os/posix/syscall/stat.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,56 @@ class LinuxARM64EBStat(ctypes.BigEndianStructure):
717717

718718
_pack_ = 8
719719

720+
# Srouce: https://github.com/riscv-collab/riscv-gnu-toolchain/blob/master/linux-headers/include/asm-generic/stat.h
721+
# struct stat {
722+
# unsigned long st_dev; /* Device. */
723+
# unsigned long st_ino; /* File serial number. */
724+
# unsigned int st_mode; /* File mode. */
725+
# unsigned int st_nlink; /* Link count. */
726+
# unsigned int st_uid; /* User ID of the file's owner. */
727+
# unsigned int st_gid; /* Group ID of the file's group. */
728+
# unsigned long st_rdev; /* Device number, if device. */
729+
# unsigned long __pad1;
730+
# long st_size; /* Size of file, in bytes. */
731+
# int st_blksize; /* Optimal block size for I/O. */
732+
# int __pad2;
733+
# long st_blocks; /* Number 512-byte blocks allocated. */
734+
# long st_atime; /* Time of last access. */
735+
# unsigned long st_atime_nsec;
736+
# long st_mtime; /* Time of last modification. */
737+
# unsigned long st_mtime_nsec;
738+
# long st_ctime; /* Time of last status change. */
739+
# unsigned long st_ctime_nsec;
740+
# unsigned int __unused4;
741+
# unsigned int __unused5;
742+
# };
743+
744+
class LinuxRISCVStat(ctypes.Structure):
745+
_fields_ = [
746+
("st_dev", ctypes.c_uint64),
747+
("st_ino", ctypes.c_uint64),
748+
("st_mode", ctypes.c_uint32),
749+
("st_nlink", ctypes.c_uint32),
750+
("st_uid", ctypes.c_uint32),
751+
("st_gid", ctypes.c_uint32),
752+
("st_rdev", ctypes.c_uint64),
753+
("__pad1", ctypes.c_uint64),
754+
("st_size", ctypes.c_int64),
755+
("st_blksize", ctypes.c_int32),
756+
("__pad2", ctypes.c_int32),
757+
("st_blocks", ctypes.c_int64),
758+
("st_atime", ctypes.c_int64),
759+
("st_atime_nsec", ctypes.c_uint64),
760+
("st_mtime", ctypes.c_int64),
761+
("st_mtime_nsec", ctypes.c_uint64),
762+
("st_ctime", ctypes.c_int64),
763+
("st_ctime_nsec", ctypes.c_uint64),
764+
("__unused4", ctypes.c_uint32),
765+
("__unused5", ctypes.c_uint32),
766+
]
767+
768+
_pack_ = 8
769+
720770
# Source: openqnx lib/c/public/sys/stat.h
721771
#
722772
# struct stat {
@@ -887,6 +937,8 @@ def get_stat64_struct(ql: Qiling):
887937
return LinuxMips32Stat64()
888938
elif ql.archtype in (QL_ARCH.ARM, QL_ARCH.ARM_THUMB):
889939
return LinuxARMStat64()
940+
elif ql.archtype in (QL_ARCH.RISCV, QL_ARCH.RISCV64):
941+
return LinuxRISCVStat()
890942
elif ql.ostype == QL_OS.MACOS:
891943
return MacOSStat64()
892944
elif ql.ostype == QL_OS.QNX:
@@ -922,6 +974,8 @@ def get_stat_struct(ql: Qiling):
922974
return LinuxARM64Stat()
923975
else:
924976
return LinuxARM64EBStat()
977+
elif ql.archtype in (QL_ARCH.RISCV, QL_ARCH.RISCV64):
978+
return LinuxRISCVStat()
925979
elif ql.ostype == QL_OS.QNX:
926980
if ql.archtype == QL_ARCH.ARM64:
927981
return QNXARM64Stat()

0 commit comments

Comments
 (0)