mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 18:10:56 +09:00
Kernel+LibC: Publish a "kernel info page" and use it for gettimeofday()
This patch adds a single "kernel info page" that is mappable read-only by any process and contains the current time of day. This is then used to implement a version of gettimeofday() that doesn't have to make a syscall. To protect against race condition issues, the info page also has a serial number which is incremented whenever the kernel updates the contents of the page. Make sure to verify that the serial number is the same before and after reading the information you want from the page.
This commit is contained in:
parent
931e4b7f5e
commit
77cf607cda
Notes:
sideshowbarker
2024-07-19 10:50:40 +09:00
Author: https://github.com/awesomekling
Commit: 77cf607cda
6 changed files with 62 additions and 9 deletions
|
@ -1,10 +1,11 @@
|
|||
#include <Kernel/KernelInfoPage.h>
|
||||
#include <Kernel/Syscall.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/times.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
@ -21,8 +22,17 @@ time_t time(time_t* tloc)
|
|||
|
||||
int gettimeofday(struct timeval* __restrict__ tv, void* __restrict__)
|
||||
{
|
||||
int rc = syscall(SC_gettimeofday, tv);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
static volatile KernelInfoPage* kernel_info;
|
||||
if (!kernel_info)
|
||||
kernel_info = (volatile KernelInfoPage*)syscall(SC_get_kernel_info_page);
|
||||
|
||||
for (;;) {
|
||||
auto serial = kernel_info->serial;
|
||||
*tv = const_cast<struct timeval&>(kernel_info->now);
|
||||
if (serial == kernel_info->serial)
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* ctime(const time_t*)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue