Skip to content

Commit bbd4558

Browse files
committed
correct getdents and add some more sgisysinfo defines
1 parent 25d6223 commit bbd4558

File tree

3 files changed

+55
-11
lines changed

3 files changed

+55
-11
lines changed

darwin-user/irix/syscall_nr.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,18 @@
349349
#define TARGET_NR_sysinfo_cpuarch 6
350350
#define TARGET_NR_sysinfo_hwserial 7
351351
#define TARGET_NR_sysinfo_hwproducer 8
352-
#define TARGET_NR_sysinfo_processors 109
353352

353+
#define TARGET_NR_sysinfo_mips_vendor 100 /* return system provider */
354+
#define TARGET_NR_sysinfo_mips_osprovider 101 /* return OS manufacturer */
355+
#define TARGET_NR_sysinfo_mips_osname 102 /* return OS name */
356+
#define TARGET_NR_sysinfo_mips_hwname 103 /* return system name */
357+
#define TARGET_NR_sysinfo_mips_numprocessor 104 /* return number of processors */
358+
#define TARGET_NR_sysinfo_mips_hostid 105 /* return hostid */
359+
#define TARGET_NR_sysinfo_mips_osrelmaj 106 /* return OS major release number */
360+
#define TARGET_NR_sysinfo_mips_osrelmin 107 /* return OS minor release number */
361+
#define TARGET_NR_sysinfo_mips_osrelpatch 108 /* return OS release number */
362+
#define TARGET_NR_sysinfo_mips_processors 109 /* return CPU revison id */
363+
#define TARGET_NR_sysinfo_mips_availprocessors 110 /* return number of available processors */
354364

355365
/* utssyssgi(obuf, ibuf, cmd) */
356366
#define TARGET_NR_utssys_uname (0)

darwin-user/strace.list

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,3 +1734,6 @@
17341734
#ifdef TARGET_NR_usync_cntl
17351735
{ TARGET_NR_usync_cntl, "usync_cntl", NULL, NULL, NULL },
17361736
#endif
1737+
#ifdef TARGET_NR_sysinfosgi
1738+
{ TARGET_NR_sysinfosgi, "sysinfosgi", NULL, NULL, NULL },
1739+
#endif

darwin-user/syscall.c

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10814,6 +10814,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
1081410814
// ret == bytes read, or target error code
1081510815

1081610816
dirp = fdopendir(dir_fd);
10817+
gemu_log("\n\tgetdents fdopendir: %p\n", dirp);
1081710818
if (!dirp) {
1081810819
ret = -host_to_target_errno(errno);
1081910820
goto fail;
@@ -10824,29 +10825,28 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
1082410825
ret = -TARGET_ENOMEM;
1082510826
goto fail;
1082610827
}
10828+
gemu_log("\n\tgetdents host_dirp: %p\n", host_dirp);
10829+
1082710830

1082810831
// collect readdir calls into getdents dirp * buffer
1082910832
target_dirp = lock_user(VERIFY_WRITE, arg2, count, 0);
1083010833
if (!target_dirp) {
1083110834
goto efault;
1083210835
}
10836+
gemu_log("\n\tgetdents target_dirp: %p\n", target_dirp);
10837+
1083310838

1083410839
struct dirent *de;
1083510840
struct target_dirent *tde = target_dirp;
1083610841
uint bytes_used = 0;
1083710842
uint target_reclen;
1083810843
uint name_len;
1083910844

10840-
for (;;) {
10841-
de = readdir(dirp);
10842-
if (!de) {
10843-
found_err = TRUE;
10844-
break;
10845-
}
10845+
while ((de = readdir(dirp))) {
1084610846
// check if new entry will overflow the target buffer
1084710847
name_len = de->d_namlen + 1;
1084810848
target_reclen = target_dirent_len + name_len;
10849-
// TODO -> QEMU_ALIGN_UP(target_reclen, alignof(struct target_dirent))?
10849+
// is this the correct way to align this structure..?
1085010850
target_reclen = QEMU_ALIGN_UP(target_reclen, __alignof(struct target_dirent));
1085110851
if (bytes_used + target_reclen > count) {
1085210852
break;
@@ -10868,8 +10868,9 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
1086810868
ret = bytes_used;
1086910869
}
1087010870
unlock_user(target_dirp, arg2, ret);
10871-
g_free(dirp);
10872-
// handle possible readdir errors here
10871+
// Don't close the `DIR *` pointer, as that will close the fd
10872+
// which was used in `fdopendir`
10873+
// closedir(dirp);
1087310874
}
1087410875
// Old Linux code
1087510876
// #ifdef __NR_getdents
@@ -14613,9 +14614,39 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
1461314614
strncpy(target_buf, "Qemu", arg3-1);
1461414615
break;
1461514616

14616-
case TARGET_NR_sysinfo_processors:
14617+
case TARGET_NR_sysinfo_mips_vendor:
14618+
strncpy(target_buf, "SGI", arg3-1);
14619+
break;
14620+
case TARGET_NR_sysinfo_mips_osprovider:
14621+
strncpy(target_buf, "Qemu", arg3-1);
14622+
break;
14623+
case TARGET_NR_sysinfo_mips_osname:
14624+
strncpy(target_buf, "IRIX", arg3-1);
14625+
break;
14626+
case TARGET_NR_sysinfo_mips_hwname:
14627+
strncpy(target_buf, "IP22", arg3-1);
14628+
break;
14629+
case TARGET_NR_sysinfo_mips_numprocessor:
14630+
strncpy(target_buf, "1", arg3-1);
14631+
break;
14632+
case TARGET_NR_sysinfo_mips_hostid:
14633+
strncpy(target_buf, "c01a4b05", arg3-1);
14634+
break;
14635+
case TARGET_NR_sysinfo_mips_osrelmaj:
14636+
strncpy(target_buf, "6", arg3-1);
14637+
break;
14638+
case TARGET_NR_sysinfo_mips_osrelmin:
14639+
strncpy(target_buf, "5", arg3-1);
14640+
break;
14641+
case TARGET_NR_sysinfo_mips_osrelpatch:
14642+
strncpy(target_buf, "0", arg3-1);
14643+
break;
14644+
case TARGET_NR_sysinfo_mips_processors:
1461714645
strncpy(target_buf, "R4000 3.0", arg3-1);
1461814646
break;
14647+
case TARGET_NR_sysinfo_mips_availprocessors:
14648+
strncpy(target_buf, "1", arg3-1);
14649+
break;
1461914650
default:
1462014651
gemu_log("qemu: Unsupported syscall: sgisysinfo(%d)\n", (int)arg1);
1462114652
ret = -TARGET_EINVAL;

0 commit comments

Comments
 (0)