= = System call = = =
is the API interface between the application and the system kernel
is a series of functional services provided by the system kernel externally.
Basic points of the system call:
A.CPU switching from user mode to kernel mode
B. The system call is optimized, using the function name rather than calling the number
C. System calls can pass parameters from user mode to kernel mode, and vice versa
If you want to use a system call through a function call, you can look at the description of the Syscall function
System calls appear to be similar to the use of C functions, using the function name to use the system call
It actually has more steps:
1. Using the function name call, actually is the C language library inside the wrapper function
2. The arguments passed to the wrapper function are passed through the stack, and the wrapper function is then put on the stack
Parameters are copied to the register in the kernel reservation
3. Because all system invocation forms are the same, the wrapper function copies the system call number
To the EAX register, indicating which system call was used
4.wrapper function Execution Trap (int 0x80) interrupts, allowing the CPU to switch from user mode to kernel mode
Execution Interrupt Vector table
5. The kernel uses the System_call assembler to perform system calls:
Save the current register contents
Check the system call number
Execute system call
Restore the contents of the register and store the results on the stack
Return to wrapper function, switch from kernel mode to user mode
6. If there is an error in the system call, set the value of the global variable errno < indicate the cause of the error;
The wrapper function returns a value indicating an error in the call
= = Library function = = =
One of the standard functions of C language which is composed of many functions. Most library functions do not use system calls and are generally abstracted from
On top of the system call, the most common version of the library is the GNU C Library (glibc).
Command line execution/lib64/libc.so.6 or/lib/libc.so.6 can print version-related information
= = = Get Library version information = =
#include <gnu/libc-version.h>
const char *gnu_get_libc_version (void);
Returns a statically allocated string ending with the ' \ S ' character, similar to 2.12 string information
There is a function of the same type called CONFSTR
#include <unistd.h>
size_t confstr (int name, char *buf, size_t len);
Used in a manner similar to CONFSTR (_cs_gnu_libc_version, buf, sizeof (BUF));
The results of the above two functions print a sample similar to the following:
Gnue_get_libc_version return:2.12
Confstr RETURN:GLIBC 2.12
= = = Handling Error = =
#include <stdio.h>
void perror (const char *msg);
Prints a string that points to the MSG parameter, followed by the current errno error description, and outputs to the stderr stream
#include <string.h>
char *strerror (int errnum);
Returns a statically assigned string that describes the Errnum error message, and it is important to note that the function
Returns the content that the pointer points to is overwritten by the next call to the function, not for multithreaded use
Linux Programming-memoirs one