Make more compatibility improvements

This commit is contained in:
Justine Tunney 2022-09-06 07:04:13 -07:00
parent 12d9e1e128
commit 55c6297e13
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
63 changed files with 513 additions and 80 deletions

View file

@ -16,28 +16,56 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/calls/sched-sysv.internal.h"
#include "libc/calls/strace.internal.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/calls/struct/cpuset.h"
#include "libc/calls/syscall_support-nt.internal.h"
#include "libc/dce.h"
#include "libc/nt/process.h"
#include "libc/nt/runtime.h"
#include "libc/nt/thread.h"
#include "libc/str/str.h"
#include "libc/sysv/errfuns.h"
static textwindows int sys_sched_getaffinity_nt(int tid, size_t size,
cpu_set_t *bitset) {
uint64_t ProcessAffinityMask, SystemAffinityMask;
if (GetProcessAffinityMask(GetCurrentProcess(), &ProcessAffinityMask,
&SystemAffinityMask)) {
bzero(bitset, size);
bitset->__bits[0] = ProcessAffinityMask;
return 0;
} else {
return __winerr();
}
}
/**
* Gets kernel scheduling for particular CPUs.
* Gets CPU affinity for current thread.
*
* While Windows allows us to change the thread affinity mask, it's only
* possible to read the process affinity mask. Therefore this function
* won't reflect the changes made by sched_setaffinity() on Windows.
*
* @param pid is the process or thread id (or 0 for caller)
* @param size is byte length of bitset
* @param size is byte length of bitset, which should 128
* @param bitset receives bitset and should be uint64_t[16] in order to
* work on older versions of Linux
* @return 0 on success, or -1 w/ errno
* @raise ENOSYS on non-Linux
*/
int sched_getaffinity(int tid, size_t size, void *bitset) {
long rc;
rc = sys_sched_getaffinity(tid, size, bitset);
if (rc != -1) {
int sched_getaffinity(int tid, size_t size, cpu_set_t *bitset) {
int rc;
if (size != 128) {
rc = einval();
} else if (IsWindows()) {
rc = sys_sched_getaffinity_nt(tid, size, bitset);
} else {
rc = sys_sched_getaffinity(tid, size, bitset);
}
if (rc > 0) {
if (rc < size) {
memset((char *)bitset + rc, 0, size - rc);
bzero((char *)bitset + rc, size - rc);
}
rc = 0;
}