Changeset View
Changeset View
Standalone View
Standalone View
lib/libvmmapi/vmmapi.c
Context not available. | |||||
#define PROT_RW (PROT_READ | PROT_WRITE) | #define PROT_RW (PROT_READ | PROT_WRITE) | ||||
#define PROT_ALL (PROT_READ | PROT_WRITE | PROT_EXEC) | #define PROT_ALL (PROT_READ | PROT_WRITE | PROT_EXEC) | ||||
struct vmctx { | |||||
int fd; | |||||
uint32_t lowmem_limit; | |||||
int memflags; | |||||
size_t lowmem; | |||||
size_t highmem; | |||||
char *baseaddr; | |||||
char *name; | |||||
}; | |||||
#define CREATE(x) sysctlbyname("hw.vmm.create", NULL, NULL, (x), strlen((x))) | #define CREATE(x) sysctlbyname("hw.vmm.create", NULL, NULL, (x), strlen((x))) | ||||
#define DESTROY(x) sysctlbyname("hw.vmm.destroy", NULL, NULL, (x), strlen((x))) | #define DESTROY(x) sysctlbyname("hw.vmm.destroy", NULL, NULL, (x), strlen((x))) | ||||
Context not available. | |||||
grehan: Might be best to pass in a length param - if NULL, the length would be returned but no copy… | |||||
Not Done Inline ActionsCan I keep the static allocation of the table and just pass a pointer to it or would you prefer dynamic allocation and forcing caller to free() it? kaktus: Can I keep the static allocation of the table and just pass a pointer to it or would you prefer… | |||||
Not Done Inline ActionsNot a lot of prior art in libc :(, but my preference would be to return a const pointer (and size param). grehan: Not a lot of prior art in libc :(, but my preference would be to return a const pointer (and… | |||||
Not Done Inline Actionsminor style(9) nit - an extra blank line should be inserted here (also matches other one-line functions in the file). grehan: minor style(9) nit - an extra blank line should be inserted here (also matches other one-line… | |||||
Not Done Inline ActionsAs above, this can be cap_ioctl_t grehan: As above, this can be cap_ioctl_t | |||||
Not Done Inline ActionsMinor style nit: bcopy is used in all other routines in this file. grehan: Minor style nit: bcopy is used in all other routines in this file. | |||||
Not Done Inline ActionsNot getting this part why we just don't do a global from that? oshogbo: Not getting this part why we just don't do a global from that? | |||||
Not Done Inline ActionsAPI refinement suggested by @jhb in https://lists.freebsd.org/pipermail/svn-src-all/2017-February/139587.html I wonder if instead of doing this in the executable and exposing vm_get_ioctls, etc. if the API shouldn't really be something like 'vm_limit_rights(ctx)' and this code should be in that function in libvmmapi? It would be something like (assuming you drop vm_get_ioctls() entirely and expose vm_ioctl_cmds[] as a static global in the library): int vm_limit_rights(struct vm_ctx *ctx) { ... cap_rights_init(&rights, CAP_IOCTL, CAP_MMAP_RW); if (cap_rights_limit(ctx->fd, &rights) == -1) { if (errno == ENOSYS) return (0); else return (-1); } /* Shouldn't get ENOSYS here if cap_rights_limit worked. */ return (cap_ioctls_limit(ctx->fd, vm_ioctl_cmds, nitems(vm_ioctl_cmds)); } You wouldn't need vm_get_device_fd() either in this API. emaste: API refinement suggested by @jhb in https://lists.freebsd.org/pipermail/svn-src-all/2017… |
Might be best to pass in a length param - if NULL, the length would be returned but no copy done, similar to how sysctl works. This allows the caller to determine the size of it's buffer.