示例#1
0
void NXClose(register NXStream *s)
{
    _NXVerifyStream(s);
    if (s->flags & NX_WRITEFLAG)
        (void)NXFlush(s);
    s->functions->destroy(s);
    NXStreamDestroy(s);
}
示例#2
0
extern int _NXStreamFlushBuffer(NXStream *s, unsigned char c)
{
    _NXVerifyStream(s);
    s->buf_left++;		/* compensate for NXPutc */
    (void)NXFlush(s);
    *s->buf_ptr++ = c;
    s->buf_left--;
    return (int)c;
}
示例#3
0
static void file_seek(register NXStream *s, register long offset)
{
    register struct file_info *fi;
    register long curPos = NXTell(s);

    if (curPos == offset)
	return;

    /*
     * Don't seek on pipes or sockets.
     */
    if (!(s->flags & NX_CANSEEK))
	return;

    fi = (struct file_info *) s->info;
    if (s->flags & NX_WRITEFLAG) {
	if (s->buf_size != s->buf_left)
	    (void)NXFlush(s);
	if( lseek(fi->fd, offset, 0) < 0)
	    NX_RAISE(NX_illegalSeek, s, (void *)errno);
	s->offset = offset;
	s->buf_ptr = s->buf_base;
	s->buf_left = s->buf_size;
    } else {
	int lastRead;
	long pageptr, pageoffset;

	lastRead = (s->buf_ptr - s->buf_base) + s->buf_left;
	if (offset >= s->offset && offset <= (s->offset + lastRead)) {
	    int delta = offset - s->offset;

	    s->buf_ptr = s->buf_base + delta;
	    s->buf_left = lastRead - delta;
	} else {
	    pageoffset = offset % vm_page_size;
	    pageptr = offset - pageoffset;
	    if( lseek(fi->fd, pageptr, 0) < 0)
		NX_RAISE(NX_illegalSeek, s, (void *)errno);
	    s->buf_left = s->functions->fill_buffer(s);
	    s->offset = pageptr;
	    s->buf_ptr = s->buf_base + pageoffset;
	    s->buf_left -= pageoffset;
	}
    }
}
示例#4
0
static void file_change(register NXStream *s)
{
    register int    curPos = NXTell(s);
    register struct file_info *fi;

    fi = (struct file_info *) s->info;
    if (s->flags & NX_READFLAG) {
	s->offset = curPos;
	s->buf_ptr = s->buf_base;
	s->buf_left = s->buf_size;
	if ((s->flags & NX_CANSEEK) && lseek(fi->fd, curPos, L_SET) < 0)
	    NX_RAISE(NX_illegalSeek, s, (void *)errno);
    } else {
	if (s->buf_size != s->buf_left)
	    (void)NXFlush(s);
	s->buf_left = 0;
    }
}
示例#5
0
__private_extern__
int NXDefaultWrite(NXStream *s, const void *buf, int count)
{
    register int n;
    int total = count;
    int curPos;
    const char * volatile bufPtr = buf;
    NXHandler exception;

    _NXVerifyStream(s);
 /*
  * Loop until copying complete. 
  */
    exception.code = 0;
    if (s->flags & NX_READFLAG) 
	NXChangeBuffer(s);
    while (count > 0) {
    /*
     * Flush buffer if necessary. 
     */
	if (s->buf_left == 0) {
	    NX_DURING {
		(void)NXFlush(s);
	    } NX_HANDLER {
		exception = NXLocalHandler;
		break;
	    } NX_ENDHANDLER
	}
    /*
     * Figure out how much to copy this time. 
     */
	n = count;
	if (n > s->buf_left)
	    n = s->buf_left;
	bcopy((const char *)bufPtr, s->buf_ptr, n);
    /*
     * Update all pointers. 
     */
	s->buf_ptr += n;
	s->buf_left -= n;
	bufPtr += n;
	count -= n;
    }
示例#6
0
void
get_rld_state_symbols(
void)
{
    unsigned long i, j, save_nname;
    NXStream *stream;
    struct mach_header **headers;
    char *object_addr;
    struct load_command *lc;
    struct symtab_command *st;

	if(grld_nloaded_states == 0)
	    return;
	headers = allocate(grld_nloaded_states * sizeof(struct mach_header *));

	/*
	 * Load the a_outname file as the base file.
	 */
	stream = NXOpenFile(fileno(stdout), NX_WRITEONLY);
	if(rld_load_basefile(stream, a_outname) == 0){
	    NXFlush(stream);
	    fflush(stdout);
	    fatal("can't load: %s as base file", a_outname);
	}
	/*
	 * Preform an rld_load() for each state at the state's address.
	 */
	for(i = 0; i < grld_nloaded_states; i++){
	    link_edit_address = (unsigned long)grld_loaded_state[i].header_addr;
	    rld_address_func(address_func);
	    if(rld_load(stream, &(headers[i]),
			grld_loaded_state[i].object_filenames,
			RLD_DEBUG_OUTPUT_FILENAME) == 0){
		NXFlush(stream);
		fflush(stdout);
		fatal("rld_load() failed");
	    }
	}

	/*
	 * Pass 1 count symbols
	 */
	save_nname = nname;
	for(i = 0; i < grld_nloaded_states; i++){
	    st = NULL;
	    object_addr = (char *)headers[i];
	    lc = (struct load_command *)
		 (object_addr + sizeof(struct mach_header));
	    for(j = 0; j < headers[i]->ncmds; j++){
		if(st == NULL && lc->cmd == LC_SYMTAB){
		    st = (struct symtab_command *)lc;
		    count_func_symbols((struct nlist *)
				       (object_addr + st->symoff),
				       st->nsyms,
				       object_addr + st->stroff,
				       st->strsize);
		}
		lc = (struct load_command *)((char *)lc + lc->cmdsize);
	    }
	}
	/*
	 * Reallocate the data structures for the symbols.
	 */
	nl = (nltype *)realloc(nl, (nname + 1) * sizeof(nltype));
	if(nl == NULL)
	    fatal("No room for %lu bytes of symbol table\n",
		  (nname + 1) * sizeof(nltype));
	npe = nl + (save_nname + 1);
	memset(npe, '\0', (nname - save_nname) * sizeof(nltype));
	/*
	 * Pass 2 load symbols.
	 */
	for(i = 0; i < grld_nloaded_states; i++){
	    st = NULL;
	    object_addr = (char *)headers[i];
	    lc = (struct load_command *)
		 (object_addr + sizeof(struct mach_header));
	    for(j = 0; j < headers[i]->ncmds; j++){
		if(st == NULL && lc->cmd == LC_SYMTAB){
		    st = (struct symtab_command *)lc;
		    load_func_symbols((struct nlist *)
				      (object_addr + st->symoff),
				      st->nsyms,
				      object_addr + st->stroff,
				      st->strsize,
				      0);
		}
		lc = (struct load_command *)((char *)lc + lc->cmdsize);
	    }
	}
#ifdef DEBUG
	if(debug & RLDDEBUG){
	    for(i = save_nname + 1; i < nname + 1; i++){
		printf("[get_rld_state_symbols] 0x%08x\t%s\n",
			(unsigned int)nl[i].value, nl[i].name);
	    }
	}
#endif /* DEBUG */
	/*
	 * Resort the symbol table.
	 */
	qsort(nl, nname + 1, sizeof(nltype),
	      (int (*)(const void *, const void *))valcmp);
	free(headers);
}