Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use _NSGetEnviron() on OSX to retrieve environ #9994

Merged
merged 1 commit into from Jun 24, 2020

Conversation

sharon-wang
Copy link
Contributor

@sharon-wang sharon-wang commented Jun 23, 2020

As per: #7247

Direct access to environ on OSX should use _NSGetEnviron, as environ is only directly accessible via that environment
subroutine from shared libraries and bundles since Mac OS X 10.5 (Leopard).

This change likely does not fix the crash noted in the issue, but makes access to environ available from shared libraries and bundles.


environ is a list of strings that is made available when a process begins. Each string has the convention "name=value" which is set in the user environment.

environ can be directly accessed, except from shared libraries and bundles, since it is only available to the loader ld when a complete program is being linked. The environment routines getenv, setenv and putenv can be used to access environ whether referenced by the loader or in shared libraries and bundles. If direct access to environ is needed in shared libraries or bundles for OSX, _NSGetEnviron (defined in crt_externs.h) can be used to retrieve environ at runtime.

Source: https://opensource.apple.com/source/Libc/Libc-1353.41.1/man/FreeBSD/environ.7.auto.html
Some other info: https://www.gnu.org/software/gnulib/manual/gnulib.html#environ
crt_externs.h: https://opensource.apple.com/source/Libc/Libc-1353.41.1/sys/crt_externs.c.auto.html

@pshipton
Copy link
Member

jenkins test sanity,extended osx jdk8

runtime/vm/rasdump.c Outdated Show resolved Hide resolved
Direct access to `environ` on OSX should use _NSGetEnviron(), as
`environ` is only directly accessible via that environment
subroutine from shared libraries and bundles.

---

`environ` is a list of strings that is made available when a
process begins. Each string has the convention "name=value" which
is set in the user environment.

`environ` can be directly accessed, except from shared libraries
and bundles, since it is only available to the loader `ld` when a
complete program is being linked. The environment routines
`getenv`, `setenv` and `putenv` can be used to access `environ`
whether referenced by the loader or in shared libraries and
bundles. If direct access to `environ` is needed in shared
libraries or bundles for OSX, `_NSGetEnviron` (defined in
`crt_externs.h`) can be used to retrieve `environ` at runtime.

Source: https://opensource.apple.com/source/Libc/Libc-1353.41.1/man/FreeBSD/environ.7.auto.html

Signed-off-by: Sharon Wang <sharon-wang-cpsc@outlook.com>
@sharon-wang
Copy link
Contributor Author

Build and tests (sanity, extended) have passed. Pushing change to add /* defined(OSX) */.

Copy link
Member

@DanHeidinga DanHeidinga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@DanHeidinga
Copy link
Member

Not going to rerun tests for the comment change

@DanHeidinga DanHeidinga merged commit 0606174 into eclipse-openj9:master Jun 24, 2020
@DanHeidinga DanHeidinga added this to the Release 0.22 (Java 15) milestone Jun 24, 2020
@pshipton
Copy link
Member

@DanHeidinga should this (and eclipse/omr#5338) be considered for the 0.21 release?

@DanHeidinga
Copy link
Member

I would suggest no given @sharon-wang hasn't been able to reproduce the issue in recent builds

@sharon-wang sharon-wang deleted the useNSGetEnviron branch January 12, 2021 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants