If Count Exceeds MAX_SCHED_CPUS, Set Count To MAX_SCHED_CPUS

Fixes out of bounds issues when running Darling on a device/virutal machine that reports more then 64 cores. Fixes #7

Co-Authored-By: Janrupf <business.janrupf@gmail.com>
This commit is contained in:
Thomas A. 2024-03-28 22:03:34 -07:00
parent 62a3321e98
commit 36da4da465

View File

@ -31,7 +31,13 @@ void dtape_processor_init(void) {
simple_lock_init(&processor_list_lock, 0); simple_lock_init(&processor_list_lock, 0);
processor_count = get_nprocs_conf(); processor_count = get_nprocs_conf();
if (processor_count > MAX_SCHED_CPUS)
processor_count = MAX_SCHED_CPUS;
processor_avail_count = get_nprocs(); processor_avail_count = get_nprocs();
if (processor_avail_count > MAX_SCHED_CPUS)
processor_avail_count = MAX_SCHED_CPUS;
processor_avail_count_user = processor_avail_count; processor_avail_count_user = processor_avail_count;
primary_processor_avail_count = processor_avail_count; primary_processor_avail_count = processor_avail_count;
primary_processor_avail_count_user = processor_avail_count; primary_processor_avail_count_user = processor_avail_count;