Cygwin: Fix return value of sched_getaffinity

Have sched_getaffinity() interface like glibc's, and provide an
undocumented internal interface __sched_getaffinity_sys() like the Linux
kernel's sched_getaffinity() for benefit of taskset(1).
This commit is contained in:
Mark Geisert 2019-06-26 02:44:56 -07:00 committed by Corinna Vinschen
parent 383e19ca55
commit fff17ad73f
4 changed files with 31 additions and 11 deletions

View File

@ -98,6 +98,7 @@ __res_querydomain SIGFE
__res_search SIGFE __res_search SIGFE
__res_send SIGFE __res_send SIGFE
__res_state SIGFE __res_state SIGFE
__sched_getaffinity_sys SIGFE
__signbitd NOSIGFE __signbitd NOSIGFE
__signbitf NOSIGFE __signbitf NOSIGFE
__signgam NOSIGFE __signgam NOSIGFE

View File

@ -510,7 +510,7 @@ details. */
337: MOUNT_BINARY -> MOUNT_TEXT 337: MOUNT_BINARY -> MOUNT_TEXT
338: Export secure_getenv. 338: Export secure_getenv.
339: Export sched_getaffinity, sched_setaffinity, pthread_getaffinity_np, 339: Export sched_getaffinity, sched_setaffinity, pthread_getaffinity_np,
pthread_setaffinity_np. pthread_setaffinity_np, __sched_getaffinity_sys.
Note that we forgot to bump the api for ualarm, strtoll, strtoull, Note that we forgot to bump the api for ualarm, strtoll, strtoull,
sigaltstack, sethostname. */ sigaltstack, sethostname. */

View File

@ -9,6 +9,10 @@ details. */
#ifndef _SYS_CPUSET_H_ #ifndef _SYS_CPUSET_H_
#define _SYS_CPUSET_H_ #define _SYS_CPUSET_H_
#ifdef __cplusplus
extern "C" {
#endif
typedef __SIZE_TYPE__ __cpu_mask; typedef __SIZE_TYPE__ __cpu_mask;
#define __CPU_SETSIZE 1024 // maximum number of logical processors tracked #define __CPU_SETSIZE 1024 // maximum number of logical processors tracked
#define __NCPUBITS (8 * sizeof (__cpu_mask)) // max size of processor group #define __NCPUBITS (8 * sizeof (__cpu_mask)) // max size of processor group
@ -22,4 +26,10 @@ typedef struct
__cpu_mask __bits[__CPU_GROUPMAX]; __cpu_mask __bits[__CPU_GROUPMAX];
} cpu_set_t; } cpu_set_t;
int __sched_getaffinity_sys (pid_t, size_t, cpu_set_t *);
#ifdef __cplusplus
}
#endif
#endif /* _SYS_CPUSET_H_ */ #endif /* _SYS_CPUSET_H_ */

View File

@ -555,8 +555,9 @@ done:
} }
int int
sched_getaffinity (pid_t pid, size_t sizeof_set, cpu_set_t *set) __sched_getaffinity_sys (pid_t pid, size_t sizeof_set, cpu_set_t *set)
{ {
/* Emulate Linux raw sched_getaffinity syscall for benefit of taskset(1) */
HANDLE process = 0; HANDLE process = 0;
int status = 0; int status = 0;
@ -603,14 +604,21 @@ done:
if (status) if (status)
{ {
set_errno (status); set_errno (status);
status = -1; return -1;
} }
else
/* On successful return, we would ordinarily return 0, but instead we
emulate the behavior of the raw sched_getaffinity syscall on Linux. */
return min (sizeof_set, sizeof (cpu_set_t));
}
int
sched_getaffinity (pid_t pid, size_t sizeof_set, cpu_set_t *set)
{ {
/* Emulate documented Linux kernel behavior on successful return */ /* Emulate the Linux glibc interface of sched_getaffinity() by calling
status = wincap.cpu_count (); the raw syscall emulation and mapping positive results to 0. */
} int status = __sched_getaffinity_sys (pid, sizeof_set, set);
return status; return status > 0 ? 0 : status;
} }
int int
@ -727,9 +735,10 @@ done:
if (status) if (status)
{ {
set_errno (status); set_errno (status);
status = -1; return -1;
} }
return status;
return 0;
} }
} /* extern C */ } /* extern C */