added safe_length option for portability and clarity

This commit is contained in:
w1redch4d
2025-04-10 19:44:54 +05:30
parent 3c8016e071
commit b9c1536283

View File

@ -30,8 +30,9 @@ int shmctl(int __shmid, int __cmd, struct shmid_ds *__buf) {
int ret = 0;
if (__cmd == IPC_RMID) {
unsigned int length = ioctl(__shmid, ASHMEM_GET_SIZE, NULL);
struct ashmem_pin pin = {0, length};
int length = ioctl(__shmid, ASHMEM_GET_SIZE, NULL);
unsigned int safe_length = length >= 0 ? length : 0;
struct ashmem_pin pin = {0, safe_length};
ret = ioctl(__shmid, ASHMEM_UNPIN, &pin);
close(__shmid);