Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
relibc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Peter Limkilde Svendsen
relibc
Commits
4e5ccbff
Verified
Commit
4e5ccbff
authored
2 years ago
by
Jacob Lorentzon
Browse files
Options
Downloads
Patches
Plain Diff
Allow constructors to access env vars.
parent
049a5156
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/ld_so/linker.rs
+8
-0
8 additions, 0 deletions
src/ld_so/linker.rs
src/ld_so/start.rs
+16
-0
16 additions, 0 deletions
src/ld_so/start.rs
src/start.rs
+25
-8
25 additions, 8 deletions
src/start.rs
with
49 additions
and
8 deletions
src/ld_so/linker.rs
+
8
−
0
View file @
4e5ccbff
...
...
@@ -472,7 +472,15 @@ impl Linker {
}
fn
run_init
(
&
self
,
objects
:
&
Vec
<
DSO
>
)
{
use
crate
::
platform
::{
self
,
types
::
*
};
for
obj
in
objects
.iter
()
.rev
()
{
if
let
Some
((
symbol
,
true
))
=
obj
.get_sym
(
"__relibc_init_environ"
)
{
unsafe
{
symbol
.as_ptr
()
.cast
::
<*
mut
*
mut
c_char
>
()
.write
(
platform
::
environ
);
}
}
obj
.run_init
();
}
}
...
...
This diff is collapsed.
Click to expand it.
src/ld_so/start.rs
+
16
−
0
View file @
4e5ccbff
...
...
@@ -167,6 +167,22 @@ pub extern "C" fn relibc_ld_so_start(sp: &'static mut Stack, ld_entry: usize) ->
(
argv
,
envs
,
auxv
)
};
unsafe
{
crate
::
platform
::
OUR_ENVIRON
=
envs
.iter
()
.map
(|(
k
,
v
)|
{
let
mut
var
=
Vec
::
with_capacity
(
k
.len
()
+
v
.len
()
+
2
);
var
.extend
(
k
.as_bytes
());
var
.push
(
b'='
);
var
.extend
(
v
.as_bytes
());
var
.push
(
b'\0'
);
let
mut
var
=
var
.into_boxed_slice
();
let
ptr
=
var
.as_mut_ptr
();
core
::
mem
::
forget
(
var
);
ptr
.cast
()
})
.chain
(
core
::
iter
::
once
(
core
::
ptr
::
null_mut
()))
.collect
::
<
Vec
<
_
>>
();
crate
::
platform
::
environ
=
crate
::
platform
::
OUR_ENVIRON
.as_mut_ptr
();
}
let
is_manual
=
if
let
Some
(
img_entry
)
=
auxv
.get
(
&
AT_ENTRY
)
{
*
img_entry
==
ld_entry
}
else
{
...
...
This diff is collapsed.
Click to expand it.
src/start.rs
+
25
−
8
View file @
4e5ccbff
...
...
@@ -67,7 +67,16 @@ static INIT_ARRAY: [extern "C" fn(); 1] = [init_array];
static
mut
init_complete
:
bool
=
false
;
#[used]
#[no_mangle]
static
mut
__relibc_init_environ
:
*
mut
*
mut
c_char
=
ptr
::
null_mut
();
fn
alloc_init
()
{
unsafe
{
if
init_complete
{
return
;
}
}
unsafe
{
if
let
Some
(
tcb
)
=
ld_so
::
tcb
::
Tcb
::
current
()
{
if
tcb
.mspace
!=
0
{
...
...
@@ -96,6 +105,10 @@ extern "C" fn init_array() {
alloc_init
();
io_init
();
unsafe
{
platform
::
environ
=
__relibc_init_environ
;
}
extern
"C"
{
fn
pthread_init
();
}
...
...
@@ -155,15 +168,19 @@ pub unsafe extern "C" fn relibc_start(sp: &'static Stack) -> ! {
platform
::
program_invocation_name
=
*
arg
;
platform
::
program_invocation_short_name
=
libgen
::
basename
(
*
arg
);
}
// Set up envp
let
envp
=
sp
.envp
();
let
mut
len
=
0
;
while
!
(
*
envp
.add
(
len
))
.is_null
()
{
len
+=
1
;
// We check for NULL here since ld.so might already have initialized it for us, and we don't
// want to overwrite it if constructors in .init_array of dependency libraries have called
// setenv.
if
platform
::
environ
.is_null
()
{
// Set up envp
let
envp
=
sp
.envp
();
let
mut
len
=
0
;
while
!
(
*
envp
.add
(
len
))
.is_null
()
{
len
+=
1
;
}
platform
::
OUR_ENVIRON
=
copy_string_array
(
envp
,
len
);
platform
::
environ
=
platform
::
OUR_ENVIRON
.as_mut_ptr
();
}
platform
::
OUR_ENVIRON
=
copy_string_array
(
envp
,
len
);
platform
::
environ
=
platform
::
OUR_ENVIRON
.as_mut_ptr
();
// Setup signal stack, otherwise we cannot handle any signals besides SIG_IGN/SIG_DFL behavior.
setup_sigstack
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment