File: mprotect_test.cpp

package info (click to toggle)
xbyak 7.24.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,068 kB
  • sloc: cpp: 21,493; ansic: 2,981; python: 372; makefile: 306; sh: 204
file content (37 lines) | stat: -rw-r--r-- 652 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#define XBYAK_NO_OP_NAMES
#include "xbyak/xbyak.h"
#include <string.h>
#include <vector>

struct Code : Xbyak::CodeGenerator {
	Code(int x)
	{
		mov(eax, x);
		ret();
	}
};

int main()
	try
{
#ifdef XBYAK_USE_MMAP_ALLOCATOR
	puts("use Allocator with mmap");
#else
	puts("use Allocator with posix_memalign");
#endif
	const int N = 70000;
	std::vector<Code*> v(N);
	for (int i = 0; i < N; i++) {
		v[i] = new Code(i);
	}
	long long sum = 0;
	for (int i = 0; i < N; i++) {
		sum += v[i]->getCode<int (*)()>()();
	}
	for (int i = 0; i < N; i++) {
		delete v[i];
	}
	printf("sum=%lld\n", sum);
} catch (std::exception& e) {
	printf("ERR %s\n", e.what());
}