@@ -375,6 +375,7 @@ pipe_paircreate(struct thread *td, struct pipepair **p_pp)
375
375
#endif
376
376
rpipe = & pp -> pp_rpipe ;
377
377
wpipe = & pp -> pp_wpipe ;
378
+ pp -> pp_owner = crhold (td -> td_ucred );
378
379
379
380
knlist_init_mtx (& rpipe -> pipe_sel .si_note , PIPE_MTX (rpipe ));
380
381
knlist_init_mtx (& wpipe -> pipe_sel .si_note , PIPE_MTX (wpipe ));
@@ -408,6 +409,7 @@ pipe_paircreate(struct thread *td, struct pipepair **p_pp)
408
409
fail :
409
410
knlist_destroy (& rpipe -> pipe_sel .si_note );
410
411
knlist_destroy (& wpipe -> pipe_sel .si_note );
412
+ crfree (pp -> pp_owner );
411
413
#ifdef MAC
412
414
mac_pipe_destroy (pp );
413
415
#endif
@@ -574,9 +576,20 @@ pipespace_new(struct pipe *cpipe, int size)
574
576
size = round_page (size );
575
577
buffer = (caddr_t ) vm_map_min (pipe_map );
576
578
579
+ if (!chgpipecnt (cpipe -> pipe_pair -> pp_owner -> cr_ruidinfo ,
580
+ size , lim_cur (curthread , RLIMIT_PIPEBUF ))) {
581
+ if (cpipe -> pipe_buffer .buffer == NULL &&
582
+ size > SMALL_PIPE_SIZE ) {
583
+ size = SMALL_PIPE_SIZE ;
584
+ goto retry ;
585
+ }
586
+ return (ENOMEM );
587
+ }
588
+
577
589
error = vm_map_find (pipe_map , NULL , 0 , (vm_offset_t * )& buffer , size , 0 ,
578
590
VMFS_ANY_SPACE , VM_PROT_RW , VM_PROT_RW , 0 );
579
591
if (error != KERN_SUCCESS ) {
592
+ chgpipecnt (cpipe -> pipe_pair -> pp_owner -> cr_ruidinfo , - size , 0 );
580
593
if (cpipe -> pipe_buffer .buffer == NULL &&
581
594
size > SMALL_PIPE_SIZE ) {
582
595
size = SMALL_PIPE_SIZE ;
@@ -1645,6 +1658,8 @@ pipe_free_kmem(struct pipe *cpipe)
1645
1658
1646
1659
if (cpipe -> pipe_buffer .buffer != NULL ) {
1647
1660
atomic_subtract_long (& amountpipekva , cpipe -> pipe_buffer .size );
1661
+ chgpipecnt (cpipe -> pipe_pair -> pp_owner -> cr_uidinfo ,
1662
+ - cpipe -> pipe_buffer .size , 0 );
1648
1663
vm_map_remove (pipe_map ,
1649
1664
(vm_offset_t )cpipe -> pipe_buffer .buffer ,
1650
1665
(vm_offset_t )cpipe -> pipe_buffer .buffer + cpipe -> pipe_buffer .size );
@@ -1731,6 +1746,7 @@ pipeclose(struct pipe *cpipe)
1731
1746
*/
1732
1747
if (ppipe -> pipe_present == PIPE_FINALIZED ) {
1733
1748
PIPE_UNLOCK (cpipe );
1749
+ crfree (cpipe -> pipe_pair -> pp_owner );
1734
1750
#ifdef MAC
1735
1751
mac_pipe_destroy (pp );
1736
1752
#endif
0 commit comments