1565 Commits

Author SHA1 Message Date
Red Bear OS 628d5c2a51 0.3.0: add dual-toolchain VaList ABI probe and macros (relibc check passes) 2026-07-06 20:33:17 +03:00
vasilito 5004e94d1d 0.3.0: fix relibc build for Rust 2024 + VaList API (cargo check passes) 2026-07-06 19:37:02 +03:00
vasilito 4ef7e57571 0.3.0: converge relibc to upstream 0.6.0 + Red Bear patches 2026-07-06 19:13:57 +03:00
Jeremy Soller 1a0edd8eeb Add program_invocation_short_name 2020-12-23 20:24:04 -07:00
Jeremy Soller 2f3987dd88 Add _SC_GETPW_R_SIZE_MAX 2020-12-23 19:47:53 -07:00
Jeremy Soller d1ee653b5c Add dirfd 2020-12-23 19:47:44 -07:00
Jeremy Soller 928b18b306 Add sysexits.h 2020-12-23 13:45:25 -07:00
Jeremy Soller 5ae7b7efe7 Use new semaphore to prevent spinning 2020-12-23 12:20:19 -07:00
Jeremy Soller 2f69f0e7f1 Add simple semaphore implementation using futex 2020-12-23 12:18:17 -07:00
Jeremy Soller 79452dbd80 Remove warnings in elf.h 2020-12-23 12:18:02 -07:00
Jeremy Soller bddd69d0c1 Print when abort is called 2020-12-23 11:20:07 -07:00
Jeremy Soller 5efaffe0f9 Ensure that nul test is passed after last commit and failed before 2020-12-23 08:25:44 -07:00
Jeremy Soller 94a6da9116 Fix lookahead buffer reading nul's 2020-12-23 08:20:11 -07:00
Jeremy Soller 07ec3b6591 Merge branch 'mk-subs' into 'master'
Add submodules target to main makefile

See merge request redox-os/relibc!323
2020-10-18 19:48:03 +00:00
hasheddan e5539a570f Add submodules target to main makefile
Adds a submodules convenience target to main makefile. Submodules must
be initialized before other targets can run successfully.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-10-18 13:45:29 -05:00
Jeremy Soller 9529e09568 Force overwrite of libc.so.6 if it exists 2020-10-06 11:12:42 -06:00
Jeremy Soller 29e2f29231 Merge branch 'fmt' into 'master'
Fix formatiing issues

See merge request redox-os/relibc!316
2020-10-02 03:22:42 +00:00
Jeremy Soller 3e49323a3a Merge branch 'dlopen' into 'master'
Add support for dlopen(NULL, ...)

See merge request redox-os/relibc!315
2020-10-02 03:21:42 +00:00
Jeremy Soller 21e72cafc6 Merge branch 'tls' into 'master'
Fix tls tests for dynamic linker

See merge request redox-os/relibc!317
2020-10-02 03:20:50 +00:00
Mateusz Tabaka eee9a80baa Fix tls tests for dynamic linker
* load TLS segment for executable - while we can skip PT_LOAD for executable,
  we still have to load TLS segment.
* set TCB address based on if elf is position independent
2020-10-01 15:45:55 +02:00
Mateusz Tabaka 79643c293b Fix formatiing issues 2020-09-30 11:40:38 +02:00
Mateusz Tabaka c11aad71b8 Add support for dlopen(NULL, ...) 2020-09-30 11:04:10 +02:00
Jeremy Soller 687f4d4923 Merge branch 'dynamic' into 'master'
Add tests for ld_so

See merge request redox-os/relibc!314
2020-09-30 00:42:45 +00:00
Mateusz Tabaka 675101ac0e Add tests for dynamic linker 2020-09-29 23:01:52 +02:00
Mateusz Tabaka 7829a7ade9 Add support for RUNPATH 2020-09-29 23:01:48 +02:00
Mateusz Tabaka 58cc9efbc0 Call pthread_init in libc's init_array 2020-09-29 19:20:24 +02:00
Mateusz Tabaka 42acd32ac0 Fix TCB master address 2020-09-29 19:15:21 +02:00
Mateusz Tabaka b05d8df5f8 Restore previous load address for ld_so
Current value gives us 0x1234000 - 0x400000 ~ 14 MB for executable,
which is too low for certain programs.
2020-09-29 18:58:35 +02:00
Mateusz Tabaka c000373a08 Add symlink from libc.so to libc.so.6
Typically it's the other way around, but we can't have shared library named libc.so.6 in target/release directory.
cargo includes 'target/release' in LD_LIBRARY_PATH for build script, so even if clean build runs fine,
every subsquent run will make build script link with relibc.
2020-09-29 00:08:11 +02:00
Jeremy Soller 2c6114be75 Merge branch 'asctime-ub-asserts' into 'master'
Catch UB in asctime_r()

See merge request redox-os/relibc!312
2020-09-17 23:19:08 +00:00
Peter Limkilde Svendsen 00642dd940 Test extreme tm member values 2020-09-17 23:10:13 +02:00
Peter Limkilde Svendsen aef1be7c1b Remove errno setting 2020-09-17 23:10:13 +02:00
Peter Limkilde Svendsen 8ef64676fe Use stricter/simpler type handling 2020-09-17 23:10:13 +02:00
Peter Limkilde Svendsen 18a12c6c3d Add range assertions to asctime_r() 2020-09-17 23:10:13 +02:00
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
Jeremy Soller 9f25fa39ea Merge branch 'gmtime-tests' into 'master'
Add more gmtime() tests

See merge request redox-os/relibc!308
2020-09-08 18:44:55 +00:00
Peter Limkilde Svendsen ff6bc68260 Add more gmtime() tests 2020-09-08 18:44:55 +00:00
Jeremy Soller f285128657 Merge branch 'asctime-char-cast' into 'master'
Avoid assuming c_char is i8 in asctime()

See merge request redox-os/relibc!307
2020-09-08 18:44:38 +00:00
Jeremy Soller dd193bcb8c Merge branch 'fix-asprintf-test-free' into 'master'
Add needed include for asprintf() test

See merge request redox-os/relibc!306
2020-09-08 18:43:57 +00:00
Jeremy Soller 4a6ef0221f Merge branch 'weak_rust_probestack' into 'master'
link: Weaken __rust_probestack symbol

See merge request redox-os/relibc!310
2020-09-06 13:04:34 +00:00
Esteban Blanc 9e0e88346d link: Weaken __rust_probestack symbol 2020-09-06 10:26:42 +02:00
Peter Limkilde Svendsen 59b0a36e81 Fix localtime() test 2020-08-27 23:16:17 +02: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
Jeremy Soller 3a0d2177cd Variable for weakened symbols, weaken umodti3 2020-08-25 08:21:31 -06:00
Peter Limkilde Svendsen 23b2eb2573 Avoid assuming c_char is i8 2020-08-23 21:45:08 +02:00
Jeremy Soller 5472e117a5 Weaken __fixdfti 2020-08-21 21:28:51 -06:00
Peter Limkilde Svendsen aec4a84e90 Include stdlib.h so free() can be used 2020-08-20 20:43:28 +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
oddcoder 9826cea092 Add SONAME for libc.so
Usually it is possible to refer to library either by the file name or by
elf "soname" soname is very similar for specifying something like
(LIB/API version) combination so if for example you have ./prog that
loads libx.so which is version 5.1.1 and there is ./plugin.so that ./prog
would load that requires libx.so version 5.1.2 both libx.so should have
the same soname to hint that they offer the exact same functionality.
And this patch specifies the soname for relibc libc.so.
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
jD91mZM2 d827c0f166 Run Linux tests in CI
commit 09cb17e66f46c6687fa0b9dc0895ad3279caa092
Author: jD91mZM2 <me@krake.one>
Date:   Mon Aug 10 18:03:20 2020 +0200

    comment out cargo tests

commit 1915c7306e40f5c6af36b04c765e25ad9ffe9d16
Author: jD91mZM2 <me@krake.one>
Date:   Mon Aug 10 17:58:52 2020 +0200

    Update redoxer docker image
2020-08-11 11:14:13 +02:00
Jeremy Soller 91f0be8790 Merge branch 'weaken_floattidf' into 'master'
Also weaken `__floattidf`

See merge request redox-os/relibc!299
2020-08-08 14:15:55 +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 d08c63b1e7 Merge branch 'fix-ci' into 'master'
Fix CI

See merge request redox-os/relibc!302
2020-08-07 14:16:45 +00: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
Jeremy Soller 4f93e43593 Merge branch 'fix-linker' into 'master'
Make linker work somewhat on Redox

See merge request redox-os/relibc!296
2020-08-04 12:24:51 +00: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
James Graves 00b08605a3 Also weaken __floattidf
Fixes link error with ion shell.
2020-08-03 14:37:32 -05:00
Jeremy Soller 2073d2a80e Use objcopy to remove duplicate symbols 2020-08-02 20:41:45 -06:00
Jeremy Soller 2008296a10 Add sys_mman expected output 2020-08-02 14:34:56 -06: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 12777ba774 Use 2020-07-27 nightly, it has rustfmt 2020-08-02 13:06:44 -06:00
Jeremy Soller f2c2d7c52e Fix compilation on newer nightly, update nightly to 2020-08-01 2020-08-02 12:24:49 -06:00
Jeremy Soller f131391b0d Merge branch 'memory' into 'master'
Make munmap use funmap2

See merge request redox-os/relibc!297
2020-07-30 14:04:06 +00:00
jD91mZM2 7d4d73dd83 Update redox_syscall 2020-07-30 15:58:21 +02: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 285a7c62d4 Use mmap2 version of redox_syscall. 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
Jeremy Soller 677f0c989d Merge branch 'dlopen_dlclose_dlsym' into 'master'
Dlopen dlclose dlsym

See merge request redox-os/relibc!290
2020-07-19 19:35:31 +00: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
Jeremy Soller cf8cbe625b Merge branch 'allocator' into 'master'
Allocator

See merge request redox-os/relibc!295
2020-07-18 19:51:37 +00: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
Jeremy Soller 04f77881d0 Merge branch 'TLS' into 'master'
Fix wrong TLS resolving

See merge request redox-os/relibc!294
2020-07-18 18:48:14 +00: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
jD91mZM2 e17c6049c6 Fix libgmp compilation 2020-07-15 11:12:59 +02:00
Jeremy Soller cbd7ead0ff Merge branch 'add_fwide' into 'master'
Add fwide function

See merge request redox-os/relibc!291
2020-07-09 12:29:53 +00: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
Wren Turkal 865b7962a1 Add implmentation for fwide posix function.
This function is used to set the orientation of a stream to either
byte-oriented or wchar-oriented.

More info on this function is here:
https://man7.org/linux/man-pages/man3/fwide.3p.html

This implementation only impmlemnts the manual switching and does
not yet guard against using a byte-oriented stream with wchar
functions and vice versa. Those step will come in additional
commits.

Signed-off-by: Wren Turkal <wt@penguintechs.org>
2020-07-08 14:33:06 -07:00
Jeremy Soller c13ba64832 Merge branch 'socketpair' into 'master'
Various socket-related changes and other

See merge request redox-os/relibc!289
2020-07-01 13:56:58 +00:00
jD91mZM2 29ad5b75c9 Fix broken CVec
Oops, forgot to initiate the pointer after uses of CVec::new()
2020-06-29 21:03:29 +02:00
jD91mZM2 56e1eceb28 Replace AllocStringWriter with CVec 2020-06-29 17:44:57 +02:00
jD91mZM2 39ce623d2d Fix bind/connect's AF_UNIX socket path... again
I don't really know for sure what all these silly rules are, but I think
I got it now...
2020-06-29 11:36:07 +02:00
jD91mZM2 593925ceb4 Unambiguate all include guards
GNU binutils also uses _FNMATCH_H for a guard, maybe along others!
2020-06-29 11:34:51 +02:00
jD91mZM2 f8b49936bc Various unix socket fixes (+socketpair!) 2020-06-27 16:39:50 +02:00
jD91mZM2 b7053b673d Fix missing types when compiling GDB 2020-06-25 13:03:06 +02:00
Jeremy Soller 7ea5cd5133 Merge branch 'rename-lcg48-rand48' into 'master'
Rename lcg48 module as rand48

See merge request redox-os/relibc!287
2020-06-24 16:55:27 +00:00
Jeremy Soller ce2de698c4 Merge branch 'random-alignment' into 'master'
Don't assume u32 alignment of random() state buffer

See merge request redox-os/relibc!286
2020-06-24 16:46:59 +00:00
Peter Limkilde Svendsen 5c8393d5aa Don't assume u32 alignment of random() state buffer 2020-06-24 16:46:59 +00:00
Jeremy Soller 954f010cc1 Merge branch 'pie' into 'master'
Fix bugs in handling non pie elfs

See merge request redox-os/relibc!285
2020-06-24 12:33:47 +00:00
oddcoder 5fcf920675 Fix bugs in handling non pie elfs
The problem here was that we alway added the base address, and we
assumed that all addresses we access are relative but this is not the
case in case of non pie binaries. The issue is that all addresses were
base+offset. so if we added the base again it will ofcourse generate
wrong address.
2020-06-24 10:21:20 +02:00
Peter Limkilde Svendsen 59b040258a Rename lcg48 as rand48 2020-06-23 18:34:44 +02:00
Jeremy Soller 547edcc267 Merge branch 'arpa_inet-types' into 'master'
Use C type names in byteorder functions

See merge request redox-os/relibc!274
2020-06-22 21:57:24 +00:00
Jeremy Soller 22a7f71282 Merge branch 'ctime_r' into 'master'
Add test for ctime_r(), replace mem::uninitialized()

See merge request redox-os/relibc!273
2020-06-22 21:57:04 +00:00
Jeremy Soller c95a5fa574 Merge branch 'random' into 'master'
Implement random() and friends

See merge request redox-os/relibc!284
2020-06-22 21:56:39 +00:00
Peter Limkilde Svendsen cc33874363 Implement random() and friends 2020-06-22 21:56:39 +00:00
Jeremy Soller db6a589421 Merge branch 'LD_LIBRARY_PATH' into 'master'
Ld library path

See merge request redox-os/relibc!279
2020-06-20 13:17:40 +00:00
Jeremy Soller d7089a09bf Merge branch 'LD_SO_ASM_REM' into 'master'
Get rid of assembly code in call_inits_finis

See merge request redox-os/relibc!282
2020-06-20 13:13:26 +00:00
oddcoder 0977133cc9 Get rid of assembly code in call_inits_finis 2020-06-20 15:01:13 +02:00
Jeremy Soller 73e1d6307b Merge branch 'socket-fix' into 'master'
Socket fix

See merge request redox-os/relibc!281
2020-06-19 11:58:24 +00:00
jD91mZM2 cdc9aa06e3 Fix getpeername
Rust's TcpListener fails because of the address format being wrong. The format
comes from `accept`, but there we internally use this function.
2020-06-19 13:56:06 +02:00
Jeremy Soller ca8b848b48 Merge branch 'headers' into 'master'
Headers

See merge request redox-os/relibc!280
2020-06-14 20:38:04 +00:00
oddcoder f4d95ce43f Add sys/select.h to sys/types.h
This was triggered by gcc for some reason It included sys/types.h and
assumed sys/select.h to be there. And that seams to be the case in musl.

The problem with relibc here is that sys/types.h is are part of relibc
"include/*.h" files, while sys/select.h is generated by cbindgen. That
makes it impossible to #include select.h in types.h epsecially that
there are files like fcntl.c that uses types.h. They would complain
about missing headers. I fixed this by renaming sys/types.h to
sys/types_internal.h and then generating types.h using cbindgen as well
except for that. however fcntl and dlmalloc can include types_internal
instead of types.h
2020-06-14 22:00:16 +02:00
oddcoder a125b8be15 Make stdbool.h C++ compatiable
The problem here is that _Bool type is not defined in C++ yet this file
is using it. That leads to issues when compiling gcc. I borrowed the
same techniques used in other stdbool.h
2020-06-14 22:00:10 +02:00
oddcoder 81da1bb1a3 Fix the avoid accessing errno issue from ld_so for real this time
This patch implements access function for both redox and linux and makes
sure that neither access errno variable
2020-06-13 19:55:33 +02:00
no name d5b63a85a4 Revert "Fix compilation on Redox by removing use of access in ld_so"
This reverts commit d9bacaec04.
2020-06-13 19:55:33 +02:00
no name c3ae8022ba Revert "Handle missing paths in load_library search without using access"
This reverts commit b0dde81c75.

The main issue was not with "access" being used, it was with errno being
accessed. This patch accesses errno as well

LD_LIBRARY_PATH="/folder/with/no/libc" ./a.out

gives segfault with the following stack trace

0x00000000004d1cae in relibc::platform::sys::e (sys=18446744073709551614) at src/platform/linux/mod.rs:54
 54                  errno = -(sys as isize) as c_int;
(gdb) bt
 #0  0x00000000004d1cae in relibc::platform::sys::e (sys=18446744073709551614) at src/platform/linux/mod.rs:54
 #1  0x00000000004d361e in <relibc::platform::sys::Sys as relibc::platform::pal::Pal>::open (path=0x5555555634c0, oflag=524288, mode=0) at src/platform/linux/mod.rs:330
 #2  0x000000000049a2ad in relibc::fs::File::open (path=0x5555555634c0, oflag=524288) at src/fs.rs:28
 #3  0x0000000000482b49 in relibc::ld_so::linker::Linker::load_recursive (self=0x7fffffffdd30, name=..., path=...) at src/ld_so/linker.rs:119
 #4  0x0000000000484963 in relibc::ld_so::linker::Linker::load_library (self=0x7fffffffdd30, name=...) at src/ld_so/linker.rs:184
 #5  0x0000000000483b53 in relibc::ld_so::linker::Linker::load_data (self=0x7fffffffdd30, name=..., data=...) at src/ld_so/linker.rs:152
 #6  0x00000000004831fe in relibc::ld_so::linker::Linker::load_recursive (self=0x7fffffffdd30, name=..., path=...) at src/ld_so/linker.rs:140
 #7  0x000000000048228a in relibc::ld_so::linker::Linker::load (self=0x7fffffffdd30, name=..., path=...) at src/ld_so/linker.rs:97
 #8  0x0000000000414a3b in relibc_ld_so_start (sp=0x7fffffffe310, ld_entry=4198896) at src/ld_so/start.rs:182
 #9  0x0000000000401209 in _start () at src/ld_so/src/lib.rs:10
 #10 0x0000000000000001 in ?? ()
 #11 0x00007fffffffe592 in ?? ()
 #12 0x0000000000000000 in ?? ()
2020-06-13 19:55:33 +02:00
Jeremy Soller 68679e41f0 Add redoxer.sh script to simplify running tests on redox 2020-06-09 20:55:55 -06:00
Jeremy Soller b771313ffd Merge branch 'master' of https://gitlab.redox-os.org/redox-os/relibc 2020-06-07 14:01:00 -06:00
Jeremy Soller b0dde81c75 Handle missing paths in load_library search without using access 2020-06-07 14:00:48 -06:00
Jeremy Soller 7bc11dc6c2 Merge branch 'relibc-netdb-v1' into 'master'
netdb: implement getnetbynane and getnetent

See merge request redox-os/relibc!278
2020-06-07 12:27:54 +00:00
Giuseppe Longo 12beb13987 netdb: implement getnetbynane and getnetent
This patch implements getnetbyname and getnetent functions.
2020-06-07 14:02:41 +02:00
Jeremy Soller d9bacaec04 Fix compilation on Redox by removing use of access in ld_so 2020-06-06 21:00:57 -06:00
Jeremy Soller d0c1160299 Merge branch 'scanf' into 'master'
Scanf

See merge request redox-os/relibc!277
2020-06-06 19:32:54 +00:00
oddcoder 92d6735e3f Add more scanf tests 2020-06-03 23:20:53 +02:00
oddcoder 8973535fdc Make scanf write to string and increase match count only when a pattern is matched
This is the behavior of glibc which I assume to be right
2020-06-03 23:20:52 +02:00
oddcoder 018f7a3f38 Fix scanf.stdout as per glibc 2020-06-03 23:20:52 +02:00
oddcoder a49139ca2f use lookahead buffer in inner_scanf 2020-06-03 23:20:52 +02:00
oddcoder 14e011b72c Implemment lookaheadreader with lookahead and commit api
The LookAheadReader api works similar to read but it has 2 methods,
lookahead: it will read 1 byte (with internal ftell) without modifying
the file's own ftell() and commit() which saves the current file ftell

LookAheadReader can wrap both buffers and files
2020-06-03 23:20:52 +02:00
oddcoder f068673adc Separate the logic from locking in ftello and fseeko 2020-06-03 23:20:52 +02:00
oddcoder 164ef739b3 Apply Cargo fmt for src/ld_so 2020-06-03 23:20:52 +02:00
Jeremy Soller 12d3838f42 Merge branch 'fpermissive' into 'master'
FIX error: right operand of shift expression '(1 << BLA)' is greater than or...

See merge request redox-os/relibc!276
2020-06-02 21:52:17 +00:00
no name c02849dd73 FIX error: right operand of shift expression '(1 << BLA)' is greater than or equal to the precision BLA of the left operand [-fpermissive] 2020-06-02 23:27:15 +02:00
Jeremy Soller 5aa74fd2f3 Merge branch 'master' of https://gitlab.redox-os.org/redox-os/relibc 2020-06-02 08:35:41 -06:00
Jeremy Soller 604f1c11a2 Build xargo locally 2020-06-02 08:35:37 -06:00
Jeremy Soller b165eacffd Remove unnecessary compiler-builtins patch 2020-06-02 08:30:06 -06:00
Jeremy Soller e7f5e412a1 Merge branch 'LD_LIBRARY_PATH' into 'master'
Ld library path

See merge request redox-os/relibc!275
2020-06-01 12:23:46 +00:00
oddcoder 3aacc160a1 Remove dependency on errno in ld.so
During early parts of ld.so, errno and other thread local variables are
not yet initialized so we cannot use function (such as unistd::access)
that depends on such thread local variables (errno). For this reason
this patch creates small wrapper around the syscall that doesn't not
touch the errno
2020-06-01 11:49:38 +02:00
oddcoder 1b10c3d246 Prioterize search path instead of overwriting it.
Current LD_LIBRARY_PATH implementation overwrites the original search
path, which is not the best idea, instead this patch would check
LD_LIBRARY_PATH first and if it didn't find the libraries it is looking
for, then it will search the original search path
2020-06-01 11:41:19 +02:00
Jeremy Soller c7910a8754 Add __need_winit_t to wctype.h 2020-05-28 13:43:55 -06:00
Peter Limkilde Svendsen e4a7186b22 Use C type names in byteorder functions 2020-05-28 20:17:57 +02:00
Jeremy Soller ae34ade595 Use path to patch compiler-builtins 2020-05-27 20:24:59 -06:00
Jeremy Soller 8de10072b6 Add compiler-builtins patch 2020-05-27 20:18:52 -06:00
Peter Limkilde Svendsen ac52c3f205 Replace mem::uninitialized() 2020-05-26 17:58:59 +02:00
Peter Limkilde Svendsen b15c90ee32 Add test for ctime_r() 2020-05-26 00:20:14 +02:00
Jeremy Soller b2338968a2 Merge branch 'alignment-test-nullcheck' into 'master'
Don't accept null pointer in tests when requesting aligned memory

See merge request redox-os/relibc!272
2020-05-24 19:19:12 +00:00
Jeremy Soller 39346f5c05 Merge branch 'simplify-posix_memalign' into 'master'
Minor fixes to posix_memalign()

See merge request redox-os/relibc!271
2020-05-24 19:18:53 +00:00
Peter Limkilde Svendsen cf9c2ed0ba Don't accept null pointer when requesting aligned memory 2020-05-24 18:39:53 +02: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
Jeremy Soller e4c26cfaa0 Merge branch 'gcc-regressions' into 'master'
Gcc regressions

See merge request redox-os/relibc!270
2020-05-23 15:16:36 +00:00
oddcoder 7eba6d88df Add test for negative pad stupport in printf 2020-05-23 16:20:20 +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 1b131b8c60 Test off by one bug in vfscanf 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 6fba592fdb Implement regression test for ftell-ungetc bug 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 49dec86a5d Unit test arbitrarily long ungetc() 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
oddcoder 4c94dfac00 Add type definition for caddr_t
Normally one shouldn't be using this datatype ever, but then someone
have to tell that to gcc folks :(
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
Jeremy Soller f6a119d3fc Merge branch 'binutils_regressions' into 'master'
Binutils regressions

See merge request redox-os/relibc!269
2020-05-13 22:02:31 +00: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 a39447e6a4 Test printf space padding regression 2020-05-08 22:38:42 +02:00
oddcoder d373bcb032 Avoid accessing memory without initialization 2020-05-08 22:38:42 +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
Jeremy Soller 8b7c45b39e Merge branch 'ld.so_regressions' into 'master'
Ld.so regressions

See merge request redox-os/relibc!268
2020-05-03 13:16:43 +00: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
Jeremy Soller c799dad4e9 Merge branch 'wide-strings' into 'master'
Wide strings Functions

See merge request redox-os/relibc!267
2020-05-02 12:56:51 +00:00
oddcoder e9615065ac Add tests for both wcsncasecmp and wcscasecmp 2020-04-26 19:13:03 +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 9725d3418a Test towlower and towupper 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
Jeremy Soller a8a73f87c7 Merge branch 'procfs' into 'master'
Implement #include<sys/user.h> and #include<sys/procfs.h>

See merge request redox-os/relibc!266
2020-04-24 22:47:59 +00: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
Jeremy Soller 763bb2488d Merge branch 'init_fini_ld.so' into 'master'
Init fini ld.so

See merge request redox-os/relibc!265
2020-04-19 12:40:00 +00: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
Jeremy Soller 77ad82a9dd Merge branch 'sigaction-restore' into 'master'
sigaction should set sigaction.sa_restorer

See merge request redox-os/relibc!264
2020-04-15 17:56:27 +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
Jeremy Soller cdbbd4a426 Merge branch 'cbindgen' into 'master'
Remove vendored cbindgen, use cbindgen dependency to generate includes in build.rs

See merge request redox-os/relibc!261
2020-04-10 23:05:58 +00:00
Graham MacDonald 2253ef609e Remove vendored cbindgen, use cbindgen dependency to generate includes in build.rs 2020-04-10 23:05:58 +00:00
Jeremy Soller 69fc62278a Merge branch 'use_kernel_loaded_elf' into 'master'
Use Kernel mapped binaries when available.

See merge request redox-os/relibc!262
2020-04-07 21:42:37 +00: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 d7a859fb84 Keep exported functions 2020-03-24 20:05:38 -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 2629918100 Fix issue if test:redox is run without build:redox 2020-03-10 21:12:40 -06:00
Jeremy Soller 0090396132 Run cargo test 2020-03-10 21:03:52 -06:00
Jeremy Soller 880e3c7854 Merge branch 'master' of https://gitlab.redox-os.org/redox-os/relibc 2020-03-10 20:57:13 -06: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 77a0294114 Merge branch 'stdc-compatiability' into 'master'
Stdc compatiability

See merge request redox-os/relibc!258
2020-03-06 03:58:42 +00:00
oddcoder 3ac6ef1848 Adjust stddef.h to be compatiable with other libc(s)
I faced many issues when compiling libstdC++-V3 and linking against
relibc mainly:
- Missing types (max_align_t)
- Different types definitions(ptrdiff_t , size_t)
- and the fact that wchar_t is part of standard C++ and it seams that we
  canno redefine standard types
2020-03-02 00:06:49 +02:00
oddcoder a2f2484e45 Add minimal basic features.h resembling musl lib's own 2020-03-01 22:59:39 +02:00
Jeremy Soller 79f265745a Fix redox ld_so 2020-02-28 19:33:20 -07:00
Jeremy Soller b1aad49df4 Merge branch 'linux-ld' of gitlab.redox-os.org:oddcoder/relibc 2020-02-28 19:12:19 -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
Jeremy Soller e85148cc15 Merge branch 'oddcoder-master-patch-78534' into 'master'
Fix make libs in CI

See merge request redox-os/relibc!256
2020-02-18 17:09:48 +00:00
Ahmed Abd El Mawgood 9f86748a58 Fix make libs in CI
There is no make libc

➜  relibc git:(master) make libc
make: *** No rule to make target 'libc'.  Stop.
2020-02-14 18:42:38 +00:00
Jeremy Soller 3d2f86b39e Merge branch 'feature/support-af-unix-sockets' into 'master'
Support AF_UNIX sockets

See merge request redox-os/relibc!255
2020-02-07 02:19:42 +00: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
Jeremy Soller 1534373645 Merge branch 'ctype_conv' into 'master'
Use lossless type conversion in ctype.h

See merge request redox-os/relibc!246
2020-01-20 17:57:56 +00:00
Peter Limkilde Svendsen 0b4b3cd55c Use lossless type conversion in ctype.h 2020-01-20 17:57:56 +00:00
Jeremy Soller 10f2e0fefc Merge branch 'fd-dup-test-robusty' into 'master'
Fix fd dup tests to be more robust

See merge request redox-os/relibc!251
2020-01-20 17:48:43 +00:00
Jeremy Soller c6e3cb8ed3 Merge branch 'no-uninit' into 'master'
Replace occurences of uninitialized with MaybeUninit

See merge request redox-os/relibc!248
2020-01-20 16:54:22 +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 7d6288abbe Merge branch 'samuela-master-patch-09777' into 'master'
Fix ar usage in Makefile for macOS compatibility

See merge request redox-os/relibc!253
2020-01-20 16:41:24 +00:00
Jeremy Soller f167081f84 Merge branch 'fix-test' into 'master'
Re-enable netdb tests, fix compiler warning, improve brk coverage

See merge request redox-os/relibc!254
2020-01-20 16:22:09 +00:00
Graham MacDonald 18e1a5608f Re-enable netdb tests, fix compiler warning, improve brk coverage 2020-01-13 22:22:40 +00:00
samuela 0be4208aa7 Fix ar usage in Makefile for macOS compatibility 2020-01-08 17:59:38 +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
Jeremy Soller 36eb561128 Format 2019-12-18 20:01:48 -07:00
Jeremy Soller 086c8f6702 Allow running linker more than once 2019-12-17 21:35:47 -07:00
Jeremy Soller 0a06388d2a Store globals and mappings on Linker struct 2019-12-16 21:27:42 -07:00
Jeremy Soller b882ce527d Fix allocation of TLS masters if main image does not require TLS 2019-12-15 11:19:37 -07:00
Jeremy Soller 4818ad61ab Always zero mmap'd memory 2019-12-15 07:46:59 -07:00
Jeremy Soller 886f859bb9 Clear FPU registers before jumping to loaded program 2019-12-15 07:46:49 -07:00
Jeremy Soller 76798b7d6b Merge branch 'master' of https://gitlab.redox-os.org/redox-os/relibc 2019-12-06 19:55:21 -07:00
Jeremy Soller fe3607d4e8 ld_so: Zero mapped memory and panic on unsupported relocation 2019-12-06 19:54:54 -07:00
Jeremy Soller 5baec1e4e8 Merge branch 'printf-inf-nan' into 'master'
Handle infinity and NaN in printf

See merge request redox-os/relibc!252
2019-12-05 01:37:17 +00:00
Peter Limkilde Svendsen 74555698fb Handle infinity and NaN in printf 2019-12-05 01:37:17 +00:00
Sean Kennedy a1c3510761 Fix fd dup tests to be more robust
i.e. not depending on the first fd to be 4.
2019-12-02 14:53:55 -05:00
Jeremy Soller 8ba70792e9 Implement DTPOFF64 2019-12-01 13:47:06 -07:00
Jeremy Soller 2ac349d2d2 Add msync function and stub for Redox 2019-12-01 10:58:47 -07:00
Jeremy Soller 15e6d23538 Update rust-toolchain 2019-11-29 18:06:12 -07:00
Jeremy Soller e3ce41da79 Fix compilation on newer nightly 2019-11-29 18:05:31 -07:00
Jeremy Soller 3db0588de0 Merge branch 'ctime_r' into 'master'
added ctime_r

See merge request redox-os/relibc!250
2019-11-28 02:41:58 +00:00
Andrzej J. Skalski 278a70c813 added ctime_r 2019-11-28 02:41:58 +00:00
Jeremy Soller 631fd4f0f5 Merge branch 'wcsstr' into 'master'
Implement wcsstr(), fix return type of wcslen()

See merge request redox-os/relibc!249
2019-11-14 02:46:53 +00:00
Peter Limkilde Svendsen 0b2c3fe5ea Implement wcsstr(), fix return type of wcslen() 2019-11-14 02:46:53 +00:00
Jeremy Soller ae69586f20 Implement getrlimit on Linux and stub on Redox 2019-09-18 20:29:25 -06:00
Jeremy Soller 46a330ec9e Fix compilation of sys/resource 2019-09-18 15:55:27 -06:00
Xavier L'Heureux f53e9b5d9a Remove the mkfifo test 2019-09-17 21:41:03 -04:00
Xavier L'Heureux e8b8b7eb25 Fix format and disable stat check for access time 2019-09-17 21:23:07 -04:00
Xavier L'Heureux 64f93fe6e0 Implement the truncate function 2019-09-17 19:57:43 -04:00
Xavier L'Heureux 5156a13b3e Add a test for futimens 2019-09-16 12:25:29 -04:00
Jeremy Soller 64dde1548c Merge branch 'patch-2' into 'master'
sys/uio.h: include sys/types.h

See merge request redox-os/relibc!244
2019-09-15 19:34:43 +00:00
Jeremy Soller 3b12a400bf Merge branch 'lcg48_refactor' into 'master'
lcg48 refactor

See merge request redox-os/relibc!243
2019-09-15 19:34:12 +00:00
Peter Limkilde Svendsen 7fdd450e16 lcg48 refactor 2019-09-15 19:34:12 +00:00
Jeremy Soller cc4c3a5cb4 Merge branch 'a64l_l64a_refactor' into 'master'
Refactor of a64l and l64a

See merge request redox-os/relibc!242
2019-09-15 19:33:29 +00:00
Peter Limkilde Svendsen a80ec357e3 Refactor of a64l and l64a 2019-09-15 19:33:29 +00:00
Jeremy Soller d1d45ff00d Merge branch 'warning' into 'master'
Fix few warnings

See merge request redox-os/relibc!236
2019-09-15 19:31:08 +00:00
Jeremy Soller f4b8847605 Merge branch 'mut-program_invocation_name' into 'master'
Make program_invocation_name modifiable

See merge request redox-os/relibc!240
2019-09-15 19:30:31 +00:00
Xavier L'Heureux 30d3cd5c88 Fix the mkfifo call on Linux and add a test to avoid regression 2019-09-13 12:35:08 -04:00
Matija Skala 81470916be sys/uio.h: include sys/types.h
needed for ssize_t
2019-09-08 08:36:22 +00:00
Steve McKay 4859c222e7 Make program_invocation_name modifiable
libiconv expects program_invocation_name to be an lvalue
2019-08-17 12:35:43 -04:00
jD91mZM2 4f2a93ea90 Vast refactor of pwd.h, add getpwent/setpwent/endpwent 2019-08-12 09:58:11 +02:00
jD91mZM2 aeab6a986d Fix a few GDB compilation issues 2019-08-12 09:30:05 +02:00
Jeremy Soller 8f502a3436 Merge branch 'fix-signal' into 'master'
Fix invalid memory reference in signal and sigaction

See merge request redox-os/relibc!239
2019-08-12 02:54:28 +00:00
Xavier L'Heureux 5799555566 Remove print statements 2019-08-11 21:53:32 -04:00
Xavier L'Heureux f2357390e9 Fix redox's implementation 2019-08-11 21:06:47 -04:00
Xavier L'Heureux 0a558de76c Fix reference getting moved
The sigaction handler called map on an option, creating a pointer to a
move value. This in turned caused UB for signal handlers. Avoid using
pointers directly, and instead prefer references.
2019-08-11 20:47:18 -04:00
Xavier L'Heureux 225583230f Test 2019-08-11 18:11:19 -04:00
Xavier L'Heureux 4c7f8c6369 test signals 2019-08-11 14:30:00 -04:00
Jeremy Soller 37a5da34b9 Fix pte_osSemaphorePend deadlock 2019-08-09 21:18:20 -06:00
Jeremy Soller e7d19e2a58 Move SIG_IGN and friends to C in order to define them correctly 2019-08-08 20:06:38 -06:00
Jeremy Soller 8feed5bbd5 Update Rust to 2019-08-08 2019-08-07 20:48:29 -06:00
jD91mZM2 a7b354c8e0 Update to latest syscall after merging ptrace 2019-08-04 19:46:10 +02:00
jD91mZM2 a1e45941bf Fix ptrace after latest kernel changes 2019-08-04 19:05:45 +02:00
jD91mZM2 b8c50c7c64 Format 2019-08-04 19:05:45 +02:00
jD91mZM2 c7d499d4f2 Upgrade to the 2018 edition
I didn't think it'd be this useful first, but thank god for `cargo fix --edition`!
2019-08-04 19:05:45 +02:00
jD91mZM2 72c2f59f17 Update redox_syscall to use bitflags 2019-08-04 19:05:45 +02:00
jD91mZM2 82abb3313e Support adding WUNTRACED 2019-08-04 19:05:45 +02:00
jD91mZM2 f389010fff Initial ptrace compatibility for Redox OS 2019-08-04 19:05:45 +02:00
jD91mZM2 7f702720af Fix header file generation for ptrace 2019-08-04 19:05:44 +02:00
jD91mZM2 43ff8801bc Format 2019-08-04 19:05:44 +02:00
jD91mZM2 35c1d5210c Implement the Once<T> synchronization structure
Not sure if I should add a RwLock for the ptrace state too...
2019-08-04 19:05:44 +02:00
jD91mZM2 e559a3e2e5 Stub for ptrace
It's happening...
2019-08-04 19:05:44 +02:00
Jeremy Soller a2721b8a31 Merge branch 'cbindgen' into 'master'
Fix cbindgen for disabled headers

See merge request redox-os/relibc!237
2019-07-31 14:07:35 +00:00
Mateusz Mikuła bd573fb7cc Fix cbindgen for disabled headers 2019-07-31 12:39:28 +02:00
Jeremy Soller f467791b12 Fix definition of SIG_ERR 2019-07-25 21:27:41 -06:00
jD91mZM2 cb63dec86f Add missing SIG_DFL and SIG_IGN constants 2019-07-25 17:34:59 +02:00
Jeremy Soller 25e67b9f58 Add setsockopt support for SO_RCVTIMEO and SO_SNDTIMEO 2019-07-24 17:18:01 -06:00
Jeremy Soller 9d7ec9b146 Fix getcwd on Redox 2019-07-21 07:57:31 -06:00
Mateusz Mikuła 9aac2672e3 Fix few warnings 2019-07-18 15:27:05 +02:00
Jeremy Soller f1be9266e2 Merge branch 'defines-cleanup' into 'master'
Remove defines that are generated by new cbindgen from bits

See merge request redox-os/relibc!234
2019-07-18 12:04:01 +00:00
Jeremy Soller aba76239b3 Merge branch 'ci' into 'master'
Don't use diff on Redox

See merge request redox-os/relibc!233
2019-07-18 11:55:54 +00:00
Mateusz Mikuła b599c453a0 Remove defines that are generated by new cbindgen from bits 2019-07-18 13:18:00 +02:00
Mateusz Mikuła c40b7d6fb4 Don't use diff on Redox 2019-07-18 13:01:22 +02:00
jD91mZM2 a8280e8991 Implement wcstol, wcstod, and printf:ing wchars 2019-07-18 12:29:22 +02:00
jD91mZM2 7c99077248 Implement wcstok 2019-07-18 08:15:40 +02:00
jD91mZM2 a2c8cfb4a5 Implement CVec, an abstraction to return vectors from Rust 2019-07-18 06:40:23 +02:00
jD91mZM2 c85145b5d1 Merge branch 'memoffset-update' into 'master'
Update memoffset to fix soundness issues

See merge request redox-os/relibc!232
2019-07-13 08:57:18 +00:00
Mateusz Mikuła 87bcc943e2 Update memoffset to fix soundness issues 2019-07-12 19:43:09 +02:00
jD91mZM2 29b5b989eb Format 2019-07-11 18:20:27 +02:00
jD91mZM2 1a0f72dad8 Fix CI & compatibility with older rust 2019-07-11 18:18:17 +02:00
jD91mZM2 57917c0e92 Fix various floating point issues in printf 2019-07-11 18:09:37 +02:00
Jeremy Soller 4621a824a8 Merge branch 'sigaltstack' into 'master'
Fix sigaltstack

See merge request redox-os/relibc!230
2019-07-10 12:34:24 +00:00
Mateusz Mikuła 799c10073d Fix sigaltstack 2019-07-10 14:01:43 +02:00
jD91mZM2 a6d6d2cfb0 Merge branch 'cbindgen-update' into 'master'
Cbindgen update

See merge request redox-os/relibc!229
2019-07-10 10:08:39 +00:00
Mateusz Mikuła 63a1319e50 Cbindgen update 2019-07-10 10:08:39 +00:00
Jeremy Soller 05f71567ab Format 2019-07-06 19:37:13 -06:00
Jeremy Soller 6a97b47d3f Do not expect unistd/isatty 2019-07-06 19:32:01 -06:00
Jeremy Soller 84745ca770 Fix fsync on Redox 2019-07-06 19:27:42 -06:00
Jeremy Soller 7b406dbc61 Improve test output 2019-07-06 19:25:16 -06:00
Jeremy Soller 06bab2aa81 Fix Redox fchdir 2019-07-06 19:25:05 -06:00
Jeremy Soller 27d97f6fe0 Use O_DIRECTORY in unistd/fchdir 2019-07-06 19:21:11 -06:00
Jeremy Soller 2c3195d54b Ignore clock function in time/time 2019-07-06 19:09:24 -06:00
Jeremy Soller 634b2ed835 Use actual break in unistd/brk 2019-07-06 19:09:16 -06:00
Jeremy Soller e27b22f63c Do not test sys_epoll by default 2019-07-06 19:02:35 -06:00
Jeremy Soller eae28f6dd9 Fix scandir test on Redox 2019-07-06 18:39:41 -06:00
Jeremy Soller 5c0b37a229 Run verify script on Redox 2019-07-06 17:31:52 -06:00
Jeremy Soller a49badbb66 Build tests for redox 2019-07-06 12:57:13 -06:00
Jeremy Soller e146cb3687 Allow multiple definitions 2019-07-06 12:48:58 -06:00
Jeremy Soller 6448119fbc Update pthreads-emb 2019-07-06 11:32:34 -06:00
jD91mZM2 8656c80614 Merge branch 'sigaltstack' into 'master'
Add sigaltstack

See merge request redox-os/relibc!218
2019-07-05 12:29:53 +00:00
Mateusz Mikuła c8887900b9 Add sigaltstack 2019-07-05 12:29:53 +00:00
jD91mZM2 9fb9820b23 Merge branch 'clippy' into 'master'
Clippy fixes

See merge request redox-os/relibc!223
2019-07-04 14:47:08 +00:00
Mateusz Mikuła 6742e41948 Clippy fixes 2019-07-04 14:47:08 +00:00
Jeremy Soller 38099fe3d9 Fix definition of errno to match what is used by musl 2019-07-03 19:47:55 -06:00
Jeremy Soller 208b56b487 Revert "Allow multiple definition in ld_so to avoid linking issues"
This reverts commit b4c738eb62.
2019-07-01 16:52:19 -06:00
Jeremy Soller b4c738eb62 Allow multiple definition in ld_so to avoid linking issues 2019-07-01 16:44:07 -06:00
Jeremy Soller 456c829da8 Fix CI 2019-07-01 16:37:47 -06:00
Jeremy Soller 50be35d152 Update cbindgen 2019-07-01 16:36:41 -06:00
jD91mZM2 dc2d22b384 Merge branch 'thread_local' into 'master'
Make errno thread local

See merge request redox-os/relibc!228
2019-07-01 18:36:34 +00:00
jD91mZM2 3ae46d8616 Merge branch 'expected_alloc_test' into 'master'
Move alloc tests to expected-output tests

See merge request redox-os/relibc!226
2019-07-01 18:35:56 +00:00
Peter Limkilde Svendsen 70857f9980 Move alloc tests to expected-output tests 2019-07-01 18:35:56 +00:00
Mateusz Mikuła ff94798253 Make errno thread local 2019-07-01 16:51:19 +02:00
jD91mZM2 bf13674e11 Merge branch 'getpagesize_check' into 'master'
Use try_from in getpagesize(), add test

See merge request redox-os/relibc!225
2019-07-01 11:03:58 +00:00
jD91mZM2 3be933ec63 Merge branch 'alloc_cleanup' into 'master'
Alloc functions cleanup

See merge request redox-os/relibc!224
2019-07-01 11:02:10 +00:00
Peter Limkilde Svendsen 02e26006e7 Alloc functions cleanup 2019-07-01 11:02:10 +00:00
jD91mZM2 b43e1bf83b Merge branch 'l64a' into 'master'
Implement l64a()

See merge request redox-os/relibc!227
2019-07-01 10:59:37 +00:00
Peter Limkilde Svendsen 6cc5216c9c Implement l64a() 2019-07-01 10:59:37 +00:00
jD91mZM2 e35f22b3df WIP: pthread_atfork
WIP mainly because we *should* use thread locals, but #[thread_local]
causes segfaults.
2019-07-01 09:07:11 +02:00
jD91mZM2 f9dca89c1f Merge branch 'cleanup' 2019-07-01 08:39:09 +02:00
Jeremy Soller 6a069d1d9e Add static TLS init on Linux 2019-06-30 21:31:57 -06:00
Jeremy Soller 2a68c68dc6 Use the same Stack struct for ld_so start as for relibc start 2019-06-30 21:31:31 -06:00
Jeremy Soller a72c5f4aca Add static tls test 2019-06-30 21:30:34 -06:00
jD91mZM2 6203a85713 Fix thread-locals 2019-06-27 08:25:08 +02:00
jD91mZM2 ec7abebc0b Fix a very slight error in the mutex
This was just my attempt at being smart, I didn't realize
`compare_exchange` returned the old value (I'm dumb!), so I thought
that if the value was 1 then it must have become 2. Normally with
small errors like these you should leave a comment explaining why, but
really, compare and *exchange* is pretty obvious. My bad.
2019-06-27 07:29:30 +02:00
jD91mZM2 d704a35b85 Untested: Remove duplicate Mutex efforts in pte.rs
See #151
2019-06-27 07:29:30 +02:00
jD91mZM2 2f4e57f87a Fix data race inside puts(...) & add dbg!() macro 2019-06-26 21:21:32 +02:00
jD91mZM2 e929538098 Uncomment pthread_atfork stub to get ion to build 2019-06-16 14:59:04 +02:00
Peter Limkilde Svendsen 8b975877e6 Formatting 2019-06-14 00:07:36 +02:00
Peter Limkilde Svendsen 3b06380738 Add test for getpagesize() 2019-06-14 00:06:11 +02:00
jD91mZM2 651d38300a Merge branch 'master' into 'master'
Use cbitset crate instead of custom bitset implementation in select

See merge request redox-os/relibc!221
2019-06-13 12:31:30 +00:00
lmiskiew 43f1b582ae Use cbitset crate instead of custom bitset implementation in select 2019-06-13 12:31:30 +00:00
Peter Limkilde Svendsen 6e88617762 Use fallible conversion in getpagesize() 2019-06-12 23:47:11 +02:00
jD91mZM2 e84ea94dd0 Execute fmt.sh 2019-06-12 14:45:33 +02:00
jD91mZM2 c29237d360 Revert "Regenerate test output after !220"
Well I'm dumb... This test was already ran in a way that wasn't
verifying output, because this test outputs things that can
differ. Excuse me for not noticing!

This reverts commit 0af78b1e06.
2019-06-12 14:42:38 +02:00
jD91mZM2 0af78b1e06 Regenerate test output after !220 2019-06-12 11:45:06 +02:00
jD91mZM2 8db2f51706 Merge branch 'assert_fail' into 'master'
Rename __assert to __assert_fail

See merge request redox-os/relibc!212
2019-06-12 09:33:59 +00:00
jD91mZM2 d9ed51b9f1 Merge branch 'lcg48_arr' into 'master'
Implement remaining LCG functions

See merge request redox-os/relibc!219
2019-06-12 09:31:18 +00:00
jD91mZM2 3013c5db50 Merge branch 'posix_memalign' into 'master'
Implement posix_memalign()

See merge request redox-os/relibc!220
2019-06-12 09:27:48 +00:00
jD91mZM2 de70b2ae98 Merge branch 'master' into 'master'
Fix out-of-bounds error in strsignal

See merge request redox-os/relibc!222
2019-06-12 09:18:09 +00:00
Jason Hansel a5409ecd36 Fix out-of-bounds error in strsignal 2019-06-10 10:25:59 -04:00
Peter Limkilde Svendsen 626c713021 Formatting 2019-05-30 18:35:16 +02:00
Peter Limkilde Svendsen 02d1a7fe6f Implement posix_memalign 2019-05-30 18:28:15 +02:00
Peter Limkilde Svendsen 7a48107080 Run fmt 2019-05-23 21:48:43 +02:00
Peter Limkilde Svendsen dcff3fd836 Use y_from_x naming for functions 2019-05-23 21:40:06 +02:00
Peter Limkilde Svendsen fe4a3ae2b4 Refactor for consistency 2019-05-23 21:33:20 +02:00
Peter Limkilde Svendsen b2a9cdf930 Implement lcong48() and seed48() 2019-05-23 20:36:13 +02:00
Peter Limkilde Svendsen 767cf86b38 Refer to newer standard (with correct half-open output intervals) 2019-05-22 21:09:26 +02:00
Peter Limkilde Svendsen 13108776ae Implement erand48(), jrand48() and nrand48() 2019-05-22 18:48:19 +02:00
jD91mZM2 dab6530fb4 Merge branch 'valloc_pagesize' into 'master'
Make valloc() get page size through sysconf(), add tests

See merge request redox-os/relibc!216
2019-05-12 14:52:56 +00:00
jD91mZM2 f1b88d9ea0 Merge branch 'lcg48' into 'master'
Implement LCG pseudorandom number functions

See merge request redox-os/relibc!213
2019-05-12 14:50:18 +00:00
Peter Limkilde Svendsen 45860e9256 Implement LCG pseudorandom number functions 2019-05-12 14:50:18 +00:00
jD91mZM2 06ab5b7de2 Merge branch 'memrchr' into 'master'
Add memrchr()

See merge request redox-os/relibc!214
2019-05-12 14:13:22 +00:00
jD91mZM2 f3363af54d Merge branch 'housekeeping' into 'master'
Spring cleanup

See merge request redox-os/relibc!217
2019-05-12 14:11:24 +00:00
Mateusz Mikuła 5dd9c042d6 Update rust-toolchain 2019-05-11 22:34:14 +02:00
Mateusz Mikuła 7597c082e7 Fix Clippy warnings 2019-05-11 22:34:13 +02:00
Jeremy Soller 20a2355bc4 Merge branch 'master' of https://gitlab.redox-os.org/redox-os/relibc 2019-05-11 10:05:45 -06:00
Jeremy Soller 2606266c3f If the prefix is recompiled, clzsi2 does not have to be removed. 2019-05-11 10:05:38 -06:00
Mateusz Mikuła 21a6701528 Rename __assert to __assert_fail
This makes relibc more compatible with other libc implementations
2019-05-11 13:50:36 +02:00
Mateusz Mikuła d62db7b1b9 Add memrchr() 2019-05-11 13:49:46 +02:00
Mateusz Mikuła 30f6a9c323 Cargo fmt 2019-05-11 13:48:03 +02:00
Peter Limkilde Svendsen f8cf25d76c Fix inaccurate comment 2019-05-11 11:44:36 +02:00
jD91mZM2 15aa52a8e9 Fix the CI; Disregard last commit
The race condition didn't trigger when I tested it, so I assumed I had
solved it...
2019-05-11 08:55:11 +02:00
jD91mZM2 123031dcfe Fix race condition in parallel Makefile
Some recipes require the headers, but they don't explicitly say
so. Parallel make (-j`nproc`) might start compiling the libs when the
headers aren't done yet.
2019-05-11 08:04:03 +02:00
Peter Limkilde Svendsen 54c5423f35 Avoid call to memalign() 2019-05-09 23:40:12 +02:00
Peter Limkilde Svendsen 8beb10b1bd Get page size through sysconf() 2019-05-08 23:20:30 +02:00
Peter Limkilde Svendsen f13bd7fdd1 Add tests for valloc 2019-05-08 22:08:13 +02:00
jD91mZM2 3be13d672f Fix the GitLab CI for Redox OS (finally!) 2019-05-08 17:14:10 +02:00
Jeremy Soller cfc541019c Add socketpair on Linux with stub on Redox 2019-04-28 19:12:54 -06:00
Jeremy Soller 75cb7033c7 Fix use of timeout in epoll_pwait on redox 2019-04-28 13:33:17 -06:00
Jeremy Soller d2cb0959f3 Fix redox epoll timeout 2019-04-28 13:10:34 -06:00
Jeremy Soller 6a9d070115 Fix time path, use c_str macro 2019-04-28 12:56:00 -06:00
Jeremy Soller 61dea7f52b Add all 3 epoll_ctl ops 2019-04-28 11:30:14 -06:00
Jeremy Soller 16083a6020 Remove epoll_ctl debug message 2019-04-28 11:27:52 -06:00
Jeremy Soller 8efa7a3ed8 Fixes for epoll on Redox 2019-04-28 11:27:01 -06:00
Jeremy Soller 3a5a7b3378 Support for native relibc compilation of tests 2019-04-28 11:00:27 -06:00
Jeremy Soller d6d01e5614 Allow custom sysroot to be specified 2019-04-28 10:49:44 -06:00
Jeremy Soller e6e31dd3b4 Format 2019-04-28 10:29:20 -06:00
Jeremy Soller f8fe67e7ba Merge remote-tracking branch 'origin/epoll' 2019-04-28 10:28:27 -06:00
Jeremy Soller 10fdea88f2 Bring in changes that were accidently lost 2019-04-28 10:26:10 -06:00
Jeremy Soller 54fb8b9b2b Fix select on regular files 2019-04-28 10:07:42 -06:00
Jeremy Soller ba711deb0d Convert select example to use pipes 2019-04-28 09:27:07 -06:00
Jeremy Soller 378ea3ac0e signal test is no longer expected 2019-04-28 09:14:05 -06:00
Jeremy Soller b399e87ef8 Add epoll test 2019-04-28 09:13:47 -06:00
Jeremy Soller dd9328bd41 Add pipe2 2019-04-28 09:13:24 -06:00
Jeremy Soller 68c4e95b6d Merge branch 'epoll' 2019-04-28 09:10:52 -06:00
Jeremy Soller c9a8674c61 Update pthreads-emb 2019-04-28 07:50:04 -06:00
Jeremy Soller 89b4fa80af Merge branch 'jD91mZM2/epoll' into 'epoll'
Add completely untested redox epoll implementation

See merge request redox-os/relibc!211
2019-04-28 13:18:50 +00:00
jD91mZM2 4c8f51ace9 Avoid allocations in redox epoll 2019-04-28 14:51:42 +02:00
Jeremy Soller be765f879d Merge branch 'master' into 'master'
Implement rand_r(), strnlen_s(), tempnam(), tmpnam()

See merge request redox-os/relibc!210
2019-04-28 12:18:50 +00:00
jD91mZM2 488981f9ec Add completely untested redox epoll implementation 2019-04-28 08:20:49 +02:00
Jeremy Soller 6d857f8db7 C flavored Rust doesn't taste good 2019-04-27 20:23:32 -06:00
Jeremy Soller 125e0e08da Add timegm 2019-04-27 19:58:41 -06:00
Jeremy Soller 5a34907033 Merge branch 'master' of https://gitlab.redox-os.org/redox-os/relibc 2019-04-27 19:57:35 -06:00
Alex Lyon 68d3c5f1b1 Format code 2019-04-26 20:40:22 -07:00
Alex Lyon 3584edf199 stdio: implement tempnam() and tmpnam() 2019-04-26 20:39:03 -07:00
Alex Lyon 5bbce37789 string: add strnlen_s() 2019-04-26 20:36:37 -07:00
Alex Lyon 67af78d0eb stdlib: make rand()/rand_r() generate from [0, RAND_MAX] 2019-04-26 13:13:25 -07:00
Alex Lyon 13a10ce7af stdlib: implement rand_r() using XorShiftRng 2019-04-25 19:35:32 -07:00
Jeremy Soller 6a16275817 Fix warning, format makefile, and update depends 2019-04-24 19:50:57 -06:00
Jeremy Soller 6074616857 Merge branch 'strerror_r' into 'master'
Handle zero len for strerror_r

See merge request redox-os/relibc!209
2019-04-24 17:19:40 +00:00
Mateusz Mikuła 1ebd8a3d72 Handle zero length for strerror_r 2019-04-24 17:42:28 +02:00
jD91mZM2 87ba8f8a08 Merge branch '140-bufferedvalist-index-may-read-out-of-bounds' into 'master'
Resolve "BufferedVaList::index may read out of bounds"

Closes #140

See merge request redox-os/relibc!208
2019-04-23 18:36:00 +00:00
jD91mZM2 8fca7bcbc1 More printf tests and corner cases 2019-04-23 08:15:58 +02:00
jD91mZM2 0a0aec502b Fix #140 2019-04-23 07:34:06 +02:00
jD91mZM2 40d01d9d57 Convert printf internals to iterator 2019-04-22 16:25:29 +02:00
jD91mZM2 c2c8806f04 Merge branch 'malloc_errno' into 'master'
Set errno in alloc functions and add further tests

See merge request redox-os/relibc!205
2019-04-22 11:16:13 +00:00
Peter Limkilde Svendsen 912385b501 Set errno in alloc functions and add further tests 2019-04-22 11:16:13 +00:00
Jeremy Soller 7bde036031 Remove va_list submodule, format 2019-04-21 15:45:55 -06:00
Jeremy Soller b2cc25dd38 Fix missing import 2019-04-21 15:28:19 -06:00
jD91mZM2 6d4ac9dba8 Finally, get rid of all rust warnings
Just a small step along the way to reduce the massive wall of spam
every time you compile.

This was done partly automagically with `cargo fix`. The rest was me
deleting or commenting out a bunch of variables. Hope nothing was
important...
2019-04-21 21:12:16 +02:00
jD91mZM2 3a3fd3da39 Use the memchr crate
https://github.com/BurntSushi/rust-memchr is supposed to be a whole
lot faster :)
2019-04-21 19:09:37 +02:00
Dan Robertson fa94f1b6d5 Use core::ffi::VaList 2019-04-21 17:46:22 +02:00
jD91mZM2 29e1c780aa Comment out or fix 2 failing tests 2019-04-21 17:46:22 +02:00
jD91mZM2 601cb43f6c Merge branch 'strerror_r' into 'master'
Add POSIX strerror_r

See merge request redox-os/relibc!207
2019-04-21 15:06:17 +00:00
jD91mZM2 78d52c6e9f Merge branch 'whiletofor' into 'master'
Changed while loops to for

See merge request redox-os/relibc!206
2019-04-21 15:04:10 +00:00
Jeremy Soller 83f89912e0 Do not copy kernel-allocated TLS 2019-04-20 10:36:18 -06:00
Mateusz Mikuła c68a0d5678 Add POSIX strerror_r 2019-04-19 17:59:56 +02:00
Michal Z 89ca696f8e Changed while loops to for
Changed while loops to for - https://gitlab.redox-os.org/redox-os/relibc/issues/128
2019-04-15 18:24:46 +02:00
Jeremy Soller b9e03cbaed Implement __tls_get_addr 2019-04-14 19:09:10 -06:00
Jeremy Soller 30aef27c76 Correctly set up TLS on Redox and other fixes for pthread_clone 2019-04-14 19:08:58 -06:00
Jeremy Soller 7fe0beb916 Add DTPMOD64 2019-04-14 13:21:07 -06:00
Jeremy Soller 5a005864a8 Fix compilation on redox 2019-04-14 13:18:57 -06:00
Jeremy Soller 361f32b63c ld_so: significant refactor to prepare for pthread_create support of TLS 2019-04-14 13:17:07 -06:00
Jeremy Soller 9f5e5f24dc Correctly set tcb pointer to the end of TLS 2019-04-14 10:44:25 -06:00
Jeremy Soller 47baf499bf Fix TLS offsets 2019-04-14 08:40:03 -06:00
Jeremy Soller cb9e779ca1 Install ld_so 2019-04-13 21:39:08 -06:00
Jeremy Soller b2cc8f6d26 Fix compilation on Redox 2019-04-13 21:32:51 -06:00
Jeremy Soller 27cebdd688 Build librelibc without incremental support, gc-sections for ld.so 2019-04-13 21:15:38 -06:00
Jeremy Soller ba50c94c3f Improve TLS support 2019-04-13 21:15:01 -06:00
Jeremy Soller 63cb2f3454 ld.so: Add auxv support, get ld_library_path from env 2019-04-13 21:14:52 -06:00
Jeremy Soller 084b69b361 Add ld_so executable 2019-04-13 12:17:38 -06:00
Jeremy Soller d5eb1e2732 Add dl-tls.h, required for shared libraries 2019-04-12 09:30:02 -06:00
Jeremy Soller d9ec8b4ab0 Do not link to standard libraries when making libc.so... 2019-04-11 21:02:01 -06:00
Jeremy Soller 2b56f2882b Add libc.so, remove compiler_builtins 2019-04-11 21:00:39 -06:00
Jeremy Soller e5529dc883 Update pthreads-emb 2019-04-11 20:31:11 -06:00
Jeremy Soller cf800b5282 Add shared object for openlibm and pthreads-emb 2019-04-11 20:10:08 -06:00
Jeremy Soller 2fdca9bd0a Work around definition of O_NOFOLLOW, and add target for only building and installing headers 2019-04-07 10:11:05 -06:00
Jeremy Soller f4fccc6d19 Update rust 2019-04-07 08:47:51 -06:00
Jeremy Soller 73dda0f32c Add missing cast 2019-04-06 21:38:59 -06:00
Jeremy Soller f2b86e985c Ensure that getpeername and getsockname return a sockaddr of family AF_INET 2019-04-06 21:34:56 -06:00
Jeremy Soller 588f032f75 Rename can be done with O_PATH 2019-04-06 20:47:20 -06:00
Jeremy Soller 54b6c8f025 Update pthreads-emb 2019-04-04 19:59:06 -06:00
Jeremy Soller 862c76b25f Correct error for unknown protocol type in socket 2019-04-01 20:35:15 -06:00
Jeremy Soller f4c036c3aa Fix returning incorrect ai_socktype from getaddrinfo 2019-04-01 20:34:53 -06:00
Jeremy Soller 42d40da973 Map stacks based on provided size. 2019-03-31 15:04:37 -06:00
Jeremy Soller 17372b4f69 Fix thread starting before pte_osThreadStart 2019-03-30 16:18:07 -06:00
jD91mZM2 3f98962054 Fix bug in scanf where EOF would be ignored 2019-03-28 17:57:13 +01:00
Jeremy Soller 6548aad36d Use next_byte function in all places in scanf 2019-03-27 21:32:02 -06:00
Jeremy Soller d13fb3f42b Fix panic in sigaction 2019-03-27 21:31:18 -06:00
Jeremy Soller bee72373be Fix panic not producing output 2019-03-27 21:28:39 -06:00
Jeremy Soller 5dca9843dc Fix use of trace macro when errno is imported 2019-03-27 20:57:12 -06:00
Jeremy Soller 65aeda1f59 Use AF_INET6 instead of PF_INET6 in test 2019-03-27 20:56:59 -06:00
Jeremy Soller a88ec09131 Prevent override of panic from relibc 2019-03-27 20:56:23 -06:00
Jeremy Soller 229ca66726 Merge branch 'usleep' into 'master'
Fix usleep

Closes #144

See merge request redox-os/relibc!204
2019-03-25 13:06:46 +00:00
Mateusz Mikuła e01d1ce11b Fix usleep 2019-03-25 13:36:48 +01:00
Jeremy Soller 7a1e2a6269 Merge branch 'new-toolchain' into 'master'
Support use of new cross compiler

See merge request redox-os/relibc!203
2019-03-17 02:28:01 +00:00
Jeremy Soller 0e667c5f25 Remove .travis.yml 2019-03-16 20:20:43 -06:00
Jeremy Soller 6f12bb6a32 Install tar before attempting to use it 2019-03-16 20:18:34 -06:00
Jeremy Soller 59653ee290 Support use of new cross compiler 2019-03-16 20:16:00 -06:00
Jeremy Soller cee4449f7c Replace make calls with MAKE variable 2019-03-16 18:54:11 -06:00
Jeremy Soller 5715fb7ba6 Work on switching to epoll as backend for select and poll 2019-03-10 13:03:00 -06:00
Jeremy Soller cdbeda1ca0 Merge branch 'patch-2' into 'master'
Fix conditional compilation of sys/mman.h

See merge request redox-os/relibc!201
2019-03-05 02:08:01 +00:00
jD91mZM2 640c6d41a7 Merge branch 'aarch64-prep' into 'master'
Aarch64 prep redux

See merge request redox-os/relibc!202
2019-03-04 09:48:26 +00:00
Robin Randhawa 9443eef518 Add wint_t definition to stddef.h
Without this the relibc tests would break. With this the relibc tests
pass and formerly breaking builds (such as uutils -> onig_sys) pass.
2019-03-03 21:50:13 +00:00
Robin Randhawa 23de2ca7ca Remove redundant wchar_t and win_t definitions
Typically with libc implementations, wchar_t and co are either defined
entirely by the libc or, under libc's arrangement, by headers supplied
by the compiler.

Things like dlmalloc in relibc need these definitions from relibc itself
and that's already already furnished by relibc's stddef.h.

These additional definitions here are redundant and collide with
compiler headers - for example: onig_sys (something that uutils depends
on) breaks. Instead, this patch makes the compiler headers define
things appropriately.
2019-03-03 21:50:04 +00:00
Robin Randhawa f9f752d74c aarch64-prep: Dummy auxv.h
For AArch64, the ring crate depends on the presence of this header and a definition
of getauxval.
2019-03-03 21:49:52 +00:00
Robin Randhawa 17bed54103 aarch64: Fix incorrect init/fini stack manipulation
The pre-index operator ('!') was missing at the end of the stp
instruction.

As a result, the stack pointer wasn't updated after the
store of the 64-bit pair and the stored values were basically lost when
follow on code used the stack for later store ops.
2019-03-03 21:49:46 +00:00
Angelo Bulfone 31fc29e70c Fix conditional compilation of sys/mman.h 2019-03-03 21:14:45 +00:00
jD91mZM2 269b8a1d3e Merge branch 'cleanup' into 'master'
tests: Macro based error handling

See merge request redox-os/relibc!195
2019-03-03 15:19:19 +00:00
jD91mZM2 37c976945a Merge branch 'implement-swab' into 'master'
Implement swab

See merge request redox-os/relibc!187
2019-02-28 08:23:11 +00:00
lmiskiew 5eb2a8f7bd Implement swab 2019-02-28 08:23:11 +00:00
jD91mZM2 30a0f70d73 Merge branch 'wcsrchr' into 'master'
implements wcsrchr from wchar.h

See merge request redox-os/relibc!197
2019-02-28 08:21:55 +00:00
jD91mZM2 fe905ed13c Merge branch 'calloc_overflow_check' into 'master'
add calloc integer overflow check

See merge request redox-os/relibc!188
2019-02-28 08:20:11 +00:00
jD91mZM2 71f8fb32e3 Merge branch 'patch-1' into 'master'
Change LONG_BIT definition, fixes #148

Closes #148

See merge request redox-os/relibc!198
2019-02-28 08:18:29 +00:00
Paul Sajna e93129b165 Change LONG_BIT definition, fixes #148 2019-02-28 07:42:19 +00:00
emturner 4ed6dca61d implements wcsrchr from wchar.h 2019-02-25 22:53:11 +00:00
Tibor Nagy fa2c6d29db tests: Rewrite libgen tests based on ctype (nice table layout), fix error handling of sleep tests 2019-02-25 19:32:20 +01:00
Tibor Nagy efd6947d8e tests: Fix function-like macros
Turns the results of these macros from compound to regular statements using the old `do { ... } while(0)` trick. Must have for function-like macros.
2019-02-25 14:13:02 +01:00
Tibor Nagy 96182ce8ad tests: Fix expected outputs 2019-02-24 22:19:07 +01:00
Tibor Nagy a92be000fb tests: Even more work on error handling
realpath: Fixing undefined behaviour in the second test. If the call fails the resolved_name argument cannot be used for error checking because its state is undefined by SUSv2.
pipe: Changing the order of close and write error handling code. Errors in close could overwrite errno after write errors, returning incorrect error messages.
gmtime: Removed duplicate checks
Other fixes for fseek, rename, mktime, putwchar
2019-02-24 22:02:11 +01:00
Tibor Nagy 2d027f0771 tests: More work on error handling 2019-02-24 00:46:26 +01:00
Jeremy Soller 76503d8943 Add epoll constants 2019-02-23 08:39:06 -07:00
Jeremy Soller f3ba7e8d8e Merge branch 'wcscspn' into 'master'
Implements wcscspn function from wchar.h

See merge request redox-os/relibc!196
2019-02-23 00:33:11 +00:00
emturner ec3488c7b0 implements wcscspn from wchar.h 2019-02-22 23:18:21 +00:00
Tibor Nagy 0c539d6e4e tests: Fix expected outputs 2019-02-22 13:28:18 +01:00
Tibor Nagy 513f4ba53c tests: Documentation for test_helpers.h, more refactoring 2019-02-22 13:19:38 +01:00
Jeremy Soller 887d89c2bb Add epoll (WIP) 2019-02-21 20:40:03 -07:00
Jeremy Soller 74d0b24939 Merge branch 'master' of https://gitlab.redox-os.org/redox-os/relibc 2019-02-21 19:43:07 -07:00
Jeremy Soller 5690c6dcdf Add trace for select and poll 2019-02-21 19:42:58 -07:00
Tibor Nagy 9a0ea6ff34 tests: More refactoring, add helper header to every test, override exit for better error reporting 2019-02-21 21:13:28 +01:00
Tibor Nagy 6266d29242 tests: Fix expected outputs 2019-02-21 17:46:18 +01:00
Tibor Nagy 64acf45c40 tests: Add helper macros for easier error handling and reporting 2019-02-21 17:35:24 +01:00
Tibor Nagy f60c95d2ca tests: Work on more thorough error handling 2019-02-21 16:15:49 +01:00
Tibor Nagy d1a424c002 tests: Replace returns with exits in the main functions
This will allow us to redefine the exit function.

For example:
```
#define exit(code) { \
    fprintf(stderr, "%s:%d: exit(%s) in function ‘%s’\n",
        __FILE__, __LINE__, #code, __func__); \
    _exit(code); \
}
```
2019-02-21 12:15:06 +01:00
Jeremy Soller f19e029468 Merge branch 'cleanup' into 'master'
General test cleanups

See merge request redox-os/relibc!193
2019-02-20 22:34:52 +00:00
Jeremy Soller 20aeb15fc7 Merge branch 'path-separator' into 'master'
unistd: Generate correct C defines for PATH_SEPARATOR

See merge request redox-os/relibc!194
2019-02-20 22:32:13 +00:00
Tibor Nagy 27a3f2ab77 unistd: Generate correct C defines for PATH_SEPARATOR 2019-02-20 22:11:25 +01:00
Tibor Nagy 4381bb2a22 tests: Remove redundant return statements
When the execution reaches the end of the main functions, they implicitly return a successful status.
2019-02-20 21:09:03 +01:00
Tibor Nagy c19cc8b731 tests: Portability fixes, replaced 0/1/-1 return codes with macros 2019-02-20 20:20:07 +01:00
Tibor Nagy ff874c87d7 tests: Fix function signatures 2019-02-20 19:27:18 +01:00
Jeremy Soller 97592716fb Merge branch 'pedantic' into 'master'
tests: set C11, enable pedantic warnings, fix GCC and Clang warnings

See merge request redox-os/relibc!192
2019-02-20 16:01:50 +00:00
Tibor Nagy 7ee59d2fdb tests: set C11, enable pedantic warnings, fix GCC and Clang warnings 2019-02-20 15:04:47 +01:00
Jeremy Soller 1af4eb7ec0 Merge branch 'ctype' into 'master'
ctype: Implement _tolower, _toupper

See merge request redox-os/relibc!191
2019-02-20 13:19:36 +00:00
Tibor Nagy d38a1d0da3 ctype: Implement _tolower, _toupper 2019-02-20 11:49:06 +01:00
Jeremy Soller 73c368ddab Use correct open flags 2019-02-19 19:29:19 -07:00
Jeremy Soller 264659b634 Merge branch 'ctype' into 'master'
ctype: Add tests for toascii, tolower, toupper

See merge request redox-os/relibc!190
2019-02-19 21:59:14 +00:00
Tibor Nagy 1eb22b2cb2 ctype: Add tests for toascii, tolower, toupper 2019-02-19 20:54:05 +01:00
Jeremy Soller 514b31cf28 Merge branch 'ctype' into 'master'
ctype: Fix iscntrl, isgraph, ispunct, make tests exhaustive

See merge request redox-os/relibc!189
2019-02-19 19:09:27 +00:00
Tibor Nagy 5fac72298f ctype: Fix iscntrl, isgraph, ispunct, make tests exhaustive
iscntrl: Didn't handle the EOF macro correctly
isgraph: Didn't handle '~' (tilde) correctly
ispunct: Several issues
2019-02-19 19:53:54 +01:00
Jeremy Soller 38da5552e8 getaddrinfo: support for setting port from service argument (numeric only) 2019-02-02 14:20:26 -07:00
Peter Limkilde Svendsen 7aa0fbdf93 Include stdint.h in test 2019-02-02 16:51:38 +01:00
Peter Limkilde Svendsen 8b7453edf2 Add test of calloc with overflow 2019-02-02 16:41:09 +01:00
Peter Limkilde Svendsen c54db6f008 Add integer overflow check to calloc 2019-02-02 15:52:39 +01:00
Jeremy Soller d2502056a8 Cleanup termios and ioctls and add tcflush 2019-01-27 19:19:50 -07:00
Jeremy Soller 602f015e93 Implement fpathconf and pathconf 2019-01-27 18:53:57 -07:00
Jeremy Soller 0dd801da03 Implement ttyname by adding fpath function to Sys. Remove realpath function and use fpath internally 2019-01-27 17:10:55 -07:00
Jeremy Soller 42f212e678 Verify current system before continuing. 2019-01-27 15:53:09 -07:00
Jeremy Soller 47235d44e7 Fix change of sockaddr member sa_data on Redox 2019-01-21 20:38:31 -07:00
Jeremy Soller c59f268fcd Implement getaddrinfo (somewhat) 2019-01-21 20:36:56 -07:00
Jeremy Soller f3c858c151 Build includes in parallel 2019-01-20 20:17:04 -07:00
Jeremy Soller f25c494a73 Show hint information 2019-01-20 20:12:58 -07:00
Jeremy Soller 0f50a40b3f Update redox_syscall 2019-01-20 19:38:38 -07:00
Jeremy Soller aa3c7da128 Switch to using syscall-instruction 2019-01-20 09:46:21 -07:00
Jeremy Soller eaa031c21c Fix ioctl on redox 2019-01-18 15:39:49 -07:00
Jeremy Soller a88933386b Implement termios functions using ioctl 2019-01-17 20:46:12 -07:00
Jeremy Soller 047deceed0 Move hostent functions to separate file 2019-01-17 20:45:25 -07:00
Jeremy Soller d0261ebb35 Move db to crate root 2019-01-17 19:56:51 -07:00
Jeremy Soller 09340bd0f2 Add setpgrp 2019-01-15 21:14:55 -07:00
Jeremy Soller 22ca2e5f7b Export group struct 2019-01-15 21:08:08 -07:00
Jeremy Soller 1a0d363caa Redox support for some minimal ioctl's 2019-01-15 20:50:17 -07:00
Jeremy Soller 74dd5091f3 Add empty netinet_ip 2019-01-15 20:49:35 -07:00
Jeremy Soller b35a4f6372 Add in_systm.h 2019-01-15 20:49:15 -07:00
Jeremy Soller c71088e768 Cleanup and format 2019-01-14 21:07:24 -07:00
Jeremy Soller 8dabff129a Begin work on getnameinfo 2019-01-14 19:26:35 -07:00
Jeremy Soller c57ac53d28 Reduce warnings 2019-01-14 19:26:18 -07:00
Jeremy Soller b3dda7519d Update openlibm 2019-01-14 14:22:24 -07:00
Jeremy Soller 2e260a6b29 Add _SC_PAGE_SIZE, use sysconf to provide getpagesize 2019-01-13 19:48:06 -07:00
Jeremy Soller f35f65c2b8 Update pthreads-emb 2019-01-13 17:00:39 -07:00
Jeremy Soller 594e53c6f1 addrinfo stub 2019-01-13 14:37:20 -07:00
Jeremy Soller 87f2ab95bb Fix redox compilation 2019-01-13 14:36:35 -07:00
Jeremy Soller 8e9d65cb46 Add support for pthreads to Linux 2019-01-13 14:17:29 -07:00
Jeremy Soller 52669688bf Fix issue of strcasecmp not showing up 2019-01-13 14:17:05 -07:00
Jeremy Soller 434cad49ce Add sysconf 2019-01-13 14:16:51 -07:00
Jeremy Soller 5b969f2bae Add pthread_sigmask 2019-01-13 10:56:09 -07:00
Jeremy Soller 89fca557f3 Remove old pthread module 2019-01-13 10:56:00 -07:00
Jeremy Soller 6c0c6dd71b Fix missing negative flags in netdb.h, add NI_MAXHOST and NI_MAXSERV 2019-01-13 10:34:17 -07:00
Jeremy Soller 018ff409f1 Add gai_strerror 2019-01-13 10:24:30 -07:00
Jeremy Soller 543f32eb50 Add nameinfo defines 2019-01-13 10:24:17 -07:00
Jeremy Soller 97312c9ae2 Fix addrinfo structure 2019-01-13 10:13:25 -07:00
Jeremy Soller 84fcb1b906 Add addrinfo constants 2019-01-13 09:58:03 -07:00
Jeremy Soller aa069b3e0b Add netinet/tcp.h 2019-01-13 09:31:25 -07:00
Jeremy Soller cea5101cba Implement shm_ functions and add MAP_FIXED 2019-01-13 09:31:04 -07:00
Jeremy Soller 5b779448ab Add IOV_MAX 2019-01-13 09:30:37 -07:00
Jeremy Soller 33b539e4c1 Fix export of O_ACCMODE 2019-01-13 09:30:27 -07:00
Jeremy Soller 0c5abf0361 Combine all libraries into libc.a, call pthread_init and pthread_terminate in libc 2019-01-07 19:11:30 -07:00
Jeremy Soller aefb4fb116 Improvements for dlfcn 2019-01-06 16:28:22 -07:00
Jeremy Soller c41c20a943 Allow for static CStr 2019-01-06 14:40:01 -07:00
Jeremy Soller dc4aa9cf0b Use typedef for Dl_info 2019-01-06 12:53:43 -07:00
Jeremy Soller 53874213fa Add dladdr 2019-01-06 12:48:36 -07:00
Jeremy Soller 46020f466f Add dlfcn, fixes for glib and gstreamer 2019-01-06 07:30:42 -07:00
Jeremy Soller 9a0c12888f Use better verbiage for iovec 2019-01-05 13:24:02 -07:00
Jeremy Soller 7ac3dfaa49 Implement sys_uio, define sockaddr_storage 2019-01-05 13:10:20 -07:00
Jeremy Soller eef2f4d1f8 Add more netinet/in.h definitions 2019-01-05 12:01:24 -07:00
Jeremy Soller 2ba67f2fe2 Add getlogin stub 2019-01-05 10:12:33 -07:00
Jeremy Soller 961d1304ab Add sigismember 2019-01-05 09:40:08 -07:00
Jeremy Soller bd956e5fe4 Force little endian for reals 2019-01-01 07:35:13 -07:00
Jeremy Soller 775ec444be Add mprotect 2018-12-31 21:04:45 -07:00
Jeremy Soller c514b0b705 Fix semaphore deadlocks 2018-12-30 08:29:57 -07:00
Jeremy Soller c9e48bf141 Use locking in dlmalloc 2018-12-29 20:11:34 -07:00
Jeremy Soller e93ead5a8f Fix double lock in pte 2018-12-29 19:40:21 -07:00
Jeremy Soller 62b83190bf Fix incorrect variable name 2018-12-29 10:03:11 -07:00
Jeremy Soller e7896f6c48 Fix panic in fread 2018-12-29 10:02:36 -07:00
Jeremy Soller 0aaa7264db Fix signal support 2018-12-29 08:20:27 -07:00
Jeremy Soller 083642fb17 Enable getitimer, setitimer, and sigprocmask 2018-12-28 21:47:49 -07:00
Jeremy Soller 5cb92284f2 Update fmap support 2018-12-28 15:46:38 -07:00
Jeremy Soller 51b093b598 Use 4096 as Linux page size for now 2018-12-26 19:57:08 -07:00
Jeremy Soller 7aa789575a Add shutdown, listen, and getpagesize 2018-12-26 19:26:38 -07:00
jD91mZM2 a321545fd0 Merge branch 'aarch64-unknown-redox' into 'master'
aarch64: Fix typo in a jmp_buf preprocessor conditional

See merge request redox-os/relibc!186
2018-12-23 10:52:46 +00:00
Robin Randhawa 0842d6504b aarch64: Fix typo in a jmp_buf preprocessor conditional 2018-12-23 16:04:35 +05:30
Jeremy Soller 09135f5bd1 Merge branch 'netdb-mutable' into 'master'
netdb: Return mutable structs in the getter functions

See merge request redox-os/relibc!185
2018-12-19 21:17:12 +00:00
Tibor Nagy 51245d69e3 netdb: Return mutable structs in the getter functions 2018-12-18 21:13:32 +01:00
Jeremy Soller 42545713a7 Merge branch 'fwrite-division-by-zero' into 'master'
Fix panic in fwrite

See merge request redox-os/relibc!184
2018-12-17 01:37:12 +00:00
lmiskiew 5b6b11cb65 Fix panic in fwrite 2018-12-17 02:01:36 +01:00
Jeremy Soller f04ac7343a Update pthreads-emb 2018-12-14 15:52:03 -07:00
Jeremy Soller a8f3608f3c Fix stdlib div functions, add _Exit 2018-12-14 13:41:22 -07:00
Jeremy Soller 89832b3ac8 Add lldiv 2018-12-14 13:20:56 -07:00
Jeremy Soller e6c866a92d Undefine complex in fenv.h 2018-12-14 12:50:23 -07:00
Jeremy Soller 74af56d71b Add statvfs and strtold 2018-12-14 12:00:21 -07:00
Jeremy Soller 0d2332d368 Add more special redox functions 2018-12-13 15:26:03 -07:00
Jeremy Soller c6d42dd9e3 Use openlibm's fenv.h 2018-12-13 15:25:47 -07:00
Jeremy Soller 4e741f5583 Add redox_fpath function 2018-12-13 14:46:27 -07:00
Jeremy Soller f7b3abc1b6 Add more wchar definitions 2018-12-13 08:11:49 -07:00
Jeremy Soller 1c1da7dfcb Implement more wchar functions 2018-12-12 20:45:17 -07:00
Jeremy Soller df1c7404eb Update pthreads-emb 2018-12-11 21:02:19 -07:00
Jeremy Soller ae115ac6ff Run pre-init array before _init 2018-12-11 21:01:10 -07:00
Jeremy Soller e764fedba5 Remove unnecessary extern C function 2018-12-11 09:17:33 -07:00
Jeremy Soller 4a4e641b23 Update pthreads-emb 2018-12-11 08:02:47 -07:00
Jeremy Soller 756a0d2edc Initialize pthreads if it is linked 2018-12-09 19:59:33 -07:00
Jeremy Soller 1becb8c43a Enable sys/mman 2018-12-09 16:24:23 -07:00
Jeremy Soller f9b836d23e Add more pte functions 2018-12-09 15:28:45 -07:00
Jeremy Soller 90bf583d28 Better patch for missing M_PI constants 2018-12-09 14:43:23 -07:00
Jeremy Soller ee40035c4b Add asprintf 2018-12-09 12:45:04 -07:00
Jeremy Soller 63b079c231 Include alloca.h in stdlib.h 2018-12-09 11:53:41 -07:00
Jeremy Soller be035f8862 Copy pthreads-emb files on install 2018-12-09 11:29:51 -07:00
Jeremy Soller 8aae8e1564 Add PTE
Add sys_timeb header
2018-12-09 11:27:44 -07:00
Jeremy Soller fc9e3923f6 drop DIR pointers again 2018-12-02 21:05:37 -07:00
Jeremy Soller de429a8df6 Fix overflow issues in Redox getdents 2018-12-02 21:04:07 -07:00
Jeremy Soller e8377d259a Mutable argv 2018-12-02 20:14:33 -07:00
Jeremy Soller 925d9f6bbf WIP: fflush all files when null is passed 2018-12-02 16:45:29 -07:00
Jeremy Soller 05f17794e4 Return correct error code from access 2018-12-02 15:26:37 -07:00
Jeremy Soller 7049359c25 Hack around closedir crashing 2018-12-02 14:27:02 -07:00
Jeremy Soller 594bcd75d4 Add closedir to dirent test 2018-12-02 13:20:33 -07:00
Jeremy Soller a39f170ed3 Reenable grp header (for git) 2018-12-02 12:35:38 -07:00
Jeremy Soller 4ced856b39 Fix fseeko not flushing write buffer 2018-12-02 12:04:15 -07:00
Jeremy Soller 62b0b0d508 Add rustcflags to makefile 2018-12-02 10:24:16 -07:00
Jeremy Soller 7dbd57f913 Fix putenv crash 2018-12-02 10:23:17 -07:00
Jeremy Soller fe57754c34 Do not cast usize to isize in strncpy 2018-12-02 08:16:38 -07:00
Jeremy Soller 3075b8b69f Replace gethostname syscall with uname 2018-12-02 08:04:53 -07:00
Jeremy Soller 52fd4d7e83 Clippy fixes 2018-12-02 08:04:53 -07:00
Jeremy Soller 28dab8ece8 Merge branch 'master' of https://gitlab.redox-os.org/redox-os/relibc 2018-12-01 08:55:05 -07:00
Jeremy Soller 9325183b21 Fix strcat 2018-12-01 08:55:02 -07:00
Jeremy Soller ca75bbc1c9 Merge branch 'isspace' into 'master'
ctype: fix isspace to test all space class characters

See merge request redox-os/relibc!182
2018-11-28 21:09:14 +00:00
Tibor Nagy 8d05067ac7 ctype: fix isspace to test all space class characters 2018-11-28 20:33:02 +01:00
Jeremy Soller d66afa4586 Do not return mutable pointer from strsignal 2018-11-27 20:54:37 -07:00
Jeremy Soller 35bcf93160 Merge branch 'master' of https://gitlab.redox-os.org/redox-os/relibc 2018-11-27 10:07:47 -07:00
Jeremy Soller 0a44d4543f Override CC for aarch64 redox 2018-11-27 10:07:44 -07:00
Jeremy Soller 950b4526c7 - Disable output of empty header files
- Remove incorrect header styles
- Use export.replace where header style was previously needed
- Check compilation of tests using system gcc
2018-11-26 21:35:02 -07:00
Jeremy Soller 4bb16e01b2 Merge branch 'master' of https://gitlab.redox-os.org/redox-os/relibc 2018-11-26 20:29:32 -07:00
Jeremy Soller 37cd503c88 Cleanups of redox pal 2018-11-26 20:29:27 -07:00
Jeremy Soller 1a8af993e6 Fix invalid inline ASM 2018-11-26 16:01:20 -07:00
Jeremy Soller 34edeaf066 Update dependencies 2018-11-26 15:48:40 -07:00
Jeremy Soller ee2a7685e6 Revert "Update compiler_builtins and redox_syscall"
This reverts commit d6a5b39505.
2018-11-26 15:45:35 -07:00
Jeremy Soller 583eaa498d Merge branch 'master' of https://gitlab.redox-os.org/redox-os/relibc 2018-11-26 15:43:29 -07:00
Jeremy Soller d6a5b39505 Update compiler_builtins and redox_syscall 2018-11-26 15:43:24 -07:00
Jeremy Soller 809f665a8a Update compiler_builtins 2018-11-26 15:43:15 -07:00
Jeremy Soller 15eed4daf1 Update core_io 2018-11-26 14:33:55 -07:00
Jeremy Soller d4e42fd9e0 Merge branch 'type' into 'master'
Some type signature fixes found using script in #111

See merge request redox-os/relibc!181
2018-11-26 13:13:43 +00:00
Ian Douglas Scott f5f561424a Correct return value of regerror 2018-11-25 21:24:32 -08:00
Ian Douglas Scott fc0b7b9111 'strtoull' and 'strtoll' type signatures 2018-11-25 21:17:25 -08:00
Ian Douglas Scott fdd966629d Some type signature fixes found using script in #111 2018-11-25 20:58:02 -08:00
Jeremy Soller de0339ee93 Fix issue with open flag overflow 2018-11-25 19:34:24 -07:00
Jeremy Soller a614c40273 Fix definition of protocol families 2018-11-25 16:45:19 -07:00
Jeremy Soller 6180222760 Format 2018-11-25 16:44:01 -07:00
Jeremy Soller e0daa157b9 Add protocol families 2018-11-25 16:43:45 -07:00
Jeremy Soller 5c4c49a9d1 Add getdelim and getline 2018-11-25 16:39:14 -07:00
Jeremy Soller 96cc56a0b5 Add readlink and symlink 2018-11-25 14:56:36 -07:00
Jeremy Soller d6a1796122 Format 2018-11-25 14:38:33 -07:00
Jeremy Soller d818a8d10e Add pwrite 2018-11-25 14:38:12 -07:00
Jeremy Soller 8a042a220d Implement pread, add more poll constants 2018-11-25 14:34:18 -07:00
Jeremy Soller 869eb160bd Add poll 2018-11-25 13:04:38 -07:00
Jeremy Soller 7398fae8b6 Re-add removed comments 2018-11-25 11:01:19 -07:00
Jeremy Soller 0ac16556bc Format 2018-11-25 10:34:42 -07:00
Jeremy Soller a5279b648f Fix warnings 2018-11-25 10:34:02 -07:00
Jeremy Soller 52493a1ec3 Add popen/pclose 2018-11-25 10:33:50 -07:00
Jeremy Soller de43271204 Merge branch 'uname' into 'master'
Implement uname for Redox

See merge request redox-os/relibc!178
2018-11-25 15:25:48 +00:00
Jeremy Soller a613154191 Merge branch 'alloca' into 'master'
Implement alloca.h

See merge request redox-os/relibc!180
2018-11-25 15:24:56 +00:00
Tibor Nagy 55eb8f2779 Implement alloca.h 2018-11-23 21:31:09 +01:00
Jeremy Soller 9790289aec Add execlp 2018-11-22 20:43:04 -07:00
Jeremy Soller 3cc215caeb Add freading, fwriting, and stdio_ext.h header 2018-11-22 19:24:48 -07:00
Jeremy Soller b4f36bce17 Add more stdio_ext functions 2018-11-22 19:09:46 -07:00
Jeremy Soller 632f9f18e5 fpending 2018-11-22 18:43:45 -07:00
Jeremy Soller 9b0c74b935 Fix ioctl being defined on redox, add cxa_atexit for gcc 2018-11-18 10:35:33 -07:00
Tibor Nagy 012a9b2eb3 Implement uname for Redox 2018-11-18 18:23:47 +01:00
Jeremy Soller 02c8355c13 Update openlibm 2018-11-18 08:58:35 -07:00
Jeremy Soller 4c9173433e Merge branch 'macos_fixes' into 'master'
Make relibc buildable on macOS (not for macOS)

See merge request redox-os/relibc!179
2018-11-17 23:47:52 +00:00
jD91mZM2 1c92751a73 Don't rely on integer wrapping in ctype
Don't rely on integer wrapping in ctype and fix strcasecmp on
non-alphabetic characters
2018-11-17 20:26:43 +01:00
Alexander Theißen 484a05e8b3 Remove unnecessary escape from include.sh
The older bash version of macOS does not understand this escape
and actually creates directories with "\" in their name. After this
change it actually works with both versions.
2018-11-17 20:17:35 +01:00
Alexander Theißen e102c234c1 Properly export CC variable in Makefile
We cannot use ?= because CC is set by default to "cc". Therefore
CC was never set. In addition we need to export the variable
in order to have the rust cc crate pick it up. Otherwise it is
only used by openlibm where it is explicitly passed.
2018-11-17 20:17:35 +01:00
Jeremy Soller 44f84f406f Force byte order to little endian, for gcc 2018-11-17 09:19:35 -07:00
Jeremy Soller e32fc12308 Weak linkage for getopt and fnmatch 2018-11-17 08:40:39 -07:00
Jeremy Soller c6f2b30738 Add netdb bits to include hostent.h_addr 2018-11-17 08:16:37 -07:00
Jeremy Soller 8c5b237963 Rename intmaxdiv_t to imaxdiv_t to match standard 2018-11-17 07:40:30 -07:00
Jeremy Soller e7f7c4ea61 Fix incorrect nul 2018-11-16 21:32:03 -07:00
Jeremy Soller a6642bc753 Fix missing separator 2018-11-16 21:16:08 -07:00
Jeremy Soller a29aa9f599 Add execvp 2018-11-16 21:07:24 -07:00
Jeremy Soller dd65d0c0c8 Fix missing nul 2018-11-16 20:37:37 -07:00
Jeremy Soller 861602bbcc Add umask 2018-11-16 19:49:47 -07:00
jD91mZM2 0684fb6e4c Bump posix-regex version 2018-11-14 20:52:12 +01:00
jD91mZM2 d252838496 Re-use posix-regex matcher in fnmatch 2018-11-14 14:19:48 +01:00
Jeremy Soller 81dc144241 Abandon overriding cargo flags, for now 2018-11-13 21:03:14 -07:00
Jeremy Soller f1c970beef Fix override of CARGOFLAGS when using target 2018-11-13 21:00:05 -07:00
Jeremy Soller 8a972542be Allow override of cargoflags 2018-11-13 20:56:59 -07:00
Jeremy Soller 2b3ae4d8b8 Add configuration for compiling with xargo 2018-11-11 08:10:37 -07:00
Jeremy Soller c36ee7237b Allow override of cargo 2018-11-11 08:03:04 -07:00
Jeremy Soller bf111188e1 Reduce warnings for redox 2018-11-10 07:54:27 -07:00
Jeremy Soller ebffc977b2 Reduce warnings 2018-11-10 07:52:45 -07:00
Jeremy Soller 131dcac554 Update serde_json 2018-11-09 18:31:35 -07:00
Jeremy Soller 4963ca3a95 Fix compile on redox 2018-11-07 20:26:27 -07:00
Jeremy Soller 39b999ccea Update to new rust-toolchain 2018-11-07 20:25:21 -07:00
Jeremy Soller d88f4053ea Merge branch 'header-guards-fix' into 'master'
Fix include guards in regex and utime

See merge request redox-os/relibc!176
2018-11-06 12:45:36 +00:00
Michal Z 0396460c84 Fix include guards in regex and utime
The include_guard in both regex and utime was "_TEMPLATE_H", this meant that including both wasn't possible.
Their header guards should be consistent with the header files as well.
Changed _TEMPLATE_H to _REGEX_H and _UTIME_H in /regex/cbindgen.toml and /utime/cbindgen.toml respectively.
2018-11-06 11:27:11 +01:00
jD91mZM2 75bac011e4 Merge branch 'MaikuZ/libgen' into 'master'
Implement libgen.h

See merge request redox-os/relibc!175
2018-11-05 20:33:54 +00:00
Michal Z a7b71a311d Implement libgen.h
Implemented the following calls according to http://pubs.opengroup.org/onlinepubs/7908799/xsh/libgen.h.html
- char* basename(char*)
- char* dirname(char*)

Added test suit for the implemented calls.

Issue: https://gitlab.redox-os.org/redox-os/relibc/issues/134
2018-11-05 17:49:14 +01:00
jD91mZM2 571b4d4976 Fix getdents on redox 2018-11-01 10:58:01 +01:00
Jeremy Soller 09bd4bc375 Update cbindgen 2018-10-29 19:27:47 -06:00
Jeremy Soller 51b2e630b9 Merge branch 'optind-reset' into 'master'
Handle getopt reinitialization

See merge request redox-os/relibc!174
2018-10-28 19:36:25 +00:00
Tibor Nagy f97f93c48d Handle getopt reinitialization 2018-10-28 19:59:08 +01:00
Jeremy Soller 740f57738c Merge branch 'cpp-extern' into 'master'
Disable symbol mangling for C++

See merge request redox-os/relibc!173
2018-10-28 13:13:51 +00:00
Tibor Nagy d4308c8a9b Disable symbol mangling for C++ 2018-10-28 13:24:34 +01:00
Jeremy Soller 6f4b8db7d8 Merge branch 'assert-duke32' into 'master'
Fix assert when used as an expression

See merge request redox-os/relibc!172
2018-10-27 17:58:58 +00:00
Tibor Nagy e7f251fdb0 Fix assert when used as an expression
Based on what musl does.
2018-10-27 17:40:24 +02:00
jD91mZM2 bfa068df88 Fix strcasecmp return value 2018-10-17 21:26:16 +02:00
Jeremy Soller 3c2121d4e0 Do not require prefix for hex 2018-10-16 18:03:21 -06:00
jD91mZM2 460f57b37f Disallow execve on non-executable interpreted files 2018-10-15 17:36:41 +02:00
jD91mZM2 75c5c04bee Implement a proper mutex type for future usage 2018-10-15 15:24:14 +02:00
jD91mZM2 23fe526c55 Fix feof and ferror 2018-10-14 15:57:42 +02:00
jD91mZM2 057d23908a Merge branch 'bugfix/netdb-gethostent' into 'master'
Don't drop the host aliases pointer vector in `gethostent`

Closes #130

See merge request redox-os/relibc!170
2018-10-13 15:02:23 +00:00
jD91mZM2 edb95246d4 Fix bug in strncasecmp 2018-10-13 16:55:21 +02:00
Jeremy Soller e4d87a101a Merge branch 'printf' into 'master'
Implement almost all of printf

See merge request redox-os/relibc!171
2018-10-13 14:14:27 +00:00
jD91mZM2 63882684b2 Implement almost all of printf 2018-10-13 14:20:54 +02:00
Benedikt Rascher-Friesenhausen 49259d3f01 Don't drop the host aliases pointer vector in gethostent
There are pointers to this vector in `HOST_ENTRY` so we must keep it around for
as long as `HOST_ENTRY` exists.
2018-10-11 20:59:54 +02:00
jD91mZM2 b517629371 Fix timeradd
wow i am stupid for writing this code
2018-10-11 19:52:54 +02:00
jD91mZM2 1f3154b45c Invoke constructors and destructors
Huge thanks to @xtibor for both discovering that this was still an issue, and also providing information with how to fix it
2018-10-11 16:59:49 +02:00
jD91mZM2 116cbda8d2 Merge branch 'test-ctor-dtor' into 'master'
Add tests for constructors and destructors

See merge request redox-os/relibc!169
2018-10-10 14:06:41 +00:00
Tibor Nagy aee3f68117 Add tests for constructors and destructors 2018-10-09 20:32:27 +02:00
jD91mZM2 f516ff72d8 Merge branch 'regoff_t' into 'master'
Move regoff_t to regex.h

See merge request redox-os/relibc!168
2018-10-09 14:49:53 +00:00
jD91mZM2 0469c0c2c6 Add tests for memcmp and fix a teeny tiny bug 2018-10-09 16:47:57 +02:00
Tibor Nagy 0f5fa8c9d4 Move regoff_t to regex.h 2018-10-09 16:43:34 +02:00
jD91mZM2 3f4fbf9084 Merge branch 'feature/optimise-memcmp' into 'master'
Optimise `memcmp` for speed

See merge request redox-os/relibc!167
2018-10-09 14:20:06 +00:00
Benedikt Rascher-Friesenhausen 8e2b7c11b4 Replace i32 with c_int in memcmp
As per the comments from jD91mZM2 on the merge request.
2018-10-07 17:40:30 +02:00
jD91mZM2 91675b5bc8 realpath on redox: don't forget the nul terminator 2018-10-07 15:12:41 +02:00
jD91mZM2 fba3bf5161 Merge branch 'assert' into 'master'
Make assert more hygienic

See merge request redox-os/relibc!166
2018-10-07 12:50:56 +00:00
jD91mZM2 758f681590 Implement scandir 2018-10-07 14:43:54 +02:00
jD91mZM2 3c8cb95b80 Cleanup strcasecmp 2018-10-07 13:02:05 +02:00
jD91mZM2 0de7d30656 Fix S_IS*
For some reason, C handles `==` before `&`.
So `a & b == c` is the same thing as `a & (b == c)`.
2018-10-07 13:01:59 +02:00
jD91mZM2 028378b8bf Fix double close
Accidentally made file references not count as references and therefore also close the fd. My bad.
2018-10-07 10:54:37 +02:00
jD91mZM2 418a960f3b Implement realpath 2018-10-07 10:32:51 +02:00
Benedikt Rascher-Friesenhausen e10a346356 Optimise memcmp for speed
I saw that in other parts of the `string` module iterations over `usize` were
used to increase iteration speed.  In this patch I apply the same logic to
`memcmp`.  With this change I measured a 7x speedup for `memcmp` on a ~1MB
buffer (comparing two buffers with the same content) on my machine (i7-7500U),
but I did not do any real world benchmarking for the change.  The increase in
speed comes with the tradeoff of both increased complexity and larger generated
assembly code for the function.

I tested the correctness of the implementation by generating two randomly filled
buffers and comparing the `memcmp` result of the old implementation against this
new one.

I ran the tests and currently currently three of them fail:
  - netdb (fails to run)
  - stdio/rename (fails to verify)
  - unistd/pipe (fails to verify)

They do so though regardless of this change, so I don't think they are related.
2018-10-07 10:25:19 +02:00
jD91mZM2 26d629674a Implement strcasestr 2018-10-06 17:37:50 +02:00
jD91mZM2 9d56ce42c6 Implement timer* macros, and GNU's getopt_long 2018-10-06 16:46:35 +02:00
Tibor Nagy 614b2f5103 Make assert more hygienic 2018-10-06 14:55:06 +02:00
jD91mZM2 baddbb98d5 Don't reinvent the wheel in strings.h 2018-10-05 19:33:41 +02:00
jD91mZM2 1acc2a1a32 Initial regex.h implementation 2018-10-05 18:07:43 +02:00
jD91mZM2 dfa3845c33 Make fread/fwrite retry their respective operations 2018-10-02 18:47:42 +02:00
jD91mZM2 6dcc8ee8d9 Implement strtof 2018-10-02 18:47:42 +02:00
Jeremy Soller aec6a48ca4 Merge branch 'termios-baudrate' into 'master'
Add termios baud rate functions

See merge request redox-os/relibc!165
2018-09-29 21:27:31 +00:00
Tibor Nagy db4452e98b Add termios baud rate functions 2018-09-29 22:52:12 +02:00
jD91mZM2 b22d386177 Re-add EOF to bits header
cbindgen can't handle negative numbers, see https://github.com/eqrion/cbindgen/issues/205
2018-09-29 20:02:37 +02:00
jD91mZM2 dd711f4dee Fix bug in fread
Bug discovered by @xTibor. Test and input data provided by him.
2018-09-29 15:04:58 +02:00
jD91mZM2 0451fac66c Delete RawFile in favor of File 2018-09-26 19:40:39 +02:00
jD91mZM2 d365813c90 Merge branch 'core-io' into 'master'
Rewrite IO to use core-io library

See merge request redox-os/relibc!164
2018-09-26 16:56:29 +00:00
jD91mZM2 4f187efc9b Change BUFSIZ type to work with cbindgen 2018-09-26 18:44:04 +02:00
jD91mZM2 243ce18ecd Implement ftell 2018-09-26 17:48:46 +02:00
jD91mZM2 21559bb503 Fix redox compilation 2018-09-26 16:40:23 +02:00
jD91mZM2 afc1ff134a Rewrite IO to use core-io library 2018-09-26 16:13:09 +02:00
Jeremy Soller aff35892be Add fs module 2018-09-24 21:40:40 -06:00
Jeremy Soller 7f14fcdee0 Remove c_str functions, replace with CStr 2018-09-24 21:08:29 -06:00
Jeremy Soller ef9fee5a2b Prepare for use of Write trait by renaming Write to WriteByte 2018-09-24 20:31:06 -06:00
Jeremy Soller 9eef8d7e2d Add core_io 2018-09-24 20:19:37 -06:00
Jeremy Soller b309cd832d Add getopt and machine/endian.h 2018-09-24 14:45:36 -07:00
jD91mZM2 d659377b24 VERY basic crti/crtn 2018-09-23 21:30:13 +02:00
jD91mZM2 6d99915154 Use RAII for file locking in stdio 2018-09-23 20:40:48 +02:00
Jeremy Soller 7e4a60f78b Fix possible deadlocks 2018-09-23 11:58:09 -06:00
jD91mZM2 658dc34d30 A few I/O related fixes 2018-09-23 17:28:42 +02:00
jD91mZM2 1e9dbfdf62 Use cbitset crate 2018-09-22 17:26:58 +02:00
jD91mZM2 2a8bc8331b Fix select return value 2018-09-22 11:12:31 +02:00
Tom Almeida b43299642b Fix buffering issue with large output through stdio 2018-09-21 15:21:39 +02:00
jD91mZM2 29b4c19d6e fixup! Untested fix for pwd.h on redox 2018-09-21 13:13:17 +02:00
jD91mZM2 64acfbb8e3 Format 2018-09-21 08:04:38 +02:00
jD91mZM2 9e9b850b90 Untested fix for pwd.h on redox 2018-09-21 08:04:06 +02:00
Jeremy Soller a0b4e21bbb Comment out SO_ERROR so it is not used 2018-09-20 15:41:59 -07:00
Jeremy Soller a567197b54 enable getsockopt and setsockopt 2018-09-20 14:39:58 -07:00
Jeremy Soller 9dbf49fdcd Format and add O_CLOEXEC where appropriate 2018-09-18 19:52:47 -06:00
jD91mZM2 2aa7597a2b Fix network problem with netdb on redox 2018-09-18 19:14:28 +02:00
Jeremy Soller 043ecf2cf9 Replace a println with a trace 2018-09-18 08:53:37 -06:00
Jeremy Soller 290ecb3e46 - fsync when tracing
- clean up trace macro some
2018-09-18 08:49:44 -06:00
Jeremy Soller 60f00508d3 Restore errno if trace_expr is successful 2018-09-18 08:34:06 -06:00
jD91mZM2 10a7944aef Avoid duplicate code 2018-09-18 08:08:55 +02:00
Jeremy Soller c2f4c1dbc9 Add trace macro and feature 2018-09-17 21:29:40 -06:00
Jeremy Soller 28f4da526d Require all target when building sysroot 2018-09-17 20:28:17 -06:00
Jeremy Soller 2cc5db9de6 Fix Linux compilation 2018-09-17 20:27:59 -06:00
Jeremy Soller 23098b694e Add print, eprint, eprintln, and fix println macros 2018-09-17 15:02:00 -06:00
Jeremy Soller 35bdab7690 Remove protocol check from socket 2018-09-17 15:01:31 -06:00
Jeremy Soller 13cd7d5a5f Oops, extra nul 2018-09-17 10:57:22 -06:00
jD91mZM2 d0a4f2f845 Delete a bunch of leftover constants 2018-09-17 18:44:33 +02:00
Jeremy Soller 76959416bb Add missing open flags 2018-09-17 09:59:41 -06:00
Jeremy Soller 716ea87bb4 Format 2018-09-17 09:46:47 -06:00
Jeremy Soller f3a832ad12 Fixes for select on Redox 2018-09-17 09:46:40 -06:00
Jeremy Soller dfb07e473a Comment out functions not implemented by Redox 2018-09-15 12:31:40 -06:00
Jeremy Soller f661d5d1c0 Fix use of uninitialized memory 2018-09-15 11:14:51 -06:00
Jeremy Soller 9d24e61548 Use alloc_aligned and free functions in platform for global allocator 2018-09-15 11:14:34 -06:00
Jeremy Soller 706a8de7a0 Call _init and _fini 2018-09-15 11:14:05 -06:00
jD91mZM2 882b86e282 Revert 'fix netdb on names with spaces', just ignore invalid lines 2018-09-05 19:24:10 +02:00
jD91mZM2 30d6f079c5 Add missing dirent macros (fixes #129) 2018-09-05 17:39:40 +02:00
jD91mZM2 49ccf364c2 Fix netdb getservbyname on names with spaces 2018-09-05 17:38:59 +02:00
jD91mZM2 eb6ddac1eb Unify gmtime and localtime code
Apparently gmtime was already implemented when I made localtime, so we had two different things written from scratch. We decided in the relibc channel of the Redox OS Mattermost chat to use my code, as it is more extensively tested and perhaps is clearer in how it works.
2018-09-05 15:52:25 +02:00
Tom Almeida 9cb594dca1 Merge branch 'Tommoa:master' into 'master'
Add contribution guidelines/tutorial

See merge request redox-os/relibc!162
2018-09-05 13:03:46 +00:00
Tom Almeida 92e1127b64 Add contribution guidelines/tutorial 2018-09-05 13:03:46 +00:00
jD91mZM2 59d74e194d Fix CI 2018-09-04 15:31:43 +02:00
jD91mZM2 eb2fe7934c Merge branch 'master' into 'master'
Updated url, implemented missing functions in header/arpa_inet/mod.rs

See merge request redox-os/relibc!161
2018-09-04 12:28:13 +00:00
thedarkula e688d9c4d1 Updated url, implemented missing functions in header/arpa_inet/mod.rs 2018-09-04 02:59:59 +01:00
jD91mZM2 50c03f289f Support shebangs in redox execve 2018-09-02 11:15:38 +02:00
jD91mZM2 077e922cc6 fixup! Delete duplicate types 2018-09-02 08:20:19 +02:00
jD91mZM2 26f953e11f Run fmt.sh 2018-09-02 08:17:52 +02:00
jD91mZM2 6fe3e05ea0 Delete duplicate types
Now that we use cbindgen differently :D
2018-09-02 08:17:15 +02:00
jD91mZM2 dbe18b92f0 Merge branch 'netdb' into 'master'
Netdb

See merge request redox-os/relibc!156
2018-09-01 14:00:18 +00:00
Paul Sajna 07eb658a8a Netdb 2018-09-01 14:00:18 +00:00
Jeremy Soller 3dbf9f872a Allow use of custom CC for compiling tests 2018-08-27 14:54:53 -06:00
Jeremy Soller 28912d84d9 Further fixes to tests makefile 2018-08-27 13:29:44 -06:00
Jeremy Soller 82b9715f41 Fix makefile for tests, add sysroot target 2018-08-27 13:02:13 -06:00
Jeremy Soller 70eda382d3 Merge branch 'pal' into 'master'
Intense refactor

See merge request redox-os/relibc!159
2018-08-27 15:27:58 +00:00
Jeremy Soller 0258fb3f5e Fix header path 2018-08-27 08:47:16 -06:00
Jeremy Soller b52c822150 Update Redox module to use CStr 2018-08-27 08:44:42 -06:00
Jeremy Soller c911facca6 Make pal functions take cstr 2018-08-27 08:33:12 -06:00
Jeremy Soller 16373257b0 format 2018-08-27 07:12:37 -06:00
Jeremy Soller 8f5470fd27 Reduce warnings 2018-08-27 07:12:24 -06:00
Jeremy Soller bab4e2896a Format 2018-08-27 06:35:30 -06:00
Jeremy Soller 7ab700315d Fix warnings and add c_str 2018-08-26 15:15:29 -06:00
Jeremy Soller 6418f893e4 Fix headers with directories 2018-08-26 12:40:19 -06:00
Jeremy Soller 124e118f9f Fix makefile 2018-08-26 12:35:41 -06:00
Jeremy Soller ed00ddfb54 Fix remaining issues, move setjmp into relibc crate, move start logic into relibc 2018-08-26 12:28:27 -06:00
Jeremy Soller c63c930e4a Make it compile 2018-08-26 12:10:02 -06:00
Jeremy Soller 277b9abcd5 Fix build, mostly 2018-08-26 08:56:02 -06:00
Jeremy Soller c20ce5ffed Large reorganization of headers (WIP) 2018-08-26 08:11:35 -06:00
Jeremy Soller ff32c8cbbd Remove stat and lstat, which can be replaced with open and fstat 2018-08-25 10:13:58 -06:00
Jeremy Soller 34f5f57213 Fix signal and socket pal implementations on Redox 2018-08-25 09:21:08 -06:00
Jeremy Soller d1dabccdce Fix missing modules in Redox platform 2018-08-25 09:14:02 -06:00
Jeremy Soller 165f099c6b Update Redox platform to pal 2018-08-25 09:07:35 -06:00
Jeremy Soller 729709a8e6 Update all modules to new Pal mechanism 2018-08-25 08:42:57 -06:00
Jeremy Soller e6f163823c WIP: platform abstraction layer 2018-08-24 20:13:07 -06:00
Jeremy Soller c25ce6a5f3 Include stddef.h in sys/types.h 2018-08-18 08:27:40 -06:00
Jeremy Soller f1df1f9f0b Fix issue with stdio.h bits file not having FILE defined 2018-08-18 08:22:16 -06:00
Jeremy Soller 83cb46afd8 Fix path to crt0.o and libc.a 2018-08-18 08:15:14 -06:00
Jeremy Soller 2e8cb6b363 Fix signature of unsetenv 2018-08-17 20:07:00 -06:00
Jeremy Soller 4e3b6732d5 Default to release for make 2018-08-17 18:41:16 -06:00
jD91mZM2 128209788c Finish up fexec migration 2018-08-13 14:46:59 +02:00
jD91mZM2 66d7aa8553 Revert 'Fix off by one error' because it introduces one
Turns out, it's just redox not having a NULL pointer here. Linux does.
2018-08-13 11:37:29 +02:00
jD91mZM2 d5f85906cb Fix off-by-one error :| 2018-08-12 21:50:22 +02:00
jD91mZM2 1c4e8852dd Migrate to new FEXEC system call 2018-08-12 20:35:45 +02:00
jD91mZM2 07563de231 Implement setenv/unsetenv 2018-08-12 07:43:23 +02:00
jD91mZM2 232a3311df Add SIGABRT to redox 2018-08-10 08:33:11 +02:00
jD91mZM2 b10fa984f3 Implement strtod 2018-08-09 16:35:49 +02:00
jD91mZM2 face6f07f3 Implement mmap 2018-08-09 10:54:44 +02:00
Tom Almeida 3aa52e88a7 Fix issues with _IONBF and reading 2018-08-09 02:51:37 +08:00
Tom Almeida d5a9cd6953 Add tests to make sure setvbuf works. 2018-08-09 02:08:53 +08:00
Tom Almeida 540395c015 Fix _IONBF crashing when reading 2018-08-09 02:07:19 +08:00
Tom Almeida a1ebe321d6 Ensure that _IONBF would be respected when writing 2018-08-09 01:38:57 +08:00
jD91mZM2 40c3d28a41 fixup! Fix a few ffmpeg issues 2018-08-08 19:29:02 +02:00
jD91mZM2 b0546336c7 Fix a few ffmpeg issues 2018-08-08 19:28:13 +02:00
Tom Almeida d219d57acb Fix an issue where _IONBF would cause an overflow error 2018-08-09 00:49:57 +08:00
jD91mZM2 deee825a1c Implement llabs 2018-08-08 16:25:10 +02:00
jD91mZM2 b26213731c Don't forget to lock stdout when printfing 2018-08-08 13:25:26 +02:00
jD91mZM2 23a8855e50 Fix garbage env pointer to main on redox 2018-08-08 11:01:16 +02:00
jD91mZM2 40a7380a58 Fix snprintf and make strftime use a counting writer 2018-08-07 21:31:05 +02:00
jD91mZM2 d39a66c351 Fix waitpid -1 on redox 2018-08-07 15:01:07 +02:00
jD91mZM2 3bb3a3e322 Fix strcpy 2018-08-07 11:35:23 +02:00
jD91mZM2 f6ca7d7c2d Add S_ISSOCK and fix str(c)spn 2018-08-05 21:49:45 +02:00
jD91mZM2 b20307dca0 Implement fnmatch.h 2018-08-05 19:50:49 +02:00
jD91mZM2 b5adee798d Move scanf unit tests to normal C tests 2018-08-05 09:53:07 +02:00
jD91mZM2 442a7bbedc Fix getcwd with a NULL argument 2018-08-04 08:42:47 +02:00
jD91mZM2 ba8bd8c4e8 Add the last few things for bash to compile :D 2018-08-03 11:18:52 +02:00
jD91mZM2 44599a032e Kind of get bash to compile
Doesn't link yet due to "multiple definitions of malloc", because some are supplied by some library of bash itself. Really odd.
2018-08-02 14:37:57 +02:00
jD91mZM2 9c57c222f6 Fix strcasecmp 2018-07-31 07:37:19 +02:00
jD91mZM2 daf65c7a46 Implement access 2018-07-30 21:08:44 +02:00
jD91mZM2 ce53ac7e13 Fix inttypes a little 2018-07-30 12:32:03 +02:00
jD91mZM2 2a303c4b60 Implement sys/file.h 2018-07-30 10:04:58 +02:00
jD91mZM2 d3e4fa71a5 Implement sys/select.h
I really really wish I could actually test this on redox. All I know is: it compiles
2018-07-29 17:26:54 +02:00
Jeremy Soller bc7f7356b9 Fix redox futimens fd type 2018-07-29 07:22:41 -06:00
Jeremy Soller a9fcb973f6 Implement utimes and utime
Format
2018-07-29 07:18:44 -06:00
jD91mZM2 3eb7b99799 Move test binaries to tests/bins/ 2018-07-29 10:04:11 +02:00
jD91mZM2 f82b48b839 Implement sys/times.h on linux 2018-07-29 09:23:56 +02:00
jD91mZM2 e7e9d57db5 Implement a dummy sgtty 2018-07-29 07:55:19 +02:00
jD91mZM2 65cbd40fce Remove an accidentally committed binary. Again. Sigh. 2018-07-29 07:19:23 +02:00
jD91mZM2 4a42983d13 Make sigset_t be a long because bash needs that to compile 2018-07-28 17:18:53 +02:00
jD91mZM2 7524a83d82 fixup! sigemptyset and sigaddset 2018-07-28 15:33:06 +02:00
jD91mZM2 892ce75eb4 sigemptyset and sigaddset 2018-07-28 14:10:57 +02:00
jD91mZM2 6da2639dfa Fix leaking uninitialized elements and missing free 2018-07-28 08:22:21 +02:00
jD91mZM2 3c88056f9d Implement getrusage on linux 2018-07-27 19:54:30 +02:00
jD91mZM2 193328952d Alias memory.h to string.h 2018-07-27 18:27:51 +02:00
jD91mZM2 fc910d4157 Merge branch 'fix-parallel-builds' into 'master'
Turn the libc and libm rules into 'order-only' prequisites

Closes #127

See merge request redox-os/relibc!158
2018-07-27 16:02:49 +00:00
Robin Randhawa cb046c78e4 Turn the libc and libm rules into 'order-only' prequisites
These prerequisites are GNU Make terminology.

This change forces the libc rule to be executed first so that the headers that
the libm rule needs are available. The original setup was using 'normal'
prerequisites which occasionally resulted in bizarre build breakage,
especially on multi-core build hosts. Seen often on my 8-way SMP build
host.

Note that this doesn't impede parallelisation of each rule indepent of
the other. It just serializes the rules themselves.

This fixes: https://gitlab.redox-os.org/redox-os/relibc/issues/127
2018-07-27 16:51:15 +01:00
jD91mZM2 f6b364845e Implement pwd.h 2018-07-27 15:15:56 +02:00
jD91mZM2 1b40f2d463 Implement setitimer/getitimer/alarm/ualarm 2018-07-27 08:22:17 +02:00
jD91mZM2 8b48b6959c fixup! Implement isatty 2018-07-26 14:32:10 +02:00
jD91mZM2 2bf426b0fb Implement isatty 2018-07-26 14:19:20 +02:00
jD91mZM2 7ff6940edd Implement futimens 2018-07-26 13:26:54 +02:00
jD91mZM2 a0f2baff12 Implement gettimeofday 2018-07-26 10:07:33 +02:00
jD91mZM2 83949290c9 Implement dirent.h 2018-07-26 09:16:22 +02:00
jD91mZM2 dec5e0a019 Add missing sockaddr_in to platform/src/types.rs 2018-07-25 14:39:28 +02:00
jD91mZM2 e749d23030 Solve stdin/out/err UB in a better way 2018-07-25 14:29:14 +02:00
jD91mZM2 992e50ef0f Fix a few things with openssl 2018-07-25 14:04:36 +02:00
jD91mZM2 0e48937991 Merge branch 'tmpfile' into 'master'
Implement tmpfile

See merge request redox-os/relibc!154
2018-07-25 06:32:19 +00:00
stratact 42811717da Remove unneeded reference 2018-07-24 23:22:00 -07:00
stratact 5f6309d87c Implement tmpfile (squashed) 2018-07-24 23:14:18 -07:00
jD91mZM2 8021ade2a9 Move stat test out of expected tests 2018-07-23 21:41:19 +02:00
jD91mZM2 dc427272af fixup! Fix stat stack corruption and link test 2018-07-23 21:21:15 +02:00
jD91mZM2 5697ac0f84 Fix stat stack corruption and link test 2018-07-23 11:26:18 +02:00
jD91mZM2 86a38b47d1 Fix broken exec test 2018-07-22 19:57:59 +02:00
jD91mZM2 ecd8aca6d6 Basic signal support 2018-07-22 17:04:13 +02:00
jD91mZM2 7b8e7feb3d Run fmt.sh 2018-07-22 11:33:01 +02:00
jD91mZM2 67d5976622 Clean up tests 2018-07-22 11:24:50 +02:00
jD91mZM2 e9484e4d60 Ignore *all* target directories 2018-07-22 10:21:14 +02:00
jD91mZM2 27e8174e10 Combine mktemp and mkostemps logic 2018-07-22 10:17:09 +02:00
jD91mZM2 e4a89ae645 Merge branch 'mkstemp' into 'master'
Implement `mkstemp` and `mkostemps`

See merge request redox-os/relibc!152
2018-07-22 07:19:22 +00:00
stratact c788f7ed26 Add expected tests 2018-07-22 00:01:43 -07:00
stratact 6fa1f60830 Implement mkstemp and mkostemps (squashed) 2018-07-21 10:25:19 -07:00
jD91mZM2 7d43d45e56 Merge branch 'arpa_inet' into 'master'
implement arpainet

See merge request redox-os/relibc!153
2018-07-19 16:02:51 +00:00
Paul Sajna 0550a7b9db implement arpainet 2018-07-19 16:02:51 +00:00
jD91mZM2 233e679c08 Make inner platform functions private once more 2018-07-18 10:04:17 +02:00
jD91mZM2 ff9ef98f47 Move gethostname to platform 2018-07-18 10:02:42 +02:00
jD91mZM2 0a57c617c7 Remove a useless comment 2018-07-18 08:07:00 +02:00
jD91mZM2 5b3e09ee16 fixup! strcoll as strcmp because no locale 2018-07-17 18:35:54 +02:00
jD91mZM2 878208485c strcoll as strcmp because no locale 2018-07-17 17:44:38 +02:00
jD91mZM2 482bd9c5f1 fmt.sh 2018-07-17 17:24:22 +02:00
jD91mZM2 b83d1c7ff0 strftime :D 2018-07-17 16:47:33 +02:00
Jeremy Soller 37b6cd942c Fix pipe 2018-07-14 12:29:18 -06:00
jD91mZM2 515d041153 Hehe make environment tests work for everybody 2018-07-14 19:53:56 +02:00
jD91mZM2 75145ab92b Pass envp to main 2018-07-14 19:48:10 +02:00
jD91mZM2 019011f029 WIP env support 2018-07-14 18:03:22 +02:00
Jeremy Soller dc443a8cc3 Format 2018-07-13 09:53:44 -06:00
Jeremy Soller 4c4ce80fcd Fix warnings 2018-07-13 09:52:53 -06:00
Jeremy Soller 52e02286f2 Merge branch 'master' of https://gitlab.redox-os.org/redox-os/relibc 2018-07-13 09:24:42 -06:00
Jeremy Soller 4718796c2b Merge branch 'master' of https://gitlab.redox-os.org/redox-os/relibc 2018-07-13 09:23:13 -06:00
jD91mZM2 9cb0881cc4 Alias wbstowcs and wbtowc to their correct functions 2018-07-13 15:01:13 +02:00
jD91mZM2 5f098c89c3 Add more tests for mktime and localtime 2018-07-13 10:16:42 +02:00
jD91mZM2 a9ea2ef64e Fixup time & support negative & mktime 2018-07-13 09:13:46 +02:00
Jeremy Soller c2cdb451f5 Add system 2018-07-12 20:00:41 -06:00
jD91mZM2 758b437170 Run fmt.sh 2018-07-12 21:40:44 +02:00
jD91mZM2 b7e11afd2f Add localtime and ctime functions
I have NO IDEA if these are correct. Implementation was 'inspired by' https://github.com/rust-lang-deprecated/time/commit/4ca23fb14ddf44fd90609fec6a2fb1efcedb8ea3. Pretty darn certain that negative values won't work
2018-07-12 21:39:53 +02:00
jD91mZM2 a7cc95cd90 Comment out #[no_mangle] on unimplemented functions
This stops configure scripts from identifying them as valid
2018-07-12 21:39:53 +02:00
Jeremy Soller b8cab5f0be Fix missing stdint.h in signal.h 2018-07-12 11:12:41 -06:00
Jeremy Soller b7eb7a43e0 Update lock file 2018-07-12 09:50:00 -06:00
Jeremy Soller 463c9f386c Fix issue with RUSAGE constants not being in C headers if negative 2018-07-12 09:49:53 -06:00
Jeremy Soller 9c27110de1 Add rusage constants 2018-07-12 09:09:30 -06:00
Jeremy Soller 6e56734224 Fix environ signature 2018-07-12 09:00:58 -06:00
Jeremy Soller 99fa77535a Add pathconf variables 2018-07-12 09:00:23 -06:00
Jeremy Soller 9fc785dcc6 Add stack_chk functionality 2018-07-12 07:40:53 -06:00
Jeremy Soller 6c11a18240 Go back to patched ralloc 2018-07-11 09:59:28 -06:00
jD91mZM2 5f4ebaaabf Fix broken ralloc submodule & fmt.sh 2018-07-11 17:13:38 +02:00
jD91mZM2 55e618d8c0 Add the last socket functions on linux; leave unimplemented on redox 2018-07-11 12:49:50 +02:00
jD91mZM2 6d923cbd0b Implement getpeername and getsockname 2018-07-11 11:43:38 +02:00
jD91mZM2 30d91b82b2 Run fmt.sh 2018-07-08 08:51:15 +02:00
jD91mZM2 d3f6985ee9 Add a few things necessary for openssl (not all) 2018-07-08 08:44:23 +02:00
jD91mZM2 587ee32a30 Merge branch 'style-tag' into 'master'
Use style = Tag everywhere possible

See merge request redox-os/relibc!151
2018-07-08 06:38:45 +00:00
jD91mZM2 985a83ee69 Use style = Tag everywhere possible 2018-07-06 17:02:23 +02:00
jD91mZM2 53f634f579 Fix inttypes 2018-07-06 17:01:52 +02:00
jD91mZM2 eaf7338946 Add aliases for compatibility 2018-07-06 13:39:07 +02:00
Jeremy Soller 919ae09d2f Fix compilation on Redox 2018-07-04 10:16:34 -06:00
Jeremy Soller 3361b05911 Merge branch 'master' of https://gitlab.redox-os.org/redox-os/relibc 2018-07-04 10:12:32 -06:00
Jeremy Soller ea5f8d59de Add dlmalloc 2018-07-04 10:10:34 -06:00
jD91mZM2 e206400d19 Move exec* back to platform
This undos a workaround. Jeremy moved the ralloc stuff to platform and suddenly this seems to work again. I don't know what is different from when I tried this before and now, but I don't really care
2018-07-04 09:29:34 +02:00
Jeremy Soller 3ef9599af5 Update ralloc 2018-07-03 21:18:23 -06:00
Jeremy Soller 42abc98a99 Cleanup allocation functions 2018-07-03 19:40:47 -06:00
Jeremy Soller b6b34a7026 Ralloc fixes and fixes for Redox execution 2018-07-03 19:07:07 -06:00
Jeremy Soller 7e6e1b164c Align stack on x86_64 2018-07-03 11:31:05 -06:00
jD91mZM2 6a0928edfd Use relibc to build openlibm 2018-07-03 19:01:24 +02:00
jD91mZM2 9c169a186f Run fmt.sh 2018-07-03 09:33:41 +02:00
jD91mZM2 aff5380723 Merge branch 'master' into 'master'
Fixing some things in stdio

See merge request redox-os/relibc!136
2018-07-03 07:21:02 +00:00
Tom Almeida 53a03cb0ba Made sure errors were properly handled by printf 2018-07-03 14:50:38 +08:00
Tom Almeida 8bc07abd05 Fix freopen.stdout. There was a trailing space 2018-07-03 14:42:31 +08:00
Tom Almeida ebe1ed15f8 Fix fgets 2018-07-03 14:34:40 +08:00
Tom Almeida bf2973e857 Ensure we correctly insert null character in gets 2018-07-03 12:50:04 +08:00
Tom Almeida d7a0f3d526 Ensure gets stops on newline or bufchar 2018-07-03 12:36:41 +08:00
Tom Almeida bf6db91993 Actually remove stdlib from stdio. This should have been done with wchar being put in, but I messed something up 2018-07-03 12:24:51 +08:00
Tom Almeida 72177be0fa Add a working implementation of gets 2018-07-03 12:14:30 +08:00
Tom Almeida 7277286efd Implement Drop for FILE, so we flush when the process exits 2018-07-03 10:05:12 +08:00
Tom Almeida 81107f8cd1 Don't reset read/write every time we check if we can read or write 2018-07-03 10:01:48 +08:00
Tom Almeida e9cecfead3 Return -1 for error in printf 2018-07-03 09:48:21 +08:00
Tom Almeida 0d61f9f4fd Make sure we can actually write before writing anything when using printf 2018-07-03 09:13:48 +08:00
Tom Almeida da664d4919 Merged relibc with branch 2018-07-03 08:39:04 +08:00
jD91mZM2 30ec8aa2c9 Add redox to CI 2018-07-02 10:35:40 +02:00
jD91mZM2 07dbc6bd76 Fix no_std on redox
Apparently a root-level cfg does not go well with a root-level no_std
2018-07-02 08:53:13 +02:00
jD91mZM2 17778ba1b4 Remove missing rustfmt.toml options 2018-07-02 07:42:33 +02:00
jD91mZM2 9c01673422 Use no_std in inttypes (whoops) 2018-07-01 21:00:03 +02:00
Stephan Vedder cc210361d6 wchar support 2018-07-01 20:59:37 +02:00
jD91mZM2 fb09b03acf Fix compilation on redox 2018-07-01 17:55:24 +02:00
Jeremy Soller 396a6dbb90 Merge branch 'mggmuggins/ci' into 'master'
Stage and Cache build

See merge request redox-os/relibc!150
2018-06-30 21:59:01 +00:00
SamwiseFilmore b911a76de4 Stage and Cache build 2018-06-30 21:01:12 +00:00
jD91mZM2 0567f699a2 Merge branch 'master' into 'master'
Workaround compilation errors

See merge request redox-os/relibc!149
2018-06-30 14:14:04 +00:00
jD91mZM2 541fbcf57c Use ptr::null over 0 2018-06-30 12:19:39 +02:00
jD91mZM2 1fd9a5f249 Moooore fixes :| 2018-06-30 12:15:51 +02:00
Tom Almeida 05b4b76426 Fix some issues 2018-06-30 17:49:34 +08:00
Tom Almeida 10a9081b66 Made sure that something that's unsafe is actually marked as unsafe 2018-06-30 17:47:30 +08:00
Tom Almeida 18418254b9 Made sure lazy_static works with no_std 2018-06-30 17:37:26 +08:00
Tom Almeida 8075447fad Changed FILE to use a vector as a buffer instead of raw pointers. This allows us to remove the large majority of unsafe blocks from the code 2018-06-30 17:37:26 +08:00
Tom Almeida 57f7de1e6d Changed FILE to use a vector as a buffer instead of raw pointers. This allows us to remove the large majority of unsafe blocks from the code 2018-06-30 17:33:02 +08:00
Tom Almeida 4c65f14f9a Fixed some issues with temporary files and moved some raw pointers to Option<&T>s 2018-06-30 17:26:39 +08:00
Tom Almeida 71fa4026f5 Changed FILE to use a vector as a buffer instead of raw pointers. This allows us to remove the large majority of unsafe blocks from the code 2018-06-30 17:26:35 +08:00
Tom Almeida a2dc22123f Merge branch 'master' into 'master'
# Conflicts:
#   src/stdio/src/default.rs
2018-06-30 09:19:54 +00:00
jD91mZM2 2f6467bce6 Fix test warning 2018-06-30 09:26:46 +02:00
jD91mZM2 674d4e3695 Preallocate because why not 2018-06-30 09:25:05 +02:00
jD91mZM2 234632d319 Workaround compilation errors 2018-06-30 09:19:06 +02:00
Jeremy Soller 29a626cd7c Merge branch 'unistd' into 'master'
Exec Functions (again) (again)

See merge request redox-os/relibc!144
2018-06-28 19:24:04 +00:00
Paul Sajna 5c5e237042 Exec Functions (again) (again) 2018-06-28 19:24:04 +00:00
Jeremy Soller da992bff56 Merge branch 'master' into 'master'
Fix off-by-one error and remove utf8 check in mktemp

See merge request redox-os/relibc!148
2018-06-28 11:36:02 +00:00
jD91mZM2 8e7cd11bc0 Fix CI 2018-06-28 08:31:34 +02:00
jD91mZM2 2c0f9ce747 Fix off-by-one error and remove utf8 check in mktemp 2018-06-28 08:03:17 +02:00
Jeremy Soller e4be43f617 Adjust list of expected binaries 2018-06-27 15:12:14 -06:00
Jeremy Soller 2e3eda4612 Add more expected files 2018-06-27 15:08:29 -06:00
Jeremy Soller cf6c8093ab Update expected output 2018-06-27 15:06:19 -06:00
Jeremy Soller 1f1665fd58 Merge branch 'master' into 'master'
Add the few last things to get gcc_complete working

See merge request redox-os/relibc!146
2018-06-27 21:02:30 +00:00
Jeremy Soller abbf0c9609 Add mktemp test binary to gitingore 2018-06-27 14:33:47 -06:00
Jeremy Soller 2dbe7ebee0 Update ralloc 2018-06-27 14:33:03 -06:00
Jeremy Soller b5da8aa35c Merge branch 'mggmuggins/ci' into 'master'
Add Gitlab CI

See merge request redox-os/relibc!140
2018-06-27 20:31:11 +00:00
Jeremy Soller 6939ca7d7a Merge branch 'mktemp' into 'master'
implement mktemp

See merge request redox-os/relibc!145
2018-06-27 20:22:12 +00:00
Paul Sajna 776491bae9 implement mktemp 2018-06-27 20:22:12 +00:00
jD91mZM2 a6ffd2cc46 Update inttypes to match the revert of ints 2018-06-27 08:08:14 +02:00
jD91mZM2 cbc3723c66 Fix signal not being linked correctly 2018-06-26 17:16:56 +02:00
jD91mZM2 727324fd73 Apparently cbindgen works on constants 2018-06-26 16:57:56 +02:00
jD91mZM2 9de73d0e5b Add uname and gethostname 2018-06-26 16:41:19 +02:00
jD91mZM2 844e244851 Use both Tag and Type 2018-06-26 16:05:02 +02:00
jD91mZM2 3927b0ab44 Revert int definitions 2018-06-26 14:10:20 +02:00
jD91mZM2 5fc1459eb9 signal: Make constants visible from C 2018-06-26 11:23:22 +02:00
jD91mZM2 0776de1ae6 Fix inttypes 2018-06-26 11:10:44 +02:00
jD91mZM2 257040e164 Fix a few stat-related things 2018-06-26 10:47:48 +02:00
jD91mZM2 ad324a0e4d Use global_asm for setjmp instead 2018-06-26 10:21:44 +02:00
jD91mZM2 feed73ffcc inttypes 2018-06-26 09:51:07 +02:00
jD91mZM2 5537817594 Export libm as well 2018-06-26 08:35:27 +02:00
jD91mZM2 441bf9f00b Add the few last things to get gcc_complete working 2018-06-25 11:43:44 +02:00
Jeremy Soller a63e6b3dd8 Merge branch 'master' into 'master'
Revert openlibm install script

See merge request redox-os/relibc!143
2018-06-24 18:50:40 +00:00
jD91mZM2 320eb0ecd0 Revert openlibm install script
Turns out that this only worked because I didn't clean before rebuilding, so it still had access to the old files. Sorry.
2018-06-24 20:19:06 +02:00
Jeremy Soller f265d7c5be Fix linking issues with lang items 2018-06-24 09:56:08 -06:00
Jeremy Soller 878f466b67 Update to new ralloc, new panic implementation, new compiler-builtins 2018-06-24 09:50:15 -06:00
Jeremy Soller be0aed56bc Merge branch 'master' into 'master'
Fix openlibm & fenv and add more integer types

See merge request redox-os/relibc!141
2018-06-24 13:18:34 +00:00
jD91mZM2 72e9525828 Add U?INT([0-9]+)_LEAST([0-9]+)_MIN/MAX macros 2018-06-24 14:27:42 +02:00
jD91mZM2 3e67314b97 Fix openlibm & fenv and add more integer types 2018-06-24 14:12:24 +02:00
SamwiseFilmore 59f1b37be8 Fix dumb mistake 2018-06-24 00:51:37 +00:00
SamwiseFilmore 382c6efb39 Add Gitlab CI 2018-06-24 00:48:54 +00:00
Jeremy Soller 7f0908eb8e Merge branch 'master' into 'master'
Reuse musl's setjmp implementation

See merge request redox-os/relibc!139
2018-06-23 17:46:01 +00:00
jD91mZM2 2283243d95 Replace setjmp lib.rs with empty file 2018-06-23 17:38:15 +02:00
jD91mZM2 4e99b55417 Implement basic setjmp using musl's awesome existing code 2018-06-23 17:38:10 +02:00
Jeremy Soller 6e67d30486 Merge branch 'master' into 'master'
Install openlibm from Makefile

See merge request redox-os/relibc!138
2018-06-23 08:33:27 +00:00
jD91mZM2 829bc64ad6 Remove unused import from test 2018-06-23 07:54:36 +02:00
Tom Almeida 7e731e0b01 Made sure lazy_static works with no_std 2018-06-23 13:08:28 +08:00
jD91mZM2 5945de62cb Install openlibm from Makefile 2018-06-23 06:54:23 +02:00
Tom Almeida c7bdd31a18 Merged relibc (#311db758) with branch 2018-06-23 05:13:02 +08:00
Tom Almeida 6bc28203ca Changed FILE to use a vector as a buffer instead of raw pointers. This allows us to remove the large majority of unsafe blocks from the code 2018-06-23 05:01:43 +08:00
jD91mZM2 12ce441f5c Use static mut over UnsafeCell 2018-06-22 22:40:30 +02:00
Tom Almeida b5529c9b71 Fixed some issues with temporary files and moved some raw pointers to Option<&T>s 2018-06-23 04:28:03 +08:00
Tom Almeida 5921f00e90 Changed FILE to use a vector as a buffer instead of raw pointers. This allows us to remove the large majority of unsafe blocks from the code 2018-06-23 04:28:00 +08:00
Jeremy Soller 8fd77a4b13 Merge branch 'master' into 'master'
Fix undefined behavior

See merge request redox-os/relibc!137
2018-06-22 20:07:31 +00:00
Tom Almeida 43a3c5677a Merged relibc (20/06/2018) with branch 2018-06-23 03:49:19 +08:00
Tom Almeida 50bfebfe3e Fixed some issues with temporary files and moved some raw pointers to Option<&T>s 2018-06-23 03:44:33 +08:00
Tom Almeida 90c6937f17 Changed FILE to use a vector as a buffer instead of raw pointers. This allows us to remove the large majority of unsafe blocks from the code 2018-06-23 03:44:30 +08:00
jD91mZM2 ea24699798 Fix undefined behavior
Transmuting from an immutable to a mutable reference is undefined
behavior in Rust, with the exception of UnsafeCell which tells the
optimizer to not draw too many conclusions. Sadly UnsafeCell::get cannot
yet be used in statics (see https://github.com/rust-lang/rust/issues/51718),
so this works around that by making the statics into functions and
making C macros to call those.
2018-06-22 21:17:44 +02:00
jD91mZM2 3034114c14 Fix broken comment 2018-06-22 15:02:34 +02:00
Jeremy Soller ccb74c6efc Merge branch 'master' into 'master'
Add empty locale functions

See merge request redox-os/relibc!135
2018-06-22 12:59:10 +00:00
jD91mZM2 0a3c8abe95 Fix setlocale return value 2018-06-22 14:54:16 +02:00
jD91mZM2 996445a6a3 Add empty locale functions 2018-06-22 14:54:10 +02:00
Jeremy Soller 05f7371e46 Merge branch 'master' into 'master'
Add scanf

See merge request redox-os/relibc!134
2018-06-21 16:58:41 +00:00
jD91mZM2 91221645c5 Add *scanf to header 2018-06-21 18:52:41 +02:00
jD91mZM2 5936c7a76e Add scanf 2018-06-21 17:16:56 +02:00
Tom Almeida 77b160c70d Fixed some issues with temporary files and moved some raw pointers to Option<&T>s 2018-06-21 09:33:21 +08:00
Jeremy Soller 6f8fff4b1c Merge branch 'sys_wait_macros' into 'master'
sys_wait: implement C macros properly

See merge request redox-os/relibc!133
2018-06-20 18:43:34 +00:00
Jasen Borisov 06a8d5d89d sys_wait: implement C macros properly
Remove the broken Rust functions and instead provide C macros in a
`include/bits` header. The C macros were taken from musl.
2018-06-20 19:40:38 +01:00
Tom Almeida 454ce67d45 Changed FILE to use a vector as a buffer instead of raw pointers. This allows us to remove the large majority of unsafe blocks from the code 2018-06-21 00:20:21 +08:00
Jeremy Soller 895e250564 Add aligned_alloc 2018-06-20 09:53:27 -06:00
Jeremy Soller 9d38494435 Fix missing strtol, strtoul 2018-06-20 09:44:09 -06:00
Jeremy Soller 1b653c4e60 Update ralloc, fix invalid c++ names 2018-06-20 08:48:56 -06:00
Jeremy Soller 009ceec188 Merge branch 'sys_wait_fix' into 'master'
Fix compilation error in `sys_wait`

See merge request redox-os/relibc!132
2018-06-14 20:09:46 +00:00
Jasen Borisov 326078a578 Fix compilation error in sys_wait 2018-06-14 20:15:25 +01:00
Jeremy Soller c5552cbb39 Merge branch 'fix-81' into 'master'
Add `sys_wait` functions (Fixes #81)

Closes #81

See merge request redox-os/relibc!131
2018-06-14 13:45:32 +00:00
stratact 3fa220237d Add sys_wait functions (Fixes #81) 2018-06-14 05:08:55 -07:00
Jeremy Soller a573549df8 Update links to gitlab 2018-06-12 12:30:45 -06:00
Jeremy Soller fd05aca991 Update README.md 2018-05-24 15:00:40 -06:00
Jeremy Soller 1f9f7ce6c8 Merge pull request #127 from stratact/master
Update `platform::rawfile`
2018-05-24 14:36:06 -06:00
stratact 3aa01b6907 Remove pointless cast 2018-05-24 13:27:24 -07:00
stratact a7a415603f Fix stupid mistake 2018-05-24 13:04:58 -07:00
stratact 16c51a297d Use the right C types from platform::types 2018-05-24 12:29:59 -07:00
Jeremy Soller f0227e737e Merge pull request #128 from ids1024/lifetime
Make functions taking raw pointer return &'a instead of &'static
2018-05-24 12:44:19 -06:00
Jeremy Soller aead6d8fd0 Merge pull request #129 from ids1024/cstr
Simplify cstr_from_bytes_with_nul_unchecked()
2018-05-24 12:43:48 -06:00
Ian Douglas Scott 5bcf1d42ff Simplify cstr_from_bytes_with_nul_unchecked()
The original implementation is modified from the `Cstr` method, but the
complexity there exists because it is trying to convert to the DST `Cstr`.
2018-05-24 11:27:35 -07:00
Ian Douglas Scott cbd0d0473c Make functions taking raw pointer return &'a instead of &'static
This is technically more correct, and matches the pointer methods in the
standard library.
2018-05-24 11:13:55 -07:00
stratact b389e4831d Have open() and dup() match -1 for Err instead of 0 2018-05-24 10:33:15 -07:00
stratact 9daae71c2a Use the super module instead of sys 2018-05-23 19:35:28 -07:00
stratact bb9d0e4aa1 Implement RawFile::from_raw_fd() 2018-05-23 13:14:42 -07:00
stratact 285d1b05c4 Implement RawFile::open() and add *_raw_df() convenience methods 2018-05-23 11:05:43 -07:00
stratact 7ca5fac214 Implement RawFile::dup() completely 2018-05-23 08:00:53 -07:00
Jeremy Soller 3311a700e0 Merge pull request #126 from ProgVal/update-ralloc
Update ralloc. Closes GH-83.
2018-05-20 07:27:15 -06:00
Valentin Lorentz 0b6d6549f1 Update ralloc. Closes GH-83. 2018-05-20 14:13:36 +02:00
Jeremy Soller ed12713aa8 Update gitignore for tests 2018-05-15 18:35:29 -06:00
Jeremy Soller c647fdfed3 Merge pull request #116 from matijaskala/patch-1
Add optimized version of memchr
2018-05-15 18:33:31 -06:00
Jeremy Soller 8eec109cc0 Merge pull request #120 from Majora320/master
Implement clock() and add CLOCK_* constants
2018-05-15 18:32:29 -06:00
Jeremy Soller c8d4ea3ee6 Merge pull request #123 from Arcterus/qsort-real
stdlib: implement qsort() as an introsort
2018-05-15 18:31:50 -06:00
Jeremy Soller 4fb4790890 Merge pull request #122 from Arcterus/qsort
Fix a bug in printf()
2018-05-15 18:31:21 -06:00
Matija Skala 9bbb070104 Add optimized version of memchr 2018-05-15 21:06:17 +02:00
Alex Lyon f5ded007c6 stdlib: recurse into the smaller partition when sorting 2018-05-13 16:16:48 -07:00
Alex Lyon 4d3ac1c0dc stdlib: save stack space by looping in introsort_helper() 2018-05-13 03:29:53 -07:00
Alex Lyon b15aa83a8a stdlib: move insertion sort from introsort() into a separate function 2018-05-13 03:15:16 -07:00
Alex Lyon aa21e5fc3f stdlib: implement qsort() as an introsort 2018-05-13 03:07:00 -07:00
Jeremy Soller 6e8e6ad5d2 Merge pull request #121 from Arcterus/strtoul
stdlib: implement strtoul() and strtol() using a macro
2018-05-12 06:24:18 -06:00
Alex Lyon 0cabecd5b5 stdio, string, platform: fix a bug in printf() involving chars
Because we were previously converting the bytes in the format
string into Rust's char type and then printing that using the
format machinery, byte values that were not valid single-byte
UTF-8 characters failed to print correctly.  I found this while
trying to implement qsort() because the output of my test program
was mysteriously incorrect despite it working when I used glibc.
2018-05-11 23:09:12 -07:00
Moses Miller d14d0b5965 Fix various formatting issues 2018-05-11 22:01:51 -07:00
Moses Miller 766e00c69e Implement conversion of nanoseconds to clocks in terms of CLOCKS_PER_SEC 2018-05-11 17:22:01 -07:00
Moses Miller 3d1a66f270 Add CLOCKS_PER_SEC 2018-05-11 16:26:56 -07:00
Moses Miller 9d8758006d Change 1000000 to 1_000_000 2018-05-11 11:41:18 -07:00
Alex Lyon 1bcc40c08f stdlib: manually fix formatting 2018-05-11 09:31:58 -07:00
Alex Lyon 7647db27c0 stdlib: implement strtoul() and strtol() using a macro 2018-05-11 01:48:27 -07:00
Moses Miller 56458e5e4c Condense 5 lines into 1 2018-05-10 20:48:13 -07:00
Moses Miller 1ecd5f8f21 Implement clock() and add CLOCK_* constants 2018-05-10 20:31:35 -07:00
Jeremy Soller 018f950851 Merge branch 'master' of https://github.com/jeizsm/relibc 2018-04-26 20:14:53 -06:00
Jeremy Soller 08091ab2a9 Merge branch 'stat' of https://github.com/sajattack/relibc 2018-04-26 20:12:57 -06:00
Marat Safin ff37adeeba add asctime
Signed-off-by: Marat Safin <jeizsm@gmail.com>
2018-04-19 07:59:58 +03:00
Jeremy Soller 43e6cad33f Merge pull request #112 from jeizsm/master
add gmtime and difftime
2018-04-17 10:07:12 -06:00
Marat Safin 8015878a73 use static variable for gmtime 2018-04-15 08:56:09 +03:00
Marat Safin 2b21dca567 add gmtime and difftime 2018-04-14 09:01:04 +03:00
Jeremy Soller 93e2e16077 Merge pull request #118 from dlrobertson/fix_ci
ci: Ensure that the correct compiler is installed
2018-04-08 12:16:01 -06:00
Dan Robertson 6a4220458c ci: Ensure that the correct compiler is installed
Ensure that a compiler is installed when the aarch64 CI build is run.
2018-04-08 13:52:34 +00:00
Jeremy Soller 722732b616 Merge pull request #114 from HermannDppes/format
Run ./fmt.sh
2018-04-04 16:07:37 -06:00
Hermann Döppes dc769fd977 Run ./fmt.sh 2018-04-04 22:52:06 +02:00
Jeremy Soller 3f627b1b40 Remove asserts 2018-04-03 19:52:50 -06:00
Jeremy Soller 5b1e11d1b1 Fix minimum alignment for malloc_inner 2018-04-03 19:52:34 -06:00
Jeremy Soller 62fbff93bc Clean up malloc 2018-04-03 19:51:50 -06:00
Jeremy Soller 742339ca9e Hacky version of memalign 2018-04-03 19:45:36 -06:00
Jeremy Soller dabd8dc6a2 Move memory handling into string, do not use compiler_builtins for memory handling 2018-03-27 21:28:48 -06:00
Jeremy Soller 79d05d7eda Build variadic functions as part of relibc 2018-03-27 21:13:11 -06:00
Jeremy Soller b849165438 Fix MAX_C macros 2018-03-27 20:33:04 -06:00
Jeremy Soller ea804582b9 Rename sys header crates, add mman constants 2018-03-27 20:25:42 -06:00
Jeremy Soller afdc80629f Fix Makefile spurious rebuilds
Add mem* functions to stdio
Add constant int functions
2018-03-27 20:14:22 -06:00
Paul Sajna 92493a55b9 fix harderer 2018-03-26 21:23:36 -07:00
Paul Sajna bc0763f3ef fmt 2018-03-26 21:17:14 -07:00
Paul Sajna 14957bb8dc fix harder 2018-03-26 21:14:38 -07:00
Jeremy Soller 6999363916 Create build directory if necessary in openlibm target 2018-03-26 20:41:02 -06:00
Jeremy Soller 78c8c2171b Add install target 2018-03-26 20:13:45 -06:00
Jeremy Soller 8c218b1608 Build crt0 as object file 2018-03-26 20:06:46 -06:00
Jeremy Soller d071522bc5 Add libm to phony 2018-03-26 19:59:42 -06:00
Jeremy Soller adcd0c9900 Only update libcrt0.a if there is a source change 2018-03-26 19:49:21 -06:00
Jeremy Soller e1abe80992 Fix CI 2018-03-26 19:34:45 -06:00
Jeremy Soller 6abd64ae16 Disable cargo cache 2018-03-26 19:13:49 -06:00
Jeremy Soller 47ee733afa Complete Makefile 2018-03-26 19:12:20 -06:00
Jeremy Soller ae137dbc03 Prepare for cross compiled openlibm 2018-03-26 18:50:51 -06:00
Jeremy Soller d9e4622f83 Add Makefile (WIP) 2018-03-26 18:38:29 -06:00
Jeremy Soller f0b41aa57e Merge pull request #104 from dlrobertson/rename
stdio: Implement rename
2018-03-26 18:22:22 -06:00
Jeremy Soller e39d2d61fa Merge branch 'master' into rename 2018-03-26 18:22:13 -06:00
Paul Sajna c7e9ec8ae2 fix 2018-03-26 16:47:12 -07:00
Paul Sajna c7ad4d3997 Merge branch 'stat' of github.com:sajattack/relibc into stat 2018-03-26 15:48:06 -07:00
Paul Sajna cafb76abdd mkfifo and constants 2018-03-26 15:47:36 -07:00
Paul 6d11736603 Merge branch 'master' into stat 2018-03-26 15:34:43 -07:00
Jeremy Soller bbf5c34ce8 Merge pull request #108 from mmstick/kill
Implement kill() and killpg()
2018-03-25 18:56:09 -06:00
Michael Aaron Murphy 43e95a9b92 Implement kill() and killpg() 2018-03-25 14:40:44 -04:00
Dan Robertson 57a17cb05f stdio: Implement rename 2018-03-25 14:41:42 +00:00
Paul Sajna 35dbc8d351 minor fixes 2018-03-23 13:37:56 -07:00
Paul Sajna 304473b68f Implement fstat, stat, lstat 2018-03-23 13:27:41 -07:00
Jeremy Soller 5f9170d861 Merge pull request #105 from jeizsm/master
add clock_gettime and time
2018-03-23 08:48:01 -06:00
Marat Safin 58b2b64183 add clock_gettime and time 2018-03-23 16:57:33 +03:00
Paul Sajna 29a6d24309 chmod and fchmod 2018-03-22 17:41:19 -07:00
Jeremy Soller 66fa211a05 Merge pull request #85 from Tommoa/master
Added functions for stdio.h
2018-03-22 10:07:57 -06:00
Tom Almeida 97e165d8c7 Merge branch 'master' into master 2018-03-22 12:49:55 +08:00
Tom Almeida e1b20ed368 Fixed getopt passing the wrong argument to stdio functions 2018-03-22 12:43:05 +08:00
Jeremy Soller e5849526a0 Update lock file 2018-03-21 21:16:21 -06:00
Jeremy Soller fcf1104ea5 Merge pull request #102 from sajattack/rand
implement rand and srand using the rand crate
2018-03-21 21:15:30 -06:00
Jeremy Soller 0ec7d0bc57 Merge branch 'master' into rand 2018-03-21 21:14:35 -06:00
Paul Sajna 5f243a21f7 Merge branch 'rand' of github.com:sajattack/relibc into rand 2018-03-21 20:13:27 -07:00
Jeremy Soller e34d32aefe Update gitignore 2018-03-21 21:12:58 -06:00
Paul Sajna cdc6209ff4 fix comment 2018-03-21 20:12:22 -07:00
Jeremy Soller 26b533c978 Merge branch 'master' into rand 2018-03-21 21:08:33 -06:00
Jeremy Soller ae097074ec Merge branch 'master' into master 2018-03-21 20:59:14 -06:00
Jeremy Soller 77b7a98d4e Merge pull request #97 from Arcterus/master
unistd: add a preliminary implementation of getopt()
2018-03-21 20:55:43 -06:00
Paul Sajna cc5a4e92ce fmt 2018-03-20 19:45:45 -07:00
Paul Sajna a24f537a38 test 2018-03-20 19:44:49 -07:00
Paul Sajna 4db812d34d implement rand and srand 2018-03-20 19:31:58 -07:00
Tom Almeida 19705ccc87 Merged master into master 2018-03-20 23:48:07 +08:00
Tom Almeida dbc3e413cc Fixed clearerr actually doing nothing 2018-03-20 23:43:42 +08:00
Alex Lyon 2751d457bf unistd: use .is_null() for pointers 2018-03-19 15:05:38 -07:00
Alex Lyon 42a6693a0b unistd: fix off-by-one in getopt() 2018-03-19 14:50:41 -07:00
Alex Lyon af78348d4a unistd: add a preliminary implementation of getopt() 2018-03-19 14:50:41 -07:00
Tom Almeida 90aec2076e Merge branch 'master' into master 2018-03-19 14:29:58 +08:00
Jeremy Soller edead8e085 Merge pull request #98 from jeizsm/master
refactor nanosleep
2018-03-18 16:40:30 -06:00
Jeremy Soller 045a510ce5 Merge pull request #92 from tdbgamer/feature/strtok
Implement strtok
2018-03-18 16:37:06 -06:00
Jeremy Soller ca61b4cb63 Merge pull request #100 from jrraymond/bsearch
implement bsearch
2018-03-18 16:36:24 -06:00
Justin Raymond d3583e11d2 fix c99 mode 2018-03-18 17:58:29 -04:00
Justin Raymond a0c76f7ce5 bsearch 2018-03-18 17:11:43 -04:00
Marat Safin 31516989c0 refactor nanosleep 2018-03-18 12:29:38 +03:00
Timothy Bess 3a89f66cfd * simplify strtok implementation 2018-03-18 00:05:13 -04:00
Jeremy Soller 5cec358a45 Merge pull request #86 from dlrobertson/add_headers
Add some of the basics for netinet/in.h and sys/socket.h
2018-03-17 18:11:46 -06:00
Jeremy Soller befca562df Merge pull request #95 from ids1024/travis
Use build matrix on Travis CI
2018-03-17 18:11:16 -06:00
Ian Douglas Scott b7d68895b0 Use build matrix on Travis CI
This makes it easy to see which target failed to build.
2018-03-17 16:00:54 -07:00
Timothy Bess 06de920be6 * remove unnecessary assignments 2018-03-17 12:58:10 -04:00
Tom Almeida d8139238e7 Merged master with branch 2018-03-18 00:22:08 +08:00
Tom Almeida c24d1e2b36 Removed all function pointers in FILE, moved internal functions to be member functions of FILE, made relevant *mut FILEs into &mut FILE and made suitable functions safe again 2018-03-18 00:20:21 +08:00
Tom Almeida d7965f2598 Made it so that AtomicBool exports as volatile char 2018-03-18 00:19:08 +08:00
Tom Almeida 25501b3640 Changed redox lseek to have the same function signature as the linux version 2018-03-18 00:18:14 +08:00
Tom Almeida b33c3a8e4f Merge branch 'master' into master 2018-03-18 00:06:59 +08:00
Jeremy Soller 362849f0f6 Merge pull request #91 from tdbgamer/master
Issue #89: Fix return types on string functions
2018-03-17 07:04:52 -06:00
Timothy Bess e91891625f * add strtok_r 2018-03-17 03:56:40 -04:00
Timothy Bess 898cf98ccc * fix test case a bit
* remove unnecessary cast
2018-03-17 03:06:59 -04:00
Timothy Bess f60fafe8fb * create basic strtok
* add test and expected output
2018-03-17 02:58:08 -04:00
Timothy Bess bebbd35e1a Issue #89
* fix return types
* fix type casts on returns
2018-03-17 00:50:22 -04:00
Tom Almeida 2cb0a994b8 Merge branch 'master' into master 2018-03-16 23:26:11 +08:00
Tom Almeida 659d3d1042 Changed object type of function pointers from Option<*const (Fn(...))> to Option<fn(...)> for readability 2018-03-16 23:14:43 +08:00
Jeremy Soller d75535974a Merge pull request #74 from sajattack/wait
wait and waitpid
2018-03-16 09:03:35 -06:00
Tom Almeida 81d96c214a Ran formatting for freopen() 2018-03-16 20:47:32 +08:00
Tom Almeida 8d40424020 Added freopen() and relevant tests 2018-03-16 20:24:40 +08:00
Paul Sajna 2610fdd126 Merge branch 'wait' of github.com:sajattack/relibc into wait 2018-03-15 16:22:23 -07:00
Paul Sajna c568ca2932 test cleanup 2018-03-15 16:18:35 -07:00
Jeremy Soller b2b7804f5b Merge branch 'master' into wait 2018-03-15 15:51:29 -06:00
Paul Sajna cdfde8c0d4 more requested changes 2018-03-15 11:55:37 -07:00
Dan Robertson 16e82636fb Add basic structures for netinet/in.h crate
Add the basic structures for the netinet/in.h header.
2018-03-15 17:34:30 +00:00
Dan Robertson 01081729c8 Add structures and stub fns for sys/socket.h
Add some of the basic structures and stub functions for sys/socket.h
2018-03-15 17:34:30 +00:00
Tom Almeida 41b96fede3 Added a different internal function for redox 2018-03-15 15:57:19 +08:00
Tom Almeida c4c8b73903 Formatted stdio files 2018-03-15 15:34:39 +08:00
Tom Almeida 8648fd39c4 Added some constants in linux for file modes in the new branch 2018-03-15 15:32:46 +08:00
Tom Almeida b0492eba84 Added some tests for stdio 2018-03-15 15:28:14 +08:00
Tom Almeida 7f2b720962 Implemented stdio functions 2018-03-15 15:27:07 +08:00
Tom Almeida 046ce1468e Removed an unused import from printf 2018-03-15 15:23:38 +08:00
Tom Almeida e73678d8ad Added a FileReader struct 2018-03-15 15:22:18 +08:00
Tom Almeida f20878c592 Added lseek to syscalls 2018-03-15 15:21:52 +08:00
Tom Almeida aa8b14e107 Added some constants in linux for file modes 2018-03-15 15:21:02 +08:00
Jeremy Soller a1baf1c92d Merge pull request #75 from azymohliad/master
Implement strstr() and strpbrk() from string.h
2018-03-14 21:22:59 -06:00
Jeremy Soller b419e150d1 Merge pull request #84 from dlrobertson/fixup_signal
Update cbindgen and fix issues with signal
2018-03-14 20:23:08 -06:00
Dan Robertson f1d802dc1e signal: sigaction struct should not be a typedef
The sigaction struct should not be a typedef, but the sigset_t struct
should be a typedef.
2018-03-15 01:07:44 +00:00
Dan Robertson 6d110ef0cb Use a sys module for OS specific information
Update cbindgen to parse modules with a path attribute and revert the
following commits:
 - 996fad7092.
 - cfe98ab3b2.
2018-03-15 00:53:35 +00:00
Paul Sajna 52acce0d34 handle the null case 2018-03-14 12:37:24 -07:00
Jeremy Soller 54c0e501e3 Merge pull request #82 from Tommoa/master
Actual working tests on strspn and strcspn
2018-03-13 21:02:04 -06:00
Tom Almeida b2d01a67f2 Actual working tests on strspn and strcspn 2018-03-14 10:55:01 +08:00
Jeremy Soller cfe98ab3b2 Fix constants in signal.h 2018-03-13 19:58:52 -06:00
Andrii Zymohliad cd2312fd56 Merge remote-tracking branch 'upstream/master' 2018-03-14 09:55:59 +08:00
Jeremy Soller d6e210b1fd Merge branch 'signal' of https://github.com/dlrobertson/relibc into dlrobertson-signal 2018-03-13 19:54:49 -06:00
Jeremy Soller 996fad7092 Fix fcntl header constants 2018-03-13 19:52:15 -06:00
Jeremy Soller 1d6115fd09 Update cbindgen and lock file 2018-03-13 19:41:31 -06:00
Jeremy Soller b09435f17d Merge pull request #78 from Tommoa/master
Yet another fix for strcspn and strspn.
2018-03-13 19:39:08 -06:00
Tom Almeida d3c2e99ed7 Merge branch 'master' into master 2018-03-14 08:56:52 +08:00
Tom Almeida d058390b75 The erroneous use came back! 2018-03-14 08:56:18 +08:00
Tom Almeida 122f6cfef5 Merge branch 'master' of github.com:Tommoa/relibc 2018-03-14 08:54:10 +08:00
Tom Almeida 9d46fa4d8c Missed having both loops look at themselves. I'm not sure how long this has been here. 2018-03-14 08:48:56 +08:00
Jeremy Soller 010e171071 Merge pull request #80 from dlrobertson/master
Add the no_mangle attribute to fns
2018-03-13 18:28:09 -06:00
Andrii Zymohliad 40efea056b Reimplement strpbrk() using strcspn() 2018-03-14 08:06:51 +08:00
Paul Sajna 2fd2a9c520 Merge branch 'wait' of github.com:sajattack/relibc into wait 2018-03-13 16:55:32 -07:00
Paul Sajna d177b8e974 requested change 2018-03-13 16:55:16 -07:00
Dan Robertson d3e44da527 Add the no_mangle attribute to fns
Add the no_mangle attribute to functions without it.
2018-03-13 23:27:32 +00:00
Tom Almeida ca82b6df5b remove erroneous import in string 2018-03-14 01:03:48 +08:00
Tom Almeida d6a7942ec4 Change the type of byteset from [u8] to [usize] in strcspn and strspn. Hopefully this is the last bug in these! 2018-03-14 01:01:23 +08:00
Jeremy Soller 1e661cdbef Merge branch 'master' into wait 2018-03-13 07:11:35 -06:00
Jeremy Soller 8d0308d3ce Merge branch 'master' into master 2018-03-12 21:59:06 -06:00
Jeremy Soller 13b7119994 Merge pull request #77 from dlrobertson/add_extern_crate
Add missing extern crate statements
2018-03-12 21:56:12 -06:00
Jeremy Soller dd847cc67e Return with 0 in all tests 2018-03-12 21:55:46 -06:00
Dan Robertson ef8a64c101 Add missing extern crate statements
Add missing extern crate statements.
2018-03-13 02:17:32 +00:00
Andrii Zymohliad c4620be999 Prettify strpbrk and strstr tests 2018-03-12 18:22:39 +08:00
Andrii Zymohliad 1e969afd43 Implement strpbrk(), add strpbrk test 2018-03-12 18:01:12 +08:00
Andrii Zymohliad a1de0ef8a1 Implement strstr(), add strstr test 2018-03-12 14:55:02 +08:00
Paul Sajna 211f95155a fmt 2018-03-11 21:24:06 -07:00
Paul Sajna b35abd1065 test and fixes 2018-03-11 21:20:59 -07:00
Paul Sajna 224cf04cf3 Merge branch 'master' of github.com:redox-os/relibc into wait 2018-03-11 20:28:39 -07:00
Jeremy Soller 7912332137 Mark sys_time functions no_mangle 2018-03-11 21:26:21 -06:00
Jeremy Soller 3e354aed04 Merge branch 'fix_includes' of https://github.com/dlrobertson/relibc into dlrobertson-fix_includes 2018-03-11 21:22:07 -06:00
Jeremy Soller 232e364f60 Remove warnings, build openlibm without stack protector 2018-03-11 21:20:56 -06:00
Jeremy Soller 477e8eb4e0 Exit run, expected, or verify on error in loop 2018-03-11 21:11:08 -06:00
Jeremy Soller 41e552b696 Only expect output for a whitelist of binaries 2018-03-11 21:04:53 -06:00
Jeremy Soller 7c13ec153e Update expects 2018-03-11 21:00:53 -06:00
Jeremy Soller ee13ed44d3 Merge pull request #69 from sajattack/stat
stat is now autogenerated correctly
2018-03-11 20:38:20 -06:00
Dan Robertson cc5669939e Fix include in resource.h and add SIZE_MAX
The rusage struct makes use of the timeval structure. Make sure to
include sys/time.h so that the type is known.

Add SIZE_MAX to stdint.h

sys/resource expects the defined structures to not be defined with a
typedef.
2018-03-12 02:38:07 +00:00
Jeremy Soller 7c305c5c0d Merge branch 'master' into stat 2018-03-11 19:31:59 -06:00
Paul Sajna c5dd3f8706 Update Cargo.lock 2018-03-11 17:01:25 -07:00
Paul Sajna ccb29cfa2c wait and waitpid 2018-03-11 16:50:46 -07:00
Dan Robertson 50eab4369d Add signal.h
Create stubs for signal.h
2018-03-11 21:36:02 +00:00
Jeremy Soller 1b1ff5c750 Merge pull request #66 from w0xel/master
Add implementation for a64l
2018-03-11 13:11:06 -06:00
Paul Sajna ca57f30425 Update cbindgen 2018-03-11 12:06:46 -07:00
Paul Sajna a000f1a2c0 fmt 2018-03-11 11:26:35 -07:00
Paul Sajna bc98f6a029 git rm include/sys/stat.h 2018-03-11 11:22:10 -07:00
Paul Sajna 76c4520cea stat is now autogenerated correctly 2018-03-11 11:19:56 -07:00
Jeremy Soller 4f5e978634 Merge pull request #68 from Tommoa/master
Fixed strcspn and strspn
2018-03-11 11:09:55 -06:00
Tom Almeida 1f9f9f7d55 Made an error in the logic of strcspn and strspn that would cause a bit shift much too large 2018-03-11 23:53:15 +08:00
Sebastian Würl 55bd1adae0 stdlib: cleaner raw pointer handling in a64l 2018-03-11 13:23:36 +01:00
Sebastian Würl d4d808fcc8 Add implementation for a64l 2018-03-11 11:55:22 +01:00
Jeremy Soller 8028c35172 Merge pull request #65 from dlrobertson/add_more_crates
Add more crates for missing headers
2018-03-10 21:52:30 -07:00
Jeremy Soller 089b41da23 Merge pull request #62 from jrraymond/strrchr
implement strrchr
2018-03-10 21:51:21 -07:00
Jeremy Soller c2a76870b5 Merge pull request #63 from Tommoa/master
Implemented fputc, fputs, and puts
2018-03-10 21:50:09 -07:00
Dan Robertson 3699b53ba2 float: Add crate for float.h
Add a crate with stubbed functions for the float.h header.
2018-03-10 21:16:55 +00:00
Dan Robertson f29e6b00d7 fenv: Add crate for fenv.h
Add a crate for building out stub functions and structures for the fenv
header.
2018-03-10 21:16:54 +00:00
Dan Robertson ca7f3a00e6 wait: Add crate for sys/wait.h
Add the basics of sys/wait.h so that we get a bit closer to being able
to compile libc-test.
2018-03-10 21:16:54 +00:00
Dan Robertson c6f16547ff resource: Add crate for sys/resource.h
Add the basics of sys/resource.h so that work can begin on sys/wait.h
2018-03-10 19:14:20 +00:00
Dan Robertson 2f718d40d6 mman: mman.h should be located at sys/mman.h
- Update target location of mman.h to sys/mman.h
 - Add more types to sys/type.h
2018-03-10 19:14:16 +00:00
Justin Raymond 63ee4de162 Update lib.rs 2018-03-10 12:39:30 -05:00
Justin Raymond 23a409204f Update .gitignore 2018-03-10 12:36:42 -05:00
Tom Almeida 49be92f87f ran fmt.sh cause I'm an idiot 2018-03-11 00:39:43 +08:00
Tom Almeida 8374fcb4be implemented fputc, fputs, and puts 2018-03-11 00:33:00 +08:00
Justin Raymond a1e62baad7 Merge branch 'master' into strrchr 2018-03-10 11:11:46 -05:00
Justin Raymond 826cf0c61c implement strrchr 2018-03-10 11:10:19 -05:00
Jeremy Soller ffeefb2a8e Merge pull request #61 from Tommoa/master
Add implementations of strspn, strcspn and strchr
2018-03-10 09:03:32 -07:00
Tom Almeida d0bf830ca7 fixed a logic error in strchr 2018-03-10 23:09:10 +08:00
Tom Almeida b0f8e31b63 ran fmt.sh 2018-03-10 23:01:49 +08:00
Tom Almeida 87ec6dfacb Fixed unused variable in memchr 2018-03-10 22:59:24 +08:00
Tom Almeida 18283feac1 Added implementations of strchr, strcspn and strspn 2018-03-10 22:58:35 +08:00
Jeremy Soller b52a1d612d Merge pull request #59 from Tommoa/master
Add implementations of memchr and memccpy
2018-03-10 07:03:40 -07:00
Jeremy Soller a227338a72 Merge pull request #58 from dlrobertson/sprintf
Add implementations of sprintf and snprintf
2018-03-10 07:00:22 -07:00
Tom Almeida a2a7efa946 Update .gitignore 2018-03-10 21:52:37 +08:00
Tom Almeida d214817c87 readability update in lib.rs 2018-03-10 21:52:06 +08:00
Jeremy Soller 0ee34fe836 Merge branch 'master' into sprintf 2018-03-10 06:46:17 -07:00
Jeremy Soller 639ea0919f Merge pull request #56 from Arcterus/master
string: address performance concerns for strncmp()
2018-03-10 06:43:22 -07:00
Tom Almeida 774856f9b2 Update lib.rs 2018-03-10 21:37:01 +08:00
Tom Almeida 3470882df6 Fixed incorrect return of memccpy 2018-03-10 17:12:05 +08:00
Tom Almeida b013f5f0ed Fixed mem test 2018-03-10 17:05:56 +08:00
Tom Almeida 4f601f4896 Added memchr and memccpy to string 2018-03-10 16:59:53 +08:00
Alex Lyon cfc1014c6e string: fix a couple minor issues in strncmp() 2018-03-09 20:54:42 -08:00
Alex Lyon 50f79e9a0e string: address performance concerns for strncmp() 2018-03-09 20:54:42 -08:00
Dan Robertson 75920d2c12 Add implementations of sprintf and snprintf
Add implementations of sprintf and snprintf so that we can get a bit
closer to compiling libc-test.
2018-03-10 02:33:03 +00:00
Jeremy Soller 3890ec58f0 Merge pull request #49 from sajattack/time
Add time and sys/time
2018-03-09 18:11:51 -07:00
Jeremy Soller 4d67145aa1 Merge pull request #54 from MggMuggins/master
Update README.md
2018-03-09 13:52:46 -07:00
MggMuggins 06a6922cde Merge branch 'master' of https://github.com/redox-os/relibc 2018-03-09 12:41:25 -06:00
MggMuggins d7aa9c44f9 Add Documentation 2018-03-09 12:38:37 -06:00
Paul 7108d0164e Merge branch 'master' into time 2018-03-09 08:37:40 -08:00
Paul Sajna 7e40d8c87b fmt 2018-03-09 07:51:15 -08:00
Paul Sajna 23bb883797 update nanosleep 2018-03-09 07:49:37 -08:00
Jeremy Soller 11043129f2 Merge pull request #52 from dlrobertson/aarch64
Aarch64: Merge the final components
2018-03-09 08:24:37 -07:00
Dan Robertson c2ae141df3 Aarch64: Merge the final components
Merge the final components for Aarch64 support into master.
2018-03-09 14:20:42 +00:00
Paul 031fc5da27 Update Makefile 2018-03-09 05:58:55 -08:00
Paul 5632d96016 Merge branch 'master' into time 2018-03-09 05:52:29 -08:00
Jeremy Soller 77c0a5b430 Merge pull request #47 from sajattack/unistd
implement setid functions and unlink
2018-03-09 06:50:04 -07:00
Paul 4d12c408fd Merge branch 'master' into time 2018-03-09 05:49:37 -08:00
Paul cdf298ba3a Merge branch 'master' into unistd 2018-03-09 05:48:22 -08:00
Jeremy Soller dd0e6187db Merge pull request #50 from Arcterus/master
Preliminary implementation of strtol()
2018-03-09 06:45:39 -07:00
Jeremy Soller b7ac90fd9f Merge branch 'master' into master 2018-03-09 06:45:17 -07:00
Jeremy Soller 580dcd3c08 Merge pull request #48 from sajattack/stat
correction to include guard of stat
2018-03-09 06:43:12 -07:00
Paul Sajna b11c079d69 Makefile fix 2018-03-09 05:34:58 -08:00
Paul Sajna 3c198a3a40 fmt 2018-03-09 05:19:25 -08:00
Paul Sajna 4d4ab1a75f fix and test 2018-03-09 05:18:21 -08:00
Paul Sajna 161d93466c fixes and tests 2018-03-09 04:48:34 -08:00
Paul Sajna e99857d125 sleep and usleep 2018-03-09 03:42:42 -08:00
Alex Lyon dec7ecd06b tests: fix Makefile 2018-03-09 03:37:30 -08:00
Paul Sajna 7e19ce23bd nanosleep 2018-03-09 03:26:45 -08:00
Alex Lyon 9325a29a74 stdlib: make rustfmt happy with strtol() 2018-03-09 03:21:18 -08:00
Alex Lyon f5b1f872a0 stdlib: implement preliminary version of strtol() 2018-03-09 03:07:16 -08:00
Alex Lyon a7e71717cb stdio: add support for %o to printf() 2018-03-09 02:51:50 -08:00
Paul Sajna 083aa0ed55 fmt 2018-03-09 02:47:22 -08:00
Paul Sajna 72909b3f4c add time and sys/time 2018-03-09 02:46:14 -08:00
Paul Sajna 1c1a48b648 fix formatting 2018-03-09 00:56:02 -08:00
Paul Sajna b9a2dfded4 correction to include guard of stat 2018-03-09 00:52:34 -08:00
Paul Sajna a7fba79be7 implement setid functions and unlink 2018-03-09 00:28:46 -08:00
Jeremy Soller e676440e1f Merge pull request #46 from dlrobertson/aarch64
Aarch64: Update syscall usage
2018-03-08 21:26:04 -07:00
Jeremy Soller 89259475ab Merge branch 'master' into aarch64 2018-03-08 21:25:28 -07:00
Jeremy Soller 54655a4e3b Add verification makefile rule 2018-03-08 21:22:17 -07:00
Dan Robertson f83ff041cc Aarch64: Update syscall usage
Don't use syscalls that are non-existent on Aarch64 linux boxes. The
FORK and RMDIR syscalls are no longer present and the CLONE and UNLINKAT
syscalls are used instead.
2018-03-09 04:19:22 +00:00
Jeremy Soller 85766a41ff Expected output 2018-03-08 21:14:46 -07:00
Jeremy Soller 4da873ae79 Merge pull request #43 from MggMuggins/master
Imp va_arg for fcntl; fcntl test
2018-03-08 21:07:39 -07:00
Jeremy Soller 76e53e86fa Merge pull request #45 from redox-os/atof
Implement atof
2018-03-08 21:00:38 -07:00
Jeremy Soller a95a034219 Fix issues by adding support for floating point values in va_list 2018-03-08 20:54:46 -07:00
Jeremy Soller 56e304a2af Fix format 2018-03-08 20:20:21 -07:00
Jeremy Soller 0e766c6b53 Implement atof 2018-03-08 20:17:45 -07:00
Jeremy Soller 96358469a4 Merge branch 'master' into master 2018-03-08 20:17:08 -07:00
MggMuggins c291632492 Imp va_arg for fcntl; fcntl test 2018-03-08 20:56:50 -06:00
Paul Sajna 799c8828c2 mkdir and rmdir 2018-03-08 19:45:16 -07:00
Jeremy Soller 231d7a023a Merge pull request #42 from dlrobertson/use_va_list
fcntl: open should use a va_list
2018-03-08 19:32:34 -07:00
Jeremy Soller 7b3fc9191a Merge pull request #40 from MggMuggins/master
Implement fcntl
2018-03-08 19:24:54 -07:00
Dan Robertson e306e3f855 fcntl: open should use a va_list
The current implementation of open requires the user to pass all three
args to the function. It should use a va_list and allow a user to
provide only the filename and flags.
2018-03-09 02:24:25 +00:00
MggMuggins 0cb3a893a1 Fix compile on redox 2018-03-08 20:19:55 -06:00
Jeremy Soller fb173dc787 Move travis instructions into ci.sh 2018-03-08 19:14:10 -07:00
MggMuggins 14c8125108 Implement fcntl
No tests written yet! See #36
2018-03-08 19:55:35 -06:00
Jeremy Soller 620a459d93 Merge pull request #39 from Arcterus/master
string: fix out of bounds bug in strncmp
2018-03-08 18:34:27 -07:00
Alex Lyon 332ae13af5 string: fix out of bounds bug in strncmp 2018-03-08 17:18:38 -08:00
Jeremy Soller dbe73d4bab Merge pull request #35 from sajattack/patch-1
Add build badge to README
2018-03-08 17:47:28 -07:00
Jeremy Soller d0c9c46ff9 Merge pull request #38 from MggMuggins/master
ctype: tests and reorganize
2018-03-08 17:47:01 -07:00
SamwiseFilmore 46fe488e05 Merge branch 'master' into master 2018-03-08 18:31:14 -06:00
MggMuggins 6ced871d9a ctype: tests and reorganize
Wrote tests for the functions implemented in 40558b2 and maybe made that
test a little more comprehensible.

Also made sure that fmt.sh and test.sh were being executed by bash all
the time (compatibility with other shells).
2018-03-08 18:25:11 -06:00
Paul bb376ff3fb Add build badge to README 2018-03-08 15:27:44 -08:00
Jeremy Soller 284cc4eece Fix formatting 2018-03-08 16:21:04 -07:00
Jeremy Soller cd4082bf9f Fix build harder 2018-03-08 16:09:28 -07:00
Jeremy Soller 07c3ce02be Fix build 2018-03-08 15:52:48 -07:00
Jeremy Soller af78f4819a Merge branch 'master' of github.com:redox-os/relibc 2018-03-08 15:43:23 -07:00
Jeremy Soller 4198055d4a Fix tests 2018-03-08 15:43:17 -07:00
Jeremy Soller 8adf1c3de0 Merge pull request #34 from MggMuggins/master
Finish ctype impls
2018-03-08 15:39:05 -07:00
MggMuggins 42de0a0a46 Merge branch 'master' of https://github.com/redox-os/relibc 2018-03-08 16:29:58 -06:00
MggMuggins 40558b2608 Finish ctype impls; Solve #31 2018-03-08 16:16:51 -06:00
Jeremy Soller cfbe27490f Remove allocation, fix pipe example 2018-03-08 15:00:17 -07:00
Jeremy Soller 0bcabc2163 Merge remote-tracking branch 'sajattack/unistd' 2018-03-08 14:53:07 -07:00
Jeremy Soller 18961114e2 Simplify perror 2018-03-08 14:51:22 -07:00
Jeremy Soller c6a31f709b Merge remote-tracking branch 'sajattack/master' 2018-03-08 14:47:03 -07:00
Jeremy Soller e1a8b288fb Update README.md 2018-03-08 14:32:06 -07:00
Jeremy Soller 38ed9ccb22 Update README.md 2018-03-08 14:31:55 -07:00
Paul Sajna 12833a5a5c add test and fork 2018-03-08 12:25:14 -08:00
Paul Sajna 22fb6c5bf0 copy strerror implementation into perror 2018-03-08 11:20:13 -08:00
Paul Sajna 6304595a1d Merge branch 'master' of github.com:redox-os/relibc 2018-03-08 11:07:51 -08:00
Jeremy Soller 8812c2148f Merge pull request #33 from dlrobertson/stub_wctype
Create crate and stubs for wctype
2018-03-08 10:07:14 -07:00
Dan Robertson a6a16cf233 Create crate and stubs for wctype
Create the wctype crate and stub functions with the unimplemented macro.
2018-03-08 16:03:45 +00:00
Jeremy Soller 013dff2aaf Merge pull request #29 from dlrobertson/add_functions
Add ctype functions and atoi/atol
2018-03-08 07:34:14 -07:00
Paul Sajna 33f1033e0e implement pipe and read 2018-03-07 23:30:10 -08:00
Dan Robertson ec288a1b53 Add ctype functions and atoi/atol
Add ctype functions
  - isalnum
  - isalpha
  - isascii
  - isdigit
  - islower
  - isspace
  - isupper
Add stdlib functions
  - atoi
  - atol
Fix some warnings
Make a fmt run
2018-03-08 05:26:40 +00:00
Paul Sajna 838c364ed5 Merge branch 'unistd' 2018-03-07 20:58:48 -08:00
Paul Sajna 3b7149612f implement perror 2018-03-07 20:57:51 -08:00
Jeremy Soller 1127c36ceb Add strerror to error test 2018-03-07 21:01:48 -07:00
Jeremy Soller b7b49d5801 Implement strerror 2018-03-07 21:00:26 -07:00
Paul Sajna f6db153ea5 Merge branch 'master' of github.com:redox-os/relibc 2018-03-07 19:46:41 -08:00
Jeremy Soller f01c669771 Remove thread local from errno, for now 2018-03-07 20:37:22 -07:00
Jeremy Soller 85b80d0fe5 Fix errno.h, add -no-pie to tests Makefile 2018-03-07 20:31:18 -07:00
Paul Sajna 95424b3c69 Merge branch 'master' of github.com:redox-os/relibc 2018-03-07 18:47:21 -08:00
Jeremy Soller 851e4d399f Fix errno.h definition 2018-03-07 19:46:23 -07:00
Paul Sajna ffd9176cdf forgot to commit the makefile 2018-03-07 18:45:03 -08:00
Jeremy Soller 633b5474db Merge pull request #27 from sajattack/master
add test for errno
2018-03-07 19:40:46 -07:00
Jeremy Soller 7e725a803e Merge pull request #26 from Arcterus/master
Implement several more string functions and add errno
2018-03-07 19:40:09 -07:00
Paul Sajna 93ddcca294 add test for errno 2018-03-07 18:36:18 -08:00
Alex Lyon 629c20f097 string: ensure resulting string has NUL byte 2018-03-07 17:52:37 -08:00
Alex Lyon 3e1b945e99 Add errno crate and set errno in strndup 2018-03-07 17:38:43 -08:00
Jeremy Soller 89a9e01676 Create README.md 2018-03-07 17:29:54 -07:00
Jeremy Soller ba515d83df Create LICENSE 2018-03-07 17:29:33 -07:00
Alex Lyon ee824f3b19 string: implement strndup and strnlen 2018-03-07 15:59:58 -08:00
Alex Lyon 9f39456dbd string: implement strcat, strcmp, strcpy, and strdup 2018-03-07 14:06:30 -08:00
Jeremy Soller 3224fa24c8 Merge pull request #23 from Arcterus/master
string: implement strncat, strncmp, and strncpy
2018-03-07 06:15:21 -07:00
Alex Lyon 114ee16c21 string: implement strncat, strncmp, and strncpy 2018-03-07 05:04:40 -08:00
Jeremy Soller 1198ad3ae7 Format vsnprintf 2018-03-06 22:02:30 -07:00
Jeremy Soller ff0cebca87 Implement more stdio functions 2018-03-06 21:47:39 -07:00
Jeremy Soller bf41415c8b Use Rust nightly, disable email notifications 2018-03-06 21:25:10 -07:00
Jeremy Soller b14ee3ed39 Fix build, add Wall 2018-03-06 21:23:36 -07:00
Jeremy Soller 853fdaad75 Merge branch 'master' of github.com:redox-os/relibc 2018-03-06 21:16:14 -07:00
Jeremy Soller a1ce114cd4 Convert errors and set errno 2018-03-06 21:15:38 -07:00
Jeremy Soller 6afdf3fabf Merge pull request #21 from sajattack/patch-1
Test if the redox version compiles too
2018-03-06 21:08:09 -07:00
Paul 8f513f809b Test if it compiles for redox too 2018-03-06 20:06:47 -08:00
Jeremy Soller cf03233e66 Fix linux build 2018-03-06 20:44:21 -07:00
Jeremy Soller b768e44678 Merge pull request #19 from sajattack/redox-fixes
redox fixes
2018-03-06 20:42:35 -07:00
Jeremy Soller 1dd2f61d76 Merge pull request #20 from dlrobertson/add_ci
Add test.sh and fmt.sh to travis.yml
2018-03-06 20:40:13 -07:00
Paul Sajna 05d316b3a5 redox fixes 2018-03-06 19:28:02 -08:00
Dan Robertson 628c68abe3 Add test.sh and fmt.sh to travis.yml
Do not accept unformatted code.
2018-03-07 03:15:24 +00:00
Jeremy Soller 98b2fba518 Merge pull request #18 from dlrobertson/aarch64
Finalize Aarch64 support
2018-03-06 20:03:47 -07:00
Dan Robertson 40b6a9c5cc Finalize Aarch64 support
Update platform support for linux to avoid the use of syscalls not
supported by Aarch64.
  - link, chown, and open should use fchownat and linkat with fd
    set to AT_FDCWD.
  - use dup3 with the 3rd arg set to 0 instead of dup2.
2018-03-07 02:56:08 +00:00
Jeremy Soller 543526cb85 Move crt0 and platform into src folder
Add cargo fmt script
2018-03-06 19:55:11 -07:00
Jeremy Soller 6bca112340 Merge pull request #16 from dlrobertson/fixes_and_nits
Fix platform
2018-03-06 19:30:13 -07:00
Dan Robertson 846e495944 Get rustfmt passing on core relibc code
- Add a rustfmt config
 - Get the current code passing the formatter
2018-03-07 01:52:50 +00:00
Dan Robertson 2096b85115 Fix platform
- Add cfg to extern crate sc. It is not used by redox.
 - Fix bad syntax in brk implementation for redox
 - nits
   - style: update brk implementation for linux
   - style: no space between not operator and ptr.is_null
   - style: should be a space around = in module path
2018-03-07 01:52:50 +00:00
Jeremy Soller a808dfe39c Merge pull request #14 from sajattack/unistd
implement some unistd
2018-03-05 19:31:08 -07:00
Paul Sajna 44e6c334e6 unwrap_or(-1) 2018-03-05 14:57:04 -08:00
Paul Sajna 151d873aba link 2018-03-04 22:34:47 -08:00
Paul Sajna 3a07bc27c2 getid functions 2018-03-04 22:11:59 -08:00
Jeremy Soller d4308b4c5d Update rust toolchain and lock file 2018-03-04 18:01:28 -07:00
Paul Sajna 2636b6f5b1 ftruncate test 2018-03-04 16:41:53 -08:00
Paul Sajna 5cc52e4b19 tests 2018-03-04 16:34:46 -08:00
Paul Sajna fc92d95b35 this [u8] to c_char* is probably wrong 2018-03-04 09:42:57 -08:00
Paul Sajna 95ed0b59bd getcwd 2018-03-04 09:35:38 -08:00
Paul Sajna b5192437c3 ftruncate 2018-03-04 09:24:33 -08:00
Paul Sajna 3ad7c62601 fsync and some tweaks 2018-03-04 09:16:56 -08:00
Paul Sajna 9de89e037a fchdir 2018-03-04 09:03:46 -08:00
Paul Sajna 95e74373fe fchown 2018-03-04 08:49:40 -08:00
Paul Sajna 8b1222c3fb brk 2018-03-04 08:41:37 -08:00
Paul Sajna c96040187f chown 2018-03-04 08:32:47 -08:00
Paul Sajna aa4f7ed3a5 Merge branch 'platform' into unistd 2018-03-04 08:21:52 -08:00
Paul Sajna 6b89b4620b Merge branch 'master' of github.com:redox-os/relibc into platform 2018-03-04 08:09:48 -08:00
Paul Sajna 4b1a1568bf add rawfile.rs 2018-03-04 08:09:13 -08:00
Jeremy Soller 8283f130d6 Merge pull request #10 from sajattack/semaphore
build semaphore header
2018-03-04 09:06:30 -07:00
Paul Sajna 0157f7fcea Merge branch 'semaphore' into platform 2018-03-04 08:03:01 -08:00
Paul Sajna 608a6fcfad merge 2018-03-04 08:02:41 -08:00
Paul Sajna e08ffa6474 merge 2018-03-04 07:57:39 -08:00
Paul Sajna 25b9ac206b remove timedwait 2018-03-04 07:50:49 -08:00
Paul ae4b64c491 missing curlyboi 2018-03-04 07:41:07 -08:00
Paul 4d506e6981 Merge branch 'master' into unistd 2018-03-04 07:39:51 -08:00
Paul Sajna 7a38acada9 Merge branch 'semaphore' of github.com:sajattack/relibc into semaphore 2018-03-04 07:34:47 -08:00
Paul Sajna 0a245a386e comment out sem_open 2018-03-04 07:34:27 -08:00
Paul Sajna caa89878d6 merge 2018-03-04 07:33:38 -08:00
Jeremy Soller 5002dd720f Add mman to lib.rs 2018-03-04 08:31:43 -07:00
Jeremy Soller 07c897e558 Clean up gcc line 2018-03-04 08:29:19 -07:00
Jeremy Soller 18c6701841 Disable stack protector 2018-03-04 08:27:20 -07:00
Jeremy Soller 654ca47351 Fix atexit_funcs call in exit 2018-03-04 08:15:26 -07:00
Jeremy Soller 7a7b3efe3a Merge branch 'master' of github.com:redox-os/relibc 2018-03-04 08:12:38 -07:00
Jeremy Soller 866d952924 Support building for Redox 2018-03-04 08:10:42 -07:00
Paul Sajna d9d7440a7f implement some unistd 2018-03-04 06:53:30 -08:00
Paul Sajna 8860109efc add stuff from old newlib to todo 2018-03-04 06:53:30 -08:00
Paul Sajna 432c3ad397 add mman to main Cargo.toml 2018-03-04 06:53:30 -08:00
Paul Sajna de29e16024 remove mman from todo 2018-03-04 06:53:30 -08:00
Paul Sajna 16cf6e0267 build mman header 2018-03-04 06:53:30 -08:00
Paul 0e423aae4d Merge branch 'master' into semaphore 2018-03-04 06:46:27 -08:00
Paul Sajna 21abb75ccc Merge branch 'semaphore' of github.com:sajattack/relibc into semaphore 2018-03-04 06:45:13 -08:00
Paul Sajna 7fcad36826 add semaphore to main Cargo.toml 2018-03-04 06:43:41 -08:00
Paul Sajna 2e1d29203d build semaphore header 2018-03-04 06:43:41 -08:00
Paul Sajna d25b1d2fa4 implement some unistd 2018-03-04 06:37:45 -08:00
Jeremy Soller 9f5db313ce Merge pull request #13 from sajattack/oldlib
add stuff from old newlib to todo
2018-03-04 07:36:00 -07:00
Jeremy Soller 50af0031c3 Merge pull request #9 from sajattack/mman
build mman header
2018-03-04 07:35:28 -07:00
Jeremy Soller 4f5d65e7a6 Merge pull request #12 from sajattack/atexit
fix atexit
2018-03-04 06:17:25 -07:00
Paul Sajna 460d7fb2c3 add stuff from old newlib to todo 2018-03-04 05:08:32 -08:00
Paul Sajna ef9545cf71 missing parens 2018-03-04 04:43:05 -08:00
Paul Sajna cdf5cb2d56 fix atexit 2018-03-04 04:34:22 -08:00
Jeremy Soller e2695b2380 Merge pull request #11 from dlrobertson/aarch64
Start on support for aarch64
2018-03-03 23:00:30 -07:00
Paul Sajna 01e519aa24 add semaphore to main Cargo.toml 2018-03-03 21:56:46 -08:00
Jeremy Soller 1a572d91b0 Merge pull request #8 from sajattack/fix-options
Fix options
2018-03-03 22:56:09 -07:00
Paul Sajna 09116f83f7 add mman to main Cargo.toml 2018-03-03 21:55:24 -08:00
Dan Robertson d9d2ec1992 Start on support for aarch64
- Add aarch64 support
   - crt0 - add support to _start
   - platform - aarch64 does not have the open syscall. Instead most
     libc implementations use openat() with AT_FDCWD
 - Use sc instead of syscall. sc is the maintained fork of syscall.
2018-03-04 05:10:31 +00:00
Paul Sajna 3210d52eee Merge branch 'fix-options' into semaphore 2018-03-03 21:10:11 -08:00
Paul Sajna 6cf4b3bf82 build semaphore header 2018-03-03 21:07:40 -08:00
Paul Sajna 2acf7e6915 remove mman from todo 2018-03-03 20:58:58 -08:00
Paul Sajna ba1a9543c8 build mman header 2018-03-03 20:57:29 -08:00
Paul Sajna ee6ffbe73e fix Options 2018-03-03 20:55:32 -08:00
Paul Sajna eea3f0ede6 Merge branch 'master' of github.com:redox-os/relibc 2018-03-03 20:07:33 -08:00
Jeremy Soller a6dfd7145f Merge pull request #6 from sajattack/master
wrap all function parameters in Options
2018-03-03 21:04:12 -07:00
Paul Sajna f4d8fd3186 Merge branch 'master' of github.com:redox-os/relibc 2018-03-03 19:58:12 -08:00
Jeremy Soller 352f485649 Build grp header 2018-03-03 20:52:10 -07:00
Jeremy Soller a9f2e9a9a7 Add template 2018-03-03 20:48:37 -07:00
Paul Sajna 2b16a3693e wrap all function parameters in Options 2018-03-03 19:42:29 -08:00
Paul Sajna 533cb67681 fix Options 2018-03-03 19:33:34 -08:00
Jeremy Soller c4b88cc1e6 Build ctype with header 2018-03-03 20:33:19 -07:00
Jeremy Soller 083fd72e66 Reorganize 2018-03-03 20:24:40 -07:00
Jeremy Soller 388d8ed8cf Merge stdlib 2018-03-03 20:17:46 -07:00
Jeremy Soller 9a423140bc Merge string 2018-03-03 20:17:08 -07:00
Jeremy Soller 800a3a7a47 Merge stdio files 2018-03-03 20:13:52 -07:00
Jeremy Soller 3855e4c4b9 Merge branch 'master' of https://github.com/sajattack/relibc into sajattack-master 2018-03-03 20:06:27 -07:00
Jeremy Soller 64b2970cf4 make it possible to printf to any fmt::Write implementer 2018-03-03 19:57:18 -07:00
Jeremy Soller 5520526bef Implement printf (very simple version) 2018-03-03 19:47:01 -07:00
Jeremy Soller bf987098dc Use openlibm 2018-03-03 17:56:53 -07:00
Paul Sajna 341bc1b938 parameter names 2018-03-03 16:49:01 -08:00
Jeremy Soller 172517e4f8 Add all stdlib functions 2018-03-03 17:44:09 -07:00
Jeremy Soller f5ef0af883 Implement malloc/free with ralloc 2018-03-03 16:54:58 -07:00
Jeremy Soller e30dec7124 WIP: stdio.h 2018-03-03 15:15:50 -07:00
Jeremy Soller 2aff4d41dd Implement argument handling, add string.h 2018-03-03 14:55:54 -07:00
Jeremy Soller 78e421cb72 Implement some functions on Linux 2018-03-03 14:31:28 -07:00
Paul Sajna 457d3972f7 merge with origin, put unistd back the way it was 2018-03-03 12:28:59 -08:00
Jeremy Soller 9fb0b77d89 Include sys/types in fctnl and unistd 2018-03-03 13:10:21 -07:00
Jeremy Soller d64dba1c1e Use patched cbindgen, implement stdbool and stdint 2018-03-03 13:05:43 -07:00
Jeremy Soller a9aae80ae0 WIP: Define common types 2018-03-03 10:08:16 -07:00
Jeremy Soller d337caafe6 Remove std from outputted libc.a 2018-03-03 09:19:25 -07:00
Jeremy Soller d20e3f69e1 no_std 2018-03-03 08:51:14 -07:00
Jeremy Soller a01ff6baf8 Add overarching staticlib 2018-03-03 08:44:18 -07:00
Jeremy Soller 7251cbec76 Add definitions for unistd 2018-03-03 08:33:19 -07:00
Jeremy Soller b720d0181f Add fcntl 2018-03-03 08:25:53 -07:00
Jeremy Soller 858ad52cf6 Finish function definitions for unistd 2018-03-03 08:04:16 -07:00
Paul Sajna 1a298045b6 #[no_mangle] 2018-03-02 21:27:35 -08:00
Paul Sajna e57a314acf rustfmt 2018-03-02 18:24:40 -08:00
Paul Sajna 7da98c514a wctype.h skeleton 2018-03-02 18:15:13 -08:00
Paul Sajna bd91a5a11e wchar.h skeleton 2018-03-02 18:08:35 -08:00
Paul Sajna 28b72a667c grp.h skeleton 2018-03-02 17:51:39 -08:00
Paul Sajna b8a5b9b551 aio.h skeleton 2018-03-02 17:40:35 -08:00
Paul Sajna 7f29a7127c ctype.h skeleton 2018-03-02 17:36:23 -08:00
Paul Sajna 3ccd24c50e mman 2018-03-02 17:30:20 -08:00
Paul Sajna ae49c54d60 stdio.h skeleton 2018-03-02 17:23:28 -08:00
Paul Sajna c1d1be4d61 semaphore.h skeleton 2018-03-02 17:07:17 -08:00
Paul Sajna e39ff9d5a3 add string.h skeleton 2018-03-02 16:59:44 -08:00
Paul Sajna aef8c1442d pthread skeleton 2018-03-02 16:55:13 -08:00
Paul Sajna af548fd1bc add bindgen post-processing script, use it for unistd and stdlib.h 2018-03-02 14:50:13 -08:00
Jeremy Soller b2b120bbc1 Add many more functions 2018-03-01 21:02:52 -07:00
Jeremy Soller 3267409c57 Add very basic example 2018-03-01 20:26:40 -07:00
1570 changed files with 105785 additions and 3985 deletions
+7
View File
@@ -0,0 +1,7 @@
[**.c]
indent_size = 4
indent_style = space
[**.yml]
indent_size = 4
indent_style = space
+11 -2
View File
@@ -1,2 +1,11 @@
Cargo.lock .idea/
target prefix/
sysroot/
**/target/
.gdb_history
*.patch
*.swp
*.swo
/.vim
.vscode/
+64 -8
View File
@@ -1,17 +1,73 @@
image: "redoxos/redoxer" image: "redoxos/redoxer:latest"
stages: variables:
- build GIT_SUBMODULE_STRATEGY: recursive
workflow: workflow:
rules: rules:
- if: '$CI_COMMIT_BRANCH == "master" && $CI_PROJECT_NAMESPACE == "redox-os"' - if: '$CI_COMMIT_BRANCH == "master" && $CI_PROJECT_NAMESPACE == "redox-os"'
- if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"' - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"'
build:linux: stages:
stage: build - build
script: cargo +nightly build - cross-build
- test
before_script:
cargo install cbindgen
build:redox: fmt:
stage: build stage: build
script: redoxer build needs: []
script:
- rustup component add rustfmt-preview
- ./fmt.sh -- --check
linux:
stage: build
script:
- ./check.sh --host
x86_64:
stage: build
script:
- ./check.sh --arch=x86_64
i586:
stage: cross-build
script:
- ./check.sh --arch=i586
aarch64:
stage: cross-build
image: "redoxos/redoxer:aarch64"
script:
- ./check.sh --arch=aarch64
riscv64gc:
stage: cross-build
script:
- ./check.sh --arch=riscv64gc
test:linux:
stage: test
needs: [linux]
script:
- ./check.sh --host --test
test:x86_64:
stage: test
needs: [x86_64]
script:
# timeout: https://gitlab.redox-os.org/redox-os/relibc/-/issues/238
- timeout -s KILL 9m ./check.sh --arch=x86_64 --test
test:aarch64:
stage: test
needs: [aarch64]
image: "redoxos/redoxer:aarch64"
# many issues that not exist in x86_64, and lack of interest to fix so far
allow_failure: true
script:
- timeout -s KILL 9m ./check.sh --arch=aarch64 --test
#TODO: Enable more arch once dynamic linker working
+7
View File
@@ -0,0 +1,7 @@
[submodule "openlibm"]
path = openlibm
url = https://gitlab.redox-os.org/redox-os/openlibm.git
branch = master
[submodule "src/dlmalloc-rs"]
path = dlmalloc-rs
url = https://gitlab.redox-os.org/redox-os/dlmalloc-rs.git
+123
View File
@@ -0,0 +1,123 @@
# Contributing
## Table of contents
1. [What to do](#what-to-do)
2. [Code style](#code-style)
3. [Sending merge requests](#sending-merge-requests)
4. [Writing tests](#writing-tests)
5. [Running tests](#running-tests)
Maintaining a libc is tough work, and we'd love some help!
## What to do
For now, we are still trying to get full libc compatibility before we move on to
any optimisation.
- We currently have a number of unimplemented functions. Search for
`unimplemented!()` and hop right in!
- If you notice any missing functionality, feel free to add it in
## Code style
We have a `rustfmt.toml` in the root directory of relibc. Please run `./fmt.sh`
before sending in any merge requests as it will automatically format your code.
With regards to general style:
### Where applicable, prefer using references to raw pointers
This is most obvious when looking at `stdio` functions. If raw pointers were
used instead of references, then the resulting code would be significantly
uglier. Instead try to check for pointer being valid with `pointer::as_ref()`
and `pointer::as_mut()` and then immediately use those references instead.
Internal functions should always take references.
### Use the c types exposed in our platform module instead of Rust's inbuilt integer types
This is so we can guarantee that everything works across platforms. While it is
generally accepted these days that an `int` has 32 bits (which matches against
an `i32`), some platforms have `int` as having 16 bits, and others have long as
being 32 bits instead of 64. If you use the types in platform, then we can
guarantee that your code will "just work" should we port relibc to a different
architecture.
### Use our internal functions
If you need to use a C string, don't reinvent the wheel. We have functions in
the platform module that convert C strings to Rust slices.
We also have structures that wrap files, wrap writable strings, and wrap various
other commonly used things that you should use instead of rolling your own.
## Sending merge requests
If you have sent us a merge request, first of all, thanks for taking your time
to help us!
The first thing to note is that we do most of our development on our
[GitLab server](https://gitlab.redox-os.org/redox-os/relibc), and as such it is
possible that none of the maintainers will see your merge request if it is
opened on GitHub.
In your merge request, please put in the description:
- What functions (if any) have been implemented or changed
- The rationale behind your merge request (e.g. why you thought this change was
required. If you are just implementing some functions, you can ignore this)
- Any issues that are related to the merge request
We have CI attached to our GitLab instance, so all merge requests are checked to
make sure that they are tested before they are merged. Please write tests for
the functions that you add/change and test locally on your own machine
***before*** submitting a merge request.
## Writing tests
Every function that gets written needs to have a test in C in order to make sure
it works as intended. Here are a few guidelines for writing good tests.
### Ensure that any literals you have are mapped to variables instead of being directly passed to a function.
Sometimes compilers take literals put into libc functions and run them
internally during compilation, which can cause some false positives. All tests
are compiled with `-fno-builtin`, which theoretically solves this issue, but
just in case, it'd be a good idea to map inputs to variables.
```c
#include "string.h"
#include "stdio.h"
int main(void) {
// Don't do this
printf("%d\n", strcspn("Hello", "Hi"));
// Do this
char *first = "Hello";
char *second = "Hi";
printf("%d\n", strcspn(first, second));
}
```
### Ensure your tests cover every section of code.
What happens if a string in `strcmp()` is shorter than the other string? What
happens if the first argument to `strcspn()` is longer than the second string?
In order to make sure that all functions work as expected, we ask that any tests
cover as much of the code that you have written as possible.
## Running tests
Running tests is an important part in trying to find bugs. Before opening a
merge request, we ask that you test on your own machine to make sure there are
no regressions.
You can run tests with `make test` in the root directory of relibc to compile
relibc, compile the tests and run them. This *will* print a lot of output to
stdout, so be warned!
You can test against verified correct output with `make verify` in the tests
directory. You will need to manually create the correct output and put it in the
tests/expected directory. Running any `make` commands in the tests directory
will ***not*** rebuild relibc, so you'll need to go back to the root directory
if you need to rebuild relibc.
Generated
+729
View File
@@ -0,0 +1,729 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "argon2"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c3610892ee6e0cbce8ae2700349fcf8f98adb0dbfbee85aec3c9179d29cc072"
dependencies = [
"base64ct",
"blake2",
"cpufeatures",
"password-hash",
]
[[package]]
name = "autocfg"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
[[package]]
name = "base64ct"
version = "1.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06"
[[package]]
name = "bcrypt-pbkdf"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6aeac2e1fe888769f34f05ac343bbef98b14d1ffb292ab69d4608b3abc86f2a2"
dependencies = [
"blowfish",
"pbkdf2",
"sha2",
]
[[package]]
name = "bitflags"
version = "2.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4388bee8683e3d04af747c73422af53102d2bd24d9eadb6cbc100baef4b43f8"
[[package]]
name = "blake2"
version = "0.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe"
dependencies = [
"digest",
]
[[package]]
name = "block-buffer"
version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
dependencies = [
"generic-array",
]
[[package]]
name = "blowfish"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e412e2cd0f2b2d93e02543ceae7917b3c70331573df19ee046bcbc35e45e87d7"
dependencies = [
"byteorder",
"cipher",
]
[[package]]
name = "byteorder"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "cbitset"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29b6ad25ae296159fb0da12b970b2fe179b234584d7cd294c891e2bbb284466b"
dependencies = [
"num-traits",
]
[[package]]
name = "cc"
version = "1.1.22"
source = "git+https://github.com/tea/cc-rs?branch=riscv-abi-arch-fix#588ceacb084af41415690c57688e338a32a1f1b4"
dependencies = [
"shlex",
]
[[package]]
name = "cfg-if"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "chrono"
version = "0.4.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327"
dependencies = [
"num-traits",
]
[[package]]
name = "chrono-tz"
version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6139a8597ed92cf816dfb33f5dd6cf0bb93a6adc938f11039f371bc5bcd26c3"
dependencies = [
"chrono",
"phf",
]
[[package]]
name = "cipher"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad"
dependencies = [
"crypto-common",
"inout",
]
[[package]]
name = "cpufeatures"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
dependencies = [
"libc",
]
[[package]]
name = "crt0"
version = "0.1.0"
[[package]]
name = "crti"
version = "0.1.0"
[[package]]
name = "crtn"
version = "0.1.0"
[[package]]
name = "crypto-common"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a"
dependencies = [
"generic-array",
"typenum",
]
[[package]]
name = "digest"
version = "0.10.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [
"block-buffer",
"crypto-common",
"subtle",
]
[[package]]
name = "dlmalloc"
version = "0.2.8"
dependencies = [
"cfg-if",
"windows-sys",
]
[[package]]
name = "drm-sys"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ecc8e1361066d91f5ffccff060a3c3be9c3ecde15be2959c1937595f7a82a9f8"
dependencies = [
"libc",
"linux-raw-sys",
]
[[package]]
name = "generic-array"
version = "0.14.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
dependencies = [
"typenum",
"version_check",
]
[[package]]
name = "generic-rt"
version = "0.1.0"
[[package]]
name = "goblin"
version = "0.10.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17582616a7718cca54cec18e534a76c7c4aec11a8b9a85695712f262fd15a4c8"
dependencies = [
"log",
"plain",
"scroll",
]
[[package]]
name = "hmac"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e"
dependencies = [
"digest",
]
[[package]]
name = "inout"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01"
dependencies = [
"generic-array",
]
[[package]]
name = "ioslice"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e571352c8a3b89074d12e3ee5173ffe162159105352aaaf1fc5764da747e31b"
[[package]]
name = "ld_so"
version = "0.1.0"
[[package]]
name = "libc"
version = "0.2.186"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"
[[package]]
name = "libm"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981"
[[package]]
name = "libredox"
version = "0.1.18+rb0.3.0"
dependencies = [
"bitflags",
"libc",
"plain",
]
[[package]]
name = "linux-raw-sys"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12"
[[package]]
name = "lock_api"
version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965"
dependencies = [
"scopeguard",
]
[[package]]
name = "log"
version = "0.4.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad"
[[package]]
name = "md-5"
version = "0.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf"
dependencies = [
"cfg-if",
"digest",
]
[[package]]
name = "memchr"
version = "2.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88904434abc2901f197fe8cc55f0445e7ded921dba5911dad2e2b39b48e663c4"
[[package]]
name = "num-traits"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
dependencies = [
"autocfg",
]
[[package]]
name = "object"
version = "0.36.7"
source = "git+https://gitlab.redox-os.org/andypython/object#7270e3f0d06e5ef4c2b80abc6166d31f4ddf4fea"
dependencies = [
"memchr",
]
[[package]]
name = "password-hash"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "346f04948ba92c43e8469c1ee6736c7563d71012b17d40745260fe106aac2166"
dependencies = [
"base64ct",
"rand_core 0.6.4",
"subtle",
]
[[package]]
name = "pbkdf2"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2"
dependencies = [
"digest",
"hmac",
"sha2",
]
[[package]]
name = "phf"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "913273894cec178f401a31ec4b656318d95473527be05c0752cc41cdc32be8b7"
dependencies = [
"phf_shared",
]
[[package]]
name = "phf_shared"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06005508882fb681fd97892ecff4b7fd0fee13ef1aa569f8695dae7ab9099981"
dependencies = [
"siphasher",
]
[[package]]
name = "plain"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6"
[[package]]
name = "posix-regex"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66df580334caab2f744839ab1be85493d7ec731a92d6cf928008ab0b212bf3bc"
[[package]]
name = "proc-macro2"
version = "1.0.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.46"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfbc457d0c7a0759a614551b11a6409e5951f6c7537be1f1b7682b9ae9230368"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7f5fa3a058cd35567ef9bfa5e75732bee0f9e4c55fa90477bef2dfcdbc4be80"
dependencies = [
"rand_core 0.10.1",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
[[package]]
name = "rand_core"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
[[package]]
name = "rand_jitter"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdcd80e68f0a8f9ca5ec7cfd02fd5fbb8fbe6ef4e9b90ea2f48bb929b74f88e"
dependencies = [
"libc",
"rand_core 0.10.1",
"windows-sys",
]
[[package]]
name = "rand_xorshift"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60aa6af80be32871323012e02e6e65f8a7cc7890931ae421d217ad8fe0df2ccf"
dependencies = [
"rand_core 0.10.1",
]
[[package]]
name = "redox-ioctl"
version = "0.1.0"
dependencies = [
"drm-sys",
"redox_syscall",
]
[[package]]
name = "redox-path"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "436d45c2b6a5b159d43da708e62b25be3a4a3d5550d654b72216ade4c4bfd717"
[[package]]
name = "redox-rt"
version = "0.1.0"
dependencies = [
"bitflags",
"generic-rt",
"goblin",
"ioslice",
"libredox",
"plain",
"redox-path",
"redox_syscall",
]
[[package]]
name = "redox_event"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5018d583d6d2f5499352aea8d177e9067d1eb03ab17c78169d5ba7a30001b15"
dependencies = [
"bitflags",
"libredox",
"redox_syscall",
]
[[package]]
name = "redox_syscall"
version = "0.9.0+rb0.3.0"
dependencies = [
"bitflags",
]
[[package]]
name = "relibc"
version = "0.6.0+rb0.3.0"
dependencies = [
"argon2",
"base64ct",
"bcrypt-pbkdf",
"bitflags",
"cbitset",
"cc",
"chrono",
"chrono-tz",
"dlmalloc",
"generic-rt",
"ioslice",
"libc",
"libm",
"libredox",
"log",
"md-5",
"memchr",
"object",
"pbkdf2",
"plain",
"posix-regex",
"rand",
"rand_jitter",
"rand_xorshift",
"redox-ioctl",
"redox-path",
"redox-rt",
"redox_event",
"redox_syscall",
"sc",
"scrypt",
"sha-crypt",
"sha2",
"spin",
"unicode-width",
]
[[package]]
name = "salsa20"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97a22f5af31f73a954c10289c93e8a50cc23d971e80ee446f1f6f7137a088213"
dependencies = [
"cipher",
]
[[package]]
name = "sc"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "010e18bd3bfd1d45a7e666b236c78720df0d9a7698ebaa9c1c559961eb60a38b"
[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "scroll"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1257cd4248b4132760d6524d6dda4e053bc648c9070b960929bf50cfb1e7add"
dependencies = [
"scroll_derive",
]
[[package]]
name = "scroll_derive"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed76efe62313ab6610570951494bdaa81568026e0318eaa55f167de70eeea67d"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "scrypt"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0516a385866c09368f0b5bcd1caff3366aace790fcd46e2bb032697bb172fd1f"
dependencies = [
"password-hash",
"pbkdf2",
"salsa20",
"sha2",
]
[[package]]
name = "sha-crypt"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88e79009728d8311d42d754f2f319a975f9e38f156fd5e422d2451486c78b286"
dependencies = [
"base64ct",
"sha2",
]
[[package]]
name = "sha2"
version = "0.10.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
dependencies = [
"cfg-if",
"cpufeatures",
"digest",
]
[[package]]
name = "shlex"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "siphasher"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ee5873ec9cce0195efcb7a4e9507a04cd49aec9c83d0389df45b1ef7ba2e649"
[[package]]
name = "spin"
version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
dependencies = [
"lock_api",
]
[[package]]
name = "subtle"
version = "2.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]]
name = "syn"
version = "2.0.118"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b9ae57f904213ebb649ce6895b8a66c66f0203b9319718f69a5612a065b1422"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "typenum"
version = "1.20.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20"
[[package]]
name = "unicode-ident"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
[[package]]
name = "unicode-width"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
[[package]]
name = "version_check"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]]
name = "windows-sys"
version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[patch.unused]]
name = "redox-scheme"
version = "0.11.2+rb0.3.0"
+143 -17
View File
@@ -1,25 +1,151 @@
[package] [package]
name = "redox_syscall" name = "relibc"
version = "0.9.0+rb0.3.0" version = "0.6.0+rb0.3.0"
description = "A Rust library to access raw Redox system calls"
license = "MIT"
authors = ["Jeremy Soller <jackpot51@gmail.com>", "vasilito <adminpupkin@gmail.com>"] authors = ["Jeremy Soller <jackpot51@gmail.com>", "vasilito <adminpupkin@gmail.com>"]
repository = "https://gitlab.redox-os.org/redox-os/syscall" edition = "2024"
documentation = "https://docs.rs/redox_syscall"
edition = "2021"
[lib] [lib]
name = "syscall" name = "relibc"
crate-type = ["staticlib"]
[features] [workspace]
default = ["userspace"] members = [
rustc-dep-of-std = ["core", "bitflags/rustc-dep-of-std"] "src/crt0",
userspace = [] "src/crti",
std = [] "src/crtn",
"redox-rt",
"ld_so",
"generic-rt",
]
exclude = ["tests", "dlmalloc-rs"]
[workspace.lints.clippy]
borrow_as_ptr = "deny"
cast_lossless = "warn" # TODO review occurrences
cast_possible_truncation = "allow" # TODO review occurrences
cast_possible_wrap = "allow" # TODO review occurrences
cast_precision_loss = "allow" # TODO review occurrences
cast_ptr_alignment = "allow" # TODO review occurrences
cast_sign_loss = "allow" # TODO review occurrences
missing_errors_doc = "allow" # TODO review occurrences
missing_panics_doc = "allow" # TODO review occurrences
missing_safety_doc = "allow" # TODO review occurrences
mut_from_ref = "warn" # TODO review occurrences
precedence = "deny"
ptr_as_ptr = "warn" # TODO review occurrences
ptr_cast_constness = "warn" # TODO review occurrences
ref_as_ptr = "warn" # TODO review occurrences
upper_case_acronyms = "allow" # TODO review occurrences
zero_ptr = "warn" # must allow on public constants due to cbindgen issue
[workspace.lints.rust]
dangling_pointers_from_temporaries = "deny"
dead_code = "allow" # TODO review occuurences
deprecated = "deny"
improper_ctypes_definitions = "deny"
internal_features = "allow" # core_intrinsics and lang_items
irrefutable_let_patterns = "deny"
mismatched_lifetime_syntaxes = "deny"
non_camel_case_types = "allow" # needed for most POSIX type names
non_snake_case = "allow" # TODO review occuurences
non_upper_case_globals = "allow" # TODO review occuurences
unexpected_cfgs = "deny"
unpredictable_function_pointer_comparisons = "deny"
unreachable_code = "allow" # TODO review occuurences
unsafe_op_in_unsafe_fn = "deny"
unused_imports = "deny"
unused_must_use = "deny"
unused_mut = "deny"
unused_unsafe = "deny"
unused_variables = "allow" # TODO review occurrences (too many for now)
[lints]
workspace = true
[workspace.dependencies]
bitflags = "2"
ioslice = { version = "0.6", default-features = false }
plain = "0.2"
redox-path = "0.3"
redox_protocols = { package = "libredox", path = "../libredox", default-features = false, features = ["protocol"] }
redox_syscall = { path = "../syscall" }
[build-dependencies]
cc = "1"
[dependencies] [dependencies]
bitflags = "2.4" bitflags.workspace = true
core = { version = "1.0.0", optional = true, package = "rustc-std-workspace-core" } cbitset = "0.2"
posix-regex = { version = "0.1.4", features = ["no_std"] }
[target.'cfg(loom)'.dev-dependencies] rand = { version = "0.10", default-features = false }
loom = "0.7" rand_xorshift = "0.5"
rand_jitter = "0.6"
memchr = { version = "2.2.0", default-features = false }
plain.workspace = true
unicode-width = "0.1"
__libc_only_for_layout_checks = { package = "libc", version = "0.2.149", optional = true }
md5-crypto = { package = "md-5", version = "0.10.6", default-features = false }
sha-crypt = { version = "0.5", default-features = false }
base64ct = { version = "1.6", default-features = false, features = ["alloc"] }
bcrypt-pbkdf = { version = "0.10", default-features = false, features = [
"alloc",
] }
scrypt = { version = "0.11", default-features = false, features = ["simple"] }
pbkdf2 = { version = "0.12", features = ["sha2"] }
sha2 = { version = "0.10", default-features = false }
generic-rt = { path = "generic-rt" }
chrono-tz = { version = "0.10", default-features = false }
chrono = { version = "0.4", default-features = false, features = ["alloc"] }
libm = "0.2"
log = "0.4"
spin = "0.9.8"
argon2 = "0.5.3"
[dependencies.dlmalloc]
path = "dlmalloc-rs"
default-features = false
features = ["c_api"]
[dependencies.object]
version = "0.36.7"
git = "https://gitlab.redox-os.org/andypython/object"
default-features = false
features = ["elf", "read_core"]
[target.'cfg(target_os = "linux")'.dependencies]
sc = "0.2.7"
[target.'cfg(target_os = "redox")'.dependencies]
redox_syscall.workspace = true
redox-rt = { path = "redox-rt" }
redox-path.workspace = true
redox_event = { version = "0.4.8", default-features = false, features = [
"redox_syscall",
] }
ioslice.workspace = true
redox-ioctl = { path = "redox-ioctl" }
redox_protocols.workspace = true
[features]
# to enable trace level, take out this `no_trace`
default = ["check_against_libc_crate", "ld_so_cache", "no_trace"]
check_against_libc_crate = ["__libc_only_for_layout_checks"]
ld_so_cache = []
math_libm = []
no_trace = ["log/release_max_level_debug"]
# for very verbose activity beyond trace level
trace_tls = []
[profile.dev]
panic = "abort"
[profile.release]
panic = "abort"
[patch.crates-io]
cc-11 = { git = "https://github.com/tea/cc-rs", branch = "riscv-abi-arch-fix", package = "cc" }
redox_syscall = { path = "../syscall" }
libredox = { path = "../libredox" }
redox-scheme = { path = "../redox-scheme" }
+17 -18
View File
@@ -1,22 +1,21 @@
Copyright (c) 2017 Redox OS Developers
MIT License MIT License
Permission is hereby granted, free of charge, to any person obtaining Copyright (c) 2018 Redox OS
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be Permission is hereby granted, free of charge, to any person obtaining a copy
included in all copies or substantial portions of the Software. of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, The above copyright notice and this permission notice shall be included in all
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF copies or substantial portions of the Software.
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+226
View File
@@ -0,0 +1,226 @@
include config.mk
CARGO?=cargo
CARGO_TEST?=$(CARGO)
CARGO_COMMON_FLAGS=-Z build-std=core,alloc,compiler_builtins
CARGOFLAGS?=$(CARGO_COMMON_FLAGS)
CC_WRAPPER?=
RUSTCFLAGS?=
LINKFLAGS?=-lgcc
USE_RUST_LIBM?=
TESTBIN?=
export OBJCOPY?=objcopy
export CARGO_TARGET_DIR?=$(shell pwd)/target
BUILD?=$(CARGO_TARGET_DIR)/$(TARGET)
CARGOFLAGS+=--target=$(TARGET)
EXCEPT_MATH=-not -name "math"
FEATURE_MATH=
ifneq ($(USE_RUST_LIBM),)
FEATURE_MATH=--features math_libm
EXCEPT_MATH=
endif
TARGET_HEADERS?=$(BUILD)/include
export CFLAGS=-I$(TARGET_HEADERS)
PROFILE?=release
HEADERS_UNPARSED=$(shell find src/header -mindepth 1 -maxdepth 1 -type d -not -name "_*" $(EXCEPT_MATH) -printf "%f\n")
HEADERS_DEPS=$(shell find src/header -type f \( -name "cbindgen.toml" -o -name "*.rs" \))
#HEADERS=$(patsubst %,%.h,$(subst _,/,$(HEADERS_UNPARSED)))
SRC=\
Cargo.* \
$(shell find src/ redox-rt/src/ ld_so/src/ redox-ioctl/src/ include/ -type f)
BUILTINS_VERSION=0.1.70
.PHONY: all clean fmt install install-libs install-headers install-tests libs headers submodules test
all: | headers libs
headers: $(HEADERS_DEPS)
rm -rf $(TARGET_HEADERS)
mkdir -p $(TARGET_HEADERS)
cp -r include/* $(TARGET_HEADERS)
ifeq ($(USE_RUST_LIBM),)
cp "openlibm/include"/*.h $(TARGET_HEADERS)
cp "openlibm/src"/*.h $(TARGET_HEADERS)
endif
@set -e ; \
for header in $(HEADERS_UNPARSED); do \
if test -f "src/header/$$header/cbindgen.toml"; then \
echo -e "\033[0;36;49mWriting Header $$header\033[0m"; \
out=`echo "$$header" | sed 's/_/\//g'`; \
out="$(TARGET_HEADERS)/$$out.h"; \
cat "src/header/$$header/cbindgen.toml" cbindgen.globdefs.toml \
| cbindgen "src/header/$$header/mod.rs" --config=/dev/stdin --output "$$out" 2>/dev/null; \
fi \
done; echo -e "\033[0;36;49mAll headers written\033[0m";
clean:
$(CARGO) clean
$(MAKE) -C tests clean
rm -rf sysroot
check:
$(CARGO) check
fmt:
./fmt.sh
install-headers: headers libs
mkdir -pv "$(DESTDIR)/include"
cp -rv "$(TARGET_HEADERS)"/* "$(DESTDIR)/include"
libs: \
$(BUILD)/$(PROFILE)/libc.a \
$(BUILD)/$(PROFILE)/libc.so \
$(BUILD)/$(PROFILE)/crt0.o \
$(BUILD)/$(PROFILE)/crti.o \
$(BUILD)/$(PROFILE)/crtn.o \
$(BUILD)/$(PROFILE)/ld.so
install-libs: headers libs
mkdir -pv "$(DESTDIR)/lib"
cp -v "$(BUILD)/$(PROFILE)/libc.a" "$(DESTDIR)/lib"
cp -v "$(BUILD)/$(PROFILE)/libc.so" "$(DESTDIR)/lib"
ln -vnfs libc.so "$(DESTDIR)/lib/libc.so.6"
cp -v "$(BUILD)/$(PROFILE)/crt0.o" "$(DESTDIR)/lib"
ln -vnfs crt0.o "$(DESTDIR)/lib/crt1.o"
cp -v "$(BUILD)/$(PROFILE)/crti.o" "$(DESTDIR)/lib"
cp -v "$(BUILD)/$(PROFILE)/crtn.o" "$(DESTDIR)/lib"
cp -v "$(BUILD)/$(PROFILE)/ld.so" "$(DESTDIR)/$(LD_SO_PATH)"
ifeq ($(USE_RUST_LIBM),)
cp -v "$(BUILD)/openlibm/libopenlibm.a" "$(DESTDIR)/lib/libm.a"
endif
# Empty libraries for dl, pthread, and rt
$(AR) -rcs "$(DESTDIR)/lib/libdl.a"
$(AR) -rcs "$(DESTDIR)/lib/libpthread.a"
$(AR) -rcs "$(DESTDIR)/lib/librt.a"
install-tests: tests
$(MAKE) -C tests
mkdir -p "$(DESTDIR)/relibc-tests"
cp -vr tests/build_$(TARGET)/* "$(DESTDIR)/relibc-tests/"
install: install-headers install-libs
submodules:
git submodule sync
git submodule update --init --recursive
sysroot:
@mkdir -p $@
.PHONY: sysroot/$(TARGET)
sysroot/$(TARGET): | sysroot
rm -rf $@
rm -rf $@.partial
mkdir -p $@.partial
$(MAKE) install DESTDIR=$(shell pwd)/$@.partial
mv $@.partial $@
touch $@
test: sysroot/$(TARGET)
# TODO: Fix SIGILL when running cargo test
# $(CARGO_TEST) test
$(MAKE) -C tests run
test-once: sysroot/$(TARGET)
$(MAKE) -C tests run-once TESTBIN=$(TESTBIN)
$(BUILD)/$(PROFILE)/libc.so: $(BUILD)/$(PROFILE)/libc.a
$(CC) -nostdlib \
-shared \
-Wl,--gc-sections \
-Wl,-z,pack-relative-relocs \
-Wl,--sort-common \
-Wl,--whole-archive $^ -Wl,--no-whole-archive \
-Wl,-soname,libc.so.6 \
$(LINKFLAGS) \
-o $@
$(BUILD)/$(PROFILE)/ld.so: $(BUILD)/$(PROFILE)/ld_so.o $(BUILD)/$(PROFILE)/libc.a
# TODO: merge ld.so with libc.so: --dynamic-list=dynamic-list-file
$(LD) --shared -Bsymbolic --no-relax -T ld_so/ld_script/$(TARGET).ld --gc-sections $^ -o $@
$(BUILD)/$(PROFILE)/libc.a: $(BUILD)/$(PROFILE)/librelibc.a $(BUILD)/openlibm/libopenlibm.a
echo "create $@" > "$@.mri"
for lib in $^; do\
echo "addlib $$lib" >> "$@.mri"; \
done
echo "save" >> "$@.mri"
echo "end" >> "$@.mri"
$(AR) -M < "$@.mri"
# Debug targets
$(BUILD)/debug/librelibc.a: $(SRC)
$(CARGO) rustc $(CARGOFLAGS) $(FEATURE_MATH) -- --emit link=$@ -g -C debug-assertions=no $(RUSTCFLAGS)
./renamesyms.sh "$@" "$(BUILD)/debug/deps/"
./stripcore.sh "$@"
touch $@
$(BUILD)/debug/crt0.o: $(SRC)
$(CARGO) rustc --manifest-path src/crt0/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort $(RUSTCFLAGS)
touch $@
$(BUILD)/debug/crti.o: $(SRC)
$(CARGO) rustc --manifest-path src/crti/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort $(RUSTCFLAGS)
touch $@
$(BUILD)/debug/crtn.o: $(SRC)
$(CARGO) rustc --manifest-path src/crtn/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort $(RUSTCFLAGS)
touch $@
$(BUILD)/debug/ld_so.o: $(SRC)
$(CARGO) rustc --manifest-path ld_so/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort -g -C debug-assertions=no $(RUSTCFLAGS)
touch $@
# Release targets
$(BUILD)/release/librelibc.a: $(SRC)
$(CARGO) rustc --release $(CARGOFLAGS) -- --emit link=$@ $(RUSTCFLAGS)
@# TODO: Better to only allow a certain whitelisted set of symbols? Perhaps
@# use some cbindgen hook, specify them manually, or grep for #[unsafe(no_mangle)].
./renamesyms.sh "$@" "$(BUILD)/release/deps/"
./stripcore.sh "$@"
touch $@
$(BUILD)/release/crt0.o: $(SRC)
$(CARGO) rustc --release --manifest-path src/crt0/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort $(RUSTCFLAGS)
touch $@
$(BUILD)/release/crti.o: $(SRC)
$(CARGO) rustc --release --manifest-path src/crti/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort $(RUSTCFLAGS)
touch $@
$(BUILD)/release/crtn.o: $(SRC)
$(CARGO) rustc --release --manifest-path src/crtn/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort $(RUSTCFLAGS)
touch $@
$(BUILD)/release/ld_so.o: $(SRC)
$(CARGO) rustc --release --manifest-path ld_so/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort $(RUSTCFLAGS)
touch $@
# Other targets
$(BUILD)/openlibm: openlibm
rm -rf $@ $@.partial
mkdir -p $(BUILD)
cp -r $< $@.partial
mv $@.partial $@
touch $@
ifeq ($(USE_RUST_LIBM),)
$(BUILD)/openlibm/libopenlibm.a: $(BUILD)/openlibm $(BUILD)/$(PROFILE)/librelibc.a
$(MAKE) -s AR=$(AR) CC="$(CC_WRAPPER) $(CC)" LD=$(LD) CPPFLAGS="$(CPPFLAGS) -fno-stack-protector -I$(shell pwd)/include -I$(TARGET_HEADERS)" -C $< libopenlibm.a
./renamesyms.sh "$@" "$(BUILD)/release/deps/"
else
$(BUILD)/openlibm/libopenlibm.a:
mkdir -p "$(BUILD)/openlibm"
$(AR) -rcs "$(BUILD)/openlibm/libopenlibm.a"
endif
+171 -5
View File
@@ -1,7 +1,173 @@
# syscall # Redox C Library (relibc)
This crate contains the system call numbers and Rust wrappers for the inline Assembly code of system calls. relibc is a portable C standard library written in Rust and is under heavy development, this library contain the following items:
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE) - C, Linux, BSD functions and extensions
[![crates.io](http://meritbadge.herokuapp.com/redox_syscall)](https://crates.io/crates/redox_syscall) - POSIX compatibility layer
[![docs.rs](https://docs.rs/redox_syscall/badge.svg)](https://docs.rs/redox_syscall) - Interfaces for system components
The motivation for this project is twofold: Reduce issues that the Redox developers were having with [newlib](https://sourceware.org/newlib/), and create a more stable and safe alternative to C standard libraries written in C. It is mainly designed to be used under Redox, as an alternative to newlib, but it also supports Linux via the [sc](https://crates.io/crates/sc) crate.
Currently Redox and Linux are supported.
## `redox-rt`
`redox-rt` is a runtime library that provides much of the code that enables POSIX on Redox, like `fork`, `exec`, signal handling, etc.
Relibc uses it as backend in `src/platform/redox`, and it's intended to eventually be usable independently, without relibc.
## Repository Layout
- `include` - Header files (mostly macros and variadic functions `cbindgen` can't generate)
- `src` - Source files
- `src/c` - C code
- `src/crt0` - Runtime code
- `src/crti` - Runtime code
- `src/crtn` - Runtime code
- `src/header` - Header files implementation
- `src/header/*` - Each folder has a `cbindgen.toml` file, it generates a C-to-Rust interface and header files
- `src/ld_so` - Dynamic loader code
- `src/platform` - Platform-specific and common code
- `src/platform/redox` - Redox-specific code
- `src/platform/linux` - Linux-specific code
- `src/pthread` - pthread implementation
- `src/sync` - Synchronization primitives
- `tests` - C tests (each MR needs to give success in all of them)
## Download the sources
To download the relibc sources run the following command:
```sh
git clone --recursive https://gitlab.redox-os.org/redox-os/relibc
```
## Build Instructions
To build relibc out of the Redox build system, do the following steps:
### Dependencies
- Install `cbindgen`
```sh
cargo install cbindgen
```
#### Install the `expect` tool
- Debian, Ubuntu and PopOS:
```sh
sudo apt install expect
```
- Fedora:
```sh
sudo dnf install expect
```
- Arch Linux:
```sh
sudo pacman -S expect
```
### Build Relibc
To build the relibc library objects, run the following command:
```sh
make all
```
- Clean old library objects and tests
```sh
make clean
```
## Build relibc inside the Redox build system
Inside of your Redox build system, run:
```sh
make prefix
```
If you need to rebuild `relibc` for testing a Cookbook recipe, run:
```sh
touch relibc
make prefix r.recipe-name
```
Touching (changing the "last modified time" of) the `relibc` folder is needed to trigger recompilation for `make prefix`. Replace `recipe-name` with your desired recipe name.
Note: Do not edit `relibc` inside `prefix` folder! Do your work on `relibc` folder directly inside your Redox build system instead.
## Tests
Relibc has a test suite that also runs every time a new commit get pushed. You can see `.gitlab-ci.yml` to see how it's being executed. That being said, `./check.sh` is the recommended way to run tests. Here's few examples:
+ `./check.sh` - Run build, without running the test
+ `./check.sh --test` - Run all tests in x86_64 Redox using Redoxer
+ `./check.sh --test --host` - Run all tests in host (Linux)
+ `./check.sh --test --arch=aarch64` - Run all tests in specified arch
- Arch can be `x86_64`, `aarch64`, `i586`, or `riscv64gc`
+ `./check.sh --test=stdio/printf` - Run a single test
- Can be combined with `--host` or `--arch`
- Will run statically linked test in Linux, dynamically linked in Redox
Couple of notes:
- Relibc and its tests will rebuild if files changed, however switching between arch or host requires you to run `make clean`
- Redoxer is needed to run tests for Redox without `--host`. You can install it using `cargo install redoxer`
- Tests can hangs, the test runner can anticipate this, assuming the kernel doesn't hang too.
## Issues
#### I'm building for my own platform which I run, and am getting `x86_64-linux-gnu-ar: command not found` (or similar)
The Makefile expects GNU compiler tools prefixed with the platform specifier, as would be present when you installed a cross compiler. Since you are building for your own platform, some Linux distributions (like Manjaro) don't install/symlink the prefixed executables.
An easy fix would be to replace the corresponding lines in `config.mk`, e.g.
```diff
ifeq ($(TARGET),x86_64-unknown-linux-gnu)
- export CC=x86_64-linux-gnu-gcc
- export LD=x86_64-linux-gnu-ld
- export AR=x86_64-linux-gnu-ar
- export NM=x86_64-linux-gnu-nm
+ export CC=gcc
+ export LD=ld
+ export AR=ar
+ export NM=nm
export OBJCOPY=objcopy
export CPPFLAGS=
LD_SO_PATH=lib/ld64.so.1
endif
```
## Contributing
Before starting to contribute, read [this](CONTRIBUTING.md) document.
## Supported OSes
- Redox OS
- Linux
## Supported architectures
- i586 (Intel/AMD)
- x86_64 (Intel/AMD)
- aarch64 (ARM64)
- riscv64gc (RISC-V)
## Funding - _Unix-style Signals and Process Management_
This project is funded through [NGI Zero Core](https://nlnet.nl/core), a fund established by [NLnet](https://nlnet.nl) with financial support from the European Commission's [Next Generation Internet](https://ngi.eu) program. Learn more at the [NLnet project page](https://nlnet.nl/project/RedoxOS-Signals).
[<img src="https://nlnet.nl/logo/banner.png" alt="NLnet foundation logo" width="20%" />](https://nlnet.nl)
[<img src="https://nlnet.nl/image/logos/NGI0_tag.svg" alt="NGI Zero Logo" width="20%" />](https://nlnet.nl/core)
+62
View File
@@ -0,0 +1,62 @@
extern crate cc;
use std::{env, fs};
fn main() {
let _crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
let target = env::var("TARGET").unwrap();
println!("cargo:rerun-if-changed=src/c");
// The Redoxer toolchain and some upstream nightlies keep the older
// `VaList<'a>` ABI for `extern "C" fn(...)` parameters, while others
// pass `VaListImpl<'f>` and require `.as_va_list()` to obtain
// `VaList<'_, '_>`. This is a host-compiler property, so probe
// directly with the host rustc (avoiding autocfg's target probing).
println!("cargo:rustc-check-cfg=cfg(relibc_valist_impl)");
let rustc = env::var("RUSTC").unwrap_or_else(|_| "rustc".to_string());
let out_dir = env::var("OUT_DIR").unwrap_or_else(|_| "/tmp".to_string());
let probe_file = std::path::Path::new(&out_dir).join("relibc_valist_probe.rs");
let probe_out = std::path::Path::new(&out_dir).join("librelibc_valist_probe.rlib");
std::fs::write(
&probe_file,
"#![feature(c_variadic)] pub fn _relibc_valist_probe(_: core::ffi::VaList<'_, '_>) {}",
)
.ok();
let probe_ok = std::process::Command::new(&rustc)
.args([
"--crate-type",
"lib",
"--edition",
"2024",
probe_file.to_str().unwrap(),
"-o",
probe_out.to_str().unwrap(),
])
.status()
.ok()
.map_or(false, |s| s.success());
if probe_ok {
println!("cargo:rustc-cfg=relibc_valist_impl");
}
let mut cc_builder = &mut cc::Build::new();
cc_builder = cc_builder.flag("-nostdinc").flag("-nostdlib");
if target.starts_with("aarch64") {
cc_builder = cc_builder.flag("-mno-outline-atomics")
}
cc_builder
.flag("-fno-stack-protector")
.flag("-Wno-expansion-to-defined")
.files(
fs::read_dir("src/c")
.expect("src/c directory missing")
.map(|res| res.expect("read_dir error").path()),
)
.compile("relibc_c");
println!("cargo:rustc-link-lib=static=relibc_c");
}
+24
View File
@@ -0,0 +1,24 @@
# needs a leading newline
[defines]
"target_os=redox" = "__redox__"
"target_os=linux" = "__linux__"
"target_pointer_width=64" = "__LP64__"
"target_pointer_width=32" = "__ILP32__"
"target_arch=x86" = "__i386__"
"target_arch=x86_64" = "__x86_64__"
"target_arch=aarch64" = "__aarch64__"
# This is not exact. It should be `defined(__riscv) && defined(__LP64__)`, or `defined(__riscv) && __riscv_xlen==64`
# This will do however, as long as we only support riscv64 and not riscv32
"target_arch=riscv64" = "__riscv"
# XXX: silences a warning
"feature = no_std" = "__relibc__"
# Ensure attributes are passed down from Rust
# <features.h> must be included where attributes are used in relibc
[fn]
must_use = "__nodiscard"
deprecated = "__deprecated"
deprecated_with_note = "__deprecatedNote({})"
no_return = "__noreturn"
Executable
+168
View File
@@ -0,0 +1,168 @@
#!/bin/bash
RED='\033[1;38;5;196m'
GREEN='\033[1;38;5;46m'
NC='\033[0m'
show_help() {
echo "Usage: $(basename "$0") [OPTIONS]"
echo ""
echo "Description:"
echo " Wrapper for Makefile / Cargo to run checks or tests on Redox OS targets."
echo ""
echo "Options:"
echo " --test Run 'make test' instead of 'make all'"
echo " --test= Run single 'make test'"
echo " --cargo Run 'cargo check' / 'cargo test' instead"
echo " (note: cargo test is currently not maintained for relibc)"
echo " --host Run the command on host (linux) target"
echo " --all-target Run the command on all supported Redox architectures"
echo " --target=<target> Override the target architecture (e.g., i586-unknown-redox)"
echo " --arch=<arch> Override the target architecture using arch (e.g., i586)"
echo " --help Show this help message"
echo ""
echo "Supported Targets:"
for t in "${SUPPORTED_TARGETS[@]}"; do
echo " - $t"
done
echo " - $(uname -m)-unknown-linux-gnu"
echo ""
echo "Environment:"
echo " TARGET Sets the default target (overridden by --target)"
}
if ! command -v cbindgen &> /dev/null; then
echo "Error: 'cbindgen' CLI not found."
echo "Please install it: cargo install cbindgen"
exit 1
fi
SUPPORTED_TARGETS=(
"x86_64-unknown-redox"
"i586-unknown-redox"
"aarch64-unknown-redox"
"riscv64gc-unknown-redox"
)
CURRENT_TARGET="${TARGET:-x86_64-unknown-redox}"
CHECK_ALL=false
CMD_ACTION="make"
CARGO_ACTION="check"
MAKE_ACTION="all"
TEST_BIN=""
IS_HOST=0
while [[ $# -gt 0 ]]; do
case "$1" in
--all-target)
CHECK_ALL=true
;;
--test)
MAKE_ACTION="test"
CARGO_ACTION="test"
;;
--test=*)
TEST_BIN="${1#*=}"
MAKE_ACTION="test-once"
;;
--cargo)
CMD_ACTION="cargo"
;;
--host)
CURRENT_TARGET="$(uname -m)-unknown-linux-gnu"
IS_HOST=1
;;
--target=*)
CURRENT_TARGET="${1#*=}"
;;
--arch=*)
CURRENT_TARGET="${1#*=}-unknown-redox"
;;
--help)
show_help
exit 0
;;
*)
echo -e "${RED}Error: Unknown option '$1'${NC}"
show_help
exit 1
;;
esac
shift
done
if [ "$IS_HOST" -eq 0 ]; then
if ! command -v redoxer &> /dev/null; then
echo "Error: 'redoxer' CLI not found."
echo "Please install it: cargo install redoxer"
exit 1
fi
fi
run_redoxer() {
export TARGET=$1
REDOXER_ENV="redoxer env"
if [ "$IS_HOST" -eq 0 ]; then
redoxer toolchain || { echo -e "${RED}Fail: redoxer toolchain for: $target.${NC}" && exit 1; }
export CARGO_TEST="redoxer"
export TEST_RUNNER="redoxer exec --folder ../../sysroot/$TARGET/:/usr --folder . --"
# TODO: Identify hang issue with pthread/barrier and pthread/once tests in multi core to get rid of this limit
export REDOXER_QEMU_ARGS="-smp 1"
MAKE_ACTION="$MAKE_ACTION IS_REDOX=1"
else
REDOXER_ENV=""
fi
if [ "$TEST_BIN" != "" ]; then
if [ "$IS_HOST" -eq 0 ]; then
MAKE_ACTION="$MAKE_ACTION TESTBIN=bins_dynamic/$TEST_BIN"
else
MAKE_ACTION="$MAKE_ACTION TESTBIN=bins_static/$TEST_BIN"
fi
fi
if [ "$CMD_ACTION" == "make" ]; then
CMD_OPT="-j $(nproc) $MAKE_ACTION"
else
CMD_OPT="$CARGO_ACTION"
fi
echo "----------------------------------------"
echo "Running $REDOXER_ENV $CMD_ACTION $CMD_OPT for: $TARGET"
if $REDOXER_ENV $CMD_ACTION $CMD_OPT; then
return 0
else
echo -e "${RED}Fail: $CMD_ACTION $CMD_OPT for $TARGET failed.${NC}"
return 1
fi
}
if [ "$CHECK_ALL" = true ]; then
echo "Running $CMD_ACTION for all supported Redox targets..."
has_error=false
for target in "${SUPPORTED_TARGETS[@]}"; do
if ! run_redoxer "$target"; then
has_error=true
fi
done
echo "----------------------------------------"
if [ "$has_error" = true ]; then
echo -e "${RED}Summary: One or more targets failed.${NC}"
exit 1
else
echo -e "${GREEN}Summary: All targets passed!${NC}"
exit 0
fi
else
if run_redoxer "$CURRENT_TARGET"; then
echo -e "${GREEN}Success: $CARGO_ACTION for $CURRENT_TARGET passed.${NC}"
exit 0
else
exit 1
fi
fi
+73
View File
@@ -0,0 +1,73 @@
ifndef TARGET
export TARGET:=$(shell rustc -Z unstable-options --print target-spec-json | grep llvm-target | cut -d '"' -f4)
endif
ifeq ($(TARGET),aarch64-unknown-linux-gnu)
export CC=aarch64-linux-gnu-gcc
export LD=aarch64-linux-gnu-ld
export AR=aarch64-linux-gnu-ar
export NM=aarch64-linux-gnu-nm
export OBJCOPY=aarch64-linux-gnu-objcopy
export CPPFLAGS=
LD_SO_PATH=lib/ld.so.1
endif
ifeq ($(TARGET),aarch64-unknown-redox)
export CC=aarch64-unknown-redox-gcc
export LD=aarch64-unknown-redox-ld
export AR=aarch64-unknown-redox-ar
export NM=aarch64-unknown-redox-nm
export OBJCOPY=aarch64-unknown-redox-objcopy
export CPPFLAGS=
LD_SO_PATH=lib/ld.so.1
endif
ifeq ($(TARGET),i586-unknown-redox)
export CC=i586-unknown-redox-gcc
export LD=i586-unknown-redox-ld
export AR=i586-unknown-redox-ar
export NM=i586-unknown-redox-nm
export OBJCOPY=i586-unknown-redox-objcopy
export CPPFLAGS=
LD_SO_PATH=lib/libc.so.1
endif
ifeq ($(TARGET),i686-unknown-redox)
export CC=i686-unknown-redox-gcc
export LD=i686-unknown-redox-ld
export AR=i686-unknown-redox-ar
export NM=i686-unknown-redox-nm
export OBJCOPY=i686-unknown-redox-objcopy
export CPPFLAGS=
LD_SO_PATH=lib/libc.so.1
endif
ifeq ($(TARGET),x86_64-unknown-linux-gnu)
export CC=x86_64-linux-gnu-gcc
export LD=x86_64-linux-gnu-ld
export AR=x86_64-linux-gnu-ar
export NM=x86_64-linux-gnu-nm
export OBJCOPY=objcopy
export CPPFLAGS=
LD_SO_PATH=lib/ld64.so.1
endif
ifeq ($(TARGET),x86_64-unknown-redox)
export CC=x86_64-unknown-redox-gcc
export LD=x86_64-unknown-redox-ld
export AR=x86_64-unknown-redox-ar
export NM=x86_64-unknown-redox-nm
export OBJCOPY=x86_64-unknown-redox-objcopy
export CPPFLAGS=
LD_SO_PATH=lib/ld64.so.1
endif
ifeq ($(TARGET),riscv64gc-unknown-redox)
export CC=riscv64-unknown-redox-gcc
export LD=riscv64-unknown-redox-ld
export AR=riscv64-unknown-redox-ar
export NM=riscv64-unknown-redox-nm
export OBJCOPY=riscv64-unknown-redox-objcopy
export CPPFLAGS=-march=rv64gc -mabi=lp64d
LD_SO_PATH=lib/ld.so.1
endif
+117
View File
@@ -0,0 +1,117 @@
name: CI
on: [push, pull_request]
jobs:
test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
rust: stable
- os: ubuntu-latest
rust: beta
- os: ubuntu-latest
rust: nightly
- os: macos-latest
rust: stable
- os: windows-latest
rust: stable
- os: ubuntu-latest
rust: stable
target: wasm32-wasip1
steps:
- uses: actions/checkout@v4
- run: rustup update ${{ matrix.rust }} --no-self-update && rustup default ${{ matrix.rust }}
shell: bash
# Configure cross-builds by adding the rustup target and configuring future
# cargo invocations.
- run: |
rustup target add ${{ matrix.target }}
echo CARGO_BUILD_TARGET=${{ matrix.target }} >> $GITHUB_ENV
if: matrix.target != ''
# For wasm install wasmtime as a test runner and configure it with Cargo.
- name: Setup `wasmtime`
uses: bytecodealliance/actions/wasmtime/setup@v1
if: matrix.target == 'wasm32-wasip1'
- run: echo CARGO_TARGET_WASM32_WASIP1_RUNNER=wasmtime >> $GITHUB_ENV
if: matrix.target == 'wasm32-wasip1'
- run: cargo test
- run: cargo test --features debug
- run: cargo test --features global
- run: cargo test --release
env:
CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS: true
- run: cargo test --release
env:
CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS: false
- run: cargo test --features debug --release
env:
CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS: true
- run: RUSTFLAGS='--cfg test_lots' cargo test --release
shell: bash
env:
CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS: true
- run: RUSTFLAGS='--cfg test_lots' cargo test --release --features debug
shell: bash
env:
CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS: true
rustfmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update stable && rustup default stable && rustup component add rustfmt
- run: cargo fmt -- --check
wasm:
name: WebAssembly
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update stable && rustup default stable && rustup target add wasm32-unknown-unknown
- run: cargo build --target wasm32-unknown-unknown
- run: cargo build --target wasm32-unknown-unknown --release
external-platform:
name: external-platform
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update stable && rustup default stable && rustup target add x86_64-fortanix-unknown-sgx
- run: cargo build --target x86_64-fortanix-unknown-sgx
fuzz:
name: Build Fuzzers
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update nightly && rustup default nightly
- run: cargo install cargo-fuzz
- run: cargo fuzz build --dev
miri:
name: Miri
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Miri
run: |
rustup toolchain install nightly --component miri
rustup override set nightly
cargo miri setup
- name: Test with Miri Stack Borrows
run: cargo miri test
- name: Test with Miri Tree Borrows
run: cargo miri test
env:
MIRIFLAGS: -Zmiri-tree-borrows
+3
View File
@@ -0,0 +1,3 @@
/target/
**/*.rs.bk
Cargo.lock
+70
View File
@@ -0,0 +1,70 @@
[package]
name = "dlmalloc"
version = "0.2.8"
authors = ["Alex Crichton <alex@alexcrichton.com>"]
license = "MIT/Apache-2.0"
readme = "README.md"
repository = "https://github.com/alexcrichton/dlmalloc-rs"
homepage = "https://github.com/alexcrichton/dlmalloc-rs"
documentation = "https://docs.rs/dlmalloc"
description = """
A Rust port of the dlmalloc allocator
"""
edition.workspace = true
[workspace]
members = ['fuzz']
[workspace.package]
edition = '2021'
[package.metadata.docs.rs]
features = ['global']
[lib]
doctest = false
[target.'cfg(all(unix, not(target_arch = "wasm32")))'.dependencies]
libc = { version = "0.2", default-features = false, optional = true }
[dependencies]
# For more information on these dependencies see rust-lang/rust's
# `src/tools/rustc-std-workspace` folder
core = { version = '1.0.0', optional = true, package = 'rustc-std-workspace-core' }
compiler_builtins = { version = '0.1.0', optional = true }
cfg-if = "1.0"
[target.'cfg(target_os = "windows")'.dependencies.windows-sys]
version = ">=0.52.0, <=0.59.*"
features = [
"Win32_Foundation",
"Win32_System_Memory",
"Win32_System_Threading",
"Win32_System_SystemInformation",
]
[dev-dependencies]
arbitrary = "1.3.2"
rand = { version = "0.8", features = ['small_rng'] }
[profile.release]
debug-assertions = true
[features]
# Enable implementations of the `GlobalAlloc` standard library API, exporting a
# new `GlobalDlmalloc` as well which implements this trait.
global = ["system", "rust_api"]
# Enable very expensive debug checks in this crate
debug = []
# Enables OS APIs based on the current target, can be implemented manually
# otherwise.
system = ["libc"]
rustc-dep-of-std = ['core', 'compiler_builtins/rustc-dep-of-std']
c_api = []
rust_api = []
default = ["global", "rust_api"]
+201
View File
@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
+25
View File
@@ -0,0 +1,25 @@
Copyright (c) 2014 Alex Crichton
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
+40
View File
@@ -0,0 +1,40 @@
# dlmalloc-rs
A port of [dlmalloc] to Rust.
[Documentation](https://docs.rs/dlmalloc)
[dlmalloc]: https://gee.cs.oswego.edu/dl/html/malloc.html
## Why dlmalloc?
This crate is a port of [dlmalloc] to Rust, and doesn't rely on C. The primary
purpose of this crate is to serve as the default allocator for Rust on the
`wasm32-unknown-unknown` target. At the time this was written the wasm target
didn't support C code, so it was required to have a Rust-only solution.
This allocator is not the most performant by a longshot. It is primarily, I
think, intended for being easy to port and easy to learn. I didn't dive too deep
into the implementation when writing it, it's just a straight port of the C
version.
It's unlikely that Rust code needs to worry/interact with this allocator in
general. Most of the time you'll be manually switching to a different allocator
:)
# License
This project is licensed under either of
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or
http://opensource.org/licenses/MIT)
at your option.
### Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in this project by you, as defined in the Apache-2.0 license,
shall be dual licensed as above, without any additional terms or conditions.
+2
View File
@@ -0,0 +1,2 @@
corpus
artifacts
+19
View File
@@ -0,0 +1,19 @@
[package]
name = "dlmalloc-fuzz"
version = "0.0.1"
publish = false
edition.workspace = true
[package.metadata]
cargo-fuzz = true
[dependencies]
arbitrary = "1.3.2"
dlmalloc = { path = '..' }
libfuzzer-sys = "0.4.7"
[[bin]]
name = "alloc"
path = "fuzz_targets/alloc.rs"
test = false
bench = false
+8
View File
@@ -0,0 +1,8 @@
#![no_main]
use arbitrary::Unstructured;
use libfuzzer_sys::fuzz_target;
fuzz_target!(|bytes: &[u8]| {
let _ = dlmalloc_fuzz::run(&mut Unstructured::new(bytes));
});
+108
View File
@@ -0,0 +1,108 @@
use arbitrary::{Result, Unstructured};
use dlmalloc::Dlmalloc;
use std::cmp;
const MAX_ALLOCATED: usize = 100 << 20; // 100 MB
pub fn run(u: &mut Unstructured<'_>) -> Result<()> {
let mut a = Dlmalloc::new();
let mut ptrs = Vec::new();
let mut allocated = 0;
unsafe {
while u.arbitrary()? {
// If there are pointers to free then have a chance of deallocating
// a pointer. Try not to deallocate things until there's a "large"
// working set but afterwards give it a 50/50 chance of allocating
// or deallocating.
let free = match ptrs.len() {
0 => false,
0..=10_000 => u.ratio(1, 3)?,
_ => u.arbitrary()?,
};
if free {
let idx = u.choose_index(ptrs.len())?;
let (ptr, size, align) = ptrs.swap_remove(idx);
allocated -= size;
a.free(ptr, size, align);
continue;
}
// 1/100 chance of reallocating a pointer to a different size.
if ptrs.len() > 0 && u.ratio(1, 100)? {
let idx = u.choose_index(ptrs.len())?;
let (ptr, size, align) = ptrs.swap_remove(idx);
// Arbitrarily choose whether to make this allocation either
// twice as large or half as small.
let new_size = if u.arbitrary()? {
u.int_in_range(size..=size * 2)?
} else if size > 10 {
u.int_in_range(size / 2..=size)?
} else {
continue;
};
if allocated + new_size - size > MAX_ALLOCATED {
ptrs.push((ptr, size, align));
continue;
}
allocated -= size;
allocated += new_size;
// Perform the `realloc` and assert that all bytes were copied.
let mut tmp = Vec::new();
for i in 0..cmp::min(size, new_size) {
tmp.push(*ptr.offset(i as isize));
}
let ptr = a.realloc(ptr, size, align, new_size);
assert!(!ptr.is_null());
for (i, byte) in tmp.iter().enumerate() {
assert_eq!(*byte, *ptr.offset(i as isize));
}
ptrs.push((ptr, new_size, align));
}
// Aribtrarily choose a size to allocate as well as an alignment.
// Enable small sizes with standard alignment happening a fair bit.
let size = if u.arbitrary()? {
u.int_in_range(1..=128)?
} else {
u.int_in_range(1..=128 * 1024)?
};
let align = if u.ratio(1, 10)? {
1 << u.int_in_range(3..=8)?
} else {
8
};
if size + allocated > MAX_ALLOCATED {
continue;
}
allocated += size;
// Choose arbitrarily between a zero-allocated chunk and a normal
// allocated chunk.
let zero = u.ratio(1, 50)?;
let ptr = if zero {
a.calloc(size, align)
} else {
a.malloc(size, align)
};
for i in 0..size {
if zero {
assert_eq!(*ptr.offset(i as isize), 0);
}
*ptr.offset(i as isize) = 0xce;
}
ptrs.push((ptr, size, align));
}
// Deallocate everythign when we're done.
for (ptr, size, align) in ptrs {
a.free(ptr, size, align);
}
a.destroy();
}
Ok(())
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+42
View File
@@ -0,0 +1,42 @@
use crate::Allocator;
use core::ptr;
pub struct System {
_priv: (),
}
impl System {
pub const fn new() -> System {
System { _priv: () }
}
}
unsafe impl Allocator for System {
fn alloc(&self, _size: usize) -> (*mut u8, usize, u32) {
(ptr::null_mut(), 0, 0)
}
fn remap(&self, _ptr: *mut u8, _oldsize: usize, _newsize: usize, _can_move: bool) -> *mut u8 {
ptr::null_mut()
}
fn free_part(&self, _ptr: *mut u8, _oldsize: usize, _newsize: usize) -> bool {
false
}
fn free(&self, _ptr: *mut u8, _size: usize) -> bool {
false
}
fn can_release_part(&self, _flags: u32) -> bool {
false
}
fn allocates_zeros(&self) -> bool {
false
}
fn page_size(&self) -> usize {
1
}
}
+56
View File
@@ -0,0 +1,56 @@
use crate::Dlmalloc;
use core::alloc::{GlobalAlloc, Layout};
use core::ptr;
pub use crate::sys::enable_alloc_after_fork;
/// An instance of a "global allocator" backed by `Dlmalloc`
///
/// This API requires the `global` feature is activated, and this type
/// implements the `GlobalAlloc` trait in the standard library.
pub struct GlobalDlmalloc;
static mut DLMALLOC: Dlmalloc = Dlmalloc::new();
unsafe impl GlobalAlloc for GlobalDlmalloc {
#[inline]
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
let _guard = lock();
let dlmalloc = ptr::addr_of_mut!(DLMALLOC);
(*dlmalloc).malloc(layout.size(), layout.align())
}
#[inline]
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
let _guard = lock();
let dlmalloc = ptr::addr_of_mut!(DLMALLOC);
(*dlmalloc).free(ptr, layout.size(), layout.align())
}
#[inline]
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
let _guard = lock();
let dlmalloc = ptr::addr_of_mut!(DLMALLOC);
(*dlmalloc).calloc(layout.size(), layout.align())
}
#[inline]
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
let _guard = lock();
let dlmalloc = ptr::addr_of_mut!(DLMALLOC);
(*dlmalloc).realloc(ptr, layout.size(), layout.align(), new_size)
}
}
unsafe fn lock() -> impl Drop {
crate::sys::acquire_global_lock();
struct Guard;
impl Drop for Guard {
fn drop(&mut self) {
crate::sys::release_global_lock()
}
}
Guard
}
+230
View File
@@ -0,0 +1,230 @@
//! A Rust port of the `dlmalloc` allocator.
//!
//! The `dlmalloc` allocator is described at
//! <https://gee.cs.oswego.edu/dl/html/malloc.html> and this Rust crate is a straight
//! port of the C code for the allocator into Rust. The implementation is
//! wrapped up in a `Dlmalloc` type and has support for Linux, OSX, and Wasm
//! currently.
//!
//! The primary purpose of this crate is that it serves as the default memory
//! allocator for the `wasm32-unknown-unknown` target in the standard library.
//! Support for other platforms is largely untested and unused, but is used when
//! testing this crate.
#![allow(dead_code)]
#![no_std]
#![deny(missing_docs)]
#[cfg(feature = "rust_api")]
use core::{cmp, ptr};
#[cfg(feature = "system")]
use sys::System;
#[cfg(feature = "global")]
pub use self::global::{enable_alloc_after_fork, GlobalDlmalloc};
mod dlmalloc;
#[cfg(feature = "c_api")]
pub use dlmalloc::Dlmalloc as DlmallocCApi;
#[cfg(feature = "global")]
mod global;
/// In order for this crate to efficiently manage memory, it needs a way to communicate with the
/// underlying platform. This `Allocator` trait provides an interface for this communication.
pub unsafe trait Allocator: Send {
/// Allocates system memory region of at least `size` bytes
/// Returns a triple of `(base, size, flags)` where `base` is a pointer to the beginning of the
/// allocated memory region. `size` is the actual size of the region while `flags` specifies
/// properties of the allocated region. If `EXTERN_BIT` (bit 0) set in flags, then we did not
/// allocate this segment and so should not try to deallocate or merge with others.
/// This function can return a `std::ptr::null_mut()` when allocation fails (other values of
/// the triple will be ignored).
fn alloc(&self, size: usize) -> (*mut u8, usize, u32);
/// Remaps system memory region at `ptr` with size `oldsize` to a potential new location with
/// size `newsize`. `can_move` indicates if the location is allowed to move to a completely new
/// location, or that it is only allowed to change in size. Returns a pointer to the new
/// location in memory.
/// This function can return a `std::ptr::null_mut()` to signal an error.
fn remap(&self, ptr: *mut u8, oldsize: usize, newsize: usize, can_move: bool) -> *mut u8;
/// Frees a part of a memory chunk. The original memory chunk starts at `ptr` with size `oldsize`
/// and is turned into a memory region starting at the same address but with `newsize` bytes.
/// Returns `true` iff the access memory region could be freed.
fn free_part(&self, ptr: *mut u8, oldsize: usize, newsize: usize) -> bool;
/// Frees an entire memory region. Returns `true` iff the operation succeeded. When `false` is
/// returned, the `dlmalloc` may re-use the location on future allocation requests
fn free(&self, ptr: *mut u8, size: usize) -> bool;
/// Indicates if the system can release a part of memory. For the `flags` argument, see
/// `Allocator::alloc`
fn can_release_part(&self, flags: u32) -> bool;
/// Indicates whether newly allocated regions contain zeros.
fn allocates_zeros(&self) -> bool;
/// Returns the page size. Must be a power of two
fn page_size(&self) -> usize;
}
/// An allocator instance
///
/// Instances of this type are used to allocate blocks of memory. For best
/// results only use one of these. Currently doesn't implement `Drop` to release
/// lingering memory back to the OS. That may happen eventually though!
#[cfg(feature = "rust_api")]
pub struct Dlmalloc<
#[cfg(feature = "system")]
A = System,
#[cfg(not(feature = "system"))]
A,
>(dlmalloc::Dlmalloc<A>);
cfg_if::cfg_if! {
if #[cfg(all(feature = "system", target_family = "wasm"))] {
#[path = "wasm.rs"]
mod sys;
} else if #[cfg(all(feature = "system", target_os = "windows"))] {
#[path = "windows.rs"]
mod sys;
} else if #[cfg(all(feature = "system", target_os = "xous"))] {
#[path = "xous.rs"]
mod sys;
} else if #[cfg(all(feature = "system", any(target_os = "linux", target_os = "macos", target_os = "redox")))] {
#[path = "unix.rs"]
mod sys;
} else {
#[path = "dummy.rs"]
mod sys;
}
}
#[cfg(feature = "system")]
#[cfg(feature = "rust_api")]
impl Dlmalloc<System> {
/// Creates a new instance of an allocator
pub const fn new() -> Dlmalloc<System> {
Dlmalloc(dlmalloc::Dlmalloc::new(System::new()))
}
}
#[cfg(feature = "rust_api")]
impl<A> Dlmalloc<A> {
/// Creates a new instance of an allocator
pub const fn new_with_allocator(sys_allocator: A) -> Dlmalloc<A> {
Dlmalloc(dlmalloc::Dlmalloc::new(sys_allocator))
}
}
#[cfg(feature = "rust_api")]
impl<A: Allocator> Dlmalloc<A> {
/// Allocates `size` bytes with `align` align.
///
/// Returns a null pointer if allocation fails. Returns a valid pointer
/// otherwise.
///
/// Safety and contracts are largely governed by the `GlobalAlloc::alloc`
/// method contracts.
#[inline]
pub unsafe fn malloc(&mut self, size: usize, align: usize) -> *mut u8 {
if align <= self.0.malloc_alignment() {
self.0.malloc(size)
} else {
self.0.memalign(align, size)
}
}
/// Same as `malloc`, except if the allocation succeeds it's guaranteed to
/// point to `size` bytes of zeros.
#[inline]
pub unsafe fn calloc(&mut self, size: usize, align: usize) -> *mut u8 {
let ptr = self.malloc(size, align);
if !ptr.is_null() && self.0.calloc_must_clear(ptr) {
ptr::write_bytes(ptr, 0, size);
}
ptr
}
/// Deallocates a `ptr` with `size` and `align` as the previous request used
/// to allocate it.
///
/// Safety and contracts are largely governed by the `GlobalAlloc::dealloc`
/// method contracts.
#[inline]
pub unsafe fn free(&mut self, ptr: *mut u8, size: usize, align: usize) {
let _ = align;
self.0.validate_size(ptr, size);
self.0.free(ptr)
}
/// Reallocates `ptr`, a previous allocation with `old_size` and
/// `old_align`, to have `new_size` and the same alignment as before.
///
/// Returns a null pointer if the memory couldn't be reallocated, but `ptr`
/// is still valid. Returns a valid pointer and frees `ptr` if the request
/// is satisfied.
///
/// Safety and contracts are largely governed by the `GlobalAlloc::realloc`
/// method contracts.
#[inline]
pub unsafe fn realloc(
&mut self,
ptr: *mut u8,
old_size: usize,
old_align: usize,
new_size: usize,
) -> *mut u8 {
self.0.validate_size(ptr, old_size);
if old_align <= self.0.malloc_alignment() {
self.0.realloc(ptr, new_size)
} else {
let res = self.malloc(new_size, old_align);
if !res.is_null() {
let size = cmp::min(old_size, new_size);
ptr::copy_nonoverlapping(ptr, res, size);
self.free(ptr, old_size, old_align);
}
res
}
}
/// If possible, gives memory back to the system if there is unused memory
/// at the high end of the malloc pool or in unused segments.
///
/// You can call this after freeing large blocks of memory to potentially
/// reduce the system-level memory requirements of a program. However, it
/// cannot guarantee to reduce memory. Under some allocation patterns, some
/// large free blocks of memory will be locked between two used chunks, so
/// they cannot be given back to the system.
///
/// The `pad` argument represents the amount of free trailing space to
/// leave untrimmed. If this argument is zero, only the minimum amount of
/// memory to maintain internal data structures will be left. Non-zero
/// arguments can be supplied to maintain enough trailing space to service
/// future expected allocations without having to re-obtain memory from the
/// system.
///
/// Returns `true` if it actually released any memory, else `false`.
pub unsafe fn trim(&mut self, pad: usize) -> bool {
self.0.trim(pad)
}
/// Releases all allocations in this allocator back to the system,
/// consuming self and preventing further use.
///
/// Returns the number of bytes released to the system.
pub unsafe fn destroy(self) -> usize {
self.0.destroy()
}
/// Get a reference the underlying [`Allocator`] that this `Dlmalloc` was
/// constructed with.
pub fn allocator(&self) -> &A {
self.0.allocator()
}
}
+131
View File
@@ -0,0 +1,131 @@
use crate::Allocator;
use core::ptr;
/// System setting for Linux
pub struct System {
_priv: (),
}
impl System {
pub const fn new() -> System {
System { _priv: () }
}
}
#[cfg(feature = "global")]
static mut LOCK: libc::pthread_mutex_t = libc::PTHREAD_MUTEX_INITIALIZER;
unsafe impl Allocator for System {
fn alloc(&self, size: usize) -> (*mut u8, usize, u32) {
let addr = unsafe {
libc::mmap(
ptr::null_mut(),
size,
libc::PROT_WRITE | libc::PROT_READ,
libc::MAP_ANON | libc::MAP_PRIVATE,
-1,
0,
)
};
if addr == libc::MAP_FAILED {
(ptr::null_mut(), 0, 0)
} else {
(addr.cast(), size, 0)
}
}
#[cfg(target_os = "linux")]
fn remap(&self, ptr: *mut u8, oldsize: usize, newsize: usize, can_move: bool) -> *mut u8 {
let flags = if can_move { libc::MREMAP_MAYMOVE } else { 0 };
let ptr = unsafe { libc::mremap(ptr.cast(), oldsize, newsize, flags) };
if ptr == libc::MAP_FAILED {
ptr::null_mut()
} else {
ptr.cast()
}
}
#[cfg(any(target_os = "redox", target_os = "macos"))]
fn remap(&self, _ptr: *mut u8, _oldsize: usize, _newsize: usize, _can_move: bool) -> *mut u8 {
ptr::null_mut()
}
#[cfg(target_os = "linux")]
fn free_part(&self, ptr: *mut u8, oldsize: usize, newsize: usize) -> bool {
unsafe {
let rc = libc::mremap(ptr.cast(), oldsize, newsize, 0);
if rc != libc::MAP_FAILED {
return true;
}
libc::munmap(ptr.add(newsize).cast(), oldsize - newsize) == 0
}
}
#[cfg(any(target_os = "redox", target_os = "macos"))]
fn free_part(&self, ptr: *mut u8, oldsize: usize, newsize: usize) -> bool {
unsafe { libc::munmap(ptr.add(newsize).cast(), oldsize - newsize) == 0 }
}
fn free(&self, ptr: *mut u8, size: usize) -> bool {
unsafe { libc::munmap(ptr.cast(), size) == 0 }
}
fn can_release_part(&self, _flags: u32) -> bool {
true
}
fn allocates_zeros(&self) -> bool {
true
}
fn page_size(&self) -> usize {
4096
}
}
#[cfg(feature = "global")]
pub fn acquire_global_lock() {
unsafe { assert_eq!(libc::pthread_mutex_lock(ptr::addr_of_mut!(LOCK)), 0) }
}
#[cfg(feature = "global")]
pub fn release_global_lock() {
unsafe { assert_eq!(libc::pthread_mutex_unlock(ptr::addr_of_mut!(LOCK)), 0) }
}
#[cfg(feature = "global")]
/// allows the allocator to remain unsable in the child process,
/// after a call to `fork(2)`
///
/// #Safety
///
/// if used, this function must be called,
/// before any allocations are made with the global allocator.
pub unsafe fn enable_alloc_after_fork() {
// atfork must only be called once, to avoid a deadlock,
// where the handler attempts to acquire the global lock twice
static mut FORK_PROTECTED: bool = false;
unsafe extern "C" fn _acquire_global_lock() {
acquire_global_lock()
}
unsafe extern "C" fn _release_global_lock() {
release_global_lock()
}
acquire_global_lock();
// if a process forks,
// it will acquire the lock before any other thread,
// protecting it from deadlock,
// due to the child being created with only the calling thread.
if !FORK_PROTECTED {
libc::pthread_atfork(
Some(_acquire_global_lock),
Some(_release_global_lock),
Some(_release_global_lock),
);
FORK_PROTECTED = true;
}
release_global_lock();
}
+76
View File
@@ -0,0 +1,76 @@
use crate::Allocator;
#[cfg(target_arch = "wasm32")]
use core::arch::wasm32 as wasm;
#[cfg(target_arch = "wasm64")]
use core::arch::wasm64 as wasm;
use core::ptr;
/// System setting for Wasm
pub struct System {
_priv: (),
}
impl System {
pub const fn new() -> System {
System { _priv: () }
}
}
unsafe impl Allocator for System {
fn alloc(&self, size: usize) -> (*mut u8, usize, u32) {
let pages = size / self.page_size();
let prev = wasm::memory_grow(0, pages);
if prev == usize::max_value() {
return (ptr::null_mut(), 0, 0);
}
(
(prev * self.page_size()) as *mut u8,
pages * self.page_size(),
0,
)
}
fn remap(&self, _ptr: *mut u8, _oldsize: usize, _newsize: usize, _can_move: bool) -> *mut u8 {
// TODO: I think this can be implemented near the end?
ptr::null_mut()
}
fn free_part(&self, _ptr: *mut u8, _oldsize: usize, _newsize: usize) -> bool {
false
}
fn free(&self, _ptr: *mut u8, _size: usize) -> bool {
false
}
fn can_release_part(&self, _flags: u32) -> bool {
false
}
fn allocates_zeros(&self) -> bool {
true
}
fn page_size(&self) -> usize {
64 * 1024
}
}
#[cfg(feature = "global")]
pub fn acquire_global_lock() {
// single threaded, no need!
assert!(!cfg!(target_feature = "atomics"));
}
#[cfg(feature = "global")]
pub fn release_global_lock() {
// single threaded, no need!
assert!(!cfg!(target_feature = "atomics"));
}
#[allow(missing_docs)]
#[cfg(feature = "global")]
pub unsafe fn enable_alloc_after_fork() {
// single threaded, no need!
assert!(!cfg!(target_feature = "atomics"));
}
+88
View File
@@ -0,0 +1,88 @@
use crate::Allocator;
use core::mem::MaybeUninit;
use core::ptr;
use windows_sys::Win32::System::Memory::*;
use windows_sys::Win32::System::SystemInformation::*;
#[cfg(feature = "global")]
use windows_sys::Win32::System::Threading::*;
pub struct System {
_priv: (),
}
impl System {
pub const fn new() -> System {
System { _priv: () }
}
}
unsafe impl Allocator for System {
fn alloc(&self, size: usize) -> (*mut u8, usize, u32) {
let addr = unsafe {
VirtualAlloc(
ptr::null_mut(),
size,
MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE,
)
};
if addr.is_null() {
(ptr::null_mut(), 0, 0)
} else {
(addr.cast(), size, 0)
}
}
fn remap(&self, _ptr: *mut u8, _oldsize: usize, _newsize: usize, _can_move: bool) -> *mut u8 {
ptr::null_mut()
}
fn free_part(&self, ptr: *mut u8, oldsize: usize, newsize: usize) -> bool {
unsafe { VirtualFree(ptr.add(newsize).cast(), oldsize - newsize, MEM_DECOMMIT) != 0 }
}
fn free(&self, ptr: *mut u8, _size: usize) -> bool {
unsafe { VirtualFree(ptr.cast(), 0, MEM_DECOMMIT) != 0 }
}
fn can_release_part(&self, _flags: u32) -> bool {
true
}
fn allocates_zeros(&self) -> bool {
true
}
fn page_size(&self) -> usize {
unsafe {
let mut info = MaybeUninit::uninit();
GetSystemInfo(info.as_mut_ptr());
info.assume_init_ref().dwPageSize as usize
}
}
}
// NB: `SRWLOCK_INIT` doesn't appear to be in `windows-sys`
#[cfg(feature = "global")]
static mut LOCK: SRWLOCK = SRWLOCK {
Ptr: ptr::null_mut(),
};
#[cfg(feature = "global")]
pub fn acquire_global_lock() {
unsafe {
AcquireSRWLockExclusive(ptr::addr_of_mut!(LOCK));
}
}
#[cfg(feature = "global")]
pub fn release_global_lock() {
unsafe {
ReleaseSRWLockExclusive(ptr::addr_of_mut!(LOCK));
}
}
/// Not needed on Windows
#[cfg(feature = "global")]
pub unsafe fn enable_alloc_after_fork() {}
+117
View File
@@ -0,0 +1,117 @@
use crate::Allocator;
use core::ptr;
pub struct System {
_priv: (),
}
impl System {
pub const fn new() -> System {
System { _priv: () }
}
}
#[cfg(target_arch = "riscv32")]
mod sys {
use core::arch::asm;
pub fn increase_heap(length: usize) -> Result<(usize, usize), ()> {
let syscall_no_increase_heap = 10usize;
let memory_flags_read_write = 2usize | 4usize;
let mut a0 = syscall_no_increase_heap;
let mut a1 = length;
let mut a2 = memory_flags_read_write;
unsafe {
asm!(
"ecall",
inlateout("a0") a0,
inlateout("a1") a1,
inlateout("a2") a2,
out("a3") _,
out("a4") _,
out("a5") _,
out("a6") _,
out("a7") _,
)
};
let result = a0;
let address = a1;
let length = a2;
// 3 is the "MemoryRange" type, and the result is only valid
// if we get nonzero address and length.
if result == 3 && address != 0 && length != 0 {
Ok((address, length))
} else {
Err(())
}
}
}
unsafe impl Allocator for System {
/// Allocate an additional `size` bytes on the heap, and return a new
/// chunk of memory, as well as the size of the allocation and some
/// flags. Since flags are unused on this platform, they will always
/// be `0`.
fn alloc(&self, size: usize) -> (*mut u8, usize, u32) {
let size = if size == 0 {
4096
} else if size & 4095 == 0 {
size
} else {
size + (4096 - (size & 4095))
};
if let Ok((address, length)) = sys::increase_heap(size) {
let start = address - size + length;
(start as *mut u8, size, 0)
} else {
(ptr::null_mut(), 0, 0)
}
}
fn remap(&self, _ptr: *mut u8, _oldsize: usize, _newsize: usize, _can_move: bool) -> *mut u8 {
// TODO
ptr::null_mut()
}
fn free_part(&self, _ptr: *mut u8, _oldsize: usize, _newsize: usize) -> bool {
false
}
fn free(&self, _ptr: *mut u8, _size: usize) -> bool {
false
}
fn can_release_part(&self, _flags: u32) -> bool {
false
}
fn allocates_zeros(&self) -> bool {
true
}
fn page_size(&self) -> usize {
4 * 1024
}
}
#[cfg(feature = "global")]
pub fn acquire_global_lock() {
// global feature should not be enabled
unimplemented!()
}
#[cfg(feature = "global")]
pub fn release_global_lock() {
// global feature should not be enabled
unimplemented!()
}
#[cfg(feature = "global")]
pub unsafe fn enable_alloc_after_fork() {
// platform does not support `fork()` call
}
+32
View File
@@ -0,0 +1,32 @@
extern crate dlmalloc;
use std::collections::HashMap;
use std::thread;
#[global_allocator]
#[cfg(feature = "global")]
static A: dlmalloc::GlobalDlmalloc = dlmalloc::GlobalDlmalloc;
#[test]
fn foo() {
println!("hello");
}
#[test]
fn map() {
let mut m = HashMap::new();
m.insert(1, 2);
m.insert(5, 3);
drop(m);
}
#[test]
fn strings() {
format!("foo, bar, {}", "baz");
}
#[test]
#[cfg(not(target_family = "wasm"))]
fn threads() {
assert!(thread::spawn(|| panic!()).join().is_err());
}
+36
View File
@@ -0,0 +1,36 @@
use arbitrary::Unstructured;
use dlmalloc::Dlmalloc;
use rand::{rngs::SmallRng, RngCore, SeedableRng};
#[test]
fn smoke() {
let mut a = Dlmalloc::new();
unsafe {
let ptr = a.malloc(1, 1);
assert!(!ptr.is_null());
*ptr = 9;
assert_eq!(*ptr, 9);
a.free(ptr, 1, 1);
let ptr = a.malloc(1, 1);
assert!(!ptr.is_null());
*ptr = 10;
assert_eq!(*ptr, 10);
a.free(ptr, 1, 1);
}
}
#[path = "../fuzz/src/lib.rs"]
mod fuzz;
#[test]
fn stress() {
let mut rng = SmallRng::seed_from_u64(0);
let mut buf = vec![0; 4096];
let iters = if cfg!(miri) { 5 } else { 2000 };
for _ in 0..iters {
rng.fill_bytes(&mut buf);
let mut u = Unstructured::new(&buf);
let _ = fuzz::run(&mut u);
}
}
Executable
+3
View File
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
cargo fmt --package relibc --package crt0 --package redox-rt "$@"
+7
View File
@@ -0,0 +1,7 @@
[package]
name = "generic-rt"
version = "0.1.0"
edition = "2024"
[lints]
workspace = true
+133
View File
@@ -0,0 +1,133 @@
#![no_std]
#![allow(internal_features)]
#![feature(core_intrinsics)]
#![deny(unsafe_op_in_unsafe_fn)]
use core::{
arch::asm,
mem::{self, offset_of},
};
#[derive(Debug)]
#[repr(C)]
pub struct GenericTcb<Os> {
/// Pointer to the end of static TLS. Must be the first member
pub tls_end: *mut u8,
/// Size of the memory allocated for the static TLS in bytes (multiple of page size)
pub tls_len: usize,
/// Pointer to this structure
pub tcb_ptr: *mut Self,
/// Size of the memory allocated for this structure in bytes (should be same as page size)
pub tcb_len: usize,
pub os_specific: Os,
}
impl<Os> GenericTcb<Os> {
/// Architecture specific code to read a usize from the TCB - aarch64
#[allow(unsafe_op_in_unsafe_fn)]
#[inline(always)]
#[cfg(target_arch = "aarch64")]
pub unsafe fn arch_read(offset: usize) -> usize {
let abi_ptr: usize;
asm!(
"mrs {}, tpidr_el0",
out(reg) abi_ptr,
);
let tcb_ptr = *(abi_ptr as *const usize);
*((tcb_ptr + offset) as *const usize)
}
/// Architecture specific code to read a usize from the TCB - x86
#[allow(unsafe_op_in_unsafe_fn)]
#[inline(always)]
#[cfg(target_arch = "x86")]
pub unsafe fn arch_read(offset: usize) -> usize {
let value;
asm!(
"
mov {}, gs:[{}]
",
out(reg) value,
in(reg) offset,
);
value
}
/// Architecture specific code to read a usize from the TCB - x86_64
#[allow(unsafe_op_in_unsafe_fn)]
#[inline(always)]
#[cfg(target_arch = "x86_64")]
pub unsafe fn arch_read(offset: usize) -> usize {
let value;
asm!(
"
mov {}, fs:[{}]
",
out(reg) value,
in(reg) offset,
);
value
}
/// Architecture specific code to read a usize from the TCB - riscv64
#[allow(unsafe_op_in_unsafe_fn)]
#[inline(always)]
#[cfg(target_arch = "riscv64")]
unsafe fn arch_read(offset: usize) -> usize {
let value;
asm!(
"ld {value}, -8(tp)", // TCB
"add {value}, {value}, {offset}",
"ld {value}, 0({value})",
value = out(reg) value,
offset = in(reg) offset,
);
value
}
pub unsafe fn current_ptr() -> Option<*mut Self> {
let tcb_ptr = unsafe { Self::arch_read(offset_of!(Self, tcb_ptr)) as *mut Self };
let tcb_len = unsafe { Self::arch_read(offset_of!(Self, tcb_len)) };
if tcb_ptr.is_null() || tcb_len < mem::size_of::<Self>() {
None
} else {
Some(tcb_ptr)
}
}
pub unsafe fn current() -> Option<&'static mut Self> {
unsafe { Some(&mut *Self::current_ptr()?) }
}
}
pub fn panic_notls(_msg: impl core::fmt::Display) -> ! {
// TODO: actually print _msg, perhaps by having panic_notls take a `T: DebugBackend` that can
// propagate until called by e.g. relibc start
core::intrinsics::abort();
}
pub trait ExpectTlsFree {
type Unwrapped;
fn expect_notls(self, msg: &str) -> Self::Unwrapped;
}
impl<T, E: core::fmt::Debug> ExpectTlsFree for Result<T, E> {
type Unwrapped = T;
fn expect_notls(self, msg: &str) -> T {
match self {
Ok(t) => t,
Err(err) => panic_notls(format_args!(
"{msg}: expect failed for Result with err: {err:?}",
)),
}
}
}
impl<T> ExpectTlsFree for Option<T> {
type Unwrapped = T;
fn expect_notls(self, msg: &str) -> T {
match self {
Some(t) => t,
None => panic_notls(format_args!("{msg}: expect failed for Option")),
}
}
}
+6
View File
@@ -0,0 +1,6 @@
#ifndef _ALLOCA_H
#define _ALLOCA_H
#define alloca(size) __builtin_alloca (size)
#endif /* _ALLOCA_H */
+1
View File
@@ -0,0 +1 @@
#include <openlibm_complex.h>
+95
View File
@@ -0,0 +1,95 @@
/*
* MIT License
* Copyright (c) 2020 Rich Felker musl-libc
*/
#ifndef _FEATURES_H__RELIBC
#define _FEATURES_H__RELIBC
// Version metadata for feature gating
// This is useful for divergent implementation specific behavior
// glibc, ulibc, and likely others define a similar macro
// musl does not define an equivalent macro
#define __RELIBC__ 1
#define __RELIBC__MAJOR 0
#define __RELIBC__MINOR 2
/*
* Sources:
* https://en.cppreference.com/w/c/language/attributes
* https://clang.llvm.org/docs/LanguageExtensions.html
* https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fc_005fattribute.html
* https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html
*/
// Clang doesn't define __has_cpp_attribute if compiling C code
#if !defined(__has_cpp_attribute)
#define __has_cpp_attribute(x) 0
#endif
// Clang doesn't define __has_c_attribute if compiling C++ code
#if !defined(__has_c_attribute)
#define __has_c_attribute(x) 0
#endif
// Check if C23+ attributes are available
#if defined(__cplusplus)
// HACK: GCC backports C++ attributes to C++98 but doesn't accept attributes
// placed before the function like cbindgen emits.
// Let's just disable attributes for C++98 by checking if a random C++11
// feature is available.
#define __HAS_ATTRIBUTE(x) __cpp_variable_templates &&__has_cpp_attribute(x)
#else
#define __HAS_ATTRIBUTE(x) \
(__has_c_attribute(x) || __STDC_VERSION__ >= 202311L || \
__has_cpp_attribute(x))
#endif
// TODO: Not emitted with cbindgen
#if __STDC_VERSION__ >= 199901L
#define __restrict restrict
#elif !defined(__GNUC__)
#define __restrict
#endif
// TODO: Not emitted with cbindgen
#if __STDC_VERSION__ >= 199901L || defined(__cplusplus)
#define __inline inline
#elif !defined(__GNUC__)
#define __inline
#endif
// Analogous to Rust's Never type
//TODO: clang fails to compile C with [[noreturn]]
#if defined(__cplusplus) && __HAS_ATTRIBUTE(noreturn) && !(__clang__)
#define __noreturn [[noreturn]]
// #elif __STDC_VERSION__ >= 201112L
// FIXME: cbindgen incorrectly places _Noreturn
// #define __noreturn _Noreturn
#elif defined(__GNUC__)
#define __noreturn __attribute__((__noreturn__))
#else
#define __noreturn
#endif
// Analogous to Rust's #[must_use]
// C23 only
#if __HAS_ATTRIBUTE(nodiscard)
#define __nodiscard [[nodiscard]]
#define __nodiscardNote(x) [[nodiscard(x)]]
#else
#define __nodiscard
#define __nodiscardNote(x)
#endif
// Analogous to Rust's #[deprecated]
// C23 only
#if __HAS_ATTRIBUTE(deprecated)
#define __deprecated [[deprecated]]
#define __deprecatedNote(x) [[deprecated(x)]]
#else
#define __deprecated
#define __deprecatedNote(x)
#endif
#endif
+3
View File
@@ -0,0 +1,3 @@
#include <openlibm_fenv.h>
#undef complex
#undef I
+22
View File
@@ -0,0 +1,22 @@
// Copied from musl
#ifndef _ISO646_H
#define _ISO646_H
#ifndef __cplusplus
#define and &&
#define and_eq &=
#define bitand &
#define bitor |
#define compl ~
#define not !
#define not_eq !=
#define or ||
#define or_eq |=
#define xor ^
#define xor_eq ^=
#endif
#endif
+17
View File
@@ -0,0 +1,17 @@
#ifndef __MACHINE_ENDIAN_H__
/* TODO: Forcing little endian, if you need a big endian system, fix this { */
#ifndef BIG_ENDIAN
#define BIG_ENDIAN 4321
#endif
#ifndef LITTLE_ENDIAN
#define LITTLE_ENDIAN 1234
#endif
#ifndef BYTE_ORDER
#define BYTE_ORDER LITTLE_ENDIAN
#endif
/* } */
#endif /* __MACHINE_ENDIAN_H__ */
+113
View File
@@ -0,0 +1,113 @@
#include <openlibm_math.h>
// Missing typedefs
typedef float float_t;
typedef double double_t;
/* double */
#ifndef M_PI
#define M_PI 3.14159265358979323846 /* pi */
#endif
#ifndef M_PI_2
#define M_PI_2 1.57079632679489661923 /* pi/2 */
#endif
#ifndef M_PI_4
#define M_PI_4 0.78539816339744830962 /* pi/4 */
#endif
#ifndef M_2_PI
#define M_2_PI 0.63661977236758134308 /* 2/pi */
#endif
#ifndef M_E
#define M_E 2.7182818284590452354 /* e */
#endif
#ifndef M_LOG2E
#define M_LOG2E 1.4426950408889634074 /* log_2 e */
#endif
#ifndef M_LOG10E
#define M_LOG10E 0.43429448190325182765 /* log_10 e */
#endif
#ifndef M_LN2
#define M_LN2 0.69314718055994530942 /* log_e 2 */
#endif
#ifndef M_LN10
#define M_LN10 2.30258509299404568402 /* log_e 10 */
#endif
#ifndef M_1_PI
#define M_1_PI 0.31830988618379067154 /* 1/pi */
#endif
#ifndef M_2_SQRTPI
#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
#endif
#ifndef M_SQRT2
#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
#endif
#ifndef M_SQRT1_2
#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
#endif
/* long double */
#ifndef M_El
#define M_El 2.718281828459045235360287471352662498L /* e */
#endif
#ifndef M_LOG2El
#define M_LOG2El 1.442695040888963407359924681001892137L /* log_2 e */
#endif
#ifndef M_LOG10El
#define M_LOG10El 0.434294481903251827651128918916605082L /* log_10 e */
#endif
#ifndef M_LN2l
#define M_LN2l 0.693147180559945309417232121458176568L /* log_e 2 */
#endif
#ifndef M_LN10l
#define M_LN10l 2.302585092994045684017991454684364208L /* log_e 10 */
#endif
#ifndef M_PIl
#define M_PIl 3.141592653589793238462643383279502884L /* pi */
#endif
#ifndef M_PI_2l
#define M_PI_2l 1.570796326794896619231321691639751442L /* pi/2 */
#endif
#ifndef M_PI_4l
#define M_PI_4l 0.785398163397448309615660845819875721L /* pi/4 */
#endif
#ifndef M_1_PIl
#define M_1_PIl 0.318309886183790671537767526745028724L /* 1/pi */
#endif
#ifndef M_2_PIl
#define M_2_PIl 0.636619772367581343075535053490057448L /* 2/pi */
#endif
#ifndef M_2_SQRTPIl
#define M_2_SQRTPIl 1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
#endif
#ifndef M_SQRT2l
#define M_SQRT2l 1.414213562373095048801688724209698079L /* sqrt(2) */
#endif
#ifndef M_SQRT1_2l
#define M_SQRT1_2l 0.707106781186547524400844362104849039L /* 1/sqrt(2) */
#endif
+1
View File
@@ -0,0 +1 @@
#include <string.h>
+10
View File
@@ -0,0 +1,10 @@
#ifndef _NETINET_IN_SYSTM_H
#define _NETINET_IN_SYSTM_H
#include <stdint.h>
typedef uint16_t n_short;
typedef uint32_t n_long;
typedef uint32_t n_time;
#endif
+6
View File
@@ -0,0 +1,6 @@
#ifndef _RELIBC_PATHS_H
#define _RELIBC_PATHS_H
#define _PATH_BSHELL "/bin/sh"
#endif
+81
View File
@@ -0,0 +1,81 @@
#ifndef _SETJMP_H
#define _SETJMP_H
#ifdef __aarch64__
typedef unsigned long jmp_buf[22];
#endif
#ifdef __arm__
typedef unsigned long long jmp_buf[32];
#endif
#ifdef __i386__
typedef unsigned long jmp_buf[6];
#endif
#ifdef __m68k__
typedef unsigned long jmp_buf[39];
#endif
#ifdef __microblaze__
typedef unsigned long jmp_buf[18];
#endif
#ifdef __mips__
typedef unsigned long long jmp_buf[13];
#endif
#ifdef __mips64__
typedef unsigned long long jmp_buf[23];
#endif
#ifdef __mipsn32__
typedef unsigned long long jmp_buf[23];
#endif
#ifdef __or1k__
typedef unsigned long jmp_buf[13];
#endif
#ifdef __powerpc__
typedef unsigned long long jmp_buf[56];
#endif
#ifdef __powerpc64__
typedef uint128_t jmp_buf[32];
#endif
#ifdef __s390x__
typedef unsigned long jmp_buf[18];
#endif
#ifdef __sh__
typedef unsigned long jmp_buf[15];
#endif
#ifdef __x32__
typedef unsigned long long jmp_buf[8];
#endif
#ifdef __x86_64__
typedef unsigned long jmp_buf[16];
#endif
#ifdef __riscv
typedef unsigned long jmp_buf[26];
#endif
typedef jmp_buf sigjmp_buf;
#ifdef __cplusplus
extern "C" {
#endif
int setjmp(jmp_buf buf);
void longjmp(jmp_buf buf, int value);
#ifdef __cplusplus
} // extern "C"
#endif
#endif /* _SETJMP_H */
+10
View File
@@ -0,0 +1,10 @@
#ifndef _STDARG_H
#define _STDARG_H
typedef __builtin_va_list va_list;
#define va_start(v,l) __builtin_va_start(v,l)
#define va_end(v) __builtin_va_end(v)
#define va_arg(v,l) __builtin_va_arg(v,l)
#define va_copy(d,s) __builtin_va_copy(d,s)
#endif /* _STDARG_H */
+243
View File
@@ -0,0 +1,243 @@
/* Copyright (C) 2013-2022 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.
You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
/* ISO C11 Standard: 7.17 Atomics <stdatomic.h>. */
#ifndef _STDATOMIC_H
#define _STDATOMIC_H
typedef enum
{
memory_order_relaxed = __ATOMIC_RELAXED,
memory_order_consume = __ATOMIC_CONSUME,
memory_order_acquire = __ATOMIC_ACQUIRE,
memory_order_release = __ATOMIC_RELEASE,
memory_order_acq_rel = __ATOMIC_ACQ_REL,
memory_order_seq_cst = __ATOMIC_SEQ_CST
} memory_order;
typedef _Atomic _Bool atomic_bool;
typedef _Atomic char atomic_char;
typedef _Atomic signed char atomic_schar;
typedef _Atomic unsigned char atomic_uchar;
typedef _Atomic short atomic_short;
typedef _Atomic unsigned short atomic_ushort;
typedef _Atomic int atomic_int;
typedef _Atomic unsigned int atomic_uint;
typedef _Atomic long atomic_long;
typedef _Atomic unsigned long atomic_ulong;
typedef _Atomic long long atomic_llong;
typedef _Atomic unsigned long long atomic_ullong;
typedef _Atomic __CHAR16_TYPE__ atomic_char16_t;
typedef _Atomic __CHAR32_TYPE__ atomic_char32_t;
typedef _Atomic __WCHAR_TYPE__ atomic_wchar_t;
typedef _Atomic __INT_LEAST8_TYPE__ atomic_int_least8_t;
typedef _Atomic __UINT_LEAST8_TYPE__ atomic_uint_least8_t;
typedef _Atomic __INT_LEAST16_TYPE__ atomic_int_least16_t;
typedef _Atomic __UINT_LEAST16_TYPE__ atomic_uint_least16_t;
typedef _Atomic __INT_LEAST32_TYPE__ atomic_int_least32_t;
typedef _Atomic __UINT_LEAST32_TYPE__ atomic_uint_least32_t;
typedef _Atomic __INT_LEAST64_TYPE__ atomic_int_least64_t;
typedef _Atomic __UINT_LEAST64_TYPE__ atomic_uint_least64_t;
typedef _Atomic __INT_FAST8_TYPE__ atomic_int_fast8_t;
typedef _Atomic __UINT_FAST8_TYPE__ atomic_uint_fast8_t;
typedef _Atomic __INT_FAST16_TYPE__ atomic_int_fast16_t;
typedef _Atomic __UINT_FAST16_TYPE__ atomic_uint_fast16_t;
typedef _Atomic __INT_FAST32_TYPE__ atomic_int_fast32_t;
typedef _Atomic __UINT_FAST32_TYPE__ atomic_uint_fast32_t;
typedef _Atomic __INT_FAST64_TYPE__ atomic_int_fast64_t;
typedef _Atomic __UINT_FAST64_TYPE__ atomic_uint_fast64_t;
typedef _Atomic __INTPTR_TYPE__ atomic_intptr_t;
typedef _Atomic __UINTPTR_TYPE__ atomic_uintptr_t;
typedef _Atomic __SIZE_TYPE__ atomic_size_t;
typedef _Atomic __PTRDIFF_TYPE__ atomic_ptrdiff_t;
typedef _Atomic __INTMAX_TYPE__ atomic_intmax_t;
typedef _Atomic __UINTMAX_TYPE__ atomic_uintmax_t;
#define ATOMIC_VAR_INIT(VALUE) (VALUE)
/* Initialize an atomic object pointed to by PTR with VAL. */
#define atomic_init(PTR, VAL) \
atomic_store_explicit (PTR, VAL, __ATOMIC_RELAXED)
#define kill_dependency(Y) \
__extension__ \
({ \
__auto_type __kill_dependency_tmp = (Y); \
__kill_dependency_tmp; \
})
extern void atomic_thread_fence (memory_order);
#define atomic_thread_fence(MO) __atomic_thread_fence (MO)
extern void atomic_signal_fence (memory_order);
#define atomic_signal_fence(MO) __atomic_signal_fence (MO)
#define atomic_is_lock_free(OBJ) __atomic_is_lock_free (sizeof (*(OBJ)), (OBJ))
#define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE
#define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE
#define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE
#define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE
#define ATOMIC_WCHAR_T_LOCK_FREE __GCC_ATOMIC_WCHAR_T_LOCK_FREE
#define ATOMIC_SHORT_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE
#define ATOMIC_INT_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE
#define ATOMIC_LONG_LOCK_FREE __GCC_ATOMIC_LONG_LOCK_FREE
#define ATOMIC_LLONG_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE
#define ATOMIC_POINTER_LOCK_FREE __GCC_ATOMIC_POINTER_LOCK_FREE
/* Note that these macros require __auto_type to remove
_Atomic qualifiers (and const qualifiers, if those are valid on
macro operands).
Also note that the header file uses the generic form of __atomic
builtins, which requires the address to be taken of the value
parameter, and then we pass that value on. This allows the macros
to work for any type, and the compiler is smart enough to convert
these to lock-free _N variants if possible, and throw away the
temps. */
#define atomic_store_explicit(PTR, VAL, MO) \
__extension__ \
({ \
__auto_type __atomic_store_ptr = (PTR); \
__typeof__ ((void)0, *__atomic_store_ptr) __atomic_store_tmp = (VAL); \
__atomic_store (__atomic_store_ptr, &__atomic_store_tmp, (MO)); \
})
#define atomic_store(PTR, VAL) \
atomic_store_explicit (PTR, VAL, __ATOMIC_SEQ_CST)
#define atomic_load_explicit(PTR, MO) \
__extension__ \
({ \
__auto_type __atomic_load_ptr = (PTR); \
__typeof__ ((void)0, *__atomic_load_ptr) __atomic_load_tmp; \
__atomic_load (__atomic_load_ptr, &__atomic_load_tmp, (MO)); \
__atomic_load_tmp; \
})
#define atomic_load(PTR) atomic_load_explicit (PTR, __ATOMIC_SEQ_CST)
#define atomic_exchange_explicit(PTR, VAL, MO) \
__extension__ \
({ \
__auto_type __atomic_exchange_ptr = (PTR); \
__typeof__ ((void)0, *__atomic_exchange_ptr) __atomic_exchange_val = (VAL); \
__typeof__ ((void)0, *__atomic_exchange_ptr) __atomic_exchange_tmp; \
__atomic_exchange (__atomic_exchange_ptr, &__atomic_exchange_val, \
&__atomic_exchange_tmp, (MO)); \
__atomic_exchange_tmp; \
})
#define atomic_exchange(PTR, VAL) \
atomic_exchange_explicit (PTR, VAL, __ATOMIC_SEQ_CST)
#define atomic_compare_exchange_strong_explicit(PTR, VAL, DES, SUC, FAIL) \
__extension__ \
({ \
__auto_type __atomic_compare_exchange_ptr = (PTR); \
__typeof__ ((void)0, *__atomic_compare_exchange_ptr) __atomic_compare_exchange_tmp \
= (DES); \
__atomic_compare_exchange (__atomic_compare_exchange_ptr, (VAL), \
&__atomic_compare_exchange_tmp, 0, \
(SUC), (FAIL)); \
})
#define atomic_compare_exchange_strong(PTR, VAL, DES) \
atomic_compare_exchange_strong_explicit (PTR, VAL, DES, __ATOMIC_SEQ_CST, \
__ATOMIC_SEQ_CST)
#define atomic_compare_exchange_weak_explicit(PTR, VAL, DES, SUC, FAIL) \
__extension__ \
({ \
__auto_type __atomic_compare_exchange_ptr = (PTR); \
__typeof__ ((void)0, *__atomic_compare_exchange_ptr) __atomic_compare_exchange_tmp \
= (DES); \
__atomic_compare_exchange (__atomic_compare_exchange_ptr, (VAL), \
&__atomic_compare_exchange_tmp, 1, \
(SUC), (FAIL)); \
})
#define atomic_compare_exchange_weak(PTR, VAL, DES) \
atomic_compare_exchange_weak_explicit (PTR, VAL, DES, __ATOMIC_SEQ_CST, \
__ATOMIC_SEQ_CST)
#define atomic_fetch_add(PTR, VAL) __atomic_fetch_add ((PTR), (VAL), \
__ATOMIC_SEQ_CST)
#define atomic_fetch_add_explicit(PTR, VAL, MO) \
__atomic_fetch_add ((PTR), (VAL), (MO))
#define atomic_fetch_sub(PTR, VAL) __atomic_fetch_sub ((PTR), (VAL), \
__ATOMIC_SEQ_CST)
#define atomic_fetch_sub_explicit(PTR, VAL, MO) \
__atomic_fetch_sub ((PTR), (VAL), (MO))
#define atomic_fetch_or(PTR, VAL) __atomic_fetch_or ((PTR), (VAL), \
__ATOMIC_SEQ_CST)
#define atomic_fetch_or_explicit(PTR, VAL, MO) \
__atomic_fetch_or ((PTR), (VAL), (MO))
#define atomic_fetch_xor(PTR, VAL) __atomic_fetch_xor ((PTR), (VAL), \
__ATOMIC_SEQ_CST)
#define atomic_fetch_xor_explicit(PTR, VAL, MO) \
__atomic_fetch_xor ((PTR), (VAL), (MO))
#define atomic_fetch_and(PTR, VAL) __atomic_fetch_and ((PTR), (VAL), \
__ATOMIC_SEQ_CST)
#define atomic_fetch_and_explicit(PTR, VAL, MO) \
__atomic_fetch_and ((PTR), (VAL), (MO))
typedef _Atomic struct
{
#if __GCC_ATOMIC_TEST_AND_SET_TRUEVAL == 1
_Bool __val;
#else
unsigned char __val;
#endif
} atomic_flag;
#define ATOMIC_FLAG_INIT { 0 }
extern _Bool atomic_flag_test_and_set (volatile atomic_flag *);
#define atomic_flag_test_and_set(PTR) \
__atomic_test_and_set ((PTR), __ATOMIC_SEQ_CST)
extern _Bool atomic_flag_test_and_set_explicit (volatile atomic_flag *,
memory_order);
#define atomic_flag_test_and_set_explicit(PTR, MO) \
__atomic_test_and_set ((PTR), (MO))
extern void atomic_flag_clear (volatile atomic_flag *);
#define atomic_flag_clear(PTR) __atomic_clear ((PTR), __ATOMIC_SEQ_CST)
extern void atomic_flag_clear_explicit (volatile atomic_flag *, memory_order);
#define atomic_flag_clear_explicit(PTR, MO) __atomic_clear ((PTR), (MO))
#endif /* _STDATOMIC_H */
+19
View File
@@ -0,0 +1,19 @@
#ifndef _STDBOOL_H
#define _STDBOOL_H
#ifndef __cplusplus
#define bool _Bool
#define true 1
#define false 0
#else /* __cplusplus */
#if __cplusplus < 201103L
#define bool bool
#define false false
#define true true
#endif /*__cplusplus < 201103L*/
#endif /* __cplusplus */
#define __bool_true_false_are_defined 1
#endif /* _STDBOOL_H */
+377
View File
@@ -0,0 +1,377 @@
/* Copyright (C) 2008-2018 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.
You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
/*
* ISO C Standard: 7.18 Integer types <stdint.h>
*/
#ifndef _STDINT_H
#define _STDINT_H
/* 7.8.1.1 Exact-width integer types */
#ifdef __INT8_TYPE__
typedef __INT8_TYPE__ int8_t;
#endif
#ifdef __INT16_TYPE__
typedef __INT16_TYPE__ int16_t;
#endif
#ifdef __INT32_TYPE__
typedef __INT32_TYPE__ int32_t;
#endif
#ifdef __INT64_TYPE__
typedef __INT64_TYPE__ int64_t;
#endif
#ifdef __UINT8_TYPE__
typedef __UINT8_TYPE__ uint8_t;
typedef __UINT8_TYPE__ u_int8_t;
#endif
#ifdef __UINT16_TYPE__
typedef __UINT16_TYPE__ uint16_t;
typedef __UINT16_TYPE__ u_int16_t;
#endif
#ifdef __UINT32_TYPE__
typedef __UINT32_TYPE__ uint32_t;
typedef __UINT32_TYPE__ u_int32_t;
// Required by openlibm
typedef __UINT32_TYPE__ __uint32_t;
#endif
#ifdef __UINT64_TYPE__
typedef __UINT64_TYPE__ uint64_t;
typedef __UINT64_TYPE__ u_int64_t;
// Required by openlibm
typedef __UINT64_TYPE__ __uint64_t;
#endif
/* 7.8.1.2 Minimum-width integer types */
typedef __INT_LEAST8_TYPE__ int_least8_t;
typedef __INT_LEAST16_TYPE__ int_least16_t;
typedef __INT_LEAST32_TYPE__ int_least32_t;
typedef __INT_LEAST64_TYPE__ int_least64_t;
typedef __UINT_LEAST8_TYPE__ uint_least8_t;
typedef __UINT_LEAST16_TYPE__ uint_least16_t;
typedef __UINT_LEAST32_TYPE__ uint_least32_t;
typedef __UINT_LEAST64_TYPE__ uint_least64_t;
/* 7.8.1.3 Fastest minimum-width integer types */
typedef __INT_FAST8_TYPE__ int_fast8_t;
typedef __INT_FAST16_TYPE__ int_fast16_t;
typedef __INT_FAST32_TYPE__ int_fast32_t;
typedef __INT_FAST64_TYPE__ int_fast64_t;
typedef __UINT_FAST8_TYPE__ uint_fast8_t;
typedef __UINT_FAST16_TYPE__ uint_fast16_t;
typedef __UINT_FAST32_TYPE__ uint_fast32_t;
typedef __UINT_FAST64_TYPE__ uint_fast64_t;
/* 7.8.1.4 Integer types capable of holding object pointers */
#ifdef __INTPTR_TYPE__
typedef __INTPTR_TYPE__ intptr_t;
#endif
#ifdef __UINTPTR_TYPE__
typedef __UINTPTR_TYPE__ uintptr_t;
#endif
/* 7.8.1.5 Greatest-width integer types */
typedef __INTMAX_TYPE__ intmax_t;
typedef __UINTMAX_TYPE__ uintmax_t;
#if (!defined __cplusplus || __cplusplus >= 201103L \
|| defined __STDC_LIMIT_MACROS)
/* 7.18.2 Limits of specified-width integer types */
#ifdef __INT8_MAX__
# undef INT8_MAX
# define INT8_MAX __INT8_MAX__
# undef INT8_MIN
# define INT8_MIN (-INT8_MAX - 1)
#endif
#ifdef __UINT8_MAX__
# undef UINT8_MAX
# define UINT8_MAX __UINT8_MAX__
#endif
#ifdef __INT16_MAX__
# undef INT16_MAX
# define INT16_MAX __INT16_MAX__
# undef INT16_MIN
# define INT16_MIN (-INT16_MAX - 1)
#endif
#ifdef __UINT16_MAX__
# undef UINT16_MAX
# define UINT16_MAX __UINT16_MAX__
#endif
#ifdef __INT32_MAX__
# undef INT32_MAX
# define INT32_MAX __INT32_MAX__
# undef INT32_MIN
# define INT32_MIN (-INT32_MAX - 1)
#endif
#ifdef __UINT32_MAX__
# undef UINT32_MAX
# define UINT32_MAX __UINT32_MAX__
#endif
#ifdef __INT64_MAX__
# undef INT64_MAX
# define INT64_MAX __INT64_MAX__
# undef INT64_MIN
# define INT64_MIN (-INT64_MAX - 1)
#endif
#ifdef __UINT64_MAX__
# undef UINT64_MAX
# define UINT64_MAX __UINT64_MAX__
#endif
#undef INT_LEAST8_MAX
#define INT_LEAST8_MAX __INT_LEAST8_MAX__
#undef INT_LEAST8_MIN
#define INT_LEAST8_MIN (-INT_LEAST8_MAX - 1)
#undef UINT_LEAST8_MAX
#define UINT_LEAST8_MAX __UINT_LEAST8_MAX__
#undef INT_LEAST16_MAX
#define INT_LEAST16_MAX __INT_LEAST16_MAX__
#undef INT_LEAST16_MIN
#define INT_LEAST16_MIN (-INT_LEAST16_MAX - 1)
#undef UINT_LEAST16_MAX
#define UINT_LEAST16_MAX __UINT_LEAST16_MAX__
#undef INT_LEAST32_MAX
#define INT_LEAST32_MAX __INT_LEAST32_MAX__
#undef INT_LEAST32_MIN
#define INT_LEAST32_MIN (-INT_LEAST32_MAX - 1)
#undef UINT_LEAST32_MAX
#define UINT_LEAST32_MAX __UINT_LEAST32_MAX__
#undef INT_LEAST64_MAX
#define INT_LEAST64_MAX __INT_LEAST64_MAX__
#undef INT_LEAST64_MIN
#define INT_LEAST64_MIN (-INT_LEAST64_MAX - 1)
#undef UINT_LEAST64_MAX
#define UINT_LEAST64_MAX __UINT_LEAST64_MAX__
#undef INT_FAST8_MAX
#define INT_FAST8_MAX __INT_FAST8_MAX__
#undef INT_FAST8_MIN
#define INT_FAST8_MIN (-INT_FAST8_MAX - 1)
#undef UINT_FAST8_MAX
#define UINT_FAST8_MAX __UINT_FAST8_MAX__
#undef INT_FAST16_MAX
#define INT_FAST16_MAX __INT_FAST16_MAX__
#undef INT_FAST16_MIN
#define INT_FAST16_MIN (-INT_FAST16_MAX - 1)
#undef UINT_FAST16_MAX
#define UINT_FAST16_MAX __UINT_FAST16_MAX__
#undef INT_FAST32_MAX
#define INT_FAST32_MAX __INT_FAST32_MAX__
#undef INT_FAST32_MIN
#define INT_FAST32_MIN (-INT_FAST32_MAX - 1)
#undef UINT_FAST32_MAX
#define UINT_FAST32_MAX __UINT_FAST32_MAX__
#undef INT_FAST64_MAX
#define INT_FAST64_MAX __INT_FAST64_MAX__
#undef INT_FAST64_MIN
#define INT_FAST64_MIN (-INT_FAST64_MAX - 1)
#undef UINT_FAST64_MAX
#define UINT_FAST64_MAX __UINT_FAST64_MAX__
#ifdef __INTPTR_MAX__
# undef INTPTR_MAX
# define INTPTR_MAX __INTPTR_MAX__
# undef INTPTR_MIN
# define INTPTR_MIN (-INTPTR_MAX - 1)
#endif
#ifdef __UINTPTR_MAX__
# undef UINTPTR_MAX
# define UINTPTR_MAX __UINTPTR_MAX__
#endif
#undef INTMAX_MAX
#define INTMAX_MAX __INTMAX_MAX__
#undef INTMAX_MIN
#define INTMAX_MIN (-INTMAX_MAX - 1)
#undef UINTMAX_MAX
#define UINTMAX_MAX __UINTMAX_MAX__
/* 7.18.3 Limits of other integer types */
#undef PTRDIFF_MAX
#define PTRDIFF_MAX __PTRDIFF_MAX__
#undef PTRDIFF_MIN
#define PTRDIFF_MIN (-PTRDIFF_MAX - 1)
#undef SIG_ATOMIC_MAX
#define SIG_ATOMIC_MAX __SIG_ATOMIC_MAX__
#undef SIG_ATOMIC_MIN
#define SIG_ATOMIC_MIN __SIG_ATOMIC_MIN__
#undef SIZE_MAX
#define SIZE_MAX __SIZE_MAX__
#undef WCHAR_MAX
#define WCHAR_MAX __WCHAR_MAX__
#undef WCHAR_MIN
#define WCHAR_MIN __WCHAR_MIN__
#undef WINT_MAX
#define WINT_MAX __WINT_MAX__
#undef WINT_MIN
#define WINT_MIN __WINT_MIN__
#endif /* (!defined __cplusplus || __cplusplus >= 201103L
|| defined __STDC_LIMIT_MACROS) */
#if (!defined __cplusplus || __cplusplus >= 201103L \
|| defined __STDC_CONSTANT_MACROS)
#undef INT8_C
#define INT8_C(c) __INT8_C(c)
#undef INT16_C
#define INT16_C(c) __INT16_C(c)
#undef INT32_C
#define INT32_C(c) __INT32_C(c)
#undef INT64_C
#define INT64_C(c) __INT64_C(c)
#undef UINT8_C
#define UINT8_C(c) __UINT8_C(c)
#undef UINT16_C
#define UINT16_C(c) __UINT16_C(c)
#undef UINT32_C
#define UINT32_C(c) __UINT32_C(c)
#undef UINT64_C
#define UINT64_C(c) __UINT64_C(c)
#undef INTMAX_C
#define INTMAX_C(c) __INTMAX_C(c)
#undef UINTMAX_C
#define UINTMAX_C(c) __UINTMAX_C(c)
#endif /* (!defined __cplusplus || __cplusplus >= 201103L
|| defined __STDC_CONSTANT_MACROS) */
#ifdef __STDC_WANT_IEC_60559_BFP_EXT__
/* TS 18661-1 widths of integer types. */
#ifdef __INT8_TYPE__
# undef INT8_WIDTH
# define INT8_WIDTH 8
#endif
#ifdef __UINT8_TYPE__
# undef UINT8_WIDTH
# define UINT8_WIDTH 8
#endif
#ifdef __INT16_TYPE__
# undef INT16_WIDTH
# define INT16_WIDTH 16
#endif
#ifdef __UINT16_TYPE__
# undef UINT16_WIDTH
# define UINT16_WIDTH 16
#endif
#ifdef __INT32_TYPE__
# undef INT32_WIDTH
# define INT32_WIDTH 32
#endif
#ifdef __UINT32_TYPE__
# undef UINT32_WIDTH
# define UINT32_WIDTH 32
#endif
#ifdef __INT64_TYPE__
# undef INT64_WIDTH
# define INT64_WIDTH 64
#endif
#ifdef __UINT64_TYPE__
# undef UINT64_WIDTH
# define UINT64_WIDTH 64
#endif
#undef INT_LEAST8_WIDTH
#define INT_LEAST8_WIDTH __INT_LEAST8_WIDTH__
#undef UINT_LEAST8_WIDTH
#define UINT_LEAST8_WIDTH __INT_LEAST8_WIDTH__
#undef INT_LEAST16_WIDTH
#define INT_LEAST16_WIDTH __INT_LEAST16_WIDTH__
#undef UINT_LEAST16_WIDTH
#define UINT_LEAST16_WIDTH __INT_LEAST16_WIDTH__
#undef INT_LEAST32_WIDTH
#define INT_LEAST32_WIDTH __INT_LEAST32_WIDTH__
#undef UINT_LEAST32_WIDTH
#define UINT_LEAST32_WIDTH __INT_LEAST32_WIDTH__
#undef INT_LEAST64_WIDTH
#define INT_LEAST64_WIDTH __INT_LEAST64_WIDTH__
#undef UINT_LEAST64_WIDTH
#define UINT_LEAST64_WIDTH __INT_LEAST64_WIDTH__
#undef INT_FAST8_WIDTH
#define INT_FAST8_WIDTH __INT_FAST8_WIDTH__
#undef UINT_FAST8_WIDTH
#define UINT_FAST8_WIDTH __INT_FAST8_WIDTH__
#undef INT_FAST16_WIDTH
#define INT_FAST16_WIDTH __INT_FAST16_WIDTH__
#undef UINT_FAST16_WIDTH
#define UINT_FAST16_WIDTH __INT_FAST16_WIDTH__
#undef INT_FAST32_WIDTH
#define INT_FAST32_WIDTH __INT_FAST32_WIDTH__
#undef UINT_FAST32_WIDTH
#define UINT_FAST32_WIDTH __INT_FAST32_WIDTH__
#undef INT_FAST64_WIDTH
#define INT_FAST64_WIDTH __INT_FAST64_WIDTH__
#undef UINT_FAST64_WIDTH
#define UINT_FAST64_WIDTH __INT_FAST64_WIDTH__
#ifdef __INTPTR_TYPE__
# undef INTPTR_WIDTH
# define INTPTR_WIDTH __INTPTR_WIDTH__
#endif
#ifdef __UINTPTR_TYPE__
# undef UINTPTR_WIDTH
# define UINTPTR_WIDTH __INTPTR_WIDTH__
#endif
#undef INTMAX_WIDTH
#define INTMAX_WIDTH __INTMAX_WIDTH__
#undef UINTMAX_WIDTH
#define UINTMAX_WIDTH __INTMAX_WIDTH__
#undef PTRDIFF_WIDTH
#define PTRDIFF_WIDTH __PTRDIFF_WIDTH__
#undef SIG_ATOMIC_WIDTH
#define SIG_ATOMIC_WIDTH __SIG_ATOMIC_WIDTH__
#undef SIZE_WIDTH
#define SIZE_WIDTH __SIZE_WIDTH__
#undef WCHAR_WIDTH
#define WCHAR_WIDTH __WCHAR_WIDTH__
#undef WINT_WIDTH
#define WINT_WIDTH __WINT_WIDTH__
#ifdef __ILP32__
#define SIZE_MAX UINT32_MAX
#else
#define SIZE_MAX UINT64_MAX
#endif
#endif
#endif /* _GCC_STDINT_H */
+22
View File
@@ -0,0 +1,22 @@
#ifndef _STDIO_EXT_H
#define _STDIO_EXT_H
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
size_t __freadahead(FILE *stream);
size_t __fpending(FILE *stream);
int __freadable(FILE *stream);
int __freading(FILE *stream);
void __fseterr(FILE *stream);
int __fwritable(FILE *stream);
int __fwriting(FILE *stream);
#ifdef __cplusplus
} // extern "C"
#endif
#endif /* _STDIO_EXT_H */
+19
View File
@@ -0,0 +1,19 @@
/* Spec:
* The <stdnoreturn.h> header shall define the macro noreturn which shall
* expand to _Noreturn */
#ifndef _STDNORETURN_H
#define _STDNORETURN_H
#ifndef __cplusplus
/* Borrowed from musl */
#if __STDC_VERSION__ >= 201112L
#elif defined(__GNUC__)
#define _Noreturn __attribute__((__noreturn__))
#else
#define _Noreturn
#endif
#define noreturn _Noreturn
#endif
#endif
+36
View File
@@ -0,0 +1,36 @@
#ifndef _SYS_PARAM_H
#define _SYS_PARAM_H
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define __bitop(array, index, op) ((array)[(index) / 8] op (1 << (index) % 8))
#define setbit(array, index) __bitop(array, index, |=)
#define clrbit(array, index) __bitop(array, index, &= ~)
#define isset(array, index) __bitop(array, index, &)
#define isclr(array, index) !isset(array, index)
#define howmany(bits, size) (((bits) + (size) - 1) / (size))
#define roundup(bits, size) (howmany(bits, size) * (size))
#define powerof2(n) !(((n) - 1) & (n))
// Shamelessly copied from musl.
// Tweak as needed.
#define MAXSYMLINKS 20
#define MAXHOSTNAMELEN 64
#define MAXNAMLEN 255
#define MAXPATHLEN 4096
#define NBBY 8
#define NGROUPS 32
#define CANBSIZ 255
#define NOFILE 256
#define NCARGS 131072
#define DEV_BSIZE 512
#define NOGROUP (-1)
#include <sys/resource.h>
#include <limits.h>
#include <machine/endian.h>
#endif
+1
View File
@@ -0,0 +1 @@
#include <poll.h>
+846
View File
@@ -0,0 +1,846 @@
/* $NetBSD: queue.h,v 1.70 2015/11/02 15:21:23 christos Exp $ */
/*
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)queue.h 8.5 (Berkeley) 8/20/94
*/
#ifndef _SYS_QUEUE_H_
#define _SYS_QUEUE_H_
/*
* This file defines five types of data structures: singly-linked lists,
* lists, simple queues, tail queues, and circular queues.
*
* A singly-linked list is headed by a single forward pointer. The
* elements are singly linked for minimum space and pointer manipulation
* overhead at the expense of O(n) removal for arbitrary elements. New
* elements can be added to the list after an existing element or at the
* head of the list. Elements being removed from the head of the list
* should use the explicit macro for this purpose for optimum
* efficiency. A singly-linked list may only be traversed in the forward
* direction. Singly-linked lists are ideal for applications with large
* datasets and few or no removals or for implementing a LIFO queue.
*
* A list is headed by a single forward pointer (or an array of forward
* pointers for a hash table header). The elements are doubly linked
* so that an arbitrary element can be removed without a need to
* traverse the list. New elements can be added to the list before
* or after an existing element or at the head of the list. A list
* may only be traversed in the forward direction.
*
* A simple queue is headed by a pair of pointers, one the head of the
* list and the other to the tail of the list. The elements are singly
* linked to save space, so elements can only be removed from the
* head of the list. New elements can be added to the list after
* an existing element, at the head of the list, or at the end of the
* list. A simple queue may only be traversed in the forward direction.
*
* A tail queue is headed by a pair of pointers, one to the head of the
* list and the other to the tail of the list. The elements are doubly
* linked so that an arbitrary element can be removed without a need to
* traverse the list. New elements can be added to the list before or
* after an existing element, at the head of the list, or at the end of
* the list. A tail queue may be traversed in either direction.
*
* A circle queue is headed by a pair of pointers, one to the head of the
* list and the other to the tail of the list. The elements are doubly
* linked so that an arbitrary element can be removed without a need to
* traverse the list. New elements can be added to the list before or after
* an existing element, at the head of the list, or at the end of the list.
* A circle queue may be traversed in either direction, but has a more
* complex end of list detection.
*
* For details on the use of these macros, see the queue(3) manual page.
*/
/*
* Include the definition of NULL only on NetBSD because sys/null.h
* is not available elsewhere. This conditional makes the header
* portable and it can simply be dropped verbatim into any system.
* The caveat is that on other systems some other header
* must provide NULL before the macros can be used.
*/
#ifdef __NetBSD__
#include <sys/null.h>
#endif
#if defined(QUEUEDEBUG)
# if defined(_KERNEL)
# define QUEUEDEBUG_ABORT(...) panic(__VA_ARGS__)
# else
# include <err.h>
# define QUEUEDEBUG_ABORT(...) err(1, __VA_ARGS__)
# endif
#endif
/*
* Singly-linked List definitions.
*/
#define SLIST_HEAD(name, type) \
struct name { \
struct type *slh_first; /* first element */ \
}
#define SLIST_HEAD_INITIALIZER(head) \
{ NULL }
#define SLIST_ENTRY(type) \
struct { \
struct type *sle_next; /* next element */ \
}
/*
* Singly-linked List access methods.
*/
#define SLIST_FIRST(head) ((head)->slh_first)
#define SLIST_END(head) NULL
#define SLIST_EMPTY(head) ((head)->slh_first == NULL)
#define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
#define SLIST_FOREACH(var, head, field) \
for((var) = (head)->slh_first; \
(var) != SLIST_END(head); \
(var) = (var)->field.sle_next)
#define SLIST_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = SLIST_FIRST((head)); \
(var) != SLIST_END(head) && \
((tvar) = SLIST_NEXT((var), field), 1); \
(var) = (tvar))
/*
* Singly-linked List functions.
*/
#define SLIST_INIT(head) do { \
(head)->slh_first = SLIST_END(head); \
} while (/*CONSTCOND*/0)
#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
(elm)->field.sle_next = (slistelm)->field.sle_next; \
(slistelm)->field.sle_next = (elm); \
} while (/*CONSTCOND*/0)
#define SLIST_INSERT_HEAD(head, elm, field) do { \
(elm)->field.sle_next = (head)->slh_first; \
(head)->slh_first = (elm); \
} while (/*CONSTCOND*/0)
#define SLIST_REMOVE_AFTER(slistelm, field) do { \
(slistelm)->field.sle_next = \
SLIST_NEXT(SLIST_NEXT((slistelm), field), field); \
} while (/*CONSTCOND*/0)
#define SLIST_REMOVE_HEAD(head, field) do { \
(head)->slh_first = (head)->slh_first->field.sle_next; \
} while (/*CONSTCOND*/0)
#define SLIST_REMOVE(head, elm, type, field) do { \
if ((head)->slh_first == (elm)) { \
SLIST_REMOVE_HEAD((head), field); \
} \
else { \
struct type *curelm = (head)->slh_first; \
while(curelm->field.sle_next != (elm)) \
curelm = curelm->field.sle_next; \
curelm->field.sle_next = \
curelm->field.sle_next->field.sle_next; \
} \
} while (/*CONSTCOND*/0)
/*
* List definitions.
*/
#define LIST_HEAD(name, type) \
struct name { \
struct type *lh_first; /* first element */ \
}
#define LIST_HEAD_INITIALIZER(head) \
{ NULL }
#define LIST_ENTRY(type) \
struct { \
struct type *le_next; /* next element */ \
struct type **le_prev; /* address of previous next element */ \
}
/*
* List access methods.
*/
#define LIST_FIRST(head) ((head)->lh_first)
#define LIST_END(head) NULL
#define LIST_EMPTY(head) ((head)->lh_first == LIST_END(head))
#define LIST_NEXT(elm, field) ((elm)->field.le_next)
#define LIST_FOREACH(var, head, field) \
for ((var) = ((head)->lh_first); \
(var) != LIST_END(head); \
(var) = ((var)->field.le_next))
#define LIST_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = LIST_FIRST((head)); \
(var) != LIST_END(head) && \
((tvar) = LIST_NEXT((var), field), 1); \
(var) = (tvar))
#define LIST_MOVE(head1, head2) do { \
LIST_INIT((head2)); \
if (!LIST_EMPTY((head1))) { \
(head2)->lh_first = (head1)->lh_first; \
LIST_INIT((head1)); \
} \
} while (/*CONSTCOND*/0)
/*
* List functions.
*/
#if defined(QUEUEDEBUG)
#define QUEUEDEBUG_LIST_INSERT_HEAD(head, elm, field) \
if ((head)->lh_first && \
(head)->lh_first->field.le_prev != &(head)->lh_first) \
QUEUEDEBUG_ABORT("LIST_INSERT_HEAD %p %s:%d", (head), \
__FILE__, __LINE__);
#define QUEUEDEBUG_LIST_OP(elm, field) \
if ((elm)->field.le_next && \
(elm)->field.le_next->field.le_prev != \
&(elm)->field.le_next) \
QUEUEDEBUG_ABORT("LIST_* forw %p %s:%d", (elm), \
__FILE__, __LINE__); \
if (*(elm)->field.le_prev != (elm)) \
QUEUEDEBUG_ABORT("LIST_* back %p %s:%d", (elm), \
__FILE__, __LINE__);
#define QUEUEDEBUG_LIST_POSTREMOVE(elm, field) \
(elm)->field.le_next = (void *)1L; \
(elm)->field.le_prev = (void *)1L;
#else
#define QUEUEDEBUG_LIST_INSERT_HEAD(head, elm, field)
#define QUEUEDEBUG_LIST_OP(elm, field)
#define QUEUEDEBUG_LIST_POSTREMOVE(elm, field)
#endif
#define LIST_INIT(head) do { \
(head)->lh_first = LIST_END(head); \
} while (/*CONSTCOND*/0)
#define LIST_INSERT_AFTER(listelm, elm, field) do { \
QUEUEDEBUG_LIST_OP((listelm), field) \
if (((elm)->field.le_next = (listelm)->field.le_next) != \
LIST_END(head)) \
(listelm)->field.le_next->field.le_prev = \
&(elm)->field.le_next; \
(listelm)->field.le_next = (elm); \
(elm)->field.le_prev = &(listelm)->field.le_next; \
} while (/*CONSTCOND*/0)
#define LIST_INSERT_BEFORE(listelm, elm, field) do { \
QUEUEDEBUG_LIST_OP((listelm), field) \
(elm)->field.le_prev = (listelm)->field.le_prev; \
(elm)->field.le_next = (listelm); \
*(listelm)->field.le_prev = (elm); \
(listelm)->field.le_prev = &(elm)->field.le_next; \
} while (/*CONSTCOND*/0)
#define LIST_INSERT_HEAD(head, elm, field) do { \
QUEUEDEBUG_LIST_INSERT_HEAD((head), (elm), field) \
if (((elm)->field.le_next = (head)->lh_first) != LIST_END(head))\
(head)->lh_first->field.le_prev = &(elm)->field.le_next;\
(head)->lh_first = (elm); \
(elm)->field.le_prev = &(head)->lh_first; \
} while (/*CONSTCOND*/0)
#define LIST_REMOVE(elm, field) do { \
QUEUEDEBUG_LIST_OP((elm), field) \
if ((elm)->field.le_next != NULL) \
(elm)->field.le_next->field.le_prev = \
(elm)->field.le_prev; \
*(elm)->field.le_prev = (elm)->field.le_next; \
QUEUEDEBUG_LIST_POSTREMOVE((elm), field) \
} while (/*CONSTCOND*/0)
#define LIST_REPLACE(elm, elm2, field) do { \
if (((elm2)->field.le_next = (elm)->field.le_next) != NULL) \
(elm2)->field.le_next->field.le_prev = \
&(elm2)->field.le_next; \
(elm2)->field.le_prev = (elm)->field.le_prev; \
*(elm2)->field.le_prev = (elm2); \
QUEUEDEBUG_LIST_POSTREMOVE((elm), field) \
} while (/*CONSTCOND*/0)
/*
* Simple queue definitions.
*/
#define SIMPLEQ_HEAD(name, type) \
struct name { \
struct type *sqh_first; /* first element */ \
struct type **sqh_last; /* addr of last next element */ \
}
#define SIMPLEQ_HEAD_INITIALIZER(head) \
{ NULL, &(head).sqh_first }
#define SIMPLEQ_ENTRY(type) \
struct { \
struct type *sqe_next; /* next element */ \
}
/*
* Simple queue access methods.
*/
#define SIMPLEQ_FIRST(head) ((head)->sqh_first)
#define SIMPLEQ_END(head) NULL
#define SIMPLEQ_EMPTY(head) ((head)->sqh_first == SIMPLEQ_END(head))
#define SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
#define SIMPLEQ_FOREACH(var, head, field) \
for ((var) = ((head)->sqh_first); \
(var) != SIMPLEQ_END(head); \
(var) = ((var)->field.sqe_next))
#define SIMPLEQ_FOREACH_SAFE(var, head, field, next) \
for ((var) = ((head)->sqh_first); \
(var) != SIMPLEQ_END(head) && \
((next = ((var)->field.sqe_next)), 1); \
(var) = (next))
/*
* Simple queue functions.
*/
#define SIMPLEQ_INIT(head) do { \
(head)->sqh_first = NULL; \
(head)->sqh_last = &(head)->sqh_first; \
} while (/*CONSTCOND*/0)
#define SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
(head)->sqh_last = &(elm)->field.sqe_next; \
(head)->sqh_first = (elm); \
} while (/*CONSTCOND*/0)
#define SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
(elm)->field.sqe_next = NULL; \
*(head)->sqh_last = (elm); \
(head)->sqh_last = &(elm)->field.sqe_next; \
} while (/*CONSTCOND*/0)
#define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
(head)->sqh_last = &(elm)->field.sqe_next; \
(listelm)->field.sqe_next = (elm); \
} while (/*CONSTCOND*/0)
#define SIMPLEQ_REMOVE_HEAD(head, field) do { \
if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
(head)->sqh_last = &(head)->sqh_first; \
} while (/*CONSTCOND*/0)
#define SIMPLEQ_REMOVE_AFTER(head, elm, field) do { \
if (((elm)->field.sqe_next = (elm)->field.sqe_next->field.sqe_next) \
== NULL) \
(head)->sqh_last = &(elm)->field.sqe_next; \
} while (/*CONSTCOND*/0)
#define SIMPLEQ_REMOVE(head, elm, type, field) do { \
if ((head)->sqh_first == (elm)) { \
SIMPLEQ_REMOVE_HEAD((head), field); \
} else { \
struct type *curelm = (head)->sqh_first; \
while (curelm->field.sqe_next != (elm)) \
curelm = curelm->field.sqe_next; \
if ((curelm->field.sqe_next = \
curelm->field.sqe_next->field.sqe_next) == NULL) \
(head)->sqh_last = &(curelm)->field.sqe_next; \
} \
} while (/*CONSTCOND*/0)
#define SIMPLEQ_CONCAT(head1, head2) do { \
if (!SIMPLEQ_EMPTY((head2))) { \
*(head1)->sqh_last = (head2)->sqh_first; \
(head1)->sqh_last = (head2)->sqh_last; \
SIMPLEQ_INIT((head2)); \
} \
} while (/*CONSTCOND*/0)
#define SIMPLEQ_LAST(head, type, field) \
(SIMPLEQ_EMPTY((head)) ? \
NULL : \
((struct type *)(void *) \
((char *)((head)->sqh_last) - offsetof(struct type, field))))
/*
* Tail queue definitions.
*/
#define _TAILQ_HEAD(name, type, qual) \
struct name { \
qual type *tqh_first; /* first element */ \
qual type *qual *tqh_last; /* addr of last next element */ \
}
#define TAILQ_HEAD(name, type) _TAILQ_HEAD(name, struct type,)
#define TAILQ_HEAD_INITIALIZER(head) \
{ TAILQ_END(head), &(head).tqh_first }
#define _TAILQ_ENTRY(type, qual) \
struct { \
qual type *tqe_next; /* next element */ \
qual type *qual *tqe_prev; /* address of previous next element */\
}
#define TAILQ_ENTRY(type) _TAILQ_ENTRY(struct type,)
/*
* Tail queue access methods.
*/
#define TAILQ_FIRST(head) ((head)->tqh_first)
#define TAILQ_END(head) (NULL)
#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
#define TAILQ_LAST(head, headname) \
(*(((struct headname *)(void *)((head)->tqh_last))->tqh_last))
#define TAILQ_PREV(elm, headname, field) \
(*(((struct headname *)(void *)((elm)->field.tqe_prev))->tqh_last))
#define TAILQ_EMPTY(head) (TAILQ_FIRST(head) == TAILQ_END(head))
#define TAILQ_FOREACH(var, head, field) \
for ((var) = ((head)->tqh_first); \
(var) != TAILQ_END(head); \
(var) = ((var)->field.tqe_next))
#define TAILQ_FOREACH_SAFE(var, head, field, next) \
for ((var) = ((head)->tqh_first); \
(var) != TAILQ_END(head) && \
((next) = TAILQ_NEXT(var, field), 1); (var) = (next))
#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
for ((var) = TAILQ_LAST((head), headname); \
(var) != TAILQ_END(head); \
(var) = TAILQ_PREV((var), headname, field))
#define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, prev) \
for ((var) = TAILQ_LAST((head), headname); \
(var) != TAILQ_END(head) && \
((prev) = TAILQ_PREV((var), headname, field), 1); (var) = (prev))
/*
* Tail queue functions.
*/
#if defined(QUEUEDEBUG)
#define QUEUEDEBUG_TAILQ_INSERT_HEAD(head, elm, field) \
if ((head)->tqh_first && \
(head)->tqh_first->field.tqe_prev != &(head)->tqh_first) \
QUEUEDEBUG_ABORT("TAILQ_INSERT_HEAD %p %s:%d", (head), \
__FILE__, __LINE__);
#define QUEUEDEBUG_TAILQ_INSERT_TAIL(head, elm, field) \
if (*(head)->tqh_last != NULL) \
QUEUEDEBUG_ABORT("TAILQ_INSERT_TAIL %p %s:%d", (head), \
__FILE__, __LINE__);
#define QUEUEDEBUG_TAILQ_OP(elm, field) \
if ((elm)->field.tqe_next && \
(elm)->field.tqe_next->field.tqe_prev != \
&(elm)->field.tqe_next) \
QUEUEDEBUG_ABORT("TAILQ_* forw %p %s:%d", (elm), \
__FILE__, __LINE__); \
if (*(elm)->field.tqe_prev != (elm)) \
QUEUEDEBUG_ABORT("TAILQ_* back %p %s:%d", (elm), \
__FILE__, __LINE__);
#define QUEUEDEBUG_TAILQ_PREREMOVE(head, elm, field) \
if ((elm)->field.tqe_next == NULL && \
(head)->tqh_last != &(elm)->field.tqe_next) \
QUEUEDEBUG_ABORT("TAILQ_PREREMOVE head %p elm %p %s:%d",\
(head), (elm), __FILE__, __LINE__);
#define QUEUEDEBUG_TAILQ_POSTREMOVE(elm, field) \
(elm)->field.tqe_next = (void *)1L; \
(elm)->field.tqe_prev = (void *)1L;
#else
#define QUEUEDEBUG_TAILQ_INSERT_HEAD(head, elm, field)
#define QUEUEDEBUG_TAILQ_INSERT_TAIL(head, elm, field)
#define QUEUEDEBUG_TAILQ_OP(elm, field)
#define QUEUEDEBUG_TAILQ_PREREMOVE(head, elm, field)
#define QUEUEDEBUG_TAILQ_POSTREMOVE(elm, field)
#endif
#define TAILQ_INIT(head) do { \
(head)->tqh_first = TAILQ_END(head); \
(head)->tqh_last = &(head)->tqh_first; \
} while (/*CONSTCOND*/0)
#define TAILQ_INSERT_HEAD(head, elm, field) do { \
QUEUEDEBUG_TAILQ_INSERT_HEAD((head), (elm), field) \
if (((elm)->field.tqe_next = (head)->tqh_first) != TAILQ_END(head))\
(head)->tqh_first->field.tqe_prev = \
&(elm)->field.tqe_next; \
else \
(head)->tqh_last = &(elm)->field.tqe_next; \
(head)->tqh_first = (elm); \
(elm)->field.tqe_prev = &(head)->tqh_first; \
} while (/*CONSTCOND*/0)
#define TAILQ_INSERT_TAIL(head, elm, field) do { \
QUEUEDEBUG_TAILQ_INSERT_TAIL((head), (elm), field) \
(elm)->field.tqe_next = TAILQ_END(head); \
(elm)->field.tqe_prev = (head)->tqh_last; \
*(head)->tqh_last = (elm); \
(head)->tqh_last = &(elm)->field.tqe_next; \
} while (/*CONSTCOND*/0)
#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
QUEUEDEBUG_TAILQ_OP((listelm), field) \
if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != \
TAILQ_END(head)) \
(elm)->field.tqe_next->field.tqe_prev = \
&(elm)->field.tqe_next; \
else \
(head)->tqh_last = &(elm)->field.tqe_next; \
(listelm)->field.tqe_next = (elm); \
(elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
} while (/*CONSTCOND*/0)
#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
QUEUEDEBUG_TAILQ_OP((listelm), field) \
(elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
(elm)->field.tqe_next = (listelm); \
*(listelm)->field.tqe_prev = (elm); \
(listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
} while (/*CONSTCOND*/0)
#define TAILQ_REMOVE(head, elm, field) do { \
QUEUEDEBUG_TAILQ_PREREMOVE((head), (elm), field) \
QUEUEDEBUG_TAILQ_OP((elm), field) \
if (((elm)->field.tqe_next) != TAILQ_END(head)) \
(elm)->field.tqe_next->field.tqe_prev = \
(elm)->field.tqe_prev; \
else \
(head)->tqh_last = (elm)->field.tqe_prev; \
*(elm)->field.tqe_prev = (elm)->field.tqe_next; \
QUEUEDEBUG_TAILQ_POSTREMOVE((elm), field); \
} while (/*CONSTCOND*/0)
#define TAILQ_REPLACE(head, elm, elm2, field) do { \
if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != \
TAILQ_END(head)) \
(elm2)->field.tqe_next->field.tqe_prev = \
&(elm2)->field.tqe_next; \
else \
(head)->tqh_last = &(elm2)->field.tqe_next; \
(elm2)->field.tqe_prev = (elm)->field.tqe_prev; \
*(elm2)->field.tqe_prev = (elm2); \
QUEUEDEBUG_TAILQ_POSTREMOVE((elm), field); \
} while (/*CONSTCOND*/0)
#define TAILQ_CONCAT(head1, head2, field) do { \
if (!TAILQ_EMPTY(head2)) { \
*(head1)->tqh_last = (head2)->tqh_first; \
(head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
(head1)->tqh_last = (head2)->tqh_last; \
TAILQ_INIT((head2)); \
} \
} while (/*CONSTCOND*/0)
/*
* Singly-linked Tail queue declarations.
*/
#define STAILQ_HEAD(name, type) \
struct name { \
struct type *stqh_first; /* first element */ \
struct type **stqh_last; /* addr of last next element */ \
}
#define STAILQ_HEAD_INITIALIZER(head) \
{ NULL, &(head).stqh_first }
#define STAILQ_ENTRY(type) \
struct { \
struct type *stqe_next; /* next element */ \
}
/*
* Singly-linked Tail queue access methods.
*/
#define STAILQ_FIRST(head) ((head)->stqh_first)
#define STAILQ_END(head) NULL
#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
#define STAILQ_EMPTY(head) (STAILQ_FIRST(head) == STAILQ_END(head))
/*
* Singly-linked Tail queue functions.
*/
#define STAILQ_INIT(head) do { \
(head)->stqh_first = NULL; \
(head)->stqh_last = &(head)->stqh_first; \
} while (/*CONSTCOND*/0)
#define STAILQ_INSERT_HEAD(head, elm, field) do { \
if (((elm)->field.stqe_next = (head)->stqh_first) == NULL) \
(head)->stqh_last = &(elm)->field.stqe_next; \
(head)->stqh_first = (elm); \
} while (/*CONSTCOND*/0)
#define STAILQ_INSERT_TAIL(head, elm, field) do { \
(elm)->field.stqe_next = NULL; \
*(head)->stqh_last = (elm); \
(head)->stqh_last = &(elm)->field.stqe_next; \
} while (/*CONSTCOND*/0)
#define STAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
if (((elm)->field.stqe_next = (listelm)->field.stqe_next) == NULL)\
(head)->stqh_last = &(elm)->field.stqe_next; \
(listelm)->field.stqe_next = (elm); \
} while (/*CONSTCOND*/0)
#define STAILQ_REMOVE_HEAD(head, field) do { \
if (((head)->stqh_first = (head)->stqh_first->field.stqe_next) == NULL) \
(head)->stqh_last = &(head)->stqh_first; \
} while (/*CONSTCOND*/0)
#define STAILQ_REMOVE(head, elm, type, field) do { \
if ((head)->stqh_first == (elm)) { \
STAILQ_REMOVE_HEAD((head), field); \
} else { \
struct type *curelm = (head)->stqh_first; \
while (curelm->field.stqe_next != (elm)) \
curelm = curelm->field.stqe_next; \
if ((curelm->field.stqe_next = \
curelm->field.stqe_next->field.stqe_next) == NULL) \
(head)->stqh_last = &(curelm)->field.stqe_next; \
} \
} while (/*CONSTCOND*/0)
#define STAILQ_FOREACH(var, head, field) \
for ((var) = ((head)->stqh_first); \
(var); \
(var) = ((var)->field.stqe_next))
#define STAILQ_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = STAILQ_FIRST((head)); \
(var) && ((tvar) = STAILQ_NEXT((var), field), 1); \
(var) = (tvar))
#define STAILQ_CONCAT(head1, head2) do { \
if (!STAILQ_EMPTY((head2))) { \
*(head1)->stqh_last = (head2)->stqh_first; \
(head1)->stqh_last = (head2)->stqh_last; \
STAILQ_INIT((head2)); \
} \
} while (/*CONSTCOND*/0)
#define STAILQ_LAST(head, type, field) \
(STAILQ_EMPTY((head)) ? \
NULL : \
((struct type *)(void *) \
((char *)((head)->stqh_last) - offsetof(struct type, field))))
#ifndef _KERNEL
/*
* Circular queue definitions. Do not use. We still keep the macros
* for compatibility but because of pointer aliasing issues their use
* is discouraged!
*/
/*
* __launder_type(): We use this ugly hack to work around the the compiler
* noticing that two types may not alias each other and elide tests in code.
* We hit this in the CIRCLEQ macros when comparing 'struct name *' and
* 'struct type *' (see CIRCLEQ_HEAD()). Modern compilers (such as GCC
* 4.8) declare these comparisons as always false, causing the code to
* not run as designed.
*
* This hack is only to be used for comparisons and thus can be fully const.
* Do not use for assignment.
*
* If we ever choose to change the ABI of the CIRCLEQ macros, we could fix
* this by changing the head/tail sentinal values, but see the note above
* this one.
*/
static __inline const void * __launder_type(const void *);
static __inline const void *
__launder_type(const void *__x)
{
__asm __volatile("" : "+r" (__x));
return __x;
}
#if defined(QUEUEDEBUG)
#define QUEUEDEBUG_CIRCLEQ_HEAD(head, field) \
if ((head)->cqh_first != CIRCLEQ_ENDC(head) && \
(head)->cqh_first->field.cqe_prev != CIRCLEQ_ENDC(head)) \
QUEUEDEBUG_ABORT("CIRCLEQ head forw %p %s:%d", (head), \
__FILE__, __LINE__); \
if ((head)->cqh_last != CIRCLEQ_ENDC(head) && \
(head)->cqh_last->field.cqe_next != CIRCLEQ_ENDC(head)) \
QUEUEDEBUG_ABORT("CIRCLEQ head back %p %s:%d", (head), \
__FILE__, __LINE__);
#define QUEUEDEBUG_CIRCLEQ_ELM(head, elm, field) \
if ((elm)->field.cqe_next == CIRCLEQ_ENDC(head)) { \
if ((head)->cqh_last != (elm)) \
QUEUEDEBUG_ABORT("CIRCLEQ elm last %p %s:%d", \
(elm), __FILE__, __LINE__); \
} else { \
if ((elm)->field.cqe_next->field.cqe_prev != (elm)) \
QUEUEDEBUG_ABORT("CIRCLEQ elm forw %p %s:%d", \
(elm), __FILE__, __LINE__); \
} \
if ((elm)->field.cqe_prev == CIRCLEQ_ENDC(head)) { \
if ((head)->cqh_first != (elm)) \
QUEUEDEBUG_ABORT("CIRCLEQ elm first %p %s:%d", \
(elm), __FILE__, __LINE__); \
} else { \
if ((elm)->field.cqe_prev->field.cqe_next != (elm)) \
QUEUEDEBUG_ABORT("CIRCLEQ elm prev %p %s:%d", \
(elm), __FILE__, __LINE__); \
}
#define QUEUEDEBUG_CIRCLEQ_POSTREMOVE(elm, field) \
(elm)->field.cqe_next = (void *)1L; \
(elm)->field.cqe_prev = (void *)1L;
#else
#define QUEUEDEBUG_CIRCLEQ_HEAD(head, field)
#define QUEUEDEBUG_CIRCLEQ_ELM(head, elm, field)
#define QUEUEDEBUG_CIRCLEQ_POSTREMOVE(elm, field)
#endif
#define CIRCLEQ_HEAD(name, type) \
struct name { \
struct type *cqh_first; /* first element */ \
struct type *cqh_last; /* last element */ \
}
#define CIRCLEQ_HEAD_INITIALIZER(head) \
{ CIRCLEQ_END(&head), CIRCLEQ_END(&head) }
#define CIRCLEQ_ENTRY(type) \
struct { \
struct type *cqe_next; /* next element */ \
struct type *cqe_prev; /* previous element */ \
}
/*
* Circular queue functions.
*/
#define CIRCLEQ_INIT(head) do { \
(head)->cqh_first = CIRCLEQ_END(head); \
(head)->cqh_last = CIRCLEQ_END(head); \
} while (/*CONSTCOND*/0)
#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
QUEUEDEBUG_CIRCLEQ_HEAD((head), field) \
QUEUEDEBUG_CIRCLEQ_ELM((head), (listelm), field) \
(elm)->field.cqe_next = (listelm)->field.cqe_next; \
(elm)->field.cqe_prev = (listelm); \
if ((listelm)->field.cqe_next == CIRCLEQ_ENDC(head)) \
(head)->cqh_last = (elm); \
else \
(listelm)->field.cqe_next->field.cqe_prev = (elm); \
(listelm)->field.cqe_next = (elm); \
} while (/*CONSTCOND*/0)
#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
QUEUEDEBUG_CIRCLEQ_HEAD((head), field) \
QUEUEDEBUG_CIRCLEQ_ELM((head), (listelm), field) \
(elm)->field.cqe_next = (listelm); \
(elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
if ((listelm)->field.cqe_prev == CIRCLEQ_ENDC(head)) \
(head)->cqh_first = (elm); \
else \
(listelm)->field.cqe_prev->field.cqe_next = (elm); \
(listelm)->field.cqe_prev = (elm); \
} while (/*CONSTCOND*/0)
#define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
QUEUEDEBUG_CIRCLEQ_HEAD((head), field) \
(elm)->field.cqe_next = (head)->cqh_first; \
(elm)->field.cqe_prev = CIRCLEQ_END(head); \
if ((head)->cqh_last == CIRCLEQ_ENDC(head)) \
(head)->cqh_last = (elm); \
else \
(head)->cqh_first->field.cqe_prev = (elm); \
(head)->cqh_first = (elm); \
} while (/*CONSTCOND*/0)
#define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
QUEUEDEBUG_CIRCLEQ_HEAD((head), field) \
(elm)->field.cqe_next = CIRCLEQ_END(head); \
(elm)->field.cqe_prev = (head)->cqh_last; \
if ((head)->cqh_first == CIRCLEQ_ENDC(head)) \
(head)->cqh_first = (elm); \
else \
(head)->cqh_last->field.cqe_next = (elm); \
(head)->cqh_last = (elm); \
} while (/*CONSTCOND*/0)
#define CIRCLEQ_REMOVE(head, elm, field) do { \
QUEUEDEBUG_CIRCLEQ_HEAD((head), field) \
QUEUEDEBUG_CIRCLEQ_ELM((head), (elm), field) \
if ((elm)->field.cqe_next == CIRCLEQ_ENDC(head)) \
(head)->cqh_last = (elm)->field.cqe_prev; \
else \
(elm)->field.cqe_next->field.cqe_prev = \
(elm)->field.cqe_prev; \
if ((elm)->field.cqe_prev == CIRCLEQ_ENDC(head)) \
(head)->cqh_first = (elm)->field.cqe_next; \
else \
(elm)->field.cqe_prev->field.cqe_next = \
(elm)->field.cqe_next; \
QUEUEDEBUG_CIRCLEQ_POSTREMOVE((elm), field) \
} while (/*CONSTCOND*/0)
#define CIRCLEQ_FOREACH(var, head, field) \
for ((var) = ((head)->cqh_first); \
(var) != CIRCLEQ_ENDC(head); \
(var) = ((var)->field.cqe_next))
#define CIRCLEQ_FOREACH_REVERSE(var, head, field) \
for ((var) = ((head)->cqh_last); \
(var) != CIRCLEQ_ENDC(head); \
(var) = ((var)->field.cqe_prev))
/*
* Circular queue access methods.
*/
#define CIRCLEQ_FIRST(head) ((head)->cqh_first)
#define CIRCLEQ_LAST(head) ((head)->cqh_last)
/* For comparisons */
#define CIRCLEQ_ENDC(head) (__launder_type(head))
/* For assignments */
#define CIRCLEQ_END(head) ((void *)(head))
#define CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
#define CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
#define CIRCLEQ_EMPTY(head) \
(CIRCLEQ_FIRST(head) == CIRCLEQ_ENDC(head))
#define CIRCLEQ_LOOP_NEXT(head, elm, field) \
(((elm)->field.cqe_next == CIRCLEQ_ENDC(head)) \
? ((head)->cqh_first) \
: (elm->field.cqe_next))
#define CIRCLEQ_LOOP_PREV(head, elm, field) \
(((elm)->field.cqe_prev == CIRCLEQ_ENDC(head)) \
? ((head)->cqh_last) \
: (elm->field.cqe_prev))
#endif /* !_KERNEL */
#endif /* !_SYS_QUEUE_H_ */
+22
View File
@@ -0,0 +1,22 @@
#ifndef _SYS_REDOX_H
#define _SYS_REDOX_H
#include <sys/types.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __redox__
ssize_t redox_fpath(int fd, void * buf, size_t count);
void * redox_physalloc(size_t size);
int redox_physfree(void * physical_address, size_t size);
#endif
#ifdef __cplusplus
} // extern "C"
#endif
#endif
+16
View File
@@ -0,0 +1,16 @@
// From musl, license MIT
#ifndef _SYS_SYSMACROS_H
#define _SYS_SYSMACROS_H
#define major(x) \
((unsigned)( (((x)>>31>>1) & 0xfffff000) | (((x)>>8) & 0x00000fff) ))
#define minor(x) \
((unsigned)( (((x)>>12) & 0xffffff00) | ((x) & 0x000000ff) ))
#define makedev(x,y) ( \
(((x)&0xfffff000ULL) << 32) | \
(((x)&0x00000fffULL) << 8) | \
(((y)&0xffffff00ULL) << 12) | \
(((y)&0x000000ffULL)) )
#endif
+13
View File
@@ -0,0 +1,13 @@
#ifndef _SYS_USER_H
#define _SYS_USER_H
#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64)
#include <arch/x64/user.h>
#elif defined(__aarch64__)
#include <arch/aarch64/user.h>
#elif defined(__riscv) && __riscv_xlen==64
#include <arch/riscv64/user.h>
#else
#error "Unknown architecture"
#endif
#endif
+21
View File
@@ -0,0 +1,21 @@
#ifndef _SYSEXITS_H
#define _SYSEXITS_H
#define EX_OK 0
#define EX_USAGE 64
#define EX_DATAERR 65
#define EX_NOINPUT 66
#define EX_NOUSER 67
#define EX_NOHOST 68
#define EX_UNAVAILABLE 69
#define EX_SOFTWARE 70
#define EX_OSERR 71
#define EX_OSFILE 72
#define EX_CANTCREAT 73
#define EX_IOERR 74
#define EX_TEMPFAIL 75
#define EX_PROTOCOL 76
#define EX_NOPERM 77
#define EX_CONFIG 78
#endif /* _SYSEXITS_H */
+1
View File
@@ -0,0 +1 @@
#include <sys/syslog.h>
+12
View File
@@ -0,0 +1,12 @@
[package]
name = "ld_so"
version = "0.1.0"
authors = ["Jeremy Soller <jackpot51@gmail.com>"]
edition = "2024"
[lib]
name = "ld_so"
crate-type = ["staticlib"]
[lints]
workspace = true
@@ -0,0 +1,263 @@
/* Script for -z combreloc */
/* Copyright (C) 2014-2025 Free Software Foundation, Inc.
Copying and distribution of this script, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. */
OUTPUT_FORMAT("elf64-littleaarch64", "elf64-bigaarch64", "elf64-littleaarch64")
OUTPUT_ARCH(aarch64)
ENTRY(_start)
SEARCH_DIR("=/usr/aarch64-linux-gnu/lib64"); SEARCH_DIR("=/usr/local/lib64"); SEARCH_DIR("=/lib64"); SEARCH_DIR("=/usr/lib64"); SEARCH_DIR("=/usr/aarch64-linux-gnu/lib"); SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib");
SECTIONS
{
/* Read-only sections, merged into text segment: */
PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000));
. = SEGMENT_START("text-segment", 0x400000) + SIZEOF_HEADERS;
/* Place the build-id as close to the ELF headers as possible. This
maximises the chance the build-id will be present in core files,
which GDB can then use to locate the associated debuginfo file. */
.note.gnu.build-id : { *(.note.gnu.build-id) }
.interp : { *(.interp) }
.hash : { *(.hash) }
.gnu.hash : { *(.gnu.hash) }
.dynsym : { *(.dynsym) }
.dynstr : { *(.dynstr) }
.gnu.version : { *(.gnu.version) }
.gnu.version_d : { *(.gnu.version_d) }
.gnu.version_r : { *(.gnu.version_r) }
.rela.dyn :
{
*(.rela.init)
*(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
*(.rela.fini)
*(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
*(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
*(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
*(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
*(.rela.ctors)
*(.rela.dtors)
*(.rela.got)
*(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
*(.rela.ifunc)
}
.rela.plt :
{
*(.rela.plt)
PROVIDE_HIDDEN (__rela_iplt_start = .);
*(.rela.iplt)
PROVIDE_HIDDEN (__rela_iplt_end = .);
}
.relr.dyn : { *(.relr.dyn) }
/* Start of the executable code region. */
.init :
{
KEEP (*(SORT_NONE(.init)))
} =0x1f2003d5
.plt : ALIGN(16) { *(.plt) *(.iplt) }
.text :
{
*(.text.unlikely .text.*_unlikely .text.unlikely.*)
*(.text.exit .text.exit.*)
*(.text.startup .text.startup.*)
*(.text.hot .text.hot.*)
*(SORT(.text.sorted.*))
*(.text .stub .text.* .gnu.linkonce.t.*)
/* .gnu.warning sections are handled specially by elf.em. */
*(.gnu.warning)
} =0x1f2003d5
.fini :
{
KEEP (*(SORT_NONE(.fini)))
} =0x1f2003d5
PROVIDE (__etext = .);
PROVIDE (_etext = .);
PROVIDE (etext = .);
/* Start of the Read Only Data region. */
.rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
.rodata1 : { *(.rodata1) }
.eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) }
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.sframe : ONLY_IF_RO { *(.sframe) *(.sframe.*) }
.gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
.gnu_extab : ONLY_IF_RO { *(.gnu_extab*) }
/* These sections are generated by the Sun/Oracle C++ compiler. */
.exception_ranges : ONLY_IF_RO { *(.exception_ranges*) }
/* Various note sections. Placed here so that they are always included
in the read-only segment and not treated as orphan sections. The
current orphan handling algorithm does place note sections after R/O
data, but this is not guaranteed to always be the case. */
.note.build-id : { *(.note.build-id) }
.note.GNU-stack : { *(.note.GNU-stack) }
.note.gnu-property : { *(.note.gnu-property) }
.note.ABI-tag : { *(.note.ABI-tag) }
.note.package : { *(.note.package) }
.note.dlopen : { *(.note.dlopen) }
.note.netbsd.ident : { *(.note.netbsd.ident) }
.note.openbsd.ident : { *(.note.openbsd.ident) }
/* Start of the Read Write Data region. */
/* Adjust the address for the data segment. We want to adjust up to
the same address within the page on the next page up. */
. = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
/* Exception handling. */
.eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.sframe : ONLY_IF_RW { *(.sframe) *(.sframe.*) }
.gnu_extab : ONLY_IF_RW { *(.gnu_extab) }
.gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
.exception_ranges : ONLY_IF_RW { *(.exception_ranges*) }
/* Thread Local Storage sections. */
/* .tdata :
{
PROVIDE_HIDDEN (__tdata_start = .);
*(.tdata .tdata.* .gnu.linkonce.td.*)
}
.tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } */
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
}
/* .init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
PROVIDE_HIDDEN (__init_array_end = .);
} */
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
PROVIDE_HIDDEN (__fini_array_end = .);
}
.ctors :
{
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
KEEP (*crtbegin?.o(.ctors))
/* We don't want to include the .ctor section from
the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
}
.dtors :
{
KEEP (*crtbegin.o(.dtors))
KEEP (*crtbegin?.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
}
.jcr : { KEEP (*(.jcr)) }
.data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }
.dynamic : { *(.dynamic) }
.got : { *(.got) *(.igot) }
. = DATA_SEGMENT_RELRO_END (24, .);
.got.plt : { *(.got.plt) *(.igot.plt) }
.data :
{
PROVIDE (__data_start = .);
*(.data .data.* .gnu.linkonce.d.*)
SORT(CONSTRUCTORS)
}
.data1 : { *(.data1) }
_edata = .;
PROVIDE (edata = .);
. = ALIGN(ALIGNOF(NEXT_SECTION));
__bss_start = .;
__bss_start__ = .;
.bss :
{
*(.dynbss)
*(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON)
/* Align here to ensure that in the common case of there only being one
type of .bss section, the section occupies space up to _end.
Align after .bss to ensure correct alignment even if the
.bss section disappears because there are no input sections.
FIXME: Why do we need it? When there is no .bss section, we do not
pad the .data section. */
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
_bss_end__ = .; __bss_end__ = .;
. = ALIGN(64 / 8);
/* Start of the Large Data region. */
. = SEGMENT_START("ldata-segment", .);
. = ALIGN(64 / 8);
__end__ = .;
_end = .;
PROVIDE (end = .);
. = DATA_SEGMENT_END (.);
/* Start of the Tiny Data region. */
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 (INFO) : { *(.comment); LINKER_VERSION; }
.gnu.build.attributes : { *(.gnu.build.attributes .gnu.build.attributes.*) }
/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */
/* DWARF 1. */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* GNU DWARF 1 extensions. */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2. */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2. */
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* SGI/MIPS DWARF 2 extensions. */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
/* DWARF 3. */
.debug_pubtypes 0 : { *(.debug_pubtypes) }
.debug_ranges 0 : { *(.debug_ranges) }
/* DWARF 5. */
.debug_addr 0 : { *(.debug_addr) }
.debug_line_str 0 : { *(.debug_line_str) }
.debug_loclists 0 : { *(.debug_loclists) }
.debug_macro 0 : { *(.debug_macro) }
.debug_names 0 : { *(.debug_names) }
.debug_rnglists 0 : { *(.debug_rnglists) }
.debug_str_offsets 0 : { *(.debug_str_offsets) }
.debug_sup 0 : { *(.debug_sup) }
.ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) }
.note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }
/DISCARD/ : {
*(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*)
/*
* XXX: As of now, ld.so links with relibc which has the main functionality. In the next refactor,
* ld.so will be moved out of relibc. So, till that time, we have to discard any sections
* that may reference use thread local storage.
*
* .init_array also depends on TLS and is discarded as we don't need it.
*/
*(.gnu.linkonce.tb.*) *(.tcommon)
*(.init_array)
}
}
+255
View File
@@ -0,0 +1,255 @@
/* Script for -z combreloc */
/* Copyright (C) 2014-2020 Free Software Foundation, Inc.
Copying and distribution of this script, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. */
OUTPUT_FORMAT("elf64-littleaarch64", "elf64-littleaarch64",
"elf64-littleaarch64")
OUTPUT_ARCH(aarch64)
ENTRY(_start)
SEARCH_DIR("/aarch64-unknown-redox/lib");
SEARCH_DIR("/usr/local/lib64");
SEARCH_DIR("/lib64");
SEARCH_DIR("/usr/lib64");
SEARCH_DIR("/usr/local/lib");
SEARCH_DIR("/lib");
SEARCH_DIR("/usr/lib");
SECTIONS
{
/* Read-only sections, merged into text segment: */
PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000)); . = SEGMENT_START("text-segment", 0x20000000) + SIZEOF_HEADERS;
.interp : { *(.interp) }
.note.gnu.build-id : { *(.note.gnu.build-id) }
.hash : { *(.hash) }
.gnu.hash : { *(.gnu.hash) }
.dynsym : { *(.dynsym) }
.dynstr : { *(.dynstr) }
.gnu.version : { *(.gnu.version) }
.gnu.version_d : { *(.gnu.version_d) }
.gnu.version_r : { *(.gnu.version_r) }
.rela.dyn :
{
*(.rela.init)
*(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
*(.rela.fini)
*(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
*(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
*(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
*(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
*(.rela.ctors)
*(.rela.dtors)
*(.rela.got)
*(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
*(.rela.ldata .rela.ldata.* .rela.gnu.linkonce.l.*)
*(.rela.lbss .rela.lbss.* .rela.gnu.linkonce.lb.*)
*(.rela.lrodata .rela.lrodata.* .rela.gnu.linkonce.lr.*)
*(.rela.ifunc)
}
.rela.plt :
{
*(.rela.plt)
PROVIDE_HIDDEN (__rela_iplt_start = .);
*(.rela.iplt)
PROVIDE_HIDDEN (__rela_iplt_end = .);
}
. = ALIGN(CONSTANT (MAXPAGESIZE));
.init :
{
KEEP (*(SORT_NONE(.init)))
}
.plt : { *(.plt) *(.iplt) }
.plt.got : { *(.plt.got) }
.plt.sec : { *(.plt.sec) }
.text :
{
*(.text.unlikely .text.*_unlikely .text.unlikely.*)
*(.text.exit .text.exit.*)
*(.text.startup .text.startup.*)
*(.text.hot .text.hot.*)
*(.text .stub .text.* .gnu.linkonce.t.*)
/* .gnu.warning sections are handled specially by elf.em. */
*(.gnu.warning)
}
.fini :
{
KEEP (*(SORT_NONE(.fini)))
}
PROVIDE (__etext = .);
PROVIDE (_etext = .);
PROVIDE (etext = .);
. = ALIGN(CONSTANT (MAXPAGESIZE));
/* Adjust the address for the rodata segment. We want to adjust up to
the same address within the page on the next page up. */
. = SEGMENT_START("rodata-segment", ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)));
.rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
.rodata1 : { *(.rodata1) }
.eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) }
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
.gnu_extab : ONLY_IF_RO { *(.gnu_extab*) }
/* These sections are generated by the Sun/Oracle C++ compiler. */
.exception_ranges : ONLY_IF_RO { *(.exception_ranges*) }
/* Adjust the address for the data segment. We want to adjust up to
the same address within the page on the next page up. */
. = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
/* Exception handling */
.eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.gnu_extab : ONLY_IF_RW { *(.gnu_extab) }
.gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
.exception_ranges : ONLY_IF_RW { *(.exception_ranges*) }
/* Thread Local Storage sections */
/* .tdata :
{
PROVIDE_HIDDEN (__tdata_start = .);
*(.tdata .tdata.* .gnu.linkonce.td.*)
}
.tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } */
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
}
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
PROVIDE_HIDDEN (__init_array_end = .);
}
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
PROVIDE_HIDDEN (__fini_array_end = .);
}
.ctors :
{
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
KEEP (*crtbegin?.o(.ctors))
/* We don't want to include the .ctor section from
the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
}
.dtors :
{
KEEP (*crtbegin.o(.dtors))
KEEP (*crtbegin?.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
}
.jcr : { KEEP (*(.jcr)) }
.data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }
.dynamic : { *(.dynamic) }
.got : { *(.got) *(.igot) }
. = DATA_SEGMENT_RELRO_END (SIZEOF (.got.plt) >= 24 ? 24 : 0, .);
.got.plt : { *(.got.plt) *(.igot.plt) }
.data :
{
*(.data .data.* .gnu.linkonce.d.*)
SORT(CONSTRUCTORS)
}
.data1 : { *(.data1) }
_edata = .; PROVIDE (edata = .);
. = .;
__bss_start = .;
.bss :
{
*(.dynbss)
*(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON)
/* Align here to ensure that the .bss section occupies space up to
_end. Align after .bss to ensure correct alignment even if the
.bss section disappears because there are no input sections.
FIXME: Why do we need it? When there is no .bss section, we do not
pad the .data section. */
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
.lbss :
{
*(.dynlbss)
*(.lbss .lbss.* .gnu.linkonce.lb.*)
*(LARGE_COMMON)
}
. = ALIGN(64 / 8);
. = SEGMENT_START("ldata-segment", .);
.lrodata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
{
*(.lrodata .lrodata.* .gnu.linkonce.lr.*)
}
.ldata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
{
*(.ldata .ldata.* .gnu.linkonce.l.*)
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
. = ALIGN(64 / 8);
_end = .; PROVIDE (end = .);
. = DATA_SEGMENT_END (.);
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
.gnu.build.attributes : { *(.gnu.build.attributes .gnu.build.attributes.*) }
/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */
/* DWARF 1 */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* GNU DWARF 1 extensions */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2 */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2 */
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* SGI/MIPS DWARF 2 extensions */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
/* DWARF 3 */
.debug_pubtypes 0 : { *(.debug_pubtypes) }
.debug_ranges 0 : { *(.debug_ranges) }
/* DWARF Extension. */
.debug_macro 0 : { *(.debug_macro) }
.debug_addr 0 : { *(.debug_addr) }
.gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
/DISCARD/ : {
*(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*)
/*
* XXX: As of now, ld.so links with relibc which has the main functionality. In the next refactor,
* ld.so will be moved out of relibc. So, till that time, we have to discard any sections
* that may reference use thread local storage.
*
* .init_array need to be not discarded unlike x86_64 linker variant
*/
*(.gnu.linkonce.tb.*) *(.tcommon)
}
}
+256
View File
@@ -0,0 +1,256 @@
/* Script for -z combreloc */
/* Copyright (C) 2014-2020 Free Software Foundation, Inc.
Copying and distribution of this script, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. */
OUTPUT_FORMAT("elf32-i386", "elf32-i386",
"elf32-i386")
OUTPUT_ARCH(i386)
ENTRY(_start)
SEARCH_DIR("/i686-unknown-redox/lib");
SEARCH_DIR("/usr/local/lib32");
SEARCH_DIR("/lib32");
SEARCH_DIR("/usr/lib32");
SEARCH_DIR("/usr/local/lib");
SEARCH_DIR("/lib");
SEARCH_DIR("/usr/lib");
SECTIONS
{
/* Read-only sections, merged into text segment: */
PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000)); . = SEGMENT_START("text-segment", 0x20000000) + SIZEOF_HEADERS;
.interp : { *(.interp) }
.note.gnu.build-id : { *(.note.gnu.build-id) }
.hash : { *(.hash) }
.gnu.hash : { *(.gnu.hash) }
.dynsym : { *(.dynsym) }
.dynstr : { *(.dynstr) }
.gnu.version : { *(.gnu.version) }
.gnu.version_d : { *(.gnu.version_d) }
.gnu.version_r : { *(.gnu.version_r) }
.rela.dyn :
{
*(.rela.init)
*(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
*(.rela.fini)
*(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
*(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
*(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
*(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
*(.rela.ctors)
*(.rela.dtors)
*(.rela.got)
*(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
*(.rela.ldata .rela.ldata.* .rela.gnu.linkonce.l.*)
*(.rela.lbss .rela.lbss.* .rela.gnu.linkonce.lb.*)
*(.rela.lrodata .rela.lrodata.* .rela.gnu.linkonce.lr.*)
*(.rela.ifunc)
}
.rela.plt :
{
*(.rela.plt)
PROVIDE_HIDDEN (__rela_iplt_start = .);
*(.rela.iplt)
PROVIDE_HIDDEN (__rela_iplt_end = .);
}
. = ALIGN(CONSTANT (MAXPAGESIZE));
.init :
{
KEEP (*(SORT_NONE(.init)))
}
.plt : { *(.plt) *(.iplt) }
.plt.got : { *(.plt.got) }
.plt.sec : { *(.plt.sec) }
.text :
{
*(.text.unlikely .text.*_unlikely .text.unlikely.*)
*(.text.exit .text.exit.*)
*(.text.startup .text.startup.*)
*(.text.hot .text.hot.*)
*(.text .stub .text.* .gnu.linkonce.t.*)
/* .gnu.warning sections are handled specially by elf.em. */
*(.gnu.warning)
}
.fini :
{
KEEP (*(SORT_NONE(.fini)))
}
PROVIDE (__etext = .);
PROVIDE (_etext = .);
PROVIDE (etext = .);
. = ALIGN(CONSTANT (MAXPAGESIZE));
/* Adjust the address for the rodata segment. We want to adjust up to
the same address within the page on the next page up. */
. = SEGMENT_START("rodata-segment", ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)));
.rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
.rodata1 : { *(.rodata1) }
.eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) }
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
.gnu_extab : ONLY_IF_RO { *(.gnu_extab*) }
/* These sections are generated by the Sun/Oracle C++ compiler. */
.exception_ranges : ONLY_IF_RO { *(.exception_ranges*) }
/* Adjust the address for the data segment. We want to adjust up to
the same address within the page on the next page up. */
. = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
/* Exception handling */
.eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.gnu_extab : ONLY_IF_RW { *(.gnu_extab) }
.gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
.exception_ranges : ONLY_IF_RW { *(.exception_ranges*) }
/* Thread Local Storage sections */
/* .tdata :
{
PROVIDE_HIDDEN (__tdata_start = .);
*(.tdata .tdata.* .gnu.linkonce.td.*)
}
.tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } */
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
}
/* .init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
PROVIDE_HIDDEN (__init_array_end = .);
} */
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
PROVIDE_HIDDEN (__fini_array_end = .);
}
.ctors :
{
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
KEEP (*crtbegin?.o(.ctors))
/* We don't want to include the .ctor section from
the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
}
.dtors :
{
KEEP (*crtbegin.o(.dtors))
KEEP (*crtbegin?.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
}
.jcr : { KEEP (*(.jcr)) }
.data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }
.dynamic : { *(.dynamic) }
.got : { *(.got) *(.igot) }
. = DATA_SEGMENT_RELRO_END (SIZEOF (.got.plt) >= 24 ? 24 : 0, .);
.got.plt : { *(.got.plt) *(.igot.plt) }
.data :
{
*(.data .data.* .gnu.linkonce.d.*)
SORT(CONSTRUCTORS)
}
.data1 : { *(.data1) }
_edata = .; PROVIDE (edata = .);
. = .;
__bss_start = .;
.bss :
{
*(.dynbss)
*(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON)
/* Align here to ensure that the .bss section occupies space up to
_end. Align after .bss to ensure correct alignment even if the
.bss section disappears because there are no input sections.
FIXME: Why do we need it? When there is no .bss section, we do not
pad the .data section. */
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
.lbss :
{
*(.dynlbss)
*(.lbss .lbss.* .gnu.linkonce.lb.*)
*(LARGE_COMMON)
}
. = ALIGN(64 / 8);
. = SEGMENT_START("ldata-segment", .);
.lrodata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
{
*(.lrodata .lrodata.* .gnu.linkonce.lr.*)
}
.ldata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
{
*(.ldata .ldata.* .gnu.linkonce.l.*)
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
. = ALIGN(64 / 8);
_end = .; PROVIDE (end = .);
. = DATA_SEGMENT_END (.);
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
.gnu.build.attributes : { *(.gnu.build.attributes .gnu.build.attributes.*) }
/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */
/* DWARF 1 */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* GNU DWARF 1 extensions */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2 */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2 */
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* SGI/MIPS DWARF 2 extensions */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
/* DWARF 3 */
.debug_pubtypes 0 : { *(.debug_pubtypes) }
.debug_ranges 0 : { *(.debug_ranges) }
/* DWARF Extension. */
.debug_macro 0 : { *(.debug_macro) }
.debug_addr 0 : { *(.debug_addr) }
.gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
/DISCARD/ : {
*(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*)
/*
* XXX: As of now, ld.so links with relibc which has the main functionality. In the next refactor,
* ld.so will be moved out of relibc. So, till that time, we have to discard any sections
* that may reference use thread local storage.
*
* .init_array also depends on TLS and is discarded as we don't need it.
*/
*(.gnu.linkonce.tb.*) *(.tcommon)
*(.init_array)
}
}
+256
View File
@@ -0,0 +1,256 @@
/* Script for -z combreloc */
/* Copyright (C) 2014-2020 Free Software Foundation, Inc.
Copying and distribution of this script, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. */
OUTPUT_FORMAT("elf32-i386", "elf32-i386",
"elf32-i386")
OUTPUT_ARCH(i386)
ENTRY(_start)
SEARCH_DIR("/i686-unknown-redox/lib");
SEARCH_DIR("/usr/local/lib32");
SEARCH_DIR("/lib32");
SEARCH_DIR("/usr/lib32");
SEARCH_DIR("/usr/local/lib");
SEARCH_DIR("/lib");
SEARCH_DIR("/usr/lib");
SECTIONS
{
/* Read-only sections, merged into text segment: */
PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000)); . = SEGMENT_START("text-segment", 0x20000000) + SIZEOF_HEADERS;
.interp : { *(.interp) }
.note.gnu.build-id : { *(.note.gnu.build-id) }
.hash : { *(.hash) }
.gnu.hash : { *(.gnu.hash) }
.dynsym : { *(.dynsym) }
.dynstr : { *(.dynstr) }
.gnu.version : { *(.gnu.version) }
.gnu.version_d : { *(.gnu.version_d) }
.gnu.version_r : { *(.gnu.version_r) }
.rela.dyn :
{
*(.rela.init)
*(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
*(.rela.fini)
*(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
*(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
*(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
*(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
*(.rela.ctors)
*(.rela.dtors)
*(.rela.got)
*(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
*(.rela.ldata .rela.ldata.* .rela.gnu.linkonce.l.*)
*(.rela.lbss .rela.lbss.* .rela.gnu.linkonce.lb.*)
*(.rela.lrodata .rela.lrodata.* .rela.gnu.linkonce.lr.*)
*(.rela.ifunc)
}
.rela.plt :
{
*(.rela.plt)
PROVIDE_HIDDEN (__rela_iplt_start = .);
*(.rela.iplt)
PROVIDE_HIDDEN (__rela_iplt_end = .);
}
. = ALIGN(CONSTANT (MAXPAGESIZE));
.init :
{
KEEP (*(SORT_NONE(.init)))
}
.plt : { *(.plt) *(.iplt) }
.plt.got : { *(.plt.got) }
.plt.sec : { *(.plt.sec) }
.text :
{
*(.text.unlikely .text.*_unlikely .text.unlikely.*)
*(.text.exit .text.exit.*)
*(.text.startup .text.startup.*)
*(.text.hot .text.hot.*)
*(.text .stub .text.* .gnu.linkonce.t.*)
/* .gnu.warning sections are handled specially by elf.em. */
*(.gnu.warning)
}
.fini :
{
KEEP (*(SORT_NONE(.fini)))
}
PROVIDE (__etext = .);
PROVIDE (_etext = .);
PROVIDE (etext = .);
. = ALIGN(CONSTANT (MAXPAGESIZE));
/* Adjust the address for the rodata segment. We want to adjust up to
the same address within the page on the next page up. */
. = SEGMENT_START("rodata-segment", ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)));
.rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
.rodata1 : { *(.rodata1) }
.eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) }
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
.gnu_extab : ONLY_IF_RO { *(.gnu_extab*) }
/* These sections are generated by the Sun/Oracle C++ compiler. */
.exception_ranges : ONLY_IF_RO { *(.exception_ranges*) }
/* Adjust the address for the data segment. We want to adjust up to
the same address within the page on the next page up. */
. = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
/* Exception handling */
.eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.gnu_extab : ONLY_IF_RW { *(.gnu_extab) }
.gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
.exception_ranges : ONLY_IF_RW { *(.exception_ranges*) }
/* Thread Local Storage sections */
/* .tdata :
{
PROVIDE_HIDDEN (__tdata_start = .);
*(.tdata .tdata.* .gnu.linkonce.td.*)
}
.tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } */
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
}
/* .init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
PROVIDE_HIDDEN (__init_array_end = .);
} */
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
PROVIDE_HIDDEN (__fini_array_end = .);
}
.ctors :
{
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
KEEP (*crtbegin?.o(.ctors))
/* We don't want to include the .ctor section from
the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
}
.dtors :
{
KEEP (*crtbegin.o(.dtors))
KEEP (*crtbegin?.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
}
.jcr : { KEEP (*(.jcr)) }
.data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }
.dynamic : { *(.dynamic) }
.got : { *(.got) *(.igot) }
. = DATA_SEGMENT_RELRO_END (SIZEOF (.got.plt) >= 24 ? 24 : 0, .);
.got.plt : { *(.got.plt) *(.igot.plt) }
.data :
{
*(.data .data.* .gnu.linkonce.d.*)
SORT(CONSTRUCTORS)
}
.data1 : { *(.data1) }
_edata = .; PROVIDE (edata = .);
. = .;
__bss_start = .;
.bss :
{
*(.dynbss)
*(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON)
/* Align here to ensure that the .bss section occupies space up to
_end. Align after .bss to ensure correct alignment even if the
.bss section disappears because there are no input sections.
FIXME: Why do we need it? When there is no .bss section, we do not
pad the .data section. */
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
.lbss :
{
*(.dynlbss)
*(.lbss .lbss.* .gnu.linkonce.lb.*)
*(LARGE_COMMON)
}
. = ALIGN(64 / 8);
. = SEGMENT_START("ldata-segment", .);
.lrodata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
{
*(.lrodata .lrodata.* .gnu.linkonce.lr.*)
}
.ldata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
{
*(.ldata .ldata.* .gnu.linkonce.l.*)
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
. = ALIGN(64 / 8);
_end = .; PROVIDE (end = .);
. = DATA_SEGMENT_END (.);
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
.gnu.build.attributes : { *(.gnu.build.attributes .gnu.build.attributes.*) }
/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */
/* DWARF 1 */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* GNU DWARF 1 extensions */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2 */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2 */
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* SGI/MIPS DWARF 2 extensions */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
/* DWARF 3 */
.debug_pubtypes 0 : { *(.debug_pubtypes) }
.debug_ranges 0 : { *(.debug_ranges) }
/* DWARF Extension. */
.debug_macro 0 : { *(.debug_macro) }
.debug_addr 0 : { *(.debug_addr) }
.gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
/DISCARD/ : {
*(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*)
/*
* XXX: As of now, ld.so links with relibc which has the main functionality. In the next refactor,
* ld.so will be moved out of relibc. So, till that time, we have to discard any sections
* that may reference use thread local storage.
*
* .init_array also depends on TLS and is discarded as we don't need it.
*/
*(.gnu.linkonce.tb.*) *(.tcommon)
*(.init_array)
}
}
+247
View File
@@ -0,0 +1,247 @@
/* Script for -z combreloc */
/* Copyright (C) 2014-2020 Free Software Foundation, Inc.
Copying and distribution of this script, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. */
OUTPUT_FORMAT("elf64-littleriscv", "elf64-littleriscv", "elf64-littleriscv" )
OUTPUT_ARCH(riscv)
ENTRY(_start)
SEARCH_DIR("/riscv64-unknown-redox/lib");
SEARCH_DIR("/usr/local/lib64");
SEARCH_DIR("/lib64");
SEARCH_DIR("/usr/lib64");
SEARCH_DIR("/usr/local/lib");
SEARCH_DIR("/lib");
SEARCH_DIR("/usr/lib");
SECTIONS
{
/* Read-only sections, merged into text segment: */
PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000)); . = SEGMENT_START("text-segment", 0x20000000) + SIZEOF_HEADERS;
.interp : { *(.interp) }
.note.gnu.build-id : { *(.note.gnu.build-id) }
.hash : { *(.hash) }
.gnu.hash : { *(.gnu.hash) }
.dynsym : { *(.dynsym) }
.dynstr : { *(.dynstr) }
.gnu.version : { *(.gnu.version) }
.gnu.version_d : { *(.gnu.version_d) }
.gnu.version_r : { *(.gnu.version_r) }
.rela.dyn :
{
*(.rela.init)
*(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
*(.rela.fini)
*(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
*(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
*(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
*(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
*(.rela.ctors)
*(.rela.dtors)
*(.rela.got)
*(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
*(.rela.ldata .rela.ldata.* .rela.gnu.linkonce.l.*)
*(.rela.lbss .rela.lbss.* .rela.gnu.linkonce.lb.*)
*(.rela.lrodata .rela.lrodata.* .rela.gnu.linkonce.lr.*)
*(.rela.ifunc)
}
.rela.plt :
{
*(.rela.plt)
PROVIDE_HIDDEN (__rela_iplt_start = .);
*(.rela.iplt)
PROVIDE_HIDDEN (__rela_iplt_end = .);
}
. = ALIGN(CONSTANT (MAXPAGESIZE));
.plt : { *(.plt) *(.iplt) }
.plt.got : { *(.plt.got) }
.plt.sec : { *(.plt.sec) }
.text :
{
*(.text.unlikely .text.*_unlikely .text.unlikely.*)
*(.text.exit .text.exit.*)
*(.text.startup .text.startup.*)
*(.text.hot .text.hot.*)
*(.text .stub .text.* .gnu.linkonce.t.*)
/* .gnu.warning sections are handled specially by elf.em. */
*(.gnu.warning)
}
PROVIDE (__etext = .);
PROVIDE (_etext = .);
PROVIDE (etext = .);
. = ALIGN(CONSTANT (MAXPAGESIZE));
/* Adjust the address for the rodata segment. We want to adjust up to
the same address within the page on the next page up. */
. = SEGMENT_START("rodata-segment", ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)));
.rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
.rodata1 : { *(.rodata1) }
.eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) }
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
.gnu_extab : ONLY_IF_RO { *(.gnu_extab*) }
/* These sections are generated by the Sun/Oracle C++ compiler. */
.exception_ranges : ONLY_IF_RO { *(.exception_ranges*) }
/* Adjust the address for the data segment. We want to adjust up to
the same address within the page on the next page up. */
. = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
/* Exception handling */
.eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.gnu_extab : ONLY_IF_RW { *(.gnu_extab) }
.gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
.exception_ranges : ONLY_IF_RW { *(.exception_ranges*) }
/* Thread Local Storage sections */
/* .tdata :
{
PROVIDE_HIDDEN (__tdata_start = .);
*(.tdata .tdata.* .gnu.linkonce.td.*)
}
.tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } */
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
}
/* .init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
PROVIDE_HIDDEN (__init_array_end = .);
} */
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
PROVIDE_HIDDEN (__fini_array_end = .);
}
.ctors :
{
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
KEEP (*crtbegin?.o(.ctors))
/* We don't want to include the .ctor section from
the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
}
.dtors :
{
KEEP (*crtbegin.o(.dtors))
KEEP (*crtbegin?.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
}
.jcr : { KEEP (*(.jcr)) }
.data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }
.dynamic : { *(.dynamic) }
.got : { *(.got) *(.igot) }
. = DATA_SEGMENT_RELRO_END (SIZEOF (.got.plt) >= 24 ? 24 : 0, .);
.got.plt : { *(.got.plt) *(.igot.plt) }
.data :
{
*(.data .data.* .gnu.linkonce.d.*)
SORT(CONSTRUCTORS)
}
.data1 : { *(.data1) }
_edata = .; PROVIDE (edata = .);
. = .;
__bss_start = .;
.bss :
{
*(.dynbss)
*(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON)
/* Align here to ensure that the .bss section occupies space up to
_end. Align after .bss to ensure correct alignment even if the
.bss section disappears because there are no input sections.
FIXME: Why do we need it? When there is no .bss section, we do not
pad the .data section. */
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
.lbss :
{
*(.dynlbss)
*(.lbss .lbss.* .gnu.linkonce.lb.*)
*(LARGE_COMMON)
}
. = ALIGN(64 / 8);
. = SEGMENT_START("ldata-segment", .);
.lrodata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
{
*(.lrodata .lrodata.* .gnu.linkonce.lr.*)
}
.ldata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
{
*(.ldata .ldata.* .gnu.linkonce.l.*)
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
. = ALIGN(64 / 8);
_end = .; PROVIDE (end = .);
. = DATA_SEGMENT_END (.);
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
.gnu.build.attributes : { *(.gnu.build.attributes .gnu.build.attributes.*) }
/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */
/* DWARF 1 */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* GNU DWARF 1 extensions */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2 */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2 */
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* SGI/MIPS DWARF 2 extensions */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
/* DWARF 3 */
.debug_pubtypes 0 : { *(.debug_pubtypes) }
.debug_ranges 0 : { *(.debug_ranges) }
/* DWARF Extension. */
.debug_macro 0 : { *(.debug_macro) }
.debug_addr 0 : { *(.debug_addr) }
.gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
/DISCARD/ : {
*(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*)
/*
* XXX: As of now, ld.so links with relibc which has the main functionality. In the next refactor,
* ld.so will be moved out of relibc. So, till that time, we have to discard any sections
* that may reference use thread local storage.
*
* .init_array also depends on TLS and is discarded as we don't need it.
*/
*(.gnu.linkonce.tb.*) *(.tcommon)
*(.init_array)
}
}
+259
View File
@@ -0,0 +1,259 @@
/* Script for -z combreloc */
/* Copyright (C) 2014-2020 Free Software Foundation, Inc.
Copying and distribution of this script, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. */
OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64",
"elf64-x86-64")
OUTPUT_ARCH(i386:x86-64)
ENTRY(_start)
SEARCH_DIR("/usr/x86_64-pc-linux-gnu/lib64");
SEARCH_DIR("/usr/lib64/binutils/x86_64-pc-linux-gnu/2.33.164");
SEARCH_DIR("/usr/local/lib64");
SEARCH_DIR("/lib64");
SEARCH_DIR("/usr/lib64");
SEARCH_DIR("/usr/x86_64-pc-linux-gnu/lib");
SEARCH_DIR("/usr/lib64/binutils/x86_64-pc-linux-gnu/2.33.1");
SEARCH_DIR("/usr/local/lib");
SEARCH_DIR("/lib");
SEARCH_DIR("/usr/lib");
SECTIONS
{
/* Read-only sections, merged into text segment: */
PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000)); . = SEGMENT_START("text-segment", 0x20000000) + SIZEOF_HEADERS;
.interp : { *(.interp) }
.note.gnu.build-id : { *(.note.gnu.build-id) }
.hash : { *(.hash) }
.gnu.hash : { *(.gnu.hash) }
.dynsym : { *(.dynsym) }
.dynstr : { *(.dynstr) }
.gnu.version : { *(.gnu.version) }
.gnu.version_d : { *(.gnu.version_d) }
.gnu.version_r : { *(.gnu.version_r) }
.rela.dyn :
{
*(.rela.init)
*(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
*(.rela.fini)
*(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
*(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
*(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
*(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
*(.rela.ctors)
*(.rela.dtors)
*(.rela.got)
*(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
*(.rela.ldata .rela.ldata.* .rela.gnu.linkonce.l.*)
*(.rela.lbss .rela.lbss.* .rela.gnu.linkonce.lb.*)
*(.rela.lrodata .rela.lrodata.* .rela.gnu.linkonce.lr.*)
*(.rela.ifunc)
}
.rela.plt :
{
*(.rela.plt)
PROVIDE_HIDDEN (__rela_iplt_start = .);
*(.rela.iplt)
PROVIDE_HIDDEN (__rela_iplt_end = .);
}
. = ALIGN(CONSTANT (MAXPAGESIZE));
.init :
{
KEEP (*(SORT_NONE(.init)))
}
.plt : { *(.plt) *(.iplt) }
.plt.got : { *(.plt.got) }
.plt.sec : { *(.plt.sec) }
.text :
{
*(.text.unlikely .text.*_unlikely .text.unlikely.*)
*(.text.exit .text.exit.*)
*(.text.startup .text.startup.*)
*(.text.hot .text.hot.*)
*(.text .stub .text.* .gnu.linkonce.t.*)
/* .gnu.warning sections are handled specially by elf.em. */
*(.gnu.warning)
}
.fini :
{
KEEP (*(SORT_NONE(.fini)))
}
PROVIDE (__etext = .);
PROVIDE (_etext = .);
PROVIDE (etext = .);
. = ALIGN(CONSTANT (MAXPAGESIZE));
/* Adjust the address for the rodata segment. We want to adjust up to
the same address within the page on the next page up. */
. = SEGMENT_START("rodata-segment", ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)));
.rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
.rodata1 : { *(.rodata1) }
.eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) }
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
.gnu_extab : ONLY_IF_RO { *(.gnu_extab*) }
/* These sections are generated by the Sun/Oracle C++ compiler. */
.exception_ranges : ONLY_IF_RO { *(.exception_ranges*) }
/* Adjust the address for the data segment. We want to adjust up to
the same address within the page on the next page up. */
. = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
/* Exception handling */
.eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.gnu_extab : ONLY_IF_RW { *(.gnu_extab) }
.gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
.exception_ranges : ONLY_IF_RW { *(.exception_ranges*) }
/* Thread Local Storage sections */
/* .tdata : ALIGN(4K)
{
PROVIDE_HIDDEN (__tdata_start = .);
*(.tdata .tdata.* .gnu.linkonce.td.*)
}
.tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } */
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
}
/* .init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
PROVIDE_HIDDEN (__init_array_end = .);
} */
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
PROVIDE_HIDDEN (__fini_array_end = .);
}
.ctors :
{
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
KEEP (*crtbegin?.o(.ctors))
/* We don't want to include the .ctor section from
the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
}
.dtors :
{
KEEP (*crtbegin.o(.dtors))
KEEP (*crtbegin?.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
}
.jcr : { KEEP (*(.jcr)) }
.data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }
.dynamic : { *(.dynamic) }
.got : { *(.got) *(.igot) }
. = DATA_SEGMENT_RELRO_END (SIZEOF (.got.plt) >= 24 ? 24 : 0, .);
.got.plt : { *(.got.plt) *(.igot.plt) }
.data :
{
*(.data .data.* .gnu.linkonce.d.*)
SORT(CONSTRUCTORS)
}
.data1 : { *(.data1) }
_edata = .; PROVIDE (edata = .);
. = .;
__bss_start = .;
.bss :
{
*(.dynbss)
*(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON)
/* Align here to ensure that the .bss section occupies space up to
_end. Align after .bss to ensure correct alignment even if the
.bss section disappears because there are no input sections.
FIXME: Why do we need it? When there is no .bss section, we do not
pad the .data section. */
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
.lbss :
{
*(.dynlbss)
*(.lbss .lbss.* .gnu.linkonce.lb.*)
*(LARGE_COMMON)
}
. = ALIGN(64 / 8);
. = SEGMENT_START("ldata-segment", .);
.lrodata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
{
*(.lrodata .lrodata.* .gnu.linkonce.lr.*)
}
.ldata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
{
*(.ldata .ldata.* .gnu.linkonce.l.*)
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
. = ALIGN(64 / 8);
_end = .; PROVIDE (end = .);
. = DATA_SEGMENT_END (.);
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
.gnu.build.attributes : { *(.gnu.build.attributes .gnu.build.attributes.*) }
/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */
/* DWARF 1 */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* GNU DWARF 1 extensions */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2 */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2 */
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* SGI/MIPS DWARF 2 extensions */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
/* DWARF 3 */
.debug_pubtypes 0 : { *(.debug_pubtypes) }
.debug_ranges 0 : { *(.debug_ranges) }
/* DWARF Extension. */
.debug_macro 0 : { *(.debug_macro) }
.debug_addr 0 : { *(.debug_addr) }
.gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
/DISCARD/ : {
*(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*)
/*
* XXX: As of now, ld.so links with relibc which has the main functionality. In the next refactor,
* ld.so will be moved out of relibc. So, till that time, we have to discard any sections
* that may reference use thread local storage.
*
* .init_array also depends on TLS and is discarded as we don't need it.
*/
*(.gnu.linkonce.tb.*) *(.tcommon)
*(.init_array)
}
}
+256
View File
@@ -0,0 +1,256 @@
/* Script for -z combreloc */
/* Copyright (C) 2014-2020 Free Software Foundation, Inc.
Copying and distribution of this script, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. */
OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64",
"elf64-x86-64")
OUTPUT_ARCH(i386:x86-64)
ENTRY(_start)
SEARCH_DIR("/x86_64-unknown-redox/lib");
SEARCH_DIR("/usr/local/lib64");
SEARCH_DIR("/lib64");
SEARCH_DIR("/usr/lib64");
SEARCH_DIR("/usr/local/lib");
SEARCH_DIR("/lib");
SEARCH_DIR("/usr/lib");
SECTIONS
{
/* Read-only sections, merged into text segment: */
PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000)); . = SEGMENT_START("text-segment", 0x20000000) + SIZEOF_HEADERS;
.interp : { *(.interp) }
.note.gnu.build-id : { *(.note.gnu.build-id) }
.hash : { *(.hash) }
.gnu.hash : { *(.gnu.hash) }
.dynsym : { *(.dynsym) }
.dynstr : { *(.dynstr) }
.gnu.version : { *(.gnu.version) }
.gnu.version_d : { *(.gnu.version_d) }
.gnu.version_r : { *(.gnu.version_r) }
.rela.dyn :
{
*(.rela.init)
*(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
*(.rela.fini)
*(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
*(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
*(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
*(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
*(.rela.ctors)
*(.rela.dtors)
*(.rela.got)
*(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
*(.rela.ldata .rela.ldata.* .rela.gnu.linkonce.l.*)
*(.rela.lbss .rela.lbss.* .rela.gnu.linkonce.lb.*)
*(.rela.lrodata .rela.lrodata.* .rela.gnu.linkonce.lr.*)
*(.rela.ifunc)
}
.rela.plt :
{
*(.rela.plt)
PROVIDE_HIDDEN (__rela_iplt_start = .);
*(.rela.iplt)
PROVIDE_HIDDEN (__rela_iplt_end = .);
}
. = ALIGN(CONSTANT (MAXPAGESIZE));
.init :
{
KEEP (*(SORT_NONE(.init)))
}
.plt : { *(.plt) *(.iplt) }
.plt.got : { *(.plt.got) }
.plt.sec : { *(.plt.sec) }
.text :
{
*(.text.unlikely .text.*_unlikely .text.unlikely.*)
*(.text.exit .text.exit.*)
*(.text.startup .text.startup.*)
*(.text.hot .text.hot.*)
*(.text .stub .text.* .gnu.linkonce.t.*)
/* .gnu.warning sections are handled specially by elf.em. */
*(.gnu.warning)
}
.fini :
{
KEEP (*(SORT_NONE(.fini)))
}
PROVIDE (__etext = .);
PROVIDE (_etext = .);
PROVIDE (etext = .);
. = ALIGN(CONSTANT (MAXPAGESIZE));
/* Adjust the address for the rodata segment. We want to adjust up to
the same address within the page on the next page up. */
. = SEGMENT_START("rodata-segment", ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)));
.rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
.rodata1 : { *(.rodata1) }
.eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) }
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
.gnu_extab : ONLY_IF_RO { *(.gnu_extab*) }
/* These sections are generated by the Sun/Oracle C++ compiler. */
.exception_ranges : ONLY_IF_RO { *(.exception_ranges*) }
/* Adjust the address for the data segment. We want to adjust up to
the same address within the page on the next page up. */
. = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
/* Exception handling */
.eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.gnu_extab : ONLY_IF_RW { *(.gnu_extab) }
.gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
.exception_ranges : ONLY_IF_RW { *(.exception_ranges*) }
/* Thread Local Storage sections */
/* .tdata : ALIGN(4K)
{
PROVIDE_HIDDEN (__tdata_start = .);
*(.tdata .tdata.* .gnu.linkonce.td.*)
}
.tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } */
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
}
/* .init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
PROVIDE_HIDDEN (__init_array_end = .);
} */
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
PROVIDE_HIDDEN (__fini_array_end = .);
}
.ctors :
{
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
KEEP (*crtbegin?.o(.ctors))
/* We don't want to include the .ctor section from
the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
}
.dtors :
{
KEEP (*crtbegin.o(.dtors))
KEEP (*crtbegin?.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
}
.jcr : { KEEP (*(.jcr)) }
.data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }
.dynamic : { *(.dynamic) }
.got : { *(.got) *(.igot) }
. = DATA_SEGMENT_RELRO_END (SIZEOF (.got.plt) >= 24 ? 24 : 0, .);
.got.plt : { *(.got.plt) *(.igot.plt) }
.data :
{
*(.data .data.* .gnu.linkonce.d.*)
SORT(CONSTRUCTORS)
}
.data1 : { *(.data1) }
_edata = .; PROVIDE (edata = .);
. = .;
__bss_start = .;
.bss :
{
*(.dynbss)
*(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON)
/* Align here to ensure that the .bss section occupies space up to
_end. Align after .bss to ensure correct alignment even if the
.bss section disappears because there are no input sections.
FIXME: Why do we need it? When there is no .bss section, we do not
pad the .data section. */
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
.lbss :
{
*(.dynlbss)
*(.lbss .lbss.* .gnu.linkonce.lb.*)
*(LARGE_COMMON)
}
. = ALIGN(64 / 8);
. = SEGMENT_START("ldata-segment", .);
.lrodata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
{
*(.lrodata .lrodata.* .gnu.linkonce.lr.*)
}
.ldata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
{
*(.ldata .ldata.* .gnu.linkonce.l.*)
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
. = ALIGN(64 / 8);
_end = .; PROVIDE (end = .);
. = DATA_SEGMENT_END (.);
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
.gnu.build.attributes : { *(.gnu.build.attributes .gnu.build.attributes.*) }
/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */
/* DWARF 1 */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* GNU DWARF 1 extensions */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2 */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2 */
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* SGI/MIPS DWARF 2 extensions */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
/* DWARF 3 */
.debug_pubtypes 0 : { *(.debug_pubtypes) }
.debug_ranges 0 : { *(.debug_ranges) }
/* DWARF Extension. */
.debug_macro 0 : { *(.debug_macro) }
.debug_addr 0 : { *(.debug_addr) }
.gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
/DISCARD/ : {
*(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*)
/*
* XXX: As of now, ld.so links with relibc which has the main functionality. In the next refactor,
* ld.so will be moved out of relibc. So, till that time, we have to discard any sections
* that may reference use thread local storage.
*
* .init_array also depends on TLS and is discarded as we don't need it.
*/
*(.gnu.linkonce.tb.*) *(.tcommon)
*(.init_array)
}
}
+136
View File
@@ -0,0 +1,136 @@
#![no_std]
#![feature(linkage)]
#![deny(unsafe_op_in_unsafe_fn)]
use core::arch::global_asm;
#[cfg(target_arch = "aarch64")]
global_asm!(
"
.weak _DYNAMIC
.hidden _DYNAMIC
.global _start
_start:
mov x28, sp
// align stack to 16 bytes
and sp, x28, #0xfffffffffffffff0
adr x1, _start
mov x0, x28
adrp x2, _DYNAMIC
add x2, x2, #:lo12:_DYNAMIC
// ld_so_start(stack=x0, ld_entry=x1, dynamic=x2)
bl relibc_ld_so_start
// restore original stack, clear registers, and jump to the new start function
mov sp, x28
mov x1, xzr
mov x2, xzr
mov x3, xzr
mov x4, xzr
mov x5, xzr
mov x6, xzr
mov x7, xzr
mov x8, xzr
mov x9, xzr
mov x10, xzr
mov x11, xzr
mov x12, xzr
mov x13, xzr
mov x14, xzr
mov x15, xzr
mov x16, xzr
mov x17, xzr
mov x18, xzr
mov x19, xzr
mov x20, xzr
mov x21, xzr
mov x22, xzr
mov x23, xzr
mov x24, xzr
mov x25, xzr
mov x26, xzr
mov x27, xzr
mov x28, xzr
mov x29, xzr
mov x30, xzr
br x0
udf #0
"
);
#[cfg(target_arch = "x86")]
global_asm!(
"
.globl _start
_start:
push esp
call relibc_ld_so_start
pop esp
# TODO: x86
ud2
"
);
#[cfg(target_arch = "x86_64")]
global_asm!(
"
.weak _DYNAMIC
.hidden _DYNAMIC
.globl _start
_start:
lea rsi, [rip + _start]
# Save original stack and align stack to 16 bytes
mov rbp, rsp
and rsp, 0xfffffffffffffff0
# Call ld_so_start(stack=rdi, ld_entry=rsi, dynamic=rdx)
mov rdi, rbp
lea rdx, [rip + _DYNAMIC]
call relibc_ld_so_start
# Restore original stack, clear registers, and jump to new start function
mov rsp, rbp
xor rcx, rcx
xor rdx, rdx
xor rdi, rdi
xor rsi, rsi
xor r8, r8
xor r9, r9
xor r10, r10
xor r11, r11
fninit
jmp rax
ud2
"
);
#[cfg(target_arch = "riscv64")]
global_asm!(
"
.globl _start
_start:
mv a0, sp
jal relibc_ld_so_start
unimp
"
);
#[unsafe(no_mangle)]
pub unsafe extern "C" fn main(_argc: isize, _argv: *const *const i8) -> usize {
// LD
0x1D
}
#[linkage = "weak"]
#[unsafe(no_mangle)]
extern "C" fn relibc_panic(_pi: &::core::panic::PanicInfo) -> ! {
loop {}
}
#[panic_handler]
#[linkage = "weak"]
pub unsafe fn rust_begin_unwind(pi: &::core::panic::PanicInfo) -> ! {
relibc_panic(pi)
}
Submodule
+1
Submodule openlibm added at e2da0dafd3
+13
View File
@@ -0,0 +1,13 @@
[package]
name = "redox-ioctl"
authors = ["bjorn3 <bjorn3_gh@protonmail.com>"]
version = "0.1.0"
edition = "2024"
license = "MIT"
description = "Ioctl definitions and (de)serialization for Redox"
[dependencies]
drm-sys = "0.8.0"
redox_syscall = { path = "../../syscall" }
[features]
+319
View File
@@ -0,0 +1,319 @@
use alloc::vec::Vec;
use core::{
cmp,
ffi::{c_char, c_int, c_uint},
iter, mem, slice,
};
use drm_sys::drm_clip_rect;
pub use drm_sys::{
__kernel_size_t, DRM_PROP_NAME_LEN, drm_get_cap, drm_mode_card_res,
drm_mode_connector_set_property, drm_mode_create_dumb, drm_mode_crtc,
drm_mode_crtc_page_flip_target, drm_mode_cursor, drm_mode_cursor2, drm_mode_destroy_dumb,
drm_mode_fb_cmd, drm_mode_fb_cmd2, drm_mode_fb_dirty_cmd, drm_mode_get_blob,
drm_mode_get_connector, drm_mode_get_encoder, drm_mode_get_plane, drm_mode_get_plane_res,
drm_mode_get_property, drm_mode_map_dumb, drm_mode_modeinfo, drm_mode_obj_get_properties,
drm_mode_property_enum, drm_mode_set_plane, drm_set_client_cap, drm_version,
};
pub const VERSION: u64 = 0;
define_ioctl_data! {
struct drm_version, DrmVersion {
version_major: c_int,
version_minor: c_int,
version_patchlevel: c_int,
name_len: __kernel_size_t,
name: *mut c_char [array<c_char, name_len>],
date_len: __kernel_size_t,
date: *mut c_char [array<c_char, date_len>],
desc_len: __kernel_size_t,
desc: *mut c_char [array<c_char, desc_len>],
}
}
pub const GET_CAP: u64 = 0x0C;
pub use drm_sys::DRM_CAP_DUMB_BUFFER;
define_ioctl_data! {
struct drm_get_cap, DrmGetCap {
capability: u64,
value: u64,
}
}
pub const SET_CLIENT_CAP: u64 = 0x0D;
pub use drm_sys::DRM_CLIENT_CAP_CURSOR_PLANE_HOTSPOT;
define_ioctl_data! {
struct drm_set_client_cap, DrmSetClientCap {
capability: u64,
value: u64,
}
}
pub const MODE_CARD_RES: u64 = 0xA0;
define_ioctl_data! {
struct drm_mode_card_res, DrmModeCardRes {
fb_id_ptr: u64 [array<u32, count_fbs>],
crtc_id_ptr: u64 [array<u32, count_crtcs>],
connector_id_ptr: u64 [array<u32, count_connectors>],
encoder_id_ptr: u64 [array<u32, count_encoders>],
count_fbs: u32,
count_crtcs: u32,
count_connectors: u32,
count_encoders: u32,
min_width: u32,
max_width: u32,
min_height: u32,
max_height: u32,
}
}
pub const MODE_GET_CRTC: u64 = 0xA1;
pub const MODE_SET_CRTC: u64 = 0xA2;
define_ioctl_data! {
struct drm_mode_crtc, DrmModeCrtc {
set_connectors_ptr: u64 [array<u32, count_connectors>],
count_connectors: u32,
crtc_id: u32,
fb_id: u32,
x: u32,
y: u32,
gamma_size: u32,
mode_valid: u32,
mode: drm_mode_modeinfo,
}
}
pub const MODE_CURSOR: u64 = 0xA3;
define_ioctl_data! {
struct drm_mode_cursor, DrmModeCursor {
flags: u32,
crtc_id: u32,
x: i32,
y:i32,
width:u32,
height:u32,
handle:u32,
}
}
pub const MODE_GET_ENCODER: u64 = 0xA6;
define_ioctl_data! {
struct drm_mode_get_encoder, DrmModeGetEncoder {
encoder_id: u32,
encoder_type: u32,
crtc_id: u32,
possible_crtcs: u32,
possible_clones: u32,
}
}
pub const MODE_GET_CONNECTOR: u64 = 0xA7;
define_ioctl_data! {
struct drm_mode_get_connector, DrmModeGetConnector {
encoders_ptr: u64 [array<u32, count_encoders>],
modes_ptr: u64 [array<drm_mode_modeinfo, count_modes>],
props_ptr: u64 [array<u32, count_props>],
prop_values_ptr: u64 [array<u64, count_props>],
count_modes: u32,
count_props: u32,
count_encoders: u32,
encoder_id: u32,
connector_id: u32,
connector_type: u32,
connector_type_id: u32,
connection: u32,
mm_width: u32,
mm_height: u32,
subpixel: u32,
pad: u32,
}
}
pub const MODE_GET_PROPERTY: u64 = 0xAA;
define_ioctl_data! {
struct drm_mode_get_property, DrmModeGetProperty {
values_ptr: u64 [array<u64, count_values>],
enum_blob_ptr: u64 [array<drm_mode_property_enum, count_enum_blobs>],
prop_id: u32,
flags: u32,
name: [c_char; DRM_PROP_NAME_LEN as usize],
count_values: u32,
count_enum_blobs: u32,
}
}
pub const MODE_SET_PROPERTY: u64 = 0xAB;
define_ioctl_data! {
struct drm_mode_connector_set_property, DrmModeConnectorSetProperty {
value: u64,
prop_id: u32,
connector_id: u32,
}
}
pub const MODE_GET_PROP_BLOB: u64 = 0xAC;
define_ioctl_data! {
struct drm_mode_get_blob, DrmModeGetBlob {
blob_id: u32,
length: u32,
data: u64 [array<u8, length>],
}
}
pub const MODE_GET_FB: u64 = 0xAD;
pub const MODE_ADD_FB: u64 = 0xAE;
define_ioctl_data! {
struct drm_mode_fb_cmd, DrmModeFbCmd {
fb_id: u32,
width: u32,
height: u32,
pitch: u32,
bpp: u32,
depth: u32,
handle: u32,
}
}
pub const MODE_RM_FB: u64 = 0xAF;
define_ioctl_data! {
struct standin_for_uint, StandinForUint {
inner: c_uint,
}
}
#[repr(transparent)]
#[allow(non_camel_case_types)]
pub struct standin_for_uint {
pub inner: c_uint,
}
pub const MODE_PAGE_FLIP: u64 = 0xB0;
define_ioctl_data! {
struct drm_mode_crtc_page_flip_target, DrmModeCrtcPageFlipTarget {
crtc_id: u32,
fb_id: u32,
flags: u32,
sequence: u32,
user_data: u64,
}
}
pub const MODE_DIRTYFB: u64 = 0xB1;
define_ioctl_data! {
struct drm_mode_fb_dirty_cmd, DrmModeFbDirtyCmd {
fb_id: u32,
flags: u32,
color: u32,
num_clips: u32,
clips_ptr: u64 [array<drm_clip_rect, num_clips>],
}
}
pub const MODE_CREATE_DUMB: u64 = 0xB2;
define_ioctl_data! {
struct drm_mode_create_dumb, DrmModeCreateDumb {
height: u32,
width: u32,
bpp: u32,
flags: u32,
handle: u32,
pitch: u32,
size: u64,
}
}
pub const MODE_MAP_DUMB: u64 = 0xB3;
define_ioctl_data! {
struct drm_mode_map_dumb, DrmModeMapDumb {
handle: u32,
pad: u32,
offset: u64,
}
}
pub const MODE_DESTROY_DUMB: u64 = 0xB4;
define_ioctl_data! {
struct drm_mode_destroy_dumb, DrmModeDestroyDumb {
handle: u32,
}
}
pub const MODE_GET_PLANE_RES: u64 = 0xB5;
define_ioctl_data! {
struct drm_mode_get_plane_res, DrmModeGetPlaneRes {
plane_id_ptr: u64 [array<u32, count_planes>],
count_planes: u32,
}
}
pub const MODE_GET_PLANE: u64 = 0xB6;
define_ioctl_data! {
struct drm_mode_get_plane, DrmModeGetPlane {
plane_id: u32,
crtc_id: u32,
fb_id: u32,
possible_crtcs: u32,
gamma_size: u32,
count_format_types: u32,
format_type_ptr: u64 [array<u32, count_format_types>],
}
}
pub const MODE_SET_PLANE: u64 = 0xB7;
define_ioctl_data! {
struct drm_mode_set_plane, DrmModeSetPlane {
plane_id: u32,
crtc_id: u32,
fb_id: u32,
flags: u32,
crtc_x: i32,
crtc_y: i32,
crtc_w: u32,
crtc_h: u32,
src_x: u32,
src_y: u32,
src_h: u32,
src_w: u32,
}
}
pub const MODE_OBJ_GET_PROPERTIES: u64 = 0xB9;
define_ioctl_data! {
struct drm_mode_obj_get_properties, DrmModeObjGetProperties {
props_ptr: u64 [array<u32, count_props>],
prop_values_ptr: u64 [array<u64, count_props>],
count_props: u32,
obj_id: u32,
obj_type: u32,
}
}
pub const MODE_CURSOR2: u64 = 0xBB;
define_ioctl_data! {
struct drm_mode_cursor2, DrmModeCursor2 {
flags: u32,
crtc_id: u32,
x: i32,
y: i32,
width: u32,
height: u32,
handle: u32,
hot_x: i32,
hot_y: i32,
}
}
pub const MODE_GET_FB2: u64 = 0xCE;
define_ioctl_data! {
struct drm_mode_fb_cmd2, DrmModeFbCmd2 {
fb_id: u32,
width: u32,
height: u32,
pixel_format: u32,
flags: u32,
handles: [u32; 4],
pitches: [u32; 4],
offsets: [u32; 4],
modifier: [u64; 4],
}
}
+169
View File
@@ -0,0 +1,169 @@
use alloc::vec::Vec;
pub trait IoctlData {
unsafe fn write(&self) -> Vec<u8>;
unsafe fn read_from(&mut self, buf: &[u8]);
}
macro_rules! define_ioctl_data {
(struct $ioctl_ty:ident, $mem_ty:ident {
$($rest:tt)*
}) => {
define_ioctl_data!(
struct $ioctl_ty, $mem_ty { $($rest)* } => (), (), ()
);
};
(struct $ioctl_ty:ident, $mem_ty:ident {
$field:ident: $ty:ty,
$($rest:tt)*
} =>
($($ioctl_fields:tt)*),
($($counted_fields:tt)*),
($($noncounted_fields:tt)*)
) => {
define_ioctl_data!(
struct $ioctl_ty, $mem_ty { $($rest)* } =>
($($ioctl_fields)* $field: $ty,),
($($counted_fields)*),
($($noncounted_fields)* $field: $ty,)
);
};
(struct $ioctl_ty:ident, $mem_ty:ident {
$field:ident: $ty:ty [array<$el:ty, $counted_by:ident>],
$($rest:tt)*
} =>
($($ioctl_fields:tt)*),
($($counted_fields:tt)*),
($($noncounted_fields:tt)*)
) => {
define_ioctl_data!(
struct $ioctl_ty, $mem_ty { $($rest)* } =>
($($ioctl_fields)* $field: $ty,),
($($counted_fields)* $field: $ty [array<$el, $counted_by>],),
($($noncounted_fields)*)
);
};
(struct $ioctl_ty:ident, $mem_ty:ident {} =>
($($ioctl_field:ident: $ioctl_field_ty:ty,)*),
($($counted_field:ident: $counted_ty:ty [array<$el:ty, $counted_by:ident>],)*),
($($noncounted_field:ident: $noncounted_ty:ty,)*)
) => {
// FIXME check ioctl_ty doesn't have padding
const _: $ioctl_ty = $ioctl_ty {
$($ioctl_field: unsafe { mem::zeroed::<$ioctl_field_ty>() },)*
};
#[repr(C)]
pub struct ${concat(__, $mem_ty, Noncounted)} {
$($noncounted_field: $noncounted_ty,)*
}
pub struct $mem_ty<'a> {
noncounted_fields: &'a mut ${concat(__, $mem_ty, Noncounted)},
$($counted_field: &'a mut [$el],)*
}
impl $crate::ioctl_data::IoctlData for $ioctl_ty {
unsafe fn write(&self) -> Vec<u8> {
let noncounted_fields = ${concat(__, $mem_ty, Noncounted)} {
$($noncounted_field: self.$noncounted_field,)*
};
// FIXME use Vec::with_capacity
let mut data = Vec::<u8>::new();
data.extend_from_slice(&unsafe {
mem::transmute::<
${concat(__, $mem_ty, Noncounted)},
[u8; size_of::<${concat(__, $mem_ty, Noncounted)}>()],
>(noncounted_fields)
});
$(
let size = self.$counted_by as usize * size_of::<$el>();
if self.$counted_field as usize != 0 {
let $counted_field = unsafe {
slice::from_raw_parts(self.$counted_field as *const u8, size)
};
data.extend_from_slice(&$counted_field);
} else {
data.extend(iter::repeat(0u8).take(size));
};
)*
data
}
unsafe fn read_from(&mut self, mut buf: &[u8]) {
// FIXME be robust against malicious scheme implementations by returning an error
// when the buf is the wrong size
let noncounted_fields = buf.split_off(..size_of::<${concat(__, $mem_ty, Noncounted)}>()).unwrap();
$(
let size = self.$counted_by as usize * size_of::<$el>();
let $counted_field = buf.split_off(..size).unwrap();
if self.$counted_field as usize != 0 {
unsafe {
slice::from_raw_parts_mut(self.$counted_field as *mut u8, size).copy_from_slice($counted_field);
}
}
)*
assert!(buf.is_empty());
let noncounted_fields = unsafe { &*(noncounted_fields as *const _ as *const ${concat(__, $mem_ty, Noncounted)}) };
$(self.$noncounted_field = noncounted_fields.$noncounted_field;)*
}
}
impl<'a> $mem_ty<'a> {
pub fn with(
mut buf: &'a mut [u8],
f: impl FnOnce($mem_ty<'a>) -> syscall::Result<usize>,
) -> syscall::Result<usize> {
let noncounted_fields = buf.split_off_mut(..size_of::<${concat(__, $mem_ty, Noncounted)}>())
.ok_or(syscall::Error::new(syscall::EINVAL))?;
let noncounted_fields = unsafe { &mut *(noncounted_fields as *mut _ as *mut ${concat(__, $mem_ty, Noncounted)}) };
$(
let $counted_field = buf.split_off_mut(..noncounted_fields.$counted_by as usize * size_of::<$el>())
.ok_or(syscall::Error::new(syscall::EINVAL))?;
let $counted_field = unsafe {
slice::from_raw_parts_mut($counted_field as *mut _ as *mut $el, noncounted_fields.$counted_by as usize)
};
)*
if !buf.is_empty() {
return Err(syscall::Error::new(syscall::EINVAL));
}
Ok( f($mem_ty {
noncounted_fields,
$($counted_field,)*
})?)
}
$(
pub fn $noncounted_field(&self) -> $noncounted_ty {
self.noncounted_fields.$noncounted_field
}
/// Should not be called for fields used as array length
pub fn ${concat(set_, $noncounted_field)}(&mut self, data: $noncounted_ty) {
self.noncounted_fields.$noncounted_field = data;
}
)*
$(
pub fn $counted_field(&self) -> &[$el] {
self.$counted_field
}
pub fn ${concat(set_, $counted_field)}(&mut self, data: &[$el]) {
let copied_count = cmp::min(data.len(), self.$counted_field.len());
self.$counted_field[..copied_count].copy_from_slice(&data[..copied_count]);
self.noncounted_fields.$counted_by = data.len() as _;
}
)*
}
};
}
+11
View File
@@ -0,0 +1,11 @@
#![feature(macro_metavar_expr_concat)]
#![deny(unsafe_op_in_unsafe_fn)]
#![no_std]
extern crate alloc;
#[macro_use]
mod ioctl_data;
pub use ioctl_data::IoctlData;
pub mod drm;
+27
View File
@@ -0,0 +1,27 @@
[package]
name = "redox-rt"
authors = ["4lDO2 <4lDO2@protonmail.com>"]
version = "0.1.0"
edition = "2024"
license = "MIT"
description = "Libc-independent runtime for Redox"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
bitflags.workspace = true
goblin = { version = "0.10", default-features = false, features = ["elf32", "elf64", "endian_fd"] }
plain.workspace = true
ioslice.workspace = true
redox_syscall.workspace = true
redox-path.workspace = true
redox_protocols.workspace = true
generic-rt = { path = "../generic-rt" }
[features]
proc = []
default = ["proc"]
[lints]
workspace = true
+485
View File
@@ -0,0 +1,485 @@
use core::{cell::SyncUnsafeCell, mem::offset_of, ptr::NonNull};
use syscall::{data::*, error::*};
use crate::{
Tcb,
proc::{FdGuard, FdGuardUpper, ForkArgs, fork_inner},
signal::{PosixStackt, RtSigarea, SigStack, inner_c},
};
use redox_protocols::protocol::{ProcCall, RtSigInfo};
use super::ForkScratchpad;
// Setup a stack starting from the very end of the address space, and then growing downwards.
pub const STACK_TOP: usize = 1 << 47;
pub const STACK_SIZE: usize = 1024 * 1024;
#[derive(Debug, Default)]
#[repr(C)]
pub struct SigArea {
pub altstack_top: usize,
pub altstack_bottom: usize,
pub tmp_x1_x2: [usize; 2],
pub tmp_x3_x4: [usize; 2],
pub tmp_x5_x6: [usize; 2],
pub tmp_x7_x8: [usize; 2],
pub tmp_sp: usize,
pub onstack: u64,
pub disable_signals_depth: u64,
pub pctl: usize, // TODO: remove
pub last_sig_was_restart: bool,
pub last_sigstack: Option<NonNull<SigStack>>,
pub tmp_rt_inf: RtSigInfo,
pub tmp_id_inf: u64,
}
#[repr(C)]
#[derive(Debug, Default)]
pub struct ArchIntRegs {
pub x30: usize,
pub x29: usize,
pub x28: usize,
pub x27: usize,
pub x26: usize,
pub x25: usize,
pub x24: usize,
pub x23: usize,
pub x22: usize,
pub x21: usize,
pub x20: usize,
pub x19: usize,
pub x18: usize,
pub x17: usize,
pub x16: usize,
pub x15: usize,
pub x14: usize,
pub x13: usize,
pub x12: usize,
pub x11: usize,
pub x10: usize,
pub x9: usize,
pub x8: usize,
pub x7: usize,
pub x6: usize,
pub x5: usize,
pub x4: usize,
pub x3: usize,
pub x2: usize,
pub x1: usize,
pub sp: usize,
pub nzcv: usize, // user-accessible PSTATE bits
pub pc: usize,
pub x0: usize,
}
/// Deactive TLS, used before exec() on Redox to not trick target executable into thinking TLS
/// is already initialized as if it was a thread.
pub unsafe fn deactivate_tcb(open_via_dup: &FdGuardUpper) -> Result<()> {
let mut env = syscall::EnvRegisters::default();
let file = open_via_dup.dup(b"regs/env")?;
env.tpidr_el0 = 0;
file.write(&mut env)?;
Ok(())
}
unsafe extern "C" fn fork_impl(args: &ForkArgs, initial_rsp: *mut usize) -> usize {
Error::mux(fork_inner(initial_rsp, args))
}
unsafe extern "C" fn child_hook(scratchpad: &ForkScratchpad) {
//let _ = syscall::write(1, alloc::format!("CUR{cur_filetable_fd}PROC{new_proc_fd}THR{new_thr_fd}\n").as_bytes());
let _ = syscall::close(scratchpad.cur_filetable_fd);
unsafe {
crate::child_hook_common(crate::ChildHookCommonArgs {
new_thr_fd: FdGuard::new(scratchpad.new_thr_fd),
new_proc_fd: if scratchpad.new_proc_fd == usize::MAX {
None
} else {
Some(FdGuard::new(scratchpad.new_proc_fd))
},
})
};
}
asmfunction!(__relibc_internal_fork_wrapper (usize) -> usize: ["
stp x29, x30, [sp, #-16]!
stp x27, x28, [sp, #-16]!
stp x25, x26, [sp, #-16]!
stp x23, x24, [sp, #-16]!
stp x21, x22, [sp, #-16]!
stp x19, x20, [sp, #-16]!
//TODO: store floating point regs
// x0: &ForkArgs
mov x1, sp
bl {fork_impl}
ldp x19, x20, [sp], #16
ldp x21, x22, [sp], #16
ldp x23, x24, [sp], #16
ldp x25, x26, [sp], #16
ldp x27, x28, [sp], #16
ldp x29, x30, [sp], #16
ret
"] <= [fork_impl = sym fork_impl]);
asmfunction!(__relibc_internal_fork_ret: ["
# scratchpad is in x1, move to x0 for child_hook
mov x0, x1
bl {child_hook}
//TODO: load floating point regs
mov x0, xzr
ldp x19, x20, [sp], #16
ldp x21, x22, [sp], #16
ldp x23, x24, [sp], #16
ldp x25, x26, [sp], #16
ldp x27, x28, [sp], #16
ldp x29, x30, [sp], #16
ret
"] <= [child_hook = sym child_hook]);
// https://devblogs.microsoft.com/oldnewthing/20220811-00/?p=106963
asmfunction!(__relibc_internal_sigentry: ["
// Clear any active reservation.
clrex
// The old pc and x0 are saved in the sigcontrol struct.
mrs x0, tpidr_el0 // ABI ptr
ldr x0, [x0] // TCB ptr
// Save x1-x6 and sp
stp x1, x2, [x0, #{tcb_sa_off} + {sa_tmp_x1_x2}]
stp x3, x4, [x0, #{tcb_sa_off} + {sa_tmp_x3_x4}]
stp x5, x6, [x0, #{tcb_sa_off} + {sa_tmp_x5_x6}]
stp x7, x8, [x0, #{tcb_sa_off} + {sa_tmp_x7_x8}]
mov x1, sp
str x1, [x0, #{tcb_sa_off} + {sa_tmp_sp}]
ldr x6, [x0, #{tcb_sa_off} + {sa_pctl}]
1:
// Load x1 with the thread's bits
add x5, x0, #{tcb_sc_off} + {sc_word}
ldaxr x1, [x5]
// First check if there are standard thread signals,
and x4, x1, x1, lsr #32 // x4 := x1 & (x1 >> 32)
cbnz x4, 3f // jump if x4 != 0
clrex
// and if not, load process pending bitset.
add x5, x6, #{pctl_pending}
ldaxr x2, [x5]
// Check if there are standard proc signals:
lsr x3, x1, #32 // mask
and w3, w2, w3 // pending unblocked proc
cbz w3, 4f // skip 'fetch_andn' step if zero
// If there was one, find which one, and try clearing the bit (last value in x3, addr in x6)
// this picks the MSB rather than the LSB, unlike x86. POSIX does not require any specific
// ordering though.
clz w3, w3
mov w4, #31
sub w3, w4, w3
// x3 now contains the sig_idx
mov x4, #1
lsl x4, x4, x3 // bit to remove
sub x4, x2, x4 // bit was certainly set, so sub is allowed
// x4 is now the new mask to be set
add x5, x6, #{pctl_pending}
add x2, x5, #{pctl_sender_infos}
add x2, x2, w3, uxtb 3
ldar x2, [x2]
// Try clearing the bit, retrying on failure.
stxr w1, x4, [x5] // try setting pending set to x4, set w1 := 0 on success
cbnz w1, 1b // retry everything if this fails
mov x1, x3
b 2f
4:
// Check for realtime signals, thread/proc.
clrex
// Load the pending set again. TODO: optimize this?
// Process pending - realtime
add x1, x6, #{pctl_pending}
ldaxr x2, [x1]
lsr x2, x2, #32
// Thread pending - realtime and allowset
add x5, x0, #{tcb_sc_off} + {sc_word} + 8
ldar x1, [x5]
orr x2, x1, x2 // combine proc and thread pending
and x2, x2, x2, lsr #32 // AND pending with allowset
cbz x2, 7f // spurious signal if realtime is clear
rbit x2, x2
clz x2, x2
// x2 now contains sig_idx - 32
// If realtime signal was directed at thread, handle it as an idempotent signal.
lsr x3, x1, x2 // x3 := x1 >> x2; x1 is thread pending
tbnz x3, #0, 5f // jump if bit is nonzero
// SYS_CALL(fd, payload_base, payload_len, metadata_len, metadata_base | (flags << 8))
// x8 x0 x1 x2 x3 x4
mov x5, x0 // save TCB pointer
mov x6, x2
ldr x8, ={SYS_CALL}
adrp x0, {proc_fd}
ldr x0, [x0, #:lo12:{proc_fd}]
add x1, x5, #{tcb_sa_off} + {sa_tmp_rt_inf}
str x6, [x1]
mov x2, #{RTINF_SIZE}
adrp x4, {proc_call}
add x4, x4, :lo12:{proc_call}
mov x3, #1
svc 0
mov x3, x0
mov x0, x5 // restore TCB pointer
mov x2, x6 // restore signal number - 32
add x1, x2, #32 // signal number
cbnz x3, 1b
b 2f
5:
// A realtime signal was sent to this thread, try clearing its bit.
// x3 contains last rt signal word, x2 contains rt_idx
clrex
// Calculate the absolute sig_idx
add x1, x3, 32
// Load si_pid and si_uid
add x2, x0, #{tcb_sc_off} + {sc_sender_infos}
add x2, x2, w1, uxtb #3
ldar x2, [x2]
add x3, x0, #{tcb_sc_off} + {sc_word} + 8
ldxr x2, [x3]
// Calculate new mask
mov x4, #1
lsl x4, x4, x2
sub x2, x2, x4 // remove bit
stxr w5, x2, [x3]
cbnz w5, 1b
str x2, [x0, #{tcb_sa_off} + {sa_tmp_id_inf}]
b 2f
3:
// A standard signal was sent to this thread, try clearing its bit.
clz w1, w1
mov x2, #31
sub x1, x2, x1
// Load si_pid and si_uid
add x2, x0, #{tcb_sc_off} + {sc_sender_infos}
add x2, x2, w1, uxtb #3
ldar x2, [x2]
// Clear bit from mask
mov x3, #1
lsl x3, x3, x1
sub x4, x4, x3
// Try updating the mask
stxr w3, x1, [x5]
cbnz w3, 1b
str x2, [x0, #{tcb_sa_off} + {sa_tmp_id_inf}]
2:
ldr x3, [x0, #{tcb_sa_off} + {sa_pctl}]
add x3, x3, {pctl_actions}
add x2, x3, w1, uxtb #4 // actions_base + sig_idx * sizeof Action
// TODO: NOT ATOMIC (tearing allowed between regs)!
ldxp x2, x3, [x2]
clrex
// Calculate new sp wrt redzone and alignment
mov x4, sp
sub x4, x4, {REDZONE_SIZE}
and x4, x4, -{STACK_ALIGN}
mov sp, x4
// skip sigaltstack step if SA_ONSTACK is clear
// tbz x2, #{SA_ONSTACK_BIT}, 2f
ldr x2, [x0, #{tcb_sc_off} + {sc_saved_pc}]
ldr x3, [x0, #{tcb_sc_off} + {sc_saved_x0}]
stp x2, x3, [sp, #-16]!
ldr x2, [x0, #{tcb_sa_off} + {sa_tmp_sp}]
mrs x3, nzcv
stp x2, x3, [sp, #-16]!
ldp x2, x3, [x0, #{tcb_sa_off} + {sa_tmp_x1_x2}]
stp x2, x3, [sp, #-16]!
ldp x3, x4, [x0, #{tcb_sa_off} + {sa_tmp_x3_x4}]
stp x4, x3, [sp, #-16]!
ldp x5, x6, [x0, #{tcb_sa_off} + {sa_tmp_x5_x6}]
stp x6, x5, [sp, #-16]!
ldp x7, x8, [x0, #{tcb_sa_off} + {sa_tmp_x7_x8}]
stp x8, x7, [sp, #-16]!
stp x10, x9, [sp, #-16]!
stp x12, x11, [sp, #-16]!
stp x14, x13, [sp, #-16]!
stp x16, x15, [sp, #-16]!
stp x18, x17, [sp, #-16]!
stp x20, x19, [sp, #-16]!
stp x22, x21, [sp, #-16]!
stp x24, x23, [sp, #-16]!
stp x26, x25, [sp, #-16]!
stp x28, x27, [sp, #-16]!
stp x30, x29, [sp, #-16]!
str w1, [sp, #-4]
sub sp, sp, #64
mov x0, sp
bl {inner}
add sp, sp, #64
ldp x30, x29, [sp], #16
ldp x28, x27, [sp], #16
ldp x26, x25, [sp], #16
ldp x24, x23, [sp], #16
ldp x22, x21, [sp], #16
ldp x20, x19, [sp], #16
ldp x18, x17, [sp], #16
ldp x16, x15, [sp], #16
ldp x14, x13, [sp], #16
ldp x12, x11, [sp], #16
ldp x10, x9, [sp], #16
ldp x8, x7, [sp], #16
ldp x6, x5, [sp], #16
ldp x4, x3, [sp], #16
ldp x2, x1, [sp], #16
ldr x0, [sp, #8]
msr nzcv, x0
8:
// x18 is reserved by ABI as 'platform register', so clobbering it should be safe.
mov x18, sp
ldr x0, [x18]
mov sp, x0
ldp x18, x0, [x18, #16]
br x18
7:
// Spurious signal, i.e. all bitsets were 0 at the time they were checked
clrex
ldr x1, [x0, #{tcb_sc_off} + {sc_flags}]
and x1, x1, ~1
str x1, [x0, #{tcb_sc_off} + {sc_flags}]
ldp x1, x2, [x0, #{tcb_sa_off} + {sa_tmp_x1_x2}]
ldp x3, x4, [x0, #{tcb_sa_off} + {sa_tmp_x3_x4}]
ldp x5, x6, [x0, #{tcb_sa_off} + {sa_tmp_x5_x6}]
ldr x18, [x0, #{tcb_sc_off} + {sc_saved_pc}]
ldr x0, [x0, #{tcb_sc_off} + {sc_saved_x0}]
br x18
"] <= [
pctl_pending = const (offset_of!(SigProcControl, pending)),
pctl_actions = const (offset_of!(SigProcControl, actions)),
pctl_sender_infos = const (offset_of!(SigProcControl, sender_infos)),
tcb_sc_off = const (offset_of!(crate::Tcb, os_specific) + offset_of!(RtSigarea, control)),
tcb_sa_off = const (offset_of!(crate::Tcb, os_specific) + offset_of!(RtSigarea, arch)),
sa_tmp_x1_x2 = const offset_of!(SigArea, tmp_x1_x2),
sa_tmp_x3_x4 = const offset_of!(SigArea, tmp_x3_x4),
sa_tmp_x5_x6 = const offset_of!(SigArea, tmp_x5_x6),
sa_tmp_x7_x8 = const offset_of!(SigArea, tmp_x7_x8),
sa_tmp_sp = const offset_of!(SigArea, tmp_sp),
sa_tmp_rt_inf = const offset_of!(SigArea, tmp_rt_inf),
sa_tmp_id_inf = const offset_of!(SigArea, tmp_id_inf),
sa_pctl = const offset_of!(SigArea, pctl),
sc_saved_pc = const offset_of!(Sigcontrol, saved_ip),
sc_saved_x0 = const offset_of!(Sigcontrol, saved_archdep_reg),
sc_sender_infos = const offset_of!(Sigcontrol, sender_infos),
sc_word = const offset_of!(Sigcontrol, word),
sc_flags = const offset_of!(Sigcontrol, control_flags),
proc_fd = sym PROC_FD,
inner = sym inner_c,
proc_call = sym PROC_CALL,
SA_ONSTACK_BIT = const 58, // (1 << 58) >> 32 = 0x0400_0000
SYS_CALL = const syscall::SYS_CALL,
STACK_ALIGN = const 16,
REDZONE_SIZE = const 128,
RTINF_SIZE = const size_of::<RtSigInfo>(),
]);
asmfunction!(__relibc_internal_rlct_clone_ret: ["
# Load registers
ldp x8, x0, [sp], #16
ldp x1, x2, [sp], #16
ldp x3, x4, [sp], #16
# Call entry point
blr x8
ret
"] <= []);
pub fn current_sp() -> usize {
let sp: usize;
unsafe {
core::arch::asm!("mov {}, sp", out(reg) sp);
}
sp
}
pub unsafe fn manually_enter_trampoline() {
let ctl = unsafe { &Tcb::current().unwrap().os_specific.control };
ctl.saved_archdep_reg.set(0);
let ip_location = &ctl.saved_ip as *const _ as usize;
unsafe {
core::arch::asm!("
bl 2f
b 3f
2:
str lr, [x0]
b __relibc_internal_sigentry
3:
",
inout("x0") ip_location => _, out("lr") _);
}
}
pub unsafe fn arch_pre(stack: &mut SigStack, os: &mut SigArea) -> PosixStackt {
PosixStackt {
sp: core::ptr::null_mut(), // TODO
size: 0, // TODO
flags: 0, // TODO
}
}
pub fn arch_ret_to_sig(stack: &mut SigStack, control: &Sigcontrol) {
let orig_pc = core::mem::replace(&mut stack.regs.pc, __relibc_internal_sigentry as usize);
control.saved_ip.set(orig_pc);
control.saved_archdep_reg.set(stack.regs.x0);
}
pub(crate) static PROC_FD: SyncUnsafeCell<usize> = SyncUnsafeCell::new(usize::MAX);
static PROC_CALL: [usize; 1] = [ProcCall::Sigdeq as usize];
+411
View File
@@ -0,0 +1,411 @@
use core::{cell::SyncUnsafeCell, mem::offset_of, ptr::NonNull, sync::atomic::Ordering};
use syscall::*;
use crate::{
proc::{FdGuard, FdGuardUpper, ForkArgs, fork_inner},
signal::{PROC_CONTROL_STRUCT, PosixStackt, RtSigarea, SigStack, inner_fastcall},
};
use redox_protocols::protocol::{ProcCall, RtSigInfo};
use super::ForkScratchpad;
// Setup a stack starting from the very end of the address space, and then growing downwards.
pub const STACK_TOP: usize = 1 << 31;
pub const STACK_SIZE: usize = 1024 * 1024;
#[derive(Debug, Default)]
#[repr(C)]
pub struct SigArea {
pub altstack_top: usize,
pub altstack_bottom: usize,
pub tmp_eip: usize,
pub tmp_esp: usize,
pub tmp_eax: usize,
pub tmp_ebx: usize,
pub tmp_ecx: usize,
pub tmp_edx: usize,
pub tmp_edi: usize,
pub tmp_esi: usize,
pub tmp_rt_inf: RtSigInfo,
pub tmp_signo: usize,
pub tmp_id_inf: u64,
pub tmp_mm0: u64,
pub disable_signals_depth: u64,
pub last_sig_was_restart: bool,
pub last_sigstack: Option<NonNull<SigStack>>,
}
#[derive(Debug, Default)]
#[repr(C, align(16))]
pub struct ArchIntRegs {
pub fxsave: [u16; 29],
// ensure fxsave region is 16 byte aligned
pub _pad: [usize; 2], // fxsave "available" +0
pub ebp: usize, // fxsave "available" +8
pub esi: usize, // avail +12
pub edi: usize, // avail +16
pub ebx: usize, // avail +20
pub eax: usize, // avail +24
pub ecx: usize, // avail +28
pub edx: usize, // avail +32
pub eflags: usize, // avail +36
pub eip: usize, // avail +40
pub esp: usize, // avail +44
}
/// Deactive TLS, used before exec() on Redox to not trick target executable into thinking TLS
/// is already initialized as if it was a thread.
pub unsafe fn deactivate_tcb(open_via_dup: &FdGuardUpper) -> Result<()> {
let mut env = syscall::EnvRegisters::default();
let file = open_via_dup.dup(b"regs/env")?;
env.fsbase = 0;
env.gsbase = 0;
file.write(&mut env)?;
Ok(())
}
unsafe extern "fastcall" fn fork_impl(args: &ForkArgs, initial_rsp: *mut usize) -> usize {
Error::mux(fork_inner(initial_rsp, args))
}
// TODO: duplicate code with x86_64
unsafe extern "cdecl" fn child_hook(scratchpad: ForkScratchpad) {
let _ = syscall::close(scratchpad.cur_filetable_fd);
unsafe {
crate::child_hook_common(crate::ChildHookCommonArgs {
new_thr_fd: FdGuard::new(scratchpad.new_thr_fd),
new_proc_fd: if scratchpad.new_proc_fd == usize::MAX {
None
} else {
Some(FdGuard::new(scratchpad.new_proc_fd))
},
})
};
}
asmfunction!(__relibc_internal_fork_wrapper (usize) -> usize: ["
mov ecx, [esp+4]
push ebp
mov ebp, esp
// Push preserved registers
push ebx
push edi
push esi
push ebp
sub esp, 32
//TODO stmxcsr [esp+16]
fnstcw [esp+24]
mov edx, esp
call {fork_impl}
jmp 2f
"] <= [fork_impl = sym fork_impl]);
asmfunction!(__relibc_internal_fork_ret: ["
// Arguments already on the stack
call {child_hook}
//TODO ldmxcsr [esp+16]
fldcw [esp+24]
xor eax, eax
.p2align 4
2:
add esp, 32
// Pop preserved registers
pop ebp
pop esi
pop edi
pop ebx
pop ebp
ret
"] <= [child_hook = sym child_hook]);
asmfunction!(__relibc_internal_sigentry: ["
// Save some registers
mov gs:[{tcb_sa_off} + {sa_tmp_esp}], esp
mov gs:[{tcb_sa_off} + {sa_tmp_eax}], eax
mov gs:[{tcb_sa_off} + {sa_tmp_edx}], edx
mov gs:[{tcb_sa_off} + {sa_tmp_ecx}], ecx
mov gs:[{tcb_sa_off} + {sa_tmp_ebx}], ebx
mov gs:[{tcb_sa_off} + {sa_tmp_edi}], edi
mov gs:[{tcb_sa_off} + {sa_tmp_esi}], esi
1:
// Read standard signal word - first for this thread
mov edx, gs:[{tcb_sc_off} + {sc_word} + 4]
mov eax, gs:[{tcb_sc_off} + {sc_word}]
and eax, edx
bsf eax, eax
jnz 9f
// Read standard signal word - for the process
lea ecx, [{pctl}]
mov eax, [ecx + {pctl_pending}]
and eax, edx
bsf eax, eax
jz 3f
// Read si_pid and si_uid, atomically.
movq gs:[{tcb_sa_off} + {sa_tmp_mm0}], mm0
movq mm0, [ecx + {pctl_sender_infos} + eax * 8]
movq gs:[{tcb_sa_off} + {sa_tmp_id_inf}], mm0
movq mm0, gs:[{tcb_sa_off} + {sa_tmp_mm0}]
// Try clearing the pending bit, otherwise retry if another thread did that first
lock btr [ecx + {pctl_pending}], eax
jnc 1b
jmp 2f
3:
// Read realtime thread and process signal word together
mov edx, [ecx + {pctl_pending} + 4]
mov eax, gs:[{tcb_sc_off} + {sc_word} + 8]
or eax, edx
and eax, gs:[{tcb_sc_off} + {sc_word} + 12]
bsf eax, eax
jz 7f // spurious signal
// If thread rather than process was specifically targeted, send the signal to it first.
bt edx, eax
jnc 8f
// SYS_CALL(fd, payload_base, payload_len, metadata_len, metadata_base)
// eax ebx ecx edx esi edi
mov ebx, [{proc_fd}]
mov ecx, gs:[0]
add ecx, {tcb_sa_off} + {sa_tmp_rt_inf}
mov [ecx], eax
mov gs:[{tcb_sa_off} + {sa_tmp_signo}], eax
mov edx, {RTINF_SIZE}
mov esi, 1
lea edi, [{proc_call}]
mov eax, {SYS_CALL}
int 0x80
test eax, eax
jnz 1b
mov eax, gs:[{tcb_sa_off} + {sa_tmp_signo}]
add eax, 32
jmp 2f
8:
add eax, 32
9:
// Read si_pid and si_uid, atomically.
movq gs:[{tcb_sa_off} + {sa_tmp_mm0}], mm0
movq mm0, gs:[{tcb_sc_off} + {sc_sender_infos} + eax * 8]
movq gs:[{tcb_sa_off} + {sa_tmp_id_inf}], mm0
movq mm0, gs:[{tcb_sa_off} + {sa_tmp_mm0}]
mov edx, eax
shr edx, 5
mov ecx, eax
and ecx, 31
lock btr gs:[{tcb_sc_off} + {sc_word} + edx * 8], ecx
add eax, 64
2:
and esp, -{STACK_ALIGN}
mov edx, eax
add edx, edx
bt dword ptr [{pctl} + {pctl_actions} + edx * 8 + 4], 28
jnc 4f
mov edx, gs:[{tcb_sa_off} + {sa_altstack_top}]
cmp esp, edx
ja 3f
cmp esp, gs:[{tcb_sa_off} + {sa_altstack_bottom}]
jnbe 4f
3:
mov esp, edx
4:
// Now that we have a stack, we can finally start populating the signal stack.
push dword ptr gs:[{tcb_sa_off} + {sa_tmp_esp}]
push dword ptr gs:[{tcb_sc_off} + {sc_saved_eip}]
push dword ptr gs:[{tcb_sc_off} + {sc_saved_eflags}]
push dword ptr gs:[{tcb_sa_off} + {sa_tmp_edx}]
push dword ptr gs:[{tcb_sa_off} + {sa_tmp_ecx}]
push dword ptr gs:[{tcb_sa_off} + {sa_tmp_eax}]
push dword ptr gs:[{tcb_sa_off} + {sa_tmp_ebx}]
push dword ptr gs:[{tcb_sa_off} + {sa_tmp_edi}]
push dword ptr gs:[{tcb_sa_off} + {sa_tmp_esi}]
push ebp
sub esp, 2 * 4 + 29 * 16
fxsave [esp]
mov [esp - 4], eax
sub esp, 48
mov ecx, esp
call {inner}
fxrstor [esp + 48]
add esp, 48 + 29 * 16 + 2 * 4
pop ebp
pop esi
pop edi
pop ebx
pop eax
pop ecx
pop edx
popfd
pop dword ptr gs:[{tcb_sa_off} + {sa_tmp_eip}]
.globl __relibc_internal_sigentry_crit_first
__relibc_internal_sigentry_crit_first:
pop esp
.globl __relibc_internal_sigentry_crit_second
__relibc_internal_sigentry_crit_second:
jmp dword ptr gs:[{tcb_sa_off} + {sa_tmp_eip}]
7:
mov eax, gs:[0]
lea esp, [eax + {tcb_sc_off} + {sc_saved_eflags}]
popfd
mov esp, gs:[{tcb_sa_off} + {sa_tmp_esp}]
mov eax, gs:[{tcb_sc_off} + {sc_saved_eip}]
mov gs:[{tcb_sa_off} + {sa_tmp_eip}], eax
mov eax, gs:[{tcb_sa_off} + {sa_tmp_eax}]
mov ebx, gs:[{tcb_sa_off} + {sa_tmp_ebx}]
mov ecx, gs:[{tcb_sa_off} + {sa_tmp_ecx}]
mov edx, gs:[{tcb_sa_off} + {sa_tmp_edx}]
mov edi, gs:[{tcb_sa_off} + {sa_tmp_edi}]
mov esi, gs:[{tcb_sa_off} + {sa_tmp_esi}]
and dword ptr gs:[{tcb_sc_off} + {sc_control}], ~1
.globl __relibc_internal_sigentry_crit_third
__relibc_internal_sigentry_crit_third:
jmp dword ptr gs:[{tcb_sa_off} + {sa_tmp_eip}]
"] <= [
inner = sym inner_fastcall,
sa_tmp_eip = const offset_of!(SigArea, tmp_eip),
sa_tmp_esp = const offset_of!(SigArea, tmp_esp),
sa_tmp_eax = const offset_of!(SigArea, tmp_eax),
sa_tmp_ebx = const offset_of!(SigArea, tmp_ebx),
sa_tmp_ecx = const offset_of!(SigArea, tmp_ecx),
sa_tmp_edx = const offset_of!(SigArea, tmp_edx),
sa_tmp_edi = const offset_of!(SigArea, tmp_edi),
sa_tmp_esi = const offset_of!(SigArea, tmp_esi),
sa_tmp_mm0 = const offset_of!(SigArea, tmp_mm0),
sa_tmp_rt_inf = const offset_of!(SigArea, tmp_rt_inf),
sa_tmp_id_inf = const offset_of!(SigArea, tmp_id_inf),
sa_tmp_signo = const offset_of!(SigArea, tmp_signo),
sa_altstack_top = const offset_of!(SigArea, altstack_top),
sa_altstack_bottom = const offset_of!(SigArea, altstack_bottom),
sc_control = const offset_of!(Sigcontrol, control_flags),
sc_saved_eflags = const offset_of!(Sigcontrol, saved_archdep_reg),
sc_saved_eip = const offset_of!(Sigcontrol, saved_ip),
sc_word = const offset_of!(Sigcontrol, word),
sc_sender_infos = const offset_of!(Sigcontrol, sender_infos),
tcb_sa_off = const offset_of!(crate::Tcb, os_specific) + offset_of!(RtSigarea, arch),
tcb_sc_off = const offset_of!(crate::Tcb, os_specific) + offset_of!(RtSigarea, control),
pctl_actions = const offset_of!(SigProcControl, actions),
pctl_sender_infos = const offset_of!(SigProcControl, sender_infos),
pctl_pending = const offset_of!(SigProcControl, pending),
pctl = sym PROC_CONTROL_STRUCT,
proc_fd = sym PROC_FD,
proc_call = sym PROC_CALL,
STACK_ALIGN = const 16,
SYS_CALL = const syscall::SYS_CALL,
RTINF_SIZE = const size_of::<RtSigInfo>(),
]);
asmfunction!(__relibc_internal_rlct_clone_ret -> usize: ["
# Load registers
pop eax
sub esp, 8
mov DWORD PTR [esp], 0x00001F80
# TODO: ldmxcsr [esp]
mov WORD PTR [esp], 0x037F
fldcw [esp]
add esp, 8
# Call entry point
call eax
ret
"] <= []);
unsafe extern "C" {
fn __relibc_internal_sigentry_crit_first();
fn __relibc_internal_sigentry_crit_second();
fn __relibc_internal_sigentry_crit_third();
}
pub unsafe fn arch_pre(stack: &mut SigStack, area: &mut SigArea) -> PosixStackt {
if stack.regs.eip == __relibc_internal_sigentry_crit_first as usize {
let stack_ptr = stack.regs.esp as *const usize;
stack.regs.esp = unsafe { stack_ptr.read() };
stack.regs.eip = unsafe { stack_ptr.sub(1).read() };
} else if stack.regs.eip == __relibc_internal_sigentry_crit_second as usize
|| stack.regs.eip == __relibc_internal_sigentry_crit_third as usize
{
stack.regs.eip = area.tmp_eip;
}
PosixStackt {
sp: stack.regs.esp as *mut (),
size: 0, // TODO
flags: 0, // TODO
}
}
pub fn arch_ret_to_sig(stack: &mut SigStack, control: &Sigcontrol) {
let orig_eip = core::mem::replace(&mut stack.regs.eip, __relibc_internal_sigentry as usize);
control.saved_ip.set(orig_eip);
control.saved_archdep_reg.set(stack.regs.eflags);
}
#[unsafe(no_mangle)]
pub unsafe fn manually_enter_trampoline() {
let c = unsafe { &crate::Tcb::current().unwrap().os_specific.control };
c.control_flags.store(
c.control_flags.load(Ordering::Relaxed) | syscall::flag::INHIBIT_DELIVERY.bits(),
Ordering::Release,
);
c.saved_archdep_reg.set(0); // TODO: Just reset DF on x86?
unsafe {
core::arch::asm!("
call 2f
jmp 3f
2:
pop dword ptr gs:[{tcb_sc_off} + {sc_saved_eip}]
jmp __relibc_internal_sigentry
3:
",
tcb_sc_off = const offset_of!(crate::Tcb, os_specific) + offset_of!(RtSigarea, control),
sc_saved_eip = const offset_of!(Sigcontrol, saved_ip),
);
}
}
/// Get current stack pointer, weak granularity guarantees.
pub fn current_sp() -> usize {
let sp: usize;
unsafe {
core::arch::asm!("mov {}, esp", out(reg) sp);
}
sp
}
pub static PROC_FD: SyncUnsafeCell<usize> = SyncUnsafeCell::new(usize::MAX);
static PROC_CALL: u64 = ProcCall::Sigdeq as u64;
+27
View File
@@ -0,0 +1,27 @@
#[cfg(target_arch = "aarch64")]
pub use self::aarch64::*;
#[cfg(target_arch = "aarch64")]
pub mod aarch64;
#[cfg(target_arch = "x86")]
pub use self::i686::*;
#[cfg(target_arch = "x86")]
pub mod i686;
#[cfg(target_arch = "x86_64")]
pub use self::x86_64::*;
#[cfg(target_arch = "x86_64")]
pub mod x86_64;
#[cfg(target_arch = "riscv64")]
pub use self::riscv64::*;
#[cfg(target_arch = "riscv64")]
pub mod riscv64;
#[derive(Debug)]
#[repr(C)]
pub struct ForkScratchpad {
pub cur_filetable_fd: usize,
pub new_proc_fd: usize,
pub new_thr_fd: usize,
}
+654
View File
@@ -0,0 +1,654 @@
use core::cell::SyncUnsafeCell;
use crate::{
Tcb,
proc::{FdGuard, FdGuardUpper, ForkArgs, fork_inner},
signal::{PosixStackt, RtSigarea, SigStack, get_sigaltstack, inner_c},
};
use core::{mem::offset_of, ptr::NonNull, sync::atomic::Ordering};
use redox_protocols::protocol::{ProcCall, RtSigInfo};
use syscall::{data::*, error::*};
use super::ForkScratchpad;
// Setup a stack starting from the very end of the address space, and then growing downwards.
pub const STACK_TOP: usize = 1 << 38;
pub const STACK_SIZE: usize = 1024 * 1024;
#[derive(Debug, Default)]
#[repr(C)]
pub struct SigArea {
pub tmp_sp: u64,
pub tmp_t1: u64,
pub tmp_t2: u64,
pub tmp_t3: u64,
pub tmp_t4: u64,
pub tmp_a0: u64,
pub tmp_a1: u64,
pub tmp_a2: u64,
pub tmp_a3: u64,
pub tmp_a4: u64,
pub tmp_a7: u64,
pub pctl: usize, // TODO: remove
pub tmp_ip: u64,
pub tmp_rt_inf: RtSigInfo,
pub tmp_id_inf: u64,
pub altstack_top: usize,
pub altstack_bottom: usize,
pub disable_signals_depth: u64,
pub last_sig_was_restart: bool,
pub last_sigstack: Option<NonNull<SigStack>>,
}
#[repr(C)]
#[derive(Debug, Default)]
pub struct ArchIntRegs {
pub int_regs: [u64; 31],
pub pc: u64,
pub fp_regs: [u64; 32],
pub fcsr: u32,
_pad: u32,
}
/// Deactive TLS, used before exec() on Redox to not trick target executable into thinking TLS
/// is already initialized as if it was a thread.
pub unsafe fn deactivate_tcb(open_via_dup: &FdGuardUpper) -> Result<()> {
let mut env = syscall::EnvRegisters::default();
let file = open_via_dup.dup(b"regs/env")?;
env.tp = 0;
file.write(&mut env)?;
Ok(())
}
unsafe extern "C" fn fork_impl(args: &ForkArgs, initial_rsp: *mut usize) -> usize {
Error::mux(fork_inner(initial_rsp, args))
}
unsafe extern "C" fn child_hook(scratchpad: &ForkScratchpad) {
let _ = syscall::close(scratchpad.cur_filetable_fd);
unsafe {
crate::child_hook_common(crate::ChildHookCommonArgs {
new_thr_fd: FdGuard::new(scratchpad.new_thr_fd),
new_proc_fd: if scratchpad.new_proc_fd == usize::MAX {
None
} else {
Some(FdGuard::new(scratchpad.new_proc_fd))
},
})
};
}
asmfunction!(__relibc_internal_fork_wrapper (usize) -> usize: ["
.attribute arch, \"rv64gc\" # rust bug 80608
addi sp, sp, -200
sd s0, 0(sp)
sd s1, 8(sp)
sd s2, 16(sp)
sd s3, 24(sp)
sd s4, 32(sp)
sd s5, 40(sp)
sd s6, 48(sp)
sd s7, 56(sp)
sd s8, 64(sp)
sd s9, 72(sp)
sd s10, 80(sp)
sd s11, 88(sp)
sd ra, 96(sp)
fsd fs0, 104(sp)
fsd fs1, 112(sp)
fsd fs2, 120(sp)
fsd fs3, 128(sp)
fsd fs4, 136(sp)
fsd fs5, 144(sp)
fsd fs6, 152(sp)
fsd fs7, 160(sp)
fsd fs8, 168(sp)
fsd fs9, 176(sp)
fsd fs10, 184(sp)
fsd fs11, 192(sp)
// a0 is forwarded from this function
mv a1, sp
jal {fork_impl}
ld s0, 0(sp)
ld s1, 8(sp)
ld s2, 16(sp)
ld s3, 24(sp)
ld s4, 32(sp)
ld s5, 40(sp)
ld s6, 48(sp)
ld s7, 56(sp)
ld s8, 64(sp)
ld s9, 72(sp)
ld s10, 80(sp)
ld s11, 88(sp)
ld ra, 96(sp)
fld fs0, 104(sp)
fld fs1, 112(sp)
fld fs2, 120(sp)
fld fs3, 128(sp)
fld fs4, 136(sp)
fld fs5, 144(sp)
fld fs6, 152(sp)
fld fs7, 160(sp)
fld fs8, 168(sp)
fld fs9, 176(sp)
fld fs10, 184(sp)
fld fs11, 192(sp)
addi sp, sp, 200
ret
"] <= [fork_impl = sym fork_impl]);
asmfunction!(__relibc_internal_fork_ret: ["
.attribute arch, \"rv64gc\" # rust bug 80608
# scratchpad is in a1, move to a0 for child_hook
mv a0, a1
jal {child_hook}
mv a0, zero
ld s0, 0(sp)
ld s1, 8(sp)
ld s2, 16(sp)
ld s3, 24(sp)
ld s4, 32(sp)
ld s5, 40(sp)
ld s6, 48(sp)
ld s7, 56(sp)
ld s8, 64(sp)
ld s9, 72(sp)
ld s10, 80(sp)
ld s11, 88(sp)
ld ra, 96(sp)
fld fs0, 104(sp)
fld fs1, 112(sp)
fld fs2, 120(sp)
fld fs3, 128(sp)
fld fs4, 136(sp)
fld fs5, 144(sp)
fld fs6, 152(sp)
fld fs7, 160(sp)
fld fs8, 168(sp)
fld fs9, 176(sp)
fld fs10, 184(sp)
fld fs11, 192(sp)
addi sp, sp, 200
ret
"] <= [child_hook = sym child_hook]);
asmfunction!(__relibc_internal_sigentry: ["
.attribute arch, \"rv64gc\" # rust bug 80608
// Save some registers
ld t0, -8(tp) // Tcb
sd sp, ({tcb_sa_off} + {sa_tmp_sp})(t0)
sd t1, ({tcb_sa_off} + {sa_tmp_t1})(t0)
sd t2, ({tcb_sa_off} + {sa_tmp_t2})(t0)
sd t3, ({tcb_sa_off} + {sa_tmp_t3})(t0)
sd t4, ({tcb_sa_off} + {sa_tmp_t4})(t0)
ld t4, ({tcb_sa_off} + {sa_off_pctl})(t0)
// First, select signal, always pick first available bit
99:
// Read first signal word
ld t1, ({tcb_sc_off} + {sc_word})(t0)
srli t2, t1, 32 // bitset to low word
and t1, t1, t2 // masked bitset in low word
beqz t1, 3f
// Found in first thread signal word
mv t3, x0
2: andi t2, t1, 1
bnez t2, 10f
addi t3, t3, 1
srli t1, t1, 1
j 2b
// If no unblocked thread signal was found, check for process.
// This is competitive; we need to atomically check if *we* cleared the process-wide pending
// bit, otherwise restart.
3: lw t1, {pctl_off_pending}(t4)
and t1, t1, t2
beqz t1, 3f
// Found in first process signal word
li t3, -1
2: andi t2, t1, 1
addi t3, t3, 1
srli t1, t1, 1
beqz t2, 2b
slli t1, t3, 3 // * 8 == size_of SenderInfo
add t1, t1, t4
ld t1, {pctl_off_sender_infos}(t1)
sd t1, ({tcb_sa_off} + {sa_tmp_id_inf})(t0)
li t1, 1
sll t1, t1, t3
not t1, t1
addi t2, t4, {pctl_off_pending}
amoand.w.aq t2, t1, (t2)
and t1, t1, t2
bne t1, t2, 9f
3:
// Read second signal word - both process and thread simultaneously.
// This must be done since POSIX requires low realtime signals to be picked first.
ld t1, ({tcb_sc_off} + {sc_word} + 8)(t0)
lw t2, ({pctl_off_pending} + 4)(t4)
or t4, t1, t2
srli t2, t1, 32
and t4, t2, t4
beqz t4, 7f
li t3, -1
2: andi t2, t4, 1
addi t3, t3, 1
srli t4, t4, 1
beqz t2, 2b
li t2, 1
sll t2, t2, t3
and t1, t1, t2
addi t3, t3, 32
bnez t1, 10f // thread signal
// otherwise, try (competitively) dequeueing realtime signal
// SYS_CALL(fd, payload_base, payload_len, metadata_len, metadata_base)
// a7 a0 a1 a2 a3 a4
// TODO: This SYS_CALL invocation has not yet been tested due to toolchain issues.
sd a0, ({tcb_sa_off} + {sa_tmp_a0})(t0)
sd a1, ({tcb_sa_off} + {sa_tmp_a1})(t0)
sd a2, ({tcb_sa_off} + {sa_tmp_a2})(t0)
sd a3, ({tcb_sa_off} + {sa_tmp_a3})(t0)
sd a4, ({tcb_sa_off} + {sa_tmp_a4})(t0)
sd a7, ({tcb_sa_off} + {sa_tmp_a7})(t0)
li a7, {SYS_CALL}
addi a2, t3, -32
add a1, t0, {tcb_sa_off} + {sa_tmp_rt_inf} // out pointer of dequeued realtime sig
sd a2, (a1)
li a2, {RTINF_SIZE}
li a3, 1
1337:
auipc a4, %pcrel_hi({proc_fd})
addi a4, a4, %pcrel_lo(1337b)
ecall
ld a3, ({tcb_sa_off} + {sa_tmp_a3})(t0)
ld a4, ({tcb_sa_off} + {sa_tmp_a4})(t0)
bnez a0, 99b // assumes error can only be EAGAIN
j 9f
10: // thread signal. t3 holds signal number
srli t1, t3, 5
bnez t1, 2f // FIXME senderinfo?
sll t2, t3, 3 // * 8 == size_of SenderInfo
add t2, t2, t0
ld t2, ({tcb_sc_off} + {sc_sender_infos})(t2)
sd t2, ({tcb_sa_off} + {sa_tmp_id_inf})(t0)
2: andi t4, t3, 31
li t2, 1
sll t2, t2, t4
not t2, t2
sll t1, t1, 3
add t1, t1, t0
addi t1, t1, {tcb_sc_off} + {sc_word}
amoand.w.aq x0, t2, (t1)
addi t3, t3, 64 // indicate signal was targeted at thread
9: // process signal t3 holds signal number
// By now we have selected a signal, stored in eax (6-bit). We now need to choose whether or
// not to switch to the alternate signal stack. If SA_ONSTACK is clear for this signal, then
// skip the sigaltstack logic.
ld t4, ({tcb_sa_off} + {sa_off_pctl})(t0)
andi t1, t3, 63
slli t1, t1, 4 // * 16 == size_of RawAction
add t1, t1, t4
ld t1, {pctl_off_actions}(t1)
slli t1, t1, 63-58 // SA_ONSTACK in sign bit
bgez t1, 3f
// If current RSP is above altstack region, switch to altstack
ld t1, ({tcb_sa_off} + {sa_altstack_top})(t0)
bgtu sp, t1, 2f
ld t2, ({tcb_sa_off} + {sa_altstack_bottom})(t0)
bgtu sp, t3, 3f
2: mv sp, t1
3:
// form mcontext on stack
addi sp, sp, -33 * 8
fsd f0, (0 * 8)(sp)
fsd f1, (1 * 8)(sp)
fsd f2, (2 * 8)(sp)
fsd f3, (3 * 8)(sp)
fsd f4, (4 * 8)(sp)
fsd f5, (5 * 8)(sp)
fsd f6, (6 * 8)(sp)
fsd f7, (7 * 8)(sp)
fsd f8, (8 * 8)(sp)
fsd f9, (9 * 8)(sp)
fsd f10, (10 * 8)(sp)
fsd f11, (11 * 8)(sp)
fsd f12, (12 * 8)(sp)
fsd f13, (13 * 8)(sp)
fsd f14, (14 * 8)(sp)
fsd f15, (15 * 8)(sp)
fsd f16, (16 * 8)(sp)
fsd f17, (17 * 8)(sp)
fsd f18, (18 * 8)(sp)
fsd f19, (19 * 8)(sp)
fsd f20, (20 * 8)(sp)
fsd f21, (21 * 8)(sp)
fsd f22, (22 * 8)(sp)
fsd f23, (23 * 8)(sp)
fsd f24, (24 * 8)(sp)
fsd f25, (25 * 8)(sp)
fsd f26, (26 * 8)(sp)
fsd f27, (27 * 8)(sp)
fsd f28, (28 * 8)(sp)
fsd f29, (29 * 8)(sp)
fsd f30, (30 * 8)(sp)
fsd f31, (31 * 8)(sp)
csrr t1, fcsr
sw t1, (32 * 8)(sp)
addi sp, sp, -32 * 8
sd x1, 0(sp)
ld t1, ({tcb_sa_off} + {sa_tmp_sp})(t0)
sd t1, (1 * 8)(sp) // x2 is sp
sd x3, (2 * 8)(sp)
sd x4, (3 * 8)(sp)
ld t1, ({tcb_sc_off} + {sc_saved_t0})(t0)
sd t1, (4 * 8)(sp) // x5 is t0
ld t1, ({tcb_sa_off} + {sa_tmp_t1})(t0)
sd t1, (5 * 8)(sp) // x6 is t1
ld t1, ({tcb_sa_off} + {sa_tmp_t2})(t0)
sd t1, (6 * 8)(sp) // x7 is t2
sd x8, (7 * 8)(sp)
sd x9, (8 * 8)(sp)
sd x10, (9 * 8)(sp)
sd x11, (10 * 8)(sp)
sd x12, (11 * 8)(sp)
sd x13, (12 * 8)(sp)
sd x14, (13 * 8)(sp)
sd x15, (14 * 8)(sp)
sd x16, (15 * 8)(sp)
sd x17, (16 * 8)(sp)
sd x18, (17 * 8)(sp)
sd x19, (18 * 8)(sp)
sd x20, (19 * 8)(sp)
sd x21, (20 * 8)(sp)
sd x22, (21 * 8)(sp)
sd x23, (22 * 8)(sp)
sd x24, (23 * 8)(sp)
sd x25, (24 * 8)(sp)
sd x26, (25 * 8)(sp)
sd x27, (26 * 8)(sp)
ld t1, ({tcb_sa_off} + {sa_tmp_t3})(t0)
sd t1, (27 * 8)(sp) // t3 is x28
ld t1, ({tcb_sa_off} + {sa_tmp_t4})(t0)
sd t1, (28 * 8)(sp) // t4 is x29
sd x30, (29 * 8)(sp)
sd x31, (30 * 8)(sp)
ld t1, ({tcb_sc_off} + {sc_saved_ip})(t0)
sd t1, (31 * 8)(sp)
// form ucontext
addi sp, sp, -64
sw t3, 60(sp)
mv t0, sp
jal {inner}
addi sp, sp, 64
addi t0, sp, 32 * 8
fld f0, (0 * 8)(t0)
fld f1, (1 * 8)(t0)
fld f2, (2 * 8)(t0)
fld f3, (3 * 8)(t0)
fld f4, (4 * 8)(t0)
fld f5, (5 * 8)(t0)
fld f6, (6 * 8)(t0)
fld f7, (7 * 8)(t0)
fld f8, (8 * 8)(t0)
fld f9, (9 * 8)(t0)
fld f10, (10 * 8)(t0)
fld f11, (11 * 8)(t0)
fld f12, (12 * 8)(t0)
fld f13, (13 * 8)(t0)
fld f14, (14 * 8)(t0)
fld f15, (15 * 8)(t0)
fld f16, (16 * 8)(t0)
fld f17, (17 * 8)(t0)
fld f18, (18 * 8)(t0)
fld f19, (19 * 8)(t0)
fld f20, (20 * 8)(t0)
fld f21, (21 * 8)(t0)
fld f22, (22 * 8)(t0)
fld f23, (23 * 8)(t0)
fld f24, (24 * 8)(t0)
fld f25, (25 * 8)(t0)
fld f26, (26 * 8)(t0)
fld f27, (27 * 8)(t0)
fld f28, (28 * 8)(t0)
fld f29, (29 * 8)(t0)
fld f30, (30 * 8)(t0)
fld f31, (31 * 8)(t0)
lw t1, (32 * 8)(t0)
csrw fcsr, t1
ld x1, 0(sp)
// skip sp
// skip gp
ld x4, (3 * 8)(sp)
ld x5, (4 * 8)(sp)
ld x6, (5 * 8)(sp)
ld x7, (6 * 8)(sp)
ld x8, (7 * 8)(sp)
ld x9, (8 * 8)(sp)
ld x10, (9 * 8)(sp)
ld x11, (10 * 8)(sp)
ld x12, (11 * 8)(sp)
ld x13, (12 * 8)(sp)
ld x14, (13 * 8)(sp)
ld x15, (14 * 8)(sp)
ld x16, (15 * 8)(sp)
ld x17, (16 * 8)(sp)
ld x18, (17 * 8)(sp)
ld x19, (18 * 8)(sp)
ld x20, (19 * 8)(sp)
ld x21, (20 * 8)(sp)
ld x22, (21 * 8)(sp)
ld x23, (22 * 8)(sp)
ld x24, (23 * 8)(sp)
ld x25, (24 * 8)(sp)
ld x26, (25 * 8)(sp)
ld x27, (26 * 8)(sp)
ld x28, (27 * 8)(sp)
ld x29, (28 * 8)(sp)
ld x30, (29 * 8)(sp)
ld x31, (30 * 8)(sp)
ld gp, (31 * 8)(sp) // new IP; this clobbers register x3/gp which is ABI reserved
.global __relibc_internal_sigentry_crit_first
__relibc_internal_sigentry_crit_first:
ld sp, (1 * 8)(sp)
.global __relibc_internal_sigentry_crit_second
__relibc_internal_sigentry_crit_second:
jr gp
7:
// A spurious signal occurred. Signals are still disabled here, but will need to be re-enabled.
// restore stack
ld sp, ({tcb_sa_off} + {sa_tmp_sp})(t0)
// move saved IP away from control, allowing arch_pre to save us if interrupted.
ld t1, ({tcb_sc_off} + {sc_saved_ip})(t0)
sd t1, ({tcb_sa_off} + {sa_tmp_ip})(t0)
// restore regs
ld t2, ({tcb_sa_off} + {sa_tmp_t2})(t0)
ld t3, ({tcb_sa_off} + {sa_tmp_t3})(t0)
ld t4, ({tcb_sa_off} + {sa_tmp_t4})(t0)
// move saved t0 away from control as well
mv t1, t0
ld t0, ({tcb_sc_off} + {sc_saved_t0})(t0)
// Re-enable signals. This code can be interrupted after this signal, so we need to define
// 'crit_third'.
ld gp, ({tcb_sc_off} + {sc_control})(t1)
andi gp, gp, ~1
sd gp, ({tcb_sc_off} + {sc_control})(t1)
.globl __relibc_internal_sigentry_crit_third
__relibc_internal_sigentry_crit_third:
ld gp, ({tcb_sa_off} + {sa_tmp_ip})(t1)
.globl __relibc_internal_sigentry_crit_fourth
__relibc_internal_sigentry_crit_fourth:
ld t1, ({tcb_sa_off} + {sa_tmp_t1})(t1)
.globl __relibc_internal_sigentry_crit_fifth
__relibc_internal_sigentry_crit_fifth:
jr gp
"] <= [
tcb_sc_off = const (offset_of!(crate::Tcb, os_specific) + offset_of!(RtSigarea, control)),
sc_word = const offset_of!(Sigcontrol, word),
sc_saved_t0 = const offset_of!(Sigcontrol, saved_archdep_reg),
sc_saved_ip = const offset_of!(Sigcontrol, saved_ip),
sc_sender_infos = const offset_of!(Sigcontrol, sender_infos),
sc_control = const offset_of!(Sigcontrol, control_flags),
tcb_sa_off = const (offset_of!(crate::Tcb, os_specific) + offset_of!(RtSigarea, arch)),
sa_off_pctl = const offset_of!(SigArea, pctl),
sa_tmp_sp = const offset_of!(SigArea, tmp_sp),
sa_tmp_t1 = const offset_of!(SigArea, tmp_t1),
sa_tmp_t2 = const offset_of!(SigArea, tmp_t2),
sa_tmp_t3 = const offset_of!(SigArea, tmp_t3),
sa_tmp_t4 = const offset_of!(SigArea, tmp_t4),
sa_tmp_a0 = const offset_of!(SigArea, tmp_a0),
sa_tmp_a1 = const offset_of!(SigArea, tmp_a1),
sa_tmp_a2 = const offset_of!(SigArea, tmp_a2),
sa_tmp_a3 = const offset_of!(SigArea, tmp_a3),
sa_tmp_a4 = const offset_of!(SigArea, tmp_a4),
sa_tmp_a7 = const offset_of!(SigArea, tmp_a7),
sa_tmp_ip = const offset_of!(SigArea, tmp_ip),
sa_tmp_id_inf = const offset_of!(SigArea, tmp_id_inf),
sa_tmp_rt_inf = const offset_of!(SigArea, tmp_rt_inf),
sa_altstack_top = const offset_of!(SigArea, altstack_top),
sa_altstack_bottom = const offset_of!(SigArea, altstack_bottom),
pctl_off_actions = const offset_of!(SigProcControl, actions),
inner = sym inner_c,
pctl_off_pending = const offset_of!(SigProcControl, pending),
pctl_off_sender_infos = const offset_of!(SigProcControl, sender_infos),
SYS_CALL = const syscall::SYS_CALL,
RTINF_SIZE = const size_of::<RtSigInfo>(),
proc_fd = sym PROC_FD,
]);
asmfunction!(__relibc_internal_rlct_clone_ret: ["
ld t0, 0(sp)
ld a0, 8(sp)
ld a1, 16(sp)
ld a2, 24(sp)
ld a3, 32(sp)
ld a4, 40(sp)
ld a5, 48(sp)
addi sp, sp, 56
jalr t0
ret
"] <= []);
pub fn current_sp() -> usize {
let sp: usize;
unsafe {
core::arch::asm!(
"mv {}, sp",
out(reg) sp,
options(nomem));
}
sp
}
pub unsafe fn manually_enter_trampoline() {
let ctl = unsafe { &Tcb::current().unwrap().os_specific.control };
ctl.control_flags.store(
ctl.control_flags.load(Ordering::Relaxed) | syscall::flag::INHIBIT_DELIVERY.bits(),
Ordering::Release,
);
ctl.saved_archdep_reg.set(0);
let ip_location = &ctl.saved_ip as *const _ as usize;
unsafe {
core::arch::asm!("
jal 2f
j 3f
2:
sd ra, 0(t0)
la t0, __relibc_internal_sigentry
jalr x0, t0
3:
",
inout("t0") ip_location => _, out("ra") _);
}
}
unsafe extern "C" {
fn __relibc_internal_sigentry_crit_first();
fn __relibc_internal_sigentry_crit_second();
fn __relibc_internal_sigentry_crit_third();
fn __relibc_internal_sigentry_crit_fourth();
fn __relibc_internal_sigentry_crit_fifth();
}
pub unsafe fn arch_pre(stack: &mut SigStack, area: &mut SigArea) -> PosixStackt {
// It is impossible to update SP and PC atomically. Instead, we abuse the fact that
// signals are disabled in the prologue of the signal trampoline, which allows us to emulate
// atomicity inside the critical section, consisting of one instruction at 'crit_first', and
// one at 'crit_second', see asm.
if stack.regs.pc == __relibc_internal_sigentry_crit_first as u64 {
// Reexecute 'ld sp, (1 * 8)(sp)'
let stack_ptr = stack.regs.int_regs[1] as *const u64; // x2
stack.regs.int_regs[1] = unsafe { stack_ptr.add(1).read() };
// and 'jr gp' steps.
stack.regs.pc = stack.regs.int_regs[2];
} else if stack.regs.pc == __relibc_internal_sigentry_crit_second as u64
|| stack.regs.pc == __relibc_internal_sigentry_crit_fifth as u64
{
// just reexecute the jump
stack.regs.pc = stack.regs.int_regs[2];
} else if stack.regs.pc == __relibc_internal_sigentry_crit_third as u64 {
// ld gp, ({tcb_sa_off} + {sa_tmp_ip})(t1)
stack.regs.int_regs[2] = area.tmp_ip;
// ld t1, ({tcb_sa_off} + {sa_tmp_t1})(t1)
stack.regs.int_regs[5] = area.tmp_t1;
// j gp
stack.regs.pc = stack.regs.int_regs[2];
} else if stack.regs.pc == __relibc_internal_sigentry_crit_fourth as u64 {
// ld t1, ({tcb_sa_off} + {sa_tmp_t1})(t1)
stack.regs.int_regs[5] = area.tmp_t1;
// jr gp
stack.regs.pc = stack.regs.int_regs[2];
}
get_sigaltstack(area, stack.regs.int_regs[1] as usize).into()
}
pub fn arch_ret_to_sig(stack: &mut SigStack, control: &Sigcontrol) {
let orig_pc = core::mem::replace(&mut stack.regs.pc, __relibc_internal_sigentry as u64);
control.saved_ip.set(orig_pc as usize);
control
.saved_archdep_reg
.set(stack.regs.int_regs[4] as usize); // t0
}
pub(crate) static PROC_FD: SyncUnsafeCell<usize> = SyncUnsafeCell::new(usize::MAX);
static PROC_CALL: [usize; 1] = [ProcCall::Sigdeq as usize];
+528
View File
@@ -0,0 +1,528 @@
use core::{
cell::SyncUnsafeCell,
mem::offset_of,
ptr::NonNull,
sync::atomic::{AtomicU8, Ordering},
};
use syscall::{
data::{SigProcControl, Sigcontrol},
error::*,
};
use crate::{
Tcb,
proc::{FdGuard, FdGuardUpper, ForkArgs, fork_inner},
signal::{PROC_CONTROL_STRUCT, PosixStackt, RtSigarea, SigStack, get_sigaltstack, inner_c},
};
use redox_protocols::protocol::{ProcCall, RtSigInfo};
use super::ForkScratchpad;
// Setup a stack starting from the very end of the address space, and then growing downwards.
pub const STACK_TOP: usize = 1 << 47;
pub const STACK_SIZE: usize = 8 * 1024 * 1024;
#[derive(Debug, Default)]
#[repr(C)]
pub struct SigArea {
pub tmp_rip: usize,
pub tmp_rsp: usize,
pub tmp_rax: usize,
pub tmp_rdx: usize,
pub tmp_rdi: usize,
pub tmp_rsi: usize,
pub tmp_r8: usize,
pub tmp_r10: usize,
pub tmp_r12: usize,
pub tmp_rt_inf: RtSigInfo,
pub tmp_id_inf: u64,
pub altstack_top: usize,
pub altstack_bottom: usize,
pub disable_signals_depth: u64,
pub last_sig_was_restart: bool,
pub last_sigstack: Option<NonNull<SigStack>>,
}
#[repr(C, align(16))]
#[derive(Debug, Default)]
pub struct ArchIntRegs {
pub ymm_upper: [u128; 16],
pub fxsave: [u128; 29],
pub r15: usize, // fxsave "available" +0
pub r14: usize, // available +8
pub r13: usize, // available +16
pub r12: usize, // available +24
pub rbp: usize, // available +32
pub rbx: usize, // available +40
pub r11: usize, // outside fxsave, and so on
pub r10: usize,
pub r9: usize,
pub r8: usize,
pub rax: usize,
pub rcx: usize,
pub rdx: usize,
pub rsi: usize,
pub rdi: usize,
pub rflags: usize,
pub rip: usize,
pub rsp: usize,
}
/// Deactive TLS, used before exec() on Redox to not trick target executable into thinking TLS
/// is already initialized as if it was a thread.
pub unsafe fn deactivate_tcb(open_via_dup: &FdGuardUpper) -> Result<()> {
let mut env = syscall::EnvRegisters::default();
let file = open_via_dup.dup(b"regs/env")?;
env.fsbase = 0;
env.gsbase = 0;
file.write(&mut env)?;
Ok(())
}
unsafe extern "sysv64" fn fork_impl(args: &ForkArgs, initial_rsp: *mut usize) -> usize {
Error::mux(fork_inner(initial_rsp, args))
}
#[allow(unsafe_op_in_unsafe_fn)]
unsafe extern "sysv64" fn child_hook(scratchpad: &ForkScratchpad) {
let _ = syscall::close(scratchpad.cur_filetable_fd);
crate::child_hook_common(crate::ChildHookCommonArgs {
new_thr_fd: FdGuard::new(scratchpad.new_thr_fd),
new_proc_fd: if scratchpad.new_proc_fd == usize::MAX {
None
} else {
Some(FdGuard::new(scratchpad.new_proc_fd))
},
});
}
asmfunction!(__relibc_internal_fork_wrapper (usize) -> usize: ["
push rbp
mov rbp, rsp
push rbx
push rbp
push r12
push r13
push r14
push r15
sub rsp, 16
stmxcsr [rsp+16]
fnstcw [rsp+8]
// rdi: &ForkArgs
// rsi: initial_rsp
mov rsi, rsp
call {fork_impl}
add rsp, 64
pop rbp
ret
"] <= [fork_impl = sym fork_impl]);
asmfunction!(__relibc_internal_fork_ret: ["
# scratchpad is in rsi, move to rdi for child_hook
mov rdi, rsi
call {child_hook}
ldmxcsr [rsp + 16]
mov rcx, [rsp + 8]
xor rax, rax
add rsp, 16
pop r15
pop r14
pop r13
pop r12
pop rbp
pop rbx
pop rbp
ret
"] <= [child_hook = sym child_hook]);
asmfunction!(__relibc_internal_rlct_clone_ret: ["
# Load registers
pop rax
pop rdi
pop rsi
pop rdx
pop rcx
pop r8
pop r9
mov DWORD PTR [rsp - 8], 0x00001F80
ldmxcsr [rsp - 8]
mov WORD PTR [rsp - 8], 0x037F
fldcw [rsp - 8]
# Call entry point
call rax
ret
"] <= []);
asmfunction!(__relibc_internal_sigentry: ["
// Save some registers
mov fs:[{tcb_sa_off} + {sa_tmp_rsp}], rsp
mov fs:[{tcb_sa_off} + {sa_tmp_rax}], rax
mov fs:[{tcb_sa_off} + {sa_tmp_rdx}], rdx
mov fs:[{tcb_sa_off} + {sa_tmp_rdi}], rdi
mov fs:[{tcb_sa_off} + {sa_tmp_rsi}], rsi
mov fs:[{tcb_sa_off} + {sa_tmp_r8}], r8
mov fs:[{tcb_sa_off} + {sa_tmp_r10}], r10
mov fs:[{tcb_sa_off} + {sa_tmp_r12}], r12
// First, select signal, always pick first available bit
1:
// Read standard signal word - first targeting this thread
mov rax, fs:[{tcb_sc_off} + {sc_word}]
mov rdx, rax
shr rdx, 32
and eax, edx
bsf eax, eax
jnz 2f
// If no unblocked thread signal was found, check for process.
// This is competitive; we need to atomically check if *we* cleared the process-wide pending
// bit, otherwise restart.
mov eax, [rip + {pctl} + {pctl_off_pending}]
and eax, edx
bsf eax, eax
jz 8f
lea rdi, [rip + {pctl} + {pctl_off_sender_infos}]
mov rdi, [rdi + rax * 8]
lock btr [rip + {pctl} + {pctl_off_pending}], eax
mov fs:[{tcb_sa_off} + {sa_tmp_id_inf}], rdi
jc 9f
8:
// Read second signal word - both process and thread simultaneously.
// This must be done since POSIX requires low realtime signals to be picked first.
mov edx, fs:[{tcb_sc_off} + {sc_word} + 8]
mov eax, [rip + {pctl} + {pctl_off_pending} + 4]
or eax, edx
and eax, fs:[{tcb_sc_off} + {sc_word} + 12]
bsf eax, eax
jz 7f
bt edx, eax // check if signal was sent to thread specifically
jnc 81f
// if so, continue as usual
add eax, 32
jmp 2f
81:
// otherwise, try (competitively) dequeueing realtime signal
// SYS_CALL(fd, payload_base, payload_len, metadata_len | (flags << 8), metadata_base)
// rax rdi rsi rdx r10 r8
mov r12d, eax
mov rsi, fs:[0]
mov rdi, [rip+{proc_fd}]
add rsi, {tcb_sa_off} + {sa_tmp_rt_inf} // out pointer of dequeued realtime sig
mov rdx, {RTINF_SIZE}
mov [rsi], eax
lea r8, [rip + {proc_call_sigdeq}]
mov r10, 1
mov eax, {SYS_CALL}
syscall
test eax, eax
jnz 1b // assumes error can only be EAGAIN
lea eax, [r12d + 32]
jmp 9f
2:
mov edx, eax
shr edx, 5
mov rdi, fs:[{tcb_sc_off} + {sc_sender_infos} + eax * 8]
lock btr fs:[{tcb_sc_off} + {sc_word} + edx * 4], eax
mov fs:[{tcb_sa_off} + {sa_tmp_id_inf}], rdi
add eax, 64 // indicate signal was targeted at thread
9:
sub rsp, {REDZONE_SIZE}
and rsp, -{STACK_ALIGN}
// By now we have selected a signal, stored in eax (6-bit). We now need to choose whether or
// not to switch to the alternate signal stack. If SA_ONSTACK is clear for this signal, then
// skip the sigaltstack logic.
lea rdx, [rip + {pctl} + {pctl_off_actions}]
mov ecx, eax
and ecx, 63
// LEA doesn't support 16x, so just do two x8s.
lea rdx, [rdx + 8 * rcx]
lea rdx, [rdx + 8 * rcx]
bt qword ptr [rdx], {SA_ONSTACK_BIT}
jnc 4f
// Otherwise, the altstack is already active. The sigaltstack being disabled, is equivalent
// to setting 'top' to usize::MAX and 'bottom' to 0.
// If current RSP is above altstack region, switch to altstack
mov rdx, fs:[{tcb_sa_off} + {sa_altstack_top}]
cmp rsp, rdx
cmova rsp, rdx
// If current RSP is below altstack region, also switch to altstack
cmp rsp, fs:[{tcb_sa_off} + {sa_altstack_bottom}]
cmovbe rsp, rdx
.p2align 4
4:
// Now that we have a stack, we can finally start initializing the signal stack!
push fs:[{tcb_sa_off} + {sa_tmp_rsp}]
push fs:[{tcb_sc_off} + {sc_saved_rip}]
push fs:[{tcb_sc_off} + {sc_saved_rflags}]
push fs:[{tcb_sa_off} + {sa_tmp_rdi}]
push fs:[{tcb_sa_off} + {sa_tmp_rsi}]
push fs:[{tcb_sa_off} + {sa_tmp_rdx}]
push rcx
push fs:[{tcb_sa_off} + {sa_tmp_rax}]
push fs:[{tcb_sa_off} + {sa_tmp_r8}]
push r9
push fs:[{tcb_sa_off} + {sa_tmp_r10}]
push r11
push rbx
push rbp
push fs:[{tcb_sa_off} + {sa_tmp_r12}]
push r13
push r14
push r15
sub rsp, (29 + 16) * 16 // fxsave region minus available bytes
fxsave64 [rsp + 16 * 16]
// TODO: self-modifying?
cmp byte ptr [rip + {supports_avx}], 0
je 5f
// Prefer vextractf128 over vextracti128 since the former only requires AVX version 1.
vextractf128 [rsp + 15 * 16], ymm0, 1
vextractf128 [rsp + 14 * 16], ymm1, 1
vextractf128 [rsp + 13 * 16], ymm2, 1
vextractf128 [rsp + 12 * 16], ymm3, 1
vextractf128 [rsp + 11 * 16], ymm4, 1
vextractf128 [rsp + 10 * 16], ymm5, 1
vextractf128 [rsp + 9 * 16], ymm6, 1
vextractf128 [rsp + 8 * 16], ymm7, 1
vextractf128 [rsp + 7 * 16], ymm8, 1
vextractf128 [rsp + 6 * 16], ymm9, 1
vextractf128 [rsp + 5 * 16], ymm10, 1
vextractf128 [rsp + 4 * 16], ymm11, 1
vextractf128 [rsp + 3 * 16], ymm12, 1
vextractf128 [rsp + 2 * 16], ymm13, 1
vextractf128 [rsp + 16], ymm14, 1
vextractf128 [rsp], ymm15, 1
5:
mov [rsp - 4], eax
sub rsp, 64 // alloc space for ucontext fields
mov rdi, rsp
call {inner}
add rsp, 64
fxrstor64 [rsp + 16 * 16]
cmp byte ptr [rip + {supports_avx}], 0
je 6f
vinsertf128 ymm0, ymm0, [rsp + 15 * 16], 1
vinsertf128 ymm1, ymm1, [rsp + 14 * 16], 1
vinsertf128 ymm2, ymm2, [rsp + 13 * 16], 1
vinsertf128 ymm2, ymm2, [rsp + 12 * 16], 1
vinsertf128 ymm2, ymm2, [rsp + 11 * 16], 1
vinsertf128 ymm2, ymm2, [rsp + 10 * 16], 1
vinsertf128 ymm2, ymm2, [rsp + 9 * 16], 1
vinsertf128 ymm2, ymm2, [rsp + 8 * 16], 1
vinsertf128 ymm2, ymm2, [rsp + 7 * 16], 1
vinsertf128 ymm2, ymm2, [rsp + 6 * 16], 1
vinsertf128 ymm2, ymm2, [rsp + 5 * 16], 1
vinsertf128 ymm2, ymm2, [rsp + 4 * 16], 1
vinsertf128 ymm2, ymm2, [rsp + 3 * 16], 1
vinsertf128 ymm2, ymm2, [rsp + 2 * 16], 1
vinsertf128 ymm2, ymm2, [rsp + 16], 1
vinsertf128 ymm2, ymm2, [rsp], 1
6:
add rsp, (29 + 16) * 16
pop r15
pop r14
pop r13
pop r12
pop rbp
pop rbx
pop r11
pop r10
pop r9
pop r8
pop rax
pop rcx
pop rdx
pop rsi
pop rdi
popfq
pop qword ptr fs:[{tcb_sa_off} + {sa_tmp_rip}]
// x86 lacks atomic instructions for setting both the stack and instruction pointer
// simultaneously, except the slow microcoded IRETQ instruction. Thus, we let the arch_pre
// function emulate atomicity between the pop rsp and indirect jump.
.globl __relibc_internal_sigentry_crit_first
__relibc_internal_sigentry_crit_first:
pop rsp
.globl __relibc_internal_sigentry_crit_second
__relibc_internal_sigentry_crit_second:
jmp qword ptr fs:[{tcb_sa_off} + {sa_tmp_rip}]
7:
// A spurious signal occurred. Signals are still disabled here, but will need to be re-enabled.
// restore flags
mov rax, fs:[0] // load FS base
// TODO: Use lahf/sahf rather than pushfq/popfq?
lea rsp, [rax + {tcb_sc_off} + {sc_saved_rflags}]
popfq
// restore stack
mov rsp, fs:[{tcb_sa_off} + {sa_tmp_rsp}]
// move saved RIP away from control, allowing arch_pre to save us if interrupted.
mov rax, fs:[{tcb_sc_off} + {sc_saved_rip}]
mov fs:[{tcb_sa_off} + {sa_tmp_rip}], rax
// restore regs
mov rax, fs:[{tcb_sa_off} + {sa_tmp_rax}]
mov rdx, fs:[{tcb_sa_off} + {sa_tmp_rdx}]
// Re-enable signals. This code can be interrupted after this signal, so we need to define
// 'crit_third'.
and qword ptr fs:[{tcb_sc_off} + {sc_control}], ~1
.globl __relibc_internal_sigentry_crit_third
__relibc_internal_sigentry_crit_third:
jmp qword ptr fs:[{tcb_sa_off} + {sa_tmp_rip}]
"] <= [
inner = sym inner_c,
sa_tmp_rip = const offset_of!(SigArea, tmp_rip),
sa_tmp_rsp = const offset_of!(SigArea, tmp_rsp),
sa_tmp_rax = const offset_of!(SigArea, tmp_rax),
sa_tmp_rdx = const offset_of!(SigArea, tmp_rdx),
sa_tmp_rdi = const offset_of!(SigArea, tmp_rdi),
sa_tmp_rsi = const offset_of!(SigArea, tmp_rsi),
sa_tmp_r8 = const offset_of!(SigArea, tmp_r8),
sa_tmp_r10 = const offset_of!(SigArea, tmp_r10),
sa_tmp_r12 = const offset_of!(SigArea, tmp_r12),
sa_tmp_rt_inf = const offset_of!(SigArea, tmp_rt_inf),
sa_tmp_id_inf = const offset_of!(SigArea, tmp_id_inf),
sa_altstack_top = const offset_of!(SigArea, altstack_top),
sa_altstack_bottom = const offset_of!(SigArea, altstack_bottom),
sc_saved_rflags = const offset_of!(Sigcontrol, saved_archdep_reg),
sc_saved_rip = const offset_of!(Sigcontrol, saved_ip),
sc_word = const offset_of!(Sigcontrol, word),
sc_sender_infos = const offset_of!(Sigcontrol, sender_infos),
sc_control = const offset_of!(Sigcontrol, control_flags),
tcb_sa_off = const offset_of!(crate::Tcb, os_specific) + offset_of!(RtSigarea, arch),
tcb_sc_off = const offset_of!(crate::Tcb, os_specific) + offset_of!(RtSigarea, control),
pctl_off_actions = const offset_of!(SigProcControl, actions),
pctl_off_pending = const offset_of!(SigProcControl, pending),
pctl_off_sender_infos = const offset_of!(SigProcControl, sender_infos),
pctl = sym PROC_CONTROL_STRUCT,
supports_avx = sym SUPPORTS_AVX,
REDZONE_SIZE = const 128,
STACK_ALIGN = const 16,
SA_ONSTACK_BIT = const 58, // (1 << 58) >> 32 = 0x0400_0000
SYS_CALL = const syscall::SYS_CALL,
proc_call_sigdeq = sym PROC_CALL_SIGDEQ,
RTINF_SIZE = const size_of::<RtSigInfo>(),
proc_fd = sym PROC_FD,
]);
unsafe extern "C" {
fn __relibc_internal_sigentry_crit_first();
fn __relibc_internal_sigentry_crit_second();
fn __relibc_internal_sigentry_crit_third();
}
/// Fixes some edge cases, and calculates the value for uc_stack.
pub unsafe fn arch_pre(stack: &mut SigStack, area: &mut SigArea) -> PosixStackt {
// It is impossible to update RSP and RIP atomically on x86_64, without using IRETQ, which is
// almost as slow as calling a SIGRETURN syscall would be. Instead, we abuse the fact that
// signals are disabled in the prologue of the signal trampoline, which allows us to emulate
// atomicity inside the critical section, consisting of one instruction at 'crit_first', one at
// 'crit_second', and one at 'crit_third', see asm.
if stack.regs.rip == __relibc_internal_sigentry_crit_first as usize {
// Reexecute pop rsp and jump steps. This case needs to be different from the one below,
// since rsp has not been overwritten with the previous context's stack, just yet. At this
// point, we know [rsp+0] contains the saved RSP, and [rsp-8] contains the saved RIP.
let stack_ptr = stack.regs.rsp as *const usize;
stack.regs.rsp = unsafe { stack_ptr.read() };
stack.regs.rip = unsafe { stack_ptr.sub(1).read() };
} else if stack.regs.rip == __relibc_internal_sigentry_crit_second as usize
|| stack.regs.rip == __relibc_internal_sigentry_crit_third as usize
{
// Almost finished, just reexecute the jump before tmp_rip is overwritten by this
// deeper-level signal.
stack.regs.rip = area.tmp_rip;
}
get_sigaltstack(area, stack.regs.rsp).into()
}
/// Rearrange the restore-stack and sigarea in a way that makes it look like a new signal was
/// immediately delivered after restoring the allowset to what it was prior to the original signal delivery.
pub fn arch_ret_to_sig(stack: &mut SigStack, control: &Sigcontrol) {
let orig_rip = core::mem::replace(&mut stack.regs.rip, __relibc_internal_sigentry as usize);
control.saved_ip.set(orig_rip);
control.saved_archdep_reg.set(stack.regs.rflags);
}
pub(crate) static SUPPORTS_AVX: AtomicU8 = AtomicU8::new(0);
// __relibc will be prepended to the name, so no_mangle is fine
#[allow(unsafe_op_in_unsafe_fn)]
#[unsafe(no_mangle)]
pub unsafe fn manually_enter_trampoline() {
let c = &Tcb::current().unwrap().os_specific.control;
c.control_flags.store(
c.control_flags.load(Ordering::Relaxed) | syscall::flag::INHIBIT_DELIVERY.bits(),
Ordering::Release,
);
c.saved_archdep_reg.set(0); // TODO: Just reset DF on x86?
core::arch::asm!("
lea rax, [rip + 2f]
mov fs:[{tcb_sc_off} + {sc_saved_rip}], rax
jmp __relibc_internal_sigentry
2:
",
out("rax") _,
tcb_sc_off = const offset_of!(crate::Tcb, os_specific) + offset_of!(RtSigarea, control),
sc_saved_rip = const offset_of!(Sigcontrol, saved_ip),
);
}
/// Get current stack pointer, weak granularity guarantees.
pub fn current_sp() -> usize {
let sp: usize;
unsafe {
core::arch::asm!("mov {}, rsp", out(reg) sp);
}
sp
}
static PROC_CALL_SIGDEQ: u64 = ProcCall::Sigdeq as u64;
pub(crate) static PROC_FD: SyncUnsafeCell<usize> = SyncUnsafeCell::new(usize::MAX);
+313
View File
@@ -0,0 +1,313 @@
#![no_std]
#![allow(internal_features)]
#![deny(unsafe_op_in_unsafe_fn)]
#![feature(core_intrinsics, int_roundings, slice_ptr_get, sync_unsafe_cell)]
#![forbid(unreachable_patterns)]
use core::cell::UnsafeCell;
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
use generic_rt::ExpectTlsFree; // not used on aarch64 or riscv64
use generic_rt::GenericTcb;
use redox_protocols::protocol::ProcMeta;
use syscall::Sigcontrol;
use self::{
proc::{FdGuard, FdGuardUpper, STATIC_PROC_INFO},
sync::Mutex,
};
extern crate alloc;
#[macro_export]
macro_rules! asmfunction(
($name:ident $(($($arg:ty),*))? $(-> $ret:ty)? : [$($asmstmt:expr),*$(,)?] <= [$($decl:ident = $(sym $symname:ident)?$(const $constval:expr)?),*$(,)?]$(,)? ) => {
::core::arch::global_asm!(concat!("
.p2align 4
.section .text.", stringify!($name), ", \"ax\", @progbits
.globl ", stringify!($name), "
.type ", stringify!($name), ", @function
", stringify!($name), ":
", $($asmstmt, "\n",)* "
.size ", stringify!($name), ", . - ", stringify!($name), "
"), $($decl = $(sym $symname)?$(const $constval)?),*);
unsafe extern "C" {
pub fn $name($($(_: $arg),*)?) $(-> $ret)?;
}
}
);
pub mod arch;
pub mod proc;
// TODO: Replace auxvs with a non-stack-based interface, but keep getauxval for compatibility
#[path = "../../src/platform/auxv_defs.rs"]
pub mod auxv_defs;
pub mod signal;
pub mod sync;
pub mod sys;
pub mod thread;
#[derive(Debug, Default)]
pub struct RtTcb {
pub control: Sigcontrol,
pub arch: UnsafeCell<crate::arch::SigArea>,
pub thr_fd: UnsafeCell<Option<FdGuardUpper>>,
}
impl RtTcb {
pub fn current() -> &'static Self {
unsafe { &Tcb::current().unwrap().os_specific }
}
pub fn thread_fd(&self) -> &FdGuardUpper {
unsafe { (&*self.thr_fd.get()).as_ref().unwrap() }
}
}
pub type Tcb = GenericTcb<RtTcb>;
/// OS and architecture specific code to activate TLS - Redox aarch64
#[allow(unsafe_op_in_unsafe_fn)]
#[cfg(target_arch = "aarch64")]
pub unsafe fn tcb_activate(_tcb: &RtTcb, tls_end: usize, tls_len: usize) {
// Uses ABI page
let abi_ptr = tls_end - tls_len - 16;
core::ptr::write(abi_ptr as *mut usize, tls_end);
core::arch::asm!(
"msr tpidr_el0, {}",
in(reg) abi_ptr,
);
}
/// OS and architecture specific code to activate TLS - Redox x86
#[allow(unsafe_op_in_unsafe_fn)]
#[cfg(target_arch = "x86")]
pub unsafe fn tcb_activate(tcb: &RtTcb, tls_end: usize, _tls_len: usize) {
let mut env = syscall::EnvRegisters::default();
let file = tcb
.thread_fd()
.dup(b"regs/env")
.expect_notls("failed to open handle for process registers");
file.read(&mut env).expect_notls("failed to read gsbase");
env.gsbase = tls_end as u32;
file.write(&env).expect_notls("failed to write gsbase");
}
/// OS and architecture specific code to activate TLS - Redox x86_64
#[allow(unsafe_op_in_unsafe_fn)]
#[cfg(target_arch = "x86_64")]
pub unsafe fn tcb_activate(tcb: &RtTcb, tls_end_and_tcb_start: usize, _tls_len: usize) {
let mut env = syscall::EnvRegisters::default();
let file = tcb
.thread_fd()
.dup(b"regs/env")
.expect_notls("failed to open handle for process registers");
file.read(&mut env).expect_notls("failed to read fsbase");
env.fsbase = tls_end_and_tcb_start as u64;
file.write(&env).expect_notls("failed to write fsbase");
}
/// OS and architecture specific code to activate TLS - Redox riscv64
#[allow(unsafe_op_in_unsafe_fn)]
#[cfg(target_arch = "riscv64")]
pub unsafe fn tcb_activate(_tcb: &RtTcb, tls_end: usize, tls_len: usize) {
// tp points to static tls block
// FIXME limited to a single initial master
let tls_start = tls_end - tls_len;
let abi_ptr = tls_start - 8;
core::ptr::write(abi_ptr as *mut usize, tls_end);
core::arch::asm!(
"mv tp, {}",
in(reg) tls_start
);
}
/// Initialize redox-rt in situations where relibc is not used
#[allow(unsafe_op_in_unsafe_fn)]
#[cfg(not(feature = "proc"))]
pub unsafe fn initialize_freestanding(this_thr_fd: FdGuardUpper) -> &'static FdGuardUpper {
// TODO: This code is a hack! Integrate the ld_so TCB code into generic-rt, and then use that
// (this function will need pointers to the ELF structs normally passed in auxvs), so the TCB
// is initialized properly.
// TODO: TLS
let page = {
&mut *(syscall::fmap(
!0,
&syscall::Map {
offset: 0,
size: syscall::PAGE_SIZE,
flags: syscall::MapFlags::PROT_READ
| syscall::MapFlags::PROT_WRITE
| syscall::MapFlags::MAP_PRIVATE,
address: 0,
},
)
.unwrap() as *mut Tcb)
};
page.tcb_ptr = page;
page.tcb_len = syscall::PAGE_SIZE;
page.tls_end = (page as *mut Tcb).cast();
// Make sure to use ptr::write to prevent dropping the existing FdGuard
page.os_specific.thr_fd.get().write(Some(this_thr_fd));
#[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))]
unsafe {
let tcb_addr = page as *mut Tcb as usize;
tcb_activate(&page.os_specific, tcb_addr, 0)
}
#[cfg(target_arch = "aarch64")]
unsafe {
let abi_ptr = core::ptr::addr_of_mut!(page.tcb_ptr);
core::arch::asm!("msr tpidr_el0, {}", in(reg) abi_ptr);
}
#[cfg(target_arch = "riscv64")]
unsafe {
let abi_ptr = core::ptr::addr_of_mut!(page.tcb_ptr) as usize;
core::arch::asm!("mv tp, {}", in(reg) (abi_ptr + 8));
}
initialize();
(*page.os_specific.thr_fd.get()).as_ref().unwrap()
}
pub(crate) fn read_proc_meta(proc: &FdGuardUpper) -> syscall::Result<ProcMeta> {
let mut bytes = [0_u8; size_of::<ProcMeta>()];
proc.read(&mut bytes)?;
Ok(*plain::from_bytes::<ProcMeta>(&bytes).unwrap())
}
pub unsafe fn initialize(
#[cfg(feature = "proc")] proc_fd: FdGuardUpper,
#[cfg(feature = "proc")] ns_fd: Option<FdGuardUpper>,
) {
#[cfg(feature = "proc")]
let metadata = read_proc_meta(&proc_fd).unwrap();
#[cfg(not(feature = "proc"))]
// Bootstrap mode, don't associate proc fds with PIDs
let metadata = ProcMeta::default();
#[cfg(feature = "proc")]
{
unsafe { crate::arch::PROC_FD.get().write(proc_fd.as_raw_fd()) };
}
unsafe {
STATIC_PROC_INFO.get().write(StaticProcInfo {
pid: metadata.pid,
#[cfg(feature = "proc")]
proc_fd: Some(proc_fd),
#[cfg(not(feature = "proc"))]
proc_fd: None,
})
};
#[cfg(feature = "proc")]
{
*DYNAMIC_PROC_INFO.lock() = DynamicProcInfo {
pgid: metadata.pgid,
ruid: metadata.ruid,
euid: metadata.euid,
suid: metadata.suid,
egid: metadata.egid,
rgid: metadata.rgid,
sgid: metadata.sgid,
ns_fd,
};
}
}
pub(crate) struct StaticProcInfo {
pid: u32,
proc_fd: Option<FdGuardUpper>,
}
pub struct DynamicProcInfo {
pub pgid: u32,
pub euid: u32,
pub suid: u32,
pub ruid: u32,
pub egid: u32,
pub rgid: u32,
pub sgid: u32,
pub ns_fd: Option<FdGuardUpper>,
}
static DYNAMIC_PROC_INFO: Mutex<DynamicProcInfo> = Mutex::new(DynamicProcInfo {
pgid: u32::MAX,
ruid: u32::MAX,
euid: u32::MAX,
suid: u32::MAX,
rgid: u32::MAX,
egid: u32::MAX,
sgid: u32::MAX,
ns_fd: None,
});
#[inline]
pub(crate) fn static_proc_info() -> &'static StaticProcInfo {
unsafe { &*STATIC_PROC_INFO.get() }
}
#[inline]
pub fn current_proc_fd() -> &'static FdGuardUpper {
let info = static_proc_info();
info.proc_fd.as_ref().unwrap()
}
#[inline]
pub fn current_namespace_fd() -> syscall::Result<usize> {
DYNAMIC_PROC_INFO
.lock()
.ns_fd
.as_ref()
.map(|g| g.as_raw_fd())
.ok_or(syscall::Error::new(syscall::ENOENT))
}
struct ChildHookCommonArgs {
new_thr_fd: FdGuard,
new_proc_fd: Option<FdGuard>,
}
unsafe fn child_hook_common(args: ChildHookCommonArgs) {
let new_thr_fd = args.new_thr_fd.to_upper().unwrap();
let new_proc_fd = args.new_proc_fd.map(|x| x.to_upper().unwrap());
// TODO: just pass PID to child rather than obtaining it via IPC?
#[cfg(feature = "proc")]
let metadata = read_proc_meta(
new_proc_fd
.as_ref()
.expect("must be present with proc feature"),
)
.unwrap();
#[cfg(not(feature = "proc"))]
let metadata = ProcMeta::default();
if let Some(proc_fd) = &new_proc_fd {
unsafe { crate::arch::PROC_FD.get().write(proc_fd.as_raw_fd()) };
}
let old_proc_fd = unsafe {
STATIC_PROC_INFO
.get()
.replace(StaticProcInfo {
pid: metadata.pid,
proc_fd: new_proc_fd,
})
.proc_fd
};
drop(old_proc_fd);
let old_thr_fd = unsafe { RtTcb::current().thr_fd.get().replace(Some(new_thr_fd)) };
drop(old_thr_fd);
}
+1190
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+68
View File
@@ -0,0 +1,68 @@
// TODO: Share code for simple futex-based mutex between relibc's Mutex<()> and this.
use core::{
cell::UnsafeCell,
ops::{Deref, DerefMut},
sync::atomic::{AtomicU32, Ordering},
};
pub struct Mutex<T> {
pub lockword: AtomicU32,
pub inner: UnsafeCell<T>,
}
unsafe impl<T: Send> Send for Mutex<T> {}
unsafe impl<T: Send> Sync for Mutex<T> {}
impl<T> Mutex<T> {
/// Represents an unlocked [Mutex].
pub const UNLOCKED: u32 = 0;
/// Represents a locked [Mutex].
pub const LOCKED: u32 = 1;
/// Represents a waiting [Mutex].
pub const WAITING: u32 = 2;
pub const fn new(t: T) -> Self {
Self {
lockword: AtomicU32::new(0),
inner: UnsafeCell::new(t),
}
}
pub fn lock(&self) -> MutexGuard<'_, T> {
while self
.lockword
.compare_exchange(
Self::UNLOCKED,
Self::LOCKED,
Ordering::Acquire,
Ordering::Relaxed,
)
.is_err()
{
core::hint::spin_loop();
}
MutexGuard { lock: self }
}
}
pub struct MutexGuard<'l, T> {
lock: &'l Mutex<T>,
}
impl<T> Deref for MutexGuard<'_, T> {
type Target = T;
fn deref(&self) -> &T {
unsafe { &*self.lock.inner.get() }
}
}
impl<T> DerefMut for MutexGuard<'_, T> {
fn deref_mut(&mut self) -> &mut T {
unsafe { &mut *self.lock.inner.get() }
}
}
impl<T> Drop for MutexGuard<'_, T> {
fn drop(&mut self) {
self.lock
.lockword
.store(Mutex::<T>::UNLOCKED, Ordering::Release);
}
}
+569
View File
@@ -0,0 +1,569 @@
use core::{
mem::{replace, size_of},
ptr::addr_of,
sync::atomic::{AtomicU32, Ordering},
};
use ioslice::IoSlice;
use syscall::{
CallFlags, EINVAL, ERESTART, StdFsCallKind, TimeSpec,
data::StdFsCallMeta,
error::{self, EINTR, ENODEV, ESRCH, Error, Result},
};
use crate::{
DYNAMIC_PROC_INFO, DynamicProcInfo, RtTcb, Tcb,
arch::manually_enter_trampoline,
proc::{FdGuard, FdGuardUpper},
read_proc_meta,
signal::tmp_disable_signals,
};
use alloc::vec::Vec;
use redox_protocols::protocol::{
NsDup, ProcCall, ProcKillTarget, RtSigInfo, ThreadCall, WaitFlags,
};
#[inline]
fn wrapper<T>(restart: bool, erestart: bool, mut f: impl FnMut() -> Result<T>) -> Result<T> {
loop {
let _guard = tmp_disable_signals();
let rt_sigarea = unsafe { &Tcb::current().unwrap().os_specific };
let res = f();
let code = if erestart { ERESTART } else { EINTR };
if let Err(err) = res
&& err == Error::new(code)
{
unsafe {
manually_enter_trampoline();
}
if restart && unsafe { (*rt_sigarea.arch.get()).last_sig_was_restart } {
continue;
}
}
return res;
}
}
// TODO: uninitialized memory?
#[inline]
pub fn posix_read(fd: usize, buf: &mut [u8]) -> Result<usize> {
wrapper(true, false, || syscall::read(fd, buf))
}
#[inline]
pub fn posix_write(fd: usize, buf: &[u8]) -> Result<usize> {
wrapper(true, false, || syscall::write(fd, buf))
}
#[inline]
pub fn posix_kill(target: ProcKillTarget, sig: usize) -> Result<()> {
if sig > 64 {
return Err(Error::new(EINVAL));
}
match wrapper(false, true, || {
this_proc_call(
&mut [],
CallFlags::empty(),
&[ProcCall::Kill as u64, target.raw() as u64, sig as u64],
)
}) {
Ok(_) | Err(Error { errno: ERESTART }) => Ok(()),
Err(error) => Err(error),
}
}
#[inline]
pub fn posix_sigqueue(pid: usize, sig: usize, arg: usize) -> Result<()> {
let target = ProcKillTarget::from_raw(pid);
if !matches!(target, ProcKillTarget::SingleProc(_)) {
return Err(Error::new(ESRCH));
}
if sig <= 32 {
return posix_kill(target, sig);
}
let mut siginf = RtSigInfo {
arg,
code: -1, // TODO: SI_QUEUE constant
uid: 0, // TODO
pid: posix_getpid(),
};
match wrapper(false, true, || {
this_proc_call(
unsafe { plain::as_mut_bytes(&mut siginf) },
CallFlags::empty(),
&[ProcCall::Sigq as u64, pid as u64, sig as u64],
)
}) {
Ok(_)
| Err(Error {
errno: error::ERESTART,
}) => Ok(()),
Err(error) => Err(error),
}
}
#[inline]
pub fn posix_getpid() -> u32 {
// SAFETY: read-only except during program/fork child initialization
unsafe { addr_of!((*crate::STATIC_PROC_INFO.get()).pid).read() }
}
#[inline]
pub fn posix_getppid() -> u32 {
this_proc_call(&mut [], CallFlags::empty(), &[ProcCall::Getppid as u64]).expect("cannot fail")
as u32
}
#[inline]
pub fn posix_setpriority(which: i32, who: u32, prio: u32) -> Result<(), syscall::Error> {
if which != 0 {
return Err(syscall::Error::new(syscall::EINVAL)); // TODO: Add support for PRIO_PGRP and PRIO_PROCESS
}
this_proc_call(
&mut [],
CallFlags::empty(),
&[ProcCall::SetProcPriority as u64, who as u64, prio as u64],
)?;
Ok(())
}
#[inline]
pub fn posix_getpriority(which: i32, who: u32) -> Result<u32, syscall::Error> {
if which != 0 {
return Err(syscall::Error::new(syscall::EINVAL));
}
let res = this_proc_call(
&mut [],
CallFlags::empty(),
&[ProcCall::GetProcPriority as u64, who as u64],
)?;
Ok(res as u32)
}
#[inline]
pub unsafe fn sys_futex_wait(addr: *mut u32, val: u32, deadline: Option<&TimeSpec>) -> Result<()> {
wrapper(true, false, || {
unsafe {
syscall::syscall5(
syscall::SYS_FUTEX,
addr as usize,
syscall::FUTEX_WAIT,
val as usize,
deadline.map_or(0, |d| d as *const _ as usize),
0,
)
}
.map(|_| ())
})
}
#[inline]
pub unsafe fn sys_futex_wake(addr: *mut u32, num: u32) -> Result<u32> {
unsafe {
syscall::syscall5(
syscall::SYS_FUTEX,
addr as usize,
syscall::FUTEX_WAKE,
num as usize,
0,
0,
)
}
.map(|awoken| awoken as u32)
}
unsafe fn raw_sys_call(
fd: usize,
payload_ptr: *const u8,
len: usize,
flags: CallFlags,
metadata: &[u64],
) -> Result<usize> {
unsafe {
syscall::syscall5(
syscall::SYS_CALL,
fd,
payload_ptr as usize,
len,
metadata.len() | flags.bits(),
metadata.as_ptr() as usize,
)
}
}
pub fn sys_call_ro(
fd: usize,
payload: &mut [u8],
flags: CallFlags,
metadata: &[u64],
) -> Result<usize> {
unsafe {
raw_sys_call(
fd,
payload.as_mut_ptr(),
payload.len(),
flags | CallFlags::READ,
metadata,
)
}
}
pub fn sys_call_wo(fd: usize, payload: &[u8], flags: CallFlags, metadata: &[u64]) -> Result<usize> {
unsafe {
raw_sys_call(
fd,
payload.as_ptr(),
payload.len(),
flags | CallFlags::WRITE,
metadata,
)
}
}
pub fn sys_call_rw(
fd: usize,
payload: &mut [u8],
flags: CallFlags,
metadata: &[u64],
) -> Result<usize> {
unsafe {
raw_sys_call(
fd,
payload.as_mut_ptr(),
payload.len(),
flags | CallFlags::READ | CallFlags::WRITE,
metadata,
)
}
}
pub fn sys_call(
fd: usize,
payload: &mut [u8],
flags: CallFlags,
metadata: &[u64],
) -> Result<usize> {
unsafe { raw_sys_call(fd, payload.as_mut_ptr(), payload.len(), flags, metadata) }
}
pub fn this_proc_call(payload: &mut [u8], flags: CallFlags, metadata: &[u64]) -> Result<usize> {
proc_call(
crate::current_proc_fd().as_raw_fd(),
payload,
flags,
metadata,
)
}
pub fn proc_call(
proc_fd: usize,
payload: &mut [u8],
flags: CallFlags,
metadata: &[u64],
) -> Result<usize> {
sys_call(proc_fd, payload, flags, metadata)
}
pub fn thread_call(
thread_fd: usize,
payload: &mut [u8],
flags: CallFlags,
metadata: &[u64],
) -> Result<usize> {
sys_call(thread_fd, payload, flags, metadata)
}
pub fn this_thread_call(payload: &mut [u8], flags: CallFlags, metadata: &[u64]) -> Result<usize> {
thread_call(
RtTcb::current().thread_fd().as_raw_fd(),
payload,
flags,
metadata,
)
}
#[derive(Clone, Copy, Debug)]
pub enum WaitpidTarget {
AnyChild,
AnyGroupMember,
SingleProc { pid: usize },
ProcGroup { pgid: usize },
}
impl WaitpidTarget {
pub fn from_posix_arg(raw: isize) -> Self {
match raw {
0 => Self::AnyGroupMember,
-1 => Self::AnyChild,
1.. => Self::SingleProc { pid: raw as usize },
..-1 => Self::ProcGroup {
pgid: -raw as usize,
},
}
}
}
pub fn sys_waitpid(target: WaitpidTarget, status: &mut usize, flags: WaitFlags) -> Result<usize> {
let (call, pid) = match target {
WaitpidTarget::AnyChild => (ProcCall::Waitpid, 0),
WaitpidTarget::SingleProc { pid } => (ProcCall::Waitpid, pid),
WaitpidTarget::AnyGroupMember => (ProcCall::Waitpgid, 0),
WaitpidTarget::ProcGroup { pgid } => (ProcCall::Waitpgid, pgid),
};
wrapper(true, false, || {
this_proc_call(
unsafe { plain::as_mut_bytes(status) },
CallFlags::empty(),
&[call as u64, pid as u64, flags.bits() as u64],
)
})
}
pub fn posix_kill_thread(thread_fd: usize, signal: u32) -> Result<()> {
// TODO: don't hardcode?
if signal > 64 {
return Err(Error::new(EINVAL));
}
match wrapper(false, true, || {
thread_call(
thread_fd,
&mut [],
CallFlags::empty(),
&[ThreadCall::SignalThread as u64, signal.into()],
)
}) {
Ok(_) | Err(Error { errno: ERESTART }) => Ok(()),
Err(error) => Err(error),
}
}
static UMASK: AtomicU32 = AtomicU32::new(0o022);
/// Controls the set of bits removed from the `mode` mask when new file descriptors are created.
///
/// Must be validated by the caller
//
// TODO: validate here?
#[inline]
pub fn swap_umask(mask: u32) -> u32 {
UMASK.swap(mask, Ordering::AcqRel)
}
#[inline]
pub fn get_umask() -> u32 {
UMASK.load(Ordering::Acquire)
}
/// Real/Effective/Set-User/Group ID
pub struct Resugid<T> {
pub ruid: T,
pub euid: T,
pub suid: T,
pub rgid: T,
pub egid: T,
pub sgid: T,
}
/// Sets [res][ug]id, fields that are None will be unchanged.
pub fn posix_setresugid(ids: &Resugid<Option<u32>>) -> Result<()> {
// TODO: not sure how "tmp" an IPC call is?
let _sig_guard = tmp_disable_signals();
let mut guard = DYNAMIC_PROC_INFO.lock();
let mut buf = [0_u8; size_of::<u32>() * 6];
plain::slice_from_mut_bytes(&mut buf)
.unwrap()
.copy_from_slice(&[
ids.ruid.unwrap_or(u32::MAX),
ids.euid.unwrap_or(u32::MAX),
ids.suid.unwrap_or(u32::MAX),
ids.rgid.unwrap_or(u32::MAX),
ids.egid.unwrap_or(u32::MAX),
ids.sgid.unwrap_or(u32::MAX),
]);
this_proc_call(&mut buf, CallFlags::empty(), &[ProcCall::SetResugid as u64])?;
if let Some(ruid) = ids.ruid {
guard.ruid = ruid;
}
if let Some(euid) = ids.euid {
guard.euid = euid;
}
if let Some(suid) = ids.suid {
guard.suid = suid;
}
if let Some(rgid) = ids.rgid {
guard.rgid = rgid;
}
if let Some(egid) = ids.egid {
guard.egid = egid;
}
if let Some(sgid) = ids.sgid {
guard.sgid = sgid;
}
Ok(())
}
pub fn posix_getresugid() -> Resugid<u32> {
let _sig_guard = tmp_disable_signals();
let DynamicProcInfo {
ruid,
euid,
suid,
rgid,
egid,
sgid,
..
} = *DYNAMIC_PROC_INFO.lock();
Resugid {
ruid,
euid,
suid,
rgid,
egid,
sgid,
}
}
pub fn getens() -> Result<usize> {
read_proc_meta(crate::current_proc_fd()).map(|meta| meta.ens as usize)
}
pub fn get_proc_credentials(cap_fd: usize, target_pid: usize, buf: &mut [u8]) -> Result<usize> {
if buf.len() < size_of::<redox_protocols::protocol::ProcMeta>() {
return Err(Error::new(EINVAL));
}
proc_call(
cap_fd,
buf,
CallFlags::empty(),
&[ProcCall::GetProcCredentials as u64, target_pid as u64],
)
}
pub fn posix_exit(status: i32) -> ! {
this_proc_call(
&mut [],
CallFlags::empty(),
&[ProcCall::Exit as u64, (status & 0xFF) as u64],
)
.expect("failed to call proc mgr with Exit");
let _ = syscall::write(1, b"redox-rt: ProcCall::Exit FAILED, abort()ing!\n");
core::intrinsics::abort();
}
pub fn posix_getpgid(pid: usize) -> Result<usize> {
this_proc_call(
&mut [],
CallFlags::empty(),
&[ProcCall::Setpgid as u64, pid as u64, u64::wrapping_neg(1)],
)
}
pub fn posix_setpgid(pid: usize, pgid: usize) -> Result<()> {
if pgid == usize::wrapping_neg(1) {
return Err(Error::new(EINVAL));
}
this_proc_call(
&mut [],
CallFlags::empty(),
&[ProcCall::Setpgid as u64, pid as u64, pgid as u64],
)?;
Ok(())
}
pub fn posix_getsid(pid: usize) -> Result<usize> {
this_proc_call(
&mut [],
CallFlags::empty(),
&[ProcCall::Getsid as u64, pid as u64],
)
}
pub fn posix_setsid() -> Result<u32> {
this_proc_call(&mut [], CallFlags::empty(), &[ProcCall::Setsid as u64])?;
Ok(posix_getpid())
}
pub fn posix_nanosleep(rqtp: &TimeSpec, rmtp: &mut TimeSpec) -> Result<()> {
wrapper(false, false, || syscall::nanosleep(rqtp, rmtp))?;
Ok(())
}
pub fn setns(fd: usize) -> Option<FdGuardUpper> {
let mut info = DYNAMIC_PROC_INFO.lock();
let new_fd_guard = FdGuard::new(fd).to_upper().unwrap();
let old_fd_guard = replace(&mut info.ns_fd, Some(new_fd_guard));
old_fd_guard
}
pub fn getns() -> Result<usize> {
let cur_ns = crate::current_namespace_fd()?;
if cur_ns == usize::MAX {
Err(Error::new(ENODEV))
} else {
Ok(cur_ns)
}
}
pub fn open<T: AsRef<str>>(path: T, flags: usize) -> Result<usize> {
let path = path.as_ref();
let fcntl_flags = flags & syscall::O_FCNTL_MASK;
unsafe {
syscall::syscall5(
syscall::SYS_OPENAT,
crate::current_namespace_fd()?,
path.as_ptr() as usize,
path.len(),
flags,
fcntl_flags,
)
}
}
pub fn openat<T: AsRef<str>>(
fd: usize,
path: T,
flags: usize,
fcntl_flags: usize,
) -> Result<usize> {
let path = path.as_ref();
unsafe {
syscall::syscall5(
syscall::SYS_OPENAT,
fd,
path.as_ptr() as usize,
path.len(),
flags,
fcntl_flags,
)
}
}
pub fn unlink<T: AsRef<str>>(path: T, flags: usize) -> Result<usize> {
let path = path.as_ref();
unsafe {
syscall::syscall4(
syscall::SYS_UNLINKAT,
crate::current_namespace_fd()?,
path.as_ptr() as usize,
path.len(),
flags,
)
}
}
pub fn mkns(names: &[IoSlice]) -> Result<FdGuardUpper> {
let mut buf = Vec::from((NsDup::ForkNs as usize).to_ne_bytes());
for name in names {
let name_bytes = name.as_slice();
let len = name_bytes.len();
let _scheme_name = core::str::from_utf8(name_bytes).map_err(|_| Error::new(EINVAL))?;
buf.extend_from_slice(&len.to_ne_bytes());
buf.extend_from_slice(name_bytes);
}
FdGuard::new(syscall::dup(crate::current_namespace_fd()?, &buf)?).to_upper()
}
pub fn register_scheme_to_ns(ns_fd: usize, name: &str, cap_fd: usize) -> Result<()> {
let mut buf = alloc::vec::Vec::from((NsDup::IssueRegister as usize).to_ne_bytes());
buf.extend_from_slice(name.as_bytes());
let ns_this_scheme = FdGuard::new(syscall::dup(ns_fd, &buf)?);
let cap_bytes = cap_fd.to_ne_bytes();
ns_this_scheme.call_wo(&cap_bytes, CallFlags::FD, &[])?;
Ok(())
}
pub fn std_fs_call_ro(fd: usize, payload: &mut [u8], metadata: &StdFsCallMeta) -> Result<usize> {
sys_call_ro(fd, payload, CallFlags::STD_FS, metadata)
}
pub fn std_fs_call_wo(fd: usize, payload: &[u8], metadata: &StdFsCallMeta) -> Result<usize> {
sys_call_wo(fd, payload, CallFlags::STD_FS, metadata)
}
pub fn std_fs_call_rw(fd: usize, payload: &mut [u8], metadata: &StdFsCallMeta) -> Result<usize> {
sys_call_rw(fd, payload, CallFlags::STD_FS, metadata)
}
pub fn fstat(fd: usize, stat: &mut syscall::Stat) -> Result<usize> {
std_fs_call_ro(fd, stat, &StdFsCallMeta::new(StdFsCallKind::Fstat, 0, 0))
}
pub fn fcntl(fd: usize, cmd: usize, arg: usize) -> Result<usize> {
let _siglock = tmp_disable_signals();
let raw_fd = syscall::fcntl(fd, cmd, arg)?;
Ok(FdGuard::new(raw_fd).as_raw_fd())
}
+70
View File
@@ -0,0 +1,70 @@
use core::mem::size_of;
use syscall::Result;
use crate::{RtTcb, arch::*, proc::*, signal::tmp_disable_signals, static_proc_info};
/// Spawns a new context sharing the same address space as the current one (i.e. a new thread).
pub unsafe fn rlct_clone_impl(stack: *mut usize, tcb: &RtTcb) -> Result<usize> {
let proc_info = static_proc_info();
let cur_proc_fd = proc_info.proc_fd.as_ref().unwrap();
let cur_thr_fd = RtTcb::current().thread_fd();
let new_thr_fd = cur_proc_fd.dup(b"new-thread")?.to_upper().unwrap();
// Inherit existing address space
{
let cur_addr_space_fd = cur_thr_fd.dup(b"addrspace")?;
let new_addr_space_sel_fd = new_thr_fd.dup(b"current-addrspace")?;
let buf = create_set_addr_space_buf(
cur_addr_space_fd.as_raw_fd(),
__relibc_internal_rlct_clone_ret as *const () as usize,
stack as usize,
);
new_addr_space_sel_fd.write(&buf)?;
}
// Inherit reference to file table
{
let cur_filetable_fd = cur_thr_fd.dup(b"filetable")?;
let new_filetable_sel_fd = new_thr_fd.dup(b"current-filetable")?;
new_filetable_sel_fd.write(&usize::to_ne_bytes(cur_filetable_fd.as_raw_fd()))?;
}
// Since the signal handler is not yet initialized, signals specifically targeting the thread
// (relibc is only required to implement thread-specific signals that already originate from
// the same process) will be discarded. Process-specific signals will ignore this new thread,
// until it has initialized its own signal handler.
let start_fd = new_thr_fd.dup(b"start")?;
let fd = new_thr_fd.as_raw_fd();
unsafe {
tcb.thr_fd.get().write(Some(new_thr_fd));
}
// Unblock context.
start_fd.write(&[0])?;
Ok(fd)
}
pub unsafe fn exit_this_thread(stack_base: *mut (), stack_size: usize) -> ! {
let _guard = tmp_disable_signals();
let tcb = RtTcb::current();
// TODO: modify interface so it writes directly to the thread fd?
let status_fd = tcb.thread_fd().dup(b"status").unwrap();
let _ = unsafe { syscall::funmap(tcb as *const RtTcb as usize, syscall::PAGE_SIZE) };
let mut buf = [0; size_of::<usize>() * 3];
plain::slice_from_mut_bytes(&mut buf)
.unwrap()
.copy_from_slice(&[usize::MAX, stack_base as usize, stack_size]);
// TODO: SYS_CALL w/CONSUME
status_fd.write(&buf).unwrap();
unreachable!()
}
Executable
+58
View File
@@ -0,0 +1,58 @@
#!/usr/bin/env bash
set -e
target=$1
deps_dir=$2
if [ -z "$target" ] || [ -z "$deps_dir" ]; then
echo "Usage:\n\t./renamesyms.sh TARGET DEPS_DIR"
exit 1
fi
if [ ! -f "$target" ]; then
echo "Target file '$target' does not exist"
exit 1
fi
if [ ! -d "$deps_dir" ] ; then
echo "Deps dir '$deps_dir' does not exist or not a directory"
exit 1
fi
symbols_file=`mktemp`
special_syms=(
__rdl_oom
__rg_alloc
__rg_alloc_zeroed
__rg_dealloc
__rg_oom
__rg_realloc
__rust_alloc
__rust_alloc_error_handler
__rust_alloc_error_handler_should_panic
__rust_alloc_zeroed
__rust_dealloc
__rust_no_alloc_shim_is_unstable
__rust_realloc
)
for dep in `find $deps_dir -type f -name "*.rlib"`; do
"${NM}" --format=posix -g "$dep" 2>/dev/null | sed 's/.*:.*//g' | awk '{if ($2 == "T") print $1}' | sed 's/^\(.*\)$/\1 __relibc_\1/g' >> $symbols_file
done
for special_sym in "${special_syms[@]}"; do
echo "$special_sym __relibc_$special_sym" >> $symbols_file
done
mangled_alloc_syms=$("${NM}" --format=posix -g "$target" 2>/dev/null | awk '{print $1}' | grep "7___rustc" || true)
for sym in $mangled_alloc_syms; do
echo "$sym __relibc_$sym" >> $symbols_file
done
sorted_file=`mktemp`
sort -u "$symbols_file" > "$sorted_file"
rm -f "$symbols_file"
"${OBJCOPY}" --redefine-syms="$sorted_file" "$target"
rm -f "$sorted_file"
+3
View File
@@ -0,0 +1,3 @@
[toolchain]
channel = "nightly-2025-11-15"
components = ["rust-src"]
+21
View File
@@ -0,0 +1,21 @@
blank_lines_lower_bound = 0
blank_lines_upper_bound = 1
brace_style = "SameLineWhere"
disable_all_formatting = false
edition = "2024"
empty_item_single_line = true
fn_single_line = false
force_explicit_abi = true
format_strings = false
hard_tabs = false
imports_granularity = "Crate"
imports_indent = "Block"
imports_layout = "Mixed"
indent_style = "Block"
max_width = 100
newline_style = "Unix"
show_parse_errors = true
skip_children = false
tab_spaces = 4
trailing_comma = "Vertical"
where_single_line = false
-207
View File
@@ -1,207 +0,0 @@
use core::{
mem,
ops::{Deref, DerefMut},
slice,
};
use super::error::{Error, Result};
pub const PAGE_SIZE: usize = 4096;
/// Size of the metadata region used to transfer information from the kernel to the bootstrapper.
pub const KERNEL_METADATA_SIZE: usize = 4 * PAGE_SIZE;
#[cfg(feature = "userspace")]
macro_rules! syscall {
($($name:ident($a:ident, $($b:ident, $($c:ident, $($d:ident, $($e:ident, $($f:ident, $($g:ident, )?)?)?)?)?)?);)+) => {
$(
pub unsafe fn $name($a: usize, $($b: usize, $($c: usize, $($d: usize, $($e: usize, $($f: usize, $($g: usize)?)?)?)?)?)?) -> Result<usize> {
let ret: usize;
core::arch::asm!(
"svc 0",
in("x8") $a,
$(
in("x0") $b,
$(
in("x1") $c,
$(
in("x2") $d,
$(
in("x3") $e,
$(
in("x4") $f,
$(
in("x5") $g,
)?
)?
)?
)?
)?
)?
lateout("x0") ret,
options(nostack),
);
Error::demux(ret)
}
)+
};
}
#[cfg(feature = "userspace")]
syscall! {
syscall0(a,);
syscall1(a, b,);
syscall2(a, b, c,);
syscall3(a, b, c, d,);
syscall4(a, b, c, d, e,);
syscall5(a, b, c, d, e, f,);
syscall6(a, b, c, d, e, f, g,);
}
#[derive(Copy, Clone, Debug, Default)]
#[repr(C)]
pub struct IntRegisters {
pub x30: usize,
pub x29: usize,
pub x28: usize,
pub x27: usize,
pub x26: usize,
pub x25: usize,
pub x24: usize,
pub x23: usize,
pub x22: usize,
pub x21: usize,
pub x20: usize,
pub x19: usize,
pub x18: usize,
pub x17: usize,
pub x16: usize,
pub x15: usize,
pub x14: usize,
pub x13: usize,
pub x12: usize,
pub x11: usize,
pub x10: usize,
pub x9: usize,
pub x8: usize,
pub x7: usize,
pub x6: usize,
pub x5: usize,
pub x4: usize,
pub x3: usize,
pub x2: usize,
pub x1: usize,
pub x0: usize,
}
impl Deref for IntRegisters {
type Target = [u8];
fn deref(&self) -> &[u8] {
unsafe {
slice::from_raw_parts(
self as *const IntRegisters as *const u8,
mem::size_of::<IntRegisters>(),
)
}
}
}
impl DerefMut for IntRegisters {
fn deref_mut(&mut self) -> &mut [u8] {
unsafe {
slice::from_raw_parts_mut(
self as *mut IntRegisters as *mut u8,
mem::size_of::<IntRegisters>(),
)
}
}
}
#[derive(Clone, Copy, Debug, Default)]
#[repr(C, packed)]
pub struct FloatRegisters {
pub fp_simd_regs: [u128; 32],
pub fpsr: u32,
pub fpcr: u32,
}
impl Deref for FloatRegisters {
type Target = [u8];
fn deref(&self) -> &[u8] {
unsafe {
slice::from_raw_parts(
self as *const FloatRegisters as *const u8,
mem::size_of::<FloatRegisters>(),
)
}
}
}
impl DerefMut for FloatRegisters {
fn deref_mut(&mut self) -> &mut [u8] {
unsafe {
slice::from_raw_parts_mut(
self as *mut FloatRegisters as *mut u8,
mem::size_of::<FloatRegisters>(),
)
}
}
}
#[derive(Clone, Copy, Debug, Default)]
#[repr(C, packed)]
pub struct EnvRegisters {
pub tpidr_el0: usize,
pub tpidrro_el0: usize,
}
impl Deref for EnvRegisters {
type Target = [u8];
fn deref(&self) -> &[u8] {
unsafe {
slice::from_raw_parts(
self as *const EnvRegisters as *const u8,
mem::size_of::<EnvRegisters>(),
)
}
}
}
impl DerefMut for EnvRegisters {
fn deref_mut(&mut self) -> &mut [u8] {
unsafe {
slice::from_raw_parts_mut(
self as *mut EnvRegisters as *mut u8,
mem::size_of::<EnvRegisters>(),
)
}
}
}
#[derive(Clone, Copy, Debug, Default)]
#[repr(C, packed)]
pub struct Exception {
pub kind: usize,
// TODO
}
impl Deref for Exception {
type Target = [u8];
fn deref(&self) -> &[u8] {
unsafe {
slice::from_raw_parts(
self as *const Exception as *const u8,
mem::size_of::<Exception>(),
)
}
}
}
impl DerefMut for Exception {
fn deref_mut(&mut self) -> &mut [u8] {
unsafe {
slice::from_raw_parts_mut(
self as *mut Exception as *mut u8,
mem::size_of::<Exception>(),
)
}
}
}
-206
View File
@@ -1,206 +0,0 @@
use super::error::{Error, Result};
use core::arch::asm;
use core::{
mem,
ops::{Deref, DerefMut},
slice,
};
pub const PAGE_SIZE: usize = 4096;
/// Size of the metadata region used to transfer information from the kernel to the bootstrapper.
pub const KERNEL_METADATA_SIZE: usize = 4 * PAGE_SIZE;
#[cfg(feature = "userspace")]
macro_rules! syscall {
($($name:ident($a:ident, $($b:ident, $($c:ident, $($d:ident, $($e:ident, $($f:ident, $($g:ident, )?)?)?)?)?)?);)+) => {
$(
pub unsafe fn $name($a: usize, $($b: usize, $($c: usize, $($d: usize, $($e: usize, $($f: usize, $($g: usize)?)?)?)?)?)?) -> Result<usize> {
let ret: usize;
asm!(
"ecall",
in("a7") $a,
$(
in("a0") $b,
$(
in("a1") $c,
$(
in("a2") $d,
$(
in("a3") $e,
$(
in("a4") $f,
$(
in("a5") $g,
)?
)?
)?
)?
)?
)?
lateout("a0") ret,
options(nostack),
);
Error::demux(ret)
}
)+
};
}
#[cfg(feature = "userspace")]
syscall! {
syscall0(a,);
syscall1(a, b,);
syscall2(a, b, c,);
syscall3(a, b, c, d,);
syscall4(a, b, c, d, e,);
syscall5(a, b, c, d, e, f,);
syscall6(a, b, c, d, e, f, g,);
}
#[derive(Copy, Clone, Debug, Default)]
#[repr(C)]
pub struct IntRegisters {
pub pc: usize,
pub x31: usize,
pub x30: usize,
pub x29: usize,
pub x28: usize,
pub x27: usize,
pub x26: usize,
pub x25: usize,
pub x24: usize,
pub x23: usize,
pub x22: usize,
pub x21: usize,
pub x20: usize,
pub x19: usize,
pub x18: usize,
pub x17: usize,
pub x16: usize,
pub x15: usize,
pub x14: usize,
pub x13: usize,
pub x12: usize,
pub x11: usize,
pub x10: usize,
pub x9: usize,
pub x8: usize,
pub x7: usize,
pub x6: usize,
pub x5: usize,
// x4(tp) is in env
// x3(gp) is a platform scratch register
pub x2: usize,
pub x1: usize,
}
impl Deref for IntRegisters {
type Target = [u8];
fn deref(&self) -> &[u8] {
unsafe {
slice::from_raw_parts(
self as *const IntRegisters as *const u8,
mem::size_of::<IntRegisters>(),
)
}
}
}
impl DerefMut for IntRegisters {
fn deref_mut(&mut self) -> &mut [u8] {
unsafe {
slice::from_raw_parts_mut(
self as *mut IntRegisters as *mut u8,
mem::size_of::<IntRegisters>(),
)
}
}
}
#[derive(Clone, Copy, Debug, Default)]
#[repr(C, packed)]
pub struct FloatRegisters {
pub fregs: [u64; 32],
pub fcsr: u32,
}
impl Deref for FloatRegisters {
type Target = [u8];
fn deref(&self) -> &[u8] {
unsafe {
slice::from_raw_parts(
self as *const FloatRegisters as *const u8,
mem::size_of::<FloatRegisters>(),
)
}
}
}
impl DerefMut for FloatRegisters {
fn deref_mut(&mut self) -> &mut [u8] {
unsafe {
slice::from_raw_parts_mut(
self as *mut FloatRegisters as *mut u8,
mem::size_of::<FloatRegisters>(),
)
}
}
}
#[derive(Clone, Copy, Debug, Default)]
#[repr(packed)]
pub struct EnvRegisters {
pub tp: usize,
}
impl Deref for EnvRegisters {
type Target = [u8];
fn deref(&self) -> &[u8] {
unsafe {
slice::from_raw_parts(
self as *const EnvRegisters as *const u8,
mem::size_of::<EnvRegisters>(),
)
}
}
}
impl DerefMut for EnvRegisters {
fn deref_mut(&mut self) -> &mut [u8] {
unsafe {
slice::from_raw_parts_mut(
self as *mut EnvRegisters as *mut u8,
mem::size_of::<EnvRegisters>(),
)
}
}
}
#[derive(Clone, Copy, Debug, Default)]
#[repr(C, packed)]
pub struct Exception {
pub kind: usize,
// TODO
}
impl Deref for Exception {
type Target = [u8];
fn deref(&self) -> &[u8] {
unsafe {
slice::from_raw_parts(
self as *const Exception as *const u8,
mem::size_of::<Exception>(),
)
}
}
}
impl DerefMut for Exception {
fn deref_mut(&mut self) -> &mut [u8] {
unsafe {
slice::from_raw_parts_mut(
self as *mut Exception as *mut u8,
mem::size_of::<Exception>(),
)
}
}
}
-288
View File
@@ -1,288 +0,0 @@
use core::{
arch::asm,
mem,
ops::{Deref, DerefMut},
slice,
};
use super::error::{Error, Result};
pub const PAGE_SIZE: usize = 4096;
/// Size of the metadata region used to transfer information from the kernel to the bootstrapper.
pub const KERNEL_METADATA_SIZE: usize = 4 * PAGE_SIZE;
#[cfg(feature = "userspace")]
macro_rules! syscall {
($($name:ident($a:ident, $($b:ident, $($c:ident, $($d:ident, $($e:ident, $($f:ident, )?)?)?)?)?);)+) => {
$(
pub unsafe fn $name(mut $a: usize, $($b: usize, $($c: usize, $($d: usize, $($e: usize, $($f: usize)?)?)?)?)?) -> Result<usize> {
asm!(
"int 0x80",
inout("eax") $a,
$(
in("ebx") $b,
$(
in("ecx") $c,
$(
in("edx") $d,
$(
in("esi") $e,
$(
in("edi") $f,
)?
)?
)?
)?
)?
options(nostack),
);
Error::demux($a)
}
)+
};
}
#[cfg(feature = "userspace")]
syscall! {
syscall0(a,);
syscall1(a, b,);
syscall2(a, b, c,);
syscall3(a, b, c, d,);
// Must be done custom because LLVM reserves ESI
//syscall4(a, b, c, d, e,);
//syscall5(a, b, c, d, e, f,);
//syscall6(a, b, c, d, e, f, g,);
}
#[cfg(feature = "userspace")]
pub unsafe fn syscall4(mut a: usize, b: usize, c: usize, d: usize, e: usize) -> Result<usize> {
asm!(
"xchg esi, {e}
int 0x80
xchg esi, {e}",
e = in(reg) e,
inout("eax") a,
in("ebx") b,
in("ecx") c,
in("edx") d,
options(nostack),
);
Error::demux(a)
}
#[cfg(feature = "userspace")]
pub unsafe fn syscall5(
mut a: usize,
b: usize,
c: usize,
d: usize,
e: usize,
f: usize,
) -> Result<usize> {
asm!(
"xchg esi, {e}
int 0x80
xchg esi, {e}",
e = in(reg) e,
inout("eax") a,
in("ebx") b,
in("ecx") c,
in("edx") d,
in("edi") f,
options(nostack),
);
Error::demux(a)
}
#[cfg(feature = "userspace")]
pub unsafe fn syscall6(
mut a: usize,
b: usize,
c: usize,
d: usize,
e: usize,
f: usize,
g: usize,
) -> Result<usize> {
#[repr(C)]
struct PackedArgs {
arg4: usize,
arg6: usize,
nr: usize,
}
let args = PackedArgs {
arg4: e,
arg6: g,
nr: a,
};
let args_ptr = &args as *const PackedArgs;
asm!(
"push ebp",
"push esi",
"mov esi, [eax + 0]", // arg4 -> esi
"mov ebp, [eax + 4]", // arg6 -> ebp
"mov eax, [eax + 8]", // nr -> eax
"int 0x80",
"pop esi",
"pop ebp",
inout("eax") args_ptr => a,
in("ebx") b,
in("ecx") c,
in("edx") d,
in("edi") f,
options(nostack),
);
Error::demux(a)
}
#[derive(Copy, Clone, Debug, Default)]
#[repr(C)]
pub struct IntRegisters {
// TODO: Some of these don't get set by Redox yet. Should they?
pub ebp: usize,
pub esi: usize,
pub edi: usize,
pub ebx: usize,
pub eax: usize,
pub ecx: usize,
pub edx: usize,
// pub orig_rax: usize,
pub eip: usize,
pub cs: usize,
pub eflags: usize,
pub esp: usize,
pub ss: usize,
// pub fs_base: usize,
// pub gs_base: usize,
// pub ds: usize,
// pub es: usize,
pub fs: usize,
// pub gs: usize
}
impl Deref for IntRegisters {
type Target = [u8];
fn deref(&self) -> &[u8] {
unsafe {
slice::from_raw_parts(
self as *const IntRegisters as *const u8,
mem::size_of::<IntRegisters>(),
)
}
}
}
impl DerefMut for IntRegisters {
fn deref_mut(&mut self) -> &mut [u8] {
unsafe {
slice::from_raw_parts_mut(
self as *mut IntRegisters as *mut u8,
mem::size_of::<IntRegisters>(),
)
}
}
}
#[derive(Clone, Copy, Debug, Default)]
#[repr(C, packed)]
pub struct FloatRegisters {
pub fcw: u16,
pub fsw: u16,
pub ftw: u8,
pub _reserved: u8,
pub fop: u16,
pub fip: u64,
pub fdp: u64,
pub mxcsr: u32,
pub mxcsr_mask: u32,
pub st_space: [u128; 8],
pub xmm_space: [u128; 16],
// TODO: YMM/ZMM
}
impl Deref for FloatRegisters {
type Target = [u8];
fn deref(&self) -> &[u8] {
unsafe {
slice::from_raw_parts(
self as *const FloatRegisters as *const u8,
mem::size_of::<FloatRegisters>(),
)
}
}
}
impl DerefMut for FloatRegisters {
fn deref_mut(&mut self) -> &mut [u8] {
unsafe {
slice::from_raw_parts_mut(
self as *mut FloatRegisters as *mut u8,
mem::size_of::<FloatRegisters>(),
)
}
}
}
#[derive(Clone, Copy, Debug, Default)]
#[repr(C, packed)]
pub struct EnvRegisters {
pub fsbase: u32,
pub gsbase: u32,
}
impl Deref for EnvRegisters {
type Target = [u8];
fn deref(&self) -> &[u8] {
unsafe {
slice::from_raw_parts(
self as *const EnvRegisters as *const u8,
mem::size_of::<EnvRegisters>(),
)
}
}
}
impl DerefMut for EnvRegisters {
fn deref_mut(&mut self) -> &mut [u8] {
unsafe {
slice::from_raw_parts_mut(
self as *mut EnvRegisters as *mut u8,
mem::size_of::<EnvRegisters>(),
)
}
}
}
#[derive(Clone, Copy, Debug, Default)]
#[repr(C, packed)]
pub struct Exception {
pub kind: usize,
pub code: usize,
pub address: usize,
}
impl Deref for Exception {
type Target = [u8];
fn deref(&self) -> &[u8] {
unsafe {
slice::from_raw_parts(
self as *const Exception as *const u8,
mem::size_of::<Exception>(),
)
}
}
}
impl DerefMut for Exception {
fn deref_mut(&mut self) -> &mut [u8] {
unsafe {
slice::from_raw_parts_mut(
self as *mut Exception as *mut u8,
mem::size_of::<Exception>(),
)
}
}
}
-194
View File
@@ -1,194 +0,0 @@
use core::{
mem,
ops::{Deref, DerefMut},
slice,
};
pub const PAGE_SIZE: usize = 4096;
/// Size of the metadata region used to transfer information from the kernel to the bootstrapper.
pub const KERNEL_METADATA_SIZE: usize = 4 * PAGE_SIZE;
#[cfg(feature = "userspace")]
macro_rules! syscall {
($($name:ident($a:ident, $($b:ident, $($c:ident, $($d:ident, $($e:ident, $($f:ident, $($g:ident, )?)?)?)?)?)?);)+) => {
$(
pub unsafe fn $name(mut $a: usize, $($b: usize, $($c: usize, $($d: usize, $($e: usize, $($f: usize, $($g: usize)?)?)?)?)?)?) -> crate::error::Result<usize> {
core::arch::asm!(
"syscall",
inout("rax") $a,
$(
in("rdi") $b,
$(
in("rsi") $c,
$(
in("rdx") $d,
$(
in("r10") $e,
$(
in("r8") $f,
$(
in("r9") $g,
)?
)?
)?
)?
)?
)?
out("rcx") _,
out("r11") _,
options(nostack),
);
crate::error::Error::demux($a)
}
)+
};
}
#[cfg(feature = "userspace")]
syscall! {
syscall0(a,);
syscall1(a, b,);
syscall2(a, b, c,);
syscall3(a, b, c, d,);
syscall4(a, b, c, d, e,);
syscall5(a, b, c, d, e, f,);
syscall6(a, b, c, d, e, f, g,);
}
#[derive(Copy, Clone, Debug, Default)]
#[repr(C)]
pub struct IntRegisters {
pub r15: usize,
pub r14: usize,
pub r13: usize,
pub r12: usize,
pub rbp: usize,
pub rbx: usize,
pub r11: usize,
pub r10: usize,
pub r9: usize,
pub r8: usize,
pub rax: usize,
pub rcx: usize,
pub rdx: usize,
pub rsi: usize,
pub rdi: usize,
pub rip: usize,
pub cs: usize,
pub rflags: usize,
pub rsp: usize,
pub ss: usize,
}
impl Deref for IntRegisters {
type Target = [u8];
fn deref(&self) -> &[u8] {
unsafe { slice::from_raw_parts(self as *const Self as *const u8, mem::size_of::<Self>()) }
}
}
impl DerefMut for IntRegisters {
fn deref_mut(&mut self) -> &mut [u8] {
unsafe { slice::from_raw_parts_mut(self as *mut Self as *mut u8, mem::size_of::<Self>()) }
}
}
#[derive(Clone, Copy, Debug, Default)]
#[repr(C, packed)]
pub struct FloatRegisters {
pub fcw: u16,
pub fsw: u16,
pub ftw: u8,
pub _reserved: u8,
pub fop: u16,
pub fip: u64,
pub fdp: u64,
pub mxcsr: u32,
pub mxcsr_mask: u32,
pub st_space: [u128; 8],
pub xmm_space: [u128; 16],
// TODO: YMM/ZMM
}
impl Deref for FloatRegisters {
type Target = [u8];
fn deref(&self) -> &[u8] {
unsafe {
slice::from_raw_parts(
self as *const FloatRegisters as *const u8,
mem::size_of::<FloatRegisters>(),
)
}
}
}
impl DerefMut for FloatRegisters {
fn deref_mut(&mut self) -> &mut [u8] {
unsafe {
slice::from_raw_parts_mut(
self as *mut FloatRegisters as *mut u8,
mem::size_of::<FloatRegisters>(),
)
}
}
}
#[derive(Clone, Copy, Debug, Default)]
#[repr(C, packed)]
pub struct EnvRegisters {
pub fsbase: u64,
pub gsbase: u64,
// TODO: PKRU?
}
impl Deref for EnvRegisters {
type Target = [u8];
fn deref(&self) -> &[u8] {
unsafe {
slice::from_raw_parts(
self as *const EnvRegisters as *const u8,
mem::size_of::<EnvRegisters>(),
)
}
}
}
impl DerefMut for EnvRegisters {
fn deref_mut(&mut self) -> &mut [u8] {
unsafe {
slice::from_raw_parts_mut(
self as *mut EnvRegisters as *mut u8,
mem::size_of::<EnvRegisters>(),
)
}
}
}
#[derive(Clone, Copy, Debug, Default)]
#[repr(C, packed)]
pub struct Exception {
pub kind: usize,
pub code: usize,
pub address: usize,
}
impl Deref for Exception {
type Target = [u8];
fn deref(&self) -> &[u8] {
unsafe {
slice::from_raw_parts(
self as *const Exception as *const u8,
mem::size_of::<Exception>(),
)
}
}
}
impl DerefMut for Exception {
fn deref_mut(&mut self) -> &mut [u8] {
unsafe {
slice::from_raw_parts_mut(
self as *mut Exception as *mut u8,
mem::size_of::<Exception>(),
)
}
}
}
+13
View File
@@ -0,0 +1,13 @@
double strtod(const char *nptr, char **endptr);
long double strtold(const char *nptr, char **endptr) {
return (long double)strtod(nptr, endptr);
}
double relibc_ldtod(const long double* val) {
return (double)(*val);
}
void relibc_dtold(double val, long double* out) {
*out = (long double)val;
}
+322
View File
@@ -0,0 +1,322 @@
//! Nul-terminated byte strings.
use core::{marker::PhantomData, ptr::NonNull, str::Utf8Error};
use alloc::{borrow::Cow, string::String};
use crate::platform::types::{c_char, wchar_t};
mod private {
pub trait Sealed {}
}
#[derive(Clone, Copy, Debug)]
pub enum Thin {}
#[derive(Clone, Copy, Debug)]
pub enum Wide {}
impl private::Sealed for Thin {}
impl private::Sealed for Wide {}
pub trait Kind: private::Sealed + Copy + 'static {
/// c_char or wchar_t
type C: Copy + 'static;
// u8 or u32
type Char: Copy + From<u8> + Into<u32> + PartialEq + 'static;
const NUL: Self::Char;
const IS_THIN_NOT_WIDE: bool;
fn r2c(c: Self::Char) -> Self::C;
fn c2r(c: Self::C) -> Self::Char;
fn chars_from_bytes(b: &[u8]) -> Option<&[Self::Char]>;
fn chars_to_bytes(c: &[Self::Char]) -> Option<&[u8]>;
unsafe fn strlen(s: *const Self::C) -> usize;
unsafe fn strchr(s: *const Self::C, c: Self::C) -> *const Self::C;
unsafe fn strchrnul(s: *const Self::C, c: Self::C) -> *const Self::C;
}
impl Kind for Thin {
type C = c_char;
type Char = u8;
const NUL: Self::Char = 0;
const IS_THIN_NOT_WIDE: bool = true;
unsafe fn strlen(s: *const c_char) -> usize {
unsafe { crate::header::string::strlen(s) }
}
unsafe fn strchr(s: *const c_char, c: c_char) -> *const c_char {
unsafe { crate::header::string::strchr(s, c.into()) }
}
unsafe fn strchrnul(s: *const c_char, c: c_char) -> *const c_char {
unsafe { crate::header::string::strchrnul(s, c.into()) }
}
fn r2c(c: u8) -> c_char {
c as _
}
fn c2r(c: c_char) -> u8 {
c as _
}
fn chars_from_bytes(b: &[u8]) -> Option<&[Self::Char]> {
Some(b)
}
fn chars_to_bytes(c: &[Self::Char]) -> Option<&[u8]> {
Some(c)
}
}
impl Kind for Wide {
type C = wchar_t;
type Char = u32;
const NUL: Self::Char = 0;
const IS_THIN_NOT_WIDE: bool = false;
unsafe fn strlen(s: *const Self::C) -> usize {
unsafe { crate::header::wchar::wcslen(s) }
}
unsafe fn strchr(s: *const Self::C, c: Self::C) -> *const Self::C {
unsafe { crate::header::wchar::wcschr(s, c) }
}
unsafe fn strchrnul(mut s: *const Self::C, c: Self::C) -> *const Self::C {
// TODO: optimized function
while unsafe { s.read() } != c && unsafe { s.read() } != 0 {
s = unsafe { s.add(1) };
}
s
}
fn r2c(c: Self::Char) -> Self::C {
c as _
}
fn c2r(c: Self::C) -> Self::Char {
c as _
}
fn chars_from_bytes(b: &[u8]) -> Option<&[Self::Char]> {
None
}
fn chars_to_bytes(c: &[Self::Char]) -> Option<&[u8]> {
None
}
}
/// Safe wrapper for immutable borrowed C strings, guaranteed to be the same layout as `*const u8`.
#[derive(Clone, Copy)]
#[repr(transparent)]
pub struct NulStr<'a, T: Kind> {
ptr: NonNull<T::C>,
_marker: PhantomData<&'a [u8]>,
}
pub type CStr<'a> = NulStr<'a, Thin>;
pub type WStr<'a> = NulStr<'a, Wide>;
impl<'a, T: Kind> NulStr<'a, T> {
/// Safety
///
/// The ptr must be valid up to and including the first NUL byte from the base ptr.
pub const unsafe fn from_ptr(ptr: *const T::C) -> Self {
Self {
ptr: unsafe { NonNull::new_unchecked(ptr.cast_mut()) },
_marker: PhantomData,
}
}
pub unsafe fn from_nullable_ptr(ptr: *const T::C) -> Option<Self> {
if ptr.is_null() {
None
} else {
Some(unsafe { Self::from_ptr(ptr) })
}
}
/// Look for the closest occurence of `c`, and if found, split the string into a slice up to
/// that byte and a `CStr` starting at that byte.
#[inline]
#[doc(alias = "strchrnul")]
pub fn find_get_subslice_or_all(
self,
c: impl Into<T::Char>,
) -> Result<(&'a [T::Char], Self), (&'a [T::Char], Self)> {
let c = c.into();
// SAFETY: strchrnul expects self.as_ptr() to be valid up to and including its last NUL
// byte
let found = unsafe { T::strchrnul(self.as_ptr(), T::r2c(c)) };
// SAFETY: the pointer returned from strchrnul is always a substring of this string, and
// hence always valid as a CStr.
let found = unsafe { Self::from_ptr(found) };
let until = unsafe { self.slice_until_substr(found) };
if found.first() == T::NUL {
// The character was not found, and we got the end of the string instead.
Err((until, found))
} else {
Ok((until, found))
}
}
/// # Safety
///
/// `substr` must be contained within `self`
#[inline]
pub unsafe fn slice_until_substr(self, substr: NulStr<'_, T>) -> &'a [T::Char] {
let index = unsafe {
// SAFETY: the sub-pointer as returned by strchr must be derived from the same
// allocation
substr.as_ptr().offset_from(self.as_ptr()) as usize
};
unsafe { core::slice::from_raw_parts(self.as_ptr().cast::<T::Char>(), index) }
}
/// Look for the closest occurence of `c`, and if found, split the string into a slice up to
/// that byte and a `CStr` starting at that byte.
#[inline]
pub fn find_get_subslice(self, c: T::Char) -> Option<(&'a [T::Char], Self)> {
let rest = self.find(c)?;
// SAFETY: the output of strchr is obviously a substring if it doesn't return NULL
Some((unsafe { self.slice_until_substr(rest) }, rest))
}
/// Look for the closest occurence of `c`, and return a new string starting at that byte if
/// found.
#[doc(alias = "strchr")]
#[doc(alias = "wcschr")]
#[inline]
pub fn find(self, c: T::Char) -> Option<Self> {
unsafe {
// SAFETY: the only requirement is for self.as_ptr() to be valid up to and including
// the nearest NUL byte, which this type requires
let ret = T::strchr(self.as_ptr(), T::r2c(c));
// SAFETY: strchr must either return NULL (not found) or a substring of self, which can
// never exceed the nearest NUL byte of self
Self::from_nullable_ptr(ret)
}
}
// TODO: strrchr, strchrnul wrappers
#[inline]
pub fn contains(self, c: T::Char) -> bool {
self.find(c).is_some()
}
#[inline]
pub fn first(self) -> T::Char {
unsafe {
// SAFETY: Self must be valid up to and including its nearest NUL byte, which certainly
// implies its readable length is nonzero (string is empty if this first byte is 0).
T::c2r(self.ptr.read())
}
}
#[inline]
pub fn first_char(self) -> Option<char> {
char::from_u32(self.first().into())
}
/// Same as `split_first` except also requires that the first char be convertible into `char`
#[inline]
pub fn split_first_char(self) -> Option<(char, Self)> {
self.split_first()
.and_then(|(c, r)| Some((char::from_u32(c.into())?, r)))
}
/// Split this string into `Some((first_byte, string_after_that))` or `None` if empty.
#[inline]
pub fn split_first(self) -> Option<(T::Char, Self)> {
if self.first() == T::NUL {
return None;
}
Some((self.first(), unsafe {
Self::from_ptr(self.as_ptr().add(1))
}))
}
pub fn to_chars_with_nul(self) -> &'a [T::Char] {
unsafe {
// SAFETY: The string must be valid at least until (and including) the NUL byte.
let len = T::strlen(self.ptr.as_ptr());
core::slice::from_raw_parts(self.ptr.as_ptr().cast(), len + 1)
}
}
pub fn to_chars(self) -> &'a [T::Char] {
let s = self.to_chars_with_nul();
&s[..s.len() - 1]
}
pub const fn as_ptr(self) -> *const T::C {
self.ptr.as_ptr()
}
pub const unsafe fn from_chars_with_nul_unchecked(chars: &'a [T::Char]) -> Self {
unsafe { Self::from_ptr(chars.as_ptr().cast()) }
}
pub fn from_chars_with_nul(chars: &'a [T::Char]) -> Result<Self, FromCharsWithNulError> {
if chars.last() != Some(&T::NUL) || chars[..chars.len() - 1].contains(&T::NUL) {
return Err(FromCharsWithNulError);
}
Ok(unsafe { Self::from_chars_with_nul_unchecked(chars) })
}
pub fn from_chars_until_nul(chars: &'a [T::Char]) -> Result<Self, FromCharsUntilNulError> {
if !chars.contains(&T::NUL) {
return Err(FromCharsUntilNulError);
}
Ok(unsafe { Self::from_chars_with_nul_unchecked(chars) })
}
/// Scan the string to get its length.
#[doc(alias = "strlen")]
#[doc(alias = "wcslen")]
pub fn len(self) -> usize {
self.to_chars().len()
}
#[inline]
pub fn is_empty(&self) -> bool {
self.first() == T::NUL
}
}
impl<'a> CStr<'a> {
pub fn to_owned_cstring(self) -> CString {
CString::from(unsafe { core::ffi::CStr::from_ptr(self.ptr.as_ptr()) })
}
pub fn borrow(string: &'a CString) -> Self {
unsafe { Self::from_ptr(string.as_ptr()) }
}
#[inline]
pub fn to_bytes(self) -> &'a [u8] {
self.to_chars()
}
#[inline]
pub fn to_bytes_with_nul(self) -> &'a [u8] {
self.to_chars_with_nul()
}
pub fn to_str(self) -> Result<&'a str, Utf8Error> {
core::str::from_utf8(self.to_bytes())
}
pub fn to_string_lossy(self) -> Cow<'a, str> {
String::from_utf8_lossy(self.to_bytes())
}
#[inline]
pub const unsafe fn from_bytes_with_nul_unchecked(bytes: &'a [u8]) -> Self {
unsafe { Self::from_chars_with_nul_unchecked(bytes) }
}
#[inline]
pub fn from_bytes_with_nul(bytes: &'a [u8]) -> Result<Self, FromCharsWithNulError> {
Self::from_chars_with_nul(bytes)
}
#[inline]
pub fn from_bytes_until_nul(bytes: &'a [u8]) -> Result<Self, FromCharsUntilNulError> {
Self::from_chars_until_nul(bytes)
}
}
unsafe impl<T: Kind> Send for NulStr<'_, T> {}
unsafe impl<T: Kind> Sync for NulStr<'_, T> {}
impl From<&core::ffi::CStr> for CStr<'_> {
fn from(s: &core::ffi::CStr) -> Self {
// SAFETY:
// * We can assume that `s` is valid because the caller should have upheld its
// safety concerns when constructing it.
unsafe { Self::from_ptr(s.as_ptr()) }
}
}
#[derive(Debug)]
pub struct FromCharsWithNulError;
#[derive(Debug)]
pub struct FromCharsUntilNulError;
pub use alloc::ffi::CString;
+294
View File
@@ -0,0 +1,294 @@
//! Equivalent of Rust's `Vec<T>`, but using relibc's own allocator.
use crate::{
io::{self, Write},
platform::{self, WriteByte, types::*},
};
use core::{
cmp, fmt,
iter::IntoIterator,
mem,
ops::{Deref, DerefMut},
ptr::{self, NonNull},
slice,
};
/// Error that occurs when an allocation fails
#[derive(Debug, Default, Hash, PartialEq, Eq, Clone, Copy)]
pub struct AllocError;
/// A normal vector allocated in Rust needs to be dropped from Rust
/// too, in order to avoid UB. This CVec is an abstraction that works
/// using only C allocations functions and can therefore be dropped
/// from C. Just like the Rust Vec, this does bounds checks to assure
/// you never reach isize::MAX. Unless you need to drop something from
/// C, prefer Rust's builtin Vec.
pub struct CVec<T> {
ptr: NonNull<T>,
len: usize,
cap: usize,
}
impl<T> CVec<T> {
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
Self {
ptr: NonNull::dangling(),
len: 0,
cap: 0,
}
}
fn check_bounds(i: usize) -> Result<usize, AllocError> {
if i > isize::MAX as usize {
Err(AllocError)
} else {
Ok(i)
}
}
fn check_mul(x: usize, y: usize) -> Result<usize, AllocError> {
x.checked_mul(y)
.ok_or(AllocError)
.and_then(Self::check_bounds)
}
pub fn with_capacity(cap: usize) -> Result<Self, AllocError> {
if cap == 0 {
return Ok(Self::new());
}
let size = Self::check_mul(cap, mem::size_of::<T>())?;
let ptr = NonNull::new(unsafe { platform::alloc(size).cast::<T>() }).ok_or(AllocError)?;
Ok(Self { ptr, len: 0, cap })
}
unsafe fn resize(&mut self, cap: usize) -> Result<(), AllocError> {
let size = Self::check_mul(cap, mem::size_of::<T>())?;
let ptr = if cap == 0 {
NonNull::dangling()
} else if self.cap > 0 {
NonNull::new(
unsafe { platform::realloc(self.ptr.as_ptr().cast::<c_void>(), size) }.cast::<T>(),
)
.ok_or(AllocError)?
} else {
NonNull::new((unsafe { platform::alloc(size) }).cast::<T>()).ok_or(AllocError)?
};
self.ptr = ptr;
self.cap = cap;
Ok(())
}
unsafe fn drop_range(&mut self, start: usize, end: usize) {
let mut start = unsafe { self.ptr.as_ptr().add(start) };
let end = unsafe { self.ptr.as_ptr().add(end) };
while start < end {
unsafe { ptr::drop_in_place(start) };
start = unsafe { start.add(1) };
}
}
// Push stuff
pub fn reserve(&mut self, required: usize) -> Result<(), AllocError> {
let required_len = self
.len
.checked_add(required)
.ok_or(AllocError)
.and_then(Self::check_bounds)?;
if required_len > self.cap {
let new_cap = cmp::min(required_len.next_power_of_two(), isize::MAX as usize);
unsafe {
self.resize(new_cap)?;
}
}
Ok(())
}
pub fn push(&mut self, elem: T) -> Result<(), AllocError> {
self.reserve(1)?;
unsafe {
ptr::write(self.ptr.as_ptr().add(self.len), elem);
}
self.len += 1; // no need to bounds check, as new len <= cap
Ok(())
}
pub fn extend_from_slice(&mut self, elems: &[T]) -> Result<(), AllocError>
where
T: Copy,
{
self.reserve(elems.len())?;
unsafe {
ptr::copy_nonoverlapping(elems.as_ptr(), self.ptr.as_ptr().add(self.len), elems.len());
}
self.len += elems.len(); // no need to bounds check, as new len <= cap
Ok(())
}
pub fn append(&mut self, other: &mut Self) -> Result<(), AllocError> {
let len = other.len;
other.len = 0; // move
self.reserve(len)?;
unsafe {
ptr::copy_nonoverlapping(other.as_ptr(), self.ptr.as_ptr().add(self.len), len);
}
self.len += other.len(); // no need to bounds check, as new len <= cap
Ok(())
}
// Pop stuff
pub fn truncate(&mut self, len: usize) {
if len < self.len {
unsafe {
let old_len = self.len;
self.drop_range(len, old_len);
}
self.len = len;
}
}
pub fn shrink_to_fit(&mut self) -> Result<(), AllocError> {
if self.len < self.cap {
unsafe {
let new_cap = self.len;
self.resize(new_cap)?;
}
}
Ok(())
}
pub fn pop(&mut self) -> Option<T> {
if self.is_empty() {
None
} else {
let elem = unsafe { ptr::read(self.as_ptr().add(self.len - 1)) };
self.len -= 1;
Some(elem)
}
}
// Misc stuff
pub fn capacity(&self) -> usize {
self.cap
}
pub fn as_ptr(&self) -> *const T {
self.ptr.as_ptr()
}
pub fn as_mut_ptr(&mut self) -> *mut T {
self.ptr.as_ptr()
}
/// Leaks the inner data. This is safe to drop from C!
pub fn leak(mut self) -> *mut T {
let ptr = self.as_mut_ptr();
mem::forget(self);
ptr
}
}
impl<T> Deref for CVec<T> {
type Target = [T];
fn deref(&self) -> &Self::Target {
unsafe { slice::from_raw_parts(self.ptr.as_ptr(), self.len) }
}
}
impl<T> DerefMut for CVec<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { slice::from_raw_parts_mut(self.ptr.as_ptr(), self.len) }
}
}
impl<T> Drop for CVec<T> {
fn drop(&mut self) {
unsafe {
let len = self.len;
self.drop_range(0, len);
}
}
}
impl<'a, T> IntoIterator for &'a CVec<T> {
type Item = <&'a [T] as IntoIterator>::Item;
type IntoIter = <&'a [T] as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
<&[T]>::into_iter(&*self)
}
}
impl<'a, T> IntoIterator for &'a mut CVec<T> {
type Item = <&'a mut [T] as IntoIterator>::Item;
type IntoIter = <&'a mut [T] as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
<&mut [T]>::into_iter(&mut *self)
}
}
impl Write for CVec<u8> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.extend_from_slice(buf).map_err(|err| {
io::Error::new(
io::ErrorKind::Other,
"AllocStringWriter::write failed to allocate",
)
})?;
Ok(buf.len())
}
fn flush(&mut self) -> io::Result<()> {
Ok(())
}
}
impl fmt::Write for CVec<u8> {
fn write_str(&mut self, s: &str) -> fmt::Result {
self.write(s.as_bytes()).map_err(|_| fmt::Error)?;
Ok(())
}
}
impl WriteByte for CVec<u8> {
fn write_u8(&mut self, byte: u8) -> fmt::Result {
self.write(&[byte]).map_err(|_| fmt::Error)?;
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::CVec;
#[test]
fn push_pop() {
let mut vec = CVec::new();
vec.push(1).unwrap();
vec.push(2).unwrap();
vec.push(3).unwrap();
assert_eq!(&vec[..], &[1, 2, 3]);
assert_eq!(vec.pop().unwrap(), 3);
assert_eq!(&vec[..], &[1, 2]);
}
#[test]
fn extend_from_slice() {
use crate::io::Write;
let mut vec = CVec::new();
vec.extend_from_slice(&[1, 2, 3]).unwrap();
vec.extend_from_slice(&[4, 5, 6]).unwrap();
assert_eq!(&vec[..], &[1, 2, 3, 4, 5, 6]);
assert_eq!(vec.write(&[7, 8, 9]).unwrap(), 3);
assert_eq!(&vec[..], &[1, 2, 3, 4, 5, 6, 7, 8, 9]);
}
#[test]
fn dropped() {
use alloc::rc::Rc;
let counter = Rc::new(());
let mut vec = CVec::with_capacity(3).unwrap();
vec.push(Rc::clone(&counter)).unwrap();
vec.push(Rc::clone(&counter)).unwrap();
vec.push(Rc::clone(&counter)).unwrap();
assert_eq!(Rc::strong_count(&counter), 4);
let popped = vec.pop().unwrap();
assert_eq!(Rc::strong_count(&counter), 4);
drop(popped);
assert_eq!(Rc::strong_count(&counter), 3);
vec.push(Rc::clone(&counter)).unwrap();
vec.push(Rc::clone(&counter)).unwrap();
vec.push(Rc::clone(&counter)).unwrap();
assert_eq!(vec.len(), 5);
assert_eq!(Rc::strong_count(&counter), 6);
vec.truncate(1);
assert_eq!(Rc::strong_count(&counter), 2);
drop(vec);
assert_eq!(Rc::strong_count(&counter), 1);
}
}
-425
View File
@@ -1,425 +0,0 @@
use super::{
arch::*,
data::{Map, Stat, StatVfs, StdFsCallMeta, TimeSpec},
error::Result,
flag::*,
number::*,
};
use core::mem;
/// Close a file descriptor
pub fn close(fd: usize) -> Result<usize> {
unsafe { syscall1(SYS_CLOSE, fd) }
}
/// Get the current system time
pub fn clock_gettime(clock: usize, tp: &mut TimeSpec) -> Result<usize> {
unsafe { syscall2(SYS_CLOCK_GETTIME, clock, tp as *mut TimeSpec as usize) }
}
/// Copy and transform a file descriptor into specified fd number
pub fn dup_into(fd: usize, out: usize, buf: &[u8]) -> Result<usize> {
unsafe { syscall4(SYS_DUP_INTO, fd, buf.as_ptr() as usize, buf.len(), out) }
}
/// Copy and transform a file descriptor, letting the kernel allocate the new fd
pub fn dup(fd: usize, buf: &[u8]) -> Result<usize> {
unsafe { syscall3(SYS_DUP, fd, buf.as_ptr() as usize, buf.len()) }
}
/// Copy and transform a file descriptor
pub fn dup2(fd: usize, newfd: usize, buf: &[u8]) -> Result<usize> {
unsafe { syscall4(SYS_DUP2, fd, newfd, buf.as_ptr() as usize, buf.len()) }
}
/// Change file permissions
pub fn fchmod(fd: usize, mode: u16) -> Result<usize> {
unsafe { syscall2(SYS_FCHMOD, fd, mode as usize) }
}
/// Change file ownership
pub fn fchown(fd: usize, uid: u32, gid: u32) -> Result<usize> {
unsafe { syscall3(SYS_FCHOWN, fd, uid as usize, gid as usize) }
}
/// Change file descriptor flags
pub fn fcntl(fd: usize, cmd: usize, arg: usize) -> Result<usize> {
unsafe { syscall3(SYS_FCNTL, fd, cmd, arg) }
}
/// Map a file into memory, but with the ability to set the address to map into, either as a hint
/// or as a requirement of the map.
///
/// # Errors
/// `EACCES` - the file descriptor was not open for reading
/// `EBADF` - if the file descriptor was invalid
/// `ENODEV` - mmapping was not supported
/// `EINVAL` - invalid combination of flags
/// `EEXIST` - if [`MapFlags::MAP_FIXED`] was set, and the address specified was already in use.
///
pub unsafe fn fmap(fd: usize, map: &Map) -> Result<usize> {
syscall3(
SYS_FMAP,
fd,
map as *const Map as usize,
mem::size_of::<Map>(),
)
}
/// Unmap whole (or partial) continous memory-mapped files
pub unsafe fn funmap(addr: usize, len: usize) -> Result<usize> {
syscall2(SYS_FUNMAP, addr, len)
}
/// Retrieve the canonical path of a file
pub fn fpath(fd: usize, buf: &mut [u8]) -> Result<usize> {
unsafe { syscall3(SYS_FPATH, fd, buf.as_mut_ptr() as usize, buf.len()) }
}
/// Create a link to a file
pub fn flink<T: AsRef<str>>(fd: usize, path: T) -> Result<usize> {
let path = path.as_ref();
unsafe { syscall3(SYS_FLINK, fd, path.as_ptr() as usize, path.len()) }
}
/// Rename a file
pub fn frename<T: AsRef<str>>(fd: usize, path: T) -> Result<usize> {
let path = path.as_ref();
unsafe { syscall3(SYS_FRENAME, fd, path.as_ptr() as usize, path.len()) }
}
/// Get metadata about a file
pub fn fstat(fd: usize, stat: &mut Stat) -> Result<usize> {
unsafe {
syscall3(
SYS_FSTAT,
fd,
stat as *mut Stat as usize,
mem::size_of::<Stat>(),
)
}
}
/// Get metadata about a filesystem
pub fn fstatvfs(fd: usize, stat: &mut StatVfs) -> Result<usize> {
unsafe {
syscall3(
SYS_FSTATVFS,
fd,
stat as *mut StatVfs as usize,
mem::size_of::<StatVfs>(),
)
}
}
/// Sync a file descriptor to its underlying medium
pub fn fsync(fd: usize) -> Result<usize> {
unsafe { syscall1(SYS_FSYNC, fd) }
}
/// Truncate or extend a file to a specified length
pub fn ftruncate(fd: usize, len: usize) -> Result<usize> {
unsafe { syscall2(SYS_FTRUNCATE, fd, len) }
}
// Change modify and/or access times
pub fn futimens(fd: usize, times: &[TimeSpec]) -> Result<usize> {
unsafe {
syscall3(
SYS_FUTIMENS,
fd,
times.as_ptr() as usize,
mem::size_of_val(times),
)
}
}
/// Fast userspace mutex
pub unsafe fn futex(
addr: *mut i32,
op: usize,
val: i32,
val2: usize,
addr2: *mut i32,
) -> Result<usize> {
syscall5(
SYS_FUTEX,
addr as usize,
op,
(val as isize) as usize,
val2,
addr2 as usize,
)
}
/// Seek to `offset` bytes in a file descriptor
pub fn lseek(fd: usize, offset: isize, whence: usize) -> Result<usize> {
unsafe { syscall3(SYS_LSEEK, fd, offset as usize, whence) }
}
/// Make a new scheme namespace
pub fn mkns(schemes: &[[usize; 2]]) -> Result<usize> {
unsafe { syscall2(SYS_MKNS, schemes.as_ptr() as usize, schemes.len()) }
}
/// Change mapping flags
pub unsafe fn mprotect(addr: usize, size: usize, flags: MapFlags) -> Result<usize> {
syscall3(SYS_MPROTECT, addr, size, flags.bits())
}
/// Sleep for the time specified in `req`
pub fn nanosleep(req: &TimeSpec, rem: &mut TimeSpec) -> Result<usize> {
unsafe {
syscall2(
SYS_NANOSLEEP,
req as *const TimeSpec as usize,
rem as *mut TimeSpec as usize,
)
}
}
/// Open a file at a specific path into specified fd number
pub fn openat_into<T: AsRef<str>>(
fd: usize,
out: usize,
path: T,
flags: usize,
fcntl_flags: usize,
) -> Result<usize> {
let path = path.as_ref();
unsafe {
syscall6(
SYS_OPENAT_INTO,
fd,
path.as_ptr() as usize,
path.len(),
flags,
fcntl_flags,
out,
)
}
}
/// Open a file at a specific path, letting the kernel allocate the new fd
pub fn openat<T: AsRef<str>>(fd: usize, path: T, flags: usize, fcntl_flags: usize) -> Result<usize> {
let path = path.as_ref();
unsafe {
syscall5(
SYS_OPENAT,
fd,
path.as_ptr() as usize,
path.len(),
flags,
fcntl_flags,
)
}
}
/// Open a file at a specific path with uid/gid filtering.
/// Red Bear: legacy wrapper preserved for bootstrap namespace capability checks.
pub fn openat_with_filter<T: AsRef<str>>(
fd: usize,
path: T,
flags: usize,
fcntl_flags: usize,
uid: u32,
gid: u32,
) -> Result<usize> {
let path = path.as_ref();
unsafe {
syscall6(
SYS_OPENAT_WITH_FILTER,
fd,
path.as_ptr() as usize,
path.len(),
flags | fcntl_flags,
uid as usize,
gid as usize,
)
}
}
/// Send a file descriptor to another process via a socket
pub fn sendfd(receiver_socket: usize, fd: usize, flags: usize, arg: u64) -> Result<usize> {
#[cfg(target_pointer_width = "32")]
unsafe {
syscall5(
SYS_SENDFD,
receiver_socket,
fd,
flags,
arg as u32 as usize,
(arg >> 32) as usize,
)
}
#[cfg(target_pointer_width = "64")]
unsafe {
syscall4(SYS_SENDFD, receiver_socket, fd, flags, arg as usize)
}
}
/// Remove a file at at specific path
pub fn unlinkat<T: AsRef<str>>(fd: usize, path: T, flags: usize) -> Result<usize> {
let path = path.as_ref();
unsafe { syscall4(SYS_UNLINKAT, fd, path.as_ptr() as usize, path.len(), flags) }
}
/// Remove a file at a specific path with uid/gid filtering.
/// Red Bear: legacy wrapper preserved for bootstrap namespace capability checks.
pub fn unlinkat_with_filter<T: AsRef<str>>(
fd: usize,
path: T,
flags: usize,
uid: u32,
gid: u32,
) -> Result<usize> {
let path = path.as_ref();
unsafe {
syscall6(
SYS_UNLINKAT_WITH_FILTER,
fd,
path.as_ptr() as usize,
path.len(),
flags,
uid as usize,
gid as usize,
)
}
}
/// Read from a file descriptor into a buffer
pub fn read(fd: usize, buf: &mut [u8]) -> Result<usize> {
unsafe { syscall3(SYS_READ, fd, buf.as_mut_ptr() as usize, buf.len()) }
}
/// Write a buffer to a file descriptor
///
/// The kernel will attempt to write the bytes in `buf` to the file descriptor `fd`, returning
/// either an `Err`, explained below, or `Ok(count)` where `count` is the number of bytes which
/// were written.
///
/// # Errors
///
/// * `EAGAIN` - the file descriptor was opened with `O_NONBLOCK` and writing would block
/// * `EBADF` - the file descriptor is not valid or is not open for writing
/// * `EFAULT` - `buf` does not point to the process's addressible memory
/// * `EIO` - an I/O error occurred
/// * `ENOSPC` - the device containing the file descriptor has no room for data
/// * `EPIPE` - the file descriptor refers to a pipe or socket whose reading end is closed
pub fn write(fd: usize, buf: &[u8]) -> Result<usize> {
unsafe { syscall3(SYS_WRITE, fd, buf.as_ptr() as usize, buf.len()) }
}
/// Yield the process's time slice to the kernel
///
/// This function will return Ok(0) on success
pub fn sched_yield() -> Result<usize> {
unsafe { syscall0(SYS_YIELD) }
}
pub trait Call {
unsafe fn raw_call(
&self,
payload_ptr: *const u8,
len: usize,
flags: CallFlags,
metadata: &[u64],
) -> Result<usize>;
}
impl Call for usize {
unsafe fn raw_call(
&self,
payload_ptr: *const u8,
len: usize,
flags: CallFlags,
metadata: &[u64],
) -> Result<usize> {
unsafe {
syscall5(
SYS_CALL,
*self,
payload_ptr as usize,
len,
metadata.len() | flags.bits(),
metadata.as_ptr() as usize,
)
}
}
}
impl Call for &[usize] {
unsafe fn raw_call(
&self,
payload_ptr: *const u8,
len: usize,
flags: CallFlags,
metadata: &[u64],
) -> Result<usize> {
let combined_flags = flags | CallFlags::MULTIPLE_FDS;
unsafe {
syscall6(
SYS_CALL,
self.as_ptr() as usize,
payload_ptr as usize,
len,
metadata.len() | combined_flags.bits(),
metadata.as_ptr() as usize,
self.len() * mem::size_of::<usize>(),
)
}
}
}
/// SYS_CALL interface, read-only variant
pub fn call_ro<T: Call>(
fd: T,
payload: &mut [u8],
flags: CallFlags,
metadata: &[u64],
) -> Result<usize> {
unsafe {
fd.raw_call(
payload.as_mut_ptr(),
payload.len(),
flags | CallFlags::READ,
metadata,
)
}
}
/// SYS_CALL interface, write-only variant
pub fn call_wo<T: Call>(
fd: T,
payload: &[u8],
flags: CallFlags,
metadata: &[u64],
) -> Result<usize> {
unsafe {
fd.raw_call(
payload.as_ptr(),
payload.len(),
flags | CallFlags::WRITE,
metadata,
)
}
}
/// SYS_CALL interface, read-write variant
pub fn call_rw<T: Call>(
fd: T,
payload: &mut [u8],
flags: CallFlags,
metadata: &[u64],
) -> Result<usize> {
unsafe {
fd.raw_call(
payload.as_mut_ptr(),
payload.len(),
flags | CallFlags::READ | CallFlags::WRITE,
metadata,
)
}
}
pub fn std_fs_call<T: Call>(fd: T, payload: &mut [u8], metadata: &StdFsCallMeta) -> Result<usize> {
call_rw(fd, payload, CallFlags::STD_FS, metadata)
}

Some files were not shown because too many files have changed in this diff Show More