Merge branch 'master' of github.com:klange/osdev

This commit is contained in:
Kevin Lange 2012-02-20 23:32:10 -06:00
commit 2da22312a5
13 changed files with 54 additions and 37 deletions

View File

@ -34,7 +34,7 @@ typedef struct {
} shm_mapping_t; } shm_mapping_t;
/* Syscalls */ /* Syscalls */
extern void * shm_obtain (char * path, size_t size); extern void * shm_obtain (char * path, size_t * size);
extern int shm_release (char * path); extern int shm_release (char * path);
/* Other exposed functions */ /* Other exposed functions */

View File

@ -184,12 +184,17 @@ static void * map_in (shm_chunk_t * chunk, process_t * proc) {
return (void *)mapping->vaddrs[0]; return (void *)mapping->vaddrs[0];
} }
static size_t chunk_size (shm_chunk_t * chunk) {
return (size_t)(chunk->num_frames * 0x1000);
}
/* Kernel-Facing Functions and Syscalls */ /* Kernel-Facing Functions and Syscalls */
void * shm_obtain (char * path, size_t size) { void * shm_obtain (char * path, size_t * size) {
validate(path); validate(path);
validate(size);
spin_lock(&bsl); spin_lock(&bsl);
process_t * proc = (process_t *)current_process; process_t * proc = (process_t *)current_process;
@ -204,7 +209,7 @@ void * shm_obtain (char * path, size_t size) {
return NULL; return NULL;
} }
chunk = create_chunk(node, size); chunk = create_chunk(node, *size);
if (chunk == NULL) { if (chunk == NULL) {
LOG(ERROR, "[shm] Could not allocate a shm_chunk_t!\n"); LOG(ERROR, "[shm] Could not allocate a shm_chunk_t!\n");
return NULL; return NULL;
@ -216,7 +221,7 @@ void * shm_obtain (char * path, size_t size) {
chunk->ref_count++; chunk->ref_count++;
} }
void * vshm_start = map_in(chunk, proc); void * vshm_start = map_in(chunk, proc);
*size = chunk_size(chunk);
spin_unlock(&bsl); spin_unlock(&bsl);

View File

@ -301,7 +301,8 @@ void waitabit() {
wins_server_global_t volatile * _request_page; wins_server_global_t volatile * _request_page;
void init_request_system () { void init_request_system () {
_request_page = (wins_server_global_t *)syscall_shm_obtain(WINS_SERVER_IDENTIFIER, sizeof(wins_server_global_t)); size_t size = sizeof(wins_server_global_t);
_request_page = (wins_server_global_t *)syscall_shm_obtain(WINS_SERVER_IDENTIFIER, &size);
if (!_request_page) { if (!_request_page) {
fprintf(stderr, "[wins] Could not get a shm block for its request page! Bailing..."); fprintf(stderr, "[wins] Could not get a shm block for its request page! Bailing...");
exit(-1); exit(-1);
@ -474,8 +475,12 @@ char * loadMemFont(char * ident, char * name, size_t * size) {
fseek(f, 0, SEEK_END); fseek(f, 0, SEEK_END);
s = ftell(f); s = ftell(f);
fseek(f, 0, SEEK_SET); fseek(f, 0, SEEK_SET);
printf("loading %s, size %d\n", name, s); printf("loading %s, size %d\n", name, s);
char * font = (char *)syscall_shm_obtain(ident, s); //malloc(s); size_t shm_size = s;
char * font = (char *)syscall_shm_obtain(ident, &shm_size); //malloc(s);
assert((shm_size >= s) && "shm_obtain returned too little memory to load a font into!");
fread(font, s, 1, f); fread(font, s, 1, f);
printf("First few bytes are %x%x%x%x\n", font[0], font[1], font[2], font[3]); printf("First few bytes are %x%x%x%x\n", font[0], font[1], font[2], font[3]);

View File

@ -35,7 +35,7 @@ DEFN_SYSCALL0(getgraphicswidth, 18);
DEFN_SYSCALL0(getgraphicsheight, 19); DEFN_SYSCALL0(getgraphicsheight, 19);
DEFN_SYSCALL0(getgraphicsdepth, 20); DEFN_SYSCALL0(getgraphicsdepth, 20);
*/ */
DEFN_SYSCALL2(shm_obtain, 35, char *, int) DEFN_SYSCALL2(shm_obtain, 35, char *, size_t *)
DEFN_SYSCALL1(shm_release, 36, char *) DEFN_SYSCALL1(shm_release, 36, char *)
@ -74,10 +74,11 @@ int main (int argc, char ** argv) {
char * julia_window_key = "julia2.windowbuffer"; char * julia_window_key = "julia2.windowbuffer";
char * game_window_key = "game2.windowbuffer"; char * game_window_key = "game2.windowbuffer";
char * julia_window = (char *)syscall_shm_obtain(julia_window_key, SIZE); size_t size = SIZE;
char * game_window = (char *)syscall_shm_obtain(game_window_key, SIZE); char * julia_window = (char *)syscall_shm_obtain(julia_window_key, &size);
memset(julia_window, 0, SIZE); char * game_window = (char *)syscall_shm_obtain(game_window_key, &size);
memset(game_window, 0, SIZE); memset(julia_window, 0, size);
memset(game_window, 0, size);
/* Fork off two children */ /* Fork off two children */
if (!fork()) { if (!fork()) {

View File

@ -11,7 +11,7 @@
DEFN_SYSCALL1(kbd_mode, 12, int); DEFN_SYSCALL1(kbd_mode, 12, int);
DEFN_SYSCALL0(kbd_get, 13); DEFN_SYSCALL0(kbd_get, 13);
DEFN_SYSCALL2(shm_obtain, 35, char *, int) DEFN_SYSCALL2(shm_obtain, 35, char *, size_t *)
DEFN_SYSCALL1(shm_release, 36, char *) DEFN_SYSCALL1(shm_release, 36, char *)
typedef struct sprite { typedef struct sprite {
@ -337,8 +337,8 @@ int main(int argc, char ** argv) {
return -2; return -2;
} }
int buf_size = (graphics_width * graphics_depth * graphics_depth); size_t buf_size = (graphics_width * graphics_depth * graphics_depth);
gfx_mem = (void *)syscall_shm_obtain(argv[4], buf_size); gfx_mem = (void *)syscall_shm_obtain(argv[4], &buf_size);
if (!gfx_mem) { if (!gfx_mem) {
return 1; return 1;
} }

View File

@ -16,7 +16,7 @@
*/ */
DEFN_SYSCALL1(kbd_mode, 12, int); DEFN_SYSCALL1(kbd_mode, 12, int);
DEFN_SYSCALL0(kbd_get, 13); DEFN_SYSCALL0(kbd_get, 13);
DEFN_SYSCALL2(shm_obtain, 35, char *, int) DEFN_SYSCALL2(shm_obtain, 35, char *, size_t *)
DEFN_SYSCALL1(shm_release, 36, char *) DEFN_SYSCALL1(shm_release, 36, char *)
uint16_t graphics_width = 0; uint16_t graphics_width = 0;
@ -116,8 +116,8 @@ int main(int argc, char ** argv) {
return -2; return -2;
} }
int buf_size = (GFX_W * GFX_H * GFX_B); size_t buf_size = (GFX_W * GFX_H * GFX_B);
gfx_mem = (void *)syscall_shm_obtain(argv[4], buf_size); gfx_mem = (void *)syscall_shm_obtain(argv[4], &buf_size);
if (!gfx_mem) { if (!gfx_mem) {
return 1; return 1;
} }

View File

@ -16,7 +16,7 @@
#include "window.h" #include "window.h"
#if 1 #if 1
DEFN_SYSCALL2(shm_obtain, 35, char *, int) DEFN_SYSCALL2(shm_obtain, 35, char *, size_t *)
DEFN_SYSCALL1(shm_release, 36, char *) DEFN_SYSCALL1(shm_release, 36, char *)
DEFN_SYSCALL2(send_signal, 37, int, int) DEFN_SYSCALL2(send_signal, 37, int, int)
DEFN_SYSCALL2(sys_signal, 38, int, int) DEFN_SYSCALL2(sys_signal, 38, int, int)
@ -66,8 +66,8 @@ window_t * init_window (process_windows_t * pw, wid_t wid, int32_t x, int32_t y,
char key[1024]; char key[1024];
SHMKEY(key, 1024, window); SHMKEY(key, 1024, window);
/* And now the fucked up stuff happens */ size_t size = (width * height * WIN_B);
window->buffer = (uint8_t *)syscall_shm_obtain(key, (width * height * WIN_B)); window->buffer = (uint8_t *)syscall_shm_obtain(key, &size);
if (!window->buffer) { if (!window->buffer) {
fprintf(stderr, "[%d] [window] Could not create a buffer for a new window for pid %d!", getpid(), pw->pid); fprintf(stderr, "[%d] [window] Could not create a buffer for a new window for pid %d!", getpid(), pw->pid);
@ -102,8 +102,8 @@ window_t * init_window_client (process_windows_t * pw, wid_t wid, int32_t x, int
char key[1024]; char key[1024];
SHMKEY_(key, 1024, window); SHMKEY_(key, 1024, window);
/* And now the fucked up stuff happens */ size_t size = (width * height * WIN_B);
window->buffer = (uint8_t *)syscall_shm_obtain(key, (width * height * WIN_B)); window->buffer = (uint8_t *)syscall_shm_obtain(key, &size);
if (!window->buffer) { if (!window->buffer) {
fprintf(stderr, "[%d] [window] Could not create a buffer for a new window for pid %d!", getpid(), pw->pid); fprintf(stderr, "[%d] [window] Could not create a buffer for a new window for pid %d!", getpid(), pw->pid);
@ -152,8 +152,9 @@ void resize_window_buffer (window_t * window, int16_t left, int16_t top, uint16_
/* Create the new one */ /* Create the new one */
window->bufid++; window->bufid++;
SHMKEY(key, 256, window); SHMKEY(key, 256, window);
window->buffer = (uint8_t *)syscall_shm_obtain(key, (width * height * WIN_B)); size_t size = (width * height * WIN_B);
memset(window->buffer, 0, (width * height * WIN_B)); window->buffer = (uint8_t *)syscall_shm_obtain(key, &size);
memset(window->buffer, 0, size);
} }
window->x = left; window->x = left;
@ -431,7 +432,8 @@ int wins_connect() {
return 0; return 0;
} }
wins_globals = (volatile wins_server_global_t *)syscall_shm_obtain(WINS_SERVER_IDENTIFIER, sizeof(wins_server_global_t)); size_t size = sizeof(wins_server_global_t);
wins_globals = (volatile wins_server_global_t *)syscall_shm_obtain(WINS_SERVER_IDENTIFIER, &size);
if (!wins_globals) { if (!wins_globals) {
fprintf(stderr, "[%d] [window] Unable to connect with wins through shared memory.\n", getpid()); fprintf(stderr, "[%d] [window] Unable to connect with wins through shared memory.\n", getpid());
return EACCES; return EACCES;

View File

@ -12,7 +12,7 @@
#include "graphics.h" #include "graphics.h"
DECL_SYSCALL2(shm_obtain, char *, int); DECL_SYSCALL2(shm_obtain, char *, size_t *);
DECL_SYSCALL1(shm_release, char *); DECL_SYSCALL1(shm_release, char *);
DECL_SYSCALL2(send_signal, int, int); DECL_SYSCALL2(send_signal, int, int);
DECL_SYSCALL2(sys_signal, int, int); DECL_SYSCALL2(sys_signal, int, int);

View File

@ -7,7 +7,7 @@
#include <stdlib.h> #include <stdlib.h>
DEFN_SYSCALL2(shm_obtain, 35, char *, int) DEFN_SYSCALL2(shm_obtain, 35, char *, size_t *)
DEFN_SYSCALL1(shm_release, 36, char *) DEFN_SYSCALL1(shm_release, 36, char *)
#define SHMSZ 27 #define SHMSZ 27
@ -26,8 +26,9 @@ int main(int argc, char ** argv) {
/* /*
* Attach the segment to our data space. * Attach the segment to our data space.
*/ */
size_t size = SHMSZ;
malloc(9 * 0x1000); // Make our heap a bit different from the server malloc(9 * 0x1000); // Make our heap a bit different from the server
if ((shm = (char *)syscall_shm_obtain(key, SHMSZ)) == (char *) NULL) { if ((shm = (char *)syscall_shm_obtain(key, &size)) == (char *) NULL) {
printf("Client: syscall_shm_mount returned NULL!\n"); printf("Client: syscall_shm_mount returned NULL!\n");
return 1; return 1;
} }

View File

@ -7,7 +7,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
DEFN_SYSCALL2(shm_obtain, 35, char *, int) DEFN_SYSCALL2(shm_obtain, 35, char *, size_t *)
DEFN_SYSCALL1(shm_release, 36, char *) DEFN_SYSCALL1(shm_release, 36, char *)
#define SHMSZ 27 #define SHMSZ 27
@ -26,7 +26,8 @@ int main(int argc, char ** argv) {
/* /*
* Attach to the shared memory chunk * Attach to the shared memory chunk
*/ */
if ((shm = (char *)syscall_shm_obtain(key, SHMSZ)) == (char *) NULL) { size_t size = SHMSZ;
if ((shm = (char *)syscall_shm_obtain(key, &size)) == (char *) NULL) {
return 1; return 1;
} }
printf("Server: mounted to 0x%x\n", shm); printf("Server: mounted to 0x%x\n", shm);

View File

@ -6,7 +6,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
DEFN_SYSCALL2(shm_obtain, 35, char *, int) DEFN_SYSCALL2(shm_obtain, 35, char *, size_t *)
DEFN_SYSCALL1(shm_release, 36, char *) DEFN_SYSCALL1(shm_release, 36, char *)
@ -23,7 +23,8 @@ int main (int argc, char ** argv) {
printf("(This should fork and the child process (but not the parent) should segfault)\n"); printf("(This should fork and the child process (but not the parent) should segfault)\n");
volatile char * shm = (char *)syscall_shm_obtain(argv[1], 27); size_t size = 27;
volatile char * shm = (char *)syscall_shm_obtain(argv[1], &size);
if (shm == NULL) { if (shm == NULL) {
return 1; return 1;
} }

View File

@ -6,7 +6,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
DEFN_SYSCALL2(shm_obtain, 35, char *, int) DEFN_SYSCALL2(shm_obtain, 35, char *, size_t *)
DEFN_SYSCALL1(shm_release, 36, char *) DEFN_SYSCALL1(shm_release, 36, char *)
@ -18,7 +18,8 @@ int main (int argc, char ** argv) {
printf("(this should not crash; but the kernel should free the shm block)\n"); printf("(this should not crash; but the kernel should free the shm block)\n");
volatile char * shm = (char *)syscall_shm_obtain(argv[1], 0x1000); size_t size = 0x1000;
volatile char * shm = (char *)syscall_shm_obtain(argv[1], &size);
if (shm == NULL) { if (shm == NULL) {
return 1; return 1;
} }

View File

@ -5,13 +5,13 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
DEFN_SYSCALL2(shm_obtain, 35, char *, int) DEFN_SYSCALL2(shm_obtain, 35, char *, size_t *)
#define KEY "shm_test3.mem" #define KEY "shm_test3.mem"
#define MAGIC 111 #define MAGIC 111
int client_proc(uint32_t size) { int client_proc(uint32_t size) {
volatile unsigned char * mem = (volatile unsigned char *)syscall_shm_obtain(KEY, size); volatile unsigned char * mem = (volatile unsigned char *)syscall_shm_obtain(KEY, &size);
while (mem[0] != MAGIC) {} while (mem[0] != MAGIC) {}
mem[0] = (uint8_t)(MAGIC + 1); mem[0] = (uint8_t)(MAGIC + 1);
@ -28,7 +28,7 @@ int client_proc(uint32_t size) {
} }
int server_proc(uint32_t size) { int server_proc(uint32_t size) {
volatile unsigned char * mem = (volatile unsigned char *)syscall_shm_obtain(KEY, size); volatile unsigned char * mem = (volatile unsigned char *)syscall_shm_obtain(KEY, &size);
for (uint32_t i = 1; i < size; i++) { for (uint32_t i = 1; i < size; i++) {
mem[i] = (unsigned char)i; mem[i] = (unsigned char)i;