| 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | /* |
| 3 | * Copyright (C) 2009 John Kacur <[email protected]> |
| 4 | */ |
| 5 | #include "rt-get_cpu.h" |
| 6 | #ifdef __NR_getcpu |
| 7 | #elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) \ |
| 8 | && __GLIBC__>=2 && __GLIBC_MINOR__>=6 |
| 9 | #else |
| 10 | int (*get_cpu)(void); |
| 11 | int (*get_cpu_vdsop)(unsigned int *, unsigned int *, void *); |
| 12 | |
| 13 | int get_cpu_setup(void) |
| 14 | { |
| 15 | void *handle = dlopen("linux-vdso.so.1", RTLD_LAZY); |
| 16 | get_cpu_vdsop = NULL; |
| 17 | if (handle) { |
| 18 | get_cpu_vdsop = dlsym(handle, "getcpu"); |
| 19 | dlclose(handle); |
| 20 | if (get_cpu_vdsop) { |
| 21 | get_cpu = getcpu_vdso; |
| 22 | return 0; |
| 23 | } |
| 24 | } |
| 25 | return -1; |
| 26 | } |
| 27 | |
| 28 | #endif |