Permalink
Browse files

enabled key system on core I/O

  • Loading branch information...
1 parent 082535d commit da6e7d47eeb07f27d42e48bfbfd1016a2641d1b9 @nickbjohnson4224 committed Jan 30, 2012
View
4 driver/biterm/main.c
@@ -155,8 +155,8 @@ int main(int argc, char **argv) {
}
}
else {
- kbd_dev = ropen(-1, fs_find(argv[1]), ACCS_EVENT);
- fb_dev = ropen(-1, fs_find(argv[2]), ACCS_READ | ACCS_WRITE | ACCS_EVENT);
+ kbd_dev = open(argv[1], ACCS_EVENT);
+ fb_dev = open(argv[2], ACCS_READ | ACCS_WRITE | ACCS_EVENT);
if (kbd_dev < 0) {
fprintf(stderr, "%s: %s: keyboard not found\n", argv[0], argv[1]);
View
2 libc/exec/load_exec.c
@@ -55,7 +55,7 @@ void *load_exec(const char *path) {
return NULL;
}
- if (rp_read(fd_rp(fd), image, size, 0) != size) {
+ if (rp_read(fd_rp(fd), fd_getkey(fd, AC_READ), image, size, 0) != size) {
free(image);
close(fd);
return NULL;
View
6 libc/exec/load_shared.c
@@ -41,9 +41,9 @@ void *load_shared(const char *soname) {
return NULL;
- fd = ropen(-1, fs_find(path), ACCS_READ);
+ fd = open(path, ACCS_READ);
- if (fd < 0 || !rp_type(fd_rp(fd), "file")) {
+ if (fd < 0) {
/* file not found */
return NULL;
}
@@ -61,7 +61,7 @@ void *load_shared(const char *soname) {
return NULL;
}
- if (rp_read(fd_rp(fd), image, size, 0) != size) {
+ if (rp_read(fd_rp(fd), fd_getkey(fd, AC_READ), image, size, 0) != size) {
free(image);
close(fd);
return NULL;
View
2 libc/graph/fb_cons.c
@@ -62,7 +62,7 @@ struct fb *fb_cons(uint64_t rp) {
memclr(fb->bitmap, sizeof(uint32_t) * fb->xdim * fb->ydim);
// check for shared memory interface
- if (rp_mmap(rp, fb->bitmap,
+ if (rp_mmap(rp, fd_getkey(fb->fd, AC_WRITE), fb->bitmap,
fb->xdim * fb->ydim * sizeof(uint32_t), 0, PROT_READ | PROT_WRITE)) {
// successful
fb->flags |= FB_SHARED;
View
2 libc/graph/fb_flip.c
@@ -56,7 +56,7 @@ int fb_flip(struct fb *fb) {
}
else {
// not shared: write whole buffer
- if (!rp_write(fd_rp(fb->fd), fb->bitmap,
+ if (!rp_write(fd_rp(fb->fd), fd_getkey(fb->fd, AC_WRITE), fb->bitmap,
fb->xdim * fb->ydim * sizeof(uint32_t), 0)) {
mutex_free(&fb->mutex);
return 1;
View
3 libc/graph/fb_resize.c
@@ -49,7 +49,8 @@ int fb_resize(struct fb *fb, int xdim, int ydim) {
if (fb->flags & FB_SHARED) {
// re-acquire shared memory
- rp_mmap(fb->rp, fb->bitmap, xdim * ydim * sizeof(uint32_t), 0, PROT_READ | PROT_WRITE);
+ rp_mmap(fb->rp, fd_getkey(fb->fd, AC_WRITE),
+ fb->bitmap, xdim * ydim * sizeof(uint32_t), 0, PROT_READ | PROT_WRITE);
}
// reset flip acceleration
View
4 libc/graph/fb_setbmp.c
@@ -41,7 +41,7 @@ int fb_setbmp(struct fb *fb, uint32_t *bitmap) {
// unshare old bitmap
if (fb->flags & FB_SHARED) {
- rp_share(fb->rp, NULL, 0, 0, 0);
+ rp_share(fb->rp, fd_getkey(fb->fd, AC_WRITE), NULL, 0, 0, 0);
fb->flags &= ~FB_SHARED;
}
@@ -55,7 +55,7 @@ int fb_setbmp(struct fb *fb, uint32_t *bitmap) {
fb->flags |= FB_USRBMP;
// check for shared memory interface
- if (!rp_share(fb->rp, fb->bitmap,
+ if (!rp_share(fb->rp, fd_getkey(fb->fd, AC_WRITE), fb->bitmap,
fb->xdim * fb->ydim * sizeof(uint32_t), 0, PROT_READ)) {
// successful
fb->flags |= FB_SHARED;
View
4 libc/graph/fb_setmode.c
@@ -14,6 +14,8 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <rhombus.h>
+
#include <string.h>
#include <stdlib.h>
@@ -39,7 +41,7 @@ int fb_setmode(struct fb *fb, int xdim, int ydim) {
if (fb->flags & FB_SHARED) {
// release shared memory
- rp_share(fb->rp, NULL, 0, 0, 0);
+ rp_share(fb->rp, fd_getkey(fb->fd, AC_WRITE), NULL, 0, 0, 0);
}
sprintf(args, "setmode %d %d 32", xdim, ydim);
View
12 libc/inc/rho/natio.h
@@ -29,12 +29,12 @@
/* core I/O *****************************************************************/
-size_t rp_read (rp_t rp, void *buf, size_t size, off_t offset);
-size_t rp_write(rp_t rp, void *buf, size_t size, off_t offset);
-int rp_sync (rp_t rp);
-int rp_reset(rp_t rp);
-int rp_share(rp_t rp, void *buf, size_t size, off_t offset, int prot);
-void *rp_mmap (rp_t rp, void *addr, size_t size, off_t offset, int prot);
+size_t rp_read (rp_t rp, rk_t key, void *buf, size_t size, off_t offset);
+size_t rp_write(rp_t rp, rk_t key, void *buf, size_t size, off_t offset);
+int rp_sync (rp_t rp, rk_t key);
+int rp_reset(rp_t rp, rk_t key);
+int rp_share(rp_t rp, rk_t key, void *buf, size_t size, off_t offset, int prot);
+void *rp_mmap (rp_t rp, rk_t key, void *addr, size_t size, off_t offset, int prot);
rp_t rp_cons(rp_t rp, const char *type);
off_t rp_size(rp_t rp);
View
25 libc/inc/unistd.h
@@ -30,10 +30,6 @@
#define _POSIX_VERSION 200112L
#define _POSIX2_VERSION 200112L
-unsigned int alarm(unsigned int seconds);
-int chdir(const char *path);
-size_t confstr(int, char *, size_t);
-
/* File access **************************************************************/
int access(const char *pathname, int mode); // TODO
@@ -50,7 +46,12 @@ int dup (int fd);
int dup2 (int fd, int newfd);
int pipe (int pipefd[2]);
-int isatty(int); // TODO
+int isatty (int fd); // TODO
+int isafile(int fd); // TODO
+int isadir (int fd); // TODO
+int isalink(int fd); // TODO
+int isashm (int fd); // TODO
+int isaevnt(int fd); // TODO
/* Links ********************************************************************/
@@ -63,11 +64,11 @@ ssize_t readlink(const char * restrict, char * restrict, size_t); // TODO
/* I/O **********************************************************************/
-off_t lseek (int fd, off_t offset, int whence);
-ssize_t read (int fd, void *buf, size_t count);
-ssize_t pread (int fd, void *buf, size_t count, off_t offset);
-ssize_t write (int fd, const void *buf, size_t count);
-ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset);
+off_t lseek (int fd, off_t offset, int whence); // TODO
+ssize_t read (int fd, void *buf, size_t count); // TODO
+ssize_t pread (int fd, void *buf, size_t count, off_t offset); // TODO
+ssize_t write (int fd, const void *buf, size_t count); // TODO
+ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset);// TODO
/* Execution ****************************************************************/
@@ -122,4 +123,8 @@ pid_t tcgetpgrp(int);
char *ttyname(int);
int ttyname_r(int, char *, size_t);
+unsigned int alarm(unsigned int seconds);
+int chdir(const char *path);
+size_t confstr(int, char *, size_t);
+
#endif/*__RLIBC_UNISTD_H*/
View
3 libc/natio/mmap.c
@@ -43,7 +43,7 @@
* uint8_t pages[]
*/
-void *rp_mmap(rp_t rp, void *addr, size_t size, off_t offset, int prot) {
+void *rp_mmap(rp_t rp, rk_t key, void *addr, size_t size, off_t offset, int prot) {
struct msg *msg;
int allocated;
@@ -90,6 +90,7 @@ void *rp_mmap(rp_t rp, void *addr, size_t size, off_t offset, int prot) {
// format message
msg->source = RP_CURRENT_THREAD;
msg->target = rp;
+ msg->key = key;
msg->length = sizeof(uint64_t) + 2 * sizeof(uint32_t);
msg->action = ACTION_MMAP;
msg->arch = ARCH_NAT;
View
7 libc/natio/read.c
@@ -39,13 +39,14 @@
* uint8_t data[]
*/
-size_t rp_read(uint64_t file, void *buf, size_t size, uint64_t offset) {
+size_t rp_read(uint64_t file, rk_t key, void *buf, size_t size, uint64_t offset) {
struct msg *msg;
msg = aalloc(sizeof(struct msg) + sizeof(uint64_t) + sizeof(uint32_t), PAGESZ);
if (!msg) return 0;
msg->source = RP_CURRENT_THREAD;
msg->target = file;
+ msg->key = key;
msg->length = sizeof(uint64_t) + sizeof(uint32_t);
msg->action = ACTION_READ;
msg->arch = ARCH_NAT;
@@ -64,7 +65,3 @@ size_t rp_read(uint64_t file, void *buf, size_t size, uint64_t offset) {
free(msg);
return size;
}
-
-int __zab(int x) {
- return x + 1;
-}
View
3 libc/natio/reset.c
@@ -27,13 +27,14 @@
* Deletes the contents of the file <file>.
*/
-int rp_reset(uint64_t file) {
+int rp_reset(uint64_t file, rk_t key) {
struct msg *msg;
msg = aalloc(sizeof(struct msg), PAGESZ);
if (!msg) return 1;
msg->source = RP_CURRENT_THREAD;
msg->target = file;
+ msg->key = key;
msg->length = 0;
msg->action = ACTION_RESET;
msg->arch = ARCH_NAT;
View
3 libc/natio/share.c
@@ -42,7 +42,7 @@
* uint8_t err;
*/
-int rp_share(uint64_t rp, void *buf, size_t size, uint64_t offset, int prot) {
+int rp_share(uint64_t rp, rk_t key, void *buf, size_t size, uint64_t offset, int prot) {
struct msg *msg;
int err;
@@ -55,6 +55,7 @@ int rp_share(uint64_t rp, void *buf, size_t size, uint64_t offset, int prot) {
if (!msg) return 1;
msg->source = RP_CURRENT_THREAD;
msg->target = rp;
+ msg->key = key;
msg->length = PAGESZ - sizeof(struct msg) + size;
msg->action = ACTION_SHARE;
msg->arch = ARCH_NAT;
View
3 libc/natio/sync.c
@@ -30,13 +30,14 @@
* some sort and guarantees pending writes are performed.
*/
-int rp_sync(uint64_t file) {
+int rp_sync(uint64_t file, rk_t key) {
struct msg *msg;
msg = aalloc(sizeof(struct msg), PAGESZ);
if (!msg) return 1;
msg->source = RP_CURRENT_THREAD;
msg->target = file;
+ msg->key = key;
msg->length = 0;
msg->action = ACTION_SYNC;
msg->arch = ARCH_NAT;
View
3 libc/natio/write.c
@@ -39,13 +39,14 @@
* uint32_t size
*/
-size_t rp_write(uint64_t file, void *buf, size_t size, uint64_t offset) {
+size_t rp_write(uint64_t file, rk_t key, void *buf, size_t size, uint64_t offset) {
struct msg *msg;
msg = aalloc(sizeof(struct msg) + sizeof(uint64_t) + size, PAGESZ);
if (!msg) return 0;
msg->source = RP_CURRENT_THREAD;
msg->target = file;
+ msg->key = key;
msg->length = sizeof(uint64_t) + size;
msg->action = ACTION_WRITE;
msg->arch = ARCH_NAT;
View
4 libc/rhombus/fdtab.c
@@ -121,12 +121,8 @@ rk_t fd_getkey(int fd, int action) {
return 0ULL;
}
- mutex_spin(&_fdtab_mutex);
-
key = _fdtab[fd].key[action];
- mutex_free(&_fdtab_mutex);
-
return key;
}
View
2 libc/stdio/fdopen.c
@@ -67,7 +67,7 @@ FILE *fdopen(int fd, const char *mode) {
// reset (erase) the file contents
if (mode[0] == 'w') {
- rp_reset(fd_rp(fd));
+ rp_reset(fd_rp(fd), fd_getkey(fd, AC_WRITE));
}
stream = calloc(sizeof(FILE), 1);
View
3 libc/stdio/fflush.c
@@ -36,7 +36,8 @@ int fflush(FILE *stream) {
mutex_spin(&stream->mutex);
if (stream->buffer && stream->buffpos) {
- size = rp_write(fd_rp(stream->fd), stream->buffer, stream->buffpos, stream->position);
+ size = rp_write(fd_rp(stream->fd), fd_getkey(stream->fd, AC_WRITE),
+ stream->buffer, stream->buffpos, stream->position);
stream->position += size;
stream->buffpos -= size;
}
View
2 libc/stdio/fopen.c
@@ -84,7 +84,7 @@ FILE *fopen(const char *path, const char *mode) {
// reset (erase) the file contents
if (mode[0] == 'w') {
- rp_reset(rp);
+ rp_reset(rp, fd_getkey(fd, AC_WRITE));
}
// open a stream on the file
View
3 libc/stdio/fread.c
@@ -50,7 +50,8 @@ size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream) {
rev_count = 0;
}
- ret = rp_read(fd_rp(stream->fd), ptr, nmemb - rev_count, stream->position);
+ ret = rp_read(fd_rp(stream->fd), fd_getkey(stream->fd, AC_READ),
+ ptr, nmemb - rev_count, stream->position);
stream->position += ret;
ret += rev_count;
View
8 libc/stdio/fwrite.c
@@ -50,7 +50,8 @@ size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) {
// no buffering
if (stream->flags & FILE_NBF) {
- ret = rp_write(fd_rp(stream->fd), (void*) ptr, size * nmemb, stream->position);
+ ret = rp_write(fd_rp(stream->fd), fd_getkey(stream->fd, AC_WRITE),
+ (void*) ptr, size * nmemb, stream->position);
stream->position += ret;
if (size == 0) {
@@ -109,7 +110,7 @@ static int __bufwrite(FILE *stream) {
for (pos = 0; pos < stream->buffpos;) {
- count = rp_write(fd_rp(stream->fd),
+ count = rp_write(fd_rp(stream->fd), fd_getkey(stream->fd, AC_WRITE),
stream->buffer, stream->buffpos - pos, stream->position);
if (count == 0) {
@@ -131,7 +132,8 @@ static int __nobufwrite(FILE *stream, void *data, size_t size) {
for (pos = 0; pos < size;) {
- count = rp_write(fd_rp(stream->fd), data, size - pos, stream->position);
+ count = rp_write(fd_rp(stream->fd), fd_getkey(stream->fd, AC_WRITE),
+ data, size - pos, stream->position);
if (count == 0) {
return -1;
View
8 librdi/class_file.c
@@ -56,13 +56,11 @@ static void __rdi_read(struct msg *msg) {
return;
}
-#ifdef KEYSEC
if (msg->key != file->key[AC_READ]) {
// access denied (key invalid)
merror(msg);
return;
}
-#endif
if (rdi_global_read_hook) {
// use global hook if defined
@@ -116,13 +114,11 @@ static void __rdi_write(struct msg *msg) {
return;
}
-#ifdef KEYSEC
if (msg->key != file->key[AC_WRITE]) {
// access denied
merror(msg);
return;
}
-#endif
if (rdi_global_write_hook) {
// use global hook if defined
@@ -165,13 +161,11 @@ static void __rdi_share(struct msg *msg) {
return;
}
-#ifdef KEYSEC
if (msg->key != file->key[AC_WRITE]) {
// access denied
merror(msg);
return;
}
-#endif
if (!rdi_global_share_hook) {
merror(msg);
@@ -212,7 +206,6 @@ static void __rdi_mmap(struct msg *msg) {
prot = ((uint32_t*) msg->data)[3];
-#ifdef KEYSEC
if (prot & PROT_WRITE) {
if (msg->key != file->key[AC_WRITE]) {
merror(msg);
@@ -225,7 +218,6 @@ static void __rdi_mmap(struct msg *msg) {
return;
}
}
-#endif
if (!rdi_global_mmap_hook) {
merror(msg);

0 comments on commit da6e7d4

Please sign in to comment.