-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split kasld.h header into separate header files for each architecture
- Loading branch information
Showing
47 changed files
with
636 additions
and
547 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
a.out | ||
*.gch | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
// --- | ||
// <[email protected]> | ||
|
||
#include "kasld.h" | ||
#include "include/kasld.h" | ||
#include <fcntl.h> | ||
#include <linux/can.h> | ||
#include <linux/can/bcm.h> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
// --- | ||
// <[email protected]> | ||
|
||
#include "kasld.h" | ||
#include "include/kasld.h" | ||
#include <errno.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
// <[email protected]> | ||
|
||
#define _GNU_SOURCE | ||
#include "kasld.h" | ||
#include "include/kasld.h" | ||
#include "include/syslog.h" | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
// <[email protected]> | ||
|
||
#define _GNU_SOURCE | ||
#include "kasld.h" | ||
#include "include/kasld.h" | ||
#include "include/syslog.h" | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
// <[email protected]> | ||
|
||
#define _GNU_SOURCE | ||
#include "kasld.h" | ||
#include "include/kasld.h" | ||
#include "include/syslog.h" | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ | |
// <[email protected]> | ||
|
||
#define _GNU_SOURCE | ||
#include "kasld.h" | ||
#include "include/kasld.h" | ||
#include "include/syslog.h" | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ | |
// <[email protected]> | ||
|
||
#define _GNU_SOURCE | ||
#include "kasld.h" | ||
#include "include/kasld.h" | ||
#include "include/syslog.h" | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,7 @@ | |
// <[email protected]> | ||
|
||
#define _GNU_SOURCE | ||
#include "kasld.h" | ||
#include "include/kasld.h" | ||
#include "include/syslog.h" | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ | |
// <[email protected]> | ||
|
||
#define _GNU_SOURCE | ||
#include "kasld.h" | ||
#include "include/kasld.h" | ||
#include "include/syslog.h" | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
// <[email protected]> | ||
|
||
#define _GNU_SOURCE | ||
#include "kasld.h" | ||
#include "include/kasld.h" | ||
#include "include/syslog.h" | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ | |
// <[email protected]> | ||
|
||
#define _GNU_SOURCE | ||
#include "kasld.h" | ||
#include "include/kasld.h" | ||
#include "include/syslog.h" | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,7 @@ | |
// <[email protected]> | ||
|
||
#define _GNU_SOURCE | ||
#include "kasld.h" | ||
#include "include/kasld.h" | ||
#include "include/syslog.h" | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
// <[email protected]> | ||
|
||
#define _GNU_SOURCE | ||
#include "kasld.h" | ||
#include "include/kasld.h" | ||
#include "include/syslog.h" | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// This file is part of KASLD - https://github.com/bcoles/kasld | ||
// | ||
// Expected kernel address space values for supported architectures. | ||
// | ||
// - KERNEL_VAS_START: Expected virtual address for start of the kernel | ||
// virtual address space (VAS). | ||
// (eg. 0xc0000000 for 32-bit systems with 3GB vmsplit) | ||
// | ||
// - KERNEL_VAS_END: Expected end of kernel virtual address space. | ||
// (including modules, I/O, guard regions, ...) | ||
// | ||
// - KERNEL_BASE_MIN: Expected minimum possible kernel base virtual address. | ||
// | ||
// - KERNEL_BASE_MAX: Expected maximum possible kernel base virtual address. | ||
// | ||
// - MODULES_START: Expected start virtual address for kernel modules. | ||
// | ||
// - MODULES_END: Expected end virtual address for kernel modules. | ||
// | ||
// - KERNEL_ALIGN: Expected kernel address alignment. | ||
// (usually 2MiB on modern systems) | ||
// | ||
// - KERNEL_TEXT_DEFAULT: Default kernel base virtual address when KASLR is | ||
// disabled (including text offset). This value is | ||
// calculated automatically based on above values. | ||
// | ||
// The default values should work on most systems, but may need | ||
// to be tweaked for the target system - especially old kernels, | ||
// embedded devices (ie, armv7), or systems with a non-default | ||
// memory layout. | ||
// --- | ||
// <[email protected]> | ||
|
||
#define MB 0x100000ul | ||
#define GB 0x40000000ul | ||
|
||
#if defined(__x86_64__) || defined(__amd64__) | ||
#include "kasld/x86_64.h" | ||
#elif defined(__i386__) | ||
#include "kasld/x86_32.h" | ||
#elif defined(__aarch64__) | ||
#include "kasld/arm64.h" | ||
#elif defined(__arm__) || defined(__ARM_ARCH_6__) || \ | ||
defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || \ | ||
defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || \ | ||
defined(__ARM_ARCH_6T2__) || defined(__ARM_ARCH_7__) || \ | ||
defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || \ | ||
defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) | ||
#include "kasld/arm32.h" | ||
#elif defined(__mips64) || defined(__mips64__) | ||
#include "kasld/mips64.h" | ||
#elif defined(__mips__) | ||
#include "kasld/mips32.h" | ||
#elif defined(__powerpc64__) || defined(__POWERPC64__) || \ | ||
defined(__ppc64__) || defined(__PPC64__) | ||
#include "kasld/ppc64.h" | ||
#elif defined(__powerpc__) || defined(__POWERPC__) || defined(__ppc__) || \ | ||
defined(__PPC__) | ||
#include "kasld/ppc32.h" | ||
#elif (defined(__riscv) || defined(__riscv__)) && __riscv_xlen == 64 | ||
#include "kasld/riscv64.h" | ||
#elif (defined(__riscv) || defined(__riscv__)) && __riscv_xlen == 32 | ||
#include "kasld/riscv32.h" | ||
#elif defined(__s390__) || defined(__s390x__) || defined(__370__) || \ | ||
defined(__zarch__) | ||
#include "kasld/s390.h" | ||
#elif defined(__sparc__) | ||
#include "kasld/sparc.h" | ||
#else | ||
#error "Unrecognised architecture!" | ||
#endif | ||
|
||
/* ----------------------------------------------------------------------------- | ||
* Sanity check configured values | ||
* ----------------------------------------------------------------------------- | ||
*/ | ||
#if KERNEL_VAS_START > KERNEL_VAS_END | ||
#error "Defined KERNEL_VAS_START is larger than KERNEL_VAS_END" | ||
#endif | ||
|
||
#if KERNEL_VAS_START > KERNEL_BASE_MIN | ||
#error "Defined KERNEL_VAS_START is larger than KERNEL_BASE_MIN" | ||
#endif | ||
|
||
#if KERNEL_BASE_MAX > KERNEL_VAS_END | ||
#error "Defined KERNEL_BASE_MAX is larger than KERNEL_VAS_END" | ||
#endif | ||
|
||
#if KERNEL_TEXT_DEFAULT > KERNEL_BASE_MAX | ||
#error "Generated KERNEL_TEXT_DEFAULT is larger than KERNEL_BASE_MAX" | ||
#endif | ||
|
||
#if KERNEL_TEXT_DEFAULT < KERNEL_BASE_MIN | ||
#error "Generated KERNEL_TEXT_DEFAULT is smaller than KERNEL_BASE_MIN" | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// This file is part of KASLD - https://github.com/bcoles/kasld | ||
// | ||
// Definitions for ARM 32-bit (arm6l / arm7l / armhf) | ||
// | ||
// KASLR support added in commit 588ab3f9afdfa1a6b1e5761c858b2c4ab6098285 in | ||
// kernel v4.6-rc1~110 on 2016-03-17. | ||
// | ||
// References: | ||
// https://github.com/torvalds/linux/commit/588ab3f9afdfa1a6b1e5761c858b2c4ab6098285 | ||
// https://people.kernel.org/linusw/how-the-arm32-linux-kernel-decompresses | ||
// https://people.kernel.org/linusw/how-the-arm32-kernel-starts | ||
// https://www.kernel.org/doc/Documentation/arm/Porting | ||
// https://elixir.bootlin.com/linux/v6.1.1/source/arch/arm/kernel/head.S | ||
// https://elixir.bootlin.com/linux/v6.1.1/source/arch/arm/include/asm/memory.h#L30 | ||
// --- | ||
// <[email protected]> | ||
|
||
// 3GB vmsplit (0xc0000000) is common; but an unsafe assumption, | ||
// especially for embedded systems | ||
// https://elixir.bootlin.com/linux/v6.1.1/source/arch/arm/Kconfig#L1116 | ||
#define PAGE_OFFSET 0xc0000000ul | ||
|
||
// https://elixir.bootlin.com/linux/v6.1.1/source/arch/arm/Kconfig#L276 | ||
#define PHYS_OFFSET 0ul | ||
|
||
// https://elixir.bootlin.com/linux/v6.1.1/source/arch/arm/include/asm/memory.h#L286 | ||
#define phys_to_virt(x) ((unsigned long)((x) - PHYS_OFFSET + PAGE_OFFSET)) | ||
|
||
#define KERNEL_VAS_START PAGE_OFFSET | ||
#define KERNEL_VAS_END 0xfffffffful | ||
|
||
// https://elixir.bootlin.com/linux/v6.1.1/source/arch/arm/include/asm/memory.h#L26 | ||
#define KERNEL_BASE_MIN PAGE_OFFSET | ||
#define KERNEL_BASE_MAX 0xf0000000ul | ||
|
||
// Modules are located below kernel: PAGE_OFFSET - 16MiB (0x01000000) | ||
// https://elixir.bootlin.com/linux/v6.1.1/source/arch/arm/include/asm/memory.h#L51 | ||
#define MODULES_START PAGE_OFFSET - 0x01000000 // 0xbf000000ul | ||
#define MODULES_END PAGE_OFFSET | ||
|
||
#define KERNEL_ALIGN 2 * MB | ||
|
||
// https://elixir.bootlin.com/linux/v6.1.1/source/arch/arm/Makefile#L145 | ||
#define TEXT_OFFSET 0x8000 | ||
|
||
#define KERNEL_TEXT_DEFAULT (KERNEL_BASE_MIN + TEXT_OFFSET) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// This file is part of KASLD - https://github.com/bcoles/kasld | ||
// | ||
// Definitions for ARM 64-bit (aarch64 / arm64) | ||
// | ||
// KASLR support added in commit 588ab3f9afdfa1a6b1e5761c858b2c4ab6098285 in | ||
// kernel v4.6-rc1~110 on 2016-03-17. | ||
// | ||
// References: | ||
// https://github.com/torvalds/linux/commit/588ab3f9afdfa1a6b1e5761c858b2c4ab6098285 | ||
// https://lwn.net/Articles/673598/ | ||
// https://www.kernel.org/doc/Documentation/arm64/memory.txt | ||
// https://github.com/torvalds/linux/blob/master/Documentation/arm64/booting.rst | ||
// https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/arm64/memory.rst | ||
// https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/kernel/head.S | ||
// --- | ||
// <[email protected]> | ||
|
||
// 52 va bits (CONFIG_ARM64_VA_BITS_48_52) is largest. | ||
// 48 va bits (CONFIG_ARM64_VA_BITS_48) is more common. | ||
// page_offset = (0xffffffffffffffffUL) << (va_bits - 1) | ||
// https://elixir.bootlin.com/linux/v6.1.1/source/arch/arm64/include/asm/memory.h#L45 | ||
// We assume 52 va bits: | ||
#define PAGE_OFFSET 0xfff8000000000000ul | ||
#define PHYS_OFFSET 0ul | ||
|
||
// https://elixir.bootlin.com/linux/v6.1.1/source/arch/arm64/include/asm/memory.h#L295 | ||
#define phys_to_virt(x) ((unsigned long)((x) - PHYS_OFFSET) | PAGE_OFFSET) | ||
|
||
#define KERNEL_VAS_START PAGE_OFFSET | ||
#define KERNEL_VAS_END 0xfffffffffffffffful | ||
|
||
// 48 va bits (CONFIG_ARM64_VA_BITS_48) is a common configuration; | ||
// but an unsafe assumption since introduction of CONFIG_ARM64_VA_BITS_48_52. | ||
// older kernels may use 0xffff000008000000ul | ||
#define KERNEL_BASE_MIN 0xffff800008000000ul | ||
#define KERNEL_BASE_MAX 0xffffffffff000000ul | ||
|
||
#define MODULES_START 0xffff800000000000ul | ||
#define MODULES_END 0xffff800007fffffful | ||
|
||
// MIN_KIMG_ALIGN is 2MiB (used without KASLR). | ||
// https://elixir.bootlin.com/linux/v6.2-rc2/source/arch/arm64/include/asm/boot.h#L18 | ||
// EFI_KIMG_ALIGN is the larger of THREAD_ALIGN or SEGMENT_ALIGN: | ||
// https://elixir.bootlin.com/linux/v6.2-rc2/source/arch/arm64/include/asm/efi.h#L102 | ||
// https://elixir.bootlin.com/linux/v6.2-rc2/source/arch/arm64/include/asm/efi.h#L72 | ||
// SEGMENT_ALIGN is hard-coded as 64KiB: | ||
// https://elixir.bootlin.com/linux/v6.2-rc2/source/arch/arm64/include/asm/memory.h#L131 | ||
// The largest possible THREAD_ALIGN is also 64KiB. | ||
// THREAD_ALIGN = THREAD_SIZE = (1 << THREAD_SHIFT) | ||
// default CONFIG_ARM64_PAGE_SHIFT is 12. largest is 16. | ||
// https://elixir.bootlin.com/linux/v6.2-rc2/source/arch/arm64/Kconfig#L262 | ||
// Use 64KiB (0x10000) by default | ||
#define KERNEL_ALIGN 0x10000ul | ||
|
||
// TEXT_OFFSET was changed from 0x80000 to zero in 2020 from kernel v5.8 onwards | ||
// https://elixir.bootlin.com/linux/v5.8/source/arch/arm64/Makefile | ||
// https://lore.kernel.org/all/20200428134119.GI6791@willie-the-truck/T/ | ||
#define TEXT_OFFSET 0 | ||
|
||
#define KERNEL_TEXT_DEFAULT (KERNEL_BASE_MIN + TEXT_OFFSET) |
Oops, something went wrong.