4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1994, by Sun Microsytems, Inc.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 * Interfaces to allocate, control, and free a shared memory lock
30 * XXXX Could we use a semaphore or a shared memory condition variable
39 #include <sys/types.h>
41 #include "prb_proc_int.h"
44 static boolean_t
getspin(volatile shmem_msg_t
*smp
);
47 * prb_shmem_init() - Allocates and initializes the shared memory region
50 prb_shmem_init(volatile shmem_msg_t
**ret_val
)
53 volatile shmem_msg_t
*smp
;
55 DBG_TNF_PROBE_0(prb_shmem_init_1
, "libtnfctl", "sunw%verbosity 2");
57 shmem_fd
= open("/dev/zero", O_RDWR
);
59 DBG((void) fprintf(stderr
, "couldn't open \"/dev/zero\""));
60 return (prb_status_map(errno
));
62 /*LINTED pointer cast may result in improper alignment*/
63 smp
= (shmem_msg_t
*) mmap(0, sizeof (struct shmem_msg
),
64 PROT_READ
| PROT_WRITE
, MAP_SHARED
,
66 if (smp
== (struct shmem_msg
*) - 1) {
67 DBG((void) fprintf(stderr
, "couldn't mmap \"/dev/zero\""));
68 return (prb_status_map(errno
));
70 (void) close(shmem_fd
);
72 /* sets the shared memory region to cause waiting */
77 return (PRB_STATUS_OK
);
81 * prb_shmem_wait() - spins until the shared memory flag is cleared
84 getspin(volatile shmem_msg_t
*smp
)
90 prb_shmem_wait(volatile shmem_msg_t
*smp
)
92 DBG_TNF_PROBE_0(prb_shmem_wait_start
, "libtnfctl",
93 "sunw%verbosity 2; start prb_shmem_wait");
97 DBG_TNF_PROBE_0(prb_shmem_wait_end
, "libtnfctl",
98 "sunw%verbosity 2; end prb_shmem_wait");
100 return (PRB_STATUS_OK
);
106 * prb_shmem_clear() - clears the shared memory flag and allows waiters to
110 prb_shmem_clear(volatile shmem_msg_t
*smp
)
112 DBG_TNF_PROBE_0(prb_shmem_clear_1
, "libtnfctl", "sunw%verbosity 2");
116 return (PRB_STATUS_OK
);
120 * prb_shmem_free() - Unmaps the shared memory region.
123 prb_shmem_free(volatile shmem_msg_t
*smp
)
125 DBG_TNF_PROBE_0(prb_shmem_free_1
, "libtnfctl", "sunw%verbosity 2");
127 if (munmap((caddr_t
) smp
, sizeof (struct shmem_msg
)) != 0) {
128 DBG((void) fprintf(stderr
, "couldn't munmap shared memory\n"));
129 return (prb_status_map(errno
));
132 return (PRB_STATUS_OK
);