Skip to content
Snippets Groups Projects
  1. Aug 08, 2020
    • Ahmed Abd El Mawgood's avatar
      Add (POSIX defined) struct flock · b5deadbe
      Ahmed Abd El Mawgood authored
      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);
      b5deadbe
    • Ahmed Abd El Mawgood's avatar
      Add elf.h header to relibc · e14b3e09
      Ahmed Abd El Mawgood authored
      e14b3e09
  2. Jun 20, 2020
  3. Jun 19, 2020
  4. Jun 14, 2020
    • Jeremy Soller's avatar
      Merge branch 'headers' into 'master' · ca8b848b
      Jeremy Soller authored
      Headers
      
      See merge request !280
      ca8b848b
    • Ahmed Abd El Mawgood's avatar
      Add sys/select.h to sys/types.h · f4d95ce4
      Ahmed Abd El Mawgood authored
      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
      f4d95ce4
    • Ahmed Abd El Mawgood's avatar
      Make stdbool.h C++ compatiable · a125b8be
      Ahmed Abd El Mawgood authored
      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
      a125b8be
  5. Jun 13, 2020
    • Ahmed Abd El Mawgood's avatar
      Fix the avoid accessing errno issue from ld_so for real this time · 81da1bb1
      Ahmed Abd El Mawgood authored
      This patch implements access function for both redox and linux and makes
      sure that neither access errno variable
      81da1bb1
    • no name's avatar
      Revert "Fix compilation on Redox by removing use of access in ld_so" · d5b63a85
      no name authored and Ahmed Abd El Mawgood's avatar Ahmed Abd El Mawgood committed
      This reverts commit d9bacaec.
      d5b63a85
    • no name's avatar
      Revert "Handle missing paths in load_library search without using access" · c3ae8022
      no name authored and Ahmed Abd El Mawgood's avatar Ahmed Abd El Mawgood committed
      This reverts commit b0dde81c.
      
      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 ?? ()
      c3ae8022
  6. Jun 10, 2020
  7. Jun 07, 2020
  8. Jun 06, 2020
  9. Jun 03, 2020
  10. Jun 02, 2020
  11. Jun 01, 2020
  12. May 28, 2020
  13. May 24, 2020
Loading