Skip to content

Commit 1bc99f2

Browse files
Merge pull request #1483 from WebPlatformForEmbedded/pgorszkowski/2.38/JSC-Opportunistically-exclude-environment-variable-from-stack-scanning-on-Linux
[JSC] Opportunistically exclude environment variable from stack scann…
2 parents 4b3faa7 + 5695a8a commit 1bc99f2

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

Source/WTF/wtf/StackBounds.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,19 @@ StackBounds StackBounds::currentThreadStackBoundsInternal()
132132
// account for a guard page
133133
size -= static_cast<rlim_t>(sysconf(_SC_PAGESIZE));
134134
void* bound = static_cast<char*>(origin) - size;
135-
return StackBounds { origin, bound };
135+
136+
static char** oldestEnviron = environ;
137+
138+
// In 32bit architecture, it is possible that environment variables are having a characters which looks like a pointer,
139+
// and conservative GC will find it as a live pointer. We would like to avoid that to precisely exclude non user stack
140+
// data region from this stack bounds. As the article (https://lwn.net/Articles/631631/) and the elf loader implementation
141+
// explain how Linux main thread stack is organized, environment variables vector is placed on the stack, so we can exclude
142+
// environment variables if we use `environ` global variable as a origin of the stack.
143+
// But `setenv` / `putenv` may alter `environ` variable's content. So we record the oldest `environ` variable content, and use it.
144+
StackBounds stackBounds { origin, bound };
145+
if (stackBounds.contains(oldestEnviron))
146+
stackBounds = { oldestEnviron, bound };
147+
return stackBounds;
136148
}
137149
#endif
138150
return ret;

0 commit comments

Comments
 (0)