Plan B User's Manual


Name

bufbox, vmboxaddr, vmbox, varbox ­ Boxes for process memory

Synopsis

#include <ulib.h>

void* vmboxaddr(char* s, USeg **sp)
char* vmbox(void* p, ulong sz, char* c)
char* bufbox(buf, char* c)
char* varbox(var, char* c)

Description

As described in vm(4), virtual memory boxes are used to wrap portions of the application address space using either symbolic names or address ranges. Vmboxaddr is used by the application to obtain the machine address for a virtual memory box with name s. This is useful when a virtual memory box named s has been created previously using make(2). Vmboxaddr is not a system call. It is a library function that reads a table maintained by the kernel in user memory to describe the set of virtual memory boxes.

If sp is non-nil, the pointer at *sp is initialized to point to a USeg structure containing information about the box.

struct USeg {
Lock;        // usr/kernel sync.
char    sel[MAXSEL];// "" are for kernel.
ulong start;// segment address
ulong limit;// one past allocated bytes
ulong size; // actual # of bytes used
};
Most fields are self-explanatory. The Lock can be used to prevent external access to the box while its contents are in use. The kernel sets the lock while accessing box contents; the user may do the same.

Vmbox is used to obtain the name for a virtual memory box given an address range starting at address p and containing l addresses. The name obtained can be used to operate on the box. The parameter c is contatenated as a constraint to the name built. The macros varbox and bufbox call vmbox to return the box name for an array buf or a variable var in scope. The box name is created in static storage and is rewritten on each call. It is also important to note that the named box is mem unless otherwise specified by user (see the example below).

Example

void* p;
USeg *l;
maken("/b/proc/me/vm/x");
p = vmboxaddr("x", &l);
memset(p, 0xff, l->size);

This code creates a segment named x and then obtains its address and length to initialize it to "0xff"s.
void* p;
maken("/b/proc/me/vm/buff");
copy("/some/box", "/b/proc/me/vm/buff");
p = vmboxaddr("buff", nil);
cprint("got %s", p);

This code copies data from /some/box into local memory at address p.
struct S v;
char    buf[N];
...
copy("/some/box", varbox(v, nil));
copy(bufbox(buf, "text"), "/other/box");
copy("/b/proc/me/vm/0x4cd000:0x4ce000", "/some/box");

The first call copies the contents of /some/box to the variable v. The second call copies the contents of buf into /other/box, using text as the type for the virtual memory range box. The third call would copy the memory starting at address 0x4cd000 up to (but not including) 0x4ce000 to /some/box.

Source

/src/b/*/u.c

See also

vm(4) and intro(2).

Bugs

Vmbox uses static storage.


Plan B User's Manual. First edition.