diff options
author | MITSUNARI Shigeo <[email protected]> | 2022-03-08 10:27:11 +0900 |
---|---|---|
committer | MITSUNARI Shigeo <[email protected]> | 2022-03-08 10:27:11 +0900 |
commit | 2861517f2598adbefb54bc6d1b5d500a17945b65 (patch) | |
tree | 6312ef6c9db36b987014e9ece539451a8f3623b6 /sample | |
parent | 507b0285ee4c5ea9fdc36ff98aef65308f6ce4d6 (diff) | |
download | xbyak-2861517f2598adbefb54bc6d1b5d500a17945b65.tar.gz xbyak-2861517f2598adbefb54bc6d1b5d500a17945b65.zip |
add memfd sample
Diffstat (limited to 'sample')
-rw-r--r-- | sample/Makefile | 4 | ||||
-rw-r--r-- | sample/memfd.cpp | 31 |
2 files changed, 35 insertions, 0 deletions
diff --git a/sample/Makefile b/sample/Makefile index 5d8f8da..7c910bb 100644 --- a/sample/Makefile +++ b/sample/Makefile @@ -37,6 +37,7 @@ endif ifneq ($(OS),mac) TARGET += static_buf64 +TARGET += memfd endif @@ -95,6 +96,8 @@ jmp_table: $(CXX) $(CFLAGS) jmp_table.cpp -o $@ -m32 jmp_table64: $(CXX) $(CFLAGS) jmp_table.cpp -o $@ -m64 +memfd: + $(CXX) $(CFLAGS) memfd.cpp -o $@ -m64 profiler: profiler.cpp ../xbyak/xbyak_util.h $(CXX) $(CFLAGS) profiler.cpp -o $@ profiler-vtune: profiler.cpp ../xbyak/xbyak_util.h @@ -121,3 +124,4 @@ test_util : test_util.cpp $(XBYAK_INC) ../xbyak/xbyak_util.h test_util2 : test_util.cpp $(XBYAK_INC) ../xbyak/xbyak_util.h jmp_table: jmp_table.cpp $(XBYAK_INC) jmp_table64: jmp_table.cpp $(XBYAK_INC) +memfd: memfd.cpp $(XBYAK_INC) 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(); +} |