コード例 #1
0
ファイル: syscall.c プロジェクト: jpwbernardi/xv6-public
// Fetch the nth word-sized system call argument as a string pointer.
// Check that the pointer is valid and the string is nul-terminated.
// (There is no shared writable memory, so the string can't change
// between this check and being used by the kernel.)
int
argstr(int n, char **pp)
{
  int addr;
  if(argint(n, &addr) < 0)
    return -1;
  return fetchstr(addr, pp);
}
コード例 #2
0
ファイル: nicstat.c プロジェクト: curasystems/nicstat
/*
 * populate_g_idnew - the master kstat function.
 *
 * This fetches all the network data from kstat and populates the
 * global variables g_idnew and g_interfacemax. It uses a kstat control
 * pointer as an argument, and the global array g_network.
 *
 * This function works by climbing down the kstat chains looking
 * for modules that look like network interfaces. The first step is
 * to check the module name against the global array g_network (the code
 * for this will need maintenance as new network cards are developed);
 * then a kstat variable is checked "obytes" or "obytes64" to ensure
 * that this really is a network module. This approach is not ideal,
 * I'd rather base the test on the kstat class == "net", however this
 * data does not yet appear reliable across all interfaces.
 */
static void
populate_g_idnew(kstat_ctl_t *kc)
{
	kstat_t *ksp;		/* Kstat struct pointer */
	int ok, i;
	int num = 0;

	for (ksp = kc->kc_chain; ksp != NULL; ksp = ksp->ks_next) {

		/* Search all modules */
		for (ok = 0, i = 0; g_network[i] != NULL; i++) {
			if (strcmp(ksp->ks_module, g_network[i]) == 0)
				ok = 1;
		}

		/* Skip if this isn't a network module */
		if (ok == 0) continue;
		if (kstat_read(kc, ksp, NULL) == -1) continue;
		if ((kstat_data_lookup(ksp, "obytes") == NULL) &&
		    (kstat_data_lookup(ksp, "obytes64") == NULL)) continue;

		/* Check for tracked interfaces */
		if (g_someints) {
			for (ok = 0, i = 0; *g_tracked[i] != NULL; i++) {
				if (strcmp(ksp->ks_name, g_tracked[i]) == 0)
					ok = 1;
			}
			if (ok == 0) continue;
		}

		/* Save network values */
		g_idnew[num].rbytes = fetch6432(ksp, "rbytes64", "rbytes", 0);
		g_idnew[num].wbytes = fetch6432(ksp, "obytes64", "obytes", 0);
		g_idnew[num].rpackets =
		    fetch6432(ksp, "ipackets64", "ipackets", 0);
		g_idnew[num].wpackets =
		    fetch6432(ksp, "opackets64", "opackets", 0);
		g_idnew[num].sat = fetch32(ksp, "defer", 0);
		g_idnew[num].sat += fetch_nocanput(ksp, 0);
		g_idnew[num].sat += fetch32(ksp, "norcvbuf", 0);
		g_idnew[num].sat += fetch32(ksp, "noxmtbuf", 0);
		g_idnew[num].time = time(0);
    fetchstr( ksp, "zonename", g_idnew[num].zone );		
/* if the speed can't be fetched, this makes %util 0.0 */
		g_idnew[num].speed = fetch64(ksp, "ifspeed", 1LL << 48);
		(void) strcpy(g_idnew[num].name, ksp->ks_name);

		num++;
	}
	g_interfacemax = num - 1;
}
コード例 #3
0
ファイル: syscall.c プロジェクト: asegid/cs537
// Fetch the nth word-sized system call argument as a string pointer.
// Check that the pointer is valid and the string is nul-terminated.
// (There is no shared writable memory, so the string can't change
// between this check and being used by the kernel.)
int
argstr(int n, char **pp)
{
 int addr;

  if(argint(n, &addr) < 0)
    return -1;

//  if((uint)addr<proc->sz)
  //cprintf("argstr executing\n");
 if(((uint)addr>=proc->sz)&&((uint)addr<proc->stack_top)){
    //cprintf("ARGstr ERROR\n");

    return -1;
  }

//  cprintf("argstr 2 executing\n");
  return fetchstr(proc, addr, pp);
}