Commit Graph

1014 Commits

Author SHA1 Message Date
Jeremy Soller 36bb60cacc Do not unmap stack while it is being used, add a comment to fix it later 2020-09-09 18:49:44 -06:00
Jeremy Soller 2ed55a926b Merge branch 'gmtime-refactor' into 'master'
Refactor gmtime_r(), fix localtime() test

See merge request redox-os/relibc!309
2020-09-08 18:45:20 +00:00
Peter Limkilde Svendsen 63711f6ca7 Formatting 2020-08-27 23:16:17 +02:00
Peter Limkilde Svendsen 845c74a82e Refactor gmtime_r() 2020-08-27 23:16:17 +02:00
Peter Limkilde Svendsen 86138c9f8a Align parameter naming with POSIX 2020-08-27 23:16:17 +02:00
Peter Limkilde Svendsen 23b2eb2573 Avoid assuming c_char is i8 2020-08-23 21:45:08 +02:00
Jeremy Soller 5af8e3ca35 Merge branch 'bump-fmap' into 'master'
Use renamed fmap call

See merge request redox-os/relibc!305
2020-08-17 12:36:11 +00:00
Jeremy Soller a78f829dca Merge branch 'brk' into 'master'
Emulate brk

See merge request redox-os/relibc!304
2020-08-17 12:35:16 +00:00
jD91mZM2 e33aea434f Use renamed fmap call 2020-08-17 13:57:39 +02:00
jD91mZM2 eaee4e6329 Emulate brk 2020-08-15 18:44:22 +02:00
Jeremy Soller 7db83596a2 Merge branch 'gcc_compile' into 'master'
Gcc compile

See merge request redox-os/relibc!303
2020-08-14 15:19:14 +00:00
oddcoder ab92ff9d41 make all ld printlns happen in case of verbose = true and apply cargo fmt
It seams that stdout of ld.so is not that much of an issue but actually
it unfortunately is. The major problem here is that sometimes programs
generate header files in stdout (./getmy_custom_headers > header.h) and
we need to keep that cleen. and this is very very popular in gcc.
2020-08-12 18:57:37 +02:00
oddcoder 7b29f6eb27 Avoid relinking already linked libs
This patch avoids collecting symbols, resolving relocs if they are
already done (usually for example libc.so during a dlopen for another
libfoo.so). This patch is purely for performance boost.
2020-08-12 18:57:37 +02:00
oddcoder 61fcc018fc Refer to libraries with soname if available and avoid loading libs twice
It is usually not optimal to load a library twice and for specifics,
it is **terrible** idea to load libc twice it was enough trouble
dealing with libc statically linked into ld.so. So What this patch does
it check for soname and if a library is already loaded it won't get
loaded again. Why soname ? because unfortunately some bins gets linked
againt libc.so while of their dependencies gets linked against
libc.so.6 while one is usually symbolic link for the other.
2020-08-12 18:57:37 +02:00
jD91mZM2 7b6ba2c73a Merge branch 'lD_PATH' into 'master'
L d path

See merge request redox-os/relibc!300
2020-08-12 10:19:32 +00:00
Ahmed Abd El Mawgood 40328a0d09 Modify ld_script so that it works on linux.
Honestly, I have no idea why are these modifications needed, but it
seams they are needed
2020-08-12 10:19:32 +00:00
jD91mZM2 b9828bd863 Merge branch 'elf_And_flock' into 'master'
Elf and flock

See merge request redox-os/relibc!283
2020-08-12 10:17:59 +00:00
oddcoder b5deadbeea Add (POSIX defined) struct flock
struct flock is posix defined locking mechanism on *nix platform

Example usage (copied from https://gavv.github.io/articles/file-locks/) :

  #include <fcntl.h>

  struct flock fl;
  memset(&fl, 0, sizeof(fl));

  // lock in shared mode
  fl.l_type = F_RDLCK;

  // lock entire file
  fl.l_whence = SEEK_SET; // offset base is start of the file
  fl.l_start = 0;         // starting offset is zero
  fl.l_len = 0;           // len is zero, which is a special value representing end
                        // of file (no matter how large the file grows in future)

  fl.l_pid = 0; // F_SETLK(W) ignores it; F_OFD_SETLK(W) requires it to be zero

  // F_SETLKW specifies blocking mode
  if (fcntl(fd, F_SETLKW, &fl) == -1) {
    exit(1);
  }

  // atomically upgrade shared lock to exclusive lock, but only
  // for bytes in range [10; 15)
  //
  // after this call, the process will hold three lock regions:
  //  [0; 10)        - shared lock
  //  [10; 15)       - exclusive lock
  //  [15; SEEK_END) - shared lock
  fl.l_type = F_WRLCK;
  fl.l_start = 10;
  fl.l_len = 5;

  // F_SETLKW specifies non-blocking mode
  if (fcntl(fd, F_SETLK, &fl) == -1) {
      exit(1);
  }

  // release lock for bytes in range [10; 15)
  fl.l_type = F_UNLCK;

  if (fcntl(fd, F_SETLK, &fl) == -1) {
      exit(1);
  }

  // close file and release locks for all regions
  // remember that locks are released when process calls close()
  // on any descriptor for a lock file
  close(fd);
2020-08-08 10:16:50 +02:00
oddcoder e14b3e09a5 Add elf.h header to relibc 2020-08-08 10:16:50 +02:00
jD91mZM2 6952a079ae Fix CI 2020-08-07 14:16:45 +00:00
jD91mZM2 72532b8280 Fix printf issue found in GDB 2020-08-05 16:49:10 +02:00
jD91mZM2 0178565f71 Move text section of linker away
Seems to collide with the program being loaded
2020-08-04 12:24:51 +00:00
Jeremy Soller ae8e070b9e Init TLS before allocator 2020-08-02 14:32:28 -06:00
Jeremy Soller 0c6398abcb Do not require allocation in static_init 2020-08-02 14:32:20 -06:00
Jeremy Soller ebb17654f8 Add llvm_asm features 2020-08-02 13:42:34 -06:00
Jeremy Soller 5d45042d5d Correct more asm! usages 2020-08-02 13:38:29 -06:00
Jeremy Soller f2c2d7c52e Fix compilation on newer nightly, update nightly to 2020-08-01 2020-08-02 12:24:49 -06:00
jD91mZM2 4c148c1860 Make munmap use funmap2 2020-07-30 13:39:20 +02:00
4lDO2 a5e02650d7 Remove ptrace write call. 2020-07-25 22:30:38 +02:00
4lDO2 e38d185870 Use fmap2 to support passing an address. 2020-07-25 22:30:38 +02:00
Jeremy Soller d6b03de7a4 Align stack to 128 bytes 2020-07-19 21:04:16 -06:00
oddcoder 37a462de5d Apply cargo fmt to the whole repo 2020-07-19 21:27:38 +02:00
no name 890a9ed033 Implement dlopen/close 2020-07-19 21:27:38 +02:00
oddcoder ea3265766c Allow struct Linker to specify which library space to use 2020-07-19 21:21:48 +02:00
oddcoder 02aa400c5c Add callbacks to ld.so version of Linker's function
It is fact that ld.so has libc statially linked into it.

Normally we wouldn't need ld.so functionality once the program is
finalyl loaded, but with the next few patches, we will have dlopen which
will reuse the same ld.so functionality.

The problem is that it seams that huge part of the code is possible not
referntially transparent. That is, it is not impossible that some of the
functions have internals states. So when using the struct Linker that is
initialized by ld.so's copy of libc. we must access it using the same
copy even if both copies are identical.
For example in dlopen if you do linker.load_library(..). That would
segfault because it is using the function from libc not ld.so

So I don't truly undestand why should this be needed, but after long
hours of being stuck I thought maybe.. maybe that is the issue and
indeed it turned out to be so.
2020-07-19 21:21:48 +02:00
oddcoder b4a6a7ece5 Refactor init and fini by merging common code 2020-07-19 21:21:48 +02:00
oddcoder 6d0c9dccd5 Allow Linker struct to specify with library name space to operate on 2020-07-19 21:21:48 +02:00
oddcoder 01b1738b3a Separate library specific data from main Linker struct 2020-07-19 21:21:48 +02:00
oddcoder aaf017d9d1 Fix regression introduced in 5fcf9206
I by mistake commented _dl_debug_state() function which would break
debugging
2020-07-19 21:21:48 +02:00
Jeremy Soller 36ac4166ef Define MAP_ANON for dlmalloc 2020-07-19 12:40:01 -06:00
no name 40acadc7d5 Sanity checking 04f77881d0 2020-07-18 21:15:57 +02:00
oddcoder 4d982f86b2 use only mspaces 2020-07-18 21:05:18 +02:00
oddcoder f4f68a3441 Make use of mspaces 2020-07-18 21:03:46 +02:00
oddcoder 3a8817072c Initialize the mspaces of allocator and keep track of it 2020-07-18 21:03:20 +02:00
oddcoder 67c703610b Compile dlmalloc with mspace support 2020-07-18 20:54:58 +02:00
oddcoder 9a1efda121 Initial allocator structure 2020-07-18 20:54:30 +02:00
oddcoder d4b2391221 Fix wrong TLS resolving
I attempted fixing this issue before at 43fbaf99. Although it did work,
it worked wrong, and it was just consistently working (but in wrong way)
until it didn't.

Since this is (hopefully) the real fix, I will try to explain exactly
what is going on.

This is explaination by example:

our TLS is memory of size 0x1000 starting at 0x7ffff6c50000,
but the real size is 0x000068 so we have padding stored at master.offset
= 0xf98

Now our symbol looks as follows

  Offset          Type                Sym. Value    Name
000000432b20  R_X86_64_DTPOFF64   0000000000000058 errno

The old code did 0x7ffff6c50000 + 0xf98 + 000000432b20 which is
obviosly overflowing the memory and wrong.

The right way 0x7ffff6c50000 + 0xf98 + 0000000000000058.

THe Tls base part and offset are added at __tls_get_addr function.
What is left is storing the 0x58 at the relocation address. The problem
is that we don't have 0x58, but we have (binary base + 0x58) in global
symbol table and binary base so what we store is the (binarybase + 0x58
- binary base).

I hope this does turn out to be wrong.
2020-07-18 20:45:37 +02:00
Wren Turkal 9a1e9c327a Make byte stream functions set stream orientation.
When a byte-oriented stream function touches a stream, that stream
should be set to byte-oriented mode if it hasn't been set yet. If
it has been set, the opertion should only succeed if the stream is
already in byte-oriented mode.

Signed-off-by: Wren Turkal <wt@penguintechs.org>
2020-07-08 14:33:11 -07:00
Wren Turkal 746a86a267 Add unlocked variation of fwide function.
Signed-off-by: Wren Turkal <wt@penguintechs.org>
2020-07-08 14:33:11 -07:00
Wren Turkal b623e245c0 Make freopen reset the stream orientation.
Signed-off-by: Wren Turkal <wt@penguintechs.org>
2020-07-08 14:33:11 -07:00