-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
242 additions
and
57 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
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,17 @@ | ||
#pragma once | ||
#include <define.h> | ||
|
||
#define asm_rdmsr(msr, lo, hi) asm volatile("rdmsr\n\t" : "=a"(lo), "=d"(hi) : "c"(msr)::"memory") | ||
#define asm_wrmsr(msr, lo, hi) asm volatile("wrmsr\n\t" ::"a"(lo), "d"(hi), "c"(msr) : "memory") | ||
|
||
//+注意 IA32_SYSENTER_CS 的约定: | ||
// Ring 0 的代码段 CS0 | ||
// Ring 0 的数据段 DS0 = CS0 + 8 | ||
// Ring 3 的代码段 CS3 = CS0 + 16 | ||
// Ring 3 的数据段 DS3 = CS0 + 24 | ||
// 如果有 REX.W 前缀则: | ||
// CS3 = CS0 + 32 | ||
// DS3 = CS0 + 40 | ||
#define IA32_SYSENTER_CS 0x174 | ||
#define IA32_SYSENTER_ESP 0x175 | ||
#define IA32_SYSENTER_EIP 0x176 |
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,121 @@ | ||
|
||
#define __syscall0(id) \ | ||
({ \ | ||
__INTPTR_TYPE__ rets; \ | ||
asm volatile("mov %%esp, %%ecx\n\t" \ | ||
"lea 1f, %%edx\n\t" \ | ||
"sysenter\n\t" \ | ||
"1:\n\t" \ | ||
: "=a"(rets) \ | ||
: "0"(id) \ | ||
: "memory", "cc", "ecx", "edx"); \ | ||
rets; \ | ||
}) | ||
|
||
#define __syscall1(id, arg1) \ | ||
({ \ | ||
__INTPTR_TYPE__ rets; \ | ||
__INTPTR_TYPE__ __arg1 = (__INTPTR_TYPE__)(arg1); \ | ||
register __INTPTR_TYPE__ _a1 asm("ebx") = __arg1; \ | ||
asm volatile("mov %%esp, %%ecx\n\t" \ | ||
"lea 1f, %%edx\n\t" \ | ||
"sysenter\n\t" \ | ||
"1:\n\t" \ | ||
: "=a"(rets) \ | ||
: "0"(id), "r"(_a1) \ | ||
: "memory", "cc", "ecx", "edx"); \ | ||
rets; \ | ||
}) | ||
|
||
#define __syscall2(id, arg1, arg2) \ | ||
({ \ | ||
__INTPTR_TYPE__ rets; \ | ||
__INTPTR_TYPE__ __arg1 = (__INTPTR_TYPE__)(arg1); \ | ||
__INTPTR_TYPE__ __arg2 = (__INTPTR_TYPE__)(arg2); \ | ||
register __INTPTR_TYPE__ _a2 asm("esi") = __arg2; \ | ||
register __INTPTR_TYPE__ _a1 asm("ebx") = __arg1; \ | ||
asm volatile("mov %%esp, %%ecx\n\t" \ | ||
"lea 1f, %%edx\n\t" \ | ||
"sysenter\n\t" \ | ||
"1:\n\t" \ | ||
: "=a"(rets) \ | ||
: "0"(id), "r"(_a1), "r"(_a2) \ | ||
: "memory", "cc", "ecx", "edx"); \ | ||
rets; \ | ||
}) | ||
|
||
#define __syscall3(id, arg1, arg2, arg3) \ | ||
({ \ | ||
__INTPTR_TYPE__ rets; \ | ||
__INTPTR_TYPE__ __arg1 = (__INTPTR_TYPE__)(arg1); \ | ||
__INTPTR_TYPE__ __arg2 = (__INTPTR_TYPE__)(arg2); \ | ||
__INTPTR_TYPE__ __arg3 = (__INTPTR_TYPE__)(arg3); \ | ||
register __INTPTR_TYPE__ _a3 asm("edi") = __arg3; \ | ||
register __INTPTR_TYPE__ _a2 asm("esi") = __arg2; \ | ||
register __INTPTR_TYPE__ _a1 asm("ebx") = __arg1; \ | ||
asm volatile("mov %%esp, %%ecx\n\t" \ | ||
"lea 1f, %%edx\n\t" \ | ||
"sysenter\n\t" \ | ||
"1:\n\t" \ | ||
: "=a"(rets) \ | ||
: "0"(id), "r"(_a1), "r"(_a2), "r"(_a3) \ | ||
: "memory", "cc", "ecx", "edx"); \ | ||
rets; \ | ||
}) | ||
|
||
#define __syscall4(id, arg1, arg2, arg3, arg4) \ | ||
({ \ | ||
__INTPTR_TYPE__ rets; \ | ||
__INTPTR_TYPE__ __arg1 = (__INTPTR_TYPE__)(arg1); \ | ||
__INTPTR_TYPE__ __arg2 = (__INTPTR_TYPE__)(arg2); \ | ||
__INTPTR_TYPE__ __arg3 = (__INTPTR_TYPE__)(arg3); \ | ||
__INTPTR_TYPE__ __arg4 = (__INTPTR_TYPE__)(arg4); \ | ||
register __INTPTR_TYPE__ _a4 asm("ecx") = __arg4; \ | ||
register __INTPTR_TYPE__ _a3 asm("edi") = __arg3; \ | ||
register __INTPTR_TYPE__ _a2 asm("esi") = __arg2; \ | ||
register __INTPTR_TYPE__ _a1 asm("ebx") = __arg1; \ | ||
asm volatile("push %%ecx\n\t" \ | ||
"mov %%esp, %%ecx\n\t" \ | ||
"lea 1f, %%edx\n\t" \ | ||
"sysenter\n\t" \ | ||
"1:\n\t" \ | ||
"pop %%ecx\n\t" \ | ||
: "=a"(rets) \ | ||
: "0"(id), "r"(_a1), "r"(_a2), "r"(_a3), "r"(_a4) \ | ||
: "memory", "cc", "edx"); \ | ||
rets; \ | ||
}) | ||
|
||
#define __syscall5(id, arg1, arg2, arg3, arg4, arg5) \ | ||
({ \ | ||
__INTPTR_TYPE__ rets; \ | ||
__INTPTR_TYPE__ __arg1 = (__INTPTR_TYPE__)(arg1); \ | ||
__INTPTR_TYPE__ __arg2 = (__INTPTR_TYPE__)(arg2); \ | ||
__INTPTR_TYPE__ __arg3 = (__INTPTR_TYPE__)(arg3); \ | ||
__INTPTR_TYPE__ __arg4 = (__INTPTR_TYPE__)(arg4); \ | ||
__INTPTR_TYPE__ __arg5 = (__INTPTR_TYPE__)(arg5); \ | ||
register __INTPTR_TYPE__ _a5 asm("edx") = __arg5; \ | ||
register __INTPTR_TYPE__ _a4 asm("ecx") = __arg4; \ | ||
register __INTPTR_TYPE__ _a3 asm("edi") = __arg3; \ | ||
register __INTPTR_TYPE__ _a2 asm("esi") = __arg2; \ | ||
register __INTPTR_TYPE__ _a1 asm("ebx") = __arg1; \ | ||
asm volatile("push %%edx\n\t" \ | ||
"push %%ecx\n\t" \ | ||
"mov %%esp, %%ecx\n\t" \ | ||
"lea 1f, %%edx\n\t" \ | ||
"sysenter\n\t" \ | ||
"1:\n\t" \ | ||
"pop %%ecx\n\t" \ | ||
"pop %%edx\n\t" \ | ||
: "=a"(rets) \ | ||
: "0"(id), "r"(_a1), "r"(_a2), "r"(_a3), "r"(_a4), "r"(_a5) \ | ||
: "memory", "cc"); \ | ||
rets; \ | ||
}) | ||
|
||
#define __syscall_concat_x(a, b) a##b | ||
#define __syscall_concat(a, b) __syscall_concat_x(a, b) | ||
#define __syscall_argn_private(_0, _1, _2, _3, _4, _5, n, ...) n | ||
#define __syscall_argn(...) __syscall_argn_private(0, ##__VA_ARGS__, 5, 4, 3, 2, 1, 0) | ||
#define __syscall(id, ...) \ | ||
__syscall_concat(__syscall, __syscall_argn(__VA_ARGS__))(id, ##__VA_ARGS__) |
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
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
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
Oops, something went wrong.