Commit Graph

928 Commits

Author SHA1 Message Date
Jeremy Soller c7910a8754 Add __need_winit_t to wctype.h 2020-05-28 13:43:55 -06:00
Peter Limkilde Svendsen da8d2fa7aa Always set memptr in posix_memalign() 2020-05-24 18:29:57 +02:00
Peter Limkilde Svendsen 60b23003c7 Simplify alignment check in posix_memalign() 2020-05-24 18:17:27 +02:00
oddcoder ee5e2bad5a Support negative padding size in printf and friends
as it seams you can do something like
        printf ("A%*s%s/\n", -5, "B", "CC");
and it will print the padding to the left
2020-05-23 16:20:20 +02:00
oddcoder d7d3e00867 Fix off-by-1 error in vfscanf
Scanf function requires look ahead to function properly, In case of
scanning from a buffer that will not be an issue, but in our case we are
reading from file, so lookaheads needs to be undone (via lseek) in our
case. The only problem here is that if we opened a file that doesn't
support lseek such as many of the file /dev/*
2020-05-23 16:20:20 +02:00
oddcoder 1733b3da6e Fix bug related to ungetc and ftell()
At least in relibc, each call to ungetc should decrement ftell() by one
also allowing negative ftell() this is not possible on relibc thus gcc
failing to compile (gcc compiles tools that is later used to compile gcc
itself and these tools are the ones that fail)
2020-05-23 16:20:20 +02:00
oddcoder 7a6f96373e Add support for multiple unget at the same time
According to the standards, only one ungetc may be guaranteed however
glibc allows more than one of those, and to be glibc compatiable, one
needs to be able to do the same, allowing only 1 ungetc may trigger bug
while compiling gcc as ungetc is used there alot
2020-05-23 16:20:20 +02:00
Jeremy Soller 0cc0fbecdc Export getrandom function 2020-05-22 15:49:51 -06:00
Jeremy Soller a6fffd3fb5 Add getrandom and sys/random.h 2020-05-22 11:50:54 -06:00
Jeremy Soller 2cf3ccae72 Fix import of user_regs_struct 2020-05-21 20:01:47 -06:00
Jeremy Soller a1034b697d Merge branch 'master' of https://gitlab.redox-os.org/redox-os/relibc 2020-05-21 14:59:41 -06:00
Jeremy Soller 06429ccc4c Fix redox socket inner_get_name 2020-05-21 14:59:22 -06:00
oddcoder 43fbaf9970 Fix a bug in thread local reloations
There was a bug (also uncovered via binutils) where R_X86_64_DTPOFF64 is
set uncorrectly. This program is the minimal reproducer of the seg fault

  #include <errno.h>
  int main() {
        int oerrno = errno;
  }

But it works after the bug fix.
2020-05-13 23:46:39 +02:00
oddcoder 4a47bc4a6f Fix regressing in printf padding with space
There was bug in printf where space paddings cause segfault,
the problem was that it was pulled from the stack twice while it should
be only done once.
2020-05-08 22:38:42 +02:00
oddcoder d62f9b6819 Fix regression in ld.so elf size calculation
In patch 1182d12006, I mistakingly added
the size of the gap to the total size of the binary, which was not
accurate. As the size of the binary was calculate by subtracting the
upperbound from the lower bound, thus all gaps in the middle are taking
into account.
2020-05-08 22:38:42 +02:00
oddcoder 850dfd971b Make "./a.out" entry the first in rmap list
This fixes a regression in gdb where sometimes it decides to ignore the
first entry in the list.
2020-05-03 14:59:55 +02:00
oddcoder 67be05d3a3 Use segments instead of sections for calculating which offset to write,
I noticed that the implementation is noth precise although it worked.
and instead of using the sections to identify memory addresses of
DT_DEBUG. I used segements
2020-05-03 14:59:52 +02:00
oddcoder 1182d12006 Fill gaps in binary memory image
Some ELFs can have gaps between the segments, this results in problems
when mprotecting or when converting (addr + size) into rust slice.
Motivated by this This patch will fill these gaps with mmaped addresses.
In theory no real memory should be allocated because mmap is lazy
allocator.
2020-05-03 13:57:24 +02:00
oddcoder eac69c920d Implement wcscasecmp and wcsncasecmp
This patch implements wcscasecmp and wcsncasecmp. These two
function are required for binutils to link against relibc.
2020-04-26 19:13:03 +02:00
oddcoder 162999ac0b Move towlower and towupper to wctype.h and Implement it
This patch creates wctype.h and impelementat two functions
that belong to that header file towupper and towlower. These
functions are building blocks for wcscasecmp and wcsncasecmp
which are utilized by binutils.

The implementation for towlower and towupper seams to be complex
so this implementation is mimicking that of musl libc
2020-04-26 19:13:03 +02:00
oddcoder 3a923aa62d Implement #include<sys/user.h> and #include<sys/procfs.h>
This patch implements sys/user.h file that works for both x86_64 as well
as aarch64. This include file is used by sys/procfs.h which is needed
dependency for binutils. There is bug in this patch in aarch64 implementation
which is the lack of f128 implementation in rust, thus we can't create cbinding
for long double.
2020-04-24 22:08:49 +02:00
oddcoder b717f6cf5a Move IO Initialization to .init_array section
Most shared object in linux have their initialization in a separate
.init_array section. but glibc does not have the same behavour. Instead
the initialization is part of crt0. which (as it seams to me) run after
.init_array section. As such, this patch move IO initialization to
separate function that is marked as .init_array member and then the crt0
call this function only if init_array was never invoked (as in
statically linked binaries).
2020-04-19 14:21:23 +02:00
oddcoder 6aeb2d6fa2 Implement code that use .init_array and .fini_array
This patch implements ld.so code that makes use of both .init_array and
.fini_array. .init_array is fully utilized and is used in the correct
manner. However .fini_array is not used yet although the function that
runs .fini_array exists
2020-04-19 14:21:23 +02:00
oddcoder cc7ff54d12 Catch circular dependency when resolving loading shared libraries
This patch implements tree-based data-structure for catching circular
dependency where libA.so will depen on arbitrarily long chain (including
zero length) of libNs.so one of which will depend on libA.so again. The
main intention of this patch was merely capturing the dependency tree to
prioterize which Elf's .init_array and which .fini_array should run
first, but as a side effect it can capture circular dependencies as well.
2020-04-19 13:28:53 +02:00
Jeremy Soller 7724989b33 Merge branch 'Debugger_Support' into 'master'
Debugger support

See merge request redox-os/relibc!263
2020-04-15 17:59:01 +00:00
Graham MacDonald 2283e25cde sigaction should set sigaction.sa_restorer 2020-04-14 23:37:54 +01:00
oddcoder de03566158 Enable RTLD debugging protocol system-wide
This patch makes use of the data structures and functions impelemented
in the last patch to enable RTLD debugging protocol as per SVR4
2020-04-13 12:39:51 +02:00
oddcoder 369d7b42c6 Initial implementation of SVR4 debugging interface for runtime linker 2020-04-13 12:12:48 +02:00
oddcoder cc305fc574 Use Kernel mapped binaries when available.
At least in linux kernel, assuming that a.out is an elf that is linked
against relibc's own ld.so. When a user attempts `./a.out`, Linux kernel
will map `./a.out`, then map `ld.so` and jump into ld.so entry point.
In relibc ld.so will simply ignore the kernel mapped a.out and create
its own mapping. This patch forces relic ld.so to use the already mapped
`a.out` when ever possible. This would normally have slight performance
improvement (especially that currently relibc doesn't map a.out but
instead copy the data into empty mmaped memory).

The real motivation behind this patch is while impelemnting Runtime
linker debugging protocol for relibc. part of the protocol is ld.so
inseting address of some ld.so managed data structure into .dynamic
seciton of a.out then the debugger would check it there. The thing is
that debuggers have information about the kernel loaded ./a.out and they
check that one specifically which is in our case totally ignored by
relibc.
2020-04-07 21:26:58 +02:00
Jeremy Soller 701e64b3a1 ld_so: Default to non-verbose 2020-03-29 20:17:29 -06:00
Jeremy Soller 6ed37efaeb Merge branch 'weak-symbols' into 'master'
Weak symbols

See merge request redox-os/relibc!260
2020-03-19 17:56:22 +00:00
Jeremy Soller 2e27cf525e Work on adding cargo test capability 2020-03-10 20:57:07 -06:00
oddcoder 4860ab12fa Resolve Both strong and weak symbols
This patch keep 2 lists, one for strong symbols and one for weak
symbols. First it will check for the symbol to be resolved in the strong
symbols' list, if it is not there it will then check in the weak symbol
list.
2020-03-08 22:03:21 +02:00
oddcoder c2488b5094 Running ./fmt.sh
These files needs formating by the auto formatter and It keeps popping
up every time I format my own code.
2020-03-07 23:52:27 +02:00
oddcoder 04ea2f9397 Refactor Linker::Link
This patch does basically two things:
- First make `global` variable not public, And make it accessable via a
function `get_sym`.
- Isolate the procedure that collect global symbols into single function
that does that and call it `collect_syms`.

The motivation of this patch is the second one where this procedure is
extended, thus it needs a seamless way to access those symbols
2020-03-07 23:52:27 +02:00
Jeremy Soller 79f265745a Fix redox ld_so 2020-02-28 19:33:20 -07:00
oddcoder bc53164293 Reduce Verbosity level when ld.so is invoked as interpreter 2020-02-24 11:56:12 +02:00
oddcoder 7f8dc2f251 Add support for invoking ld.so via execve() and friends
Introduction:

The original implementation of `relibc_ld_so_start` assumes that
ld.so will always be invoked manually as in "/lib/ld64.so ./a.out"
The problem is regarding this snippet.
    if sp.argc < 2 {
      eprintln!("ld.so [executable] [arguments...]");
      unistd::_exit(1);
      loop {}
    }

As such, In linux when user types "./a.out" he will recieve the message
    ld.so [executable] [arguments...]

This patch makes use of AUXV, specifically AT_ENTRY. When invoking ld.so
manually, AT_ENTRY happens to be the entry point of ld.so. But when
running `./a.out` directly, AT_ENTRY becomes the entry point of `a.out`
this patch compares AT_ENTRY to the entry point of ld.so, if they are
equal only then it will assume that argv[1] is the real program and
adjust the stack, otherwise it will proceed with the stack unadjusted.
2020-02-24 11:56:09 +02:00
Tiago Lam 76f07b163b platform/redox: Support AF_UNIX in accept.
As with the previous commit, accept() was calling inner_get_name() and
assuming only "tcp:" or "udp:" addresses would be received. Thus, in
order to support AF_UNIX sockets, inner_get_name() was split into two,
inner_af_inet() and inner_af_unix() - where the former keeps the
previous logic, dealing with "tcp:" and "udp:" addresses, and the latter
deals now with "chan:" addresses and filling in the sockaddr_un
appropriately.
2020-02-06 08:41:51 +00:00
Tiago Lam d36cd72788 platform/redox: Support AF_UNIX in bind / connect.
Previously, domain AF_INET was assumed while processing bind() /
connect(), which end up calling bind_or_connect!. Instead, match on the
domain type and process the path for AF_UNIX domains.
2020-02-06 08:41:48 +00:00
Tiago Lam 12f6ffd152 platform/redox: Support AF_UNIX in socket.
To add support for UNIX sockets (AF_UNIX), of SOCK_STREAM type, the
"chan:" scheme is used, which will be supportedby the ipcd running in
userspace.

Later commits add similar AF_UNIX support for the rest of the methods in
impl PalSocket.
2020-02-06 08:21:12 +00:00
Tiago Lam 2bc667f71c header/sys_un: Set sockaddr_un members to public.
Future commits will make use of this, in order to support AF_UNIX
sockets.
2020-02-06 08:21:12 +00:00
Jeremy Soller 662051a91b Only call epoll_ctl once per descriptor, fixing vim on Redox 2020-01-28 20:15:01 -07:00
Jeremy Soller 4c4ce7ec03 Add Redox termios definitions 2020-01-27 21:01:59 -07:00
Jeremy Soller 9a449d4f6c Stub for SO_ERROR to fix curl 2020-01-21 20:29:26 -07:00
Jeremy Soller 2e5d4a4d25 Merge remote-tracking branch 'origin/truncate-n-mkfifo' 2020-01-20 11:17:15 -07:00
Peter Limkilde Svendsen 0b4b3cd55c Use lossless type conversion in ctype.h 2020-01-20 17:57:56 +00:00
AdminXVII 884ec85838 Replace occurences of uninitialized with MaybeUninit
mem::uninitialized is deprecated, so move over the not-UB MaybeUninit.
2020-01-20 16:54:22 +00:00
Jeremy Soller a3f7a174f6 WIP - implementation of dlfcn 2019-12-18 21:21:25 -07:00
Jeremy Soller 2cbc78f238 Add linker pointer 2019-12-18 21:15:00 -07:00