Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Dolu1990
    @Dolu1990
    Ok :)
    thanks
    Paul Ruiz
    @pnru_gitlab
    @lawrie Looking into statx a bit more. I think that the structure currently is exactly 256 bytes in length, as per the definition here:
    https://code.woboq.org/qt5/include/bits/statx.h.html
    (quite helpfully, if one hovers over a struct field a popup appears with the byte offset). The offset of the file size field is 40 though - as you have it. I am not quite sure that you have the mask argument correct: value zero requests no fields to be filled in, I think you need the value 0x7FF here. Maybe the kernel infers that when 0 is specified.
    All that does not explain the crash without exit(0). Maybe there is still a dormant issue with printf. Do you get the same crash if you use sprintf + write? If that works okay, we need to search for a stack corruption issue with printf.
    Lawrie Griffiths
    @lawrie
    Yes, I believe I tried the sprintf and that crashed as well. I will try it again.
    I am currently putting a lot of trivial system calls into syscall.s.
    fork and kill are a bit tricky. I think risc-v linux just has clone and execve.
    Lots of things only have the "at" versions.
    Paul Ruiz
    @pnru_gitlab
    Lots of things only have the "at" versions.
    That makes sense. The "at" versions are the newer and more generic ones and when moving to a new platform there is a lot of scope to clean up: as there is not a huge installed base of binaries to support, lot's of stuff can be moved to wrappers and the syscall list kept short.
    I think risc-v linux just has clone and execve.
    That makes sense too: clone is variant of fork that can optionally create a new process or a new thread; it is Linux specific. Back in V6 Unix there was no "environment" concept, this was added in V7 and exece appeared next to exec. I guess execve is the core one that supports all other variants as library wrappers.
    Lawrie Griffiths
    @lawrie
    Yes, the seek test program still crashes if I use sprintf.
    printf is not giving problems in anything else I have tried.
    Looking at the old Unix system calls, I don't know what corresponds to alarm and pause in Linux.
    Paul Ruiz
    @pnru_gitlab

    For fork I think the below may work:

              .globl fork
    fork:
              li        x10,  SIGCHLD
             mv      x11, x1
              li        x17, __NR_clone
              ecall
              jal      x0,cerror

    where SIGCHILD is 17 and __NR_clone is 220

    alarm sets a timer and after the timer expires, the process receives a SIGALARM signal. It is used to implement sleep(). Let me see what might fit.
    Lawrie Griffiths
    @lawrie
    I have added your fork to syscalls.s
    For wait, there is waitid.
    Paul Ruiz
    @pnru_gitlab
    Forget about alarm and pause, they are ancient relics now. For linux just do a wrapper routine sleep() that works from the nanosleep system call.
    Lawrie Griffiths
    @lawrie
    I added nanosleep.
    Paul Ruiz
    @pnru_gitlab
    Wow - a this speed you'll have a full list by tomorrow.
    Lawrie Griffiths
    @lawrie
    I am stopping for tonight now. Most are untested, apart from some simple ones like getpid, getuid, getgid.
    Lawrie Griffiths
    @lawrie
    Paul Ruiz
    @pnru_gitlab
    Made a mistake in my fork: it should be mv x11,x2 (i.e. use sp as 2nd argument).
    Lawrie Griffiths
    @lawrie
    @pnru_gitlab Your fork implementation works:
    root@buildroot:~# cat fork_test.c 
    
    #include <stdio.h> 
    #include <sys/types.h> 
    #include <unistd.h> 
    #include <errno.h>
    
    int main()  { 
       int p;
       int err;
    
       p = fork();
       err = errno;
    
       printf("p  = %d\n", p);
       printf("errno  = %d\n", err);
    
       if (p < 0) {
         printf("Fork failed\n");
       } else if (p == 0) {
         printf("Child process\n");
       } else {
         printf("Parent process\n");
       }
    
       return 0; 
    } 
    
    root@buildroot:~# ./a.out
    p  = 193
    errno  = 0
    p  = 0
    errno  = 0
    Parent process
    Child process
    Paul Ruiz
    @pnru_gitlab
    Great!
    emard
    @emard
    I was thinking, author of the riscv-lcc compiler would be great to come here to chat a bit, if he replies about saxonsoc efforts just invite him to join :)
    Lawrie Griffiths
    @lawrie
    @pnru_gitlab I have execve working as well.
    Lawrie Griffiths
    @lawrie
    @emard He has replied, and I have invited him - michg/riscv32_lcc#1
    Lawrie Griffiths
    @lawrie
    @pnru_gitlab Another Unix system call I don't know how to support is nice.
    Lawrie Griffiths
    @lawrie
    I am also not sure how to do signal. Linux has signalfd4.
    Also not sure how to do stime.
    Lawrie Griffiths
    @lawrie
    The Unix calls in your list that I haven't got an equivalent of are: alarm, mpxchan, chroot, creat, gtime,gtty. nice, nosys, nullsys. pause, profil, ptrace, rext, ssig, stime, stty, ftime, sysacct, syslock, sysphys.
    Do you think we need any of those?
    Paul Ruiz
    @pnru_gitlab
    The nice() system call adjusts the process priority. On Linux it is a wrapper, using setpriority() and getpriority():
    https://linux.die.net/man/2/nice
    https://linux.die.net/man/2/getpriority
    For the wrapper, read the notes on both man pages. Because valid return codes are -20..+20 and half of that range conflicts with the Linux error code range (-4095..-1) some trickery is involved. Use PRIO_PROCESS for which.
    Paul Ruiz
    @pnru_gitlab
    On the syscall list:
    • alarm & pause: not needed, nanosleep will do (with wrappers for sleep and usleep)
    • mpxchan: a (failed) networking experiment, not relevant.
    • chroot: still exists, but perhaps not in the 80% of usage list
    • creat & mknod: not needed, these have been rolled into open() flags.
    • gtty & stty: not needed, these have been replaced by ioctl(), which you have
    • nosys & nullsys: not needed - nosys is a placeholder for calls that have not been included and results in a ENOSYS error (like you saw yesterday) and nullsys is for a call that was silently ignored.
    • profil was used for profiling code. Not sure how this works on Linux and can be ignored for now, I think.
    • ptrace was the original debugger interface and can be ignored. How this works on Risc-V linux will come back as a topic if we ever do a debugger for lcc code.
    • rexit: internal name of exit(); you already have that one
    • ssig: sets the signal mask. Signals (at least historically) need a fairly complex support routine in user space to work - I suggest we leave it too later.
    • gtime, stime, ftime: gtime is the internal name of time(). stime sets the time, needs root privilege and will be needed for Emard's RTC code, ftime gets time at millisecond resolution and is maybe outside the "80% set".
    • sysacct, syslock, sysphys: historical accounting and file locking. Can safely be skipped.
    I've been too quick on mknod. I think you will need to include mkdir and rmdir in the core lcc set. Come to think of it, maybe nice is also not in the 80% of usage set.
    Lawrie Griffiths
    @lawrie
    @emard There is a new version of riscv32_lcc.tar.gz in Smp/images with my latest system calls.
    I also added an examples directory with my C test code.
    emard
    @emard
    eheheeee I will download
    not yet updated at Smp
    Lawrie Griffiths
    @lawrie
    It is there now
    emard
    @emard
    dowloading extra fresh!
    Lawrie Griffiths
    @lawrie
    I will add setpriority, getprioriity, mkdir and rmdir.
    I don't know what the Linux system calls are for time and stime - perhaps settimeofday, gettimeofday.
    Lawrie Griffiths
    @lawrie
    I don't know what the parameters are for signalfd4, but as you say, we can leave signals for the moment.
    @pnru_gitlab Not sure how do do rmdir. I have unlinkat - perhaps that does it.
    Paul Ruiz
    @pnru_gitlab
    Yes: https://linux.die.net/man/2/unlinkat
    AT_REMOVEDIR is defined as 0x200
    Paul Ruiz
    @pnru_gitlab
    time and stime are clock_gettime and clock_settime on Linux:
    https://man7.org/linux/man-pages/man2/clock_settime.2.html
    Use CLOCK_REALTIME as the clock id (= 0).
    Paul Ruiz
    @pnru_gitlab
    For signals, the right base call is probably sigaction. I've been too focussed on ancient Unix it seems.
    https://man7.org/linux/man-pages/man7/signal.7.html