コード例 #1
0
ファイル: shmcrash.c プロジェクト: jrziviani/osdev
int main (int argc, char ** argv) {
	if (argc < 2) {
		fprintf(stderr, "%s: expected argument\n", argv[0]);
		return 1;
	}

	printf("(This should fork and the child process (but not the parent) should segfault)\n");

	size_t size = 27;
	volatile char * shm = (char *)syscall_shm_obtain(argv[1], &size);
	if (shm == NULL) {
		return 1;
	}

	int pid = getpid();
	uint32_t f = fork();
	if (getpid() != pid) {
		// Child: client
		return main_client(shm);
	} else {
		// Parent: server
		return main_server(shm);
	}

	return 0;
}
コード例 #2
0
ファイル: shmemfonts.c プロジェクト: descent/osdev
/*
 * XXX: take font name as an argument / allow multiple fonts
 */
static void _loadSansSerif() {
	char * font;
	size_t s = 0;
	int error;
	font = (char *)syscall_shm_obtain(WINS_SERVER_IDENTIFIER ".fonts.sans-serif", &s);
	error = FT_New_Memory_Face(library, font, s, 0, &face);
	error = FT_Set_Pixel_Sizes(face, FONT_SIZE, FONT_SIZE);
}
コード例 #3
0
ファイル: shmemfonts.c プロジェクト: Saruta/ToyOS
/*
 * XXX: take font name as an argument / allow multiple fonts
 */
static void _load_font(int i, char * name) {
	char * font;
	size_t s = 0;
	int error;
	char tmp[100];
	snprintf(tmp, 100, "sys.%s%s", getenv("DISPLAY"), name);

	font = (char *)syscall_shm_obtain(tmp, &s);
	error = FT_New_Memory_Face(library, font, s, 0, &faces[i]);
	error = FT_Set_Pixel_Sizes(faces[i], FONT_SIZE, FONT_SIZE);
}
コード例 #4
0
ファイル: shman.c プロジェクト: Munix-Project/munix-helios
static shm_t * shm_connect(uint8_t device_type, char * id, char * unique_id) {
	/* RULES: if device is a client and the id is non existant, throw an error*/
	/* otherwise, if it exists, connect into the server */
	/* else if it's a server and the id doesn't exist, create one*/
	/* otherwise, if the id exists and the device is a server, throw an error*/
	if(device_type == SHM_DEV_CLIENT && (!hashmap_contains(shm_network, id) || !servers_online)) {
		/* Can't connect to that server. It is offline / doesn't exist */
		return (shm_t*)SHM_ERR_SERV_NOEXIST;
	} else if(device_type == SHM_DEV_SERVER && hashmap_contains(shm_network, id)) {
		/* That server is already online. We don't want to have ID conflicts */
		return (shm_t*)SHM_ERR_SERV_ALREADYON;
	}

	/*
	 * Before we even try to connect as client, we must know if the server we're
	 * connecting to is also online
	 */
	if(device_type == SHM_DEV_CLIENT) {
		if(get_server_from_network(id)->dev_status == SHM_STAT_OFFLINE) {
			/* Oops, the server is offline */
			return (shm_t*)SHM_ERR_SERV_OFFLINE;
		}
	}

	/* All seems good. We're continuing the function */

	shm_t * shm_new_dev = malloc(sizeof(shm_t));

	shm_new_dev->dev_type = device_type; /* Set its type */
	shm_new_dev->dev_status = SHM_STAT_ONLINE; /* Set device as online */

	strcpy(shm_new_dev->shm_key, id); /* Set its ID so we know what server we're called/what server we're connected to */
	strcpy(shm_new_dev->unique_id, unique_id);
	shm_new_dev->shm = (char*)syscall_shm_obtain(id, &shman_size);
	memset(shm_new_dev->shm, 0, shman_size);

	/* Add this device into a hashmap with a list (which indicates the nodes connected to the hash) as value and ID as key */
	if(device_type == SHM_DEV_SERVER)
		add_server_to_network(shm_new_dev);
	else
		add_client_to_list(shm_new_dev);

	return shm_new_dev;
}
コード例 #5
0
ファイル: shm_server.c プロジェクト: campaul/osdev
int main(int argc, char ** argv) {
	char c;
	volatile char *shm;
	volatile char *s;

	if (argc < 2) {
		fprintf(stderr, "%s: expected argument\n", argv[0]);
		return 1;
	}
	char * key = argv[1];

	/*
	 * Attach to the shared memory chunk
	 */
	size_t size = SHMSZ;
	if ((shm = (char *)syscall_shm_obtain(key, &size)) == (char *) NULL) {
		return 1;
	}
	printf("Server: mounted to 0x%x\n", shm);

	/*
	 * Now put some things into the memory for the
	 * other process to read.
	 */
	s = shm;

	for (c = 'a'; c <= 'z'; c++)
		*s++ = c;
	*s = '\0';


	/*
	 * Finally, we wait until the other process 
	 * changes the first character of our memory
	 * to '*', indicating that it has read what 
	 * we put there.
	 */
	while (*shm != '*') {}

	return 0;
}
コード例 #6
0
ファイル: shman.c プロジェクト: Munix-Project/munix-helios
/*
 * shm_network_init - Shared Memory Manager constructor
 */
static void shm_network_init() {
	shm_network = hashmap_create(1);
	shm_client_list = hashmap_create(1);
	shm_cmd = (char*) syscall_shm_obtain(SHM_RESKEY_SHMAN_CMD, &shman_size);
}