7 #include "JackCompilerDeps.h"
17 #define MAX_SERVERS 8 /* maximum concurrent servers */
18 #define MAX_SHM_ID 256 /* generally about 16 per server */
19 #define JACK_SERVER_NAME_SIZE 256 /* maximum length of server name */
20 #define JACK_SHM_MAGIC 0x4a41434b /* shm magic number: "JACK" */
21 #define JACK_SHM_NULL_INDEX -1 /* NULL SHM index */
22 #define JACK_SHM_REGISTRY_INDEX -2 /* pseudo SHM index for registry */
25 /* On Mac OS X, SHM_NAME_MAX is the maximum length of a shared memory
26 * segment name (instead of NAME_MAX or PATH_MAX as defined by the
36 #define SHM_NAME_MAX NAME_MAX
38 typedef char shm_name_t
[SHM_NAME_MAX
];
39 typedef shm_name_t jack_shm_id_t
;
41 #elif WIN32 // TO CHECK
44 #define SHM_NAME_MAX NAME_MAX
46 typedef char shm_name_t
[SHM_NAME_MAX
];
47 typedef shm_name_t jack_shm_id_t
;
51 typedef int jack_shm_id_t
;
54 /* shared memory type */
56 shm_POSIX
= 1, /* POSIX shared memory */
57 shm_SYSV
= 2, /* System V shared memory */
58 shm_WIN32
= 3 /* Windows 32 shared memory */
61 typedef int16_t jack_shm_registry_index_t
;
64 * A structure holding information about shared memory allocated by
65 * JACK. this persists across invocations of JACK, and can be used by
66 * multiple JACK servers. It contains no pointers and is valid across
69 * The registry consists of two parts: a header including an array of
70 * server names, followed by an array of segment registry entries.
72 typedef struct _jack_shm_server
{
74 int pid
; /* process ID */
76 pid_t pid
; /* process ID */
79 char name
[JACK_SERVER_NAME_SIZE
];
83 typedef struct _jack_shm_header
{
84 uint32_t magic
; /* magic number */
85 uint16_t protocol
; /* JACK protocol version */
86 jack_shmtype_t type
; /* shm type */
87 jack_shmsize_t size
; /* total registry segment size */
88 jack_shmsize_t hdr_len
; /* size of header */
89 jack_shmsize_t entry_len
; /* size of registry entry */
90 jack_shm_server_t server
[MAX_SERVERS
]; /* current server array */
94 typedef struct _jack_shm_registry
{
95 jack_shm_registry_index_t index
; /* offset into the registry */
98 int allocator
; /* PID that created shm segment */
100 pid_t allocator
; /* PID that created shm segment */
103 jack_shmsize_t size
; /* for POSIX unattach */
104 jack_shm_id_t id
; /* API specific, see above */
108 #define JACK_SHM_REGISTRY_SIZE (sizeof (jack_shm_header_t) \
109 + sizeof (jack_shm_registry_t) * MAX_SHM_ID)
112 * a structure holding information about shared memory
113 * allocated by JACK. this version is valid only
114 * for a given address space. It contains a pointer
115 * indicating where the shared memory has been
116 * attached to the address space.
120 struct _jack_shm_info
{
121 jack_shm_registry_index_t index
; /* offset into the registry */
124 void *attached_at
; /* address where attached */
126 } ptr
; /* a "pointer" that has the same 8 bytes size when compling in 32 or 64 bits */
127 } POST_PACKED_STRUCTURE
;
129 typedef struct _jack_shm_info jack_shm_info_t
;
131 /* utility functions used only within JACK */
133 void jack_shm_copy_from_registry (jack_shm_info_t
*,
134 jack_shm_registry_index_t
);
135 void jack_shm_copy_to_registry (jack_shm_info_t
*,
136 jack_shm_registry_index_t
*);
137 int jack_release_shm_info (jack_shm_registry_index_t
);
138 char* jack_shm_addr (jack_shm_info_t
* si
);
140 // here begin the API
141 int jack_register_server (const char *server_name
, int new_registry
);
142 int jack_unregister_server (const char *server_name
);
144 int jack_initialize_shm (const char *server_name
);
145 int jack_initialize_shm_server (void);
146 int jack_initialize_shm_client (void);
147 int jack_cleanup_shm (void);
149 int jack_shmalloc (const char *shm_name
, jack_shmsize_t size
,
150 jack_shm_info_t
* result
);
151 void jack_release_shm (jack_shm_info_t
*);
152 void jack_release_lib_shm (jack_shm_info_t
*);
153 void jack_destroy_shm (jack_shm_info_t
*);
154 int jack_attach_shm (jack_shm_info_t
*);
155 int jack_attach_lib_shm (jack_shm_info_t
*);
156 int jack_attach_shm_read (jack_shm_info_t
*);
157 int jack_attach_lib_shm_read (jack_shm_info_t
*);
158 int jack_resize_shm (jack_shm_info_t
*, jack_shmsize_t size
);
164 #endif /* __jack_shm_h__ */