Deleted Added
full compact
streams.c (89059) streams.c (89306)
1/*
2 * Copyright (c) 1998 Mark Newton
3 * Copyright (c) 1994 Christos Zoulas
4 * Copyright (c) 1997 Todd Vierling
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 16 unchanged lines hidden (view full) ---

25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Stolen from NetBSD /sys/compat/svr4/svr4_net.c. Pseudo-device driver
30 * skeleton produced from /usr/share/examples/drivers/make_pseudo_driver.sh
31 * in 3.0-980524-SNAP then hacked a bit (but probably not enough :-).
32 *
1/*
2 * Copyright (c) 1998 Mark Newton
3 * Copyright (c) 1994 Christos Zoulas
4 * Copyright (c) 1997 Todd Vierling
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 16 unchanged lines hidden (view full) ---

25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Stolen from NetBSD /sys/compat/svr4/svr4_net.c. Pseudo-device driver
30 * skeleton produced from /usr/share/examples/drivers/make_pseudo_driver.sh
31 * in 3.0-980524-SNAP then hacked a bit (but probably not enough :-).
32 *
33 * $FreeBSD: head/sys/dev/streams/streams.c 89059 2002-01-08 06:50:17Z msmith $
33 * $FreeBSD: head/sys/dev/streams/streams.c 89306 2002-01-13 11:58:06Z alfred $
34 */
35
36#include <sys/param.h>
37#include <sys/systm.h>
38#include <sys/kernel.h> /* SYSINIT stuff */
39#include <sys/conf.h> /* cdevsw stuff */
40#include <sys/malloc.h> /* malloc region definitions */
41#include <sys/file.h>

--- 219 unchanged lines hidden (view full) ---

261 return EOPNOTSUPP;
262 }
263
264 if ((error = falloc(td, &fp, &fd)) != 0)
265 return error;
266
267 if ((error = socreate(family, &so, type, protocol,
268 td->td_proc->p_ucred, td)) != 0) {
34 */
35
36#include <sys/param.h>
37#include <sys/systm.h>
38#include <sys/kernel.h> /* SYSINIT stuff */
39#include <sys/conf.h> /* cdevsw stuff */
40#include <sys/malloc.h> /* malloc region definitions */
41#include <sys/file.h>

--- 219 unchanged lines hidden (view full) ---

261 return EOPNOTSUPP;
262 }
263
264 if ((error = falloc(td, &fp, &fd)) != 0)
265 return error;
266
267 if ((error = socreate(family, &so, type, protocol,
268 td->td_proc->p_ucred, td)) != 0) {
269 FILEDESC_LOCK(p->p_fd);
269 p->p_fd->fd_ofiles[fd] = 0;
270 p->p_fd->fd_ofiles[fd] = 0;
271 FILEDESC_UNLOCK(p->p_fd);
270 ffree(fp);
271 return error;
272 }
273
272 ffree(fp);
273 return error;
274 }
275
276 FILEDESC_LOCK(p->p_fd);
274 fp->f_data = (caddr_t)so;
275 fp->f_flag = FREAD|FWRITE;
276 fp->f_ops = &svr4_netops;
277 fp->f_type = DTYPE_SOCKET;
277 fp->f_data = (caddr_t)so;
278 fp->f_flag = FREAD|FWRITE;
279 fp->f_ops = &svr4_netops;
280 fp->f_type = DTYPE_SOCKET;
281 FILEDESC_UNLOCK(p->p_fd);
278
279 (void)svr4_stream_get(fp);
280 PROC_LOCK(p);
281 td->td_dupfd = fd;
282 PROC_UNLOCK(p);
283 return ENXIO;
284}
285

--- 64 unchanged lines hidden (view full) ---

350 struct socket *so;
351 struct svr4_strm *st;
352
353 if (fp == NULL || fp->f_type != DTYPE_SOCKET)
354 return NULL;
355
356 so = (struct socket *) fp->f_data;
357
282
283 (void)svr4_stream_get(fp);
284 PROC_LOCK(p);
285 td->td_dupfd = fd;
286 PROC_UNLOCK(p);
287 return ENXIO;
288}
289

--- 64 unchanged lines hidden (view full) ---

354 struct socket *so;
355 struct svr4_strm *st;
356
357 if (fp == NULL || fp->f_type != DTYPE_SOCKET)
358 return NULL;
359
360 so = (struct socket *) fp->f_data;
361
358 if (so->so_emuldata)
362 /*
363 * mpfixme: lock socketbuffer here
364 */
365 if (so->so_emuldata) {
359 return so->so_emuldata;
366 return so->so_emuldata;
367 }
360
361 /* Allocate a new one. */
362 st = malloc(sizeof(struct svr4_strm), M_TEMP, M_WAITOK);
363 st->s_family = so->so_proto->pr_domain->dom_family;
364 st->s_cmd = ~0;
365 st->s_afd = -1;
366 st->s_eventmask = 0;
368
369 /* Allocate a new one. */
370 st = malloc(sizeof(struct svr4_strm), M_TEMP, M_WAITOK);
371 st->s_family = so->so_proto->pr_domain->dom_family;
372 st->s_cmd = ~0;
373 st->s_afd = -1;
374 st->s_eventmask = 0;
367 so->so_emuldata = st;
368 fp->f_ops = &svr4_netops;
375 /*
376 * avoid a race where we loose due to concurrancy issues
377 * of two threads trying to allocate the so_emuldata.
378 */
379 if (so->so_emuldata) {
380 /* lost the race, use the existing emuldata */
381 FREE(st, M_TEMP);
382 st = so->so_emuldata;
383 } else {
384 /* we won, or there was no race, use our copy */
385 so->so_emuldata = st;
386 fp->f_ops = &svr4_netops;
387 }
369
370 return st;
371}
372
373void
374svr4_delete_socket(p, fp)
375 struct proc *p;
376 struct file *fp;

--- 24 unchanged lines hidden (view full) ---

401{
402 struct socket *so = (struct socket *)fp->f_data;
403
404 /* CHECKUNIT_DIAG(ENXIO);*/
405
406 svr4_delete_socket(td->td_proc, fp);
407 free(so->so_emuldata, M_TEMP);
408 return soo_close(fp, td);
388
389 return st;
390}
391
392void
393svr4_delete_socket(p, fp)
394 struct proc *p;
395 struct file *fp;

--- 24 unchanged lines hidden (view full) ---

420{
421 struct socket *so = (struct socket *)fp->f_data;
422
423 /* CHECKUNIT_DIAG(ENXIO);*/
424
425 svr4_delete_socket(td->td_proc, fp);
426 free(so->so_emuldata, M_TEMP);
427 return soo_close(fp, td);
409 return (0);
410}
428}