Ejemplo n.º 1
0
/*
 * Read the platform configuration file from the EPROM.
 *
 * On success, an allocated buffer containing the data and its size are
 * returned.  It is up to the caller to free this buffer.
 *
 * Return value:
 *   0	      - success
 *   -ENXIO   - no EPROM is available
 *   -EBUSY   - not able to acquire access to the EPROM
 *   -ENOENT  - no recognizable file written
 *   -ENOMEM  - buffer could not be allocated
 *   -EINVAL  - invalid EPROM contentents found
 */
int eprom_read_platform_config(struct hfi1_devdata *dd, void **data, u32 *size)
{
	u32 directory[EP_PAGE_DWORDS]; /* aligned buffer */
	int ret;

	if (!dd->eprom_available)
		return -ENXIO;

	ret = acquire_chip_resource(dd, CR_EPROM, EPROM_TIMEOUT);
	if (ret)
		return -EBUSY;

	/* read the last page of the segment for the EPROM format magic */
	ret = read_length(dd, SEG_SIZE - EP_PAGE_SIZE, EP_PAGE_SIZE, directory);
	if (ret)
		goto done;

	/* last dword of the segment contains a magic value */
	if (directory[EP_PAGE_DWORDS - 1] == FOOTER_MAGIC) {
		/* segment format */
		ret = read_segment_platform_config(dd, directory, data, size);
	} else {
		/* partition format */
		ret = read_partition_platform_config(dd, data, size);
	}

done:
	release_chip_resource(dd, CR_EPROM);
	return ret;
}
Ejemplo n.º 2
0
/*
 * Read the platform configuration file from the EPROM.
 *
 * On success, an allocated buffer containing the data and its size are
 * returned.  It is up to the caller to free this buffer.
 *
 * Return value:
 *   0	      - success
 *   -ENXIO   - no EPROM is available
 *   -EBUSY   - not able to acquire access to the EPROM
 *   -ENOENT  - no recognizable file written
 *   -ENOMEM  - buffer could not be allocated
 */
int eprom_read_platform_config(struct hfi1_devdata *dd, void **data, u32 *size)
{
	u32 directory[EP_PAGE_DWORDS]; /* aligned buffer */
	int ret;

	if (!dd->eprom_available)
		return -ENXIO;

	ret = acquire_chip_resource(dd, CR_EPROM, EPROM_TIMEOUT);
	if (ret)
		return -EBUSY;

	/* read the last page of P0 for the EPROM format magic */
	ret = read_length(dd, P1_START - EP_PAGE_SIZE, EP_PAGE_SIZE, directory);
	if (ret)
		goto done;

	/* last dword of P0 contains a magic indicator */
	if (directory[EP_PAGE_DWORDS - 1] == 0) {
		/* partition format */
		ret = read_partition_platform_config(dd, data, size);
		goto done;
	}

	/* nothing recognized */
	ret = -ENOENT;

done:
	release_chip_resource(dd, CR_EPROM);
	return ret;
}
Ejemplo n.º 3
0
static readstat_error_t discard_vector(rdata_sexptype_header_t sexptype_header, size_t element_size, rdata_ctx_t *ctx) {
    int32_t length;
    readstat_error_t retval = READSTAT_OK;
    
    if ((retval = read_length(&length, ctx)) != READSTAT_OK)
        goto cleanup;
    
    if (length > 0) {
        if (lseek_st(ctx, length * element_size) == -1) {
            return READSTAT_ERROR_READ;
        }
    } else if (ctx->error_handler) {
        char error_buf[1024];
        snprintf(error_buf, sizeof(error_buf), "Vector with non-positive length: %d\n", length);
        ctx->error_handler(error_buf, ctx->user_ctx);
    }
    
    if (sexptype_header.attributes) {
        rdata_sexptype_info_t temp_info;
        if ((retval = read_sexptype_header(&temp_info, ctx)) != READSTAT_OK)
            goto cleanup;
        
        retval = recursive_discard(temp_info.header, ctx);
    }
    
cleanup:
    
    return retval;
}
Ejemplo n.º 4
0
/*
 * Read all of partition 1.  The actual file is at the front.  Adjust
 * the returned size if a trailing image magic is found.
 */
static int read_partition_platform_config(struct hfi1_devdata *dd, void **data,
					  u32 *size)
{
	void *buffer;
	void *p;
	u32 length;
	int ret;

	buffer = kmalloc(P1_SIZE, GFP_KERNEL);
	if (!buffer)
		return -ENOMEM;

	ret = read_length(dd, P1_START, P1_SIZE, buffer);
	if (ret) {
		kfree(buffer);
		return ret;
	}

	/* scan for image magic that may trail the actual data */
	p = strnstr(buffer, IMAGE_TRAIL_MAGIC, P1_SIZE);
	if (p)
		length = p - buffer;
	else
		length = P1_SIZE;

	*data = buffer;
	*size = length;
	return 0;
}
Ejemplo n.º 5
0
/* return length of recieved packet on success.
 * return 0 if could not read any packet.
 * return -1 on failure (connection must be killed).
 */
static int read_packet_TCP_secure_connection(TCP_Secure_Connection *con, uint8_t *data, uint16_t max_len)
{
    if (con->next_packet_length == 0) {
        uint16_t len = read_length(con->sock);

        if (len == (uint16_t)~0)
            return -1;

        if (len == 0)
            return 0;

        con->next_packet_length = len;
    }

    if (max_len + crypto_box_MACBYTES < con->next_packet_length)
        return -1;

    uint8_t data_encrypted[con->next_packet_length];
    int len_packet = read_TCP_packet(con->sock, data_encrypted, con->next_packet_length);

    if (len_packet != con->next_packet_length)
        return 0;

    con->next_packet_length = 0;

    int len = decrypt_data_fast(con->shared_key, con->recv_nonce, data_encrypted, len_packet, data);

    if (len + crypto_box_MACBYTES != len_packet)
        return -1;

    increment_nonce(con->recv_nonce);

    return len;
}
Ejemplo n.º 6
0
/* Use a standard message across the unix sockets:
 * 4 byte length of message as little endian encoded uint32_t followed by the
 * string. Return NULL in case of failure. */
char *_recv_unix_msg(int sockd, int timeout1, int timeout2, const char *file, const char *func, const int line)
{
	char *buf = NULL;
	uint32_t msglen;
	int ret, ern;

	ret = wait_read_select(sockd, timeout1);
	if (unlikely(ret < 1)) {
		ern = errno;
		LOGERR("Select1 failed in recv_unix_msg (%d)", ern);
		goto out;
	}
	/* Get message length */
	ret = read_length(sockd, &msglen, 4);
	if (unlikely(ret < 4)) {
		ern = errno;
		LOGERR("Failed to read 4 byte length in recv_unix_msg (%d?)", ern);
		goto out;
	}
	msglen = le32toh(msglen);
	if (unlikely(msglen < 1 || msglen > 0x80000000)) {
		LOGWARNING("Invalid message length %u sent to recv_unix_msg", msglen);
		goto out;
	}
	ret = wait_read_select(sockd, timeout2);
	if (unlikely(ret < 1)) {
		ern = errno;
		LOGERR("Select2 failed in recv_unix_msg (%d)", ern);
		goto out;
	}
	buf = ckzalloc(msglen + 1);
	ret = read_length(sockd, buf, msglen);
	if (unlikely(ret < (int)msglen)) {
		ern = errno;
		LOGERR("Failed to read %u bytes in recv_unix_msg (%d?)", msglen, ern);
		dealloc(buf);
	}
out:
	shutdown(sockd, SHUT_RD);
	if (unlikely(!buf))
		LOGERR("Failure in recv_unix_msg from %s %s:%d", file, func, line);
	return buf;
}
Ejemplo n.º 7
0
/*
 * read a sequence of bytes and add them to tree
 */
static void
read_bytes(unsigned int *offset, tvbuff_t *tvb, proto_tree *etch_tree)
{
  int length;
  read_type(offset, tvb, etch_tree);
  length = read_length(offset, tvb, etch_tree);
  proto_tree_add_item(etch_tree, hf_etch_bytes, tvb, *offset, length,
                      ENC_NA);
  (*offset) += length;
}
Ejemplo n.º 8
0
static readstat_error_t read_generic_list(int attributes, rdata_ctx_t *ctx) {
    readstat_error_t retval = READSTAT_OK;
    int32_t length;
    int i;
    rdata_sexptype_info_t sexptype_info;
    
    
    if ((retval = read_length(&length, ctx)) != READSTAT_OK)
        goto cleanup;
    
    for (i=0; i<length; i++) {        
        if ((retval = read_sexptype_header(&sexptype_info, ctx)) != READSTAT_OK)
            goto cleanup;
        
        if (sexptype_info.header.type == RDATA_SEXPTYPE_CHARACTER_VECTOR) {
            int32_t vec_length;
            
            if ((retval = read_length(&vec_length, ctx)) != READSTAT_OK)
                goto cleanup;
            if (ctx->column_handler) {
                if (ctx->column_handler(NULL, READSTAT_TYPE_STRING, NULL, NULL, vec_length, ctx->user_ctx)) {
                    retval = READSTAT_ERROR_USER_ABORT;
                    goto cleanup;
                }
            }
            retval = read_string_vector(vec_length, ctx->text_value_handler, ctx->user_ctx, ctx);
        } else {
            retval = read_value_vector(sexptype_info.header, NULL, ctx);
        }
        if (retval != READSTAT_OK)
            goto cleanup;
    }
    
    if (attributes) {
        if ((retval = read_attributes(&handle_data_frame_attribute, ctx)) != READSTAT_OK)
            goto cleanup;
    }
    
cleanup:
    
    return retval;
}
Ejemplo n.º 9
0
//! @brief Read from peripheral until entire data framing packet read.
static status_t read_data_packet(framing_data_packet_t * packet, uint8_t * data, packet_type_t packetType)
{
    // Read the packet header.
    status_t status = read_header(&packet->header);
    if (status != kStatus_Success)
    {
        return status;
    }

    if (packet->header.packetType == kFramingPacketType_Ping)
    {
        return serial_send_ping_response(g_bootloaderContext.activePeripheral);
    }

    uint8_t expectedPacketType = kFramingPacketType_Command;

    if (packetType != kPacketType_Command)
    {
        expectedPacketType = kFramingPacketType_Data;
    }
    if (packet->header.packetType != expectedPacketType)
    {
        debug_printf("Error: read_data_packet found unexpected packet type 0x%x\r\n", packet->header.packetType);
        return kStatus_Fail;
    }

    // Read the packet length.
    status = read_length(packet);
    if (status != kStatus_Success)
    {
        return status;
    }

    // Make sure the packet doesn't exceed the allocated buffer size.
    packet->length = MIN(kIncomingPacketBufferSize, packet->length);

    // Read the crc
    status = read_crc16(packet);
    if (status != kStatus_Success)
    {
        return status;
    }

    // Read the data.
    if (packet->length > 0)
    {
        // Clear the data area so unsent parameters default to zero.
        memset(data, 0, packet->length);

        status = read_data(data, packet->length, kDefaultByteReadTimeoutMs * packet->length);
    }

    return status;
}
Ejemplo n.º 10
0
/*
 * read a string and add it to tree
 */
static void
read_string(unsigned int *offset, tvbuff_t *tvb, proto_tree *etch_tree)
{
  int byteLength;
  read_type(offset, tvb, etch_tree);

  byteLength = read_length(offset, tvb, etch_tree);

  proto_tree_add_item(etch_tree, hf_etch_string, tvb, *offset,
                      byteLength, ENC_ASCII|ENC_NA);
  (*offset) += byteLength;
}
Ejemplo n.º 11
0
static readstat_error_t read_string_vector(int32_t length, rdata_text_value_handler text_value_handler, 
        void *callback_ctx, rdata_ctx_t *ctx) {
    int32_t string_length;
    readstat_error_t retval = READSTAT_OK;
    rdata_sexptype_info_t info;
    size_t buffer_size = 4096;
    char *buffer = NULL;
    int i;

    buffer = malloc(buffer_size);
    
    for (i=0; i<length; i++) {
        if ((retval = read_sexptype_header(&info, ctx)) != READSTAT_OK)
            goto cleanup;
        
        if (info.header.type != RDATA_SEXPTYPE_CHARACTER_STRING) {
            retval = READSTAT_ERROR_PARSE;
            goto cleanup;
        }

        if ((retval = read_length(&string_length, ctx)) != READSTAT_OK)
            goto cleanup;
        
        if (string_length + 1 > buffer_size) {
            buffer = realloc(buffer, string_length + 1);
            if (buffer == NULL) {
                retval = READSTAT_ERROR_MALLOC;
                goto cleanup;
            }
        }
        
        if (read_st(ctx, buffer, string_length) != string_length) {
            retval = READSTAT_ERROR_READ;
            goto cleanup;
        }
        
        buffer[string_length] = '\0';
        
        if (text_value_handler) {
            if (text_value_handler(buffer, i, callback_ctx)) {
                retval = READSTAT_ERROR_USER_ABORT;
                goto cleanup;
            }
        }
    }
cleanup:
    
    if (buffer)
        free(buffer);

    return retval;
}
void TraCIClient::do_send_command( const CommandId command,
                                   const TraciMessage &out,
                                   TraciMessage &in ) const
{
    // Preconditions
    if ( ! socket_.get() )
    {
        std::cerr << "TraCIClient::do_send_command: no socket" << std::endl;
        abort();
    }

    // Send command
    try
    {
        socket_->sendExact( out );
        socket_->receiveExact( in );
    }
    catch ( SocketException &e )
    {
        std::cerr << "Error in TraCIClient::do_send_command: " << e.what() << std::endl;
        abort();
    }

    // check response
    unsigned int command_start = in.position();
    unsigned int command_length = read_length( in );

    // check received command ID
    UbyteType rcvdCommandId(in);
    if ( command != rcvdCommandId )
    {
        std::cerr << sc_->world().scheduler().current_time();
        std::cerr << ": Error in method TraCIClient::do_send_command, Server answered to command: ";
        std::cerr << std::hex << "0x" << static_cast<unsigned int>(rcvdCommandId);
        std::cerr << ". Expected command: 0x" << static_cast<unsigned int>(command) << std::dec << std::endl;
        abort();
    }

    // check response status
    const StatusResponseType response(in);
    if ( !response.isSuccess() )
    {
        std::cerr << sc_->world().scheduler().current_time()
             << ": Error in method TraCIClient::do_send_command, Server returned error "
             << "[0x" << std::hex << std::setfill('0') << std::setw(2) << static_cast<unsigned int>(response.result) << "]: "
             << response.description << std::dec << std::setfill(' ') << std::endl;
        abort();
    }

    // Right length?
    check_position( in, command_start + command_length, "TraCIClient::do_send_command" );
}
Ejemplo n.º 13
0
static int handle_vector_attribute(char *key, rdata_sexptype_info_t val_info, rdata_ctx_t *ctx) {
    readstat_error_t retval = READSTAT_OK;
    if (strcmp(key, "levels") == 0) {
        int32_t length;
        
        if ((retval = read_length(&length, ctx)) != READSTAT_OK)
            return retval;
        
        retval = read_string_vector(length, ctx->value_label_handler, ctx->user_ctx, ctx);
    } else if (strcmp(key, "class") == 0) {
        int32_t length;
        
        if ((retval = read_length(&length, ctx)) != READSTAT_OK)
            return retval;

        ctx->class_is_posixct = 0;
        retval = read_string_vector(length, &handle_class_name, &ctx->class_is_posixct, ctx);
    } else {
        retval = recursive_discard(val_info.header, ctx);
    }
    return retval;
}
Ejemplo n.º 14
0
file *rl_decode(const char *data, long size) {
    int i;
    byte_buffer *buff = new_buffer(size);
    memcpy(buff->buffer, data, size);

    // 1. Get size of each run.
    uchar bytes[2];
    for (i = 0; i < 2; ++i) {
        bytes[i] = get_next_byte(buff);
    }
    const ushort NUM_BITS = *((ushort *)bytes);

    // 2. Decode data
    int zeros = 1;
    int remaining = 8 * size;
    int max_len = (4 * size)/3;

    byte_buffer *output = new_buffer(max_len);
    i = 0;

    while (remaining > NUM_BITS) {
        int bits = read_length(buff, NUM_BITS);
        for (i = 0; i < bits; ++i) {
            if (zeros) {
                append_bit_to_buffer(output, 0);
            } else {
                append_bit_to_buffer(output, 1);
            }
        }
        zeros = (zeros == 0)? 1 : 0;
        remaining -= NUM_BITS;
    }

    // 3. Convert output buffer to file
    file *f = (file *)malloc(sizeof(file));
    f->size = (long)output->current_byte;
    f->data = (char *)malloc(f->size);
    memcpy(f->data, output->buffer, f->size);

    // 4. Free resources
    free_buffer(output);
    free_buffer(buff);

    return f;
}
Ejemplo n.º 15
0
static int handle_data_frame_attribute(char *key, rdata_sexptype_info_t val_info, rdata_ctx_t *ctx) {
    readstat_error_t retval = READSTAT_OK;
    
    if (strcmp(key, "names") == 0 && val_info.header.type == RDATA_SEXPTYPE_CHARACTER_VECTOR) {
        int32_t length;
        
        if ((retval = read_length(&length, ctx)) != READSTAT_OK)
            return retval;
        
        retval = read_string_vector(length, ctx->column_name_handler, ctx->user_ctx, ctx);
    } else if (strcmp(key, "label.table") == 0) {
        retval = recursive_discard(val_info.header, ctx);
    } else {
        retval = recursive_discard(val_info.header, ctx);
    }
    
    return retval;
}
//---------------------------------------------------------------------
void TraCIClient::send_command( CommandId command,
                                const traci::TraciType & content,
                                traci::TraciType & answer ) const
throw( tcpip::SocketException )
{
    Storage in;
    send_command(command, content, in);

    if ( !in.valid_pos() )
        throw std::runtime_error( "traci::TraCIClient::send_command: missing response command" );

    const unsigned int commandStart = in.position();
    const unsigned int commandLength = read_length(in);

    answer.read(in);

    check_position( in, commandStart + commandLength, "TraCIClient::command_get_value" );
}
	inline void QTrimImpl ( FORMAT<TUPLETYPE>& fq )
	{
		std::vector< float > sum_qscores;
		MapQualityToSumScore ( std::get<3>(fq.data), sum_qscores );
		size_t read_length ( std::get<1>(fq.data).size() );
		size_t cut_pos(0);
		while ( read_length > quality_score_trait_.min_read_length_ )
		{
			if ( sum_qscores[read_length-1] < quality_score_trait_.q_table_[read_length-1] )			
			{
				++cut_pos;
				--read_length;
			}
			else
				break;
		}
		std::get<1>(fq.data).resize ( std::get<1>(fq.data).size() - cut_pos );  
		std::get<3>(fq.data).resize ( std::get<3>(fq.data).size() - cut_pos );  
	}
Ejemplo n.º 18
0
            static codepoint_type decode(Iter c) {
                size_t len = read_length(static_cast<codeunit_type>(*c));

                codepoint_type res = 0;
                // switch on first byte
                switch (len) {
                    case 1: res = *c; break;
                    case 2: res = *c & 0x1f; break;
                    case 3: res = *c & 0x0f; break;
                    case 4: res = *c & 0x07; break;
                    default:
                        assert(false && "bad utf8 codeunit");
                };

                // then loop to catch remaining?
                for (size_t i = 1; i < len; ++i) {
                    res = (res << 6) | (c[i] & 0x3f);
                }
                return res;
            }
Ejemplo n.º 19
0
int main(int argc, char **argv) {
  unsigned int status = 0;
  int length = 0;

  if ((status=usage(argc, argv, 2, 1)) == FILE_OPEN_SUCCESS) { // if correct arguments, i.e, having a input file

  FILE *fp = fopen(argv[1], "r");

  if ((status=parse_header(fp)) == PARSE_HEADER_SUCCESS) { 
      length = read_length(fp);
      printf("length: %d\n", length);
      char * msg;
      msg = read_hidden_msg(fp, length);
      printf("%s\n", msg);      // ouput hidden messaage
  } 

  fclose(fp);
  }

  return EXIT_SUCCESS;
}
Ejemplo n.º 20
0
/*
 * read an array from tvb and add it to tree
 */
static void
read_array(unsigned int *offset, tvbuff_t *tvb, proto_tree *etch_tree)
{
  int length;

  /*  array type */
  read_type(offset, tvb, etch_tree);

  /*  Array of type: */
  read_array_type(offset, tvb, etch_tree);

  /*  Array dim */
  proto_tree_add_item(etch_tree, hf_etch_dim, tvb, *offset, 1, ENC_BIG_ENDIAN);
  (*offset)++;

  /*  Array length */
  length = read_length(offset, tvb, etch_tree);

  for (; length > 0; length--) {
    read_value(offset, tvb, etch_tree, hf_etch_value);
  }
  /*  terminaton */
  read_type(offset, tvb, etch_tree);
}
Ejemplo n.º 21
0
void main(void) {
    unsigned char cal_length, cal_dia;
    unsigned int length, dia, dia_offset, latest_l, latest_d;
    unsigned int tot_acc, mass_acc, timb_acc;
    unsigned int tot_num, mass_num, timb_num;
    unsigned int count1, count2, count3;
    OSCCON = 255;
    OSCTUNEbits.PLLEN = 1;

    TRISA = 0b00011111;
    PORTA = 0;
    ADCON1 = 0b00001101;
    TRISB = 0;
    PORTB = 0;
    TRISC = 0b00010000;
    PORTC = 0b00000000;
    TRISD = 0;
    PORTD = 0;
    TRISE = 0;
    PORTE = 0;

    init_display();
    init_counters();

    LED1 = 0;
    LED2 = 0;
    LED3 = 0;

    latest_l = 0;
    latest_d = 0;
    tot_acc = 0;
    tot_num = 0;
    timb_acc = 0;
    timb_num = 0;
    mass_acc = 0;
    mass_num = 0;

    cal_length = read_ad(0);
    cal_dia = read_ad(1);

    dia_offset = 2;
    
    while (1) {
        length = read_length(cal_length);
        dia = dia_offset + read_diameter(cal_dia);

        write_length(length);
        write_dia(dia);

        if (!CALIBRATE) {
            count1 = read_counter(1);
            count2 = read_counter(2);
            count3 = read_counter(3);
            cal_length = read_ad(0);
            cal_dia = read_ad(1);
            write_debug_info(cal_length, cal_dia, count1, count2, count3);
        }

        if (!RESET_DIA) {
            reset_dia();
        }
        
        if (!RESET_LENGTH) {
            delay(20000);
            delay(20000);
            if (!RESET_LENGTH) {
                LED1 = 1;
                if (length >= 100) {
                    tot_num = tot_num + 1;
                    tot_acc = tot_acc + length / 100;
                    latest_l = length;
                    latest_d = dia;
                    if (dia >= 15) {
                        timb_num = timb_num + 1;
                        timb_acc = timb_acc + length / 100;
                    } else {
                        mass_num = mass_num + 1;
                        mass_acc = mass_acc + length / 100;
                    }
                }
                reset_length();
                while (!RESET_LENGTH) {
                    write_length(0);
                    write_dia(0);
                    write_length(8);
                    write_dia(8);
                }
                write_stats(latest_l, latest_d, tot_num, tot_acc, timb_num, timb_acc, mass_num, mass_acc);
                LED1 = 0;
            }
        }
    }
}
Ejemplo n.º 22
0
std::string request_get_dot_output(smx_simcall_t req, int value)
{
  std::string label;

  const smx_actor_t issuer = MC_smx_simcall_get_issuer(req);

  switch (req->call) {
  case SIMCALL_COMM_ISEND:
    if (issuer->host)
      label = simgrid::xbt::string_printf("[(%lu)%s] iSend", issuer->pid,
                  MC_smx_process_get_host_name(issuer));
    else
      label = bprintf("[(%lu)] iSend", issuer->pid);
    break;

  case SIMCALL_COMM_IRECV:
    if (issuer->host)
      label = simgrid::xbt::string_printf("[(%lu)%s] iRecv", issuer->pid,
                  MC_smx_process_get_host_name(issuer));
    else
      label = simgrid::xbt::string_printf("[(%lu)] iRecv", issuer->pid);
    break;

  case SIMCALL_COMM_WAIT: {
    if (value == -1) {
      if (issuer->host)
        label = simgrid::xbt::string_printf("[(%lu)%s] WaitTimeout", issuer->pid,
                    MC_smx_process_get_host_name(issuer));
      else
        label = simgrid::xbt::string_printf("[(%lu)] WaitTimeout", issuer->pid);
    } else {
      smx_activity_t remote_act = simcall_comm_wait__get__comm(req);
      simgrid::mc::Remote<simgrid::kernel::activity::Comm> temp_comm;
      mc_model_checker->process().read(temp_comm, remote(
        static_cast<simgrid::kernel::activity::Comm*>(remote_act)));
      simgrid::kernel::activity::Comm* comm = temp_comm.getBuffer();

      smx_actor_t src_proc = mc_model_checker->process().resolveProcess(
        simgrid::mc::remote(comm->src_proc));
      smx_actor_t dst_proc = mc_model_checker->process().resolveProcess(
        simgrid::mc::remote(comm->dst_proc));
      if (issuer->host)
        label = simgrid::xbt::string_printf("[(%lu)%s] Wait [(%lu)->(%lu)]",
                    issuer->pid,
                    MC_smx_process_get_host_name(issuer),
                    src_proc ? src_proc->pid : 0,
                    dst_proc ? dst_proc->pid : 0);
      else
        label = simgrid::xbt::string_printf("[(%lu)] Wait [(%lu)->(%lu)]",
                    issuer->pid,
                    src_proc ? src_proc->pid : 0,
                    dst_proc ? dst_proc->pid : 0);
    }
    break;
  }

  case SIMCALL_COMM_TEST: {
    smx_activity_t remote_act = simcall_comm_test__get__comm(req);
    simgrid::mc::Remote<simgrid::kernel::activity::Comm> temp_comm;
    mc_model_checker->process().read(temp_comm, remote(
      static_cast<simgrid::kernel::activity::Comm*>(remote_act)));
    simgrid::kernel::activity::Comm* comm = temp_comm.getBuffer();
    if (comm->src_proc == nullptr || comm->dst_proc == nullptr) {
      if (issuer->host)
        label = simgrid::xbt::string_printf("[(%lu)%s] Test FALSE",
                    issuer->pid,
                    MC_smx_process_get_host_name(issuer));
      else
        label = bprintf("[(%lu)] Test FALSE", issuer->pid);
    } else {
      if (issuer->host)
        label = simgrid::xbt::string_printf("[(%lu)%s] Test TRUE", issuer->pid,
                    MC_smx_process_get_host_name(issuer));
      else
        label = simgrid::xbt::string_printf("[(%lu)] Test TRUE", issuer->pid);
    }
    break;
  }

  case SIMCALL_COMM_WAITANY: {
    unsigned long comms_size = read_length(
      mc_model_checker->process(), remote(simcall_comm_waitany__get__comms(req)));
    if (issuer->host)
      label = simgrid::xbt::string_printf("[(%lu)%s] WaitAny [%d of %lu]",
                  issuer->pid,
                  MC_smx_process_get_host_name(issuer), value + 1,
                  comms_size);
    else
      label = simgrid::xbt::string_printf("[(%lu)] WaitAny [%d of %lu]",
                  issuer->pid, value + 1, comms_size);
    break;
  }

  case SIMCALL_COMM_TESTANY:
    if (value == -1) {
      if (issuer->host)
        label = simgrid::xbt::string_printf("[(%lu)%s] TestAny FALSE",
                    issuer->pid, MC_smx_process_get_host_name(issuer));
      else
        label = simgrid::xbt::string_printf("[(%lu)] TestAny FALSE", issuer->pid);
    } else {
      if (issuer->host)
        label = simgrid::xbt::string_printf("[(%lu)%s] TestAny TRUE [%d of %lu]",
                    issuer->pid,
                    MC_smx_process_get_host_name(issuer), value + 1,
                    simcall_comm_testany__get__count(req));
      else
        label = simgrid::xbt::string_printf("[(%lu)] TestAny TRUE [%d of %lu]",
                    issuer->pid,
                    value + 1,
                    simcall_comm_testany__get__count(req));
    }
    break;

  case SIMCALL_MUTEX_TRYLOCK:
    label = simgrid::xbt::string_printf("[(%lu)] Mutex TRYLOCK", issuer->pid);
    break;

  case SIMCALL_MUTEX_LOCK:
    label = simgrid::xbt::string_printf("[(%lu)] Mutex LOCK", issuer->pid);
    break;

  case SIMCALL_MC_RANDOM:
    if (issuer->host)
      label = simgrid::xbt::string_printf("[(%lu)%s] MC_RANDOM (%d)",
                  issuer->pid, MC_smx_process_get_host_name(issuer), value);
    else
      label = simgrid::xbt::string_printf("[(%lu)] MC_RANDOM (%d)", issuer->pid, value);
    break;

  default:
    THROW_UNIMPLEMENTED;
  }

  const char* color = get_color(issuer->pid - 1);
  return  simgrid::xbt::string_printf(
        "label = \"%s\", color = %s, fontcolor = %s", label.c_str(),
        color, color);
}
Ejemplo n.º 23
0
char *request_get_dot_output(smx_simcall_t req, int value)
{
  char *label = nullptr;

  const smx_process_t issuer = MC_smx_simcall_get_issuer(req);

  switch (req->call) {
  case SIMCALL_COMM_ISEND:
    if (issuer->host)
      label =
          bprintf("[(%lu)%s] iSend", issuer->pid,
                  MC_smx_process_get_host_name(issuer));
    else
      label = bprintf("[(%lu)] iSend", issuer->pid);
    break;

  case SIMCALL_COMM_IRECV:
    if (issuer->host)
      label =
          bprintf("[(%lu)%s] iRecv", issuer->pid,
                  MC_smx_process_get_host_name(issuer));
    else
      label = bprintf("[(%lu)] iRecv", issuer->pid);
    break;

  case SIMCALL_COMM_WAIT: {
    if (value == -1) {
      if (issuer->host)
        label =
            bprintf("[(%lu)%s] WaitTimeout", issuer->pid,
                    MC_smx_process_get_host_name(issuer));
      else
        label = bprintf("[(%lu)] WaitTimeout", issuer->pid);
    } else {
      smx_synchro_t remote_act = simcall_comm_wait__get__comm(req);
      s_smx_synchro_t synchro;
      mc_model_checker->process().read_bytes(&synchro,
        sizeof(synchro), remote(remote_act));

      smx_process_t src_proc = MC_smx_resolve_process(synchro.comm.src_proc);
      smx_process_t dst_proc = MC_smx_resolve_process(synchro.comm.dst_proc);
      if (issuer->host)
        label =
            bprintf("[(%lu)%s] Wait [(%lu)->(%lu)]", issuer->pid,
                    MC_smx_process_get_host_name(issuer),
                    src_proc ? src_proc->pid : 0,
                    dst_proc ? dst_proc->pid : 0);
      else
        label =
            bprintf("[(%lu)] Wait [(%lu)->(%lu)]", issuer->pid,
                    src_proc ? src_proc->pid : 0,
                    dst_proc ? dst_proc->pid : 0);
    }
    break;
  }

  case SIMCALL_COMM_TEST: {
    smx_synchro_t remote_act = simcall_comm_test__get__comm(req);
    s_smx_synchro_t synchro;
    mc_model_checker->process().read_bytes(&synchro,
      sizeof(synchro), remote(remote_act));
    if (synchro.comm.src_proc == nullptr || synchro.comm.dst_proc == NULL) {
      if (issuer->host)
        label =
            bprintf("[(%lu)%s] Test FALSE", issuer->pid,
                    MC_smx_process_get_host_name(issuer));
      else
        label = bprintf("[(%lu)] Test FALSE", issuer->pid);
    } else {
      if (issuer->host)
        label =
            bprintf("[(%lu)%s] Test TRUE", issuer->pid,
                    MC_smx_process_get_host_name(issuer));
      else
        label = bprintf("[(%lu)] Test TRUE", issuer->pid);
    }
    break;
  }

  case SIMCALL_COMM_WAITANY: {
    unsigned long comms_size = read_length(
      mc_model_checker->process(), remote(simcall_comm_waitany__get__comms(req)));
    if (issuer->host)
      label =
          bprintf("[(%lu)%s] WaitAny [%d of %lu]", issuer->pid,
                  MC_smx_process_get_host_name(issuer), value + 1,
                  comms_size);
    else
      label =
          bprintf("[(%lu)] WaitAny [%d of %lu]", issuer->pid, value + 1,
                  comms_size);
    break;
  }

  case SIMCALL_COMM_TESTANY:
    if (value == -1) {
      if (issuer->host)
        label =
            bprintf("[(%lu)%s] TestAny FALSE", issuer->pid,
                    MC_smx_process_get_host_name(issuer));
      else
        label = bprintf("[(%lu)] TestAny FALSE", issuer->pid);
    } else {
      if (issuer->host)
        label =
            bprintf("[(%lu)%s] TestAny TRUE [%d of %lu]", issuer->pid,
                    MC_smx_process_get_host_name(issuer), value + 1,
                    xbt_dynar_length(simcall_comm_testany__get__comms(req)));
      else
        label =
            bprintf("[(%lu)] TestAny TRUE [%d of %lu]", issuer->pid,
                    value + 1,
                    xbt_dynar_length(simcall_comm_testany__get__comms(req)));
    }
    break;

  case SIMCALL_MUTEX_TRYLOCK:
    label = bprintf("[(%lu)] Mutex TRYLOCK", issuer->pid);
    break;

  case SIMCALL_MUTEX_LOCK:
    label = bprintf("[(%lu)] Mutex LOCK", issuer->pid);
    break;

  case SIMCALL_MC_RANDOM:
    if (issuer->host)
      label =
          bprintf("[(%lu)%s] MC_RANDOM (%d)", issuer->pid,
                  MC_smx_process_get_host_name(issuer), value);
    else
      label = bprintf("[(%lu)] MC_RANDOM (%d)", issuer->pid, value);
    break;

  default:
    THROW_UNIMPLEMENTED;
  }

  char* str =
      bprintf("label = \"%s\", color = %s, fontcolor = %s", label,
              colors[issuer->pid - 1], colors[issuer->pid - 1]);
  xbt_free(label);
  return str;

}
Ejemplo n.º 24
0
static readstat_error_t read_value_vector(rdata_sexptype_header_t header, const char *name, rdata_ctx_t *ctx) {
    readstat_error_t retval = READSTAT_OK;
    int32_t length;
    size_t input_elem_size = 0;
    void *vals = NULL;
    size_t buf_len = 0;
    int output_data_type;
    int i;
    
    switch (header.type) {
        case RDATA_SEXPTYPE_REAL_VECTOR:
            input_elem_size = sizeof(double);
            output_data_type = READSTAT_TYPE_DOUBLE;
            break;
        case RDATA_SEXPTYPE_INTEGER_VECTOR:
            input_elem_size = sizeof(int32_t);
            output_data_type = READSTAT_TYPE_DOUBLE;
            break;
        case RDATA_SEXPTYPE_LOGICAL_VECTOR:
            input_elem_size = sizeof(int32_t);
            output_data_type = READSTAT_TYPE_DOUBLE;
            break;
        default:
            retval = READSTAT_ERROR_PARSE;
            break;
    }
    if (retval != READSTAT_OK)
        goto cleanup;

    if ((retval = read_length(&length, ctx)) != READSTAT_OK)
        goto cleanup;

    buf_len = length * input_elem_size;
    
    vals = malloc(buf_len);
    if (vals == NULL) {
        retval = READSTAT_ERROR_MALLOC;
        goto cleanup;
    }
    
    if (read_st(ctx, vals, buf_len) != buf_len) {
        retval = READSTAT_ERROR_READ;
        goto cleanup;
    }
    
    if (ctx->machine_needs_byteswap) {
        if (input_elem_size == sizeof(double)) {
            double *d_vals = (double *)vals;
            for (i=0; i<buf_len/sizeof(double); i++) {
                d_vals[i] = byteswap_double(d_vals[i]);
            }
        } else {
            uint32_t *i_vals = (uint32_t *)vals;
            for (i=0; i<buf_len/sizeof(uint32_t); i++) {
                i_vals[i] = byteswap4(i_vals[i]);
            }
        }
    }
    
    ctx->class_is_posixct = 0;
    if (header.attributes) {
        if ((retval = read_attributes(&handle_vector_attribute, ctx)) != READSTAT_OK)
            goto cleanup;
    }
    
    if (ctx->column_handler) {
        if (header.type == RDATA_SEXPTYPE_LOGICAL_VECTOR ||
                header.type == RDATA_SEXPTYPE_INTEGER_VECTOR) {
            double *real_vals = malloc(length * sizeof(double));
            int32_t *i_vals = (int32_t *)vals;
            for (i=0; i<length; i++) {
                if (i_vals[i] == INT32_MIN) {
                    real_vals[i] = NAN;
                } else {
                    real_vals[i] = i_vals[i];
                }
            }
            if (ctx->column_handler(name, output_data_type, NULL, real_vals, length, ctx->user_ctx)) {
                retval = READSTAT_ERROR_USER_ABORT;
                goto cleanup;
            }
            free(real_vals);
        } else {
            if (ctx->column_handler(name, output_data_type, ctx->class_is_posixct ? "%ts" : NULL, vals, length, ctx->user_ctx)) {
                retval = READSTAT_ERROR_USER_ABORT;
                goto cleanup;
            }
        }
    }

cleanup:
    
    return retval;
}
Ejemplo n.º 25
0
int main(int argc, char **argv)
{
  int32 length;
  int c, block = 1, last_type = ASCII;

  ifp = stdin;
  ofp = stdout;
  print_banner();

  if (argc > 3)
    usage();

  /* possibly open input & output files */
  if (argc >= 2) {
    ifp = fopen(argv[1], "r");
    if (!ifp) {
      fprintf(stderr, "error: cannot open %s for reading\n", argv[1]);
      exit(1);
    }
  }
  if (argc == 3) {
    ofp = fopen(argv[2], "w");
    if (!ofp) {
      fprintf(stderr, "error: cannot open %s for writing\n", argv[2]);
      exit(1);
    }
  }

  #ifdef _MSDOS
    /* As we are processing a PFB (binary) input */
    /* file, we must set its file mode to binary. */
    _setmode(_fileno(ifp), _O_BINARY);
  #endif

  /* main loop through blocks */

  for (;;) {
    c = fgetc(ifp);
    if (c == EOF) {
      break;
    }
    if (c != MARKER) {
      fprintf(stderr,
              "error:  missing marker (128) at beginning of block %d",
              block);
      exit(1);
    }
    switch (c = fgetc(ifp)) {
    case ASCII:
      if (last_type != ASCII)
        fputc('\n', ofp);
      last_type = ASCII;
      for (length = read_length(); length > 0; length--)
        if ((c = fgetc(ifp)) == '\r')
          fputc('\n', ofp);
        else
          fputc(c, ofp);
      break;
    case BINARY:
      last_type = BINARY;
      for (length = read_length(); length > 0; length--)
        output_hex(fgetc(ifp));
      break;
    case DONE:
      /* nothing to be done --- will exit at top of loop with EOF */
      break;
    default:
      fprintf(stderr, "error: bad block type %d in block %d\n",
              c, block);
      break;
    }
    block++;
  }
  fclose(ifp);
  fclose(ofp);
  syncfs("/");
  return 0;
}
Ejemplo n.º 26
0
    bool format(const DistributedType* dtype)
    {
        Type type = dtype->get_type();
        switch(type) {
        case T_INVALID: {
            out << "<invalid>";
            break;
        }
        case T_INT8: {
            if(!remaining(sizeof(int8_t))) {
                return false;
            }
            int v = *(int8_t*)(in + offset);
            offset += sizeof(int8_t);
            out << v;
            break;
        }
        case T_INT16: {
            if(!remaining(sizeof(int16_t))) {
                return false;
            }
            int v = swap_le(*(int16_t*)(in + offset));
            offset += sizeof(int16_t);
            out << v;
            break;
        }
        case T_INT32: {
            if(!remaining(sizeof(int32_t))) {
                return false;
            }
            int v = swap_le(*(int32_t*)(in + offset));
            offset += sizeof(int32_t);
            out << v;
            break;
        }
        case T_INT64: {
            if(!remaining(sizeof(int64_t))) {
                return false;
            }
            int64_t v = swap_le(*(int64_t*)(in + offset));
            offset += sizeof(int64_t);
            out << v;
            break;
        }
        case T_UINT8: {
            if(!remaining(sizeof(uint8_t))) {
                return false;
            }
            unsigned int v = *(uint8_t*)(in + offset);
            offset += sizeof(uint8_t);
            out << v;
            break;
        }
        case T_UINT16: {
            if(!remaining(sizeof(uint16_t))) {
                return false;
            }
            unsigned int v = swap_le(*(uint16_t*)(in + offset));
            offset += sizeof(uint16_t);
            out << v;
            break;
        }
        case T_UINT32: {
            if(!remaining(sizeof(uint32_t))) {
                return false;
            }
            unsigned int v = swap_le(*(uint32_t*)(in + offset));
            offset += sizeof(uint32_t);
            out << v;
            break;
        }
        case T_UINT64: {
            if(!remaining(sizeof(uint64_t))) {
                return false;
            }
            uint64_t v = swap_le(*(uint64_t*)(in + offset));
            offset += sizeof(uint64_t);
            out << v;
            break;
        }
        case T_FLOAT32: {
            if(!remaining(sizeof(float))) {
                return false;
            }
            float v = (float)swap_le(*(float*)(in + offset));
            offset += sizeof(float);
            out << v;
            break;
        }
        case T_FLOAT64: {
            if(!remaining(sizeof(double))) {
                return false;
            }
            double v = (double)swap_le(*(double*)(in + offset));
            offset += sizeof(double);
            out << v;
            break;
        }
        case T_CHAR: {
            if(!remaining(sizeof(char))) {
                return false;
            }
            char v = *(char*)(in + offset);
            format_quoted('\'', string(1, v), out);
            offset += sizeof(char);
            break;
        }
        case T_STRING: {
            // Read string length
            sizetag_t length = dtype->get_size();


            // If we have a string alias format as a quoted string
            if(dtype->has_alias() && dtype->get_alias() == "string") {
                // Read string
                if(!remaining(length)) {
                    return false;
                }
                string str((const char*)in + offset, length);
                offset += length;

                // Enquoute and escape string then output
                format_quoted('"', str, out);
            } else {
                // Otherwise format as an array of char
                out << '[';
                const ArrayType* arr = dtype->as_array();
                bool ok = format(arr->get_element_type());
                if(!ok) {
                    return false;
                }
                for(unsigned int i = 1; i < arr->get_array_size(); ++i) {
                    out << ", ";
                    ok = format(arr->get_element_type());
                    if(!ok) {
                        return false;
                    }
                }

                out << ']';
            }
            break;
        }
        case T_VARSTRING: {

            // If we have a string alias format as a quoted string
            if(dtype->has_alias() && dtype->get_alias() == "string") {
                // Read string length
                if(!remaining(sizeof(sizetag_t))) {
                    return false;
                }
                sizetag_t length = read_length();

                // Read string
                if(!remaining(length)) {
                    return false;
                }
                string str((const char*)in + offset, length);
                offset += length;

                // Enquoute and escape string then output
                format_quoted('"', str, out);
            } else {
                // Otherwise format as an array of char
                out << '[';
                // Read array byte length
                if(!remaining(sizeof(sizetag_t))) {
                    out << ']';
                    return false;
                }
                sizetag_t length = read_length();

                if(length == 0) {
                    out << ']';
                    break;
                }

                // Read array
                if(!remaining(length)) {
                    out << ']';
                    return false;
                }
                size_t array_end = offset + length;

                const ArrayType* arr = dtype->as_array();
                bool ok = format(arr->get_element_type());
                if(!ok) {
                    out << ']';
                    return false;
                }

                while(offset < array_end) {
                    out << ", ";
                    ok = format(arr->get_element_type());
                    if(!ok) {
                        out << ']';
                        return false;
                    }
                }

                // Check to make sure we didn't overshoot the array while reading
                if(offset > array_end) {
                    out << ']';
                    return false;
                }

                out << ']';
            }

            break;
        }
        case T_BLOB: {
            // Read blob length
            sizetag_t length = dtype->get_size();

            // If we have a blob alias format as a hex constant
            if(dtype->has_alias() && dtype->get_alias() == "blob") {
                // Read blob
                if(!remaining(length)) {
                    return false;
                }
                string blob((const char*)in + offset, length);
                offset += length;

                // Format blob as a hex constant then output
                format_hex(blob, out);
            } else {
                // Otherwise format as an array of uint8
                out << '[';
                const ArrayType* arr = dtype->as_array();
                bool ok = format(arr->get_element_type());
                if(!ok) {
                    out << ']';
                    return false;
                }

                for(unsigned int i = 1; i < arr->get_array_size(); ++i) {
                    out << ", ";
                    ok = format(arr->get_element_type());
                    if(!ok) {
                        out << ']';
                        return false;
                    }
                }

                out << ']';
            }

            break;
        }
        case T_VARBLOB: {
            // If we have a blob alias format as a hex constant
            if(dtype->has_alias() && dtype->get_alias() == "blob") {
                // Read blob length
                if(!remaining(sizeof(sizetag_t))) {
                    return false;
                }
                sizetag_t length = read_length();


                // Read blob with length
                if(!remaining(length)) {
                    return false;
                }
                string blob((const char*)in + offset - 2, length + 2);
                offset += length;

                // Format blob and length as a hex constant then output
                format_hex(blob, out);
            } else {
                // Otherwise format as an array of uint8
                out << '[';
                // Read array byte length
                if(!remaining(sizeof(sizetag_t))) {
                    out << ']';
                    return false;
                }
                sizetag_t length = read_length();

                if(length == 0) {
                    out << ']';
                    break;
                }
                // Read array
                if(!remaining(length)) {
                    out << ']';
                    return false;
                }
                size_t array_end = offset + length;

                const ArrayType* arr = dtype->as_array();
                bool ok = format(arr->get_element_type());
                if(!ok) {
                    out << ']';
                    return false;
                }
                while(offset < array_end) {
                    out << ", ";
                    ok = format(arr->get_element_type());
                    if(!ok) {
                        out << ']';
                        return false;
                    }
                }

                // Check to make sure we didn't overshoot the array while reading
                if(offset > array_end) {
                    out << ']';
                    return false;
                }

                out << ']';
            }

            break;
        }
        case T_ARRAY: {
            out << '[';
            const ArrayType* arr = dtype->as_array();
            bool ok = format(arr->get_element_type());
            if(!ok) {
                out << ']';
                return false;
            }
            for(unsigned int i = 1; i < arr->get_array_size(); ++i) {
                out << ", ";
                ok = format(arr->get_element_type());
                if(!ok) {
                    out << ']';
                    return false;
                }
            }

            out << ']';
            break;
        }
        case T_VARARRAY: {
            out << '[';
            // Read array byte length
            if(!remaining(sizeof(sizetag_t))) {
                out << ']';
                return false;
            }
            sizetag_t length = read_length();

            if(length == 0) {
                out << ']';
                break;
            }

            // Read array
            if(!remaining(length)) {
                out << ']';
                return false;
            }
            size_t array_end = offset + length;

            const ArrayType* arr = dtype->as_array();
            bool ok = format(arr->get_element_type());
            if(!ok) {
                out << ']';
                return false;
            }
            while(offset < array_end) {
                out << ", ";
                ok = format(arr->get_element_type());
                if(!ok) {
                    out << ']';
                    return false;
                }
            }

            // Check to make sure we didn't overshoot the array while reading
            if(offset > array_end) {
                out << ']';
                return false;
            }

            out << ']';
            break;
        }
        case T_STRUCT: {
            out << '{';
            const Struct* strct = dtype->as_struct();
            size_t num_fields = strct->get_num_fields();
            if(num_fields > 0) {
                bool ok = format(strct->get_field(0)->get_type());
                if(!ok) {
                    out << '}';
                    return false;
                }
                for(unsigned int i = 1; i < num_fields; ++i) {
                    out << ", ";
                    ok = format(strct->get_field(i)->get_type());
                    if(!ok) {
                        out << '}';
                        return false;
                    }
                }
            }
            out << '}';
            break;
        }
        case T_METHOD: {
            out << '(';
            const Method* method = dtype->as_method();
            size_t num_params = method->get_num_parameters();
            if(num_params > 0) {
                bool ok = format(method->get_parameter(0)->get_type());
                if(!ok) {
                    out << ')';
                    return false;
                }
                for(unsigned int i = 1; i < num_params; ++i) {
                    out << ", ";
                    ok = format(method->get_parameter(i)->get_type());
                    if(!ok) {
                        out << ')';
                        return false;
                    }
                }
            }
            out << ')';
            break;
        }
        default: {
            out << "<error>";
            return false;
        }
        }
        return true;
    }
Ejemplo n.º 27
0
static readstat_error_t read_toplevel_object(const char *table_name, const char *key, rdata_ctx_t *ctx) {
    rdata_sexptype_info_t sexptype_info;
    readstat_error_t retval = READSTAT_OK;
    
    if ((retval = read_sexptype_header(&sexptype_info, ctx)) != READSTAT_OK)
        goto cleanup;

    if (sexptype_info.header.type == RDATA_SEXPTYPE_REAL_VECTOR ||
            sexptype_info.header.type == RDATA_SEXPTYPE_INTEGER_VECTOR ||
            sexptype_info.header.type == RDATA_SEXPTYPE_LOGICAL_VECTOR) {
        if (table_name == NULL && ctx->table_handler) {
            if (ctx->table_handler(key, ctx->user_ctx)) {
                retval = READSTAT_ERROR_USER_ABORT;
                goto cleanup;
            }   
        }
        
        if ((retval = read_value_vector(sexptype_info.header, key, ctx)) != READSTAT_OK)
            goto cleanup;
    } else if (sexptype_info.header.type == RDATA_SEXPTYPE_CHARACTER_VECTOR) {
        if (table_name == NULL && ctx->table_handler) {
            if (ctx->table_handler(key, ctx->user_ctx)) {
                retval = READSTAT_ERROR_USER_ABORT;
                goto cleanup;
            }   
        }
        int32_t length;
        
        if ((retval = read_length(&length, ctx)) != READSTAT_OK)
            goto cleanup;

        if (ctx->column_handler) {
            if (ctx->column_handler(key, READSTAT_TYPE_STRING, NULL, NULL, length, ctx->user_ctx)) {
                retval = READSTAT_ERROR_USER_ABORT;
                goto cleanup;
            }
        }
        
        if ((retval = read_string_vector(length, ctx->text_value_handler, ctx->user_ctx, ctx)) != READSTAT_OK)
            goto cleanup;
    } else if (sexptype_info.header.type == RDATA_SEXPTYPE_GENERIC_VECTOR &&
            sexptype_info.header.object && sexptype_info.header.attributes) {
        if (table_name != NULL) {
            retval = recursive_discard(sexptype_info.header, ctx);
        } else {
            if (ctx->table_handler) {
                if (ctx->table_handler(key, ctx->user_ctx)) {
                    retval = READSTAT_ERROR_USER_ABORT;
                    goto cleanup;
                }
            }
            retval = read_generic_list(sexptype_info.header.attributes, ctx);
        }
        if (retval != READSTAT_OK)
            goto cleanup;
    } else {
        if ((retval = recursive_discard(sexptype_info.header, ctx)) != READSTAT_OK)
            goto cleanup;
    }

cleanup:

    return retval;
}
Ejemplo n.º 28
0
/*
 * The segment magic has been checked.  There is a footer and table of
 * contents present.
 *
 * directory is a u32 aligned buffer of size EP_PAGE_SIZE.
 */
static int read_segment_platform_config(struct hfi1_devdata *dd,
					void *directory, void **data, u32 *size)
{
	struct hfi1_eprom_footer *footer;
	struct hfi1_eprom_table_entry *table;
	struct hfi1_eprom_table_entry *entry;
	void *buffer = NULL;
	void *table_buffer = NULL;
	int ret, i;
	u32 directory_size;
	u32 seg_base, seg_offset;
	u32 bytes_available, ncopied, to_copy;

	/* the footer is at the end of the directory */
	footer = (struct hfi1_eprom_footer *)
			(directory + EP_PAGE_SIZE - sizeof(*footer));

	/* make sure the structure version is supported */
	if (footer->version != FOOTER_VERSION)
		return -EINVAL;

	/* oprom size cannot be larger than a segment */
	if (footer->oprom_size >= SEG_SIZE)
		return -EINVAL;

	/* the file table must fit in a segment with the oprom */
	if (footer->num_table_entries >
			MAX_TABLE_ENTRIES(SEG_SIZE - footer->oprom_size))
		return -EINVAL;

	/* find the file table start, which precedes the footer */
	directory_size = DIRECTORY_SIZE(footer->num_table_entries);
	if (directory_size <= EP_PAGE_SIZE) {
		/* the file table fits into the directory buffer handed in */
		table = (struct hfi1_eprom_table_entry *)
				(directory + EP_PAGE_SIZE - directory_size);
	} else {
		/* need to allocate and read more */
		table_buffer = kmalloc(directory_size, GFP_KERNEL);
		if (!table_buffer)
			return -ENOMEM;
		ret = read_length(dd, SEG_SIZE - directory_size,
				  directory_size, table_buffer);
		if (ret)
			goto done;
		table = table_buffer;
	}

	/* look for the platform configuration file in the table */
	for (entry = NULL, i = 0; i < footer->num_table_entries; i++) {
		if (table[i].type == HFI1_EFT_PLATFORM_CONFIG) {
			entry = &table[i];
			break;
		}
	}
	if (!entry) {
		ret = -ENOENT;
		goto done;
	}

	/*
	 * Sanity check on the configuration file size - it should never
	 * be larger than 4 KiB.
	 */
	if (entry->size > (4 * 1024)) {
		dd_dev_err(dd, "Bad configuration file size 0x%x\n",
			   entry->size);
		ret = -EINVAL;
		goto done;
	}

	/* check for bogus offset and size that wrap when added together */
	if (entry->offset + entry->size < entry->offset) {
		dd_dev_err(dd,
			   "Bad configuration file start + size 0x%x+0x%x\n",
			   entry->offset, entry->size);
		ret = -EINVAL;
		goto done;
	}

	/* allocate the buffer to return */
	buffer = kmalloc(entry->size, GFP_KERNEL);
	if (!buffer) {
		ret = -ENOMEM;
		goto done;
	}

	/*
	 * Extract the file by looping over segments until it is fully read.
	 */
	seg_offset = entry->offset % SEG_SIZE;
	seg_base = entry->offset - seg_offset;
	ncopied = 0;
	while (ncopied < entry->size) {
		/* calculate data bytes available in this segment */

		/* start with the bytes from the current offset to the end */
		bytes_available = SEG_SIZE - seg_offset;
		/* subtract off footer and table from segment 0 */
		if (seg_base == 0) {
			/*
			 * Sanity check: should not have a starting point
			 * at or within the directory.
			 */
			if (bytes_available <= directory_size) {
				dd_dev_err(dd,
					   "Bad configuration file - offset 0x%x within footer+table\n",
					   entry->offset);
				ret = -EINVAL;
				goto done;
			}
			bytes_available -= directory_size;
		}

		/* calculate bytes wanted */
		to_copy = entry->size - ncopied;

		/* max out at the available bytes in this segment */
		if (to_copy > bytes_available)
			to_copy = bytes_available;

		/*
		 * Read from the EPROM.
		 *
		 * The sanity check for entry->offset is done in read_length().
		 * The EPROM offset is validated against what the hardware
		 * addressing supports.  In addition, if the offset is larger
		 * than the actual EPROM, it silently wraps.  It will work
		 * fine, though the reader may not get what they expected
		 * from the EPROM.
		 */
		ret = read_length(dd, seg_base + seg_offset, to_copy,
				  buffer + ncopied);
		if (ret)
			goto done;

		ncopied += to_copy;

		/* set up for next segment */
		seg_offset = footer->oprom_size;
		seg_base += SEG_SIZE;
	}

	/* success */
	ret = 0;
	*data = buffer;
	*size = entry->size;

done:
	kfree(table_buffer);
	if (ret)
		kfree(buffer);
	return ret;
}
Ejemplo n.º 29
0
void LVCssDeclaration::apply( css_style_rec_t * style )
{
    if (!_data)
        return;
    int * p = _data;
    for (;;)
    {
        switch (*p++)
        {
        case cssd_display:
            style->display = (css_display_t) *p++;
            break;
        case cssd_white_space:
            style->white_space = (css_white_space_t) *p++;
            break;
        case cssd_text_align:
            style->text_align = (css_text_align_t) *p++;
            break;
        case cssd_text_align_last:
            style->text_align_last = (css_text_align_t) *p++;
            break;
        case cssd_text_decoration:
            style->text_decoration = (css_text_decoration_t) *p++;
            break;
        case cssd_hyphenate:
            style->hyphenate = (css_hyphenate_t) *p++;
            break;
        case cssd_list_style_type:
            style->list_style_type = (css_list_style_type_t) *p++;
            break;
        case cssd_list_style_position:
            style->list_style_position = (css_list_style_position_t) *p++;
            break;
        case cssd_page_break_before:
            style->page_break_before = (css_page_break_t) *p++;
            break;
        case cssd_page_break_after:
            style->page_break_after = (css_page_break_t) *p++;
            break;
        case cssd_page_break_inside:
            style->page_break_inside = (css_page_break_t) *p++;
            break;
        case cssd_vertical_align:
            style->vertical_align = (css_vertical_align_t) *p++;
            break;
        case cssd_font_family:
            style->font_family = (css_font_family_t) *p++;
            break;
        case cssd_font_names:
            {
                lString8 names;
                names.reserve(64);
                int len = *p++;
                for (int i=0; i<len; i++)
                    names << (lChar8)(*p++);
                names.pack();
                style->font_name = names;
            }
            break;
        case cssd_font_style:
            style->font_style = (css_font_style_t) *p++;
            break;
        case cssd_font_weight:
            style->font_weight = (css_font_weight_t) *p++;
            break;
        case cssd_font_size:
            style->font_size = read_length( p );
            break;
        case cssd_text_indent:
            style->text_indent = read_length( p );
            break;
        case cssd_line_height:
            style->line_height = read_length( p );
            break;
        case cssd_letter_spacing:
            style->letter_spacing = read_length( p );
            break;
        case cssd_color:
            style->color = read_length( p );
            break;
        case cssd_background_color:
            style->background_color = read_length( p );
            break;
        case cssd_width:
            style->width = read_length( p );
            break;
        case cssd_height:
            style->height = read_length( p );
            break;
        case cssd_margin_left:
            style->margin[0] = read_length( p );
            break;
        case cssd_margin_right:
            style->margin[1] = read_length( p );
            break;
        case cssd_margin_top:
            style->margin[2] = read_length( p );
            break;
        case cssd_margin_bottom:
            style->margin[3] = read_length( p );
            break;
        case cssd_margin:
            style->margin[2] = read_length( p );
            style->margin[1] = read_length( p );
            style->margin[3] = read_length( p );
            style->margin[0] = read_length( p );
            break;
        case cssd_padding_left:
            style->padding[0] = read_length( p );
            break;
        case cssd_padding_right:
            style->padding[1] = read_length( p );
            break;
        case cssd_padding_top:
            style->padding[2] = read_length( p );
            break;
        case cssd_padding_bottom:
            style->padding[3] = read_length( p );
            break;
        case cssd_padding:
            style->padding[2] = read_length( p );
            style->padding[1] = read_length( p );
            style->padding[3] = read_length( p );
            style->padding[0] = read_length( p );
            break;
        case cssd_stop:
            return;
        }
    }
}