summaryrefslogtreecommitdiffstats
path: root/drivers/staging/comedi/comedi_buf.c
diff options
context:
space:
mode:
authorIan Abbott <abbotti@mev.co.uk>2017-04-20 19:05:14 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-04-25 20:43:42 +0200
commit255364f7b8a0fee3fb642b3e1521e943dd67bfb3 (patch)
tree9b67464441cc98d69eece7d42852637ee3dd89ca /drivers/staging/comedi/comedi_buf.c
parente44adf05b85e5a9d1d224f5ecde1c1c5e5371e36 (diff)
staging: comedi: support vm_access_process for mmap'd buffer
If a process that has mmap'd a COMEDI buffer is being run under a debugger such as GDB, the buffer contents are inaccessible from the debugger. Support the `access()` VM operation to allow the buffer contents to be accessed by another process. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/comedi/comedi_buf.c')
-rw-r--r--drivers/staging/comedi/comedi_buf.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c
index 1e1df89b5018..8e9b30b26810 100644
--- a/drivers/staging/comedi/comedi_buf.c
+++ b/drivers/staging/comedi/comedi_buf.c
@@ -161,6 +161,30 @@ int comedi_buf_map_put(struct comedi_buf_map *bm)
return 1;
}
+/* helper for "access" vm operation */
+int comedi_buf_map_access(struct comedi_buf_map *bm, unsigned long offset,
+ void *buf, int len, int write)
+{
+ unsigned int pgoff = offset & ~PAGE_MASK;
+ unsigned long pg = offset >> PAGE_SHIFT;
+ int done = 0;
+
+ while (done < len && pg < bm->n_pages) {
+ int l = min_t(int, len - done, PAGE_SIZE - pgoff);
+ void *b = bm->page_list[pg].virt_addr + pgoff;
+
+ if (write)
+ memcpy(b, buf, l);
+ else
+ memcpy(buf, b, l);
+ buf += l;
+ done += l;
+ pg++;
+ pgoff = 0;
+ }
+ return done;
+}
+
/* returns s->async->buf_map and increments its kref refcount */
struct comedi_buf_map *
comedi_buf_map_from_subdev_get(struct comedi_subdevice *s)