textpos = do_mmap(bprm->file, 0, text_len, PROT_READ|PROT_EXEC, 0, 0); 
textpos = do_mmap(bprm->file, 0, text_len, PROT_READ|PROT_EXEC, MAP_SHARED, 0); 
static int load_flat_file(struct linux_binprm * bprm,		struct lib_info *libinfo, int id, unsigned long *extra_stack){	struct flat_hdr * hdr;	unsigned long textpos = 0, datapos = 0, result;	unsigned long realdatastart = 0;	unsigned long text_len, data_len, bss_len, stack_len, flags;	unsigned long memp = 0; /* for finding the brk area */	unsigned long extra, rlim;	unsigned long *reloc = 0, *rp;	struct inode *inode;	int i, rev, relocs = 0;	loff_t fpos;	unsigned long start_code, end_code;	hdr = ((struct flat_hdr *) bprm->buf);		/* exec-header */	inode = bprm->file->f_dentry->d_inode;	text_len  = ntohl(hdr->data_start);	data_len  = ntohl(hdr->data_end) - ntohl(hdr->data_start);	bss_len   = ntohl(hdr->bss_end) - ntohl(hdr->data_end);	stack_len = ntohl(hdr->stack_size);	if (extra_stack) {		stack_len += *extra_stack;		*extra_stack = stack_len;	}	relocs    = ntohl(hdr->reloc_count);	flags     = ntohl(hdr->flags);	rev       = ntohl(hdr->rev);	if (flags & FLAT_FLAG_KTRACE)		printk("BINFMT_FLAT: Loading file: %s\n", bprm->filename);	if (strncmp(hdr->magic, "bFLT", 4) ||			(rev != FLAT_VERSION && rev != OLD_FLAT_VERSION)) {		/*		 * because a lot of people do not manage to produce good		 * flat binaries,  we leave this printk to help them realise		 * the problem.  We only print the error if its not a script file		 */		if (strncmp(hdr->magic, "#!", 2))			printk("BINFMT_FLAT: bad magic/rev (0x%x, need 0x%x)\n",					rev, (int) FLAT_VERSION);		return -ENOEXEC;	}		/* Don't allow old format executables to use shared libraries */	if (rev == OLD_FLAT_VERSION && id != 0) {		printk("BINFMT_FLAT: shared libraries are not available before rev 0x%x\n",				(int) FLAT_VERSION);		return -ENOEXEC;	}	/*	 * fix up the flags for the older format,  there were all kinds	 * of endian hacks,  this only works for the simple cases	 */	if (rev == OLD_FLAT_VERSION && flat_old_ram_flag(flags))		flags = FLAT_FLAG_RAM;#ifndef CONFIG_BINFMT_ZFLAT	if (flags & (FLAT_FLAG_GZIP|FLAT_FLAG_GZDATA)) {		printk("Support for ZFLAT executables is not enabled.\n");		return -ENOEXEC;	}#endif	/*	 * Check initial limits. This avoids letting people circumvent	 * size limits imposed on them by creating programs with large	 * arrays in the data or bss.	 */	rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;	if (rlim >= RLIM_INFINITY)		rlim = ~0;	if (data_len + bss_len > rlim)		return -ENOMEM;	/* Flush all traces of the currently running executable */	if (id == 0) {		result = flush_old_exec(bprm);		if (result)			return result;		/* OK, This is the point of no return */		set_personality(PER_LINUX);	}	/*	 * calculate the extra space we need to map in	 */	extra = max(bss_len + stack_len, relocs * sizeof(unsigned long));	/*	 * there are a couple of cases here,  the separate code/data	 * case,  and then the fully copied to RAM case which lumps	 * it all together.	 */	if ((flags & (FLAT_FLAG_RAM|FLAT_FLAG_GZIP)) == 0) {		/*		 * this should give us a ROM ptr,  but if it doesn't we don't		 * really care		 */		DBG_FLT("BINFMT_FLAT: ROM mapping of file (we hope)\n");		down_write(&current->mm->mmap_sem);		textpos = do_mmap(bprm->file, 0, text_len, PROT_READ|PROT_EXEC, 0, 0);		up_write(&current->mm->mmap_sem);		if (!textpos  || textpos >= (unsigned long) -4096) {			if (!textpos)				textpos = (unsigned long) -ENOMEM;			printk("Unable to mmap process text, errno %d\n", (int)-textpos);			return(textpos);		}		down_write(&current->mm->mmap_sem);		realdatastart = do_mmap(0, 0, data_len + extra +				MAX_SHARED_LIBS * sizeof(unsigned long),				PROT_READ|PROT_WRITE|PROT_EXEC, 0, 0);		up_write(&current->mm->mmap_sem);		if (realdatastart == 0 || realdatastart >= (unsigned long)-4096) {			if (!realdatastart)				realdatastart = (unsigned long) -ENOMEM;			printk("Unable to allocate RAM for process data, errno %d\n",					(int)-datapos);			do_munmap(current->mm, textpos, text_len);			return realdatastart;		}		datapos = realdatastart + MAX_SHARED_LIBS * sizeof(unsigned long);		DBG_FLT("BINFMT_FLAT: Allocated data+bss+stack (%d bytes): %x\n",				(int)(data_len + bss_len + stack_len), (int)datapos);		fpos = ntohl(hdr->data_start);#ifdef CONFIG_BINFMT_ZFLAT		if (flags & FLAT_FLAG_GZDATA) {			result = decompress_exec(bprm, fpos, (char *) datapos, 						 data_len + (relocs * sizeof(unsigned long)), 0);		} else#endif		{			result = bprm->file->f_op->read(bprm->file, (char *) datapos,					data_len + (relocs * sizeof(unsigned long)), &fpos);		}		if (result >= (unsigned long)-4096) {			printk("Unable to read data+bss, errno %d\n", (int)-result);			do_munmap(current->mm, textpos, text_len);			do_munmap(current->mm, realdatastart, data_len + extra);			return result;		}		reloc = (unsigned long *) (datapos+(ntohl(hdr->reloc_start)-text_len));		memp = realdatastart;	} else {		down_write(&current->mm->mmap_sem);		textpos = do_mmap(0, 0, text_len + data_len + extra +					MAX_SHARED_LIBS * sizeof(unsigned long),				PROT_READ | PROT_EXEC | PROT_WRITE, 0, 0);		up_write(&current->mm->mmap_sem);		if (!textpos  || textpos >= (unsigned long) -4096) {			if (!textpos)				textpos = (unsigned long) -ENOMEM;			printk("Unable to allocate RAM for process text/data, errno %d\n",					(int)-textpos);			return(textpos);		}		realdatastart = textpos + ntohl(hdr->data_start);		datapos = realdatastart + MAX_SHARED_LIBS * sizeof(unsigned long);		reloc = (unsigned long *) (textpos + ntohl(hdr->reloc_start) +				MAX_SHARED_LIBS * sizeof(unsigned long));		memp = textpos;#ifdef CONFIG_BINFMT_ZFLAT		/*		 * load it all in and treat it like a RAM load from now on		 */		if (flags & FLAT_FLAG_GZIP) {			result = decompress_exec(bprm, sizeof (struct flat_hdr),					 (((char *) textpos) + sizeof (struct flat_hdr)),					 (text_len + data_len + (relocs * sizeof(unsigned long))						  - sizeof (struct flat_hdr)),					 0);			memmove((void *) datapos, (void *) realdatastart,					data_len + (relocs * sizeof(unsigned long)));		} else if (flags & FLAT_FLAG_GZDATA) {			fpos = 0;			result = bprm->file->f_op->read(bprm->file,					(char *) textpos, text_len, &fpos);			if (result < (unsigned long) -4096)				result = decompress_exec(bprm, text_len, (char *) datapos,						 data_len + (relocs * sizeof(unsigned long)), 0);		}		else#endif		{			fpos = 0;			result = bprm->file->f_op->read(bprm->file,					(char *) textpos, text_len, &fpos);			if (result < (unsigned long) -4096) {				fpos = ntohl(hdr->data_start);				result = bprm->file->f_op->read(bprm->file, (char *) datapos,					data_len + (relocs * sizeof(unsigned long)), &fpos);			}		}		if (result >= (unsigned long)-4096) {			printk("Unable to read code+data+bss, errno %d\n",(int)-result);			do_munmap(current->mm, textpos, text_len + data_len + extra +				MAX_SHARED_LIBS * sizeof(unsigned long));			return result;		}	}	if (flags & FLAT_FLAG_KTRACE)		printk("Mapping is %x, Entry point is %x, data_start is %x\n",			(int)textpos, 0x00ffffff&ntohl(hdr->entry), ntohl(hdr->data_start));	/* The main program needs a little extra setup in the task structure */	start_code = textpos + sizeof (struct flat_hdr);	end_code = textpos + text_len;	if (id == 0) {		current->mm->start_code = start_code;		current->mm->end_code = end_code;		current->mm->start_data = datapos;		current->mm->end_data = datapos + data_len;		/*		 * set up the brk stuff, uses any slack left in data/bss/stack		 * allocation.  We put the brk after the bss (between the bss		 * and stack) like other platforms.		 */		current->mm->start_brk = datapos + data_len + bss_len;		current->mm->brk = (current->mm->start_brk + 3) & ~3;		current->mm->context.end_brk = memp + ksize((void *) memp) - stack_len;		set_mm_counter(current->mm, rss, 0);	}	if (flags & FLAT_FLAG_KTRACE)		printk("%s %s: TEXT=%x-%x DATA=%x-%x BSS=%x-%x\n",			id ? "Lib" : "Load", bprm->filename,			(int) start_code, (int) end_code,			(int) datapos,			(int) (datapos + data_len),			(int) (datapos + data_len),			(int) (((datapos + data_len + bss_len) + 3) & ~3));	text_len -= sizeof(struct flat_hdr); /* the real code len */	/* Store the current module values into the global library structure */	libinfo->lib_list[id].start_code = start_code;	libinfo->lib_list[id].start_data = datapos;	libinfo->lib_list[id].start_brk = datapos + data_len + bss_len;	libinfo->lib_list[id].text_len = text_len;	libinfo->lib_list[id].loaded = 1;	libinfo->lib_list[id].entry = (0x00ffffff & ntohl(hdr->entry)) + textpos;	libinfo->lib_list[id].build_date = ntohl(hdr->build_date);		/*	 * We just load the allocations into some temporary memory to	 * help simplify all this mumbo jumbo	 *	 * We've got two different sections of relocation entries.	 * The first is the GOT which resides at the begining of the data segment	 * and is terminated with a -1.  This one can be relocated in place.	 * The second is the extra relocation entries tacked after the image's	 * data segment. These require a little more processing as the entry is	 * really an offset into the image which contains an offset into the	 * image.	 */	if (flags & FLAT_FLAG_GOTPIC) {		for (rp = (unsigned long *)datapos; *rp != 0xffffffff; rp++) {			unsigned long addr;			if (*rp) {				addr = calc_reloc(*rp, libinfo, id, 0);				if (addr == RELOC_FAILED)					return -ENOEXEC;				*rp = addr;			}		}	}	/*	 * Now run through the relocation entries.	 * We've got to be careful here as C++ produces relocatable zero	 * entries in the constructor and destructor tables which are then	 * tested for being not zero (which will always occur unless we're	 * based from address zero).  This causes an endless loop as __start	 * is at zero.  The solution used is to not relocate zero addresses.	 * This has the negative side effect of not allowing a global data	 * reference to be statically initialised to _stext (I've moved	 * __start to address 4 so that is okay).	 */	if (rev > OLD_FLAT_VERSION) {		for (i=0; i < relocs; i++) {			unsigned long addr, relval;			/* Get the address of the pointer to be			   relocated (of course, the address has to be			   relocated first).  */			relval = ntohl(reloc[i]);			addr = flat_get_relocate_addr(relval);			rp = (unsigned long *) calc_reloc(addr, libinfo, id, 1);			if (rp == (unsigned long *)RELOC_FAILED)				return -ENOEXEC;			/* Get the pointer's value.  */			addr = flat_get_addr_from_rp(rp, relval, flags);			if (addr != 0) {				/*				 * Do the relocation.  PIC relocs in the data section are				 * already in target order				 */				if ((flags & FLAT_FLAG_GOTPIC) == 0)					addr = ntohl(addr);				addr = calc_reloc(addr, libinfo, id, 0);				if (addr == RELOC_FAILED)					return -ENOEXEC;				/* Write back the relocated pointer.  */				flat_put_addr_at_rp(rp, addr, relval);			}		}	} else {		for (i=0; i < relocs; i++)			old_reloc(ntohl(reloc[i]));	}		flush_icache_range(start_code, end_code);	/* zero the BSS,  BRK and stack areas */	memset((void*)(datapos + data_len), 0, bss_len + 			(memp + ksize((void *) memp) - stack_len -	/* end brk */			libinfo->lib_list[id].start_brk) +		/* start brk */			stack_len);	return 0;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/8f5bb0438b86d1a5393176ceeec2836fd469edf8/binfmt_flat.c/clean/fs/binfmt_flat.c