Skip to content

Commit 2ec4701

Browse files
committed
Add support for more getauxval(3) parameters
1 parent c946021 commit 2ec4701

File tree

6 files changed

+91
-25
lines changed

6 files changed

+91
-25
lines changed

kos/include/elf.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,6 +1945,9 @@ typedef struct elf64_auxv_t /*[NAME(elf64_auxv)][PREFIX(a_)]*/ {
19451945
/* Everything from here on seems to be non-portable (linux- (and KOS) specific?) */
19461946
#define AT_PLATFORM 15 /* String identifying platform. */
19471947
#define AT_HWCAP 16 /* Machine dependent hints about processor capabilities. */
1948+
#define HWCAP_X86_SSE2 0x0001 /* [i386] */
1949+
#define HWCAP_X86_64 0x0002 /* [x86_64] */
1950+
#define HWCAP_X86_AVX512_1 0x0004 /* [x86_64] */
19481951
#define AT_CLKTCK 17 /* Frequency of times() */
19491952
#define AT_FPUCW 18 /* Used FPU control word.
19501953
* This entry gives some information about the
@@ -1959,10 +1962,10 @@ typedef struct elf64_auxv_t /*[NAME(elf64_auxv)][PREFIX(a_)]*/ {
19591962
#define AT_BASE_PLATFORM 24 /* String identifying real platforms. */
19601963
#define AT_RANDOM 25 /* Address of 16 random bytes. */
19611964
#define AT_HWCAP2 26 /* More machine-dependent hints about processor capabilities. */
1962-
/*efine AT_ 27 * ... */
1963-
/*efine AT_ 28 * ... */
1964-
/*efine AT_ 29 * ... */
1965-
/*efine AT_ 30 * ... */
1965+
#define AT_RSEQ_FEATURE_SIZE 27 /* rseq supported feature size. */
1966+
#define AT_RSEQ_ALIGN 28 /* rseq allocation alignment. */
1967+
#define AT_HWCAP3 29 /* extension of AT_HWCAP. */
1968+
#define AT_HWCAP4 30 /* extension of AT_HWCAP. */
19661969
#define AT_EXECFN 31 /* Filename of executable (absolute & normalized; s.a. `dlmodulename()') */
19671970
#define AT_SYSINFO 32 /* Pointer to the global system page used for system calls and other nice things. */
19681971
#define AT_SYSINFO_EHDR 33 /* *ditto* */

kos/src/kernel/core/memory/mman/driver.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,51 +1694,51 @@ driver_dlsym_drv(struct driver *__restrict self,
16941694
struct driver_syminfo *__restrict info)
16951695
THROWS(E_SEGFAULT, ...) {
16961696
NCX char const *name = info->dsi_name + 4;
1697-
if (strcmp(name, "self") == 0) {
1697+
if (strcmp(name, "self") == 0) { /* extern struct driver drv_self; */
16981698
info->dsi_addr = self;
16991699
info->dsi_size = sizeof(*self);
17001700
goto ok;
17011701
}
17021702
if (name[0] == 'l' && name[1] == 'o' &&
17031703
name[2] == 'a' && name[3] == 'd') {
17041704
NCX char const *load_name = name + 4;
1705-
if (strcmp(load_name, "addr") == 0) {
1705+
if (strcmp(load_name, "addr") == 0) { /* extern byte_t drv_loadaddr[]; */
17061706
info->dsi_addr = (void *)self->d_module.md_loadaddr;
17071707
goto ok_size0;
17081708
}
1709-
if (strcmp(load_name, "min") == 0) {
1709+
if (strcmp(load_name, "min") == 0) { /* extern byte_t drv_loadmin[]; */
17101710
info->dsi_addr = self->d_module.md_loadmin;
17111711
goto ok_size0;
17121712
}
1713-
if (strcmp(load_name, "max") == 0) {
1713+
if (strcmp(load_name, "max") == 0) { /* extern byte_t drv_loadmax[]; */
17141714
info->dsi_addr = self->d_module.md_loadmax;
17151715
goto ok_size0;
17161716
}
17171717
}
1718-
if (strcmp(name, "name") == 0) {
1718+
if (strcmp(name, "name") == 0) { /* extern char drv_name[]; */
17191719
info->dsi_addr = (void *)self->d_name;
17201720
info->dsi_size = (strlen(self->d_name) + 1) * sizeof(char);
17211721
goto ok;
17221722
}
1723-
if (strcmp(name, "file") == 0) {
1723+
if (strcmp(name, "file") == 0) { /* extern struct mfile *drv_file; */
17241724
COMPILER_UNUSED(driver_getfile(self)); /* Make sure it was initialized */
17251725
info->dsi_addr = &self->d_module.md_file;
17261726
info->dsi_size = sizeof(void *);
17271727
goto ok;
17281728
}
1729-
if (strcmp(name, "cmdline") == 0) {
1729+
if (strcmp(name, "cmdline") == 0) { /* extern char drv_cmdline[]; */
17301730
info->dsi_addr = (void *)self->d_cmdline;
17311731
info->dsi_size = (strlen(self->d_cmdline) + 1) * sizeof(char);
17321732
goto ok;
17331733
}
17341734
if (name[0] == 'a' && name[1] == 'r' && name[2] == 'g') {
17351735
NCX char const *arg_name = name + 3;
1736-
if (strcmp(arg_name, "c") == 0) {
1736+
if (strcmp(arg_name, "c") == 0) { /* extern size_t drv_argc; */
17371737
info->dsi_addr = &self->d_argc;
17381738
info->dsi_size = sizeof(self->d_argc);
17391739
goto ok;
17401740
}
1741-
if (strcmp(arg_name, "v") == 0) {
1741+
if (strcmp(arg_name, "v") == 0) { /* extern char *drv_argv[]; */
17421742
info->dsi_addr = self->d_argv;
17431743
info->dsi_size = self->d_argc * sizeof(char *);
17441744
goto ok;

kos/src/kernel/core/misc/except-syscall.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ PUBLIC ATTR_PERTASK ATTR_ALIGN(struct user_except_handler) this_user_except_hand
8585
* TID. */
8686
PUBLIC ATTR_PERTASK ATTR_ALIGN(NCX pid_t *) this_tid_address = NULL;
8787

88-
DEFINE_PERMMAN_ONEXEC(reset_user_except_handler);
89-
PRIVATE ATTR_USED NOBLOCK void
90-
NOTHROW(KCALL reset_user_except_handler)(void) {
88+
DEFINE_PERMMAN_ONEXEC(onexec_reset_user_except_handler);
89+
INTDEF NOBLOCK void NOTHROW(KCALL onexec_reset_user_except_handler)(void);
90+
INTERN NOBLOCK void NOTHROW(KCALL onexec_reset_user_except_handler)(void) {
9191
struct user_except_handler *hand;
9292
hand = &PERTASK(this_user_except_handler);
9393
hand->ueh_mode = EXCEPT_HANDLER_MODE_DISABLED;

kos/src/kernel/core/sched/sigaction.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ NOTHROW(FCALL sighand_has_nondefault_sig_ign)(struct sighand const *__restrict s
438438

439439
/* During exec(), all signal handler dispositions of the calling thread are reset */
440440
DEFINE_PERMMAN_ONEXEC(onexec_posix_signals_reset_action);
441+
INTDEF void KCALL onexec_posix_signals_reset_action(void);
441442
INTERN void KCALL onexec_posix_signals_reset_action(void) {
442443
REF struct sighand_ptr *handptr;
443444
/* Posix says that signals set to SIG_IGN should remain SIG_IGN after exec(). */

kos/src/kernel/core/sched/task-clone.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -949,20 +949,20 @@ task_clone_kthread(int (*thread_main)(), size_t argc, ...)
949949

950950

951951
/* Per-task relocations */
952-
INTDEF uintptr_t __kernel_pertask_relocations_start[];
953-
INTDEF uintptr_t __kernel_pertask_relocations_end[];
952+
extern uintptr_t __kernel_pertask_relocations_start[];
953+
extern uintptr_t __kernel_pertask_relocations_end[];
954954

955955
/* Initialize task relocations, as defined by `DEFINE_PERTASK_RELOCATION()' */
956956
INTERN NOBLOCK NONNULL((1)) void
957957
NOTHROW(FCALL _task_init_relocations)(struct task *__restrict self) {
958958
uintptr_t *p_offset;
959959
/* Apply relocations */
960-
for (p_offset = __kernel_pertask_relocations_start;
961-
p_offset < __kernel_pertask_relocations_end; ++p_offset) {
960+
p_offset = __kernel_pertask_relocations_start;
961+
do {
962962
uintptr_t *reladdr;
963963
reladdr = (uintptr_t *)((byte_t *)self + *p_offset);
964964
*reladdr += (uintptr_t)self;
965-
}
965+
} while (++p_offset < __kernel_pertask_relocations_end);
966966

967967
/* Assert that relocations were applied correctly. */
968968
assert(self->t_self == self);

kos/src/libc/user/sys.auxv.c

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@
5050
#include <string.h> /* preadall */
5151
#endif /* __i386__ && !__x86_64__ */
5252

53+
#if defined(__x86_64__) || defined(__i386__)
54+
#include <asm/intrin-cpuid.h>
55+
#endif /* ... */
56+
57+
#if __has_include(<fpu_control.h>)
58+
#include <fpu_control.h>
59+
#endif /* __has_include(<fpu_control.h>) */
60+
5361
DECL_BEGIN
5462

5563
PRIVATE ATTR_SECTION(".rodata.crt.system.getauxval") char const
@@ -135,10 +143,6 @@ NOTHROW_NCX(LIBCCALL libc_getauxval)(ulongptr_t type)
135143
ulongptr_t result;
136144
switch (type) {
137145

138-
case AT_IGNORE:
139-
result = 0;
140-
break;
141-
142146
case AT_EXECFD:
143147
result = dlmodulefd(dlopen(NULL, 0));
144148
break;
@@ -271,9 +275,67 @@ NOTHROW_NCX(LIBCCALL libc_getauxval)(ulongptr_t type)
271275
case AT_MINSIGSTKSZ:
272276
return SIGSTKSZ;
273277

278+
#ifdef __x86_64__
279+
case AT_HWCAP: {
280+
/* This logic here matches what is done by GLibc */
281+
uint32_t eax, ebx, ecx, edx;
282+
result = HWCAP_X86_64;
283+
__cpuid(0, &eax, &ecx, &edx, &ebx);
284+
if (ebx == 0x756e6547 && ecx == 0x6c65746e && edx == 0x49656e69 && eax >= 7) {
285+
uint32_t b7 = __cpuid_ebx(0x7);
286+
if ((b7 & (CPUID_7B_AVX512CD | CPUID_7B_AVX512ER | CPUID_7B_AVX512BW |
287+
CPUID_7B_AVX512DQ | CPUID_7B_AVX512VL)) ==
288+
/* */ (CPUID_7B_AVX512CD | CPUID_7B_AVX512BW | CPUID_7B_AVX512DQ | CPUID_7B_AVX512VL))
289+
result |= HWCAP_X86_AVX512_1;
290+
}
291+
} break;
292+
#elif defined(__i386__)
293+
case AT_HWCAP: {
294+
/* This logic here matches what is done by GLibc */
295+
uint32_t eax, ebx, ecx, edx;
296+
result = 0;
297+
__cpuid(0, &eax, &ecx, &edx, &ebx);
298+
if (eax >= 1) {
299+
if (__cpuid_edx(0x1) & CPUID_1D_SSE2)
300+
result |= HWCAP_X86_SSE2;
301+
}
302+
} break;
303+
#endif /* ... */
304+
305+
#ifdef _FPU_DEFAULT
306+
case AT_FPUCW:
307+
result = _FPU_DEFAULT;
308+
break;
309+
#endif /* _FPU_DEFAULT */
310+
311+
//TODO:#define AT_DCACHEBSIZE 19 /* Cache block sizes. Data cache block size. */
312+
//TODO:#define AT_ICACHEBSIZE 20 /* Instruction cache block size. */
313+
//TODO:#define AT_UCACHEBSIZE 21 /* Unified cache block size. */
314+
//TODO:#define AT_HWCAP2 26 /* More machine-dependent hints about processor capabilities. */
315+
//TODO:#define AT_RSEQ_FEATURE_SIZE 27 /* rseq supported feature size. */
316+
//TODO:#define AT_RSEQ_ALIGN 28 /* rseq allocation alignment. */
317+
//TODO:#define AT_HWCAP3 29 /* extension of AT_HWCAP. */
318+
//TODO:#define AT_HWCAP4 30 /* extension of AT_HWCAP. */
319+
//TODO:#define AT_SYSINFO 32 /* Pointer to the global system page used for system calls and other nice things. */
320+
//TODO:#define AT_SYSINFO_EHDR 33 /* *ditto* */
321+
//TODO:#define AT_L1I_CACHESHAPE 34 /* Shapes of the caches. Bits 0-3 contains associativity; bits 4-7 contains log2 of line size; mask those to get cache size. */
322+
//TODO:#define AT_L1D_CACHESHAPE 35 /* ... */
323+
//TODO:#define AT_L2_CACHESHAPE 36 /* ... */
324+
//TODO:#define AT_L3_CACHESHAPE 37 /* ... */
325+
//TODO:#define AT_L1I_CACHESIZE 40 /* Shapes of the caches, with more room to describe them. `AT_*GEOMETRY' are comprised of cache line size in bytes in the bottom 16 bits and the cache associativity in the next 16 bits. */
326+
//TODO:#define AT_L1I_CACHEGEOMETRY 41 /* ... */
327+
//TODO:#define AT_L1D_CACHESIZE 42 /* ... */
328+
//TODO:#define AT_L1D_CACHEGEOMETRY 43 /* ... */
329+
//TODO:#define AT_L2_CACHESIZE 44 /* ... */
330+
//TODO:#define AT_L2_CACHEGEOMETRY 45 /* ... */
331+
//TODO:#define AT_L3_CACHESIZE 46 /* ... */
332+
//TODO:#define AT_L3_CACHEGEOMETRY 47 /* ... */
333+
274334
default:
275335
not_found:
276336
libc_seterrno(ENOENT);
337+
ATTR_FALLTHROUGH
338+
case AT_IGNORE:
277339
result = 0;
278340
break;
279341
}

0 commit comments

Comments
 (0)