Esempio n. 1
0
void*
hiloDestruccion()
{
  t_nodo_proceso * nodoARemover;
  while (1)
    {
      sem_wait(&sem_listaTerminados);
      pthread_mutex_lock(&mutex_listaTerminados);
      nodoARemover = queue_pop(listaTerminados);
      pthread_mutex_unlock(&mutex_listaTerminados);
      int pidARemover = nodoARemover->pcb.pid;
      debugTrackPLP("[Achievement] Removing process %d from the system.",pidARemover);
      debugTrackPLP("Requesting segment destroy...");
      t_datosEnviar * paquete = pedirPaquete((void*) &pidARemover,
          KERNEL_DESTRUIR_SEGMENTOS_PROGRAMA, sizeof(int));
      common_send(socketUMV, paquete, NULL );
      destruirPaquete(paquete);
      paquete = pedirPaquete("T", PROGRAMA_CERRAR, 2);
      common_send(nodoARemover->soquet_prog, paquete, NULL );
      destruirPaquete(paquete);
      free(nodoARemover);
    }
  return NULL ;

}
Esempio n. 2
0
void*
hiloDestruccion()
{
  t_nodo_proceso * nodoARemover;
  while (1)
    {
      sem_wait(&sem_listaTerminados);
      pthread_mutex_lock(&mutex_listaTerminados);
      nodoARemover = queue_pop(listaTerminados);
      pthread_mutex_unlock(&mutex_listaTerminados);
      int pidARemover = nodoARemover->pcb.pid;
      log_info(log_kernel,"Sacando el proceso PID %d de Terminados",pidARemover);
      log_info(log_kernel,"Destruyendo segmentos del PID %d",pidARemover);
      t_datosEnviar * paquete = pedirPaquete((void*) &pidARemover,
          KERNEL_DESTRUIR_SEGMENTOS_PROGRAMA, sizeof(int));
      common_send(socketUMV, paquete, NULL );
      destruirPaquete(paquete);
      paquete = pedirPaquete("T", PROGRAMA_CERRAR, 2);
      common_send(nodoARemover->soquet_prog, paquete, NULL );
      destruirPaquete(paquete);
      free(nodoARemover);
    }
  return NULL ;

}
Esempio n. 3
0
void terminarCPUSinPCB() {
	t_datosEnviar* info1 = pedirPaquete("a", CPU_PCP_DISCONNECTION, 2);
	t_datosEnviar* info = pedirPaquete("a", UMV_CAE_CPU, 2);
	common_send(umvSocket, info, NULL );
	common_send(pcpSocket, info1, NULL );
	destruirPaquete(info1);
	destruirPaquete(info);
	close(umvSocket);
	close(pcpSocket);
	config_destroy(configuracion_CPU);
	exit(0);
}
Esempio n. 4
0
void terminaFinishedProcess(void* dataExtra, t_size extraSize) {
	t_datosEnviar* paquete = empaquetarPCB(CPU_PCP_FIN_PROCESO);
	log_debug(logger, "Process %d finished executing", currentPCB->pid);
	dictionary_iterator(diccionarioDeVariables, (void*) imprimirDiccionario);
	common_send(pcpSocket, paquete, NULL );
	destruirPaquete(paquete);
}
Esempio n. 5
0
int
pedirSegmento(int * error, int tamanio, int pid)
{
  int tam = tamanio;

  t_datosEnviar * paquete;
  void * pedidoSegmentoUMV = malloc(3 * sizeof(int));
  memcpy(pedidoSegmentoUMV, &pid, sizeof(int));
  memcpy(pedidoSegmentoUMV + sizeof(int), &tam, sizeof(int));

  paquete = pedirPaquete(pedidoSegmentoUMV, KERNEL_PEDIR_SEGMENTO_UMV, //Pedir Segmento
      2 * sizeof(int));
  common_send(socketUMV, paquete, NULL );

  free(paquete->data);

  paquete = common_receive(socketUMV, NULL );

  if (paquete->codigo_Operacion == ERROR_NO_CREO_SEGMENTO)
    {
      *error = 1;
    }
  memcpy(&tam, paquete->data, sizeof(int));
  destruirPaquete(paquete);
  free(pedidoSegmentoUMV);
  return tam; //Guardado la base
}
Esempio n. 6
0
void sendWaitAnswer(int cpuSocket, int codOp)
{
	char* mensajeComun = strdup("o");
	t_datosEnviar* mensaje = pedirPaquete(mensajeComun, codOp,
			string_length(mensajeComun) + 1);
	common_send(cpuSocket, mensaje, NULL );
	destruirPaquete(mensaje);
}
Esempio n. 7
0
void terminaExcepcion(void* dataExtra, t_size extraSize) {
	char* error_msg = (char*) dataExtra;
	t_datosEnviar* paquete = empaquetarPCB(CPU_PCP_EXCEPTION);
	log_info(logger, "Process finished with an exception: %s", error_msg);
	aniadirAlPaquete(paquete, error_msg, extraSize);
	common_send(pcpSocket, paquete, NULL );
	destruirPaquete(paquete);
}
ssize_t
_user_send(int socket, const void *data, size_t length, int flags)
{
	if (data == NULL || !IS_USER_ADDRESS(data))
		return B_BAD_ADDRESS;

	SyscallRestartWrapper<ssize_t> result;
	return result = common_send(socket, data, length, flags, false);
}
Esempio n. 9
0
void printText(t_nodo_proceso_ejecutando* procesoEjecutando,
		struct pollfd** socketsCPU, int* cantSocketsCpu, t_datosEnviar* paquete)
{
	debugTrackPCP(" Request to print text \" %s \"", paquete->data);
	log_info(log_kernel,
			"Request to print text  \" %s \", requested by the CPU with pid %d\n",
			paquete->data, procesoEjecutando->cpu.pid);
	t_datosEnviar* mensaje = pedirPaquete(paquete->data,
			PROGRAMA_PAQUETE_PARA_IMPRIMIR, paquete->data_size);
	common_send(procesoEjecutando->proceso.soquet_prog, mensaje, NULL );
	destruirPaquete(mensaje);
}
Esempio n. 10
0
void terminarCPU(void* dataExtra, t_size size) {
	if (proceso_activo) {
		t_datosEnviar* pcbAEnviar = empaquetarPCB(CPU_PCP_DISCONNECTION);
		common_send(pcpSocket, pcbAEnviar, NULL );
		destruirPaquete(pcbAEnviar);
	} else {
           t_datosEnviar* cerrar = pedirPaquete("a",CPU_PCP_DISCONNECTION,2);
           common_send(pcpSocket,cerrar,NULL);
           destruirPaquete(cerrar);
           }
           t_datosEnviar* info = pedirPaquete("a", UMV_CAE_CPU, 2);
           common_send(umvSocket, info, NULL );
           destruirPaquete(info);
           close(umvSocket);
	       close(pcpSocket);
	       clean_variable_dictionary();
	       free(currentPCB);
	       config_destroy(configuracion_CPU);
	       exit(0);
         
}
Esempio n. 11
0
void terminaFinQuantum(void* dataExtra, t_size extraSize) {
	t_datosEnviar* paquete = empaquetarPCB(CPU_PCP_FIN_QUANTUM);
	log_info(logger, "Process finished a quantum.");
	if (currentPCB->currentStack.contextSize > 0) {
	log_info(logger, "Current variable state on context:\n ");
	dictionary_iterator(diccionarioDeVariables,imprimirDiccionario);
	} else {
		log_debug(logger,"No variables in current context.");
	}
	common_send(pcpSocket, paquete, NULL );
	destruirPaquete(paquete);
}
Esempio n. 12
0
void sharedVariableRequest(t_nodo_proceso_ejecutando* procesoEjecutando,
		struct pollfd** socketsCPU, int* cantSocketsCpu, t_datosEnviar* paquete)
{

	t_varCompartida* varBuscada = dictionary_get(dictionarySharedVariables,
			(char*) paquete->data);
	t_datosEnviar* mensaje = pedirPaquete(&varBuscada->valor, PCP_CPU_OK,
			sizeof(uint32_t));
	debugTrackPCP(" Request of the shared variable: %s .", mensaje->data);
	common_send(procesoEjecutando->cpu.socket, mensaje, NULL );
	destruirPaquete(mensaje);
}
Esempio n. 13
0
void doHandshakeUMV() {
	t_datosEnviar* paquete = pedirPaquete("a", HANDSHAKE_UMV, 2);
	common_send(umvSocket, paquete, destroyOnConnectionFailure);
	destruirPaquete(paquete);
	paquete = common_receive(umvSocket, NULL );
	if (paquete->codigo_Operacion != UMV_CONTESTA_CPU_EXITO) {
		log_debug(logger, "Failure handshaking umv");
		destruirPaquete(paquete);
		destroyOnConnectionFailure();
	}
	log_debug(logger, "Successful handshake with UMV");
	destruirPaquete(paquete);
}
Esempio n. 14
0
void printVariable(t_nodo_proceso_ejecutando* procesoEjecutando,
		struct pollfd** socketsCPU, int* cantSocketsCpu, t_datosEnviar* paquete)
{
	debugTrackPCP(" Request to print variable: %d", *(int*)paquete->data);
	log_info(log_kernel,
			"Request to print variable \" %d \", requested by the CPU with pid %d\n",
			paquete->data, procesoEjecutando->cpu.pid);

	char* traduccion = string_itoa(*((int*) paquete->data));
	t_datosEnviar* mensaje = pedirPaquete(traduccion,
			PROGRAMA_PAQUETE_PARA_IMPRIMIR, string_length(traduccion) + 1);
	common_send(procesoEjecutando->proceso.soquet_prog, mensaje, NULL );
	destruirPaquete(mensaje);
	free(traduccion);
}
Esempio n. 15
0
void
startCommunicationWithUMV()
{
  t_datosEnviar *mensaje = pedirPaquete("OK", UMV_ACEPTA_KERNEL, 3);
  socketUMV = connect_to(configuration.ipUMV, configuration.puertoUMV);
  common_send(socketUMV, mensaje, NULL );
  mensaje = common_receive(socketUMV, NULL );
  if (mensaje->codigo_Operacion != UMV_ACEPTA_KERNEL)
    {
      shutdownKernel();
      log_error(log_kernel,
          "No se pudo conectar con la UMV, cerrando el Kernel");
    }
  log_info(log_kernel, "Se conecto exitosamente con la UMV");
}
Esempio n. 16
0
t_datos_kernel doHandshakeKernel() {
	int pidCPU = getpid();
	t_datosEnviar* paquete = pedirPaquete(&pidCPU, HANDSHAKE, sizeof(int));
	common_send(pcpSocket, paquete, destroyOnConnectionFailure);
	destruirPaquete(paquete);
	paquete = common_receive(pcpSocket, NULL );
	if (paquete->codigo_Operacion != PCP_CPU_OK) {
		log_debug(logger, "Failure handshaking kernel");
		destruirPaquete(paquete);
		destroyOnConnectionFailure();
	}
	log_debug(logger, "Successful handshake with Kernel");
	t_datos_kernel kernelData = getKernelData(paquete->data);
	destruirPaquete(paquete);
	return kernelData;

}
Esempio n. 17
0
void exceptionCPU(t_nodo_proceso_ejecutando* procesoEjecutando,
		struct pollfd** socketsCPU, int* cantSocketsCpu, t_datosEnviar* paquete)
{

	t_pcb* pcb = unserializePCB(paquete->data);
	char* textoError = malloc(paquete->data_size - sizeof(t_pcb));
	memcpy(textoError, paquete->data + sizeof(t_pcb),
			paquete->data_size - sizeof(t_pcb));

	debugTrackPCP(
			" Exception on the process with pid: %d, on the CPU  %d. Exception details: %s",
			pcb->pid, procesoEjecutando->cpu.pid, textoError);
	log_warning(log_kernel, "Exception on process. Exception details: %s",textoError);

	procesoEjecutando->proceso.pcb = *pcb;
	debugTrackPCP("Updating PCB.");
	t_datosEnviar* mensaje = pedirPaquete(textoError,
			PROGRAMA_PAQUETE_PARA_IMPRIMIR, string_length(textoError) + 1);
	common_send(procesoEjecutando->proceso.soquet_prog, mensaje, NULL );
	destruirPaquete(mensaje);
	pcp_exitProcess(procesoEjecutando);
	free(procesoEjecutando);
	free(textoError);
}
Esempio n. 18
0
//接收图片命令处理
static int trans_handler_v1(int sock_fd, struct protocal_common *common_data)
{
	print("trans image trans_handler_v1\n");
	struct prot_trans_head_v1 recv_head;
	unsigned char * recv_data = NULL;
	int recv_data_len = 0;
	int ret;

	struct protocal_common resp_common;
	
	if ((common_data == NULL) || (sock_fd < 0))
	{
		print("param error\n");
		goto _err;
	}

	if (ntohl(common_data->head_len) != sizeof(recv_head))
	{
		print("trans_handler_v1 head size error\n");
		goto _err;
	}

	ret = common_recv(sock_fd, (unsigned char *)&recv_head, sizeof(recv_head));
	if (ret != sizeof(recv_head))
	{
		print("recv_head error, should: %ld really: %d\n", sizeof(recv_head), ret);
		goto _err;
	}

	recv_data_len = ntohl(common_data->data_len);

	CURR_IMAGE_DATA_LOCK;
	if (curr_image_info.p_curr_image_buf != NULL)
	{
		//如果不为空,说明上一张图片传输未完成,返回错误
		print("new image come, but previos is not complate\n");
		//goto _err; //开始新的图片
		free(curr_image_info.p_curr_image_buf);
		curr_image_info.p_curr_image_buf = NULL;
	}

	if (curr_image_info.p_curr_image_buf == NULL)
	{
		recv_data = (unsigned char *)malloc(recv_data_len);
		if (recv_data == NULL)
		{
			print("malloc mem %d error\n", recv_data_len);
			goto _err;
		}
		memset(recv_data, 0, recv_data_len);
	}
		
	curr_image_info.p_curr_image_buf = recv_data;
	curr_image_info.curr_image_size = recv_data_len;
	curr_image_info.recv_size = 0;
	curr_image_info.pic_time = recv_head.time;

	curr_image_info.width = ntohl(recv_head.width);
	curr_image_info.height = ntohl(recv_head.height);
	curr_image_info.image_type = ntohl(recv_head.image_type);
	curr_image_info.image_formate = ntohl(recv_head.format);
	CURR_IMAGE_DATA_UNLOCK;

	//回应客户端
	resp_common.head_len = htonl(0);
	resp_common.data_len = htonl(0);
	resp_common.version = htonl(1);
	resp_common.command = htonl(PROT_RESPONSE_OK);
	common_send(sock_fd, (unsigned char *)&resp_common, sizeof(resp_common));

	
	return 0;

_err:
	if (recv_data != NULL)
		free(recv_data);
	
	//回应客户端
	resp_common.head_len = htonl(0);
	resp_common.data_len = htonl(0);
	resp_common.version = htonl(1);
	resp_common.command = htonl(PROT_RESPONSE_ERROR);
	common_send(sock_fd, (unsigned char *)&resp_common, sizeof(resp_common));
	
	return -1;
}
Esempio n. 19
0
//传输图片数据
static int trans_image_data_v2(int sock_fd, struct protocal_common *common_data)
{
	int head_len;
	int data_len;
	int ret;
	struct prot_trans_image_v1 pack_head;
	unsigned char * pack_data = NULL;
	int image_data_offset; //对整张图片的偏移
	int pack_index;
	struct protocal_common resp_common;
	struct image_t save_image;

	unsigned char * rgb888_buff = NULL;
	struct image_data_format image_format;

	if (common_data == NULL)
	{
		print("param error\n");
		return -1;
	}

	head_len = ntohl(common_data->head_len);
	data_len = ntohl(common_data->data_len);

	if (head_len != sizeof(pack_head))
	{
		print("head len is error\n");
		goto _err;
	}
	
	ret = common_recv(sock_fd, (unsigned char *)&pack_head, head_len);
	if (ret != head_len)
	{
		print("recv data error, should: %d really: %d\n", head_len, ret);
		goto _err;
	}

	if ((ntohl(pack_head.lask_pack) == 0) && (data_len != IMAGE_PAKE_SIZE))
	{
		print("this version of protocal is only support %d pack\n", IMAGE_PAKE_SIZE);
		goto _err;
	}

	if ((pack_head.pic_time.tv_sec != curr_image_info.pic_time.tv_sec) || (pack_head.pic_time.tv_usec != curr_image_info.pic_time.tv_usec))
	{
		print("pic time is not equal, this pack will ignore\n");
		goto _err;
	}

	pack_index = ntohl(pack_head.pack_index);
	if ((pack_index < 0) || (pack_index > curr_image_info.curr_image_size/IMAGE_PAKE_SIZE+(curr_image_info.curr_image_size%IMAGE_PAKE_SIZE == 0?0:1)))
	{
		print("index is error, pack_index: %d curr_image_info.curr_image_size:%d\n", pack_index, curr_image_info.curr_image_size);
		goto _err;
	}
	pack_data = (unsigned char *)malloc(data_len);
	if (pack_data == NULL)
	{
		print("malloc mem error\n");
		goto _err;
	}

	//读取数据
	ret = common_recv(sock_fd, pack_data, data_len);
	if (ret != data_len)
	{
		print("pack data may be %d  , but really: %d\n", data_len, ret);
		goto _err;
	}

	//将数据存储到分配的图片中
	image_data_offset = pack_index * IMAGE_PAKE_SIZE;
	CURR_IMAGE_DATA_LOCK;
	memcpy(curr_image_info.p_curr_image_buf+image_data_offset, pack_data, data_len);
	CURR_IMAGE_DATA_UNLOCK;

	//回应客户端
	//回应客户端
	resp_common.head_len = htonl(0);
	resp_common.data_len = htonl(0);
	resp_common.version = htonl(1);
	resp_common.command = htonl(PROT_RESPONSE_OK);
	common_send(sock_fd, (unsigned char *)&resp_common, sizeof(resp_common));

	//需要将图片放入内存池
	if (ntohl(pack_head.lask_pack) == 1)
	{
		rgb888_buff = malloc(curr_image_info.width * curr_image_info.height * 3);
		if (rgb888_buff == NULL)
		{
			goto _err;
		}
		image_format.format = IMAGE_FORMAT_YUYV;
		image_format.width = curr_image_info.width;
		image_format.height = curr_image_info.height;
		ret = yuyv_to_rgb888(&image_format, curr_image_info.p_curr_image_buf, 
			curr_image_info.curr_image_size, rgb888_buff, curr_image_info.width * curr_image_info.height * 3);
		if (ret < 0)
		{
			goto _err;
		}
		//1 保存图片到数据库
		save_image.width = curr_image_info.width;
		save_image.height = curr_image_info.height;
		save_image.format = IMAGE_FORMAT_RGB888_SIGNAL;
		save_image.data_len = 0;
		cgettimeofday(&save_image.time);

		pool_save(&save_image, rgb888_buff, curr_image_info.width * curr_image_info.height *3);
		printf("copy image to mem pool\n");
		
	}

	if (pack_data != NULL)
		free(pack_data);
	if (rgb888_buff != NULL)
		free(rgb888_buff);

	return 0;
_err:
	if (pack_data != NULL)
	{
		free(pack_data);
		pack_data = NULL;
	}
	//回应客户端
	resp_common.head_len = htonl(0);
	resp_common.data_len = htonl(0);
	resp_common.version = htonl(1);
	resp_common.command = htonl(PROT_RESPONSE_ERROR);
	common_send(sock_fd, (unsigned char *)&resp_common, sizeof(resp_common));
	
	return -1;

}
Esempio n. 20
0
void
atenderProgramaEntrante(t_datosEnviar* paquete, int socketCliente,
    int * PIDActual)
{
  if (paquete->codigo_Operacion == HANDSHAKE)
    {
      destruirPaquete(paquete);
      t_datosEnviar *paqueteEscribir;
      void *dataGenerica;
      paquete = pedirPaquete("K", PLP_PROGRAMA_CONFIRMAR_CONECCION, 2);
      common_send(socketCliente, paquete, NULL );
      destruirPaquete(paquete);
      paquete = common_receive(socketCliente, NULL );
      if (paquete->codigo_Operacion == ENVIAR_SCRIPT)
        {

          debugTrackPLP(
              "[Achievement] Programa autenticado, recibiendo script");
          char* programa = malloc(paquete->data_size);
          memcpy(programa, paquete->data, paquete->data_size);

          t_metadata_program * metadataDelPrograma;
          metadataDelPrograma = metadata_desde_literal((const char*) programa);
          int peso;
          peso = metadataDelPrograma->cantidad_de_funciones * 3
              + metadataDelPrograma->cantidad_de_etiquetas * 5
              + metadataDelPrograma->instrucciones_size;

          int error = 0;
          t_pcb * pcbNuevo = malloc(sizeof(t_pcb));

          pcbNuevo->pid = generarPid(PIDActual);

          int direccionStack, direccionCodigo, direccionIndiceEtiquetas,
              direccionIndiceCodigo;

          destruirPaquete(paquete);
          error = 0;

          debugTrackPLP("[Accion] Pidiendo segmentos en a la UMV");

          direccionCodigo = pedirSegmento(&error, strlen(programa) + 1,
              pcbNuevo->pid);
          direccionStack = pedirSegmento(&error, configuration.tamanio_pila,
              pcbNuevo->pid);
          direccionIndiceEtiquetas = pedirSegmento(&error,
              metadataDelPrograma->etiquetas_size, pcbNuevo->pid);
          direccionIndiceCodigo = pedirSegmento(&error,
              metadataDelPrograma->instrucciones_size * sizeof(t_intructions),
              pcbNuevo->pid);

          if (error == 1)
            {
              debugTrackPLP(
                  "[Error] No se pudo crear la totalidad de segmentos");
              paquete = pedirPaquete("A", PLP_PROGRAMA_NO_SE_PUDO_CREAR, 2);
              common_send(socketCliente, paquete, NULL );
              destruirPaquete(paquete);
              void * pidMomentaneo = malloc(sizeof(int));
              memcpy(pidMomentaneo, &(pcbNuevo->pid), sizeof(int));
              paquete = pedirPaquete(pidMomentaneo,
                  KERNEL_DESTRUIR_SEGMENTOS_PROGRAMA, sizeof(int));
              common_send(socketUMV, paquete, NULL );
              debugTrackPLP(
                  "[Accion] Eliminando el resto de los segmentos pedidos");
              PIDActual--;
              destruirPaquete(paquete);
              free(pidMomentaneo);
            }
          else
            {
              debugTrackPLP(
                  "[PID:%d]-[Achievement] Se pudo alocar todos los segmentos para el proceso ",
                  pcbNuevo->pid);
              pcbNuevo->codeIndex = direccionIndiceCodigo;
              pcbNuevo->codeSegment = direccionCodigo;
              pcbNuevo->indiceEtiquetas = direccionIndiceEtiquetas;
              pcbNuevo->programCounter =
                  metadataDelPrograma->instruccion_inicio;
              pcbNuevo->tamanioIndiceEtiquetas =
                  metadataDelPrograma->etiquetas_size;
              pcbNuevo->currentStack.base = direccionStack;
              pcbNuevo->currentStack.contextSize = 0;
              pcbNuevo->currentStack.size = configuration.tamanio_pila;
              pcbNuevo->currentStack.stack_pointer = direccionStack;

              if (pcbNuevo->codeSegment != -1)
                {
                  debugTrackPLP(
                      "[PID:%d]-[Achievement] Alocado segmento de codigo en la direccion virtual %d",
                      pcbNuevo->pid, pcbNuevo->codeSegment);

                  dataGenerica = malloc(
                      3 * sizeof(uint32_t) + strlen(programa) + 1);
                  int tamanioData = strlen(programa) + 1;

                  memcpy(dataGenerica, &(pcbNuevo->pid), sizeof(uint32_t));
                  memcpy(dataGenerica + sizeof(uint32_t), &tamanioData,
                      sizeof(uint32_t));
                  memcpy(dataGenerica + 2 * sizeof(uint32_t),
                      &(pcbNuevo->codeSegment), sizeof(uint32_t));
                  memcpy(dataGenerica + 3 * sizeof(uint32_t), programa,
                      tamanioData);

                  paqueteEscribir = pedirPaquete(dataGenerica,
                      KERNEL_ESCRIBIR_SEGMENTO_UMV,
                      3 * sizeof(uint32_t) + strlen(programa) + 1);
                  common_send(socketUMV, paqueteEscribir, NULL );
                  destruirPaquete(paqueteEscribir);
                  paqueteEscribir = common_receive(socketUMV, NULL );
                  free(dataGenerica);
                  destruirPaquete(paqueteEscribir);

                }
              if (pcbNuevo->codeIndex != -1)
                {
                  debugTrackPLP(
                      "[PID:%d]-[Achievement] Alocado segmento de indice de codigo en la direccion virtual %d",
                      pcbNuevo->pid, pcbNuevo->codeIndex);
                  int tamanioData = metadataDelPrograma->instrucciones_size
                      * sizeof(t_intructions);
                  paqueteEscribir = pedirPaquete(&(pcbNuevo->pid),
                      KERNEL_ESCRIBIR_SEGMENTO_UMV, sizeof(int));
                  aniadirAlPaquete(paqueteEscribir, &(tamanioData),
                      sizeof(int));
                  aniadirAlPaquete(paqueteEscribir, &(pcbNuevo->codeIndex),
                      sizeof(int));
                  aniadirAlPaquete(paqueteEscribir,
                      metadataDelPrograma->instrucciones_serializado,
                      tamanioData);
                  common_send(socketUMV, paqueteEscribir, NULL );
                  destruirPaquete(paqueteEscribir);
                  paqueteEscribir = common_receive(socketUMV, NULL );
                  destruirPaquete(paqueteEscribir);

                }
              if (pcbNuevo->indiceEtiquetas != -1)
                {

                  debugTrackPLP(
                      "[PID:%d]-[Achievement] Alocado segmento de indice de etiquetas en la direccion virtual %d",
                      pcbNuevo->pid, pcbNuevo->indiceEtiquetas);

                  int tamanioData = metadataDelPrograma->etiquetas_size;
                  dataGenerica = malloc(
                      (tamanioData + 1) * sizeof(char) + 3 * sizeof(int));
                  memcpy(dataGenerica, &(pcbNuevo->pid), sizeof(int));
                  memcpy(dataGenerica + sizeof(int), &tamanioData, sizeof(int));
                  memcpy(dataGenerica + 2 * sizeof(int),
                      &(pcbNuevo->indiceEtiquetas), sizeof(int));
                  memcpy(dataGenerica + 3 * sizeof(int),
                      metadataDelPrograma->etiquetas, tamanioData);
                  paqueteEscribir = pedirPaquete(dataGenerica,
                      KERNEL_ESCRIBIR_SEGMENTO_UMV, (tamanioData + 1) * sizeof(char) + 3 * sizeof(int));
                  common_send(socketUMV, paqueteEscribir, NULL );
                  destruirPaquete(paqueteEscribir);
                  paqueteEscribir = common_receive(socketUMV, NULL );
                  destruirPaquete(paqueteEscribir);
                  free(dataGenerica);

                }

              debugTrackPLP("[PID:%d]-[Achievement] PCB listo para encolarse",
                  pcbNuevo->pid);

              paquete = pedirPaquete("A", PLP_PROGRAMA_ENCOLADO, 2);
              common_send(socketCliente, paquete, NULL );
              free(programa);
              encolarPCB(pcbNuevo, peso, socketCliente);

            }
        }

      else
        {
          destruirPaquete(paquete);
          pedirPaquete("NK", PROGRAMA_CERRAR, 3);
          puts("No Validado");
          common_send(socketCliente, paquete, NULL );
          destruirPaquete(paquete);
        }
    }

}
Esempio n. 21
0
void terminaBlockedIO(void* dataExtra, t_size extraSize) {
	t_datosEnviar* paquete = empaquetarPCB(CPU_PCP_ENTRADA_SALIDA);
	aniadirAlPaquete(paquete, dataExtra, extraSize);
	common_send(pcpSocket, paquete, NULL );
	destruirPaquete(paquete);
}
Esempio n. 22
0
int main(int argc, char **argv) {

	remove("/tp-2015-2c-signiorcodigo/swap/log_swap");

	swapConfig = config_create("/tp-2015-2c-signiorcodigo/swap/swapConfig");

	setupSwap();

	setPages();

	int socketEscucha, socketMemoria;

	char * puerto = getPort();

	socketEscucha = setup_listen("localhost", puerto);

	socketMemoria = esperarConexionEntrante(socketEscucha, 1024, log_swap);

	t_data * paqueteInicio = leer_paquete(socketMemoria);

	if (paqueteInicio->header->codigo_operacion == 1) {

		int datonulo = 0;

		paqueteInicio = pedirPaquete(2, sizeof(int), &datonulo);

		common_send(socketMemoria, paqueteInicio);

		log_info(log_swap, "Conectado con la memoria en el socket: %d",
				socketMemoria);

	} else {

		log_info(log_swap, "Falla en la conexion con la memoria");

		exit(EXIT_FAILURE);
	}

	t_data * paquete;

	while (1) {

		paquete = leer_paquete(socketMemoria);

		switch (paquete->header->codigo_operacion) {

		case LEER: {

			int pid, page;

			memcpy(&pid, paquete->data, sizeof(int));
			memcpy(&page, paquete->data + sizeof(int), sizeof(int));

			char * content = readProcessPage(pid, page);

			paquete = pedirPaquete(LEER, getSwapPagesSize(), content);

			common_send(socketMemoria, paquete);

			break;
		}

		case ESCRIBIR: {

			int pid, page;
			char * content = malloc(getSwapPagesSize());

			memcpy(&pid, paquete->data, sizeof(int));
			memcpy(&page, paquete->data + sizeof(int), sizeof(int));
			memcpy(content, paquete->data + 2 * sizeof(int),
					getSwapPagesSize());

			writeProcessPage(pid, page, content);

			break;
		}

		case INICIAR: {

			int pid, pagesAmount;

			memcpy(&pid, paquete->data, sizeof(int));
			memcpy(&pagesAmount, paquete->data + sizeof(int), sizeof(int));

			int blank_pages = getBlankPages();
			int success;

			if (blank_pages >= pagesAmount) {
				success = reserve(pid, pagesAmount);

				if (success == -1) {
					compact();
					success = reserve(pid, pagesAmount);
				}
			}else{
				success = -1;
			}


			if (success == -1) {

				paquete = pedirPaquete(0, sizeof(int), &pid);
				log_info(log_swap,
						"No se pudo reservar las paginas solicitadas para el proceso con pid: %d",
						pid);

			} else {

				paquete = pedirPaquete(1, sizeof(int), &pid);
				int absolutePage = getProcessFirstPage(pid);

				int byteInicial = absolutePage * getSwapPagesSize();

				int size = pagesAmount * getSwapPagesSize();

				log_info(log_swap,
						"Se inicia el proceso %d en el byte %d con tamanio %d",
						pid, byteInicial, size);

			}

			common_send(socketMemoria, paquete);

			break;
		}

		case FINALIZAR: {

			int pid;

			memcpy(&pid, paquete->data, sizeof(int));

			int processSpace = getProcessReservedSpace(pid)
					* getSwapPagesSize();

			int byteInicial = getProcessFirstPage(pid) * getSwapPagesSize();

			freeSpace(pid);

			log_info(log_swap,
					"Proceso %d liberado. N° de byte inicial: %d, y tamaño en bytes: %d",
					pid, byteInicial, processSpace);

			break;
		}

		default: {

			break;
		}

		}

	}

	return 0;
}
Esempio n. 23
0
void terminaBlockedSemaphore(void* dataExtra, t_size extraSize) {
	t_datosEnviar* paquete = empaquetarPCB(CPU_PCP_PROCESS_WAITING);
	common_send(pcpSocket, paquete, NULL );
	destruirPaquete(paquete);
}
Esempio n. 24
0
ssize_t
send(int socket, const void *data, size_t length, int flags)
{
	SyscallFlagUnsetter _;
	RETURN_AND_SET_ERRNO(common_send(socket, data, length, flags, true));
}