March 2, 2024
3:49 a.m.
Jinoh Kang (@iamahuman) commented about server/mapping.c:
> + unsigned int capacity;
> + mem_size_t size;
> + int unix_fd;
> + void *tmp;
> +
> + capacity = session.object_capacity * 3 / 2;
> + size = offsetof(session_shm_t, objects[capacity]);
> + size = (size + page_mask) & ~((mem_size_t)page_mask);
> +
> + unix_fd = get_unix_fd( session_mapping->fd );
> + if (!grow_file( unix_fd, size )) return -1;
> + session_mapping->size = size;
> +
> + if ((tmp = mmap( NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, unix_fd, 0 )) == MAP_FAILED) return -1;
> + munmap( (void *)session.shared, session.shared->size );
> + session.shared = tmp;
1. Ensure `session_mapping->size == session.shared.size` at all times, since we rely on it in the `map_shared_session_section` loop.
- Note that we don't have to ensure `backing_file[st_size] == session_mapping->size`. It's normal for a section to only have a portion of the backing file.
2. Consistently use `mapping->size` as we've done in `create_session_mapping`.
```suggestion:-4+0
if ((tmp = mmap( NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, unix_fd, 0 )) == MAP_FAILED) return -1;
munmap( (void *)session.shared, session_mapping->size );
session.shared = tmp;
session_mapping->size = size;
```
--
https://gitlab.winehq.org/wine/wine/-/merge_requests/3103#note_63266