mm: remove the path arguments to foc_abs_path()
authorBarret Rhoden <brho@cs.berkeley.edu>
Sun, 12 May 2019 23:03:35 +0000 (19:03 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Sun, 12 May 2019 23:03:35 +0000 (19:03 -0400)
I think the VFS version of foc_abs_path() needed the buffer for the
storage of the absolute path, since the VFS didn't maintain that
internally.  9ns maintains that pointer, so we can just return it.

The lifetime of that chan's name should be the lifetime of the chan
itself.  Although I can imagine cases where that isn't true, e.g. if you
walk a chan to another chan, hopefully those chans are externalized to
the rest of the system, i.e. only used in chan.c during walk().  Keep in
mind walks from O_PATH chans.

If that turns out to not be the case, then we can copy it out, though
even then we'd need to understand when the chan's name is changing,
since there's no reason it can't be changed during foc_abs_path().

Similarly, I'd like to know if we ever have a chan exposed to the rest
of the system that has no name.  The answer to this is probably related
to whether or not the chan's name can change.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/drivers/dev/proc.c
kern/include/mm.h
kern/src/mm.c
kern/src/profiler.c

index c12ace7..16bf9dc 100644 (file)
@@ -411,7 +411,7 @@ static void build_maps_cb(struct vm_region *vmr, void *arg)
        unsigned long inode_nr;
 
        if (vmr_has_file(vmr)) {
-               path = foc_abs_path(vmr->__vm_foc, path_buf, sizeof(path_buf));
+               path = foc_abs_path(vmr->__vm_foc);
                inode_nr = 0; /* TODO: do we care about this? */
        } else {
                strlcpy(path_buf, "[heap]", sizeof(path_buf));
index 9569aa1..d1ec141 100644 (file)
@@ -30,7 +30,7 @@ struct file_or_chan {
 };
 
 char *foc_to_name(struct file_or_chan *foc);
-char *foc_abs_path(struct file_or_chan *foc, char *path, size_t max_size);
+char *foc_abs_path(struct file_or_chan *foc);
 ssize_t foc_read(struct file_or_chan *foc, void *buf, size_t amt, off64_t off);
 struct file_or_chan *foc_open(char *path, int omode, int perm);
 struct file_or_chan *fd_to_foc(struct fd_table *fdt, int fd);
index 1284ed8..b5249ed 100644 (file)
@@ -65,10 +65,14 @@ char *foc_to_name(struct file_or_chan *foc)
        panic("unknown F_OR_C type");
 }
 
-char *foc_abs_path(struct file_or_chan *foc, char *path, size_t max_size)
+char *foc_abs_path(struct file_or_chan *foc)
 {
        switch (foc->type) {
        case F_OR_C_CHAN:
+               /* Not sure, but I'd like to know if we have externally visible
+                * chans that have no name. */
+               assert(foc->chan->name);
+               assert(foc->chan->name->s);
                return foc->chan->name->s;
        }
        panic("unknown F_OR_C type");
index 6103027..63bc68f 100644 (file)
@@ -533,20 +533,13 @@ void profiler_notify_mmap(struct proc *p, uintptr_t addr, size_t size, int prot,
                           int flags, struct file_or_chan *foc, size_t offset)
 {
        struct profiler *prof;
+       char *path;
 
        rcu_read_lock();
        prof = rcu_dereference(gbl_prof);
-       if (prof) {
-               if (foc && (prot & PROT_EXEC)) {
-                       char path_buf[PROFILER_MAX_PRG_PATH];
-                       char *path = foc_abs_path(foc, path_buf,
-                                                 sizeof(path_buf));
-
-                       if (likely(path))
-                               profiler_push_pid_mmap(prof, p, addr, size,
-                                                      offset, path);
-               }
-       }
+       if (prof && foc && (prot & PROT_EXEC))
+               profiler_push_pid_mmap(prof, p, addr, size, offset,
+                                      foc_abs_path(foc));
        rcu_read_unlock();
 }