3

I have an assignment that has me design my own system call. To do this, I would like to view the definition of the open system call. By this, I mean I would like to see how the actual open(const char*, const int) is defined, not sys_open (Since I know where the source code is and can read it).

In both xv6's documentation and files in xv6-public, I am unable to find any reference of the prototype of definition. The theory of my friend and I is that it's defined in some asm file, or some .o file. Would anyone happen to know where the actual source code is? I'd appreciate this greatly.

Tried a ctrl-f for open in the source documentation, and tried a grep over all files in xv6-public. Found nothing.

Flacarile
  • 69
  • 5
  • By "the actual open" do you mean the subroutine named `open` in the C runtime library, which will be a tiny wrapper around an `int` instruction to transfer control to the kernel, or do you mean the code inside the kernel that fields system-call traps and dispatches to `sys_open`? (The latter appears to be in `trapasm.S`, `traps.c`, and `syscall.c`. The former is not part of the xv6-public code repository; consult your instructor for where to find the C library.) – zwol Jun 19 '19 at 15:56
  • what course of OS do you take to build xv6 ? – alinsoar Jun 19 '19 at 16:00
  • @zwol I mean whatever is the first thing that runs when you call open() in a program. i.e: int fd = open("temp", O_RDONLY); – Flacarile Jun 19 '19 at 16:25
  • @alinsoar Currently taking Operating System Fundamentals at the U of Windsor. Xv6 was recently introduced into our curriculum. As for building, we simply did a github install. Our bash guy installed a make qemu command. not sure how it runs – Flacarile Jun 19 '19 at 16:28
  • Wonderful idea to implement xv6. Could I find the laboratory materials posted online ? Are you using raspberry-pi to have it run or how do you do ? – alinsoar Jun 19 '19 at 16:31
  • 1
    @alinsoar No raspberry-pi. I simply log in to my university's ssh, and am able to run it. – Flacarile Jun 19 '19 at 16:57
  • @Flacarile OK, you're talking about the `open` subroutine in the user-mode runtime library. That code is not part of the xv6-public Git repository, nor do I see it anywhere on the PDOS or 6.828 websites. You need to ask your instructor where to find the source code for the user-mode runtime library (often called "the C library", for historical reasons) being used for your course. We probably can't help you any further. – zwol Jun 19 '19 at 18:09

1 Answers1

2

Well,

open is declared in user.h.

open is defined in usys.S:

Lets see:

SYSCALL(open)

Will be transformed in

  .globl open; 
  open: 
    movl $SYS_ ## open, %eax; 
    int $T_SYSCALL; 
    ret

What happened?

When function open is called

  • register %eax is set to SYS_open (which value is 15 (see syscall.h) and SYS_open is defined in sysfile.c
  • interuption T_SYSCALL (64 see traps.h) is raised.
  • after the system call returned, open returns too.
Mathieu
  • 8,840
  • 7
  • 32
  • 45