diff -ur -Xcludes uClinux-2.4.x/arch/v850/kernel/bug.c test-oolb/uClinux-2.4.x/arch/v850/kernel/bug.c --- uClinux-2.4.x/arch/v850/kernel/bug.c Fri Jan 11 11:07:31 2002 +++ test-oolb/uClinux-2.4.x/arch/v850/kernel/bug.c Mon Mar 25 13:42:45 2002 @@ -1,8 +1,8 @@ /* * arch/v850/kernel/bug.c -- Bug reporting functions * - * Copyright (C) 2001 NEC Corporation - * Copyright (C) 2001 Miles Bader + * Copyright (C) 2001, 2002 NEC Corporation + * Copyright (C) 2001, 2002 Miles Bader * * This file is subject to the terms and conditions of the GNU General * Public License. See the file COPYING in the main directory of this @@ -29,6 +29,17 @@ machine_halt (); } + + +/* We define `out_of_line_bug' for inline functions in header files to use. + There might be an arch-independent version of `out_of_line_bug', so + avoid interfering with it, if it exists. */ +void out_of_line_bug (void) __attribute__ ((weak, noreturn)); +void out_of_line_bug (void) +{ + BUG(); +} + int bad_trap (int trap_num, struct pt_regs *regs) { diff -ur -Xcludes uClinux-2.4.x/fs/open.c test-oolb/uClinux-2.4.x/fs/open.c --- uClinux-2.4.x/fs/open.c Mon Jan 7 12:04:02 2002 +++ test-oolb/uClinux-2.4.x/fs/open.c Mon Mar 25 13:10:55 2002 @@ -71,6 +71,30 @@ return error; } +/* + * Install a file pointer in the fd array. + * + * The VFS is full of places where we drop the files lock between + * setting the open_fds bitmap and installing the file in the file + * array. At any such point, we are vulnerable to a dup2() race + * installing a file in the array before us. We need to detect this and + * fput() the struct file we are about to overwrite in this case. + * + * It should never happen - if we allow dup2() do it, _really_ bad things + * will follow. + */ + +void fd_install(unsigned int fd, struct file * file) +{ + struct files_struct *files = current->files; + + write_lock(&files->file_lock); + if (files->fd[fd]) + BUG(); + files->fd[fd] = file; + write_unlock(&files->file_lock); +} + int do_truncate(struct dentry *dentry, loff_t length) { struct inode *inode = dentry->d_inode; diff -ur -Xcludes uClinux-2.4.x/include/asm-i386/highmem.h test-oolb/uClinux-2.4.x/include/asm-i386/highmem.h --- uClinux-2.4.x/include/asm-i386/highmem.h Mon Jan 7 12:13:20 2002 +++ test-oolb/uClinux-2.4.x/include/asm-i386/highmem.h Mon Mar 25 13:10:54 2002 @@ -62,7 +62,7 @@ static inline void *kmap(struct page *page) { if (in_interrupt()) - BUG(); + out_of_line_bug(); if (page < highmem_start_page) return page_address(page); return kmap_high(page); @@ -71,7 +71,7 @@ static inline void kunmap(struct page *page) { if (in_interrupt()) - BUG(); + out_of_line_bug(); if (page < highmem_start_page) return; kunmap_high(page); @@ -95,7 +95,7 @@ vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx); #if HIGHMEM_DEBUG if (!pte_none(*(kmap_pte-idx))) - BUG(); + out_of_line_bug(); #endif set_pte(kmap_pte-idx, mk_pte(page, kmap_prot)); __flush_tlb_one(vaddr); @@ -113,7 +113,7 @@ return; if (vaddr != __fix_to_virt(FIX_KMAP_BEGIN+idx)) - BUG(); + out_of_line_bug(); /* * force other mappings to Oops if they'll try to access diff -ur -Xcludes uClinux-2.4.x/include/asm-i386/mmu_context.h test-oolb/uClinux-2.4.x/include/asm-i386/mmu_context.h --- uClinux-2.4.x/include/asm-i386/mmu_context.h Fri Sep 28 19:15:24 2001 +++ test-oolb/uClinux-2.4.x/include/asm-i386/mmu_context.h Mon Mar 25 13:10:54 2002 @@ -48,7 +48,7 @@ else { cpu_tlbstate[cpu].state = TLBSTATE_OK; if(cpu_tlbstate[cpu].active_mm != next) - BUG(); + out_of_line_bug(); if(!test_and_set_bit(cpu, &next->cpu_vm_mask)) { /* We were in lazy tlb mode and leave_mm disabled * tlb flush IPI delivery. We must flush our tlb. diff -ur -Xcludes uClinux-2.4.x/include/asm-i386/pci.h test-oolb/uClinux-2.4.x/include/asm-i386/pci.h --- uClinux-2.4.x/include/asm-i386/pci.h Mon Jan 7 12:13:21 2002 +++ test-oolb/uClinux-2.4.x/include/asm-i386/pci.h Mon Mar 25 13:10:54 2002 @@ -73,7 +73,7 @@ size_t size, int direction) { if (direction == PCI_DMA_NONE) - BUG(); + out_of_line_bug(); flush_write_buffers(); return virt_to_bus(ptr); } @@ -89,7 +89,7 @@ size_t size, int direction) { if (direction == PCI_DMA_NONE) - BUG(); + out_of_line_bug(); /* Nothing to do */ } @@ -101,7 +101,7 @@ unsigned long offset, size_t size, int direction) { if (direction == PCI_DMA_NONE) - BUG(); + out_of_line_bug(); return (page - mem_map) * PAGE_SIZE + offset; } @@ -110,7 +110,7 @@ size_t size, int direction) { if (direction == PCI_DMA_NONE) - BUG(); + out_of_line_bug(); /* Nothing to do */ } @@ -135,16 +135,16 @@ int i; if (direction == PCI_DMA_NONE) - BUG(); + out_of_line_bug(); /* * temporary 2.4 hack */ for (i = 0; i < nents; i++ ) { if (sg[i].address && sg[i].page) - BUG(); + out_of_line_bug(); else if (!sg[i].address && !sg[i].page) - BUG(); + out_of_line_bug(); if (sg[i].address) sg[i].dma_address = virt_to_bus(sg[i].address); @@ -164,7 +164,7 @@ int nents, int direction) { if (direction == PCI_DMA_NONE) - BUG(); + out_of_line_bug(); /* Nothing to do */ } @@ -182,7 +182,7 @@ size_t size, int direction) { if (direction == PCI_DMA_NONE) - BUG(); + out_of_line_bug(); flush_write_buffers(); } @@ -197,7 +197,7 @@ int nelems, int direction) { if (direction == PCI_DMA_NONE) - BUG(); + out_of_line_bug(); flush_write_buffers(); } diff -ur -Xcludes uClinux-2.4.x/include/asm-i386/smplock.h test-oolb/uClinux-2.4.x/include/asm-i386/smplock.h --- uClinux-2.4.x/include/asm-i386/smplock.h Fri Sep 28 19:15:25 2001 +++ test-oolb/uClinux-2.4.x/include/asm-i386/smplock.h Mon Mar 25 13:10:54 2002 @@ -59,7 +59,7 @@ static __inline__ void unlock_kernel(void) { if (current->lock_depth < 0) - BUG(); + out_of_line_bug(); #if 1 if (--current->lock_depth < 0) spin_unlock(&kernel_flag); diff -ur -Xcludes uClinux-2.4.x/include/asm-v850/page.h test-oolb/uClinux-2.4.x/include/asm-v850/page.h --- uClinux-2.4.x/include/asm-v850/page.h Mon Oct 22 22:39:02 2001 +++ test-oolb/uClinux-2.4.x/include/asm-v850/page.h Mon Mar 25 13:27:17 2002 @@ -1,8 +1,8 @@ /* * include/asm-v850/page.h -- VM ops * - * Copyright (C) 2001 NEC Corporation - * Copyright (C) 2001 Miles Bader + * Copyright (C) 2001, 2002 NEC Corporation + * Copyright (C) 2001, 2002 Miles Bader * * This file is subject to the terms and conditions of the GNU General * Public License. See the file COPYING in the main directory of this @@ -92,6 +92,7 @@ #ifndef __ASSEMBLY__ extern void __bug(const char *file, int line, void *data); +extern void out_of_line_bug(void) __attribute ((noreturn)); #define BUG() __bug(__FILE__, __LINE__, NULL) #define PAGE_BUG(page) __bug(__FILE__, __LINE__, page) diff -ur -Xcludes uClinux-2.4.x/include/asm-v850/pgalloc.h test-oolb/uClinux-2.4.x/include/asm-v850/pgalloc.h --- uClinux-2.4.x/include/asm-v850/pgalloc.h Fri Jan 18 15:23:58 2002 +++ test-oolb/uClinux-2.4.x/include/asm-v850/pgalloc.h Mon Mar 25 13:28:19 2002 @@ -1,8 +1,8 @@ /* * include/asm-v850/pgalloc.h * - * Copyright (C) 2001 NEC Corporation - * Copyright (C) 2001 Miles Bader + * Copyright (C) 2001, 2002 NEC Corporation + * Copyright (C) 2001, 2002 Miles Bader * * This file is subject to the terms and conditions of the GNU General * Public License. See the file COPYING in the main directory of this @@ -44,12 +44,12 @@ */ static inline void __flush_tlb(void) { - BUG(); + out_of_line_bug (); } static inline void __flush_tlb_one(unsigned long addr) { - BUG(); + out_of_line_bug (); } #define flush_tlb() __flush_tlb() @@ -59,34 +59,34 @@ */ static inline void flush_tlb_all(void) { - BUG(); + out_of_line_bug (); } static inline void flush_tlb_mm(struct mm_struct *mm) { - BUG(); + out_of_line_bug (); } static inline void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr) { - BUG(); + out_of_line_bug (); } static inline void flush_tlb_range(struct mm_struct *mm, unsigned long start, unsigned long end) { - BUG(); + out_of_line_bug (); } extern inline void flush_tlb_kernel_page(unsigned long addr) { - BUG(); + out_of_line_bug (); } extern inline void flush_tlb_pgtables(struct mm_struct *mm, unsigned long start, unsigned long end) { - BUG(); + out_of_line_bug (); } #endif /* _V850_PGALLOC_H */ diff -ur -Xcludes uClinux-2.4.x/include/asm-v850/pgtable.h test-oolb/uClinux-2.4.x/include/asm-v850/pgtable.h --- uClinux-2.4.x/include/asm-v850/pgtable.h Fri Jan 11 11:07:39 2002 +++ test-oolb/uClinux-2.4.x/include/asm-v850/pgtable.h Mon Mar 25 13:28:25 2002 @@ -4,7 +4,7 @@ #include #include -#define page_address(page) ({ if (!(page)->virtual) BUG(); (page)->virtual;}) +#define page_address(page) ({ if (!(page)->virtual) out_of_line_bug(); (page)->virtual;}) #define __page_address(page) (PAGE_OFFSET + (((page) - mem_map) << PAGE_SHIFT)) #define pgd_present(pgd) (1) /* pages are always present on NO_MM */ #define kern_addr_valid(addr) (1) diff -ur -Xcludes uClinux-2.4.x/include/linux/dcache.h test-oolb/uClinux-2.4.x/include/linux/dcache.h --- uClinux-2.4.x/include/linux/dcache.h Thu Feb 28 13:27:13 2002 +++ test-oolb/uClinux-2.4.x/include/linux/dcache.h Mon Mar 25 13:10:54 2002 @@ -242,11 +242,8 @@ static __inline__ struct dentry * dget(struct dentry *dentry) { - if (dentry) { - if (!atomic_read(&dentry->d_count)) - BUG(); + if (dentry) atomic_inc(&dentry->d_count); - } return dentry; } diff -ur -Xcludes uClinux-2.4.x/include/linux/file.h test-oolb/uClinux-2.4.x/include/linux/file.h --- uClinux-2.4.x/include/linux/file.h Thu Aug 24 03:22:26 2000 +++ test-oolb/uClinux-2.4.x/include/linux/file.h Mon Mar 25 13:10:54 2002 @@ -71,30 +71,7 @@ write_unlock(&files->file_lock); } -/* - * Install a file pointer in the fd array. - * - * The VFS is full of places where we drop the files lock between - * setting the open_fds bitmap and installing the file in the file - * array. At any such point, we are vulnerable to a dup2() race - * installing a file in the array before us. We need to detect this and - * fput() the struct file we are about to overwrite in this case. - * - * It should never happen - if we allow dup2() do it, _really_ bad things - * will follow. - */ - -static inline void fd_install(unsigned int fd, struct file * file) -{ - struct files_struct *files = current->files; - - write_lock(&files->file_lock); - if (files->fd[fd]) - BUG(); - files->fd[fd] = file; - write_unlock(&files->file_lock); -} - +void fd_install(unsigned int fd, struct file * file); void put_files_struct(struct files_struct *fs); #endif /* __LINUX_FILE_H */ diff -ur -Xcludes uClinux-2.4.x/include/linux/highmem.h test-oolb/uClinux-2.4.x/include/linux/highmem.h --- uClinux-2.4.x/include/linux/highmem.h Fri Jan 18 15:23:58 2002 +++ test-oolb/uClinux-2.4.x/include/linux/highmem.h Mon Mar 25 13:34:42 2002 @@ -60,8 +60,6 @@ { char *kaddr; - if (offset + size > PAGE_SIZE) - BUG(); kaddr = kmap(page); memset(kaddr + offset, 0, size); kunmap(page); @@ -75,7 +73,7 @@ char *kaddr; if (offset + size > PAGE_SIZE) - BUG(); + out_of_line_bug (); kaddr = kmap(page); memset(kaddr + offset, 0, size); flush_page_to_ram(page); diff -ur -Xcludes uClinux-2.4.x/include/linux/kernel.h test-oolb/uClinux-2.4.x/include/linux/kernel.h --- uClinux-2.4.x/include/linux/kernel.h Thu Jan 17 10:34:24 2002 +++ test-oolb/uClinux-2.4.x/include/linux/kernel.h Mon Mar 25 13:13:56 2002 @@ -176,4 +176,6 @@ char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */ }; +extern void out_of_line_bug(void) ATTRIB_NORET; + #endif diff -ur -Xcludes uClinux-2.4.x/include/linux/nfs_fs.h test-oolb/uClinux-2.4.x/include/linux/nfs_fs.h --- uClinux-2.4.x/include/linux/nfs_fs.h Thu Mar 7 10:44:50 2002 +++ test-oolb/uClinux-2.4.x/include/linux/nfs_fs.h Mon Mar 25 13:34:50 2002 @@ -168,7 +168,7 @@ struct rpc_cred *cred = (struct rpc_cred *)(file->private_data); #ifdef RPC_DEBUG if (cred && cred->cr_magic != RPCAUTH_CRED_MAGIC) - BUG(); + out_of_line_bug(); #endif return cred; } diff -ur -Xcludes uClinux-2.4.x/include/linux/quotaops.h test-oolb/uClinux-2.4.x/include/linux/quotaops.h --- uClinux-2.4.x/include/linux/quotaops.h Thu Mar 7 10:46:32 2002 +++ test-oolb/uClinux-2.4.x/include/linux/quotaops.h Mon Mar 25 13:29:58 2002 @@ -40,8 +40,6 @@ static __inline__ void DQUOT_INIT(struct inode *inode) { - if (!inode->i_sb) - BUG(); lock_kernel(); if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode)) inode->i_sb->dq_op->initialize(inode, -1); @@ -51,11 +49,8 @@ static __inline__ void DQUOT_DROP(struct inode *inode) { lock_kernel(); - if (IS_QUOTAINIT(inode)) { - if (!inode->i_sb) - BUG(); + if (IS_QUOTAINIT(inode)) inode->i_sb->dq_op->drop(inode); /* Ops must be set when there's any quota... */ - } unlock_kernel(); } diff -ur -Xcludes uClinux-2.4.x/include/linux/sched.h test-oolb/uClinux-2.4.x/include/linux/sched.h --- uClinux-2.4.x/include/linux/sched.h Thu Mar 7 10:44:35 2002 +++ test-oolb/uClinux-2.4.x/include/linux/sched.h Mon Mar 25 13:28:52 2002 @@ -939,7 +939,6 @@ static inline void unhash_process(struct task_struct *p) { - if (task_on_runqueue(p)) BUG(); write_lock_irq(&tasklist_lock); nr_threads--; unhash_pid(p); diff -ur -Xcludes uClinux-2.4.x/include/linux/skbuff.h test-oolb/uClinux-2.4.x/include/linux/skbuff.h --- uClinux-2.4.x/include/linux/skbuff.h Thu Mar 7 10:45:18 2002 +++ test-oolb/uClinux-2.4.x/include/linux/skbuff.h Mon Mar 25 13:34:52 2002 @@ -756,9 +756,9 @@ return skb->len - skb->data_len; } -#define SKB_PAGE_ASSERT(skb) do { if (skb_shinfo(skb)->nr_frags) BUG(); } while (0) -#define SKB_FRAG_ASSERT(skb) do { if (skb_shinfo(skb)->frag_list) BUG(); } while (0) -#define SKB_LINEAR_ASSERT(skb) do { if (skb_is_nonlinear(skb)) BUG(); } while (0) +#define SKB_PAGE_ASSERT(skb) do { if (skb_shinfo(skb)->nr_frags) out_of_line_bug(); } while (0) +#define SKB_FRAG_ASSERT(skb) do { if (skb_shinfo(skb)->frag_list) out_of_line_bug(); } while (0) +#define SKB_LINEAR_ASSERT(skb) do { if (skb_is_nonlinear(skb)) out_of_line_bug(); } while (0) /* * Add data to an sk_buff @@ -825,8 +825,6 @@ static inline char *__skb_pull(struct sk_buff *skb, unsigned int len) { skb->len-=len; - if (skb->len < skb->data_len) - BUG(); return skb->data+=len; } @@ -1094,7 +1092,7 @@ { #ifdef CONFIG_HIGHMEM if (in_irq()) - BUG(); + out_of_line_bug(); local_bh_disable(); #endif diff -ur -Xcludes uClinux-2.4.x/include/net/tcp.h test-oolb/uClinux-2.4.x/include/net/tcp.h --- uClinux-2.4.x/include/net/tcp.h Thu Mar 7 10:47:07 2002 +++ test-oolb/uClinux-2.4.x/include/net/tcp.h Mon Mar 25 13:35:45 2002 @@ -1329,8 +1329,6 @@ if (tp->ucopy.memory > sk->rcvbuf) { struct sk_buff *skb1; - if (sk->lock.users) BUG(); - while ((skb1 = __skb_dequeue(&tp->ucopy.prequeue)) != NULL) { sk->backlog_rcv(sk, skb1); NET_INC_STATS_BH(TCPPrequeueDropped); diff -ur -Xcludes uClinux-2.4.x/kernel/ksyms.c test-oolb/uClinux-2.4.x/kernel/ksyms.c --- uClinux-2.4.x/kernel/ksyms.c Mon Jan 7 12:16:09 2002 +++ test-oolb/uClinux-2.4.x/kernel/ksyms.c Mon Mar 25 13:10:55 2002 @@ -172,6 +172,7 @@ EXPORT_SYMBOL(set_buffer_async_io); /* for reiserfs_writepage */ EXPORT_SYMBOL(__mark_buffer_dirty); EXPORT_SYMBOL(__mark_inode_dirty); +EXPORT_SYMBOL(fd_install); EXPORT_SYMBOL(get_empty_filp); EXPORT_SYMBOL(init_private_file); EXPORT_SYMBOL(filp_open); @@ -462,6 +463,7 @@ /* misc */ EXPORT_SYMBOL(panic); +EXPORT_SYMBOL(out_of_line_bug); EXPORT_SYMBOL(sprintf); EXPORT_SYMBOL(snprintf); EXPORT_SYMBOL(sscanf); diff -ur -Xcludes uClinux-2.4.x/kernel/panic.c test-oolb/uClinux-2.4.x/kernel/panic.c --- uClinux-2.4.x/kernel/panic.c Mon Jan 7 12:16:09 2002 +++ test-oolb/uClinux-2.4.x/kernel/panic.c Mon Mar 25 13:10:55 2002 @@ -120,3 +120,21 @@ } int tainted = 0; + +/* + * A BUG() call in an inline function in a header should be avoided, + * because it can seriously bloat the kernel. So here we have + * helper functions. + * We lose the BUG()-time file-and-line info this way, but it's + * usually not very useful from an inline anyway. The backtrace + * tells us what we want to know. + */ + +void out_of_line_bug(void) +{ + BUG(); + + /* Satisfy __attribute__((noreturn)) */ + for ( ; ; ) + ; +}