From 7f1c6e13b525aec7775dc1d994cdc4ebe2c95b62 Mon Sep 17 00:00:00 2001 From: Max Qian <64824374+AstroAir@users.noreply.github.com> Date: Mon, 14 Aug 2023 11:51:41 +0000 Subject: [PATCH] Fix error in Linux --- libs/indicore/sharedblob.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/libs/indicore/sharedblob.c b/libs/indicore/sharedblob.c index 52bd43c29a..91d999e088 100644 --- a/libs/indicore/sharedblob.c +++ b/libs/indicore/sharedblob.c @@ -93,33 +93,20 @@ void* IDSharedBlobAlloc(size_t size) { sb->hMapObject = CreateFileMapping(INVALID_HANDLE_VALUE, &sa, PAGE_READWRITE, 0, sb->allocated, NULL); if (sb->hMapObject == NULL) { - // 错误处理逻辑 goto ERROR_LABEL; } sb->mapstart = MapViewOfFile(sb->hMapObject, FILE_MAP_ALL_ACCESS, 0, 0, sb->allocated); if (sb->mapstart == NULL) { - // 错误处理逻辑 goto ERROR_LABEL; } #else - sb->fd = shm_open("/mysharedmem", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); - if (sb->fd == -1) { - // 错误处理逻辑 - goto ERROR_LABEL; - } - int ret = ftruncate(sb->fd, sb->allocated); - if (ret == -1) { - // 错误处理逻辑 - goto ERROR_LABEL; - } + if (ret == -1) goto ERROR_LABEL; - sb->mapstart = mmap(NULL, sb->allocated, PROT_READ | PROT_WRITE, MAP_SHARED, sb->fd, 0); - if (sb->mapstart == MAP_FAILED) { - // 错误处理逻辑 - goto ERROR_LABEL; - } + // FIXME: try to map far more than sb->allocated, to allow efficient mremap + sb->mapstart = mmap(0, sb->allocated, PROT_READ | PROT_WRITE, MAP_SHARED, sb->fd, 0); + if (sb->mapstart == MAP_FAILED) goto ERROR_LABEL; #endif sharedBufferAdd(sb);