Changeset 1986
- Timestamp:
- May 9, 2005, 7:02:45 AM (20 years ago)
- Location:
- trunk/src/emx
- Files:
-
- 6 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/emx/ChangeLog.LIBC
-
Property cvs2svn:cvs-rev
changed from
1.45
to1.46
r1985 r1986 7 7 o Added a signal notification callback to the thread structure. 8 8 o Changed tcpip term callback to more generic exitlist callback (SPM). 9 o Ported the BSD SysV Shared Memory module. 9 10 10 11 2005-05-05: knut st. osmundsen <bird-gccos2-spam@anduin.net> -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/include/InnoTekLIBC/backend.h
-
Property cvs2svn:cvs-rev
changed from
1.23
to1.24
r1985 r1986 894 894 /** @defgroup grp_Back_sysvipc LIBC Backend - SysV IPC 895 895 * @{ */ 896 897 /** 898 * sysget syscall. 899 */ 900 int __libc_Back_sysvSemGet(key_t key, int nsems, int semflg); 901 902 /** 903 * semop syscall. 904 */ 905 int __libc_Back_sysvSemOp(int semid, struct sembuf *sops_user, size_t nsops); 906 896 907 /** 897 908 * semctl syscall … … 899 910 int __libc_Back_sysvSemCtl(int semid, int semnum, int cmd, union semun real_arg); 900 911 901 /** 902 * sysget syscall. 903 */ 904 int __libc_Back_sysvSemGet(key_t key, int nsems, int semflg); 905 906 /** 907 * semop syscall. 908 */ 909 int __libc_Back_sysvSemOp(int semid, struct sembuf *sops_user, size_t nsops); 912 913 /** 914 * shmget. 915 */ 916 int __libc_Back_sysvShmGet(key_t key, size_t size, int shmflg); 917 918 /** 919 * shmat. 920 */ 921 int __libc_Back_sysvShmAt(int shmid, const void *shmaddr, int shmflg, void **ppvActual); 922 923 /** 924 * shmdt. 925 */ 926 int __libc_Back_sysvShmDt(const void *shmaddr); 927 928 /** 929 * shmctl. 930 */ 931 int __libc_Back_sysvShmCtl(int shmid, int cmd, struct shmid_ds *bufptr); 932 933 /** @} */ 934 935 936 /** @defgroup grp_Back_safesem LIBC Backend - Internal Signal-Safe Semaphores. 937 * @{ */ 938 939 /** 940 * Creates a safe mutex sem. 941 * 942 * @returns 0 on success. 943 * @returns Negative error code (errno.h) on failure. 944 * @param phmtx Where to store the semaphore handle. 945 * @param fShared Set if the semaphore should be sharable between processes. 946 */ 947 int __libc_Back_safesemMtxCreate(uintptr_t *phmtx, int fShared); 948 949 /** 950 * Opens a shared safe mutex sem. 951 * 952 * @returns 0 on success. 953 * @returns Negative error code (errno.h) on failure. 954 * @param hmtx The semaphore handle. 955 */ 956 int __libc_Back_safesemMtxOpen(uintptr_t hmtx); 957 958 /** 959 * Closes a shared safe mutex sem. 960 * 961 * @returns 0 on success. 962 * @returns Negative error code (errno.h) on failure. 963 * @param hmtx The semaphore handle. 964 */ 965 int __libc_Back_safesemMtxClose(uintptr_t hmtx); 966 967 /** 968 * Locks a mutex semaphore. 969 * 970 * @returns 0 on success. 971 * @returns Negative errno on failure. 972 * @param hmtx Handle to the mutex. 973 */ 974 int __libc_Back_safesemMtxLock(uintptr_t hmtx); 975 976 /** 977 * Unlocks a mutex semaphore. 978 * 979 * @returns 0 on success. 980 * @returns Negative errno on failure. 981 * @param hmtx Handle to the mutex. 982 */ 983 int __libc_Back_safesemMtxUnlock(uintptr_t hmtx); 984 985 /** 986 * Creates a safe event sem. 987 * 988 * @returns 0 on success. 989 * @returns Negative error code (errno.h) on failure. 990 * @param phev Where to store the semaphore handle. 991 * @param fShared Set if the semaphore should be sharable between processes. 992 */ 993 int __libc_Back_safesemEvCreate(uintptr_t *phev, int fShared); 994 995 /** 996 * Opens a shared safe event sem. 997 * 998 * @returns 0 on success. 999 * @returns Negative error code (errno.h) on failure. 1000 * @param hev The semaphore handle. 1001 */ 1002 int __libc_Back_safesemEvOpen(uintptr_t hev); 1003 1004 /** 1005 * Closes a shared safe mutex sem. 1006 * 1007 * @returns 0 on success. 1008 * @returns Negative error code (errno.h) on failure. 1009 * @param hev The semaphore handle. 1010 */ 1011 int __libc_Back_safesemEvClose(uintptr_t hev); 1012 1013 /** 1014 * Sleep on a semaphore. 1015 * 1016 * This is the most difficult thing we're doing in this file. 1017 * 1018 * @returns 0 on success. 1019 * @returns Negative error code (errno.h) on failure. 1020 * 1021 * @param hev The semaphore to sleep on. 1022 * @param hmtx The semaphore protecting hev and which is to be unlocked while 1023 * sleeping and reaquired upon waking up. 1024 * @param pfnComplete Function to execute on signal and on wait completion. 1025 * @param pvUser User argument to pfnComplete. 1026 */ 1027 int __libc_Back_safesemEvSleep(uintptr_t hev, uintptr_t hmtx, void (*pfnComplete)(void *pvUser), void *pvUser); 1028 1029 /** 1030 * Wakes up all threads sleeping on a given event semaphore. 1031 * 1032 * @returns 0 on success. 1033 * @returns Negative error code (errno.h) on failure. 1034 * @param hev Event semaphore to post. 1035 */ 1036 int __libc_Back_safesemEvWakeup(uintptr_t hev); 1037 910 1038 911 1039 /** @} */ -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/include/InnoTekLIBC/logstrict.h
-
Property cvs2svn:cvs-rev
changed from
1.12
to1.13
r1985 r1986 184 184 #define __LIBC_LOG_GRP_MMAN 16 185 185 186 /** Backend SysV IPC APIs. */ 187 #define __LIBC_LOG_GRP_BACK_IPC 17 186 188 /** Backend Thread APIs. */ 187 189 #define __LIBC_LOG_GRP_BACK_THREAD 18 -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/include/InnoTekLIBC/sharedpm.h
-
Property cvs2svn:cvs-rev
changed from
1.22
to1.23
r1985 r1986 557 557 /** 116 - Pointer to SysV Sempahore globals. */ 558 558 struct __libc_SysV_Sem *pSysVSem; 559 560 /* 120 - The rest of the block, up to cbProcess, is undefined in this version. 559 /** 120 - Pointer to SysV Shared Memory globals. */ 560 struct __libc_SysV_Shm *pSysVShm; 561 /** 124 - Pointer to SysV Message Queue globals. */ 562 struct __libc_SysV_Msg *pSysVMsg; 563 564 /* 128 - The rest of the block, up to cbProcess, is undefined in this version. 561 565 * Future versions of LIBC may use this area assuming it's initalized with zeros. 562 566 */ -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/include/sys/shm.h
-
Property cvs2svn:cvs-rev
changed from
1.2
to1.3
r1985 r1986 39 39 /** @file 40 40 * FreeBSD 5.3 41 * @changed the SHMLBA to 64KB. 41 42 */ 42 43 … … 48 49 #define SHM_RDONLY 010000 /* Attach read-only (else read-write) */ 49 50 #define SHM_RND 020000 /* Round attach address to SHMLBA */ 50 #define SHMLBA PAGE_SIZE/* Segment low boundary address multiple */51 #define SHMLBA (0x10000) /* Segment low boundary address multiple */ 51 52 52 53 /* "official" access mode definitions; somewhat braindead since you have … … 63 64 #define SHM_INFO 14 64 65 66 #ifdef __EMX__ 67 typedef __uint32_t shmatt_t; 68 #endif 69 65 70 struct shmid_ds { 66 71 struct ipc_perm shm_perm; /* operation permission structure */ 72 #ifdef __EMX__ 73 size_t shm_segsz; /* size of segment in bytes */ 74 #else 67 75 int shm_segsz; /* size of segment in bytes */ 76 #endif 68 77 pid_t shm_lpid; /* process ID of last shared memory op */ 69 78 pid_t shm_cpid; /* process ID of creator */ 70 short shm_nattch; /* number of current attaches */ 79 #ifdef __EMX__ 80 shmatt_t shm_nattch; /* number of current attaches */ 81 #else 82 short shm_nattch; /* number of current attaches */ 83 #endif 71 84 time_t shm_atime; /* time of last shmat() */ 72 85 time_t shm_dtime; /* time of last shmdt() */ … … 88 101 shmall; /* max amount of shared memory (pages) */ 89 102 }; 103 #ifndef __EMX__ 90 104 extern struct shminfo shminfo; 91 105 extern struct shmid_ds *shmsegs; 106 #endif 92 107 93 108 struct shm_info { … … 100 115 }; 101 116 117 #ifndef __EMX__ 102 118 struct thread; 103 119 struct proc; … … 106 122 void shmexit(struct vmspace *); 107 123 void shmfork(struct proc *, struct proc *); 124 #endif /* !__EMX__ */ 108 125 #else /* !_KERNEL */ 109 126 … … 116 133 117 134 __BEGIN_DECLS 135 #ifndef __EMX__ 118 136 int shmsys(int, ...); 137 #endif 119 138 void *shmat(int, const void *, int); 120 139 int shmget(key_t, size_t, int); -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/libc.def
-
Property cvs2svn:cvs-rev
changed from
1.111
to1.112
r1985 r1986 1529 1529 "__getenv_long" @1534 1530 1530 "__getenv_longlong" @1535 1531 "___libc_Back_sysvSemCtl" @1536 1532 "___libc_Back_sysvSemGet" @1537 1533 "___libc_Back_sysvSemOp" @1538 1534 "__std_ftok" @1539 1535 "__std_semctl" @1540 1536 "__std_semget" @1541 1537 "__std_semop" @1542 1531 "___libc_Back_safesemEvClose" @1536 1532 "___libc_Back_safesemEvCreate" @1537 1533 "___libc_Back_safesemEvOpen" @1538 1534 "___libc_Back_safesemEvSleep" @1539 1535 "___libc_Back_safesemEvWakeup" @1540 1536 "___libc_Back_safesemMtxClose" @1541 1537 "___libc_Back_safesemMtxCreate" @1542 1538 "___libc_Back_safesemMtxLock" @1543 1539 "___libc_Back_safesemMtxOpen" @1544 1540 "___libc_Back_safesemMtxUnlock" @1545 1541 "___libc_Back_sysvSemCtl" @1546 1542 "___libc_Back_sysvSemGet" @1547 1543 "___libc_Back_sysvSemOp" @1548 1544 "___libc_Back_sysvShmAt" @1549 1545 "___libc_Back_sysvShmCtl" @1550 1546 "___libc_Back_sysvShmDt" @1551 1547 "___libc_Back_sysvShmGet" @1552 1548 "__std_ftok" @1553 1549 "__std_semctl" @1554 1550 "__std_semget" @1555 1551 "__std_semop" @1556 1552 "__std_shmat" @1557 1553 "__std_shmctl" @1558 1554 "__std_shmdt" @1559 1555 "__std_shmget" @1560 -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/process/semctl.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.2
r1985 r1986 40 40 41 41 /** 42 * sem op.42 * semctl. 43 43 */ 44 44 int _STD(semctl)(int semid, int semnum, int cmd, ...) -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/sys/sysv_sem.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.2
r1985 r1986 8 8 9 9 #include "libc-alias.h" 10 #include <sys/cdefs.h> 10 11 //__FBSDID("$FreeBSD: src/sys/kern/sysv_sem.c,v 1.70.2.3 2005/03/22 17:20:07 sam Exp $"); 11 #include <sys/cdefs.h>12 12 13 13 #include <sys/types.h> … … 33 33 #include <InnoTekLIBC/libc.h> 34 34 #include <InnoTekLIBC/backend.h> 35 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_BACK_ FS35 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_BACK_IPC 36 36 #include <InnoTekLIBC/logstrict.h> 37 37 … … 51 51 struct semid_ds u; 52 52 /** Event semaphore to wait on. */ 53 HEVhev;54 /** Mutex protecting the semid_ds and HEVmembers. */55 HMTXhmtx;53 uintptr_t hev; 54 /** Mutex protecting the semid_ds and hev members. */ 55 uintptr_t hmtx; 56 56 }; 57 57 … … 74 74 struct sem *sem; 75 75 /** Mutex protecting the undo list and other global sem stuff. */ 76 HMTXhmtx;76 uintptr_t hmtx; 77 77 /** list of active undo structures. */ 78 78 SLIST_HEAD(, sem_undo) semu_list; … … 96 96 97 97 //#define SEMUNDO_MTX gpGlobals->hmtx 98 #define SEMUNDO_LOCK() semMtxLock(gpGlobals->hmtx);99 #define SEMUNDO_UNLOCK() semMtxUnlock(gpGlobals->hmtx);98 #define SEMUNDO_LOCK() __libc_Back_safesemMtxLock(gpGlobals->hmtx); 99 #define SEMUNDO_UNLOCK() __libc_Back_safesemMtxUnlock(gpGlobals->hmtx); 100 100 #define SEMUNDO_LOCKASSERT(how) do {} while (0) //mtx_assert(gpGlobals->hmtx, (how)); 101 101 … … 238 238 #define TUNABLE_INT_FETCH(path, var) _getenv_int("LIBC_" path, (var)) 239 239 240 //static int spmRequestMutexErrno(__LIBC_PSPMXCPTREGREC pRegRec);241 //static int spmRequestMutex(__LIBC_PSPMXCPTREGREC pRegRec);242 //static int spmReleaseMutex(__LIBC_PSPMXCPTREGREC pRegRec);243 244 //int __libc_spmLock(__LIBC_PSPMXCPTREGREC pRegRec);245 246 240 247 241 static int seminit(void) … … 290 284 */ 291 285 size_t cb = sizeof(*gpGlobals); 292 cb += sizeof(struct semid_kernel) * s eminfo.semmni;286 cb += sizeof(struct semid_kernel) * si.semmni; 293 287 cb += sizeof(struct sem) * si.semmns; 294 cb += s eminfo.semmnu * seminfo.semusz;288 cb += si.semmnu * si.semusz; 295 289 296 290 /* 297 * Take the sem and allocate the memory.291 * Retake the sem and allocate the memory. 298 292 */ 299 293 rc = __libc_spmLock(&RegRec, &pSPMHdr); … … 321 315 SLIST_INIT(&pGlobals->semu_list); 322 316 pGlobals->semu = (int *)pu8; 323 pGlobals->seminfo = si;317 pGlobals->seminfo = si; 324 318 325 319 /* Set globals. */ … … 333 327 */ 334 328 int i; 335 FS_VAR_SAVE_LOAD();336 329 if (!pGlobals->cUsers) 337 330 { 338 331 /* create */ 339 340 rc = DosCreateMutexSemEx(NULL, &pGlobals->hmtx, DC_SEM_SHARED, FALSE); 332 rc = __libc_Back_safesemMtxCreate(&pGlobals->hmtx, 1); 341 333 for (i = 0; i < pGlobals->seminfo.semmni && !rc; i++) 342 rc = DosCreateMutexSemEx(NULL, &pGlobals->sema[i].hmtx, DC_SEM_SHARED, FALSE);334 rc = __libc_Back_safesemMtxCreate(&pGlobals->sema[i].hmtx, 1); 343 335 for (i = 0; i < pGlobals->seminfo.semmni && !rc; i++) 344 rc = DosCreateEventSemEx(NULL, &pGlobals->sema[i].hev, DC_SEM_SHARED, FALSE);336 rc = __libc_Back_safesemEvCreate(&pGlobals->sema[i].hev, 1); 345 337 } 346 338 else 347 339 { 348 340 /* open */ 349 rc = DosOpenMutexSemEx(NULL, &pGlobals->hmtx);341 rc = __libc_Back_safesemMtxOpen(pGlobals->hmtx); 350 342 for (i = 0; i < pGlobals->seminfo.semmni && !rc; i++) 351 rc = DosOpenMutexSemEx(NULL, &pGlobals->sema[i].hmtx);343 rc = __libc_Back_safesemMtxOpen(pGlobals->sema[i].hmtx); 352 344 for (i = 0; i < pGlobals->seminfo.semmni && !rc; i++) 353 rc = DosOpenEventSemEx(NULL, &pGlobals->sema[i].hev);345 rc = __libc_Back_safesemEvOpen(pGlobals->sema[i].hev); 354 346 } 355 347 __atomic_increment_u32(&pGlobals->cUsers); 356 FS_RESTORE();357 348 358 349 /* … … 369 360 if (rc) 370 361 rc = -__libc_native2errno(rc); 371 LIBCLOG_RETURN_INT(rc);372 }373 374 375 /**376 * This function checks that there is at least 2k of writable377 * stack available. If there isn't, a crash is usually the378 * result.379 * @internal380 */381 static int semMtxLockStackChecker(void)382 {383 char volatile *pch = alloca(2048);384 if (!pch)385 return -1;386 /* With any luck the compiler doesn't optimize this away. */387 pch[0] = pch[1024] = pch[2044] = 0x7f;388 return 0;389 }390 391 392 /**393 * Locks a mutex semaphore.394 *395 * @returns 0 on success.396 * @returns Negative errno on failure.397 * @param hmtx Handle to the mutex.398 */399 static int semMtxLock(HMTX hmtx)400 {401 LIBCLOG_ENTER("hmtx=%#lx\n", hmtx);402 ULONG ul;403 int rc;404 FS_VAR();405 406 /*407 * Check stack.408 */409 if (semMtxLockStackChecker())410 {411 LIBC_ASSERTM_FAILED("Too little stack left!\n");412 LIBCLOG_RETURN_INT(-EFAULT);413 }414 415 /*416 * Request semaphore and enter "must complete section" to avoid signal trouble.417 */418 FS_SAVE_LOAD();419 rc = DosRequestMutexSem(hmtx, 30*1000);420 DosEnterMustComplete(&ul);421 if (!rc)422 {423 FS_RESTORE();424 LIBCLOG_RETURN_INT(0);425 }426 427 /* failure out */428 DosExitMustComplete(&ul);429 LIBC_ASSERTM_FAILED("DosRequestMutexSem(%lu) failed with rc=%d!\n", hmtx, rc);430 rc = -__libc_native2errno(rc);431 FS_RESTORE();432 LIBCLOG_RETURN_INT(rc);433 }434 435 436 /**437 * Unlocks a mutex semaphore.438 *439 * @returns 0 on success.440 * @returns Negative errno on failure.441 * @param hmtx Handle to the mutex.442 */443 static int semMtxUnlock(HMTX hmtx)444 {445 LIBCLOG_ENTER("hmtx=%#lx\n", hmtx);446 ULONG ul = 0;447 int rc;448 FS_VAR();449 450 /*451 * Release the semaphore.452 */453 FS_SAVE_LOAD();454 rc = DosReleaseMutexSem(hmtx);455 if (rc)456 {457 FS_RESTORE();458 LIBC_ASSERTM_FAILED("DosReleaseMutexSem(%lu) -> %d\n", hmtx, rc);459 rc = -__libc_native2errno(rc);460 LIBCLOG_RETURN_INT(rc);461 }462 463 DosExitMustComplete(&ul);464 FS_RESTORE();465 LIBCLOG_RETURN_INT(0);466 }467 468 469 /**470 * Arguments to semEvSleepSignalCallback().471 */472 struct semEvSleepSignalCallback_args473 {474 /** Set if pfnComplete have already been executed. */475 volatile int fDone;476 /** Callback to execute. */477 void (*pfnComplete)(int semid, struct semid_kernel *semaptr, uint16_t volatile *pu16);478 /** Semaphore id. */479 int semid;480 /** Semaphore id we was sleeping on. */481 struct semid_kernel *semaptr;482 /** Pointer to the value to decrement. */483 uint16_t volatile *pu16;484 };485 486 /**487 * Signal notification callback.488 */489 static void semEvSleepSignalCallback(int iSignal, void *pvUser)490 {491 struct semEvSleepSignalCallback_args *pArgs = (struct semEvSleepSignalCallback_args *)pvUser;492 if (!pArgs->fDone)493 {494 pArgs->pfnComplete(pArgs->semid, pArgs->semaptr, pArgs->pu16);495 pArgs->fDone = 1;496 }497 }498 499 /**500 * Sleep on a semaphore.501 *502 * This is the most difficult thing we're doing in this file.503 *504 * @returns 0 on success.505 * @returns Negative error code (errno.h) on failure.506 * @param semaptr Semaphore to wakeup.507 * @param pfnComplete Function to execute on signal and on wait completion.508 */509 static int semEvSleep(struct semid_kernel *semaptr, void (*pfnComplete)(int semid, struct semid_kernel *semaptr, uint16_t volatile *pu16), int semid, uint16_t volatile *pu16)510 {511 LIBCLOG_ENTER("semaptr=%p pfnComplete=%p semid=%#x pu16=%p:{%d}\n", (void *)semaptr, (void *)pfnComplete, semid, (void *)pu16, *pu16);512 513 /*514 * Setup signal notification.515 */516 __LIBC_PTHREAD pThrd = __libc_threadCurrentNoAuto();517 int rc;518 if (pThrd)519 {520 struct semEvSleepSignalCallback_args Args;521 Args.fDone = 0;522 Args.pfnComplete = pfnComplete;523 Args.semid = semid;524 Args.semaptr = semaptr;525 Args.pu16 = pu16;526 pThrd->pvSigCallbackUser = &Args;527 pThrd->pfnSigCallback = semEvSleepSignalCallback;528 529 /*530 * Reset the event semaphore.531 */532 ULONG ulIgnore;533 FS_VAR_SAVE_LOAD();534 rc = DosResetEventSem(semaptr->hev, &ulIgnore);535 if (!rc || rc == ERROR_ALREADY_RESET)536 {537 /*538 * Release the sempahore and exit the must complete section.539 */540 rc = semMtxUnlock(semaptr->hev);541 if (!rc)542 {543 /*544 * Now, lets wait.545 */546 DosWaitEventSem(semaptr->hev, SEM_INDEFINITE_WAIT);547 548 /*549 * Regain access to the semaphore and must complete section550 * before checking if we got an interrupt or not.551 */552 rc = semMtxLock(semaptr->hmtx);553 if (!Args.fDone)554 Args.pfnComplete(Args.semid, Args.semaptr, Args.pu16);555 else if (!rc)556 rc = -EINTR;557 }558 }559 else560 rc = -__libc_native2errno(rc);561 FS_RESTORE();562 }563 else564 rc = -ENOSYS;565 566 LIBCLOG_RETURN_INT(rc);567 }568 569 570 /**571 * Wakes up all threads sleeping on a given event semaphore.572 *573 * @returns 0 on success.574 * @returns Negative error code (errno.h) on failure.575 * @param semaptr Semaphore to wakeup.576 */577 static int semEvWakeup(struct semid_kernel *semaptr)578 {579 LIBCLOG_ENTER("semaptr=%p\n", (void *)semaptr);580 FS_VAR_SAVE_LOAD();581 int rc = DosPostEventSem(semaptr->hev);582 FS_RESTORE();583 if (rc)584 {585 if (rc == ERROR_ALREADY_POSTED || rc == ERROR_TOO_MANY_POSTS)586 rc = 0;587 else588 rc = -__libc_native2errno(rc);589 }590 362 LIBCLOG_RETURN_INT(rc); 591 363 } … … 789 561 u_short usval, count; 790 562 uid_t uid; 791 HMTXhmtx;563 uintptr_t hmtx; 792 564 793 565 … … 814 586 LIBCLOG_RETURN_INT(-EINVAL); 815 587 semaptr = &sema[semid]; 816 semMtxLock(hmtx = semaptr->hmtx);588 __libc_Back_safesemMtxLock(hmtx = semaptr->hmtx); 817 589 if ((semaptr->u.sem_perm.mode & SEM_ALLOC) == 0) { 818 590 error = EINVAL; 819 591 goto done2; 820 592 } 821 if ((error = __libc_spmCanIPC(&semaptr->u.sem_perm, IPC_R)))822 goto done2; 823 semMtxUnlock(hmtx); hmtx = NULLHANDLE;593 if ((error = -__libc_spmCanIPC(&semaptr->u.sem_perm, IPC_R))) 594 goto done2; 595 __libc_Back_safesemMtxUnlock(hmtx); hmtx = NULLHANDLE; 824 596 memcpy(real_arg.buf, &semaptr->u, sizeof(struct semid_ds)); 825 597 rval = IXSEQ_TO_IPCID(semid, semaptr->u.sem_perm); … … 835 607 switch (cmd) { 836 608 case IPC_RMID: 837 semMtxLock(hmtx = semaptr->hmtx);609 __libc_Back_safesemMtxLock(hmtx = semaptr->hmtx); 838 610 if ((error = semvalid(semid, semaptr)) != 0) 839 611 goto done2; 840 if ((error = __libc_spmCanIPC(&semaptr->u.sem_perm, IPC_M)))612 if ((error = -__libc_spmCanIPC(&semaptr->u.sem_perm, IPC_M))) 841 613 goto done2; 842 614 uid = __libc_spmGetId(__LIBC_SPMID_EUID); … … 855 627 semundo_clear(semid, -1); 856 628 SEMUNDO_UNLOCK(); 857 semEvWakeup(semaptr);629 __libc_Back_safesemEvWakeup(semaptr->hev); 858 630 break; 859 631 … … 861 633 if ((error = copyin(real_arg.buf, &sbuf, sizeof(sbuf))) != 0) 862 634 goto done2; 863 semMtxLock(hmtx = semaptr->hmtx);635 __libc_Back_safesemMtxLock(hmtx = semaptr->hmtx); 864 636 if ((error = semvalid(semid, semaptr)) != 0) 865 637 goto done2; 866 if ((error = __libc_spmCanIPC(&semaptr->u.sem_perm, IPC_M)))638 if ((error = -__libc_spmCanIPC(&semaptr->u.sem_perm, IPC_M))) 867 639 goto done2; 868 640 semaptr->u.sem_perm.uid = sbuf.sem_perm.uid; … … 874 646 875 647 case IPC_STAT: 876 semMtxLock(hmtx = semaptr->hmtx);648 __libc_Back_safesemMtxLock(hmtx = semaptr->hmtx); 877 649 if ((error = semvalid(semid, semaptr)) != 0) 878 650 goto done2; 879 if ((error = __libc_spmCanIPC(&semaptr->u.sem_perm, IPC_R)))651 if ((error = -__libc_spmCanIPC(&semaptr->u.sem_perm, IPC_R))) 880 652 goto done2; 881 653 sbuf = semaptr->u; 882 semMtxUnlock(hmtx); hmtx = NULLHANDLE;654 __libc_Back_safesemMtxUnlock(hmtx); hmtx = NULLHANDLE; 883 655 error = copyout(semaptr, real_arg.buf, 884 656 sizeof(struct semid_ds)); … … 886 658 887 659 case GETNCNT: 888 semMtxLock(hmtx = semaptr->hmtx);660 __libc_Back_safesemMtxLock(hmtx = semaptr->hmtx); 889 661 if ((error = semvalid(semid, semaptr)) != 0) 890 662 goto done2; 891 if ((error = __libc_spmCanIPC(&semaptr->u.sem_perm, IPC_R)))663 if ((error = -__libc_spmCanIPC(&semaptr->u.sem_perm, IPC_R))) 892 664 goto done2; 893 665 if (semnum < 0 || semnum >= semaptr->u.sem_nsems) { … … 899 671 900 672 case GETPID: 901 semMtxLock(hmtx = semaptr->hmtx);673 __libc_Back_safesemMtxLock(hmtx = semaptr->hmtx); 902 674 if ((error = semvalid(semid, semaptr)) != 0) 903 675 goto done2; 904 if ((error = __libc_spmCanIPC(&semaptr->u.sem_perm, IPC_R)))676 if ((error = -__libc_spmCanIPC(&semaptr->u.sem_perm, IPC_R))) 905 677 goto done2; 906 678 if (semnum < 0 || semnum >= semaptr->u.sem_nsems) { … … 912 684 913 685 case GETVAL: 914 semMtxLock(hmtx = semaptr->hmtx);686 __libc_Back_safesemMtxLock(hmtx = semaptr->hmtx); 915 687 if ((error = semvalid(semid, semaptr)) != 0) 916 688 goto done2; 917 if ((error = __libc_spmCanIPC(&semaptr->u.sem_perm, IPC_R)))689 if ((error = -__libc_spmCanIPC(&semaptr->u.sem_perm, IPC_R))) 918 690 goto done2; 919 691 if (semnum < 0 || semnum >= semaptr->u.sem_nsems) { … … 926 698 case GETALL: 927 699 array = _hmalloc(sizeof(*array) * semaptr->u.sem_nsems); 928 semMtxLock(hmtx = semaptr->hmtx);700 __libc_Back_safesemMtxLock(hmtx = semaptr->hmtx); 929 701 if ((error = semvalid(semid, semaptr)) != 0) 930 702 goto done2; 931 if ((error = __libc_spmCanIPC(&semaptr->u.sem_perm, IPC_R)))703 if ((error = -__libc_spmCanIPC(&semaptr->u.sem_perm, IPC_R))) 932 704 goto done2; 933 705 for (i = 0; i < semaptr->u.sem_nsems; i++) 934 706 array[i] = semaptr->u.sem_base[i].semval; 935 semMtxUnlock(hmtx); hmtx = NULLHANDLE;707 __libc_Back_safesemMtxUnlock(hmtx); hmtx = NULLHANDLE; 936 708 error = copyout(array, real_arg.array, 937 709 i * sizeof(real_arg.array[0])); … … 939 711 940 712 case GETZCNT: 941 semMtxLock(hmtx = semaptr->hmtx);713 __libc_Back_safesemMtxLock(hmtx = semaptr->hmtx); 942 714 if ((error = semvalid(semid, semaptr)) != 0) 943 715 goto done2; 944 if ((error = __libc_spmCanIPC(&semaptr->u.sem_perm, IPC_R)))716 if ((error = -__libc_spmCanIPC(&semaptr->u.sem_perm, IPC_R))) 945 717 goto done2; 946 718 if (semnum < 0 || semnum >= semaptr->u.sem_nsems) { … … 952 724 953 725 case SETVAL: 954 semMtxLock(hmtx = semaptr->hmtx);726 __libc_Back_safesemMtxLock(hmtx = semaptr->hmtx); 955 727 if ((error = semvalid(semid, semaptr)) != 0) 956 728 goto done2; 957 if ((error = __libc_spmCanIPC(&semaptr->u.sem_perm, IPC_W)))729 if ((error = -__libc_spmCanIPC(&semaptr->u.sem_perm, IPC_W))) 958 730 goto done2; 959 731 if (semnum < 0 || semnum >= semaptr->u.sem_nsems) { … … 969 741 semundo_clear(semid, semnum); 970 742 SEMUNDO_UNLOCK(); 971 semEvWakeup(semaptr);743 __libc_Back_safesemEvWakeup(semaptr->hev); 972 744 break; 973 745 974 746 case SETALL: 975 semMtxLock(hmtx = semaptr->hmtx);747 __libc_Back_safesemMtxLock(hmtx = semaptr->hmtx); 976 748 raced: 977 749 if ((error = semvalid(semid, semaptr)) != 0) 978 750 goto done2; 979 751 count = semaptr->u.sem_nsems; 980 semMtxUnlock(hmtx); hmtx = NULLHANDLE;752 __libc_Back_safesemMtxUnlock(hmtx); hmtx = NULLHANDLE; 981 753 array = _hmalloc(sizeof(*array) * count); 982 754 error = copyin(real_arg.array, array, count * sizeof(*array)); 983 755 if (error) 984 756 break; 985 semMtxLock(hmtx = semaptr->hmtx);757 __libc_Back_safesemMtxLock(hmtx = semaptr->hmtx); 986 758 if ((error = semvalid(semid, semaptr)) != 0) 987 759 goto done2; … … 992 764 goto raced; 993 765 } 994 if ((error = __libc_spmCanIPC(&semaptr->u.sem_perm, IPC_W)))766 if ((error = -__libc_spmCanIPC(&semaptr->u.sem_perm, IPC_W))) 995 767 goto done2; 996 768 for (i = 0; i < semaptr->u.sem_nsems; i++) { … … 1005 777 semundo_clear(semid, -1); 1006 778 SEMUNDO_UNLOCK(); 1007 semEvWakeup(semaptr);779 __libc_Back_safesemEvWakeup(semaptr->hev); 1008 780 break; 1009 781 … … 1015 787 done2: 1016 788 if (hmtx) 1017 semMtxUnlock(hmtx);789 __libc_Back_safesemMtxUnlock(hmtx); 1018 790 1019 791 if (array != NULL) … … 1046 818 struct semid_kernel * sema = gpGlobals->sema; 1047 819 1048 error = semMtxLock(gpGlobals->hmtx);820 error = __libc_Back_safesemMtxLock(gpGlobals->hmtx); 1049 821 if (error) 1050 822 LIBCLOG_RETURN_INT(error); … … 1058 830 if (semid < seminfo.semmni) { 1059 831 DPRINTF(("found public key\n")); 1060 if ((error = __libc_spmCanIPC(&sema[semid].u.sem_perm,832 if ((error = -__libc_spmCanIPC(&sema[semid].u.sem_perm, 1061 833 semflg & 0700))) { 1062 834 goto done2; … … 1124 896 errno = -IXSEQ_TO_IPCID(semid, sema[semid].u.sem_perm); 1125 897 done2: 1126 semMtxUnlock(gpGlobals->hmtx);898 __libc_Back_safesemMtxUnlock(gpGlobals->hmtx); 1127 899 LIBCLOG_RETURN_INT(-error); 1128 900 } 1129 901 1130 1131 static void __libc_Back_sysvSemSleepDone(int semid, struct semid_kernel *semaptr, uint16_t volatile *pu16) 902 /** 903 * Args to __libc_Back_sysvSemSleepDone. 904 */ 905 struct SleepDoneArgs 1132 906 { 907 int semid; 908 struct semid_kernel *semaptr; 909 uint16_t volatile *pu16; 910 }; 911 912 /** 913 * Wakeup function, called before signals are delivered. 914 */ 915 static void SleepDone(void *pvUser) 916 { 917 struct SleepDoneArgs *pArgs = (struct SleepDoneArgs *)pvUser; 918 1133 919 /* 1134 920 * Make sure that the semaphore still exists 1135 921 */ 1136 if (( semaptr->u.sem_perm.mode & SEM_ALLOC) == 0 ||1137 semaptr->u.sem_perm.seq != IPCID_TO_SEQ(semid)) {922 if ((pArgs->semaptr->u.sem_perm.mode & SEM_ALLOC) == 0 || 923 pArgs->semaptr->u.sem_perm.seq != IPCID_TO_SEQ(pArgs->semid)) { 1138 924 return; 1139 925 } … … 1143 929 * waiting processes. 1144 930 */ 1145 __atomic_decrement_u16(p u16);931 __atomic_decrement_u16(pArgs->pu16); 1146 932 } 1147 933 … … 1199 985 1200 986 semaptr = &sema[semid]; 1201 error = semMtxLock(semaptr->hmtx);987 error = __libc_Back_safesemMtxLock(semaptr->hmtx); 1202 988 if (error) { 1203 989 if (sops != small_sops) … … 1232 1018 } 1233 1019 1234 if ((error = __libc_spmCanIPC(&semaptr->u.sem_perm, j))) {1020 if ((error = -__libc_spmCanIPC(&semaptr->u.sem_perm, j))) { 1235 1021 DPRINTF(("error = %d from ipaccess\n", error)); 1236 1022 goto done2; … … 1315 1101 } 1316 1102 1317 uint16_t volatile *pu16 = sopptr->sem_op == 0 ? &semptr->semzcnt : &semptr->semncnt; 1318 __atomic_increment_u16(pu16); 1103 struct SleepDoneArgs Args; 1104 Args.semaptr = semaptr; 1105 Args.semid = semid; 1106 Args.pu16 = sopptr->sem_op == 0 ? &semptr->semzcnt : &semptr->semncnt; 1107 __atomic_increment_u16(Args.pu16); 1319 1108 DPRINTF(("semop: good night (%d)!\n", sopptr->sem_op)); 1320 error = - semEvSleep(semaptr, __libc_Back_sysvSemSleepDone, semid, pu16);1109 error = -__libc_Back_safesemEvSleep(semaptr->hev, semaptr->hmtx, SleepDone, &Args); 1321 1110 DPRINTF(("semop: good morning (error=%d)!\n", error)); 1322 1111 /* return code is checked below, after sem[nz]cnt-- */ … … 1413 1202 if (do_wakeup) { 1414 1203 DPRINTF(("semop: doing wakeup\n")); 1415 semEvWakeup(semaptr);1204 __libc_Back_safesemEvWakeup(semaptr->hev); 1416 1205 DPRINTF(("semop: back from wakeup\n")); 1417 1206 } 1418 1207 DPRINTF(("semop: done\n")); 1419 1208 done2: 1420 semMtxUnlock(semaptr->hmtx);1209 __libc_Back_safesemMtxUnlock(semaptr->hmtx); 1421 1210 if (sops != small_sops) 1422 1211 free(sops); … … 1473 1262 semaptr = &gpGlobals->sema[semid]; 1474 1263 SEMUNDO_LOCK(); 1475 semMtxUnlock(semaptr->hmtx);1264 __libc_Back_safesemMtxUnlock(semaptr->hmtx); 1476 1265 if ((semaptr->u.sem_perm.mode & SEM_ALLOC) == 0) { 1477 1266 panic("semexit - semid not allocated"); … … 1499 1288 semaptr->u.sem_base[semnum].semval += adjval; 1500 1289 1501 semEvWakeup(semaptr);1290 __libc_Back_safesemEvWakeup(semaptr->hev); 1502 1291 DPRINTF(("semexit: back from wakeup\n")); 1503 1292 skip: 1504 semMtxUnlock(semaptr->hmtx);1293 __libc_Back_safesemMtxUnlock(semaptr->hmtx); 1505 1294 SEMUNDO_UNLOCK(); 1506 1295 } -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.