|
|
1.1 root 1: /* $Header: /kernel/kersrc/io.286/shmcon.c,v 1.1 92/07/17 15:24:47 bin Exp Locker: bin $
2: *
3: * The information contained herein is a trade secret of INETCO
4: * Systems, and is confidential information. It is provided under
5: * a license agreement, and may be copied or disclosed only under
6: * the terms of that agreement. Any reproduction or disclosure of
7: * this material without the express written authorization of
8: * INETCO Systems or persuant to the license agreement is unlawful.
9: *
10: * Copyright (c) 1987, 1985, 1984.
11: * An unpublished work by INETCO Systems, Ltd.
12: * All rights reserved.
13: */
14:
15: /*
16: * System V Compatible Shared Memory Device Driver
17: *
18: * This device driver provides System V compatible shared memory operations.
19: * Operations are performed through the shared memory device (/dev/shm).
20: * and are implemented as ioctl calls from shmctl, shmget, shmat, shmdt
21: * utilities.
22: *
23: * Author: Allan Cornish, INETCO Systems Ltd., Sep 1984
24: *
25: * $Log: shmcon.c,v $
26: * Revision 1.1 92/07/17 15:24:47 bin
27: * Initial revision
28: *
29: * Revision 2.1 88/09/03 13:12:40 src
30: * *** empty log message ***
31: *
32: * Revision 1.1 88/03/24 17:06:36 src
33: * Initial revision
34: *
35: * 87/03/02 Allan Cornish /usr/src/sys/i8086/drv/shmcon.c
36: * Shmioctl() now supports long key [was short] on SHMGET operations.
37: * This allows compatability with System V.
38: *
39: * 85/10/16 Allan Cornish
40: * Driver split into shmcon.c, shm.c [driver implementation, system V shm].
41: *
42: * 85/07/22 Allan Cornish
43: * Shmget, shmctl now return immediately if u.u_error is set.
44: *
45: * 85/07/19 Allan Cornish
46: * Separation of io_seek into shmid and off improved through type casting.
47: * Errno set to EFAULT if fucopy() or ufcopy() report no bytes transferred.
48: * This would occur if an user address fault occurred.
49: *
50: * 85/07/03 Allan Cornish
51: * Replaced use of EDOM with EIDRM.
52: * Replaced shmaccess() by calls to ipcaccess(), increasing shared ipc code.
53: * Eliminated shmlock() and shmunlock(), as shared memory use is synchronous.
54: *
55: * 84/09/30 Allan Cornish
56: * Initial Revision.
57: */
58:
59: #include <coherent.h>
60: #include <sched.h>
61: #include <types.h>
62: #include <errno.h>
63: #include <stat.h>
64: #include <con.h>
65: #include <seg.h>
66: #include <shm.h>
67:
68: #ifndef EIDRM
69: #define EIDRM EDOM
70: #endif
71:
72: /*
73: * Functions.
74: */
75:
76: int shmload();
77: int shmread();
78: int shmwrite();
79: int shmioctl();
80: int nulldev();
81: int nonedev();
82:
83: /*
84: * Device Configuration.
85: */
86:
87: CON shmcon = {
88: DFCHR, /* Flags */
89: 24, /* Major Index */
90: nulldev, /* Open */
91: nulldev, /* Close */
92: nonedev, /* Block */
93: shmread, /* Read */
94: shmwrite, /* Write */
95: shmioctl, /* Ioctl */
96: nulldev, /* Power fail */
97: nulldev, /* Timeout */
98: shmload, /* Load */
99: nulldev /* Unload */
100: };
101:
102: unsigned NSHMID = 16;
103: struct shmid_ds *shmids;
104: struct seg **shmsegs;
105:
106: /*
107: * Shared Memory Device Load.
108: */
109:
110: static
111: shmload()
112: {
113: register struct shmid_ds * idp;
114: register unsigned wanted;
115:
116: if ( NSHMID == 0 )
117: return 0;
118:
119: wanted = NSHMID * (sizeof(struct shmid_ds) + sizeof(struct seg *));
120:
121: if ( (shmids = kalloc( wanted )) == 0 ) {
122:
123: printf("couldn't kalloc %u shared memory ids\n", NSHMID );
124: NSHMID = 0;
125: return 0;
126: }
127: shmsegs = (struct seg *) &shmids[ NSHMID ];
128:
129: for ( idp = &shmids[NSHMID]; --idp >= shmids; )
130: idp->shm_perm.mode = 0;
131:
132: return 0;
133: }
134:
135: /*
136: ** Shared Memory Read.
137: */
138:
139: static
140: shmread( dev, iop )
141:
142: dev_t dev;
143: register IO *iop;
144:
145: {
146: register struct shmid_ds *idp;
147: int shmid;
148: unsigned off;
149: faddr_t faddr;
150:
151: off = ((unsigned *) &iop->io_seek)[0];
152: shmid = ((unsigned *) &iop->io_seek)[1];
153:
154: if ( shmid >= NSHMID ) {
155: u.u_error = EFAULT;
156: return -1;
157: }
158:
159: idp = &shmids[shmid];
160:
161: if ( (idp->shm_perm.mode & IPC_ALLOC) == 0 ) {
162: u.u_error = EIDRM;
163: return -1;
164: }
165:
166: if ( (ipcaccess(&idp->shm_perm) & SHM_R) == 0 ) {
167: u.u_error = EACCES;
168: return -1;
169: }
170:
171: if ( ((long) off + iop->io_ioc) > idp->shm_segsz ) {
172: u.u_error = EFAULT;
173: return -1;
174: }
175:
176: FP_SEL(faddr) = FP_SEL(shmsegs[shmid]->s_faddr);
177: FP_OFF(faddr) = off;
178:
179: if ( ! fucopy( faddr, iop->io_base, iop->io_ioc ) ) {
180: u.u_error = EFAULT;
181: return -1;
182: }
183:
184: iop->io_ioc = 0;
185: return 0;
186: }
187:
188: /*
189: ** Shared Memory Write.
190: */
191:
192: static
193: shmwrite( dev, iop )
194:
195: dev_t dev;
196: register IO *iop;
197:
198: {
199: register struct shmid_ds *idp;
200: int shmid;
201: unsigned off;
202: faddr_t faddr;
203:
204: off = ((unsigned *) &iop->io_seek)[0];
205: shmid = ((unsigned *) &iop->io_seek)[1];
206:
207: if ( shmid >= NSHMID ) {
208: u.u_error = EFAULT;
209: return -1;
210: }
211:
212: idp = &shmids[shmid];
213:
214: if ( (idp->shm_perm.mode & IPC_ALLOC) == 0 ) {
215: u.u_error = EIDRM;
216: return -1;
217: }
218:
219: if ( (ipcaccess(&idp->shm_perm) & SHM_W) == 0 ) {
220: u.u_error = EFAULT;
221: return -1;
222: }
223:
224: if ( ((long) off + iop->io_ioc) > idp->shm_segsz ) {
225: u.u_error = EFAULT;
226: return -1;
227: }
228:
229: FP_SEL(faddr) = FP_SEL(shmsegs[shmid]->s_faddr);
230: FP_OFF(faddr) = off;
231:
232: if ( ! ufcopy(iop->io_base, faddr, iop->io_ioc ) ) {
233: u.u_error = EFAULT;
234: return -1;
235: }
236:
237: iop->io_ioc = 0;
238: return 0;
239: }
240:
241: /*
242: * Shared Memory Device Ioctl.
243: *
244: * Input: dev = shared memory device (/dev/shm).
245: * com = command to perform (SHMCTL, SHMGET,SHMAT).
246: * vec = pointer to return value, followed by parameters.
247: *
248: * Action: Initiate command.
249: * Save commands return value in *vec.
250: */
251:
252: static
253: shmioctl( dev, com, vec )
254:
255: dev_t dev;
256: int com;
257: int *vec;
258:
259: {
260: switch ( com ) {
261:
262: case SHMCTL:
263: putuwd( vec+0,
264: ushmctl( getuwd( vec+1 ),
265: getuwd( vec+2 ),
266: getuwd( vec+3 ) ));
267: break;
268:
269: case SHMGET:
270: putuwd( vec+0,
271: ushmget( getuwd( vec+1 ),
272: getuwd( vec+2 ),
273: getuwd( vec+3 ),
274: getuwd( vec+4 ) ));
275: break;
276:
277: default:
278: u.u_error = EINVAL;
279: break;
280: }
281: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.