NAME | FEATURES | DESCRIPTION | EXAMPLES | FILES | ATTRIBUTES | SEE ALSO
DEV_MEM
Two devices are available on top of ChorusOS: /dev/kmem and /dev/mem . A generic driver (which works with the MEM_FLAT, MEM_PROTECTED or MEM_VIRTUAL modules) managing these devices is enabled when the DEV_MEM feature is set to true. They may be read, written, and sought, but not memory-mapped (the mmap() primitive is not supported). In addition, an ioctl() is available to implement two specific BSD4.4 system calls, sysctl() and kvm_nlist() .
These devices are built using the mknod utility as follows:
mknod /dev/kmem c 2 1 mknod /dev/mem c 2 0
/dev/kmem is used to access the supervisor address space, and /dev/mem the physical memory space. When the memory model is flat, you can access the kernel space or the physical memory using these two devices. When VIRTUAL_ADDRESS_SPACE is set to true, /dev/mem is used to access physical memory and /dev/kmem is used to access the supervisor space.
The ioctl() function on /dev/kmem implements the following 4.4BSD specific system calls:
include <sys/memio.h> include <cx/memio.h> int sysctl(char* mib, u_int size, void* old, size_t* oldlenp, void* new, size_t newlen)
where
mib[0] = CTL_NET
or
mib[0] = CTL_KERN , mib[1] = KERN_FILE
and
kvm_nlist(kvm_t kvmd, struct nlist* nl)
On top of ChorusOS sysctl() is partially implemented. The following system I/O controls are not supported: CTL_HW , CTL_VM , CTL_FS , CTL_MACDEP , CTL_DEBUG and CTL_KERN with a mib[1] value different from KERN_FILE.
char mib[6]; int res size_t needed; mib[0] = CTL_KERN; mib[1] = PF_ROUTE; mib[2] = 0; mib[3] = 0; mib[4] = NET_RT_DUMP; mib[5] = 0; res = sysctl(mib, 6, NULL, &needed, NULL, 0);
is implemented on top of ChorusOS as follows:
char mib[6]; int res int kvmd; MemIoctl ioctl_args; size_t needed; mib[0] = CTL_KERN; mib[1] = PF_ROUTE; mib[2] = 0; mib[3] = 0; mib[4] = NET_RT_DUMP; mib[5] = 0; ioctl_args.name = mib; ioctl_args.namelen = 6; ioctl_args.old = NULL; ioctl_args.oldlenp = &needed; ioctl_args.new = NULL; ioctl_args.newlen = 0; ioctl_args.retval = NULL; kvmd = open("/dev/kmem", O_RDONLY); /* ... */ res = ioctl(kvmd, MEMIORW, &ioctl_args);
The kvm_nlist() function used to get the values of a symbols list is translated on top of ChorusOS as follows:
struct nlist nl [] = { ... }; MemSymb ioctl_args; int kvmd; kvmd = open("/dev/kmem", O_RDONLY); /* ... */ ioctl_args.nlistp = nl; ioctl_args.len = sizeof(nl); res = ioctl(kvmd, MEMNLIST, &ioctl_args);
The ioctl() returns 0 when no error has occurred. It is possible that no symbol is found, in this case no value is copied out. Consequently, before calling this primitive, each symbol value must be erased as follows: nl[i].n_value = NULL . A non NULL returned value stored in n_value field will indicate that the symbol is found. Other ioctl() commands are available in the memio.h file for future use.
/dev/kmem , /dev/mem
See attributes(5) for descriptions of the following attributes:
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
---|---|
Interface Stability | Evolving |
NAME | FEATURES | DESCRIPTION | EXAMPLES | FILES | ATTRIBUTES | SEE ALSO