Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 6 May 2004 10:57:25 +0300
From:      Artis Caune <artis-ml@fbsd.lv>
To:        freebsd-hackers@freebsd.org
Subject:   ioctl
Message-ID:  <20040506075725.GA1056@fbsd.lv>

next in thread | raw e-mail | index | archive | help
Is it correct to use code like this
instead of copyin() / copyout() ?
Kernel module gets pointer to structure
which resides in userland memory space
and modify it directly!!!
   > userland: ioctl(tp_fd, TP_GET_TP_STATS, &tp_stats)
   > kernel:   tp_stats->hooked = hooked;
(freebsd 5.x, KLD)


-----   START userland   -----

#define TP_GET_TP_STATS _IOR('D', 200, struct tp_stats_s)

struct tp_stats_s {
	int hooked;
	u_short policer_active_pipes;
} tp_stats;

if (ioctl(tp_fd, TP_GET_TP_STATS, &tp_stats) != -1) {

    printf("Traffic Policer is %s\n",
           tp_stats.hooked ? "enabled" : "disabled");
    printf("statistics:\n");
    printf("  %-30s%u\n", "pipes hash table depth",
           tp_stats.policer_pipes_hash_depth);
    printf("  %-30s%u\n", "active pipes",
           tp_stats.policer_active_pipes);
  } else
    fprintf(stderr, "IOCTL error\n");

-----   END userland   -----



-----   START kernel   -----

static int
tp_dev_ioctl (dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
{
  switch (cmd) {
  case TP_GET_TP_STATS:
    err = get_tp_stats((struct tp_stats_s *)addr);
    break;
...
}

static int
get_tp_stats (struct tp_stats_s *tp_stats)
{
  TP_LOCK;
  tp_stats->hooked = hooked;
  /* hash depth will be gone in -release, just for debug */
  tp_stats->policer_pipes_hash_depth = policer_pipes_hash_depth;
  tp_stats->policer_active_pipes = policer_get_active_pipes();
  TP_UNLOCK;

  return (0);
}
...
-----   END kernel   -----



thanks,

-- 
Artis



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040506075725.GA1056>