aboutsummaryrefslogtreecommitdiffhomepage
path: root/sample/memfd.cpp
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <[email protected]>2022-03-08 10:27:11 +0900
committerMITSUNARI Shigeo <[email protected]>2022-03-08 10:27:11 +0900
commit2861517f2598adbefb54bc6d1b5d500a17945b65 (patch)
tree6312ef6c9db36b987014e9ece539451a8f3623b6 /sample/memfd.cpp
parent507b0285ee4c5ea9fdc36ff98aef65308f6ce4d6 (diff)
downloadxbyak-2861517f2598adbefb54bc6d1b5d500a17945b65.tar.gz
xbyak-2861517f2598adbefb54bc6d1b5d500a17945b65.zip
add memfd sample
Diffstat (limited to 'sample/memfd.cpp')
-rw-r--r--sample/memfd.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/sample/memfd.cpp b/sample/memfd.cpp
new file mode 100644
index 0000000..c29272b
--- /dev/null
+++ b/sample/memfd.cpp
@@ -0,0 +1,31 @@
+/*
+ cat /proc/`psidof ./memfd`/maps
+
+7fca70b44000-7fca70b4a000 rw-p 00000000 00:00 0
+7fca70b67000-7fca70b68000 rwxs 00000000 00:05 19960170 /memfd:xyz (deleted)
+7fca70b68000-7fca70b69000 rwxs 00000000 00:05 19960169 /memfd:abc (deleted)
+7fca70b69000-7fca70b6a000 r--p 00029000 103:03 19136541 /lib/x86_64-linux-gnu/ld-2.27.so
+7fca70b6a000-7fca70b6b000 rw-p 0002a000 103:03 19136541 /lib/x86_64-linux-gnu/ld-2.27.so
+*/
+#define XBYAK_USE_MEMFD
+#include <xbyak/xbyak.h>
+
+class Code : Xbyak::MmapAllocator, public Xbyak::CodeGenerator {
+public:
+ Code(const char *name, int v)
+ : Xbyak::MmapAllocator(name)
+ , Xbyak::CodeGenerator(4096, nullptr, this /* specify external MmapAllocator */)
+ {
+ mov(eax, v);
+ ret();
+ }
+};
+
+int main()
+{
+ Code c1("abc", 123);
+ Code c2("xyz", 456);
+ printf("c1 %d\n", c1.getCode<int (*)()>()());
+ printf("c2 %d\n", c2.getCode<int (*)()>()());
+ getchar();
+}