Commit Graph

1043 Commits

Author SHA1 Message Date
Red Bear OS 3b28c27e00 relibc: implement wcsxfrm() — identity transformation
Replaced todo_skip stub with proper wcsxfrm() implementation.

The wide-char string transformation uses the current locale's
collation. Red Bear has no locale support, so the transformation
is the identity (same as C/POSIX locale). Cross-referenced with
Linux 7.1 time/wcsxfrm.c.

Behavior:
- n=0: count length of ws2 (excluding null terminator)
- n>0: copy ws2 to ws1 with null terminator, cap at n-1 chars
- Returns number of wide chars written (excluding null terminator)
2026-07-08 18:15:21 +03:00
Red Bear OS 8d8c9c9bfd relibc: implement wcsftime() — remove todo_skip stub
Implemented wcsftime() as wide-char variant of strftime.
Cross-referenced from Linux 7.1 time/wcsftime.c.

Algorithm: convert wchar format to UTF-8 byte string (non-ASCII
chars replaced with '?'), call strftime::strftime with byte format
to format into a byte buffer, then convert each output byte to
a wchar_t in the output buffer (maxsize-1 chars + null terminator).

Also exposed time::strftime module as pub for cross-module access.
2026-07-08 18:14:05 +03:00
Red Bear OS 01807f6fa7 relibc: implement madvise() — remove ENOSYS stub
Replaced ENOSYS stub with proper POSIX madvise() implementation
cross-referenced from Linux 7.1 mm/madvise.c.

Flag validation: MADV_NORMAL, RANDOM, SEQUENTIAL, WILLNEED, DONTNEED.
Address must be page-aligned. Unknown flags → EINVAL.

Red Bear has no page cache, swap, or lazy allocation. All MADV_*
flags are no-ops: the hints are advisory and the kernel is free to
ignore them. MADV_DONTNEED would need page table teardown support
which is not implemented.
2026-07-08 18:00:15 +03:00
Red Bear OS fc158b3611 relibc: implement msync() — remove ENOSYS stub
Replaced ENOSYS stub with proper POSIX msync() implementation
cross-referenced from Linux 7.1 mm/msync.c:42-55.

Flag validation: MS_ASYNC|MS_INVALIDATE|MS_SYNC, rejects unknown
flags and MS_ASYNC|MS_SYNC combination. Address page-aligned check.
Length rounded to page boundary with overflow check.

Red Bear filesystem I/O is synchronous (no writeback cache).
MS_SYNC/MS_ASYNC are no-ops. MS_INVALIDATE not implemented (needs
kernel cache invalidation), but stale cache is not a concern
with direct filesystem reads.
2026-07-08 17:58:47 +03:00
Red Bear OS c1e4c1d53d relibc: use /scheme/proc/{pid}/ctx for ptrace GETREGS/SETREGS 2026-07-08 17:58:11 +03:00
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 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 94a6da9116 Fix lookahead buffer reading nul's 2020-12-23 08:20:11 -07: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
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
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
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 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
Peter Limkilde Svendsen 63711f6ca7 Formatting 2020-08-27 23:16:17 +02:00
Peter Limkilde Svendsen 845c74a82e Refactor gmtime_r() 2020-08-27 23:16:17 +02:00
Peter Limkilde Svendsen 86138c9f8a Align parameter naming with POSIX 2020-08-27 23:16:17 +02:00
Peter Limkilde Svendsen 23b2eb2573 Avoid assuming c_char is i8 2020-08-23 21:45:08 +02:00
Jeremy Soller 5af8e3ca35 Merge branch 'bump-fmap' into 'master'
Use renamed fmap call

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

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

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

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

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

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

  #include <fcntl.h>

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

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

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

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

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

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

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

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

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

  // close file and release locks for all regions
  // remember that locks are released when process calls close()
  // on any descriptor for a lock file
  close(fd);
2020-08-08 10:16:50 +02:00
oddcoder e14b3e09a5 Add elf.h header to relibc 2020-08-08 10:16:50 +02:00
jD91mZM2 6952a079ae Fix CI 2020-08-07 14:16:45 +00:00
jD91mZM2 72532b8280 Fix printf issue found in GDB 2020-08-05 16:49:10 +02:00