rem: fd = sys_open(path, STREAM_TYPE_FILE, 0);
add: fd = sys_open(path, 0);
context: int elf_load_uspace(const char *path, struct proc *p, int flags, addr *entry){	struct Elf32_Ehdr eheader;	struct Elf32_Phdr *pheaders = NULL;	int fd;	int err;	int i;	ssize_t len;	dprintf("elf_load: entry path '%s', proc %p\n", path, p);	fd = sys_open(path, STREAM_TYPE_FILE, 0);	if(fd < 0)		return fd;			len = sys_read(fd, &eheader, 0, sizeof(eheader));	if(len < 0) {		err = len;		goto error;	}	if(len != sizeof(eheader)) {		// short read		err = ERR_INVALID_BINARY;		goto error;	}	err = verify_eheader(&eheader);	if(err < 0)		goto error;	pheaders = (struct Elf32_Phdr *)kmalloc(eheader.e_phnum * eheader.e_phentsize);	if(pheaders == NULL) {		dprintf("error allocating space for program headers\n");		err = ERR_NO_MEMORY;		goto error;	}	dprintf("reading in program headers at 0x%x, len 0x%x\n", eheader.e_phoff, eheader.e_phnum * eheader.e_phentsize);	len = sys_read(fd, pheaders, eheader.e_phoff, eheader.e_phnum * eheader.e_phentsize);	if(len < 0) {		err = len;		dprintf("error reading in program headers\n");		goto error;	}	if(len != eheader.e_phnum * eheader.e_phentsize) {		dprintf("short read while reading in program headers\n");		err = -1;		goto error;	}	for(i=0; i < eheader.e_phnum; i++) {		char region_name[64];		region_id id;		char *region_addr;		sprintf(region_name, "%s_seg%d", path, i);		region_addr = (char *)ROUNDOWN(pheaders[i].p_vaddr, PAGE_SIZE);		if(pheaders[i].p_flags & PF_W) {			/*			 * rw segment			 */			unsigned start_clearing;			unsigned to_clear;			unsigned A= pheaders[i].p_vaddr+pheaders[i].p_memsz;			unsigned B= pheaders[i].p_vaddr+pheaders[i].p_filesz;			A= ROUNDOWN(A, PAGE_SIZE);			B= ROUNDOWN(B, PAGE_SIZE);			id= vm_map_file(				p->_aspace_id,				region_name,				(void **)&region_addr,				REGION_ADDR_EXACT_ADDRESS,				ROUNDUP(pheaders[i].p_filesz+ (pheaders[i].p_vaddr % PAGE_SIZE), PAGE_SIZE),				LOCK_RW,				REGION_PRIVATE_MAP,				path,				ROUNDOWN(pheaders[i].p_offset, PAGE_SIZE)			);			if(id < 0) {				dprintf("error allocating region!\n");				err = ERR_INVALID_BINARY;				goto error;			}			/*			 * clean garbage brought by mmap			 */			start_clearing=				(unsigned)region_addr				+ (pheaders[i].p_vaddr % PAGE_SIZE)				+ pheaders[i].p_filesz;			to_clear=				ROUNDUP(pheaders[i].p_filesz+ (pheaders[i].p_vaddr % PAGE_SIZE), PAGE_SIZE)				- (pheaders[i].p_vaddr % PAGE_SIZE)				- (pheaders[i].p_filesz);			memset((void*)start_clearing, 0, to_clear);			/*			 * check if we need extra storage for the bss			 */			if(A != B) {				/* XXX - this is broken! The final comma on the 1st line means we don't do the				 *       subtraction? What's actually desired here?				 */				size_t bss_size=					ROUNDUP(pheaders[i].p_memsz+ (pheaders[i].p_vaddr % PAGE_SIZE), PAGE_SIZE)/*, */					- ROUNDUP(pheaders[i].p_filesz+ (pheaders[i].p_vaddr % PAGE_SIZE), PAGE_SIZE);				sprintf(region_name, "%s_bss%d", path, 'X');				region_addr+= ROUNDUP(pheaders[i].p_filesz+ (pheaders[i].p_vaddr % PAGE_SIZE), PAGE_SIZE),				id= vm_create_anonymous_region(					p->_aspace_id,					region_name,					(void **)&region_addr,					REGION_ADDR_EXACT_ADDRESS,					bss_size,					REGION_WIRING_LAZY,					LOCK_RW				);				if(id < 0) {					dprintf("error allocating region!\n");					err = ERR_INVALID_BINARY;					goto error;				}			}		} else {			/*			 * assume rx segment			 */			id= vm_map_file(				p->_aspace_id,				region_name,				(void **)&region_addr,				REGION_ADDR_EXACT_ADDRESS,				ROUNDUP(pheaders[i].p_memsz + (pheaders[i].p_vaddr % PAGE_SIZE), PAGE_SIZE),				LOCK_RO,				REGION_PRIVATE_MAP,				path,				ROUNDOWN(pheaders[i].p_offset, PAGE_SIZE)			);			if(id < 0) {				dprintf("error mapping text!\n");				err = ERR_INVALID_BINARY;				goto error;			}		}	}	dprintf("elf_load: done!\n");	*entry = eheader.e_entry;	err = 0;error:	if(pheaders)		kfree(pheaders);	sys_close(fd);	return err;}