Skip to contentSkip to conversation

getpriority() shouldn't use libc wrapper

PATCH In review Thayne Harbaugh 1 participant 2 messages Sep 26, 2007 – Oct 2, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 getpriority() shouldn't use libc wrapper

The linux-user getpriority() syscall goes through the libc wrapper. This causes a problem because the libc wrapper remaps the return value from the kernel. This patch calls the kernel getpriority syscall directly.

linux-user/syscall.c +6 -1
Index: qemu/linux-user/syscall.c
===================================================================
@@ -174,6 +174,7 @@
 #define __NR_sys_getcwd1 __NR_getcwd
 #define __NR_sys_getdents __NR_getdents
 #define __NR_sys_getdents64 __NR_getdents64
+#define __NR_sys_getpriority __NR_getpriority
 #define __NR_sys_linkat __NR_linkat
 #define __NR_sys_mkdirat __NR_mkdirat
 #define __NR_sys_mknodat __NR_mknodat
@@ -229,6 +230,7 @@
 #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)
 _syscall3(int, sys_getdents64, uint, fd, struct dirent64 *, dirp, uint, count);
 #endif
+_syscall2(int, sys_getpriority, int, which, int, who);
 _syscall5(int, _llseek,  uint,  fd, ulong, hi, ulong, lo,
           loff_t *, res, uint, wh);
 #if defined(TARGET_NR_linkat) && defined(__NR_linkat)
@@ -4010,7 +4012,10 @@
         break;
 #endif
     case TARGET_NR_getpriority:
-        ret = get_errno(getpriority(arg1, arg2));
+        /* libc does special remapping of the return value of
+         * sys_getpriority() so it's just easiest to call
+         * sys_getpriority() directly rather than through libc. */
+        ret = sys_getpriority(arg1, arg2);
         break;
     case TARGET_NR_setpriority:
         ret = get_errno(setpriority(arg1, arg2, arg3));
#1 lore raw
Quoted 4 lines · Thayne Harbaugh

The linux-user getpriority() syscall goes through the libc wrapper. This causes a problem because the libc wrapper remaps the return value from the kernel. This patch calls the kernel getpriority syscall directly.

I didn't see any discussion about this nor did I see it committed. Were there any concerns or objections? It fixes several failures in the LTP test suite.

The bug is that the kernel returns -1 on error and 1-40 on success - the libc wrapper remaps this to -1 or error and -20 - 19 on succes (errno must be cleared and checked for the -1 case to determine if there was an error). If qemu uses the libc wrapper then the return value is aleady remapped to negative numbers - which appear to be errors.