1e41f4b71Sopenharmony_ci# Virtual Dynamic Shared Object 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ci## Basic Concepts 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ciDifferent from a common dynamic shared library, which stores its .so files in the file system, the virtual dynamic shared object (VDSO) has its .so files stored in the system image. The kernel determines the .so files needed and provides them to the application program. That is why the VDSO is called a virtual dynamic shared library. 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ciThe VDSO mechanism allows OpenHarmony user-mode programs to quickly obtain kernel-related data. It can accelerate certain system calls and implement quick read of non-sensitive data (hardware and software configuration). 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci## Working Principles 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ciThe VDSO can be regarded as a section of memory (read-only) maintained by the kernel and mapped to the address space of the user-mode applications. By linking **vdso.so**, the applications can directly access this mapped memory instead of invoking system calls, accelerating application execution. 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ciVDSO can be divided into: 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci- Data page: provides the kernel-time data mapped to the user process. 18e41f4b71Sopenharmony_ci- Code page: provides the logic for shielding system calls. 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci**Figure 1** VDSO system design 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ciThe VDSO mechanism involves the following steps: 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci1. Creates the VDSO data page during kernel initialization. 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci2. Creates the VDSO code page during kernel initialization. 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci3. Updates kernel data to the VDSO data page based on the system clock interrupts. 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci4. Maps the code page to the user space when a user process is created. 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci5. Binds the VDSO symbols when the user program creates dynamic linking. 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci6. The VDSO code page intercepts specific system calls (for example, **clock_gettime(CLOCK_REALTIME_COARSE, &ts)**). 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci7. The VDSO code page allows direct read of the mapped VDSO data page rather than invoking a system call. 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci8. Returns data from the VDSO data page to the VDSO code page. 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci9. Returns the data obtained from the VDSO data page to the user program. 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci> **NOTE**<br> 45e41f4b71Sopenharmony_ci> 46e41f4b71Sopenharmony_ci> - The VDSO mechanism supports the **CLOCK_REALTIME_COARSE** and **CLOCK_MONOTONIC_COARSE** functions of the **clock_gettime** API in the LibC library. For details about how to use the **clock_gettime** API, see the POSIX standard. 47e41f4b71Sopenharmony_ci> 48e41f4b71Sopenharmony_ci> - You can call **clock_gettime(CLOCK_REALTIME_COARSE, &ts)** or **clock_gettime(CLOCK_MONOTONIC_COARSE, &ts)** of the Libc library to use the VDSO. 49e41f4b71Sopenharmony_ci> 50e41f4b71Sopenharmony_ci> - When VDSO is used, the time precision is the same as that of the tick interrupt of the system. The VDSO mechanism is applicable to the scenario where there is no demand for high time precision and **clock_gettime** or **gettimeofday** is frequently triggered in a short period of time. The VDSO mechanism is not recommended for the system demanding high time precision. 51