util.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * linux/ipc/util.h
  3. * Copyright (C) 1999 Christoph Rohland
  4. *
  5. * ipc helper functions (c) 1999 Manfred Spraul <manfred@colorfullife.com>
  6. */
  7. #ifndef _IPC_UTIL_H
  8. #define _IPC_UTIL_H
  9. #define USHRT_MAX 0xffff
  10. #define SEQ_MULTIPLIER (IPCMNI)
  11. void sem_init (void);
  12. void msg_init (void);
  13. void shm_init (void);
  14. struct ipc_id_ary {
  15. int size;
  16. struct kern_ipc_perm *p[0];
  17. };
  18. struct ipc_ids {
  19. int in_use;
  20. int max_id;
  21. unsigned short seq;
  22. unsigned short seq_max;
  23. struct mutex mutex;
  24. struct ipc_id_ary nullentry;
  25. struct ipc_id_ary* entries;
  26. };
  27. struct seq_file;
  28. void __init ipc_init_ids(struct ipc_ids* ids, int size);
  29. #ifdef CONFIG_PROC_FS
  30. void __init ipc_init_proc_interface(const char *path, const char *header,
  31. struct ipc_ids *ids,
  32. int (*show)(struct seq_file *, void *));
  33. #else
  34. #define ipc_init_proc_interface(path, header, ids, show) do {} while (0)
  35. #endif
  36. /* must be called with ids->mutex acquired.*/
  37. int ipc_findkey(struct ipc_ids* ids, key_t key);
  38. int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size);
  39. /* must be called with both locks acquired. */
  40. struct kern_ipc_perm* ipc_rmid(struct ipc_ids* ids, int id);
  41. int ipcperms (struct kern_ipc_perm *ipcp, short flg);
  42. /* for rare, potentially huge allocations.
  43. * both function can sleep
  44. */
  45. void* ipc_alloc(int size);
  46. void ipc_free(void* ptr, int size);
  47. /*
  48. * For allocation that need to be freed by RCU.
  49. * Objects are reference counted, they start with reference count 1.
  50. * getref increases the refcount, the putref call that reduces the recount
  51. * to 0 schedules the rcu destruction. Caller must guarantee locking.
  52. */
  53. void* ipc_rcu_alloc(int size);
  54. void ipc_rcu_getref(void *ptr);
  55. void ipc_rcu_putref(void *ptr);
  56. struct kern_ipc_perm* ipc_get(struct ipc_ids* ids, int id);
  57. struct kern_ipc_perm* ipc_lock(struct ipc_ids* ids, int id);
  58. void ipc_lock_by_ptr(struct kern_ipc_perm *ipcp);
  59. void ipc_unlock(struct kern_ipc_perm* perm);
  60. int ipc_buildid(struct ipc_ids* ids, int id, int seq);
  61. int ipc_checkid(struct ipc_ids* ids, struct kern_ipc_perm* ipcp, int uid);
  62. void kernel_to_ipc64_perm(struct kern_ipc_perm *in, struct ipc64_perm *out);
  63. void ipc64_perm_to_ipc_perm(struct ipc64_perm *in, struct ipc_perm *out);
  64. #if defined(__ia64__) || defined(__x86_64__) || defined(__hppa__) || defined(__XTENSA__)
  65. /* On IA-64, we always use the "64-bit version" of the IPC structures. */
  66. # define ipc_parse_version(cmd) IPC_64
  67. #else
  68. int ipc_parse_version (int *cmd);
  69. #endif
  70. extern void free_msg(struct msg_msg *msg);
  71. extern struct msg_msg *load_msg(const void __user *src, int len);
  72. extern int store_msg(void __user *dest, struct msg_msg *msg, int len);
  73. #endif