Example #1
0
void RequestHandler::send(g_fd out, g_ui_transaction_id transaction, uint8_t* data, uint32_t length) {

	// lock
	g_atomic_lock(&sending_locked);

	// write transaction id
	uint32_t idlen = sizeof(g_ui_transaction_id);
	uint8_t idbytes[idlen];
	*((g_ui_transaction_id*) idbytes) = transaction;
	g_write(out, idbytes, idlen);

	// write length
	uint32_t lenlen = sizeof(uint32_t);
	uint8_t lenbytes[lenlen];
	*((uint32_t*) lenbytes) = length;
	g_write(out, lenbytes, lenlen);

	// write data
	uint32_t written = 0;
	while (written < length) {
		written += g_write(out, &data[written], length - written);
	}

	// unlock
	sending_locked = false;
}
Example #2
0
void RequestHandler::event_dispatch_thread() {

	// register a name
	std::stringstream namestr;
	namestr << "windowserver:event-dispatcher";
	g_task_register_id(namestr.str().c_str());

	while (true) {
		// wait for events
		g_atomic_block(&event_dispatch_events_empty);

		// lock
		g_atomic_lock(&sending_locked);

		// call listener
		UIEventDispatchData ldata = event_dispatch_queue.back();
		event_dispatch_queue.pop_back();

		// write transaction id
		uint32_t idlen = sizeof(g_ui_transaction_id);
		uint8_t idbytes[idlen];
		*((g_ui_transaction_id*) idbytes) = 0;
		g_write(ldata.output, idbytes, idlen);

		// write length
		uint32_t lenlen = sizeof(uint32_t);
		uint8_t lenbytes[lenlen];
		*((uint32_t*) lenbytes) = ldata.length + 4;
		g_write(ldata.output, lenbytes, lenlen);

		// write listener id
		uint32_t lidlen = sizeof(uint32_t);
		uint8_t lidbytes[lidlen];
		*((uint32_t*) lidbytes) = ldata.listener;
		g_write(ldata.output, lidbytes, lidlen);

		// write data
		uint32_t written = 0;
		while (written < ldata.length) {
			written += g_write(ldata.output, &ldata.data[written], ldata.length - written);
		}

		// delete the data
		delete ldata.data;

		// check if empty
		if (event_dispatch_queue.empty()) {
			event_dispatch_events_empty = true;
		}

		// unlock
		sending_locked = false;
	}
}
void g_write(char name[]) {
    const identifier* tp = getReadTableItem(name);
    if (tp == null) {
        error(49, lineNumber);  //error : identifier undefined.
        return;
    }
    if (tp->datat == inttype ||tp->datat == intarrtype) {
        g_write(inttype);
    }
    else if (tp->datat == chartype || tp->datat == chararrtype) {
        g_write(chartype);
    }
}
Example #4
0
/**
 * Sends a message (thread-safe) to the window manager.
 */
g_ui_transaction_id g_ui::send(uint8_t* data, uint32_t length) {

	// check if ready
	if (!g_ui_ready) {
		return -1;
	}

	static uint8_t sending_locked = false;

	// lock
	g_atomic_lock(&sending_locked);

	// create transaction
	g_ui_transaction_id transaction = next_transaction++;

	// create data for response
	g_ui_transaction_data* response_data = new g_ui_transaction_data;
	response_data->data = 0;
	response_data->length = 0;
	response_data->waiting = true;

	// insert to map
	if (transaction_map == 0) {
		transaction_map = new std::map<g_ui_transaction_id, g_ui_transaction_data*>();
	}
	transaction_map->insert(std::make_pair(transaction, response_data));

	// write transaction id
	uint32_t idlen = sizeof(g_ui_transaction_id);
	uint8_t idbytes[idlen];
	*((g_ui_transaction_id*) idbytes) = transaction;
	g_write(g_ui_channel_out, idbytes, idlen);

	// write length
	uint32_t lenlen = sizeof(uint32_t);
	uint8_t lenbytes[lenlen];
	*((uint32_t*) lenbytes) = length;
	g_write(g_ui_channel_out, lenbytes, lenlen);

	// write data
	int32_t written = 0;
	while (written < length) {
		written += g_write(g_ui_channel_out, &data[written], length - written);
	}

	// unlock
	sending_locked = false;

	return transaction;
}
Example #5
0
void
mono_crash_dump (const char *jsonFile, MonoStackHash *hashes)
{
	size_t size = strlen (jsonFile);

	gboolean success = FALSE;

	// Save up to 100 dump files for a given stacktrace hash
	for (int increment = 0; increment < 100; increment++) {
		char name [100]; 
		name [0] = '\0';
		g_snprintf (name, sizeof (name), "mono_crash.%" PRIx64 ".%d.json", hashes->offset_free_hash, increment);

		int handle = g_open (name, O_WRONLY | O_CREAT | O_EXCL, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH);
		if (handle != -1) {
			g_write (handle, jsonFile, (guint32) size);
			success = TRUE;
		}

		/*cleanup*/
		if (handle)
			close (handle);

		if (success)
			return;
	}

	g_assertf (!success, "Couldn't create any of (many) attempted crash files\n");
	return;
}
Example #6
0
static gint64 gst_disk_cache_append_file(int file, gpointer data, glong size)
{
  gint64 pos = g_lseek64(file, 0, SEEK_END);
  if(size == g_write(file, data, size))
    return pos;
  else
    return -1;
}
Example #7
0
static gboolean
mono_merp_write_fingerprint_payload (const char *non_param_data, const MERPStruct *merp)
{
	int handle = g_open (merp->crashLogPath, O_TRUNC | O_WRONLY | O_CREAT, merp_file_permissions);
	g_assertf (handle != -1, "Could not open crash log file at %s", merp->crashLogPath);

	g_async_safe_fprintf(handle, "{\n");
	g_async_safe_fprintf(handle, "\t\"payload\" : \n");
	g_write (handle, non_param_data, (guint32)strlen (non_param_data));	\
	g_async_safe_fprintf(handle, ",\n");

	g_async_safe_fprintf(handle, "\t\"parameters\" : \n{\n");
	g_async_safe_fprintf(handle, "\t\t\"ApplicationBundleId\" : \"%s\",\n", merp->bundleIDArg);
	g_async_safe_fprintf(handle, "\t\t\"ApplicationVersion\" : \"%s\",\n", merp->versionArg);
	g_async_safe_fprintf(handle, "\t\t\"ApplicationBitness\" : \"%s\",\n", get_merp_bitness (merp->archArg));
	g_async_safe_fprintf(handle, "\t\t\"ApplicationName\" : \"%s\",\n", merp->serviceNameArg);
	g_async_safe_fprintf(handle, "\t\t\"BlameModuleName\" : \"%s\",\n", merp->moduleName);
	g_async_safe_fprintf(handle, "\t\t\"BlameModuleVersion\" : \"%s\",\n", merp->moduleVersion);
	g_async_safe_fprintf(handle, "\t\t\"BlameModuleOffset\" : \"0x%lx\",\n", merp->moduleOffset);
	g_async_safe_fprintf(handle, "\t\t\"ExceptionType\" : \"%s\",\n", get_merp_exctype (merp->exceptionArg));
	g_async_safe_fprintf(handle, "\t\t\"StackChecksum\" : \"0x%llx\",\n", merp->hashes.offset_free_hash);
	g_async_safe_fprintf(handle, "\t\t\"StackHash\" : \"0x%llx\",\n", merp->hashes.offset_rich_hash);
	g_async_safe_fprintf(handle, "\t\t\"Extra\" : \n\t\t{\n");

	for (GSList *cursor = merp->annotations; cursor; cursor = cursor->next) {
		MonoMerpAnnotationEntry *iter = (MonoMerpAnnotationEntry *) cursor->data;
		g_async_safe_fprintf(handle, "\t\t\t\"%s\" : \"%s\"\n", iter->key, iter->value);
	}

	g_async_safe_fprintf(handle, "\t\t},\n");

	// Provided by icall
	g_async_safe_fprintf(handle, "\t\t\"OSVersion\" : \"%s\",\n", merp->osVersion);
	g_async_safe_fprintf(handle, "\t\t\"LanguageID\" : \"0x%x\",\n", merp->uiLidArg);
	g_async_safe_fprintf(handle, "\t\t\"SystemManufacturer\" : \"%s\",\n", merp->systemManufacturer);
	g_async_safe_fprintf(handle, "\t\t\"SystemModel\" : \"%s\",\n", merp->systemModel);
	g_async_safe_fprintf(handle, "\t\t\"EventType\" : \"%s\"\n", merp->eventType);

	// End of parameters 
	g_async_safe_fprintf(handle, "\t}\n");
	g_async_safe_fprintf(handle, "}\n");

	// End of object
	close (handle);

	return TRUE;
}
Example #8
0
// -----------------------------------------------------------------
// Flush lbuf to output, resetting buf_length
static void flush_lbuf_to_file(gauge_file *gf, fmatrix *lbuf,
                               int *buf_length) {

  FILE *fp = gf->fp;
  int stat;

  if (*buf_length <= 0)
    return;

  stat = (int)g_write(lbuf, 4 * sizeof(fmatrix), *buf_length, fp);
  if (stat != *buf_length) {
    printf("w_serial: node%d gauge configuration write error %d file %s\n",
           this_node, errno, gf->filename);
    fflush(stdout);
    terminate(1);
  }
  *buf_length = 0;
}
Example #9
0
gboolean
mono_state_alloc_mem (MonoStateMem *mem, long tag, size_t size)
{
	char name [100];
	mem_file_name (tag, name, sizeof (name));

	memset (mem, 0, sizeof (*mem));
	mem->tag = tag;
	mem->size = size;

	mem->handle = g_open (name, O_RDWR | O_CREAT | O_EXCL, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH);
	if (mem->handle < 1) {
		mem->mem = (gpointer *) mmap (0, mem->size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
	} else {
		lseek (mem->handle, mem->size, SEEK_SET);
		g_write (mem->handle, "", 1);

		mem->mem = (gpointer *) mmap (0, mem->size, PROT_READ | PROT_WRITE, MAP_SHARED, mem->handle, 0);
	}
	if (mem->mem == GINT_TO_POINTER (-1))
		return FALSE;

	return TRUE;
}
Example #10
0
static int f_write (lua_State *L) {
  return g_write(L, tofile(L), 2);
}
Example #11
0
static int io_write (lua_State *L) {
  return g_write(L, getiofile(L, IO_OUTPUT), 1);
}
Example #12
0
static int f_write(lua_State *L) {
	FILE *f = tofile(L);
	lua_pushvalue(L, 1);  /* push file at the stack top (to be returned) */
	return g_write(L, f, 2);
}
Example #13
0
static gboolean gst_disk_cache_write_file(int file, gint64 pos, gpointer data, glong size)
{
  g_lseek64(file, pos, SEEK_SET);

  return size == g_write(file, data, size);
}
Example #14
0
 int LuaIOLib::file_write(lua_State *lua)
 {
     auto file = cast_userdata<LuaFile>(lua, 1);
     lua_pushvalue(lua, 1);
     return g_write(lua, file->file(), 2);
 }
Example #15
0
int Client::cWrite(const char *msg, int msg_size)
{
    return g_write(sockfd, msg, msg_size);
}
Example #16
0
static int io_write (lua_State *L) {
  return g_write(L, getiofile(L, IO_OUTPUT), 1);
	//am_log("LUA", lua_tostring(L, -1));
	//lua_pushboolean(L, true);
	//return 1;
}