diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2022-07-03 00:07:14 +0200 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2022-07-03 00:07:14 +0200 |
| commit | 53365241294de8eae2da2edfb6b47f04b02f5808 (patch) | |
| tree | 84207aa9154910518978b28ac0e3f28b72219e27 /src/custommem.c | |
| parent | de30d37ba91b093d459365a93ea9cc4418fc502a (diff) | |
| download | box64-53365241294de8eae2da2edfb6b47f04b02f5808.tar.gz box64-53365241294de8eae2da2edfb6b47f04b02f5808.zip | |
[DYNAREC] Add a mecanism to remember fixed address accessed with LOCK, so MOV to/from them use a Memory Barrier automaticaly
Diffstat (limited to '')
| -rw-r--r-- | src/custommem.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/custommem.c b/src/custommem.c index 186543fb..691771ec 100644 --- a/src/custommem.c +++ b/src/custommem.c @@ -40,6 +40,9 @@ static uintptr_t*** box64_jmptbl3[1<<JMPTABL_SHIFT]; static uintptr_t** box64_jmptbldefault2[1<<JMPTABL_SHIFT]; static uintptr_t* box64_jmptbldefault1[1<<JMPTABL_SHIFT]; static uintptr_t box64_jmptbldefault0[1<<JMPTABL_SHIFT]; +// lock addresses +KHASH_SET_INIT_INT64(lockaddress) +static kh_lockaddress_t *lockaddress = NULL; #endif static pthread_mutex_t mutex_prot; #if defined(PAGE64K) @@ -1237,6 +1240,7 @@ void init_custommem_helper(box64context_t* ctx) box64_jmptbldefault2[i] = box64_jmptbldefault1; box64_jmptbl3[i] = box64_jmptbldefault2; } + lockaddress = kh_init(lockaddress); #endif pthread_atfork(NULL, NULL, atfork_child_custommem); // init mapmem list @@ -1309,6 +1313,8 @@ void fini_custommem_helper(box64context_t *ctx) free(box64_jmptbl3[i3]); } } + kh_destroy(lockaddress, lockaddress); + lockaddress = NULL; #endif uint8_t* m; for(int i=0; i<(1<<20); ++i) { @@ -1332,3 +1338,20 @@ void fini_custommem_helper(box64context_t *ctx) free(tmp); } } + +#ifdef DYNAREC +// add an address to the list of "LOCK"able +void addLockAddress(uintptr_t addr) +{ + int ret; + kh_put(lockaddress, lockaddress, addr, &ret); +} + +// return 1 is the address is used as a LOCK, 0 else +int isLockAddress(uintptr_t addr) +{ + khint_t k = kh_get(lockaddress, lockaddress, addr); + return (k==kh_end(lockaddress))?0:1; +} + +#endif |