1 module mecca.platform.os.linux.ucontext; 2 3 version (linux): 4 version (X86_64) 5 package(mecca): 6 7 import core.sys.posix.ucontext; 8 9 private alias gregset_t = typeof(ucontext_t.uc_mcontext.gregs); 10 11 // Implements a platform agnostic interface to `ucontext_t`. 12 struct Ucontext 13 { 14 private ucontext_t context; 15 16 nothrow: 17 @nogc: 18 19 Mcontext uc_mcontext() return 20 { 21 return Mcontext(&context.uc_mcontext); 22 } 23 } 24 25 struct Mcontext 26 { 27 private mcontext_t* context; 28 29 nothrow: 30 @nogc: 31 32 RegisterSet registers() 33 { 34 return RegisterSet(&context.gregs); 35 } 36 } 37 38 struct RegisterSet 39 { 40 private gregset_t* gregs; 41 42 nothrow: 43 @nogc: 44 45 auto rax() 46 { 47 return (*gregs)[REG_RAX]; 48 } 49 50 auto rbx() 51 { 52 return (*gregs)[REG_RBX]; 53 } 54 55 auto rcx() 56 { 57 return (*gregs)[REG_RCX]; 58 } 59 60 auto rdx() 61 { 62 return (*gregs)[REG_RDX]; 63 } 64 65 auto rdi() 66 { 67 return (*gregs)[REG_RDI]; 68 } 69 70 auto rsi() 71 { 72 return (*gregs)[REG_RSI]; 73 } 74 75 auto rbp() 76 { 77 return (*gregs)[REG_RBP]; 78 } 79 80 auto rsp() 81 { 82 return (*gregs)[REG_RSP]; 83 } 84 85 auto r8() 86 { 87 return (*gregs)[REG_R8]; 88 } 89 90 auto r9() 91 { 92 return (*gregs)[REG_R9]; 93 } 94 95 auto r10() 96 { 97 return (*gregs)[REG_R10]; 98 } 99 100 auto r11() 101 { 102 return (*gregs)[REG_R11]; 103 } 104 105 auto r12() 106 { 107 return (*gregs)[REG_R12]; 108 } 109 110 auto r13() 111 { 112 return (*gregs)[REG_R13]; 113 } 114 115 auto r14() 116 { 117 return (*gregs)[REG_R14]; 118 } 119 120 auto r15() 121 { 122 return (*gregs)[REG_R15]; 123 } 124 125 auto rip() 126 { 127 return (*gregs)[REG_RIP]; 128 } 129 }