Revert "shm: remove size hack"

This reverts commit 662b23be80.
This commit is contained in:
DH 2024-10-22 22:36:17 +03:00
parent 1fbb7c2edf
commit 418780eb25
3 changed files with 12 additions and 7 deletions

View file

@ -30,6 +30,7 @@
struct HostFile : orbis::File {
bool closeOnExit = true;
bool alignTruncate = false;
~HostFile() {
if (hostFd > 0 && closeOnExit) {
@ -437,10 +438,12 @@ static orbis::ErrorCode host_truncate(orbis::File *file, std::uint64_t len,
return orbis::ErrorCode::ISDIR;
}
if (hostFile->alignTruncate) {
len = rx::alignUp(len, vm::kPageSize);
}
if (::ftruncate(hostFile->hostFd, len)) {
auto result = convertErrno();
ORBIS_LOG_ERROR("host_truncate", hostFile->hostFd, len);
return result;
return convertErrno();
}
return {};
@ -934,11 +937,13 @@ orbis::ErrorCode HostFsDevice::rename(const char *from, const char *to,
return convertErrorCode(ec);
}
orbis::File *createHostFile(int hostFd, orbis::Ref<IoDevice> device) {
orbis::File *createHostFile(int hostFd, orbis::Ref<IoDevice> device,
bool alignTruncate) {
auto newFile = orbis::knew<HostFile>();
newFile->hostFd = hostFd;
newFile->ops = &hostOps;
newFile->device = std::move(device);
newFile->device = device;
newFile->alignTruncate = alignTruncate;
return newFile;
}

View file

@ -74,5 +74,5 @@ IoDevice *createHostIoDevice(orbis::kstring hostPath, orbis::kstring virtualPath
orbis::Ref<orbis::File> wrapSocket(int hostFd, orbis::kstring name, int dom, int type, int prot);
orbis::ErrorCode createSocket(orbis::Ref<orbis::File> *file,
orbis::kstring name, int dom, int type, int prot);
orbis::File *createHostFile(int hostFd, orbis::Ref<IoDevice> device);
orbis::File *createHostFile(int hostFd, orbis::Ref<IoDevice> device, bool alignTruncate = false);
IoDevice *createFdWrapDevice(int fd);

View file

@ -35,7 +35,7 @@ orbis::ErrorCode ShmDevice::open(orbis::Ref<orbis::File> *file,
return convertErrno();
}
auto hostFile = createHostFile(fd, this);
auto hostFile = createHostFile(fd, this, true);
*file = hostFile;
return {};
}