mirror of
https://passt.top/passt
synced 2024-11-05 20:31:11 +00:00
17689cc9bf
...instead of argv[0], which might or might not contain a valid path to the executable itself. Instead of mangling argv[0], use the same link to find out if we're already running the AVX2 build where supported. Alternatively, we could use execvpe(), but that might result in running a different installed version, in case e.g. the set of binaries is present in both /usr/bin and /usr/local/bin, with both being in $PATH. Reported-by: Wenli Quan <wquan@redhat.com> Link: https://bugzilla.redhat.com/show_bug.cgi?id=2101310 Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
48 lines
1.1 KiB
C
48 lines
1.1 KiB
C
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
/* PASST - Plug A Simple Socket Transport
|
|
* for qemu/UNIX domain socket mode
|
|
*
|
|
* PASTA - Pack A Subtle Tap Abstraction
|
|
* for network namespace/tap device mode
|
|
*
|
|
* arch.c - Architecture-specific implementations
|
|
*
|
|
* Copyright (c) 2022 Red Hat GmbH
|
|
* Author: Stefano Brivio <sbrivio@redhat.com>
|
|
*/
|
|
|
|
#include <limits.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
/**
|
|
* arch_avx2_exec() - Switch to AVX2 build if supported
|
|
* @argv: Arguments from command line
|
|
*/
|
|
#ifdef __x86_64__
|
|
void arch_avx2_exec(char **argv)
|
|
{
|
|
char exe[PATH_MAX] = { 0 }, new_path[PATH_MAX + sizeof(".avx2")], *p;
|
|
|
|
if (readlink("/proc/self/exe", exe, PATH_MAX - 1) < 0) {
|
|
perror("readlink /proc/self/exe");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
p = strstr(exe, ".avx2");
|
|
if (p && strlen(p) == strlen(".avx2"))
|
|
return;
|
|
|
|
if (__builtin_cpu_supports("avx2")) {
|
|
snprintf(new_path, PATH_MAX + sizeof(".avx2"), "%s.avx2", exe);
|
|
execve(new_path, argv, environ);
|
|
perror("Can't run AVX2 build, using non-AVX2 version");
|
|
}
|
|
}
|
|
#else
|
|
void arch_avx2_exec(char **argv) { (void)argv; }
|
|
#endif
|