correct getdents and add some more sgisysinfo defines

This commit is contained in:
tehzz 2020-05-09 20:20:17 -04:00
parent 25d6223cc9
commit bbd4558471
3 changed files with 55 additions and 11 deletions

View File

@ -349,8 +349,18 @@
#define TARGET_NR_sysinfo_cpuarch 6 #define TARGET_NR_sysinfo_cpuarch 6
#define TARGET_NR_sysinfo_hwserial 7 #define TARGET_NR_sysinfo_hwserial 7
#define TARGET_NR_sysinfo_hwproducer 8 #define TARGET_NR_sysinfo_hwproducer 8
#define TARGET_NR_sysinfo_processors 109
#define TARGET_NR_sysinfo_mips_vendor 100 /* return system provider */
#define TARGET_NR_sysinfo_mips_osprovider 101 /* return OS manufacturer */
#define TARGET_NR_sysinfo_mips_osname 102 /* return OS name */
#define TARGET_NR_sysinfo_mips_hwname 103 /* return system name */
#define TARGET_NR_sysinfo_mips_numprocessor 104 /* return number of processors */
#define TARGET_NR_sysinfo_mips_hostid 105 /* return hostid */
#define TARGET_NR_sysinfo_mips_osrelmaj 106 /* return OS major release number */
#define TARGET_NR_sysinfo_mips_osrelmin 107 /* return OS minor release number */
#define TARGET_NR_sysinfo_mips_osrelpatch 108 /* return OS release number */
#define TARGET_NR_sysinfo_mips_processors 109 /* return CPU revison id */
#define TARGET_NR_sysinfo_mips_availprocessors 110 /* return number of available processors */
/* utssyssgi(obuf, ibuf, cmd) */ /* utssyssgi(obuf, ibuf, cmd) */
#define TARGET_NR_utssys_uname (0) #define TARGET_NR_utssys_uname (0)

View File

@ -1734,3 +1734,6 @@
#ifdef TARGET_NR_usync_cntl #ifdef TARGET_NR_usync_cntl
{ TARGET_NR_usync_cntl, "usync_cntl", NULL, NULL, NULL }, { TARGET_NR_usync_cntl, "usync_cntl", NULL, NULL, NULL },
#endif #endif
#ifdef TARGET_NR_sysinfosgi
{ TARGET_NR_sysinfosgi, "sysinfosgi", NULL, NULL, NULL },
#endif

View File

@ -10814,6 +10814,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
// ret == bytes read, or target error code // ret == bytes read, or target error code
dirp = fdopendir(dir_fd); dirp = fdopendir(dir_fd);
gemu_log("\n\tgetdents fdopendir: %p\n", dirp);
if (!dirp) { if (!dirp) {
ret = -host_to_target_errno(errno); ret = -host_to_target_errno(errno);
goto fail; goto fail;
@ -10824,12 +10825,16 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
ret = -TARGET_ENOMEM; ret = -TARGET_ENOMEM;
goto fail; goto fail;
} }
gemu_log("\n\tgetdents host_dirp: %p\n", host_dirp);
// collect readdir calls into getdents dirp * buffer // collect readdir calls into getdents dirp * buffer
target_dirp = lock_user(VERIFY_WRITE, arg2, count, 0); target_dirp = lock_user(VERIFY_WRITE, arg2, count, 0);
if (!target_dirp) { if (!target_dirp) {
goto efault; goto efault;
} }
gemu_log("\n\tgetdents target_dirp: %p\n", target_dirp);
struct dirent *de; struct dirent *de;
struct target_dirent *tde = target_dirp; struct target_dirent *tde = target_dirp;
@ -10837,16 +10842,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
uint target_reclen; uint target_reclen;
uint name_len; uint name_len;
for (;;) { while ((de = readdir(dirp))) {
de = readdir(dirp);
if (!de) {
found_err = TRUE;
break;
}
// check if new entry will overflow the target buffer // check if new entry will overflow the target buffer
name_len = de->d_namlen + 1; name_len = de->d_namlen + 1;
target_reclen = target_dirent_len + name_len; target_reclen = target_dirent_len + name_len;
// TODO -> QEMU_ALIGN_UP(target_reclen, alignof(struct target_dirent))? // is this the correct way to align this structure..?
target_reclen = QEMU_ALIGN_UP(target_reclen, __alignof(struct target_dirent)); target_reclen = QEMU_ALIGN_UP(target_reclen, __alignof(struct target_dirent));
if (bytes_used + target_reclen > count) { if (bytes_used + target_reclen > count) {
break; break;
@ -10868,8 +10868,9 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
ret = bytes_used; ret = bytes_used;
} }
unlock_user(target_dirp, arg2, ret); unlock_user(target_dirp, arg2, ret);
g_free(dirp); // Don't close the `DIR *` pointer, as that will close the fd
// handle possible readdir errors here // which was used in `fdopendir`
// closedir(dirp);
} }
// Old Linux code // Old Linux code
// #ifdef __NR_getdents // #ifdef __NR_getdents
@ -14613,9 +14614,39 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
strncpy(target_buf, "Qemu", arg3-1); strncpy(target_buf, "Qemu", arg3-1);
break; break;
case TARGET_NR_sysinfo_processors: case TARGET_NR_sysinfo_mips_vendor:
strncpy(target_buf, "SGI", arg3-1);
break;
case TARGET_NR_sysinfo_mips_osprovider:
strncpy(target_buf, "Qemu", arg3-1);
break;
case TARGET_NR_sysinfo_mips_osname:
strncpy(target_buf, "IRIX", arg3-1);
break;
case TARGET_NR_sysinfo_mips_hwname:
strncpy(target_buf, "IP22", arg3-1);
break;
case TARGET_NR_sysinfo_mips_numprocessor:
strncpy(target_buf, "1", arg3-1);
break;
case TARGET_NR_sysinfo_mips_hostid:
strncpy(target_buf, "c01a4b05", arg3-1);
break;
case TARGET_NR_sysinfo_mips_osrelmaj:
strncpy(target_buf, "6", arg3-1);
break;
case TARGET_NR_sysinfo_mips_osrelmin:
strncpy(target_buf, "5", arg3-1);
break;
case TARGET_NR_sysinfo_mips_osrelpatch:
strncpy(target_buf, "0", arg3-1);
break;
case TARGET_NR_sysinfo_mips_processors:
strncpy(target_buf, "R4000 3.0", arg3-1); strncpy(target_buf, "R4000 3.0", arg3-1);
break; break;
case TARGET_NR_sysinfo_mips_availprocessors:
strncpy(target_buf, "1", arg3-1);
break;
default: default:
gemu_log("qemu: Unsupported syscall: sgisysinfo(%d)\n", (int)arg1); gemu_log("qemu: Unsupported syscall: sgisysinfo(%d)\n", (int)arg1);
ret = -TARGET_EINVAL; ret = -TARGET_EINVAL;