Port to 3.1 - Fix out of range access in GetRecycleMemoryInfo (#27959)
authorJan Vorlicek <janvorli@microsoft.com>
Tue, 14 Jan 2020 18:34:51 +0000 (19:34 +0100)
committerAnirudh Agnihotry <anirudhagnihotry098@gmail.com>
Tue, 14 Jan 2020 18:34:51 +0000 (10:34 -0800)
commit719bfcc82f2dd2e27125f834540bff8b35f94894
tree3123c7a9e4fc62965313e9ab202c8f33e22f57ed
parentb72ff3bafd1ea7171c1bd9c44f4ca26f498b51f1
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
src/vm/win32threadpool.h