Пример #1
0
int sa3addcall (sa3cg cg, char* cr, char* cd) {
	/* Thread #0 parser */
	uint32   size = 0;	
	sa3call*    c = NULL;
	int     saret = 0;
	uint16  pklen = 0;
	uint16  fklen = 0;
	char*      pk = NULL;
	char*   tmpcr = NULL;

	CHK_CG  (cg, saret);
	CHK_STR (cr, saret);
	CHK_STR (cd, saret);

	CALL_API (saret, getstruct (&size, (void**)&c, 2, cr, cd));

	CALL_API (saret, put_ent (cg->pdb, NULL, 0, (void*) c, size, CR));

CLEANUP:
	if (NULL != pk) {
		freekey (&pk);
	}

	return saret;
}
Пример #2
0
int sa3adddecl (sa3cg cg, char* type, char* func, char* param) {
	uint32   size   = 0;
	sa3decl* d      = NULL;
	int      saret  = 0;
	uint16   keylen = 0;
	char*    key    = NULL;
	char*    _func  = NULL;

	CHK_CG  (cg,    saret);
	CHK_STR (type,  saret);
	CHK_STR (func,  saret);
	CHK_STR (param, saret);

	CALL_API (saret, getstruct (&size, (void**) &d, 3, type, func, param));
	
	/*   TODO: child thread start */ {
		_func = (char*) PI2PTR (d, d->func);
		// CALL_API (saret, getkey ("dl \0", (const char*) _func, &keylen, &key));
		CALL_API (saret, put_ent (cg->pdb, _func, STRLEN(_func), (void*) d, size, DL));
	} /* TODO: child thread end */

CLEANUP:
	if (NULL != d) {
		freestruct ((void**)&d);
	}
	if (NULL != key) {
		freekey (&key);
	}

	return saret;
}
Пример #3
0
int main(int argc, char **argv)
{
  const struct struct_s *mystruct = getstruct();

  printf("Calling getstruct()\n");
  mystruct = getstruct();
  printf("getstruct returned %p\n", mystruct);
  printf("  n = %d (vs %d) %s\n",
         mystruct->n, DUMMY_SCALAR_VALUE1,
         mystruct->n == DUMMY_SCALAR_VALUE1 ? "PASS" : "FAIL");

  printf("  pn = %p (vs %p) %s\n",
         mystruct->pn, &dummy_scalar,
         mystruct->pn == &dummy_scalar ? "PASS" : "FAIL");
  if (mystruct->pn == &dummy_scalar)
    {
      printf(" *pn = %d (vs %d) %s\n",
             *mystruct->pn, DUMMY_SCALAR_VALUE2,
             *mystruct->pn == DUMMY_SCALAR_VALUE2 ? "PASS" : "FAIL");
    }

  printf("  ps = %p (vs %p) %s\n",
         mystruct->ps, &dummy_struct,
         mystruct->ps == &dummy_struct ? "PASS" : "FAIL");
  if (mystruct->ps == &dummy_struct)
    {
      printf("  ps->n = %d (vs %d) %s\n",
             mystruct->ps->n, DUMMY_SCALAR_VALUE3,
             mystruct->ps->n == DUMMY_SCALAR_VALUE3 ? "PASS" : "FAIL");
    }

  printf("  pf = %p (vs %p) %s\n",
         mystruct->pf, dummyfunc,
         mystruct->pf == dummyfunc ? "PASS" : "FAIL");
  if (mystruct->pf == dummyfunc)
    {
      printf("Calling mystruct->pf()\n");
      mystruct->pf();
    }

  printf("Exit-ing\n");
  return 0;
}
Пример #4
0
Файл: diso.c Проект: bfeng/mipc
/*
 * d u m p _ o s h d r
 *
 * Dump object file section headers.
 *
 * Returns:	OK	Always
 *
 * The o_secnam structure is read to determine section names.
 */
int dump_oshdr(FILE *fp, long start, long count)
{
  int j;
  struct outsect secbuf;

  fprintf(stdout,
	"Name          Index Core start Core size  File start File size  Alignment\n");
  for (j = 0 ; j < count ; j++) {
	(void) getstruct(fp, (char *)&secbuf, SF_SECT);
	if (j >= start)
		fprintf(stdout, "%-13s %4.4d  0x%08.8x 0x%08.8x 0x%08.8x 0x%08.8x 0x%08.8x\n",
			o_secnam[j], j, secbuf.os_base, secbuf.os_size, secbuf.os_foff,
			secbuf.os_flen, secbuf.os_lign);
  }

  return(OK);
}
Пример #5
0
static struct user *
getuser(struct proc *aproc)
{
    static union {
        struct user     user;
        char            upgs[UPAGES][NBPG];
    } u;
    static struct pte uptes[UPAGES];
    static struct dmap dmap;
    int             i, nbytes;

    /*
     * If process is not in core, we simply snarf it's user struct
     * from the swap device.
     */
    if ((aproc->p_sched & SLOAD) == 0) {
        if (!getstruct
            ((off_t) aproc->p_smap, "aproc->p_smap", (off_t) & dmap,
             sizeof(dmap))) {
            /*
             * warnx("can't read dmap for pid %d from %s", aproc->p_pid,
             * _PATH_DRUM); 
             */
            return (NULL);
        }
        if (SKRD(swap, SW_UADDR, &u.user, SW_UBYTES)) {
            /*
             * warnx("can't read u for pid %d from %s", aproc->p_pid, _PATH_DRUM); 
             */
            return (NULL);
        }
        return (&u.user);
    }

    /*
     * Process is in core.  Follow p_addr to read in the page
     * table entries that map the u-area and then read in the
     * physical pages that comprise the u-area.
     *
     * If at any time, an lseek() or read() fails, print a warning
     * message and return NULL.
     */
    if (SKRD(kmem, aproc->p_addr, uptes, sizeof(uptes))) {
        /*
         * warnx("can't read user pt for pid %d from %s", aproc->p_pid, _PATH_DRUM); 
         */
        return (NULL);
    }

    nbytes = sizeof(struct user);
    for (i = 0; i < UPAGES && nbytes > 0; i++) {
        if (SKRD(mem, ptob(uptes[i].pg_pfnum), u.upgs[i], NBPG)) {
            /*
             * warnx("can't read user page %u for pid %d from %s",
             * uptes[i].pg_pfnum, aproc->p_pid, _PATH_MEM); 
             */
            return (NULL);
        }
        nbytes -= NBPG;
    }
    return (&u.user);
}
Пример #6
0
Файл: diso.c Проект: bfeng/mipc
/*
 * i n i t _ o b j f
 *
 * Initialise object file tables.
 *
 * Returns:	OK	Success
 *		FAILED	Otherwise
 */
int init_objf(FILE *fp)
{
  char *cp;
  int j;
  unsigned int uj;
  long int lj;

  /* load the header into memory for fast access */
  (void) getstruct(fp, (char *)&o_hdrbuf, SF_HEAD);
  if (BADMAGIC(o_hdrbuf)) {
	fprintf(stderr, "%s: bad magic number.\n", progname);
	return(FAILED);
  }
  if (o_hdrbuf.oh_nsect == 0) {
	fprintf(stderr, "%s: no sections present.\n", progname);
	return(FAILED);
  }

  /* check that the whole file can be read */
  if (fseek(fp, OFF_CHAR(o_hdrbuf) + o_hdrbuf.oh_nchar, SEEK_SET) != 0) {
	fprintf(stderr, "%s: cannot seek to end of file.\n", progname);
	return(FAILED);
  }

  /* load the section data into memory for fast access */
  uj = o_hdrbuf.oh_nsect * sizeof(struct outsect);
  if (fseek(fp, OFF_SECT(o_hdrbuf), SEEK_SET) != 0) {
	fprintf(stderr, "%s: cannot seek to section area.\n", progname);
	return(FAILED);
  }
  if (fread(o_sectab, sizeof(char), uj, fp) != uj) {
	fprintf(stderr, "%s: cannot read section area.\n", progname);
	return(FAILED);
  }

  /* load the relocation data into memory for fast access */
  /* ### Should this be left on disk and only the indices loaded ? */
  uj = o_hdrbuf.oh_nrelo * sizeof(struct outrelo);
  if (fseek(fp, OFF_RELO(o_hdrbuf), SEEK_SET) != 0) {
	fprintf(stderr, "%s: cannot seek to relocation area.\n", progname);
	return(FAILED);
  }
  if ((cp = (char *)malloc(uj)) == (char *)NULL) {
	fprintf(stderr, "%s: malloc failed\n", progname);
	return(FAILED);
  }
  if (fread(cp, sizeof(char), uj, fp) != uj) {
	fprintf(stderr, "%s: cannot read relocation area.\n", progname);
	return(FAILED);
  }
  /* initialise the in-memory relocation table array pointers */
  o_reltab = (struct outrelo *)cp;

  /* ### needs to be optional for files without symbol tables */
  /* load the symbol table into memory for fast access */
  uj = o_hdrbuf.oh_nname * sizeof(struct outname);
  if ((cp = (char *)malloc(uj)) == (char *)NULL) {
	fprintf(stderr, "%s: malloc failed\n", progname);
	return(FAILED);
  }
  if (fseek(fp, OFF_NAME(o_hdrbuf), SEEK_SET) != 0) {
	fprintf(stderr, "%s: cannot seek to symbol area.\n", progname);
	return(FAILED);
  }
  if (fread(cp, sizeof(char), uj, fp) != uj) {
	fprintf(stderr, "%s: cannot read symbol area.\n", progname);
	return(FAILED);
  }
  /* initialise the in-memory symbol table array pointers */
  o_symtab = (struct outname *)cp;

  /* load the string area into memory for fast access */
  uj = (unsigned int)o_hdrbuf.oh_nchar;
  if ((o_strtab = (char *)malloc(uj)) == (char *)NULL) {
	fprintf(stderr, "%s: malloc failed\n", progname);
	return(FAILED);
  }
  if (fseek(fp, OFF_CHAR(o_hdrbuf), SEEK_SET) != 0) {
	fprintf(stderr, "%s: cannot seek to string area.\n", progname);
	return(FAILED);
  }
  if (fread(o_strtab, sizeof(char), uj, fp) != uj) {
	fprintf(stderr, "%s: cannot read string area.\n", progname);
	return(FAILED);
  }

  /* build the section name table */
  for (j = 0 ; j < o_hdrbuf.oh_nname ; j++) {
	if ((o_symtab[j].on_type & S_ETC) == S_SCT) {
		lj = o_symtab[j].on_foff - (long)OFF_CHAR(o_hdrbuf);
		/* check that addressing isn't messed up */
		assert(lj >= 0 && lj < o_hdrbuf.oh_nchar);
		strncpy(o_secnam[(o_symtab[j].on_type & S_TYP) - S_MIN],
				o_strtab + lj, SZ_NAME + 1);
	}
  }

  /* build the local symbol tables */
  for (j = 0 ; j < MAXSECT ; j++)
	locsym[j] = (struct locname *)NULL;

  /* build the local .text symbol table */
  /* ### full disassembly ? */

  /* build the local .rom symbol table */
  if (gen_locsym(fp, ROM) == FAILED)
	return(FAILED);

  /* there's no point in building the .data and .bss tables */

  return(OK);
}
Пример #7
0
Файл: diso.c Проект: bfeng/mipc
/*
 * d u m p _ o s y m
 *
 * Dump object file symbol table data.
 *
 * Returns:	OK	Success
 *		FAILED	Invalid arguments
 *
 * The o_hdrbuf structure is read to determine section addresses.
 * The o_strtab and o_secnam structures are read to determine symbol values.
 */
int dump_osym(FILE *fp, long start, long count)
{
  char buff[BUFF_LEN], data[S_BUFF_LEN];
  int j;
  unsigned int uj;
  long lj;
  struct outname nambuf;

  if (start < 0 || (start + count) > o_hdrbuf.oh_nname)
	return(FAILED);

  for (j = 0 ; j < count ; j++) {
	(void) getstruct(fp, (char *)&nambuf, SF_NAME);
	sprintf(buff, "%4.4d", j + start);
#if 1
	lj = nambuf.on_foff - (long)OFF_CHAR(o_hdrbuf);
	/* check that addressing isn't messed up */
	assert(lj >= 0 && lj < o_hdrbuf.oh_nchar);
	/* name size is defined by SZ_NAME */
	sprintf(data, " %-13s", o_strtab + lj);
	strcat(buff, data);
#else
	sprintf(data, " 0x%08.8x", nambuf.on_foff);
	strcat(buff, data);
#endif
	strcat(buff, " Type:");
	uj = nambuf.on_type & S_TYP;
	if (uj >= S_MIN && uj <= S_MAX) {
#if 1
		/* use arbitrary names for Minix 386 */
		sprintf(data, " %-5s", o_secnam[uj - S_MIN]);
#else
		sprintf(data, "  0x%02.2x", uj - S_MIN);
#endif
		strcat(buff, data);
	}
	/* S_UND is the empty S_TYP field */
	if ((nambuf.on_type & S_TYP) == S_UND) strcat(buff, " S_UND");
	if ((nambuf.on_type & S_TYP) == S_ABS) strcat(buff, " S_ABS");
	if ((nambuf.on_type & S_TYP) == S_CRS) strcat(buff, " S_CRS");

	if ((nambuf.on_type & S_EXT) == S_EXT) strcat(buff, " S_EXT");
	else strcat(buff, "      ");

	if ((nambuf.on_type & S_ETC) == S_SCT) strcat(buff, " S_SCT");
	if ((nambuf.on_type & S_ETC) == S_LIN) strcat(buff, " S_LIN");
	if ((nambuf.on_type & S_ETC) == S_FIL) strcat(buff, " S_FIL");
	if ((nambuf.on_type & S_ETC) == S_MOD) strcat(buff, " S_MOD");
	if ((nambuf.on_type & S_ETC) == S_COM) strcat(buff, " S_COM");
	if ((nambuf.on_type & S_ETC) == 0) strcat(buff, "      ");

	if (nambuf.on_type &
		~(S_TYP | S_EXT | S_SCT | S_LIN | S_FIL | S_MOD | S_COM))
		strcat(buff, " UNKNOWN");

#if 1
	/* Desc is not used, so save space */
	strcat(buff, " Desc: 0x00");
#else
	strcat(buff, " Desc:");
	sprintf(data, " 0x%04.4x", nambuf.on_desc);
	strcat(buff, data);
#endif
	strcat(buff, " Valu:");
	sprintf(data, " 0x%08.8x", nambuf.on_valu);
	strcat(buff, data);
	fprintf(stdout, "%s\n", buff);
  }
#if 0
  fprintf(stdout, "Name Type Debug Value\n");
  fprintf(stdout, "0x%08.8x 0x%04.4x 0x%04.4x 0x%08.8x\n",
		nambuf.on_u.on_off, nambuf.on_type,
		nambuf.on_desc, nambuf.on_valu);
#endif

  return(OK);
}
Пример #8
0
Файл: diso.c Проект: bfeng/mipc
/*
 * d u m p _ o r e l
 *
 * Dump object file relocation data.
 *
 * Returns:	OK	Success
 *		FAILED	Invalid arguments
 *
 * The o_hdrbuf and o_sectab structures are read to determine section addresses.
 * The o_symtab and o_strtab structures are read to determine symbol values.
 */
int dump_orel(FILE *fp, long start, long count)
{
  char buff[BUFF_LEN], data[S_BUFF_LEN];
  int j;
  unsigned int uj;
  long int lj;
  struct outrelo relbuf;

  if (start < 0 || (start + count) > o_hdrbuf.oh_nrelo)
	return(FAILED);

  for (j = 0 ; j < count ; j++) {
	(void) getstruct(fp, (char *)&relbuf, SF_RELO);
	sprintf(buff, "%04d Type:", j + start);
	if (relbuf.or_type & RELO1) strcat(buff, " RELO1");
	if (relbuf.or_type & RELO2) strcat(buff, " RELO2");
	if (relbuf.or_type & RELO4) strcat(buff, " RELO4");
	if (relbuf.or_type & RELPC) strcat(buff, " RELPC");
	else strcat(buff, "      ");
	if (relbuf.or_type & RELBR) strcat(buff, " RELBR");
	if (relbuf.or_type & RELWR) strcat(buff, " RELWR");
	if (relbuf.or_type & ~(RELO1 | RELO2 | RELO4 | RELPC | RELBR | RELWR))
		strcat(buff, "UNKNOWN");

	strcat(buff, " Sect:");
	uj = relbuf.or_sect & S_TYP;
	if (uj >= S_MIN && uj <= S_MAX) {
#if 1
		/* use arbitrary names for Minix 386 */
		sprintf(data, " %-5s", o_secnam[uj - S_MIN]);
#else
		sprintf(data, "  0x%02.2x", uj - S_MIN);
#endif
		strcat(buff, data);
	}
	/* S_UND is the empty S_TYP field */
	if ((relbuf.or_sect & S_TYP) == S_UND) strcat(buff, " S_UND");
	if ((relbuf.or_sect & S_TYP) == S_ABS) strcat(buff, " S_ABS");
	if ((relbuf.or_sect & S_TYP) == S_CRS) strcat(buff, " S_CRS");

	if ((relbuf.or_sect & S_EXT) == S_EXT) strcat(buff, " S_EXT");
	else strcat(buff, "      ");

	if (relbuf.or_sect & ~(S_TYP | S_EXT))
		strcat(buff, " UNKNOWN");

	strcat(buff, " Symb:");
	if (relbuf.or_nami < o_hdrbuf.oh_nname) {
		lj = o_symtab[relbuf.or_nami].on_foff - (long)OFF_CHAR(o_hdrbuf);
		/* check that addressing isn't messed up */
		assert(lj >= 0 && lj < o_hdrbuf.oh_nchar);
		/* name size is defined by SZ_NAME */
		sprintf(data, "%-13s", o_strtab + lj);
	}
	else
		sprintf(data, " 0x%04.4x", relbuf.or_nami);
	strcat(buff, data);
	strcat(buff, " Addr:");
	sprintf(data, " 0x%08.8x", relbuf.or_addr);
	strcat(buff, data);
	fprintf(stdout, "%s\n", buff);

#if 0
	printf("Type Section Symbol Address\n");
	printf("0x%02.2x 0x%02.2x 0x%04.4x 0x%08.8x\n",
		relbuf.or_type, relbuf.or_sect,
		relbuf.or_nami, relbuf.or_addr);
#endif
  }

  return(OK);
}