summaryrefslogtreecommitdiff
path: root/src/vm
diff options
context:
space:
mode:
authorJan Vorlicek <janvorli@microsoft.com>2020-01-14 19:34:51 +0100
committerAnirudh Agnihotry <anirudhagnihotry098@gmail.com>2020-01-14 10:34:51 -0800
commit719bfcc82f2dd2e27125f834540bff8b35f94894 (patch)
tree3123c7a9e4fc62965313e9ab202c8f33e22f57ed /src/vm
parentb72ff3bafd1ea7171c1bd9c44f4ca26f498b51f1 (diff)
downloadcoreclr-719bfcc82f2dd2e27125f834540bff8b35f94894.tar.gz
coreclr-719bfcc82f2dd2e27125f834540bff8b35f94894.tar.bz2
coreclr-719bfcc82f2dd2e27125f834540bff8b35f94894.zip
Port to 3.1 - Fix out of range access in GetRecycleMemoryInfo (#27959)
Ports change #26873 to release 3.1 branch. On OpenVZ virtualized linux, GetCurrentProcessorNumber which uses sched_getcpu() can return a value greater than the number of processors reported by sched_getaffinity with CPU_COUNT or sysconf(_SC_NPROCESSORS_ONLN). For example, taskset -c 2,3 ./MyApp will make CPU_COUNT be 2 but sched_getcpu() can return 2 or 3, and OpenVZ kernel can make sysconf(_SC_NPROCESSORS_ONLN) return a limited cpu count but sched_getcpu() still report the real processor number. Example of affinity vs current CPU id on OpenVZ: nproc: 8 nprocOnline: 1 affinity: 1, 0, 0, 0, 0, 0, 0, 0, cpuid: 2 affinity: 1, 0, 0, 0, 0, 0, 0, 0, cpuid: 2 affinity: 1, 0, 0, 0, 0, 0, 0, 0, cpuid: 2 affinity: 1, 0, 0, 0, 0, 0, 0, 0, cpuid: 2 affinity: 1, 0, 0, 0, 0, 0, 0, 0, cpuid: 2 affinity: 1, 0, 0, 0, 0, 0, 0, 0, cpuid: 5 affinity: 1, 0, 0, 0, 0, 0, 0, 0, cpuid: 5
Diffstat (limited to 'src/vm')
-rw-r--r--src/vm/win32threadpool.h4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/vm/win32threadpool.h b/src/vm/win32threadpool.h
index e05849ec79..f3fe62f58b 100644
--- a/src/vm/win32threadpool.h
+++ b/src/vm/win32threadpool.h
@@ -749,7 +749,9 @@ public:
#else // !FEATURE_PAL
if (PAL_HasGetCurrentProcessorNumber())
{
- processorNumber = GetCurrentProcessorNumber();
+ // On linux, GetCurrentProcessorNumber which uses sched_getcpu() can return a value greater than the number
+ // of processors reported by sysconf(_SC_NPROCESSORS_ONLN) when using OpenVZ kernel.
+ processorNumber = GetCurrentProcessorNumber()%NumberOfProcessors;
}
#endif // !FEATURE_PAL
return pRecycledListPerProcessor[processorNumber][memType];