Skip to content

Commit

Permalink
Fix division and multiplication of page segments
Browse files Browse the repository at this point in the history
  • Loading branch information
kriszyp committed Feb 26, 2024
1 parent 5f00403 commit 4a86d2d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "lmdb",
"author": "Kris Zyp",
"version": "3.0.0-beta.7-debug1",
"version": "3.0.0-beta.7-debug2",
"description": "Simple, efficient, scalable, high-performance LMDB interface",
"license": "MIT",
"repository": {
Expand Down
7 changes: 3 additions & 4 deletions src/env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,9 +624,8 @@ int32_t EnvWrap::toSharedBuffer(MDB_env* env, uint32_t* keyBuffer, MDB_val data
if (dataAddress > mapAddress && (dataAddress + data.mv_size) <= (mapAddress + stat.me_mapsize)) {
// an address within the memory map
int64_t mapOffset = dataAddress - mapAddress;
size_t bufferPosition = (mapOffset + (mapOffset >> 4)) >> 32;
bufferStart = bufferPosition << 32;
bufferStart += mapAddress - (bufferStart >> 4);
size_t bufferPosition = mapOffset / 0xf0000000ll; // we don't use the full 4GB because we want to have overlap so records avoid crossing boundaries
bufferStart = bufferPosition * 0xf0000000ll + mapAddress;
end = bufferStart + 0xffffffffll;
if (end > mapAddress + stat.me_mapsize)
end = mapAddress + stat.me_mapsize;
Expand All @@ -641,7 +640,7 @@ int32_t EnvWrap::toSharedBuffer(MDB_env* env, uint32_t* keyBuffer, MDB_val data
if ((dataAddress + data.mv_size) > end) {
int64_t mapOffset = dataAddress - mapAddress;
size_t bufferPosition = (mapOffset + (mapOffset >> 4)) >> 32;
fprintf(stderr, "Shared address crosses boundaries, dataAddress: %p, data start: %p, data end: %p, buffer end: %p, mapAddress %p, mapOffset %p, bufferPosition %p, \n", dataAddress, dataAddress + data.mv_size, bufferStart, end, mapAddress, mapOffset, bufferPosition);
fprintf(stderr, "Shared address crosses boundaries, dataAddress: %p, data end: %p, buffer start: %p, buffer end: %p, mapAddress %p, mapOffset %p, bufferPosition %p, \n", dataAddress, dataAddress + data.mv_size, bufferStart, end, mapAddress, mapOffset, bufferPosition);
// crosses boundaries, create one-off for this address
bufferStart = dataAddress;
end = bufferStart + 0xffffffffll;
Expand Down

0 comments on commit 4a86d2d

Please sign in to comment.