The answer is not so simple as the question. It is open to interpretation.
open
is a function [in glibc
], but it is also the name of the corresponding syscall.
This seems like an interview related question. Or, some certification test question. Or, a test question from some programming course.
But, IMO, it's poorly worded without more (such) context, and the answer depends upon some interpretation of how sophisticated an answer is required.
The TL;DR is probably: B
, C
, and D
.
But, A
and E
are also possible in some contexts ... ;-)
So, we need the context: The mayonaise you like is the mayonaise you grew up with ... :-)
b) it’s a function
Yes, it's a function that is linked from glibc
c) it’s a library call
Yes, because it is a function in glibc
However, if the definition of "library call" is only a function in glibc
that does not invoke a syscall, then the answer is No.
a) it’s a function provided by the kernel
For many syscalls, (e.g. open
, close
, read
, write
) the kernel does not provide a function to userspace, so the answer is No.
However, for some kernel syscalls, the kernel does inject a function into userspace via the VDSO
mechanism. See: https://man7.org/linux/man-pages/man7/vdso.7.html and https://en.wikipedia.org/wiki/VDSO
An example of this is clock_gettime
. Under a simple implementation, the function invokes a syscall. But, for speed, the kernel injects code into the app, and the library function knows this, and just invokes the injected code which has special access to some portions of kernel memory that are mapped (R/O) into userspace.
So, the answer is: It depends
d) it’s a system call
In most cases, the TL;DR answer is Yes, it's a system call.
But, the library function is considered to be a [thin] "wrapper" function around the kernel's syscall.
Here, the underlying implementation would be an internal version of:
syscall(SYS_open,...)
So, the "syscall" is SYS_open
So, the answer could be: No, open
is just a [glibc
] library function [that invokes the SYS_open
syscall].
e) it’s a kernel routine
The answer is No.
But, because when the kernel receives an int 0x80
, syscall
, or sysenter
, it dispatches to a given handler function in the kernel.
The convention for a given syscall (e.g.) whatever
is sys_whatever
. So, the kernel [internally] calls sys_open
, which probably calls do_open
.
So, under a loose interpretation, the kernel does have a function for this. So, the answer could be Yes
So, the question was probably posed for the "simple" interpretation:
B, C, D
(and sometimes A)