[bcl] Add null reference checks to Interlocked.Exchange<T> (mono/mono#17400)
* [bcl] Add null reference checks to Interlocked.Exchange<T>
and Interlocked.CompareExchange<T>
This is to mimic the old behavior in unmanaged when the intrinsic cannot be
used.
The issue was detected via the coreclr acceptance test:
https://github.com/mono/coreclr/blob/mono/tests/src/baseservices/threading/interlocked/exchange/exchangetneg.il
* and netcore
Commit migrated from https://github.com/mono/mono/commit/
d8ae32a9ee7763c861bdc31831271d82aa8a4953