jack1 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
4.0KB

  1. #ifndef __jack_shm_h__
  2. #define __jack_shm_h__
  3. #include <limits.h>
  4. #include <sys/types.h>
  5. #include <jack/types.h>
  6. #define MAX_SERVERS 8 /* maximum concurrent servers */
  7. #define MAX_SHM_ID 256 /* generally about 16 per server */
  8. #define JACK_SERVER_NAME_SIZE 256 /* maximum length of server name */
  9. #define JACK_SHM_MAGIC 0x4a41434b /* shm magic number: "JACK" */
  10. #define JACK_SHM_NULL_INDEX -1 /* NULL SHM index */
  11. #define JACK_SHM_REGISTRY_INDEX -2 /* pseudo SHM index for registry */
  12. /* On Mac OS X, SHM_NAME_MAX is the maximum length of a shared memory
  13. * segment name (instead of NAME_MAX or PATH_MAX as defined by the
  14. * standard).
  15. */
  16. #ifdef USE_POSIX_SHM
  17. #ifndef SHM_NAME_MAX
  18. #define SHM_NAME_MAX NAME_MAX
  19. #endif
  20. typedef char shm_name_t[SHM_NAME_MAX];
  21. typedef shm_name_t jack_shm_id_t;
  22. #else /* System V SHM */
  23. typedef int jack_shm_id_t;
  24. #endif /* SHM type */
  25. /* shared memory type */
  26. typedef enum {
  27. shm_POSIX = 1, /* POSIX shared memory */
  28. shm_SYSV = 2 /* System V shared memory */
  29. } jack_shmtype_t;
  30. typedef int16_t jack_shm_registry_index_t;
  31. /**
  32. * A structure holding information about shared memory allocated by
  33. * JACK. this persists across invocations of JACK, and can be used by
  34. * multiple JACK servers. It contains no pointers and is valid across
  35. * address spaces.
  36. *
  37. * The registry consists of two parts: a header including an array of
  38. * server names, followed by an array of segment registry entries.
  39. */
  40. typedef struct _jack_shm_server {
  41. pid_t pid; /* process ID */
  42. char name[JACK_SERVER_NAME_SIZE];
  43. } jack_shm_server_t;
  44. typedef struct _jack_shm_header {
  45. uint32_t magic; /* magic number */
  46. uint16_t protocol; /* JACK protocol version */
  47. jack_shmtype_t type; /* shm type */
  48. jack_shmsize_t size; /* total registry segment size */
  49. jack_shmsize_t hdr_len; /* size of header */
  50. jack_shmsize_t entry_len; /* size of registry entry */
  51. jack_shm_server_t server[MAX_SERVERS]; /* current server array */
  52. } jack_shm_header_t;
  53. typedef struct _jack_shm_registry {
  54. jack_shm_registry_index_t index; /* offset into the registry */
  55. pid_t allocator; /* PID that created shm segment */
  56. jack_shmsize_t size; /* for POSIX unattach */
  57. jack_shm_id_t id; /* API specific, see above */
  58. } jack_shm_registry_t;
  59. #define JACK_SHM_REGISTRY_SIZE (sizeof(jack_shm_header_t) \
  60. + sizeof(jack_shm_registry_t) * MAX_SHM_ID)
  61. /**
  62. * a structure holding information about shared memory
  63. * allocated by JACK. this version is valid only
  64. * for a given address space. It contains a pointer
  65. * indicating where the shared memory has been
  66. * attached to the address space.
  67. */
  68. typedef struct _jack_shm_info {
  69. jack_shm_registry_index_t index; /* offset into the registry */
  70. void *attached_at; /* address where attached */
  71. } jack_shm_info_t;
  72. /* utility functions used only within JACK */
  73. extern void jack_shm_copy_from_registry (jack_shm_info_t *,
  74. jack_shm_registry_index_t);
  75. extern void jack_shm_copy_to_registry(jack_shm_info_t*,
  76. jack_shm_registry_index_t*);
  77. extern void jack_release_shm_info (jack_shm_registry_index_t);
  78. static inline char* jack_shm_addr (jack_shm_info_t* si)
  79. {
  80. return si->attached_at;
  81. }
  82. /* here beginneth the API */
  83. extern int jack_register_server(const char *server_name, int new_registry);
  84. extern void jack_unregister_server(const char *server_name);
  85. extern int jack_initialize_shm(const char *server_name);
  86. extern int jack_cleanup_shm(void);
  87. extern int jack_shmalloc(jack_shmsize_t size, jack_shm_info_t* result);
  88. extern void jack_release_shm(jack_shm_info_t*);
  89. extern void jack_destroy_shm(jack_shm_info_t*);
  90. extern int jack_attach_shm(jack_shm_info_t*);
  91. extern int jack_resize_shm(jack_shm_info_t*, jack_shmsize_t size);
  92. #endif /* __jack_shm_h__ */