call instruction — jump to function elsewheresome inconsistency:
system call = event of entering kernel mode on request?
system call = whole process from beginning to end?
same issue as with ‘function call’
syscallsyscall:%rax — system call number%rdi, %rsi, %rdx, %r10, %r8, %r9 — args
syscall:%rax — return value%rax contains -1 times ‘‘error number’’
mmap, brk — allocate memoryfork — create new processexecve — run a program in the current processopen, read, write — access files_exit — terminate a processsocket, accept, getpeername — socket-related/* unistd.h contains definitions of:
O_RDONLY (integer constant), open() */
#include <unistd.h>
int main(void) {
int file_descriptor;
file_descriptor = open("input.txt", O_RDONLY);
if (file_descriptor < 0) {
printf("error: %s\n", strerror(errno));
exit(1);
}
...
result = read(file_descriptor, ...);
...
}strace — Linux tool to trace system calls$ strace -o trace.txt ./hello_world
$ cat trace.txt
execve("./hello_world", ["./hello_world"],
0x7ffeedafd0a0 /* 28 vars */) = 0
write(1, "Hello, World!\n\0", 14) = 14
exit(0) = ?
+++ exited with 0 +++
when statically linked:
execve("./hello_world", ["./hello_world"], 0x7ffeb4127f70 /* 28 vars */)
= 0
brk(NULL) = 0x22f8000
brk(0x22f91c0) = 0x22f91c0
arch_prctl(ARCH_SET_FS, 0x22f8880) = 0
uname({sysname="Linux", nodename="reiss-t3620", ...}) = 0
readlink("/proc/self/exe", "/u/cr4bd/spring2023/cs3130/slide"..., 4096)
= 57
brk(0x231a1c0) = 0x231a1c0
brk(0x231b000) = 0x231b000
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or
directory)
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 4), ...}) = 0
write(1, "Hello, World!\n", 14) = 14
exit_group(0) = ?
+++ exited with 0 +++
execve: run program
brk: allocate heap space
arch_prctl(ARCH_SET_FS, …): thread local storage pointer
uname: get system information
readlink of /proc/self/exe: get name of this program
access: can we access this file [in this case, a config file]?
fstat: get information about open file
exit_group: variant of exit
when dynamically linked:
execve("./hello_world", ["./hello_world"], 0x7ffcfe91d540 /* 28 vars */)
= 0
brk(NULL) = 0x55d6c351b000
...
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=196684, ...}) = 0
mmap(NULL, 196684, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f7a62dd3000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0"..., 832) = 832
...
close(3) = 0
write(1, "Hello, World!\n", 14) = 14
exit_group(0) = ?
+++ exited with 0 +++
| A. | 42 is printed | B. | 100 is printed |
| C. | program 1 crashes | D. | program 2 crashes |
| E. | something else |
thread = illusion of own processor
own register values
own program counter value
actual implementation:
many threads sharing one processor
input — available now:
input — not available now:
output — ready now:
output — not ready now
exception: hardware calls OS specified routine
context switch: OS switches to another thread
A. program calls a function in the standard library
strlen, pow; also if we consider the calling of a function just the call instruction, then the library functions that do make system calls won’t do so until later)B. program writes a file to disk
C. program A goes to sleep, letting program B run
D. program exits
E. program returns from one function to another function
F. program pops a value from the stack
no: A. program calls a function in the standard library
no: B. program writes a file to disk
yes: C. program A goes to sleep, letting program B run
yes: D. program exits
no: E. program returns from one function to another function
no: F. program pops a value from the stack
terms for exceptions aren’t standardized
our readings use one set of terms
all these terms appear differently elsewhere
process = thread(s) + address space
illusion of dedicated machine: