Skip to content

Commit 1132711

Browse files
committed
add stat->st_mode h2t conversion
1 parent eda8972 commit 1132711

File tree

2 files changed

+79
-3
lines changed

2 files changed

+79
-3
lines changed

darwin-user/syscall.c

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7219,11 +7219,46 @@ static inline int target_to_host_mlockall_arg(int arg)
72197219
}
72207220
#endif
72217221

7222+
static const bitmask_transtbl st_mode_tlb[] = {
7223+
{ TARGET_S_IFMT, TARGET_S_IFIFO, S_IFMT, S_IFIFO },
7224+
{ TARGET_S_IFMT, TARGET_S_IFCHR, S_IFMT, S_IFCHR },
7225+
{ TARGET_S_IFMT, TARGET_S_IFDIR, S_IFMT, S_IFDIR },
7226+
{ TARGET_S_IFMT, TARGET_S_IFBLK, S_IFMT, S_IFBLK },
7227+
{ TARGET_S_IFMT, TARGET_S_IFREG, S_IFMT, S_IFREG },
7228+
{ TARGET_S_IFMT, TARGET_S_IFLNK, S_IFMT, S_IFLNK },
7229+
{ TARGET_S_IFMT, TARGET_S_IFSOCK, S_IFMT, S_IFSOCK },
7230+
#ifdef S_IFNAM
7231+
{ TARGET_S_IFMT, TARGET_S_IFNAM, S_IFMT, S_IFNAM },
7232+
#endif
7233+
{ TARGET_S_ISUID, TARGET_S_ISUID, S_ISUID, S_ISUID },
7234+
{ TARGET_S_ISGID, TARGET_S_ISGID, S_ISGID, S_ISGID },
7235+
{ TARGET_S_ISVTX, TARGET_S_ISVTX, S_ISVTX, S_ISVTX },
7236+
7237+
{ TARGET_S_IREAD, TARGET_S_IREAD, S_IREAD, S_IREAD },
7238+
{ TARGET_S_IWRITE, TARGET_S_IWRITE, S_IWRITE, S_IWRITE },
7239+
{ TARGET_S_IEXEC, TARGET_S_IEXEC, S_IEXEC, S_IEXEC },
7240+
{ TARGET_S_ENFMT, TARGET_S_ENFMT, S_ISGID, S_ISGID },
7241+
{ TARGET_S_IRWXU, TARGET_S_IRWXU, S_IRWXU, S_IRWXU },
7242+
{ TARGET_S_IRWXU, TARGET_S_IRUSR, S_IRWXU, S_IRUSR },
7243+
{ TARGET_S_IRWXU, TARGET_S_IWUSR, S_IRWXU, S_IWUSR },
7244+
{ TARGET_S_IRWXU, TARGET_S_IXUSR, S_IRWXU, S_IXUSR },
7245+
{ TARGET_S_IRWXG, TARGET_S_IRWXG, S_IRWXG, S_IRWXG },
7246+
{ TARGET_S_IRWXG, TARGET_S_IRGRP, S_IRWXG, S_IRGRP },
7247+
{ TARGET_S_IRWXG, TARGET_S_IWGRP, S_IRWXG, S_IWGRP },
7248+
{ TARGET_S_IRWXG, TARGET_S_IXGRP, S_IRWXG, S_IXGRP },
7249+
{ TARGET_S_IRWXO, TARGET_S_IRWXO, S_IRWXO, S_IRWXO },
7250+
{ TARGET_S_IRWXO, TARGET_S_IROTH, S_IRWXO, S_IROTH },
7251+
{ TARGET_S_IRWXO, TARGET_S_IWOTH, S_IRWXO, S_IWOTH },
7252+
{ TARGET_S_IRWXO, TARGET_S_IXOTH, S_IRWXO, S_IXOTH },
7253+
{ 0, 0, 0, 0 },
7254+
};
7255+
72227256
static inline abi_long host_to_target_stat(void *cpu_env,
72237257
abi_ulong target_addr,
72247258
struct stat *host_st)
72257259
{
72267260
struct target_stat *target_st;
7261+
int cnvt_st_mode = host_to_target_bitmask(host_st->st_mode, st_mode_tlb);
72277262

72287263
if (!lock_user_struct(VERIFY_WRITE, target_st, target_addr, 0))
72297264
return -TARGET_EFAULT;
@@ -7235,7 +7270,7 @@ static inline abi_long host_to_target_stat(void *cpu_env,
72357270
#endif
72367271
__put_user(host_st->st_dev, &target_st->st_dev);
72377272
__put_user(host_st->st_ino, &target_st->st_ino);
7238-
__put_user(host_st->st_mode, &target_st->st_mode);
7273+
__put_user(cnvt_st_mode, &target_st->st_mode);
72397274
__put_user(host_st->st_uid, &target_st->st_uid);
72407275
__put_user(host_st->st_gid, &target_st->st_gid);
72417276
__put_user(host_st->st_nlink, &target_st->st_nlink);

darwin-user/syscall_defs.h

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,7 +1929,7 @@ struct target_stat {
19291929
uint32_t st_rdev;
19301930
abi_long st_pad1[2]; /* Reserved for st_rdev expansion */
19311931
abi_long st_size;
1932-
abi_long st_pad2;
1932+
abi_long st_pad2;
19331933

19341934
/*
19351935
* Actually this should be timestruc_t st_atime, st_mtime and st_ctime
@@ -1944,7 +1944,7 @@ struct target_stat {
19441944
int32_t target_st_ctime;
19451945
abi_long target_st_ctime_nsec;
19461946

1947-
abi_long st_blksize;
1947+
abi_long st_blksize;
19481948
abi_long st_blocks;
19491949
char st_fstype[16];
19501950
abi_long st_projid;
@@ -3451,4 +3451,45 @@ struct target_prthread {
34513451
#define TARGET_PC_SYNC_IO 10
34523452
#endif
34533453

3454+
/* stat st_mode flags */
3455+
#ifdef TARGET_ABI_IRIX
3456+
/* masks */
3457+
#define TARGET_S_IFMT 0xF000 /* type of file */
3458+
#define TARGET_S_IAMB 0x1FF /* access mode bits */
3459+
3460+
#define TARGET_S_IFIFO 0x1000 /* fifo */
3461+
#define TARGET_S_IFCHR 0x2000 /* character special */
3462+
#define TARGET_S_IFDIR 0x4000 /* directory */
3463+
#define TARGET_S_IFNAM 0x5000 /* XENIX special named file */
3464+
#define TARGET_S_INSEM 0x1 /* XENIX semaphore subtype of IFNAM */
3465+
#define TARGET_S_INSHD 0x2 /* XENIX shared data subtype of IFNAM */
3466+
#define TARGET_S_IFBLK 0x6000 /* block special */
3467+
#define TARGET_S_IFREG 0x8000 /* regular */
3468+
#define TARGET_S_IFLNK 0xA000 /* symbolic link */
3469+
#define TARGET_S_IFSOCK 0xC000 /* socket */
3470+
3471+
#define TARGET_S_ISUID 0x800 /* set user id on execution */
3472+
#define TARGET_S_ISGID 0x400 /* set group id on execution */
3473+
#define TARGET_S_ISVTX 0x200 /* save swapped text even after use */
3474+
3475+
#define TARGET_S_IREAD 00400 /* read permission, owner */
3476+
#define TARGET_S_IWRITE 00200 /* write permission, owner */
3477+
#define TARGET_S_IEXEC 00100 /* execute/search permission, owner */
3478+
#define TARGET_S_ENFMT S_ISGID /* record locking enforcement flag */
3479+
3480+
#define TARGET_S_IRWXU 00700 /* read, write, execute: owner */
3481+
#define TARGET_S_IRUSR 00400 /* read permission: owner */
3482+
#define TARGET_S_IWUSR 00200 /* write permission: owner */
3483+
#define TARGET_S_IXUSR 00100 /* execute permission: owner */
3484+
#define TARGET_S_IRWXG 00070 /* read, write, execute: group */
3485+
#define TARGET_S_IRGRP 00040 /* read permission: group */
3486+
#define TARGET_S_IWGRP 00020 /* write permission: group */
3487+
#define TARGET_S_IXGRP 00010 /* execute permission: group */
3488+
#define TARGET_S_IRWXO 00007 /* read, write, execute: other */
3489+
#define TARGET_S_IROTH 00004 /* read permission: other */
3490+
#define TARGET_S_IWOTH 00002 /* write permission: other */
3491+
#define TARGET_S_IXOTH 00001 /* execute permission: other */
3492+
3493+
#endif /* TARGET_ABI_IRIX */
3494+
34543495
#endif

0 commit comments

Comments
 (0)