long test1c() {
	unsigned char *pages;
	size_t page_size = PAGE_SIZE;
	size_t addr_size = page_size * PAGE_NUM;
	int wcount[PAGE_NUM], ret;

	bzero(wcount, PAGE_NUM * sizeof(int));

	pages = mmap(ADDR_START,
		addr_size,	
		PROT_READ | PROT_WRITE,
		MAP_PRIVATE | MAP_ANONYMOUS,
		0,
		0);
	if (pages == MAP_FAILED)
		return -errno;

	fprintf(stderr, "pages = %lx\n", (unsigned long)pages);

	ret = start_trace((unsigned long)pages, addr_size);
	if (ret) {
		fprintf(stderr, "start_trace failed: %s\n", strerror(errno));
		return -errno;
	}
	fprintf(stderr, "start_trace\n");

	ret = start_trace((unsigned long)pages, addr_size);
	if (!ret || errno != EINVAL) {
		fprintf(stderr, "the 2nd start_trace should fail\n");
		return -1;
	}

	ret = get_trace(getpid(), wcount);
	if (ret) {
		fprintf(stderr, "get_trace failed: %s\n", strerror(errno));
		return -errno;
	}
	fprintf(stderr, "get_trace\n");
	
	ret = stop_trace();
	if (ret) {
		fprintf(stderr, "stop_trace failed: %s\n", strerror(errno));
		return -errno;
	}
	fprintf(stderr, "stop_trace\n");

	ret = stop_trace();
	if (!ret || errno != EINVAL) {
		fprintf(stderr, "the 2nd stop_trace should fail\n");
		return -1;
	}

	ret = get_trace(getpid(), wcount);
	if (!ret || errno != EINVAL) {
		fprintf(stderr, "the 2nd get_trace should fail\n");
		return -1;
	}
	
	return 0;
}
Graph* GraphBuilder::build_graph(const char* pathfile)
{
	unsigned int nodes;
	unsigned int edges;
	int count;
	syscall_t *trace = NULL;
	Graph *graph = NULL;
	std::cout<<"Getting system call trace for "<<pathfile<<std::endl;

	count = get_trace(pathfile, &trace);
	if(count < 0) {
		std::cerr<<"error getting trace"<<std::endl;
		return NULL;
	}
	graph = new Graph(trace, count);
	graph->generate_edges();

	nodes = graph->getVertexs().size();
	edges = graph->getEdges().size();

	if(aggregate) {
		graph->aggregate_vertexs();
		printf("\t\t   Nodes  Edges\n");
		printf("Initial graph    : %-6u %-6u\n", nodes, edges);
		printf("After aggregation: %-6u %-6u\n",
				graph->getVertexs().size(),
				graph->getEdges().size()
				);
	} else {
		printf("Graph, no aggreg.: %-4u %-4u\n", nodes, edges);
	}

	free(trace);
	return graph;
}
void *thread1b(void *args) {
	unsigned char *pages = (unsigned char *)((void **)args)[0];
	int *wcount = (int *)((void **)args)[1];

	size_t page_size = PAGE_SIZE;
	size_t addr_size = page_size * PAGE_NUM;
	unsigned long addr;
	int ret, i;

	fprintf(stderr, "in child: new thread created\n");

	for (i = 0 ; i < 10 ; i++) {
		for (addr = 0 ; addr < addr_size ; addr += page_size)
			pages[addr]++;
		usleep(20);
	}
	
	ret = get_trace(gettid(), wcount);
	if (ret) {
		fprintf(stderr, "in child: get_trace failed: %s\n", 
				strerror(errno));
		return NULL;
	}
	fprintf(stderr, "in child: get_trace\n");
	
	return NULL;
}
Beispiel #4
0
/**
 * Compute command
 */
void command_compute(char* line) {

    char cmd[MAX_BUFFER];
    char key[MAX_BUFFER];
    char func[MAX_BUFFER];
    char arg1[MAX_BUFFER];

    int argc = sscanf(line, "%s %s %s %s", cmd, func, key, arg1);
    if (argc < 3) {
        goto invalid;
    }

    MATRIX_GUARD(key);
    uint32_t result = 0;

    if (strcasecmp(func, "sum") == 0) {
        result = get_sum(m);
    } else if (strcasecmp(func, "trace") == 0) {
        result = get_trace(m);
    } else if (strcasecmp(func, "minimum") == 0) {
        result = get_minimum(m);
    } else if (strcasecmp(func, "maximum") == 0) {
        result = get_maximum(m);
    } else if (strcasecmp(func, "frequency") == 0) {
        result = get_frequency(m, atoll(arg1));
    } else {
        goto invalid;
    }

    printf("%" PRIu32 "\n", result);
    return;

invalid:
    puts("invalid arguments");
}
Beispiel #5
0
  void print_backtrace(size_t max) {
    VMException::Backtrace s = get_trace(2, max);
    demangle(s);

    for(size_t i = 0; i < s.size(); i++) {
      std::cout << s[i] << std::endl;
    }
  }
static PAIRALIGN *get_align(const char *aseq,const char *bseq,Local_Overlap *O,int piece,
                            int which){
  int *trace=get_trace(aseq,bseq,O,piece,which);
  if(trace == NULL) return NULL;

  PAIRALIGN *pairalign = construct_pair_align(aseq,bseq,O,piece,trace,which);

  return(pairalign);
}
Beispiel #7
0
/*
 * Invoke user cmd
 *
 */
uint8_t invoke_user_cmd(const uint8_t * pData, const uint8_t len) {
    uint8_t user_cmd;

    user_cmd = nibble_to_bin(pData[0]);
    user_cmd <<= 4;
    user_cmd |= nibble_to_bin(pData[1]);

    DEBUG_PRINTF("user_cmd: 0x%2x\r\n", user_cmd);

    switch (user_cmd) {
        case CMD_RESET_DEVICE:
            reset_device();
            break;

        case CMD_GET_BL_VERS:
            serprintf(device_vers_tag);
            break;

        case CMD_UNLOCK_MCU:
            if (len == 10) {
                uint32_t unlock_code = 0;
                uint16_t idx = 2;

                while (idx < 10) {
                    unlock_code <<= 4;
                    unlock_code |= nibble_to_bin(pData[idx++]);
                    unlock_code <<= 4;
                    unlock_code |= nibble_to_bin(pData[idx++]);
                }

                clear_mcu_iap(unlock_code);
            }
            break;

        case CMD_DEBUG_ON:
            set_trace(get_trace() == 0 ? serprintf : 0);
            break;

        default:
            break;
    }

    return SDP_ACK_x06;
}
Beispiel #8
0
/**
 * Compute command.
 */
void command_compute(char* line) {

	char cmd[MAX_BUFFER];
	char key[MAX_BUFFER];
	char func[MAX_BUFFER];
	char arg1[MAX_BUFFER];

	int argc = sscanf(line, "%s %s %s %s", cmd, func, key, arg1);
	if (argc < 3) {
		goto invalid;
	}

	MATRIX_GUARD(key);
	float result = 0;

	if (strcasecmp(func, "sum") == 0) {
		result = get_sum(m);
	} else if (strcasecmp(func, "trace") == 0) {
		result = get_trace(m);
	} else if (strcasecmp(func, "minimum") == 0) {
		result = get_minimum(m);
	} else if (strcasecmp(func, "maximum") == 0) {
		result = get_maximum(m);
	} else if (strcasecmp(func, "determinant") == 0) {
		result = get_determinant(m);
	} else if (strcasecmp(func, "frequency") == 0) {
		ssize_t count = get_frequency(m, atof(arg1));
		printf("%zu\n", count);
		return;
	} else {
		goto invalid;
	}

	printf("%.2f\n", result);
	return;

invalid:
	puts("invalid arguments");
}
void *thread2b(void *args) {
	unsigned char *pages = (unsigned char *)((void **)args)[0];
	int *wcount = (int *)((void **)args)[1];

	int ret, i;

	fprintf(stderr, "in child: new thread created\n");

	for (i = 0 ; i < 10 ; i++) {
		while(!pages[0]);
		pages[0]--;
	}
	
	ret = get_trace(gettid(), wcount);
	if (ret) {
		fprintf(stderr, "in child: get_trace failed: %s\n", 
				strerror(errno));
		return NULL;
	}
	fprintf(stderr, "in child: get_trace\n");
	
	return NULL;
}
Beispiel #10
0
const char*
StackTrace::GetTrace()
{
    return get_trace();
}
Beispiel #11
0
static void list_status_header(STATUS_PKT *sp)
{
   int len;
   char dt[MAX_TIME_LENGTH];
   POOL_MEM msg(PM_MESSAGE);
   char b1[32], b2[32], b3[32], b4[32], b5[35];
#if defined(HAVE_WIN32)
   char buf[300];
#endif

   len = Mmsg(msg, _("%s Version: %s (%s) %s %s %s %s\n"),
              my_name, VERSION, BDATE, VSS, HOST_OS, DISTNAME, DISTVER);
   sendit(msg, len, sp);
   bstrftime_nc(dt, sizeof(dt), daemon_start_time);
   len = Mmsg(msg, _("Daemon started %s. Jobs: run=%d running=%d.\n"),
        dt, num_jobs_run, job_count());
   sendit(msg, len, sp);

#if defined(HAVE_WIN32)
   if (GetWindowsVersionString(buf, sizeof(buf))) {
      len = Mmsg(msg, "%s\n", buf);
      sendit(msg, len, sp);
   }

   if (debug_level > 0) {
      if (!privs) {
         privs = enable_backup_privileges(NULL, 1);
      }
      len = Mmsg(msg, "Priv 0x%x\n", privs);
      sendit(msg, len, sp);
      len = Mmsg(msg, "APIs=%sOPT,%sATP,%sLPV,%sCFA,%sCFW,\n",
                 p_OpenProcessToken ? "" : "!",
                 p_AdjustTokenPrivileges ? "" : "!",
                 p_LookupPrivilegeValue ? "" : "!",
                 p_CreateFileA ? "" : "!",
                 p_CreateFileW ? "" : "!");
      sendit(msg, len, sp);
      len = Mmsg(msg, " %sWUL,%sWMKD,%sGFAA,%sGFAW,%sGFAEA,%sGFAEW,%sSFAA,%sSFAW,%sBR,%sBW,%sSPSP,\n",
                 p_wunlink ? "" : "!",
                 p_wmkdir ? "" : "!",
                 p_GetFileAttributesA ? "" : "!",
                 p_GetFileAttributesW ? "" : "!",
                 p_GetFileAttributesExA ? "" : "!",
                 p_GetFileAttributesExW ? "" : "!",
                 p_SetFileAttributesA ? "" : "!",
                 p_SetFileAttributesW ? "" : "!",
                 p_BackupRead ? "" : "!",
                 p_BackupWrite ? "" : "!",
                 p_SetProcessShutdownParameters ? "" : "!");
      sendit(msg, len, sp);
      len = Mmsg(msg, " %sWC2MB,%sMB2WC,%sFFFA,%sFFFW,%sFNFA,%sFNFW,%sSCDA,%sSCDW,\n",
                 p_WideCharToMultiByte ? "" : "!",
                 p_MultiByteToWideChar ? "" : "!",
                 p_FindFirstFileA ? "" : "!",
                 p_FindFirstFileW ? "" : "!",
                 p_FindNextFileA ? "" : "!",
                 p_FindNextFileW ? "" : "!",
                 p_SetCurrentDirectoryA ? "" : "!",
                 p_SetCurrentDirectoryW ? "" : "!");
      sendit(msg, len, sp);
      len = Mmsg(msg, " %sGCDA,%sGCDW,%sGVPNW,%sGVNFVMPW\n",
                 p_GetCurrentDirectoryA ? "" : "!",
                 p_GetCurrentDirectoryW ? "" : "!",
                 p_GetVolumePathNameW ? "" : "!",
                 p_GetVolumeNameForVolumeMountPointW ? "" : "!");
      sendit(msg, len, sp);
   }
#endif

   len = Mmsg(msg, _(" Heap: heap=%s smbytes=%s max_bytes=%s bufs=%s max_bufs=%s\n"),
              edit_uint64_with_commas((char *)sbrk(0)-(char *)start_heap, b1),
              edit_uint64_with_commas(sm_bytes, b2),
              edit_uint64_with_commas(sm_max_bytes, b3),
              edit_uint64_with_commas(sm_buffers, b4),
              edit_uint64_with_commas(sm_max_buffers, b5));
   sendit(msg, len, sp);
   len = Mmsg(msg, _(" Sizeof: boffset_t=%d size_t=%d debug=%d trace=%d "
                     "bwlimit=%skB/s\n"), sizeof(boffset_t), sizeof(size_t),
              debug_level, get_trace(), edit_uint64_with_commas(me->max_bandwidth_per_job / 1024, b1));
   sendit(msg, len, sp);

   if (me->secure_erase_cmdline) {
      len = Mmsg(msg, _(" secure erase command='%s'\n"), me->secure_erase_cmdline);
      sendit(msg, len, sp);
   }

   len = list_fd_plugins(msg);
   if (len > 0) {
      sendit(msg, len, sp);
   }
}
Beispiel #12
0
long test2b() {
	unsigned char *pages;
	size_t page_size = PAGE_SIZE;
	size_t addr_size = page_size;

	int wcount[1], wcount2[1], i, ret;
	void *args[2];

	pthread_t thread;

	bzero(wcount, sizeof(int));
	bzero(wcount2, sizeof(int));
	
	pages = mmap(ADDR_START,
		addr_size,	
		PROT_READ | PROT_WRITE,
		MAP_PRIVATE | MAP_ANONYMOUS,
		0,
		0);
	if (pages == MAP_FAILED)
		return -errno;
	fprintf(stderr, "pages = %lx\n", (unsigned long)pages);

	bzero(pages, addr_size);

	ret = start_trace((unsigned long)pages, addr_size);
	if (ret) {
		fprintf(stderr, "start_trace failed: %s\n", strerror(errno));
		return -errno;
	}
	fprintf(stderr, "start_trace\n");

	args[0] = pages;
	args[1] = wcount2;
	pthread_create(&thread, NULL, thread2b, args);
	usleep(1);
	
	for (i = 0 ; i < 10 ; i++) {
		pages[0]++;
		usleep(20);
	}

	pthread_join(thread, NULL);

	ret = get_trace(gettid(), wcount);
	if (ret) {
		fprintf(stderr, "get_trace failed: %s\n", strerror(errno));
		return -errno;
	}
	fprintf(stderr, "get_trace\n");

	printf("wcount[0]=%02d, wcount2[0]=%02d, page[0]=%d\n",
		wcount[0], wcount2[0], pages[0]);

	ret = stop_trace();
	if (ret) {
		fprintf(stderr, "stop_trace failed: %s\n", strerror(errno));
		return -errno;
	}
	fprintf(stderr, "stop_trace\n");

	if (wcount[0] < 9 || wcount2[0] > 0)
		return -1;

	return 0;
}
Beispiel #13
0
long test2a() {
	unsigned char *pages;
	size_t page_size = PAGE_SIZE;
	size_t addr_size = page_size * PAGE_NUM;
	int wcount[PAGE_NUM], ret, i, stat;
	unsigned long addr;
	pid_t pid;

	bzero(wcount, PAGE_NUM * sizeof(int));

	pages = mmap(ADDR_START,
		addr_size,	
		PROT_READ | PROT_WRITE,
		MAP_PRIVATE | MAP_ANONYMOUS,
		0,
		0);
	if (pages == MAP_FAILED)
		return -errno;

	fprintf(stderr, "pages = %lx\n", (unsigned long)pages);

	ret = start_trace((unsigned long)pages, addr_size);
	if (ret) {
		fprintf(stderr, "start_trace failed: %s\n", strerror(errno));
		return -errno;
	}
	fprintf(stderr, "start_trace\n");

	pid = fork();
	if (pid < 0) {
		fprintf(stderr, "fork failed: %s\n", strerror(errno));
		return -errno;
	}

	if (pid == 0) {
		for (i = 0 ; i < 10 ; i++) {
			for (addr = 0 ; addr < addr_size ; addr += page_size)
				pages[addr]++;
			usleep(20);
		}
	
		exit(0);
	}

	wait(&stat);
	for (i = 0 ; i < 10 ; i++) {
		for (addr = 0 ; addr < addr_size ; addr += page_size)
			pages[addr]++;
		usleep(20);
	}

	ret = get_trace(getpid(), wcount);
	if (ret) {
		fprintf(stderr, "get_trace failed: %s\n", strerror(errno));
		return -errno;
	}
	fprintf(stderr, "get_trace\n");

	for (i = 0 ; i < PAGE_NUM ; i++)
		printf("wcount[%d] = %d, page[%04X] = %d\n", i, wcount[i], 
		       i * page_size, pages[i * page_size]);	

	ret = stop_trace();
	if (ret) {
		fprintf(stderr, "stop_trace failed: %s\n", strerror(errno));
		return -errno;
	}
	fprintf(stderr, "stop_trace\n");

	for (i = 0 ; i < PAGE_NUM ; i++)
		if (pages[i * page_size] != 10)
			return -1;

	return 0;
}
Beispiel #14
0
long test1a() {
	unsigned char *pages;
	size_t page_size = PAGE_SIZE;
	size_t addr_size = page_size * PAGE_NUM;
	unsigned long addr;
	int wcount[PAGE_NUM], i, ret;

	bzero(wcount, PAGE_NUM * sizeof(int));

	pages = mmap(ADDR_START,
		addr_size,	
		PROT_READ | PROT_WRITE,
		MAP_PRIVATE | MAP_ANONYMOUS,
		0,
		0);
	if (pages == MAP_FAILED)
		return -errno;

	fprintf(stderr, "pages = %lx\n", (unsigned long)pages);


	for (i = 0 ; i < 1000 ; i++) {
		for (addr = 0 ; addr < addr_size ; addr += page_size)
			pages[addr] = 0;
		usleep(1);
	}
	fprintf(stderr, "write each page 1000 times\n");

	ret = start_trace((unsigned long)pages, addr_size);
	if (ret) {
		fprintf(stderr, "start_trace failed: %s\n", strerror(errno));
		return -errno;
	}
	fprintf(stderr, "start_trace\n");

	for (i = 0 ; i < 1000 ; i++) {
		for (addr = 0 ; addr < addr_size ; addr += page_size)
			pages[addr] = 0;
		usleep(1);
	}
	fprintf(stderr, "write each page 1000 times\n");

	ret = get_trace(getpid(), wcount);
	if (ret) {
		fprintf(stderr, "get_trace failed: %s\n", strerror(errno));
		return -errno;
	}
	fprintf(stderr, "get_trace\n");
	
	for (i = 0 ; i < PAGE_NUM ; i++)
		printf("wcount[%d] = %d\n", i, wcount[i]);
	
	ret = stop_trace();
	if (ret) {
		fprintf(stderr, "stop_trace failed: %s\n", strerror(errno));
		return -errno;
	}
	fprintf(stderr, "stop_trace\n");

	for (i = 0 ; i < PAGE_NUM ; i++)
		if (wcount[i] < 900)
			return -1;

	return 0;
}
Beispiel #15
0
/* Naive recombination of modular factors: combine up to maxK modular
 * factors, degree <= klim and divisible by hint
 *
 * target = polynomial we want to factor
 * famod = array of modular factors.  Product should be congruent to
 * target/lc(target) modulo p^a
 * For true factors: S1,S2 <= p^b, with b <= a and p^(b-a) < 2^31 */
static GEN
nfcmbf(nfcmbf_t *T, GEN p, long a, long maxK, long klim)
{
  GEN pol = T->pol, nf = T->nf, famod = T->fact, dn = T->dn;
  GEN bound = T->bound;
  GEN nfpol = gel(nf,1);
  long K = 1, cnt = 1, i,j,k, curdeg, lfamod = lg(famod)-1, dnf = degpol(nfpol);
  GEN res = cgetg(3, t_VEC);
  pari_sp av0 = avma;
  GEN pk = gpowgs(p,a), pks2 = shifti(pk,-1);

  GEN ind      = cgetg(lfamod+1, t_VECSMALL);
  GEN degpol   = cgetg(lfamod+1, t_VECSMALL);
  GEN degsofar = cgetg(lfamod+1, t_VECSMALL);
  GEN listmod  = cgetg(lfamod+1, t_COL);
  GEN fa       = cgetg(lfamod+1, t_COL);
  GEN lc = absi(leading_term(pol)), lt = is_pm1(lc)? NULL: lc;
  GEN C2ltpol, C = T->L->topowden, Tpk = T->L->Tpk;
  GEN Clt  = mul_content(C, lt);
  GEN C2lt = mul_content(C,Clt);
  const double Bhigh = get_Bhigh(lfamod, dnf);
  trace_data _T1, _T2, *T1, *T2;
  pari_timer ti;

  TIMERstart(&ti);

  if (maxK < 0) maxK = lfamod-1;

  C2ltpol = C2lt? gmul(C2lt,pol): pol;
  {
    GEN q = ceil_safe(sqrtr(T->BS_2));
    GEN t1,t2, ltdn, lt2dn;
    GEN trace1   = cgetg(lfamod+1, t_MAT);
    GEN trace2   = cgetg(lfamod+1, t_MAT);

    ltdn = mul_content(lt, dn);
    lt2dn= mul_content(ltdn, lt);

    for (i=1; i <= lfamod; i++)
    {
      pari_sp av = avma;
      GEN P = gel(famod,i);
      long d = degpol(P);

      degpol[i] = d; P += 2;
      t1 = gel(P,d-1);/* = - S_1 */
      t2 = gsqr(t1);
      if (d > 1) t2 = gsub(t2, gmul2n(gel(P,d-2), 1));
      /* t2 = S_2 Newton sum */
      t2 = typ(t2)!=t_INT? FpX_rem(t2, Tpk, pk): modii(t2, pk);
      if (lt)
      {
        if (typ(t2)!=t_INT) {
          t1 = FpX_red(gmul(ltdn, t1), pk);
          t2 = FpX_red(gmul(lt2dn,t2), pk);
        } else {
          t1 = remii(mulii(ltdn, t1), pk);
          t2 = remii(mulii(lt2dn,t2), pk);
        }
      }
      gel(trace1,i) = gclone( nf_bestlift(t1, NULL, T->L) );
      gel(trace2,i) = gclone( nf_bestlift(t2, NULL, T->L) ); avma = av;
    }
    T1 = init_trace(&_T1, trace1, T->L, q);
    T2 = init_trace(&_T2, trace2, T->L, q);
    for (i=1; i <= lfamod; i++) { 
      gunclone(gel(trace1,i));
      gunclone(gel(trace2,i));
    }
  }
  degsofar[0] = 0; /* sentinel */

  /* ind runs through strictly increasing sequences of length K,
   * 1 <= ind[i] <= lfamod */
nextK:
  if (K > maxK || 2*K > lfamod) goto END;
  if (DEBUGLEVEL > 3)
    fprintferr("\n### K = %d, %Z combinations\n", K,binomial(utoipos(lfamod), K));
  setlg(ind, K+1); ind[1] = 1;
  i = 1; curdeg = degpol[ind[1]];
  for(;;)
  { /* try all combinations of K factors */
    for (j = i; j < K; j++)
    {
      degsofar[j] = curdeg;
      ind[j+1] = ind[j]+1; curdeg += degpol[ind[j+1]];
    }
    if (curdeg <= klim && curdeg % T->hint == 0) /* trial divide */
    {
      GEN t, y, q, list;
      pari_sp av;

      av = avma;
      /* d - 1 test */
      if (T1)
      {
        t = get_trace(ind, T1);
        if (rtodbl(QuickNormL2(t,DEFAULTPREC)) > Bhigh)
        {
          if (DEBUGLEVEL>6) fprintferr(".");
          avma = av; goto NEXT;
        }
      }
      /* d - 2 test */
      if (T2)
      {
        t = get_trace(ind, T2);
        if (rtodbl(QuickNormL2(t,DEFAULTPREC)) > Bhigh)
        {
          if (DEBUGLEVEL>3) fprintferr("|");
          avma = av; goto NEXT;
        }
      }
      avma = av;
      y = lt; /* full computation */
      for (i=1; i<=K; i++)
      {
        GEN q = gel(famod, ind[i]);
        if (y) q = gmul(y, q);
        y = FqX_centermod(q, Tpk, pk, pks2);
      }
      y = nf_pol_lift(y, bound, T);
      if (!y)
      {
        if (DEBUGLEVEL>3) fprintferr("@");
        avma = av; goto NEXT;
      }
      /* try out the new combination: y is the candidate factor */
      q = RgXQX_divrem(C2ltpol, y, nfpol, ONLY_DIVIDES);
      if (!q)
      {
        if (DEBUGLEVEL>3) fprintferr("*");
        avma = av; goto NEXT;
      }

      /* found a factor */
      list = cgetg(K+1, t_VEC);
      gel(listmod,cnt) = list;
      for (i=1; i<=K; i++) list[i] = famod[ind[i]];

      y = Q_primpart(y);
      gel(fa,cnt++) = QXQX_normalize(y, nfpol);
      /* fix up pol */
      pol = q;
      for (i=j=k=1; i <= lfamod; i++)
      { /* remove used factors */
        if (j <= K && i == ind[j]) j++;
        else
        {
          famod[k] = famod[i];
          update_trace(T1, k, i);
          update_trace(T2, k, i);
          degpol[k] = degpol[i]; k++;
        }
      }
      lfamod -= K;
      if (lfamod < 2*K) goto END;
      i = 1; curdeg = degpol[ind[1]];

      if (C2lt) pol = Q_primpart(pol);
      if (lt) lt = absi(leading_term(pol));
      Clt  = mul_content(C, lt);
      C2lt = mul_content(C,Clt);
      C2ltpol = C2lt? gmul(C2lt,pol): pol;
      if (DEBUGLEVEL > 2)
      {
        fprintferr("\n"); msgTIMER(&ti, "to find factor %Z",y);
        fprintferr("remaining modular factor(s): %ld\n", lfamod);
      }
      continue;
    }

NEXT:
    for (i = K+1;;)
    {
      if (--i == 0) { K++; goto nextK; }
      if (++ind[i] <= lfamod - K + i)
      {
        curdeg = degsofar[i-1] + degpol[ind[i]];
        if (curdeg <= klim) break;
      }
    }
  }
END:
  if (degpol(pol) > 0)
  { /* leftover factor */
    if (signe(leading_term(pol)) < 0) pol = gneg_i(pol);

    if (C2lt && lfamod < 2*K) pol = QXQX_normalize(Q_primpart(pol), nfpol);
    setlg(famod, lfamod+1);
    gel(listmod,cnt) = shallowcopy(famod);
    gel(fa,cnt++) = pol;
  }
  if (DEBUGLEVEL>6) fprintferr("\n");
  if (cnt == 2) { 
    avma = av0; 
    gel(res,1) = mkvec(T->pol);
    gel(res,2) = mkvec(T->fact);
  }
  else
  {
    setlg(listmod, cnt); setlg(fa, cnt);
    gel(res,1) = fa;
    gel(res,2) = listmod;
    res = gerepilecopy(av0, res);
  }
  return res;
}
Beispiel #16
0
long test1b() {
	unsigned char *pages;
	size_t page_size = PAGE_SIZE;
	size_t addr_size = page_size * PAGE_NUM;
	
	unsigned long addr;
	int wcount[PAGE_NUM], wcount2[PAGE_NUM], i, ret;
	void *args[2];

	pthread_t thread;

	bzero(wcount, PAGE_NUM * sizeof(int));
	bzero(wcount2, PAGE_NUM * sizeof(int));
	
	pages = mmap(ADDR_START,
		addr_size,	
		PROT_READ | PROT_WRITE,
		MAP_PRIVATE | MAP_ANONYMOUS,
		0,
		0);
	if (pages == MAP_FAILED)
		return -errno;
	fprintf(stderr, "pages = %lx\n", (unsigned long)pages);

	bzero(pages, addr_size);

	ret = start_trace((unsigned long)pages, addr_size);
	if (ret) {
		fprintf(stderr, "start_trace failed: %s\n", strerror(errno));
		return -errno;
	}
	fprintf(stderr, "start_trace\n");

	args[0] = pages;
	args[1] = wcount2;
	pthread_create(&thread, NULL, thread1b, args);
	pthread_join(thread, NULL);

	usleep(10);
	
	for (i = 0 ; i < 10 ; i++) {
		for (addr = 0 ; addr < addr_size ; addr += page_size)
			pages[addr]++;
		usleep(20);
	}
	ret = get_trace(gettid(), wcount);
	if (ret) {
		fprintf(stderr, "get_trace failed: %s\n", strerror(errno));
		return -errno;
	}
	fprintf(stderr, "get_trace\n");

	for (i = 0 ; i < PAGE_NUM ; i++)
		printf("wcount[%d]=%02d, wcount2[%d]=%02d, page[%04X]=%d\n",
			i, wcount[i], i, wcount2[i], 
			i * page_size, pages[i * page_size]);

	ret = stop_trace();
	if (ret) {
		fprintf(stderr, "stop_trace failed: %s\n", strerror(errno));
		return -errno;
	}
	fprintf(stderr, "stop_trace\n");

	for (i = 0 ; i < PAGE_NUM ; i++)
		if (wcount[i] < 9  || wcount[i] > 10 || 
		    wcount2[i] < 9 || wcount[i] > 10)
			return -1;

	return 0;
}
Beispiel #17
0
 static VMException::Backtrace get_cpp_backtrace() {
   VMException::Backtrace s = get_trace(2);
   demangle(s);
   return s;
 }