tools/testing/selftests/sgx/main.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/sgx/main.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/sgx/main.c- Extension
.c- Size
- 56092 bytes
- Lines
- 1994
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
cpuid.helf.herrno.hfcntl.hstdbool.hstdio.hstdint.hstdlib.hstring.hunistd.hsys/ioctl.hsys/mman.hsys/stat.hsys/time.hsys/types.hsys/auxv.hdefines.hkselftest_harness.hmain.h
Detected Declarations
struct vdso_symtabenum sgx_secinfo_page_statefunction vdso_get_symtabfunction sgx2_supportedfunction elf_sym_hashfunction encl_get_tcs_offsetfunction encl_get_data_offsetfunction setup_test_enclfunction sgx_calc_section_metricfunction get_total_epc_memfunction test_handlerfunction enclavefunction ioctlfunction ioctl
Annotated Snippet
struct vdso_symtab {
Elf64_Sym *elf_symtab;
const char *elf_symstrtab;
Elf64_Word *elf_hashtab;
};
static Elf64_Dyn *vdso_get_dyntab(void *addr)
{
Elf64_Ehdr *ehdr = addr;
Elf64_Phdr *phdrtab = addr + ehdr->e_phoff;
int i;
for (i = 0; i < ehdr->e_phnum; i++)
if (phdrtab[i].p_type == PT_DYNAMIC)
return addr + phdrtab[i].p_offset;
return NULL;
}
static void *vdso_get_dyn(void *addr, Elf64_Dyn *dyntab, Elf64_Sxword tag)
{
int i;
for (i = 0; dyntab[i].d_tag != DT_NULL; i++)
if (dyntab[i].d_tag == tag)
return addr + dyntab[i].d_un.d_ptr;
return NULL;
}
static bool vdso_get_symtab(void *addr, struct vdso_symtab *symtab)
{
Elf64_Dyn *dyntab = vdso_get_dyntab(addr);
symtab->elf_symtab = vdso_get_dyn(addr, dyntab, DT_SYMTAB);
if (!symtab->elf_symtab)
return false;
symtab->elf_symstrtab = vdso_get_dyn(addr, dyntab, DT_STRTAB);
if (!symtab->elf_symstrtab)
return false;
symtab->elf_hashtab = vdso_get_dyn(addr, dyntab, DT_HASH);
if (!symtab->elf_hashtab)
return false;
return true;
}
static inline int sgx2_supported(void)
{
unsigned int eax, ebx, ecx, edx;
__cpuid_count(SGX_CPUID, 0x0, eax, ebx, ecx, edx);
return eax & 0x2;
}
static unsigned long elf_sym_hash(const char *name)
{
unsigned long h = 0, high;
while (*name) {
h = (h << 4) + *name++;
high = h & 0xf0000000;
if (high)
h ^= high >> 24;
h &= ~high;
}
return h;
}
static Elf64_Sym *vdso_symtab_get(struct vdso_symtab *symtab, const char *name)
{
Elf64_Word bucketnum = symtab->elf_hashtab[0];
Elf64_Word *buckettab = &symtab->elf_hashtab[2];
Elf64_Word *chaintab = &symtab->elf_hashtab[2 + bucketnum];
Elf64_Sym *sym;
Elf64_Word i;
for (i = buckettab[elf_sym_hash(name) % bucketnum]; i != STN_UNDEF;
i = chaintab[i]) {
sym = &symtab->elf_symtab[i];
if (!strcmp(name, &symtab->elf_symstrtab[sym->st_name]))
return sym;
}
Annotation
- Immediate include surface: `cpuid.h`, `elf.h`, `errno.h`, `fcntl.h`, `stdbool.h`, `stdio.h`, `stdint.h`, `stdlib.h`.
- Detected declarations: `struct vdso_symtab`, `enum sgx_secinfo_page_state`, `function vdso_get_symtab`, `function sgx2_supported`, `function elf_sym_hash`, `function encl_get_tcs_offset`, `function encl_get_data_offset`, `function setup_test_encl`, `function sgx_calc_section_metric`, `function get_total_epc_mem`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.