Print this page
11927 Log, or optionally panic, on zero-length kmem allocations
Reviewed by: Dan McDonald <danmcd@joyent.com>
Reviewed by: Jason King <jason.brian.king@gmail.com>


 835 }
 836 
 837 /*
 838  * Duplicate all file descriptors across a fork.
 839  */
 840 void
 841 flist_fork(uf_info_t *pfip, uf_info_t *cfip)
 842 {
 843         int fd, nfiles;
 844         uf_entry_t *pufp, *cufp;
 845 
 846         mutex_init(&cfip->fi_lock, NULL, MUTEX_DEFAULT, NULL);
 847         cfip->fi_rlist = NULL;
 848 
 849         /*
 850          * We don't need to hold fi_lock because all other lwp's in the
 851          * parent have been held.
 852          */
 853         cfip->fi_nfiles = nfiles = flist_minsize(pfip);
 854 
 855         cfip->fi_list = kmem_zalloc(nfiles * sizeof (uf_entry_t), KM_SLEEP);

 856 
 857         for (fd = 0, pufp = pfip->fi_list, cufp = cfip->fi_list; fd < nfiles;
 858             fd++, pufp++, cufp++) {
 859                 cufp->uf_file = pufp->uf_file;
 860                 cufp->uf_alloc = pufp->uf_alloc;
 861                 cufp->uf_flag = pufp->uf_flag;
 862                 cufp->uf_busy = pufp->uf_busy;
 863                 if (pufp->uf_file == NULL) {
 864                         ASSERT(pufp->uf_flag == 0);
 865                         if (pufp->uf_busy) {
 866                                 /*
 867                                  * Grab locks to appease ASSERTs in fd_reserve
 868                                  */
 869                                 mutex_enter(&cfip->fi_lock);
 870                                 mutex_enter(&cufp->uf_lock);
 871                                 fd_reserve(cfip, fd, -1);
 872                                 mutex_exit(&cufp->uf_lock);
 873                                 mutex_exit(&cfip->fi_lock);
 874                         }
 875                 }




 835 }
 836 
 837 /*
 838  * Duplicate all file descriptors across a fork.
 839  */
 840 void
 841 flist_fork(uf_info_t *pfip, uf_info_t *cfip)
 842 {
 843         int fd, nfiles;
 844         uf_entry_t *pufp, *cufp;
 845 
 846         mutex_init(&cfip->fi_lock, NULL, MUTEX_DEFAULT, NULL);
 847         cfip->fi_rlist = NULL;
 848 
 849         /*
 850          * We don't need to hold fi_lock because all other lwp's in the
 851          * parent have been held.
 852          */
 853         cfip->fi_nfiles = nfiles = flist_minsize(pfip);
 854 
 855         cfip->fi_list = nfiles == 0 ? NULL :
 856             kmem_zalloc(nfiles * sizeof (uf_entry_t), KM_SLEEP);
 857 
 858         for (fd = 0, pufp = pfip->fi_list, cufp = cfip->fi_list; fd < nfiles;
 859             fd++, pufp++, cufp++) {
 860                 cufp->uf_file = pufp->uf_file;
 861                 cufp->uf_alloc = pufp->uf_alloc;
 862                 cufp->uf_flag = pufp->uf_flag;
 863                 cufp->uf_busy = pufp->uf_busy;
 864                 if (pufp->uf_file == NULL) {
 865                         ASSERT(pufp->uf_flag == 0);
 866                         if (pufp->uf_busy) {
 867                                 /*
 868                                  * Grab locks to appease ASSERTs in fd_reserve
 869                                  */
 870                                 mutex_enter(&cfip->fi_lock);
 871                                 mutex_enter(&cufp->uf_lock);
 872                                 fd_reserve(cfip, fd, -1);
 873                                 mutex_exit(&cufp->uf_lock);
 874                                 mutex_exit(&cfip->fi_lock);
 875                         }
 876                 }