int main(int argc, char** argv) { g_task_register_id("init"); // load spawner process g_ramdisk_spawn_status spawner_stat = g_ramdisk_spawn("applications/spawner.bin", G_SECURITY_LEVEL_KERNEL); if (spawner_stat != G_RAMDISK_SPAWN_STATUS_SUCCESSFUL) { g_logger::log("unable to load system spawner process"); yield: asm("hlt"); goto yield; } // wait for spawner to get ready g_tid spawner_id; while ((spawner_id = g_task_get_id(G_SPAWNER_IDENTIFIER)) == -1) { g_yield(); } // let the spawner load the launch service g_pid ls_pid; std::string launch_srv_path = "/applications/launch.bin"; g_spawn_status stat = g_spawn_p(launch_srv_path.c_str(), "/system/launch/init", "/", G_SECURITY_LEVEL_KERNEL, &ls_pid); if (stat == G_SPAWN_STATUS_SUCCESSFUL) { g_logger::log("launch service executed in process %i", ls_pid); } else { g_logger::log("failed to load launch service from '" + launch_srv_path + "' with code %i", stat); } }
void wait(ls_statement_t* stat) { std::string identifier = stat->pairs[0]->value; klog(("waiting for '" + identifier + "'").c_str()); while (g_task_get_id(identifier.c_str()) == -1) { g_yield(); } }
void g_mouse::registerMouse() { uint32_t ps2driverid = g_task_get_id(G_PS2_DRIVER_IDENTIFIER); if (ps2driverid == -1) { return; } mouseTopic = g_ipc_next_topic(); g_ps2_register_request request; request.command = G_PS2_COMMAND_REGISTER_MOUSE; g_send_message_t(ps2driverid, &request, sizeof(g_ps2_register_request), mouseTopic); }
/** * Opens a connection to the window server. */ g_ui_open_status g_ui::open() { // check if already open if (g_ui_initialized) { return G_UI_OPEN_STATUS_EXISTING; } // get window managers id g_tid window_mgr = g_task_get_id(G_UI_REGISTRATION_THREAD_IDENTIFIER); if (window_mgr == -1) { klog("failed to retrieve task id of window server with identifier '%s'", G_UI_REGISTRATION_THREAD_IDENTIFIER); return G_UI_OPEN_STATUS_COMMUNICATION_FAILED; } // start event dispatcher g_ui_event_dispatcher_tid = g_create_thread((void*) &event_dispatch_thread); // send initialization request g_message_transaction init_tx = g_get_message_tx_id(); g_ui_initialize_request request; request.header.id = G_UI_PROTOCOL_INITIALIZATION; g_send_message_t(window_mgr, &request, sizeof(g_ui_initialize_request), init_tx); // receive initialization response uint32_t response_buffer_size = sizeof(g_message_header) + sizeof(g_ui_initialize_response); g_local<uint8_t> response_buffer(new uint8_t[response_buffer_size]); if (g_receive_message_t(response_buffer(), response_buffer_size, init_tx) != G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL) { klog("failed to communicate with the window server"); return G_UI_OPEN_STATUS_COMMUNICATION_FAILED; } // check response g_ui_initialize_response* response = (g_ui_initialize_response*) G_MESSAGE_CONTENT(response_buffer()); if (response->status != G_UI_PROTOCOL_SUCCESS) { klog("failed to open UI"); return G_UI_OPEN_STATUS_FAILED; } // mark UI as ready g_ui_initialized = true; g_ui_delegate_tid = response->window_server_delegate_thread; return G_UI_OPEN_STATUS_SUCCESSFUL; }
/** * Opens a connection to the window server. */ g_ui_open_status g_ui::open() { // check if already open if (g_ui_ready) { return G_UI_OPEN_STATUS_EXISTING; } // get window managers id g_tid window_mgr = g_task_get_id(G_WINDOW_MANAGER_IDENTIFIER); if (window_mgr == -1) { g_logger::log("failed to retrieve task id of window server"); return G_UI_OPEN_STATUS_COMMUNICATION_FAILED; } // open in/out pipes g_fs_pipe_status status; g_fd g_ui_channel_out_read; g_pipe_s(&g_ui_channel_out, &g_ui_channel_out_read, &status); g_fd g_ui_channel_in_write; g_pipe_s(&g_ui_channel_in_write, &g_ui_channel_in, &status); if (status == G_FS_PIPE_ERROR) { g_logger::log("failed to open UI communication pipe"); return G_UI_OPEN_STATUS_COMMUNICATION_FAILED; } // tell window manager to open uint32_t topic = g_ipc_next_topic(); g_message_empty(open_request); open_request.type = G_UI_COMMAND_OPEN_REQUEST; open_request.topic = topic; open_request.parameterA = g_ui_channel_out_read; open_request.parameterB = g_ui_channel_in_write; auto request_status = g_send_msg(window_mgr, &open_request); if (request_status != G_MESSAGE_SEND_STATUS_SUCCESSFUL) { g_logger::log("failed to send UI-open request to window server"); return G_UI_OPEN_STATUS_COMMUNICATION_FAILED; } // wait for response g_message_empty(open_response); auto response_status = g_recv_topic_msg(g_get_tid(), topic, &open_response); if (response_status != G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL) { g_logger::log("failed to receive UI-open response from window server"); return G_UI_OPEN_STATUS_COMMUNICATION_FAILED; } // check response message if (open_response.type != G_UI_COMMAND_OPEN_RESPONSE) { g_logger::log("window servers UI-open response was not a proper 'opened'-response"); return G_UI_OPEN_STATUS_COMMUNICATION_FAILED; } // start asynchronous receiver g_create_thread((void*) &asynchronous_receiver_thread); g_create_thread((void*) &event_dispatch_thread); // mark UI as ready g_logger::log("successfully opened UI in window server"); g_ui_ready = true; return G_UI_OPEN_STATUS_SUCCESSFUL; }
g_spawn_status g_spawn_poi(const char* path, const char* args, const char* workdir, g_security_level securityLevel, g_pid* pid, g_fd out_stdio[3], g_fd in_stdio[3]) { g_spawn_status res = G_SPAWN_STATUS_UNKNOWN; uint32_t tid = g_get_tid(); // get spawner task identifier g_tid spawner_tid = g_task_get_id(G_SPAWNER_IDENTIFIER); if (spawner_tid == -1) { return res; } // create transaction g_message_transaction tx = g_get_message_tx_id(); // create request size_t path_bytes = __g_strlen(path) + 1; size_t args_bytes = __g_strlen(args) + 1; size_t workdir_bytes = __g_strlen(workdir) + 1; size_t requestlen = sizeof(g_spawn_command_spawn_request) + path_bytes + args_bytes + workdir_bytes; g_local<uint8_t> _request(new uint8_t[requestlen]); uint8_t* request = _request(); // copy request contents g_spawn_command_spawn_request* req = (g_spawn_command_spawn_request*) request; req->header.command = G_SPAWN_COMMAND_SPAWN_REQUEST; req->security_level = securityLevel; req->path_bytes = path_bytes; req->args_bytes = args_bytes; req->workdir_bytes = workdir_bytes; if (in_stdio != nullptr) { req->stdin = in_stdio[0]; req->stdout = in_stdio[1]; req->stderr = in_stdio[2]; } else { req->stdin = G_FD_NONE; req->stdout = G_FD_NONE; req->stderr = G_FD_NONE; } uint8_t* insert = request; insert += sizeof(g_spawn_command_spawn_request); __g_memcpy(insert, path, path_bytes); insert += path_bytes; __g_memcpy(insert, args, args_bytes); insert += args_bytes; __g_memcpy(insert, workdir, workdir_bytes); // send request to spawner g_send_message_t(spawner_tid, request, requestlen, tx); // receive response size_t resp_len = sizeof(g_message_header) + sizeof(g_spawn_command_spawn_response); g_local<uint8_t> resp_buf(new uint8_t[resp_len]); g_receive_message_t(resp_buf(), resp_len, tx); g_spawn_command_spawn_response* response = (g_spawn_command_spawn_response*) G_MESSAGE_CONTENT(resp_buf()); // if successful, take response parameters if (response->status == G_SPAWN_STATUS_SUCCESSFUL) { if (pid != nullptr) { *pid = response->spawned_process_id; } if (out_stdio != nullptr) { out_stdio[0] = response->stdin_write; out_stdio[1] = response->stdout_read; out_stdio[2] = response->stderr_read; } } return response->status; }