diff --git a/arch/x64/arch.hh b/arch/x64/arch.hh
index 5eab78f2f1f1294d12116d2d8fbcd7e0988c60fc..7185ddabf074d82f90df630ed014cf2069eb59a5 100644
--- a/arch/x64/arch.hh
+++ b/arch/x64/arch.hh
@@ -18,6 +18,20 @@ inline void irq_enable()
     processor::sti();
 }
 
+class irq_flag {
+public:
+    // need to clear the red zone when playing with the stack. also, can't
+    // use "m" constraint as it might be addressed relative to %rsp
+    void save() {
+        asm volatile("sub $128, %%rsp; pushfq; popq %0; add $128, %%rsp" : "=r"(_rflags));
+    }
+    void restore() {
+        asm volatile("sub $128, %%rsp; pushq %0; popfq; add $128, %%rsp" : : "r"(_rflags));
+    }
+private:
+    unsigned long _rflags;
+};
+
 }