sem.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343
  1. /*
  2. * linux/ipc/sem.c
  3. * Copyright (C) 1992 Krishna Balasubramanian
  4. * Copyright (C) 1995 Eric Schenk, Bruno Haible
  5. *
  6. * IMPLEMENTATION NOTES ON CODE REWRITE (Eric Schenk, January 1995):
  7. * This code underwent a massive rewrite in order to solve some problems
  8. * with the original code. In particular the original code failed to
  9. * wake up processes that were waiting for semval to go to 0 if the
  10. * value went to 0 and was then incremented rapidly enough. In solving
  11. * this problem I have also modified the implementation so that it
  12. * processes pending operations in a FIFO manner, thus give a guarantee
  13. * that processes waiting for a lock on the semaphore won't starve
  14. * unless another locking process fails to unlock.
  15. * In addition the following two changes in behavior have been introduced:
  16. * - The original implementation of semop returned the value
  17. * last semaphore element examined on success. This does not
  18. * match the manual page specifications, and effectively
  19. * allows the user to read the semaphore even if they do not
  20. * have read permissions. The implementation now returns 0
  21. * on success as stated in the manual page.
  22. * - There is some confusion over whether the set of undo adjustments
  23. * to be performed at exit should be done in an atomic manner.
  24. * That is, if we are attempting to decrement the semval should we queue
  25. * up and wait until we can do so legally?
  26. * The original implementation attempted to do this.
  27. * The current implementation does not do so. This is because I don't
  28. * think it is the right thing (TM) to do, and because I couldn't
  29. * see a clean way to get the old behavior with the new design.
  30. * The POSIX standard and SVID should be consulted to determine
  31. * what behavior is mandated.
  32. *
  33. * Further notes on refinement (Christoph Rohland, December 1998):
  34. * - The POSIX standard says, that the undo adjustments simply should
  35. * redo. So the current implementation is o.K.
  36. * - The previous code had two flaws:
  37. * 1) It actively gave the semaphore to the next waiting process
  38. * sleeping on the semaphore. Since this process did not have the
  39. * cpu this led to many unnecessary context switches and bad
  40. * performance. Now we only check which process should be able to
  41. * get the semaphore and if this process wants to reduce some
  42. * semaphore value we simply wake it up without doing the
  43. * operation. So it has to try to get it later. Thus e.g. the
  44. * running process may reacquire the semaphore during the current
  45. * time slice. If it only waits for zero or increases the semaphore,
  46. * we do the operation in advance and wake it up.
  47. * 2) It did not wake up all zero waiting processes. We try to do
  48. * better but only get the semops right which only wait for zero or
  49. * increase. If there are decrement operations in the operations
  50. * array we do the same as before.
  51. *
  52. * With the incarnation of O(1) scheduler, it becomes unnecessary to perform
  53. * check/retry algorithm for waking up blocked processes as the new scheduler
  54. * is better at handling thread switch than the old one.
  55. *
  56. * /proc/sysvipc/sem support (c) 1999 Dragos Acostachioaie <dragos@iname.com>
  57. *
  58. * SMP-threaded, sysctl's added
  59. * (c) 1999 Manfred Spraul <manfred@colorfullife.com>
  60. * Enforced range limit on SEM_UNDO
  61. * (c) 2001 Red Hat Inc <alan@redhat.com>
  62. * Lockless wakeup
  63. * (c) 2003 Manfred Spraul <manfred@colorfullife.com>
  64. *
  65. * support for audit of ipc object properties and permission changes
  66. * Dustin Kirkland <dustin.kirkland@us.ibm.com>
  67. *
  68. * namespaces support
  69. * OpenVZ, SWsoft Inc.
  70. * Pavel Emelianov <xemul@openvz.org>
  71. */
  72. #include <linux/slab.h>
  73. #include <linux/spinlock.h>
  74. #include <linux/init.h>
  75. #include <linux/proc_fs.h>
  76. #include <linux/time.h>
  77. #include <linux/security.h>
  78. #include <linux/syscalls.h>
  79. #include <linux/audit.h>
  80. #include <linux/capability.h>
  81. #include <linux/seq_file.h>
  82. #include <linux/rwsem.h>
  83. #include <linux/nsproxy.h>
  84. #include <linux/ipc_namespace.h>
  85. #include <asm/uaccess.h>
  86. #include "util.h"
  87. #define sem_ids(ns) ((ns)->ids[IPC_SEM_IDS])
  88. #define sem_unlock(sma) ipc_unlock(&(sma)->sem_perm)
  89. #define sem_checkid(sma, semid) ipc_checkid(&sma->sem_perm, semid)
  90. static int newary(struct ipc_namespace *, struct ipc_params *);
  91. static void freeary(struct ipc_namespace *, struct kern_ipc_perm *);
  92. #ifdef CONFIG_PROC_FS
  93. static int sysvipc_sem_proc_show(struct seq_file *s, void *it);
  94. #endif
  95. #define SEMMSL_FAST 256 /* 512 bytes on stack */
  96. #define SEMOPM_FAST 64 /* ~ 372 bytes on stack */
  97. /*
  98. * linked list protection:
  99. * sem_undo.id_next,
  100. * sem_array.sem_pending{,last},
  101. * sem_array.sem_undo: sem_lock() for read/write
  102. * sem_undo.proc_next: only "current" is allowed to read/write that field.
  103. *
  104. */
  105. #define sc_semmsl sem_ctls[0]
  106. #define sc_semmns sem_ctls[1]
  107. #define sc_semopm sem_ctls[2]
  108. #define sc_semmni sem_ctls[3]
  109. void sem_init_ns(struct ipc_namespace *ns)
  110. {
  111. ns->sc_semmsl = SEMMSL;
  112. ns->sc_semmns = SEMMNS;
  113. ns->sc_semopm = SEMOPM;
  114. ns->sc_semmni = SEMMNI;
  115. ns->used_sems = 0;
  116. ipc_init_ids(&ns->ids[IPC_SEM_IDS]);
  117. }
  118. #ifdef CONFIG_IPC_NS
  119. void sem_exit_ns(struct ipc_namespace *ns)
  120. {
  121. free_ipcs(ns, &sem_ids(ns), freeary);
  122. }
  123. #endif
  124. void __init sem_init (void)
  125. {
  126. sem_init_ns(&init_ipc_ns);
  127. ipc_init_proc_interface("sysvipc/sem",
  128. " key semid perms nsems uid gid cuid cgid otime ctime\n",
  129. IPC_SEM_IDS, sysvipc_sem_proc_show);
  130. }
  131. /*
  132. * sem_lock_(check_) routines are called in the paths where the rw_mutex
  133. * is not held.
  134. */
  135. static inline struct sem_array *sem_lock(struct ipc_namespace *ns, int id)
  136. {
  137. struct kern_ipc_perm *ipcp = ipc_lock(&sem_ids(ns), id);
  138. if (IS_ERR(ipcp))
  139. return (struct sem_array *)ipcp;
  140. return container_of(ipcp, struct sem_array, sem_perm);
  141. }
  142. static inline struct sem_array *sem_lock_check(struct ipc_namespace *ns,
  143. int id)
  144. {
  145. struct kern_ipc_perm *ipcp = ipc_lock_check(&sem_ids(ns), id);
  146. if (IS_ERR(ipcp))
  147. return (struct sem_array *)ipcp;
  148. return container_of(ipcp, struct sem_array, sem_perm);
  149. }
  150. static inline void sem_lock_and_putref(struct sem_array *sma)
  151. {
  152. ipc_lock_by_ptr(&sma->sem_perm);
  153. ipc_rcu_putref(sma);
  154. }
  155. static inline void sem_getref_and_unlock(struct sem_array *sma)
  156. {
  157. ipc_rcu_getref(sma);
  158. ipc_unlock(&(sma)->sem_perm);
  159. }
  160. static inline void sem_putref(struct sem_array *sma)
  161. {
  162. ipc_lock_by_ptr(&sma->sem_perm);
  163. ipc_rcu_putref(sma);
  164. ipc_unlock(&(sma)->sem_perm);
  165. }
  166. static inline void sem_rmid(struct ipc_namespace *ns, struct sem_array *s)
  167. {
  168. ipc_rmid(&sem_ids(ns), &s->sem_perm);
  169. }
  170. /*
  171. * Lockless wakeup algorithm:
  172. * Without the check/retry algorithm a lockless wakeup is possible:
  173. * - queue.status is initialized to -EINTR before blocking.
  174. * - wakeup is performed by
  175. * * unlinking the queue entry from sma->sem_pending
  176. * * setting queue.status to IN_WAKEUP
  177. * This is the notification for the blocked thread that a
  178. * result value is imminent.
  179. * * call wake_up_process
  180. * * set queue.status to the final value.
  181. * - the previously blocked thread checks queue.status:
  182. * * if it's IN_WAKEUP, then it must wait until the value changes
  183. * * if it's not -EINTR, then the operation was completed by
  184. * update_queue. semtimedop can return queue.status without
  185. * performing any operation on the sem array.
  186. * * otherwise it must acquire the spinlock and check what's up.
  187. *
  188. * The two-stage algorithm is necessary to protect against the following
  189. * races:
  190. * - if queue.status is set after wake_up_process, then the woken up idle
  191. * thread could race forward and try (and fail) to acquire sma->lock
  192. * before update_queue had a chance to set queue.status
  193. * - if queue.status is written before wake_up_process and if the
  194. * blocked process is woken up by a signal between writing
  195. * queue.status and the wake_up_process, then the woken up
  196. * process could return from semtimedop and die by calling
  197. * sys_exit before wake_up_process is called. Then wake_up_process
  198. * will oops, because the task structure is already invalid.
  199. * (yes, this happened on s390 with sysv msg).
  200. *
  201. */
  202. #define IN_WAKEUP 1
  203. /**
  204. * newary - Create a new semaphore set
  205. * @ns: namespace
  206. * @params: ptr to the structure that contains key, semflg and nsems
  207. *
  208. * Called with sem_ids.rw_mutex held (as a writer)
  209. */
  210. static int newary(struct ipc_namespace *ns, struct ipc_params *params)
  211. {
  212. int id;
  213. int retval;
  214. struct sem_array *sma;
  215. int size;
  216. key_t key = params->key;
  217. int nsems = params->u.nsems;
  218. int semflg = params->flg;
  219. if (!nsems)
  220. return -EINVAL;
  221. if (ns->used_sems + nsems > ns->sc_semmns)
  222. return -ENOSPC;
  223. size = sizeof (*sma) + nsems * sizeof (struct sem);
  224. sma = ipc_rcu_alloc(size);
  225. if (!sma) {
  226. return -ENOMEM;
  227. }
  228. memset (sma, 0, size);
  229. sma->sem_perm.mode = (semflg & S_IRWXUGO);
  230. sma->sem_perm.key = key;
  231. sma->sem_perm.security = NULL;
  232. retval = security_sem_alloc(sma);
  233. if (retval) {
  234. ipc_rcu_putref(sma);
  235. return retval;
  236. }
  237. id = ipc_addid(&sem_ids(ns), &sma->sem_perm, ns->sc_semmni);
  238. if (id < 0) {
  239. security_sem_free(sma);
  240. ipc_rcu_putref(sma);
  241. return id;
  242. }
  243. ns->used_sems += nsems;
  244. sma->sem_base = (struct sem *) &sma[1];
  245. /* sma->sem_pending = NULL; */
  246. sma->sem_pending_last = &sma->sem_pending;
  247. /* sma->undo = NULL; */
  248. sma->sem_nsems = nsems;
  249. sma->sem_ctime = get_seconds();
  250. sem_unlock(sma);
  251. return sma->sem_perm.id;
  252. }
  253. /*
  254. * Called with sem_ids.rw_mutex and ipcp locked.
  255. */
  256. static inline int sem_security(struct kern_ipc_perm *ipcp, int semflg)
  257. {
  258. struct sem_array *sma;
  259. sma = container_of(ipcp, struct sem_array, sem_perm);
  260. return security_sem_associate(sma, semflg);
  261. }
  262. /*
  263. * Called with sem_ids.rw_mutex and ipcp locked.
  264. */
  265. static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
  266. struct ipc_params *params)
  267. {
  268. struct sem_array *sma;
  269. sma = container_of(ipcp, struct sem_array, sem_perm);
  270. if (params->u.nsems > sma->sem_nsems)
  271. return -EINVAL;
  272. return 0;
  273. }
  274. asmlinkage long sys_semget(key_t key, int nsems, int semflg)
  275. {
  276. struct ipc_namespace *ns;
  277. struct ipc_ops sem_ops;
  278. struct ipc_params sem_params;
  279. ns = current->nsproxy->ipc_ns;
  280. if (nsems < 0 || nsems > ns->sc_semmsl)
  281. return -EINVAL;
  282. sem_ops.getnew = newary;
  283. sem_ops.associate = sem_security;
  284. sem_ops.more_checks = sem_more_checks;
  285. sem_params.key = key;
  286. sem_params.flg = semflg;
  287. sem_params.u.nsems = nsems;
  288. return ipcget(ns, &sem_ids(ns), &sem_ops, &sem_params);
  289. }
  290. /* Manage the doubly linked list sma->sem_pending as a FIFO:
  291. * insert new queue elements at the tail sma->sem_pending_last.
  292. */
  293. static inline void append_to_queue (struct sem_array * sma,
  294. struct sem_queue * q)
  295. {
  296. *(q->prev = sma->sem_pending_last) = q;
  297. *(sma->sem_pending_last = &q->next) = NULL;
  298. }
  299. static inline void prepend_to_queue (struct sem_array * sma,
  300. struct sem_queue * q)
  301. {
  302. q->next = sma->sem_pending;
  303. *(q->prev = &sma->sem_pending) = q;
  304. if (q->next)
  305. q->next->prev = &q->next;
  306. else /* sma->sem_pending_last == &sma->sem_pending */
  307. sma->sem_pending_last = &q->next;
  308. }
  309. static inline void remove_from_queue (struct sem_array * sma,
  310. struct sem_queue * q)
  311. {
  312. *(q->prev) = q->next;
  313. if (q->next)
  314. q->next->prev = q->prev;
  315. else /* sma->sem_pending_last == &q->next */
  316. sma->sem_pending_last = q->prev;
  317. q->prev = NULL; /* mark as removed */
  318. }
  319. /*
  320. * Determine whether a sequence of semaphore operations would succeed
  321. * all at once. Return 0 if yes, 1 if need to sleep, else return error code.
  322. */
  323. static int try_atomic_semop (struct sem_array * sma, struct sembuf * sops,
  324. int nsops, struct sem_undo *un, int pid)
  325. {
  326. int result, sem_op;
  327. struct sembuf *sop;
  328. struct sem * curr;
  329. for (sop = sops; sop < sops + nsops; sop++) {
  330. curr = sma->sem_base + sop->sem_num;
  331. sem_op = sop->sem_op;
  332. result = curr->semval;
  333. if (!sem_op && result)
  334. goto would_block;
  335. result += sem_op;
  336. if (result < 0)
  337. goto would_block;
  338. if (result > SEMVMX)
  339. goto out_of_range;
  340. if (sop->sem_flg & SEM_UNDO) {
  341. int undo = un->semadj[sop->sem_num] - sem_op;
  342. /*
  343. * Exceeding the undo range is an error.
  344. */
  345. if (undo < (-SEMAEM - 1) || undo > SEMAEM)
  346. goto out_of_range;
  347. }
  348. curr->semval = result;
  349. }
  350. sop--;
  351. while (sop >= sops) {
  352. sma->sem_base[sop->sem_num].sempid = pid;
  353. if (sop->sem_flg & SEM_UNDO)
  354. un->semadj[sop->sem_num] -= sop->sem_op;
  355. sop--;
  356. }
  357. sma->sem_otime = get_seconds();
  358. return 0;
  359. out_of_range:
  360. result = -ERANGE;
  361. goto undo;
  362. would_block:
  363. if (sop->sem_flg & IPC_NOWAIT)
  364. result = -EAGAIN;
  365. else
  366. result = 1;
  367. undo:
  368. sop--;
  369. while (sop >= sops) {
  370. sma->sem_base[sop->sem_num].semval -= sop->sem_op;
  371. sop--;
  372. }
  373. return result;
  374. }
  375. /* Go through the pending queue for the indicated semaphore
  376. * looking for tasks that can be completed.
  377. */
  378. static void update_queue (struct sem_array * sma)
  379. {
  380. int error;
  381. struct sem_queue * q;
  382. q = sma->sem_pending;
  383. while(q) {
  384. error = try_atomic_semop(sma, q->sops, q->nsops,
  385. q->undo, q->pid);
  386. /* Does q->sleeper still need to sleep? */
  387. if (error <= 0) {
  388. struct sem_queue *n;
  389. remove_from_queue(sma,q);
  390. q->status = IN_WAKEUP;
  391. /*
  392. * Continue scanning. The next operation
  393. * that must be checked depends on the type of the
  394. * completed operation:
  395. * - if the operation modified the array, then
  396. * restart from the head of the queue and
  397. * check for threads that might be waiting
  398. * for semaphore values to become 0.
  399. * - if the operation didn't modify the array,
  400. * then just continue.
  401. */
  402. if (q->alter)
  403. n = sma->sem_pending;
  404. else
  405. n = q->next;
  406. wake_up_process(q->sleeper);
  407. /* hands-off: q will disappear immediately after
  408. * writing q->status.
  409. */
  410. smp_wmb();
  411. q->status = error;
  412. q = n;
  413. } else {
  414. q = q->next;
  415. }
  416. }
  417. }
  418. /* The following counts are associated to each semaphore:
  419. * semncnt number of tasks waiting on semval being nonzero
  420. * semzcnt number of tasks waiting on semval being zero
  421. * This model assumes that a task waits on exactly one semaphore.
  422. * Since semaphore operations are to be performed atomically, tasks actually
  423. * wait on a whole sequence of semaphores simultaneously.
  424. * The counts we return here are a rough approximation, but still
  425. * warrant that semncnt+semzcnt>0 if the task is on the pending queue.
  426. */
  427. static int count_semncnt (struct sem_array * sma, ushort semnum)
  428. {
  429. int semncnt;
  430. struct sem_queue * q;
  431. semncnt = 0;
  432. for (q = sma->sem_pending; q; q = q->next) {
  433. struct sembuf * sops = q->sops;
  434. int nsops = q->nsops;
  435. int i;
  436. for (i = 0; i < nsops; i++)
  437. if (sops[i].sem_num == semnum
  438. && (sops[i].sem_op < 0)
  439. && !(sops[i].sem_flg & IPC_NOWAIT))
  440. semncnt++;
  441. }
  442. return semncnt;
  443. }
  444. static int count_semzcnt (struct sem_array * sma, ushort semnum)
  445. {
  446. int semzcnt;
  447. struct sem_queue * q;
  448. semzcnt = 0;
  449. for (q = sma->sem_pending; q; q = q->next) {
  450. struct sembuf * sops = q->sops;
  451. int nsops = q->nsops;
  452. int i;
  453. for (i = 0; i < nsops; i++)
  454. if (sops[i].sem_num == semnum
  455. && (sops[i].sem_op == 0)
  456. && !(sops[i].sem_flg & IPC_NOWAIT))
  457. semzcnt++;
  458. }
  459. return semzcnt;
  460. }
  461. /* Free a semaphore set. freeary() is called with sem_ids.rw_mutex locked
  462. * as a writer and the spinlock for this semaphore set hold. sem_ids.rw_mutex
  463. * remains locked on exit.
  464. */
  465. static void freeary(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp)
  466. {
  467. struct sem_undo *un;
  468. struct sem_queue *q;
  469. struct sem_array *sma = container_of(ipcp, struct sem_array, sem_perm);
  470. /* Invalidate the existing undo structures for this semaphore set.
  471. * (They will be freed without any further action in exit_sem()
  472. * or during the next semop.)
  473. */
  474. for (un = sma->undo; un; un = un->id_next)
  475. un->semid = -1;
  476. /* Wake up all pending processes and let them fail with EIDRM. */
  477. q = sma->sem_pending;
  478. while(q) {
  479. struct sem_queue *n;
  480. /* lazy remove_from_queue: we are killing the whole queue */
  481. q->prev = NULL;
  482. n = q->next;
  483. q->status = IN_WAKEUP;
  484. wake_up_process(q->sleeper); /* doesn't sleep */
  485. smp_wmb();
  486. q->status = -EIDRM; /* hands-off q */
  487. q = n;
  488. }
  489. /* Remove the semaphore set from the IDR */
  490. sem_rmid(ns, sma);
  491. sem_unlock(sma);
  492. ns->used_sems -= sma->sem_nsems;
  493. security_sem_free(sma);
  494. ipc_rcu_putref(sma);
  495. }
  496. static unsigned long copy_semid_to_user(void __user *buf, struct semid64_ds *in, int version)
  497. {
  498. switch(version) {
  499. case IPC_64:
  500. return copy_to_user(buf, in, sizeof(*in));
  501. case IPC_OLD:
  502. {
  503. struct semid_ds out;
  504. ipc64_perm_to_ipc_perm(&in->sem_perm, &out.sem_perm);
  505. out.sem_otime = in->sem_otime;
  506. out.sem_ctime = in->sem_ctime;
  507. out.sem_nsems = in->sem_nsems;
  508. return copy_to_user(buf, &out, sizeof(out));
  509. }
  510. default:
  511. return -EINVAL;
  512. }
  513. }
  514. static int semctl_nolock(struct ipc_namespace *ns, int semid,
  515. int cmd, int version, union semun arg)
  516. {
  517. int err = -EINVAL;
  518. struct sem_array *sma;
  519. switch(cmd) {
  520. case IPC_INFO:
  521. case SEM_INFO:
  522. {
  523. struct seminfo seminfo;
  524. int max_id;
  525. err = security_sem_semctl(NULL, cmd);
  526. if (err)
  527. return err;
  528. memset(&seminfo,0,sizeof(seminfo));
  529. seminfo.semmni = ns->sc_semmni;
  530. seminfo.semmns = ns->sc_semmns;
  531. seminfo.semmsl = ns->sc_semmsl;
  532. seminfo.semopm = ns->sc_semopm;
  533. seminfo.semvmx = SEMVMX;
  534. seminfo.semmnu = SEMMNU;
  535. seminfo.semmap = SEMMAP;
  536. seminfo.semume = SEMUME;
  537. down_read(&sem_ids(ns).rw_mutex);
  538. if (cmd == SEM_INFO) {
  539. seminfo.semusz = sem_ids(ns).in_use;
  540. seminfo.semaem = ns->used_sems;
  541. } else {
  542. seminfo.semusz = SEMUSZ;
  543. seminfo.semaem = SEMAEM;
  544. }
  545. max_id = ipc_get_maxid(&sem_ids(ns));
  546. up_read(&sem_ids(ns).rw_mutex);
  547. if (copy_to_user (arg.__buf, &seminfo, sizeof(struct seminfo)))
  548. return -EFAULT;
  549. return (max_id < 0) ? 0: max_id;
  550. }
  551. case IPC_STAT:
  552. case SEM_STAT:
  553. {
  554. struct semid64_ds tbuf;
  555. int id;
  556. if (cmd == SEM_STAT) {
  557. sma = sem_lock(ns, semid);
  558. if (IS_ERR(sma))
  559. return PTR_ERR(sma);
  560. id = sma->sem_perm.id;
  561. } else {
  562. sma = sem_lock_check(ns, semid);
  563. if (IS_ERR(sma))
  564. return PTR_ERR(sma);
  565. id = 0;
  566. }
  567. err = -EACCES;
  568. if (ipcperms (&sma->sem_perm, S_IRUGO))
  569. goto out_unlock;
  570. err = security_sem_semctl(sma, cmd);
  571. if (err)
  572. goto out_unlock;
  573. memset(&tbuf, 0, sizeof(tbuf));
  574. kernel_to_ipc64_perm(&sma->sem_perm, &tbuf.sem_perm);
  575. tbuf.sem_otime = sma->sem_otime;
  576. tbuf.sem_ctime = sma->sem_ctime;
  577. tbuf.sem_nsems = sma->sem_nsems;
  578. sem_unlock(sma);
  579. if (copy_semid_to_user (arg.buf, &tbuf, version))
  580. return -EFAULT;
  581. return id;
  582. }
  583. default:
  584. return -EINVAL;
  585. }
  586. return err;
  587. out_unlock:
  588. sem_unlock(sma);
  589. return err;
  590. }
  591. static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
  592. int cmd, int version, union semun arg)
  593. {
  594. struct sem_array *sma;
  595. struct sem* curr;
  596. int err;
  597. ushort fast_sem_io[SEMMSL_FAST];
  598. ushort* sem_io = fast_sem_io;
  599. int nsems;
  600. sma = sem_lock_check(ns, semid);
  601. if (IS_ERR(sma))
  602. return PTR_ERR(sma);
  603. nsems = sma->sem_nsems;
  604. err = -EACCES;
  605. if (ipcperms (&sma->sem_perm, (cmd==SETVAL||cmd==SETALL)?S_IWUGO:S_IRUGO))
  606. goto out_unlock;
  607. err = security_sem_semctl(sma, cmd);
  608. if (err)
  609. goto out_unlock;
  610. err = -EACCES;
  611. switch (cmd) {
  612. case GETALL:
  613. {
  614. ushort __user *array = arg.array;
  615. int i;
  616. if(nsems > SEMMSL_FAST) {
  617. sem_getref_and_unlock(sma);
  618. sem_io = ipc_alloc(sizeof(ushort)*nsems);
  619. if(sem_io == NULL) {
  620. sem_putref(sma);
  621. return -ENOMEM;
  622. }
  623. sem_lock_and_putref(sma);
  624. if (sma->sem_perm.deleted) {
  625. sem_unlock(sma);
  626. err = -EIDRM;
  627. goto out_free;
  628. }
  629. }
  630. for (i = 0; i < sma->sem_nsems; i++)
  631. sem_io[i] = sma->sem_base[i].semval;
  632. sem_unlock(sma);
  633. err = 0;
  634. if(copy_to_user(array, sem_io, nsems*sizeof(ushort)))
  635. err = -EFAULT;
  636. goto out_free;
  637. }
  638. case SETALL:
  639. {
  640. int i;
  641. struct sem_undo *un;
  642. sem_getref_and_unlock(sma);
  643. if(nsems > SEMMSL_FAST) {
  644. sem_io = ipc_alloc(sizeof(ushort)*nsems);
  645. if(sem_io == NULL) {
  646. sem_putref(sma);
  647. return -ENOMEM;
  648. }
  649. }
  650. if (copy_from_user (sem_io, arg.array, nsems*sizeof(ushort))) {
  651. sem_putref(sma);
  652. err = -EFAULT;
  653. goto out_free;
  654. }
  655. for (i = 0; i < nsems; i++) {
  656. if (sem_io[i] > SEMVMX) {
  657. sem_putref(sma);
  658. err = -ERANGE;
  659. goto out_free;
  660. }
  661. }
  662. sem_lock_and_putref(sma);
  663. if (sma->sem_perm.deleted) {
  664. sem_unlock(sma);
  665. err = -EIDRM;
  666. goto out_free;
  667. }
  668. for (i = 0; i < nsems; i++)
  669. sma->sem_base[i].semval = sem_io[i];
  670. for (un = sma->undo; un; un = un->id_next)
  671. for (i = 0; i < nsems; i++)
  672. un->semadj[i] = 0;
  673. sma->sem_ctime = get_seconds();
  674. /* maybe some queued-up processes were waiting for this */
  675. update_queue(sma);
  676. err = 0;
  677. goto out_unlock;
  678. }
  679. /* GETVAL, GETPID, GETNCTN, GETZCNT, SETVAL: fall-through */
  680. }
  681. err = -EINVAL;
  682. if(semnum < 0 || semnum >= nsems)
  683. goto out_unlock;
  684. curr = &sma->sem_base[semnum];
  685. switch (cmd) {
  686. case GETVAL:
  687. err = curr->semval;
  688. goto out_unlock;
  689. case GETPID:
  690. err = curr->sempid;
  691. goto out_unlock;
  692. case GETNCNT:
  693. err = count_semncnt(sma,semnum);
  694. goto out_unlock;
  695. case GETZCNT:
  696. err = count_semzcnt(sma,semnum);
  697. goto out_unlock;
  698. case SETVAL:
  699. {
  700. int val = arg.val;
  701. struct sem_undo *un;
  702. err = -ERANGE;
  703. if (val > SEMVMX || val < 0)
  704. goto out_unlock;
  705. for (un = sma->undo; un; un = un->id_next)
  706. un->semadj[semnum] = 0;
  707. curr->semval = val;
  708. curr->sempid = task_tgid_vnr(current);
  709. sma->sem_ctime = get_seconds();
  710. /* maybe some queued-up processes were waiting for this */
  711. update_queue(sma);
  712. err = 0;
  713. goto out_unlock;
  714. }
  715. }
  716. out_unlock:
  717. sem_unlock(sma);
  718. out_free:
  719. if(sem_io != fast_sem_io)
  720. ipc_free(sem_io, sizeof(ushort)*nsems);
  721. return err;
  722. }
  723. static inline unsigned long
  724. copy_semid_from_user(struct semid64_ds *out, void __user *buf, int version)
  725. {
  726. switch(version) {
  727. case IPC_64:
  728. if (copy_from_user(out, buf, sizeof(*out)))
  729. return -EFAULT;
  730. return 0;
  731. case IPC_OLD:
  732. {
  733. struct semid_ds tbuf_old;
  734. if(copy_from_user(&tbuf_old, buf, sizeof(tbuf_old)))
  735. return -EFAULT;
  736. out->sem_perm.uid = tbuf_old.sem_perm.uid;
  737. out->sem_perm.gid = tbuf_old.sem_perm.gid;
  738. out->sem_perm.mode = tbuf_old.sem_perm.mode;
  739. return 0;
  740. }
  741. default:
  742. return -EINVAL;
  743. }
  744. }
  745. /*
  746. * This function handles some semctl commands which require the rw_mutex
  747. * to be held in write mode.
  748. * NOTE: no locks must be held, the rw_mutex is taken inside this function.
  749. */
  750. static int semctl_down(struct ipc_namespace *ns, int semid,
  751. int cmd, int version, union semun arg)
  752. {
  753. struct sem_array *sma;
  754. int err;
  755. struct semid64_ds semid64;
  756. struct kern_ipc_perm *ipcp;
  757. if(cmd == IPC_SET) {
  758. if (copy_semid_from_user(&semid64, arg.buf, version))
  759. return -EFAULT;
  760. }
  761. ipcp = ipcctl_pre_down(&sem_ids(ns), semid, cmd, &semid64.sem_perm, 0);
  762. if (IS_ERR(ipcp))
  763. return PTR_ERR(ipcp);
  764. sma = container_of(ipcp, struct sem_array, sem_perm);
  765. err = security_sem_semctl(sma, cmd);
  766. if (err)
  767. goto out_unlock;
  768. switch(cmd){
  769. case IPC_RMID:
  770. freeary(ns, ipcp);
  771. goto out_up;
  772. case IPC_SET:
  773. ipc_update_perm(&semid64.sem_perm, ipcp);
  774. sma->sem_ctime = get_seconds();
  775. break;
  776. default:
  777. err = -EINVAL;
  778. }
  779. out_unlock:
  780. sem_unlock(sma);
  781. out_up:
  782. up_write(&sem_ids(ns).rw_mutex);
  783. return err;
  784. }
  785. asmlinkage long sys_semctl (int semid, int semnum, int cmd, union semun arg)
  786. {
  787. int err = -EINVAL;
  788. int version;
  789. struct ipc_namespace *ns;
  790. if (semid < 0)
  791. return -EINVAL;
  792. version = ipc_parse_version(&cmd);
  793. ns = current->nsproxy->ipc_ns;
  794. switch(cmd) {
  795. case IPC_INFO:
  796. case SEM_INFO:
  797. case IPC_STAT:
  798. case SEM_STAT:
  799. err = semctl_nolock(ns, semid, cmd, version, arg);
  800. return err;
  801. case GETALL:
  802. case GETVAL:
  803. case GETPID:
  804. case GETNCNT:
  805. case GETZCNT:
  806. case SETVAL:
  807. case SETALL:
  808. err = semctl_main(ns,semid,semnum,cmd,version,arg);
  809. return err;
  810. case IPC_RMID:
  811. case IPC_SET:
  812. err = semctl_down(ns, semid, cmd, version, arg);
  813. return err;
  814. default:
  815. return -EINVAL;
  816. }
  817. }
  818. /* If the task doesn't already have a undo_list, then allocate one
  819. * here. We guarantee there is only one thread using this undo list,
  820. * and current is THE ONE
  821. *
  822. * If this allocation and assignment succeeds, but later
  823. * portions of this code fail, there is no need to free the sem_undo_list.
  824. * Just let it stay associated with the task, and it'll be freed later
  825. * at exit time.
  826. *
  827. * This can block, so callers must hold no locks.
  828. */
  829. static inline int get_undo_list(struct sem_undo_list **undo_listp)
  830. {
  831. struct sem_undo_list *undo_list;
  832. undo_list = current->sysvsem.undo_list;
  833. if (!undo_list) {
  834. undo_list = kzalloc(sizeof(*undo_list), GFP_KERNEL);
  835. if (undo_list == NULL)
  836. return -ENOMEM;
  837. spin_lock_init(&undo_list->lock);
  838. atomic_set(&undo_list->refcnt, 1);
  839. current->sysvsem.undo_list = undo_list;
  840. }
  841. *undo_listp = undo_list;
  842. return 0;
  843. }
  844. static struct sem_undo *lookup_undo(struct sem_undo_list *ulp, int semid)
  845. {
  846. struct sem_undo **last, *un;
  847. last = &ulp->proc_list;
  848. un = *last;
  849. while(un != NULL) {
  850. if(un->semid==semid)
  851. break;
  852. if(un->semid==-1) {
  853. *last=un->proc_next;
  854. kfree(un);
  855. } else {
  856. last=&un->proc_next;
  857. }
  858. un=*last;
  859. }
  860. return un;
  861. }
  862. static struct sem_undo *find_undo(struct ipc_namespace *ns, int semid)
  863. {
  864. struct sem_array *sma;
  865. struct sem_undo_list *ulp;
  866. struct sem_undo *un, *new;
  867. int nsems;
  868. int error;
  869. error = get_undo_list(&ulp);
  870. if (error)
  871. return ERR_PTR(error);
  872. spin_lock(&ulp->lock);
  873. un = lookup_undo(ulp, semid);
  874. spin_unlock(&ulp->lock);
  875. if (likely(un!=NULL))
  876. goto out;
  877. /* no undo structure around - allocate one. */
  878. sma = sem_lock_check(ns, semid);
  879. if (IS_ERR(sma))
  880. return ERR_PTR(PTR_ERR(sma));
  881. nsems = sma->sem_nsems;
  882. sem_getref_and_unlock(sma);
  883. new = kzalloc(sizeof(struct sem_undo) + sizeof(short)*nsems, GFP_KERNEL);
  884. if (!new) {
  885. sem_putref(sma);
  886. return ERR_PTR(-ENOMEM);
  887. }
  888. new->semadj = (short *) &new[1];
  889. new->semid = semid;
  890. spin_lock(&ulp->lock);
  891. un = lookup_undo(ulp, semid);
  892. if (un) {
  893. spin_unlock(&ulp->lock);
  894. kfree(new);
  895. sem_putref(sma);
  896. goto out;
  897. }
  898. sem_lock_and_putref(sma);
  899. if (sma->sem_perm.deleted) {
  900. sem_unlock(sma);
  901. spin_unlock(&ulp->lock);
  902. kfree(new);
  903. un = ERR_PTR(-EIDRM);
  904. goto out;
  905. }
  906. new->proc_next = ulp->proc_list;
  907. ulp->proc_list = new;
  908. new->id_next = sma->undo;
  909. sma->undo = new;
  910. sem_unlock(sma);
  911. un = new;
  912. spin_unlock(&ulp->lock);
  913. out:
  914. return un;
  915. }
  916. asmlinkage long sys_semtimedop(int semid, struct sembuf __user *tsops,
  917. unsigned nsops, const struct timespec __user *timeout)
  918. {
  919. int error = -EINVAL;
  920. struct sem_array *sma;
  921. struct sembuf fast_sops[SEMOPM_FAST];
  922. struct sembuf* sops = fast_sops, *sop;
  923. struct sem_undo *un;
  924. int undos = 0, alter = 0, max;
  925. struct sem_queue queue;
  926. unsigned long jiffies_left = 0;
  927. struct ipc_namespace *ns;
  928. ns = current->nsproxy->ipc_ns;
  929. if (nsops < 1 || semid < 0)
  930. return -EINVAL;
  931. if (nsops > ns->sc_semopm)
  932. return -E2BIG;
  933. if(nsops > SEMOPM_FAST) {
  934. sops = kmalloc(sizeof(*sops)*nsops,GFP_KERNEL);
  935. if(sops==NULL)
  936. return -ENOMEM;
  937. }
  938. if (copy_from_user (sops, tsops, nsops * sizeof(*tsops))) {
  939. error=-EFAULT;
  940. goto out_free;
  941. }
  942. if (timeout) {
  943. struct timespec _timeout;
  944. if (copy_from_user(&_timeout, timeout, sizeof(*timeout))) {
  945. error = -EFAULT;
  946. goto out_free;
  947. }
  948. if (_timeout.tv_sec < 0 || _timeout.tv_nsec < 0 ||
  949. _timeout.tv_nsec >= 1000000000L) {
  950. error = -EINVAL;
  951. goto out_free;
  952. }
  953. jiffies_left = timespec_to_jiffies(&_timeout);
  954. }
  955. max = 0;
  956. for (sop = sops; sop < sops + nsops; sop++) {
  957. if (sop->sem_num >= max)
  958. max = sop->sem_num;
  959. if (sop->sem_flg & SEM_UNDO)
  960. undos = 1;
  961. if (sop->sem_op != 0)
  962. alter = 1;
  963. }
  964. retry_undos:
  965. if (undos) {
  966. un = find_undo(ns, semid);
  967. if (IS_ERR(un)) {
  968. error = PTR_ERR(un);
  969. goto out_free;
  970. }
  971. } else
  972. un = NULL;
  973. sma = sem_lock_check(ns, semid);
  974. if (IS_ERR(sma)) {
  975. error = PTR_ERR(sma);
  976. goto out_free;
  977. }
  978. /*
  979. * semid identifiers are not unique - find_undo may have
  980. * allocated an undo structure, it was invalidated by an RMID
  981. * and now a new array with received the same id. Check and retry.
  982. */
  983. if (un && un->semid == -1) {
  984. sem_unlock(sma);
  985. goto retry_undos;
  986. }
  987. error = -EFBIG;
  988. if (max >= sma->sem_nsems)
  989. goto out_unlock_free;
  990. error = -EACCES;
  991. if (ipcperms(&sma->sem_perm, alter ? S_IWUGO : S_IRUGO))
  992. goto out_unlock_free;
  993. error = security_sem_semop(sma, sops, nsops, alter);
  994. if (error)
  995. goto out_unlock_free;
  996. error = try_atomic_semop (sma, sops, nsops, un, task_tgid_vnr(current));
  997. if (error <= 0) {
  998. if (alter && error == 0)
  999. update_queue (sma);
  1000. goto out_unlock_free;
  1001. }
  1002. /* We need to sleep on this operation, so we put the current
  1003. * task into the pending queue and go to sleep.
  1004. */
  1005. queue.sma = sma;
  1006. queue.sops = sops;
  1007. queue.nsops = nsops;
  1008. queue.undo = un;
  1009. queue.pid = task_tgid_vnr(current);
  1010. queue.id = semid;
  1011. queue.alter = alter;
  1012. if (alter)
  1013. append_to_queue(sma ,&queue);
  1014. else
  1015. prepend_to_queue(sma ,&queue);
  1016. queue.status = -EINTR;
  1017. queue.sleeper = current;
  1018. current->state = TASK_INTERRUPTIBLE;
  1019. sem_unlock(sma);
  1020. if (timeout)
  1021. jiffies_left = schedule_timeout(jiffies_left);
  1022. else
  1023. schedule();
  1024. error = queue.status;
  1025. while(unlikely(error == IN_WAKEUP)) {
  1026. cpu_relax();
  1027. error = queue.status;
  1028. }
  1029. if (error != -EINTR) {
  1030. /* fast path: update_queue already obtained all requested
  1031. * resources */
  1032. goto out_free;
  1033. }
  1034. sma = sem_lock(ns, semid);
  1035. if (IS_ERR(sma)) {
  1036. BUG_ON(queue.prev != NULL);
  1037. error = -EIDRM;
  1038. goto out_free;
  1039. }
  1040. /*
  1041. * If queue.status != -EINTR we are woken up by another process
  1042. */
  1043. error = queue.status;
  1044. if (error != -EINTR) {
  1045. goto out_unlock_free;
  1046. }
  1047. /*
  1048. * If an interrupt occurred we have to clean up the queue
  1049. */
  1050. if (timeout && jiffies_left == 0)
  1051. error = -EAGAIN;
  1052. remove_from_queue(sma,&queue);
  1053. goto out_unlock_free;
  1054. out_unlock_free:
  1055. sem_unlock(sma);
  1056. out_free:
  1057. if(sops != fast_sops)
  1058. kfree(sops);
  1059. return error;
  1060. }
  1061. asmlinkage long sys_semop (int semid, struct sembuf __user *tsops, unsigned nsops)
  1062. {
  1063. return sys_semtimedop(semid, tsops, nsops, NULL);
  1064. }
  1065. /* If CLONE_SYSVSEM is set, establish sharing of SEM_UNDO state between
  1066. * parent and child tasks.
  1067. */
  1068. int copy_semundo(unsigned long clone_flags, struct task_struct *tsk)
  1069. {
  1070. struct sem_undo_list *undo_list;
  1071. int error;
  1072. if (clone_flags & CLONE_SYSVSEM) {
  1073. error = get_undo_list(&undo_list);
  1074. if (error)
  1075. return error;
  1076. atomic_inc(&undo_list->refcnt);
  1077. tsk->sysvsem.undo_list = undo_list;
  1078. } else
  1079. tsk->sysvsem.undo_list = NULL;
  1080. return 0;
  1081. }
  1082. /*
  1083. * add semadj values to semaphores, free undo structures.
  1084. * undo structures are not freed when semaphore arrays are destroyed
  1085. * so some of them may be out of date.
  1086. * IMPLEMENTATION NOTE: There is some confusion over whether the
  1087. * set of adjustments that needs to be done should be done in an atomic
  1088. * manner or not. That is, if we are attempting to decrement the semval
  1089. * should we queue up and wait until we can do so legally?
  1090. * The original implementation attempted to do this (queue and wait).
  1091. * The current implementation does not do so. The POSIX standard
  1092. * and SVID should be consulted to determine what behavior is mandated.
  1093. */
  1094. void exit_sem(struct task_struct *tsk)
  1095. {
  1096. struct sem_undo_list *undo_list;
  1097. struct sem_undo *u, **up;
  1098. struct ipc_namespace *ns;
  1099. undo_list = tsk->sysvsem.undo_list;
  1100. if (!undo_list)
  1101. return;
  1102. tsk->sysvsem.undo_list = NULL;
  1103. if (!atomic_dec_and_test(&undo_list->refcnt))
  1104. return;
  1105. ns = tsk->nsproxy->ipc_ns;
  1106. /* There's no need to hold the semundo list lock, as current
  1107. * is the last task exiting for this undo list.
  1108. */
  1109. for (up = &undo_list->proc_list; (u = *up); *up = u->proc_next, kfree(u)) {
  1110. struct sem_array *sma;
  1111. int nsems, i;
  1112. struct sem_undo *un, **unp;
  1113. int semid;
  1114. semid = u->semid;
  1115. if(semid == -1)
  1116. continue;
  1117. sma = sem_lock(ns, semid);
  1118. if (IS_ERR(sma))
  1119. continue;
  1120. if (u->semid == -1)
  1121. goto next_entry;
  1122. BUG_ON(sem_checkid(sma, u->semid));
  1123. /* remove u from the sma->undo list */
  1124. for (unp = &sma->undo; (un = *unp); unp = &un->id_next) {
  1125. if (u == un)
  1126. goto found;
  1127. }
  1128. printk ("exit_sem undo list error id=%d\n", u->semid);
  1129. goto next_entry;
  1130. found:
  1131. *unp = un->id_next;
  1132. /* perform adjustments registered in u */
  1133. nsems = sma->sem_nsems;
  1134. for (i = 0; i < nsems; i++) {
  1135. struct sem * semaphore = &sma->sem_base[i];
  1136. if (u->semadj[i]) {
  1137. semaphore->semval += u->semadj[i];
  1138. /*
  1139. * Range checks of the new semaphore value,
  1140. * not defined by sus:
  1141. * - Some unices ignore the undo entirely
  1142. * (e.g. HP UX 11i 11.22, Tru64 V5.1)
  1143. * - some cap the value (e.g. FreeBSD caps
  1144. * at 0, but doesn't enforce SEMVMX)
  1145. *
  1146. * Linux caps the semaphore value, both at 0
  1147. * and at SEMVMX.
  1148. *
  1149. * Manfred <manfred@colorfullife.com>
  1150. */
  1151. if (semaphore->semval < 0)
  1152. semaphore->semval = 0;
  1153. if (semaphore->semval > SEMVMX)
  1154. semaphore->semval = SEMVMX;
  1155. semaphore->sempid = task_tgid_vnr(current);
  1156. }
  1157. }
  1158. sma->sem_otime = get_seconds();
  1159. /* maybe some queued-up processes were waiting for this */
  1160. update_queue(sma);
  1161. next_entry:
  1162. sem_unlock(sma);
  1163. }
  1164. kfree(undo_list);
  1165. }
  1166. #ifdef CONFIG_PROC_FS
  1167. static int sysvipc_sem_proc_show(struct seq_file *s, void *it)
  1168. {
  1169. struct sem_array *sma = it;
  1170. return seq_printf(s,
  1171. "%10d %10d %4o %10lu %5u %5u %5u %5u %10lu %10lu\n",
  1172. sma->sem_perm.key,
  1173. sma->sem_perm.id,
  1174. sma->sem_perm.mode,
  1175. sma->sem_nsems,
  1176. sma->sem_perm.uid,
  1177. sma->sem_perm.gid,
  1178. sma->sem_perm.cuid,
  1179. sma->sem_perm.cgid,
  1180. sma->sem_otime,
  1181. sma->sem_ctime);
  1182. }
  1183. #endif