Skip to content

Commit 921abdf

Browse files
BernardXiongRbb666
authored andcommitted
[smart] move vdso.c to arch/common folder.
1 parent 721dfbf commit 921abdf

File tree

1 file changed

+116
-0
lines changed
  • components/lwp/arch/common

1 file changed

+116
-0
lines changed

components/lwp/arch/common/vdso.c

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* Copyright (c) 2006-2025 RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2024-07-04 rcitach init ver.
9+
* 2025-04-22 ScuDays Add VDSO functionality under the riscv64 architecture.
10+
*/
11+
12+
#include <rtthread.h>
13+
#include <mmu.h>
14+
#include <lwp_user_mm.h>
15+
16+
#include "vdso.h"
17+
#include "vdso_datapage.h"
18+
#define DBG_TAG "vdso"
19+
#define DBG_LVL DBG_INFO
20+
#include <rtdbg.h>
21+
22+
enum vdso_abi
23+
{
24+
VDSO_ABI_COMMON,
25+
};
26+
27+
enum vvar_pages
28+
{
29+
VVAR_DATA_PAGE_OFFSET,
30+
VVAR_TIMENS_PAGE_OFFSET,
31+
VVAR_NR_PAGES,
32+
};
33+
34+
35+
struct vdso_abi_info
36+
{
37+
const char *name;
38+
const char *vdso_code_start;
39+
const char *vdso_code_end;
40+
unsigned long vdso_pages;
41+
};
42+
43+
static struct vdso_abi_info vdso_info[] = {
44+
[VDSO_ABI_COMMON] = {
45+
.name = "vdso_common",
46+
.vdso_code_start = __vdso_text_start,
47+
.vdso_code_end = __vdso_text_end,
48+
},
49+
};
50+
51+
static union {
52+
struct vdso_data data[CS_BASES];
53+
uint8_t page[ARCH_PAGE_SIZE];
54+
} vdso_data_store __page_aligned_data;
55+
struct vdso_data *vdso_data = vdso_data_store.data;
56+
int init_ret_flag = RT_EOK;
57+
58+
static int __setup_additional_pages(enum vdso_abi abi, struct rt_lwp *lwp)
59+
{
60+
RT_ASSERT(lwp != RT_NULL);
61+
62+
int ret;
63+
void *vdso_base = RT_NULL;
64+
unsigned long vdso_data_len, vdso_text_len;
65+
66+
vdso_data_len = VVAR_NR_PAGES * ARCH_PAGE_SIZE;
67+
vdso_text_len = vdso_info[abi].vdso_pages << ARCH_PAGE_SHIFT;
68+
69+
vdso_base = lwp_map_user_phy(lwp, RT_NULL, rt_kmem_v2p((void *)vdso_data), vdso_data_len, 0);
70+
if (vdso_base != RT_NULL)
71+
{
72+
ret = RT_EOK;
73+
}
74+
else
75+
{
76+
ret = RT_ERROR;
77+
}
78+
79+
vdso_base += vdso_data_len;
80+
vdso_base = lwp_map_user_phy(lwp, vdso_base, rt_kmem_v2p((void *)vdso_info[abi].vdso_code_start), vdso_text_len, 0);
81+
82+
lwp->vdso_vbase = vdso_base;
83+
return ret;
84+
}
85+
86+
int arch_setup_additional_pages(struct rt_lwp *lwp)
87+
{
88+
int ret;
89+
if (init_ret_flag != RT_EOK) return -RT_ERROR;
90+
ret = __setup_additional_pages(VDSO_ABI_COMMON, lwp);
91+
92+
return ret;
93+
}
94+
95+
96+
static void __initdata(void)
97+
{
98+
struct tm time_vdso = SOFT_RTC_VDSOTIME_DEFAULT;
99+
vdso_data->realtime_initdata = timegm(&time_vdso);
100+
}
101+
102+
103+
static int validate_vdso_elf(void)
104+
{
105+
if (rt_memcmp(vdso_info[VDSO_ABI_COMMON].vdso_code_start, ELF_HEAD, ELF_HEAD_LEN))
106+
{
107+
LOG_E("vDSO is not a valid ELF object!");
108+
init_ret_flag = -RT_ERROR;
109+
return -RT_ERROR;
110+
}
111+
vdso_info[VDSO_ABI_COMMON].vdso_pages = (vdso_info[VDSO_ABI_COMMON].vdso_code_end - vdso_info[VDSO_ABI_COMMON].vdso_code_start) >> ARCH_PAGE_SHIFT;
112+
113+
__initdata();
114+
return RT_EOK;
115+
}
116+
INIT_COMPONENT_EXPORT(validate_vdso_elf);

0 commit comments

Comments
 (0)