[Issue 14934] GC interface doesn't allow safe extension of a memory range
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Wed Aug 19 09:34:11 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=14934
Steven Schveighoffer <schveiguy at yahoo.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |REOPENED
CC| |schveiguy at yahoo.com
Resolution|WORKSFORME |---
--- Comment #3 from Steven Schveighoffer <schveiguy at yahoo.com> ---
(In reply to Martin Nowak from comment #1)
> Please let's try to avoid arbitrary code execution with the GC lock held.
I really don't see another way to do this. Your idea of using
enterCriticalRegion isn't viable, because you need to call removeRange and
addRange (which take the lock, that might be held while attempting to suspend
the threads). Unless I misunderstand how it works.
However, I don't think it needs to be an "advertised" feature. I'm not sure we
need to do it via a delegate, all we need is exposure to the lock. This needs
to be done only in low-level situations.
> void* reallocImpl(void* p, size_t newSize)
> {
> thread_enterCriticalRegion();
> auto oldp = p;
> p = realloc(p, newSize);
> if (p !is oldp)
> {
> GC.removeRange(oldp);
> GC.addRange(p, newSize);
> }
> thread_exitCriticalRegion();
> return newPtr;
> }
Note, you need to remove and re-add the range in both cases, because the new
range is bigger.
--
More information about the Digitalmars-d-bugs
mailing list