Skip to content

Commit 04f3226

Browse files
committed
Add errno handling to shmdt() and shmctl() on Windows
Set errno for error conditions in shmdt() and shmctl(): - EINVAL for invalid segment address/key - Windows error mapping for UnmapViewOfFile failures - EINVAL for unknown shmctl commands This completes errno handling for all shmop system calls on Windows.
1 parent 516e543 commit 04f3226

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

TSRM/tsrm_win32.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,7 @@ TSRM_API int shmdt(const void *shmaddr)
780780
int ret;
781781

782782
if (!shm || !shm->segment) {
783+
errno = EINVAL;
783784
return -1;
784785
}
785786

@@ -789,7 +790,10 @@ TSRM_API int shmdt(const void *shmaddr)
789790

790791
ret = 0;
791792
if (shm->descriptor->shm_nattch <= 0) {
792-
ret = UnmapViewOfFile(shm->descriptor) ? 0 : -1;
793+
if (!UnmapViewOfFile(shm->descriptor)) {
794+
tsrm_set_errno_from_win32_error(GetLastError());
795+
ret = -1;
796+
}
793797
shm->descriptor = NULL;
794798
}
795799
return ret;
@@ -800,6 +804,7 @@ TSRM_API int shmctl(int key, int cmd, struct shmid_ds *buf)
800804
shm_pair *shm = shm_get(key, NULL);
801805

802806
if (!shm || !shm->segment) {
807+
errno = EINVAL;
803808
return -1;
804809
}
805810

@@ -822,6 +827,7 @@ TSRM_API int shmctl(int key, int cmd, struct shmid_ds *buf)
822827
return 0;
823828

824829
default:
830+
errno = EINVAL;
825831
return -1;
826832
}
827833
}/*}}}*/

0 commit comments

Comments
 (0)