Exemplo n.º 1
0
void audio_release(int dev, struct file *file)
{
	const struct coproc_operations *coprocessor;
	int mode = translate_mode(file);

	dev = dev >> 4;

	/*
	 * We do this in DMAbuf_release(). Why are we doing it
	 * here? Why don't we test the file mode before setting
	 * both flags? DMAbuf_release() does.
	 * ...pester...pester...pester...
	 */
	audio_devs[dev]->dmap_out->closing = 1;
	audio_devs[dev]->dmap_in->closing = 1;

	/*
	 * We need to make sure we allocated the dmap_out buffer
	 * before we go mucking around with it in sync_output().
	 */
	if (mode & OPEN_WRITE)
		sync_output(dev);

	if ( (coprocessor = audio_devs[dev]->coproc) != NULL ) {
		coprocessor->close(coprocessor->devc, COPR_PCM);
		module_put(coprocessor->owner);
	}
	DMAbuf_release(dev, mode);

	module_put(audio_devs[dev]->d->owner);
}
Exemplo n.º 2
0
void handle_open(syscall_req_t* req, syscall_rsp_t* rsp)
{
	char* name = sandbox_file_name(req->payload, req->payload_len);
	open_subheader_t* o = &req->header.subheader.open;	
	int native_flags = translate_flags(o->flags);
	int native_mode = translate_mode(o->mode);
	rsp->header.return_val = open(name, native_flags, native_mode);
	free(name);
}
Exemplo n.º 3
0
File::File(Mount& mnt,
           const fs::path& p,
           yt::FDMode fdmode,
           CreateIfNecessary create_if_necessary)
    : ctx_(mnt.ctx_)
{

    /* mode is not the same for both nfs_creat and nfs_open. For nfs_open
     * mode has the same meaning as flags but for nfs_creat is the mode used
     * for file creation. The newer version of libnfs makes this difference
     * obvious by introducing a second field 'flags' along with mode. We should
     * consider upgrading to the latest libnfs then and drop the workaround
     * introduced below.
     */
    const int mode = create_if_necessary == CreateIfNecessary::T ?
        translate_create_mode(fdmode) : translate_mode(fdmode);

    LOG_TRACE(mnt.share_name() << ", " << p << ", mode " << mode <<
              ", create: " << create_if_necessary);

    nfsfh* fh;
    int ret;

    if (create_if_necessary == CreateIfNecessary::T)
    {
        ret = nfs_creat(ctx_.get(),
                        p.string().c_str(),
                        mode,
                        &fh);
    }
    else
    {
        ret = nfs_open(ctx_.get(),
                       p.string().c_str(),
                       mode,
                       &fh);
    }

    if (ret < 0)
    {
        const char* err = nfs_get_error(ctx_.get());
        std::stringstream ss;
        ss << "Failed to open " << p << ": " << err;
        LOG_ERROR(ss.str());
        throw Exception(ss.str().c_str());
    }
    else
    {
        fh_ = std::shared_ptr<nfsfh>(fh, FhDeleter(ctx_));
    }
}
Exemplo n.º 4
0
static void print_block(struct pt_block *block,
			struct pt_image_section_cache *iscache,
			const struct ptxed_options *options,
			const struct ptxed_stats *stats,
			uint64_t offset, uint64_t time)
{
	xed_machine_mode_enum_t mode;
	xed_state_t xed;
	uint64_t last_ip;

	if (!block || !options) {
		printf("[internal error]\n");
		return;
	}

	if (block->resynced)
		printf("[overflow]\n");

	if (block->enabled)
		printf("[enabled]\n");

	if (block->resumed)
		printf("[resumed]\n");

	if (options->track_blocks) {
		printf("[block");
		if (stats)
			printf(" %" PRIx64, stats->blocks);
		printf("]\n");
	}

	mode = translate_mode(block->mode);
	xed_state_init2(&xed, mode, XED_ADDRESS_WIDTH_INVALID);

	last_ip = 0ull;
	for (; block->ninsn; --block->ninsn) {
		xed_decoded_inst_t inst;
		xed_error_enum_t xederrcode;
		uint8_t raw[pt_max_insn_size], *praw;
		int size, errcode;

		/* For truncated block, the last instruction is provided in the
		 * block since it can't be read entirely from the image section
		 * cache.
		 */
		if (block->truncated && (block->ninsn == 1)) {
			praw = block->raw;
			size = block->size;
		} else {
			praw = raw;
			size = pt_iscache_read(iscache, raw, sizeof(raw),
					       block->isid, block->ip);
			if (size < 0) {
				printf(" [error reading insn: (%d) %s]\n", size,
				       pt_errstr(pt_errcode(size)));
				break;
			}
		}

		xed_decoded_inst_zero_set_mode(&inst, &xed);

		if (block->speculative)
			printf("? ");

		if (options->print_offset)
			printf("%016" PRIx64 "  ", offset);

		if (options->print_time)
			printf("%016" PRIx64 "  ", time);

		printf("%016" PRIx64, block->ip);

		xederrcode = xed_decode(&inst, praw, size);
		if (xederrcode != XED_ERROR_NONE) {
			printf(" [xed decode error: (%u) %s]\n", xederrcode,
			       xed_error_enum_t2str(xederrcode));
			break;
		}

		if (!options->dont_print_insn)
			xed_print_insn(&inst, block->ip, options);

		printf("\n");

		last_ip = block->ip;

		errcode = xed_next_ip(&block->ip, &inst, last_ip);
		if (errcode < 0) {
			diagnose_block_at("reconstruct error", offset, block,
					  errcode);
			break;
		}
	}

	/* Decode should have brought us to @block->end_ip. */
	if (last_ip != block->end_ip)
		diagnose_block_at("reconstruct error", offset, block,
				  -pte_nosync);

	if (block->interrupted)
		printf("[interrupt]\n");

	if (block->aborted)
		printf("[aborted]\n");

	if (block->committed)
		printf("[committed]\n");

	if (block->disabled)
		printf("[disabled]\n");

	if (block->stopped)
		printf("[stopped]\n");
}
Exemplo n.º 5
0
static void print_insn(const struct pt_insn *insn, xed_state_t *xed,
		       const struct ptxed_options *options, uint64_t offset,
		       uint64_t time)
{
	if (!insn || !options) {
		printf("[internal error]\n");
		return;
	}

	if (insn->resynced)
		printf("[overflow]\n");

	if (insn->enabled)
		printf("[enabled]\n");

	if (insn->resumed)
		printf("[resumed]\n");

	if (insn->speculative)
		printf("? ");

	if (options->print_offset)
		printf("%016" PRIx64 "  ", offset);

	if (options->print_time)
		printf("%016" PRIx64 "  ", time);

	printf("%016" PRIx64, insn->ip);

	if (!options->dont_print_insn) {
		xed_machine_mode_enum_t mode;
		xed_decoded_inst_t inst;
		xed_error_enum_t errcode;

		mode = translate_mode(insn->mode);

		xed_state_set_machine_mode(xed, mode);
		xed_decoded_inst_zero_set_mode(&inst, xed);

		errcode = xed_decode(&inst, insn->raw, insn->size);
		switch (errcode) {
		case XED_ERROR_NONE:
			xed_print_insn(&inst, insn->ip, options);
			break;

		default:
			printf(" [xed decode error: (%u) %s]", errcode,
			       xed_error_enum_t2str(errcode));
			break;
		}
	}

	printf("\n");

	if (insn->interrupted)
		printf("[interrupt]\n");

	if (insn->aborted)
		printf("[aborted]\n");

	if (insn->committed)
		printf("[committed]\n");

	if (insn->disabled)
		printf("[disabled]\n");

	if (insn->stopped)
		printf("[stopped]\n");
}
Exemplo n.º 6
0
int audio_open(int dev, struct file *file)
{
	int ret;
	int bits;
	int dev_type = dev & 0x0f;
	int mode = translate_mode(file);
	const struct audio_driver *driver;
	const struct coproc_operations *coprocessor;

	dev = dev >> 4;

	if (dev_type == SND_DEV_DSP16)
		bits = 16;
	else
		bits = 8;

	if (dev < 0 || dev >= num_audiodevs)
		return -ENXIO;

	driver = audio_devs[dev]->d;

	if (!try_module_get(driver->owner))
		return -ENODEV;

	if ((ret = DMAbuf_open(dev, mode)) < 0)
		goto error_1;

	if ( (coprocessor = audio_devs[dev]->coproc) != NULL ) {
		if (!try_module_get(coprocessor->owner))
			goto error_2;

		if ((ret = coprocessor->open(coprocessor->devc, COPR_PCM)) < 0) {
			printk(KERN_WARNING "Sound: Can't access coprocessor device\n");
			goto error_3;
		}
	}
	
	audio_devs[dev]->local_conversion = 0;

	if (dev_type == SND_DEV_AUDIO)
		set_format(dev, AFMT_MU_LAW);
	else 
		set_format(dev, bits);

	audio_devs[dev]->audio_mode = AM_NONE;

	return 0;

	/*
	 * Clean-up stack: this is what needs (un)doing if
	 * we can't open the audio device ...
	 */
	error_3:
	module_put(coprocessor->owner);

	error_2:
	DMAbuf_release(dev, mode);

	error_1:
	module_put(driver->owner);

	return ret;
}