c7500c1b53
Add SUBARCH target for Clang+um (which must go last, not alphabetically,
so the other SUBARCHes are assigned). Remove open-coded "DEFINE"
macro, instead using linux/kbuild.h's version which was updated to use
Clang-friendly assembly in commit cf0c3e68aa
("kbuild: fix asm-offset
generation to work with clang"). Redefine "DEFINE_LONGS" in terms of
"COMMENT" and "DEFINE" so that the intended coment actually has useful
content. Add a missed "break" to avoid implicit fall-through warnings.
This lets me run KUnit tests with Clang:
$ ./tools/testing/kunit/kunit.py run --make_options LLVM=1
...
Cc: Jeff Dike <jdike@addtoit.com>
Cc: Richard Weinberger <richard@nod.at>
Cc: Anton Ivanov <anton.ivanov@cambridgegreys.com>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: David Gow <davidgow@google.com>
Cc: linux-um@lists.infradead.org
Cc: linux-kbuild@vger.kernel.org
Cc: linux-kselftest@vger.kernel.org
Cc: kunit-dev@googlegroups.com
Cc: llvm@lists.linux.dev
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Link: https://lore.kernel.org/lkml/Yg2YubZxvYvx7%2Fnm@dev-arch.archlinux-ax161/
Tested-by: David Gow <davidgow@google.com>
Link: https://lore.kernel.org/lkml/CABVgOSk=oFxsbSbQE-v65VwR2+mXeGXDDjzq8t7FShwjJ3+kUg@mail.gmail.com/
Signed-off-by: Kees Cook <keescook@chromium.org>
---
v1: https://lore.kernel.org/lkml/20220217002843.2312603-1-keescook@chromium.org
v2: https://lore.kernel.org/lkml/20220224055831.1854786-1-keescook@chromium.org
v3:
- use kbuild.h to avoid duplication (Masahiro)
- fix intended comments (Masahiro)
- use SUBARCH (Nathan)
85 lines
2.1 KiB
C
85 lines
2.1 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <stdio.h>
|
|
#include <stddef.h>
|
|
#include <signal.h>
|
|
#include <poll.h>
|
|
#include <sys/mman.h>
|
|
#include <sys/user.h>
|
|
#define __FRAME_OFFSETS
|
|
#include <linux/ptrace.h>
|
|
#include <asm/types.h>
|
|
#include <linux/kbuild.h>
|
|
|
|
#define DEFINE_LONGS(sym, val) \
|
|
COMMENT(#val " / sizeof(unsigned long)"); \
|
|
DEFINE(sym, val / sizeof(unsigned long))
|
|
|
|
void foo(void)
|
|
{
|
|
#ifdef __i386__
|
|
DEFINE_LONGS(HOST_FP_SIZE, sizeof(struct user_fpregs_struct));
|
|
DEFINE_LONGS(HOST_FPX_SIZE, sizeof(struct user_fpxregs_struct));
|
|
|
|
DEFINE(HOST_IP, EIP);
|
|
DEFINE(HOST_SP, UESP);
|
|
DEFINE(HOST_EFLAGS, EFL);
|
|
DEFINE(HOST_AX, EAX);
|
|
DEFINE(HOST_BX, EBX);
|
|
DEFINE(HOST_CX, ECX);
|
|
DEFINE(HOST_DX, EDX);
|
|
DEFINE(HOST_SI, ESI);
|
|
DEFINE(HOST_DI, EDI);
|
|
DEFINE(HOST_BP, EBP);
|
|
DEFINE(HOST_CS, CS);
|
|
DEFINE(HOST_SS, SS);
|
|
DEFINE(HOST_DS, DS);
|
|
DEFINE(HOST_FS, FS);
|
|
DEFINE(HOST_ES, ES);
|
|
DEFINE(HOST_GS, GS);
|
|
DEFINE(HOST_ORIG_AX, ORIG_EAX);
|
|
#else
|
|
#ifdef FP_XSTATE_MAGIC1
|
|
DEFINE_LONGS(HOST_FP_SIZE, 2696);
|
|
#else
|
|
DEFINE(HOST_FP_SIZE, sizeof(struct _fpstate) / sizeof(unsigned long));
|
|
#endif
|
|
DEFINE_LONGS(HOST_BX, RBX);
|
|
DEFINE_LONGS(HOST_CX, RCX);
|
|
DEFINE_LONGS(HOST_DI, RDI);
|
|
DEFINE_LONGS(HOST_SI, RSI);
|
|
DEFINE_LONGS(HOST_DX, RDX);
|
|
DEFINE_LONGS(HOST_BP, RBP);
|
|
DEFINE_LONGS(HOST_AX, RAX);
|
|
DEFINE_LONGS(HOST_R8, R8);
|
|
DEFINE_LONGS(HOST_R9, R9);
|
|
DEFINE_LONGS(HOST_R10, R10);
|
|
DEFINE_LONGS(HOST_R11, R11);
|
|
DEFINE_LONGS(HOST_R12, R12);
|
|
DEFINE_LONGS(HOST_R13, R13);
|
|
DEFINE_LONGS(HOST_R14, R14);
|
|
DEFINE_LONGS(HOST_R15, R15);
|
|
DEFINE_LONGS(HOST_ORIG_AX, ORIG_RAX);
|
|
DEFINE_LONGS(HOST_CS, CS);
|
|
DEFINE_LONGS(HOST_SS, SS);
|
|
DEFINE_LONGS(HOST_EFLAGS, EFLAGS);
|
|
#if 0
|
|
DEFINE_LONGS(HOST_FS, FS);
|
|
DEFINE_LONGS(HOST_GS, GS);
|
|
DEFINE_LONGS(HOST_DS, DS);
|
|
DEFINE_LONGS(HOST_ES, ES);
|
|
#endif
|
|
|
|
DEFINE_LONGS(HOST_IP, RIP);
|
|
DEFINE_LONGS(HOST_SP, RSP);
|
|
#endif
|
|
|
|
DEFINE(UM_FRAME_SIZE, sizeof(struct user_regs_struct));
|
|
DEFINE(UM_POLLIN, POLLIN);
|
|
DEFINE(UM_POLLPRI, POLLPRI);
|
|
DEFINE(UM_POLLOUT, POLLOUT);
|
|
|
|
DEFINE(UM_PROT_READ, PROT_READ);
|
|
DEFINE(UM_PROT_WRITE, PROT_WRITE);
|
|
DEFINE(UM_PROT_EXEC, PROT_EXEC);
|
|
}
|