Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Conversation

@janvorli
Copy link
Member

There is a method ThreadpoolMgr::ShiftWaitArray which uses memcpy to do
a move a segment of the waitPointer and waitHandle arrays one position
down, so the source and destination ranges overlap. However, it uses
memcpy, which on Linux copies items starting from the last one. So
the arrays get corrupted after the memcpy, containing multiple copies
of the last element and not containig some elements that were expected
to move.
The fix is to use memmove which should be used when the source and
destination memory regions overlap.

There is a method ThreadpoolMgr::ShiftWaitArray which uses memcpy to do
a move a segment of the waitPointer and waitHandle arrays one position
down, so the source and destination ranges overlap. However, it uses
memcpy, which on Linux copies items starting from the last one. So
the arrays get corrupted after the memcpy, containing multiple copies
of the last element and not containig some elements that were expected
to move.
The fix is to use memmove which should be used when the source and
destination memory regions overlap.
@janvorli
Copy link
Member Author

@jkotas Can you take a look please?

@janvorli
Copy link
Member Author

Fixes #2093

@jkotas
Copy link
Member

jkotas commented Nov 19, 2015

👍

janvorli added a commit that referenced this pull request Nov 19, 2015
Fix issue with threadpool and wait for multiple objects on Linux
@janvorli janvorli merged commit 97433b9 into dotnet:master Nov 19, 2015
@janvorli janvorli deleted the fix-threadpool-shiftwaitarray branch November 19, 2015 10:36
@stephentoub
Copy link
Member

Thanks for fixing this, @janvorli! Nice job.

A quick search shows ~600 uses of memcpy in the coreclr src. If slightly different semantics between Windows and Linux could result in a bug like this being hidden until we ran on Linux, I wonder if it'd be worth auditing those call sites to proactively look for any other cases that should have been memmove?

@janvorli
Copy link
Member Author

@stephentoub I have the same concern. I'll create a PS item to track it.

@janvorli
Copy link
Member Author

#2101 created to track the need to audit the memcpy usages.

picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…hiftwaitarray

Fix issue with threadpool and wait for multiple objects on Linux

Commit migrated from dotnet/coreclr@97433b9
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants