Ejemplo n.º 1
0
static int do_RenameStream(int argc, wchar_t **argv)
{
    if (argc != 4 || ':' != argv[2][0])
        fail("usage: RenameStream FileName:ExistingStreamName :NewStreamName ReplaceIfExists");
    fail("not implemented!");
#if 0
    HANDLE h = CreateFileW(argv[1],
        DELETE | SYNCHRONIZE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
        0, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, 0);
    if (INVALID_HANDLE_VALUE == h)
        errprint(0);
    else
    {
        typedef struct _FILE_RENAME_INFORMATION {
            BOOLEAN ReplaceIfExists;
            HANDLE RootDirectory;
            ULONG FileNameLength;
            WCHAR FileName[1];
        } FILE_RENAME_INFORMATION, *PFILE_RENAME_INFORMATION;
        size_t namesize = wcslen(argv[2]) * sizeof(wchar_t);
        size_t infosize = sizeof(FILE_RENAME_INFORMATION) + namesize;
        FILE_RENAME_INFORMATION *RenameInfo = _alloca(infosize);
        memset(RenameInfo, 0, infosize);
        RenameInfo->ReplaceIfExists = !!(wcstoul(argv[3], 0, 0));
        RenameInfo->RootDirectory = 0;
        RenameInfo->FileNameLength = namesize;
        memcpy(RenameInfo->FileName, argv[2], namesize);
        /*
         * This seems to fail with ERROR_INVALID_HANDLE on Win32 and ERROR_INVALID_NAME on Win64.
         * Do not have the time to figure the exact reasons why right now.
         */
        BOOL r = SetFileInformationByHandle(h, FileRenameInfo, &RenameInfo, infosize);
        errprint(r);
        CloseHandle(h);
    }
#endif
    return 0;
}
Ejemplo n.º 2
0
status_t wait_for_event_or_timeout(xen_instance_t *xen, xc_evtchn *xce, unsigned long ms)
{
    struct pollfd fd = {
        .fd = xen->libxcw.xc_evtchn_fd(xce),
        .events = POLLIN | POLLERR
    };

    switch ( poll(&fd, 1, ms) ) {
    case -1:
        if (errno == EINTR)
            return VMI_SUCCESS;

        errprint("Poll exited with an error\n");
        return VMI_FAILURE;
    case 0:
        return VMI_SUCCESS;
    default:
    {
        int port = xen->libxcw.xc_evtchn_pending(xce);
        if ( -1 == port )
        {
            errprint("Failed to read port from event channel\n");
            return VMI_FAILURE;
        }

        if ( xen->libxcw.xc_evtchn_unmask(xce, port) )
        {
            errprint("Failed to unmask event channel port\n");
            return VMI_FAILURE;
        }

        return VMI_SUCCESS;
    }
    };

    return VMI_FAILURE;
}
Ejemplo n.º 3
0
status_t
set_os_type_from_config(
    vmi_instance_t vmi)
{
    status_t ret = VMI_FAILURE;
    GHashTable *configtbl = (GHashTable *)vmi->config;
    const char* ostype = NULL;

    vmi->os_type = VMI_OS_UNKNOWN;
    if (vmi->os_data) {
        free(vmi->os_data);
        vmi->os_data = NULL;
    }

    ostype = g_hash_table_lookup(configtbl, "ostype");
    if (ostype == NULL) {
        ostype = g_hash_table_lookup(configtbl, "os_type");
    }

    if (ostype == NULL) {
        errprint("Undefined OS type!\n");
        return VMI_FAILURE;
    }

    if (strncmp(ostype, "Linux", CONFIG_STR_LENGTH) == 0) {
        vmi->os_type = VMI_OS_LINUX;
        ret = VMI_SUCCESS;
    } else if (strncmp(ostype, "Windows", CONFIG_STR_LENGTH) == 0) {
        vmi->os_type = VMI_OS_WINDOWS;
        ret = VMI_SUCCESS;
    } else {
        errprint("VMI_ERROR: Unknown OS type: %s!\n", ostype);
        ret = VMI_FAILURE;
    }

    return ret;
}
Ejemplo n.º 4
0
/*******************************************************************
 *
 * Description:     Open a connection to the cs server.
 *
 * Modified args:   None
 *
 * Return value:    0 if ok, negative if error.
 *
 *******************************************************************/
int
cs_cl_open(CONSRV *cs)
{
    struct sockaddr_in srvaddr;
    
    if ((cs->reqbuf = malloc(CS_SRV_BUF_SIZE)) == NULL)
    {
        errprint("Can't allocate request buffer for CONSRV client.\n");
        return -1;
    }
    
    memset(cs->reqbuf, 0, CS_SRV_BUF_SIZE);
    if ((cs->fd_srv = socket(AF_INET, SOCK_STREAM, 0)) < 0)
    {
        errprint("Can't create client socket.\n");
        free(cs->reqbuf);
        return -1;
    }
    
    memset(&srvaddr, 0, sizeof(srvaddr));
    srvaddr.sin_family = AF_INET;
    srvaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
    srvaddr.sin_port = htons(CS_SRV_PORT);
    
    DEBUG(1, "Connecting to cs server at port %d.\n", ntohs(srvaddr.sin_port));
    
    if (connect(cs->fd_srv, (struct sockaddr *)&srvaddr, sizeof(srvaddr)) < 0)
    {
        errprint("Can't connect to server socket.\n");
        free(cs->reqbuf);
        return -1;
    }
    
    DEBUG(1, "connected to server.\n");
    
    return 0;
}
Ejemplo n.º 5
0
static memory_cache_entry_t create_new_entry (vmi_instance_t vmi, addr_t paddr,
        uint32_t length)
{

    // sanity check - are we getting memory outside of the physical memory range?
    //
    // This does not work with a Xen PV VM during page table lookups, because
    // cr3 > [physical memory size]. It *might* not work when examining a PV
    // snapshot, since we're not sure where the page tables end up. So, we
    // just do it for a HVM guest.
    //
    // TODO: perform other reasonable checks

    if (vmi->hvm && (paddr + length - 1 > vmi->size)) {
        errprint("--requesting PA [0x%"PRIx64"] beyond memsize [0x%"PRIx64"]\n",
                paddr + length, vmi->size);
        errprint("\tpaddr: %"PRIx64", length %"PRIx32", vmi->size %"PRIx64"\n", paddr, length,
                vmi->size);
        return 0;
    }

    memory_cache_entry_t entry =
        (memory_cache_entry_t)
        safe_malloc(sizeof(struct memory_cache_entry));

    entry->paddr = paddr;
    entry->length = length;
    entry->last_updated = time(NULL);
    entry->last_used = entry->last_updated;
    entry->data = get_memory_data(vmi, paddr, length);

    if (vmi->memory_cache_size >= vmi->memory_cache_size_max) {
        clean_cache(vmi);
    }

    return entry;
}
Ejemplo n.º 6
0
bool
midibus::init_in ()
{
#ifdef SEQ64_HAVE_LIBASOUND
    int result = snd_seq_create_simple_port             /* create ports */
    (
        m_seq, "sequencer64 in",                        /* "seq24 in"   */
        SND_SEQ_PORT_CAP_NO_EXPORT | SND_SEQ_PORT_CAP_WRITE,
        SND_SEQ_PORT_TYPE_MIDI_GENERIC | SND_SEQ_PORT_TYPE_APPLICATION
    );
    m_local_addr_port = result;
    if (result < 0)
    {
        errprint("snd_seq_create_simple_port(read) error");
        return false;
    }

    snd_seq_port_subscribe_t * subs;
    snd_seq_port_subscribe_alloca(&subs);

    snd_seq_addr_t sender;
    sender.client = m_dest_addr_client;
    sender.port = m_dest_addr_port;
    snd_seq_port_subscribe_set_sender(subs, &sender);   /* destination        */

    snd_seq_addr_t dest;
    dest.client = m_local_addr_client;
    dest.port = m_local_addr_port;
    snd_seq_port_subscribe_set_dest(subs, &dest);       /* local              */

    /*
     * Use the master queue, and get ticks, then subscribe.
     */

    snd_seq_port_subscribe_set_queue(subs, m_queue);
    snd_seq_port_subscribe_set_time_update(subs, 1);
    result = snd_seq_subscribe_port(m_seq, subs);
    if (result < 0)
    {
        fprintf
        (
            stderr, "snd_seq_connect_from(%d:%d) error\n",
            m_dest_addr_client, m_dest_addr_port
        );
        return false;
    }
#endif  // SEQ64_HAVE_LIBASOUND
    return true;
}
Ejemplo n.º 7
0
void *th_force(void *param){

	thforce_data *d = (thforce_data *)param;
	char *guess;
	int i,n,k,found;

	if((guess = calloc(d->len+1,sizeof(char)))==NULL){
		errprint("malloc error!\n");
		return 0;
	}

	*(d->progress)=0;
	found=0;

	for (i=0;i<d->comb;i++) {
		n = i;
		guess[0]=d->set[d->start + (i % d->num)];
		n/= d->num;
		for (k=1; k<d->len; k++){
			guess[k] = d->set[n % d->set_len]; 
			n /= d->set_len;
		}

		
		found = open_key(guess, d->len, &(d->header), d->iv_mode, 
				d->chain_mode, d->crypt_disk,
				d->fast_check, d->keyslot, d->pbk_hash);
		
		*(d->progress)=*(d->progress) + 1;

		if(found){

			/* entering mutex section */
			pthread_mutex_lock(&condition_mutex);
			pthread_cond_signal(&condition_cond);

			memset(d->win_pwd,0,d->len);
			sprintf(d->win_pwd,"%s",guess);

			/* exiting mutex section */
			pthread_mutex_unlock(&condition_mutex);
			goto end;
		}
	}

end:
	free(guess);
	pthread_exit(NULL);
}
Ejemplo n.º 8
0
static status_t sanity_check(xen_instance_t *xen)
{
    libxs_wrapper_t *w = &xen->libxsw;

    if ( !w->xs_open || !w->xs_close || !w->xs_read || !w->xs_directory )
        return VMI_FAILURE;

    xen->xshandle = xen->libxsw.xs_open(0);
    if ( !xen->xshandle ) {
        errprint("Failed to open libxenstore interface.\n");
        return VMI_FAILURE;
    }

    return VMI_SUCCESS;
}
Ejemplo n.º 9
0
void *
safe_malloc_(
    size_t size,
    char const *file,
    int line)
{
    void *p = malloc(size);

    if (NULL == p) {
        errprint("malloc %lu bytes failed at %s:%d\n",
                 (unsigned long) size, file, line);
        exit(EXIT_FAILURE);
    }
    return p;
}
Ejemplo n.º 10
0
void
setov(void)
{
	register int j = 0, k;
	tchar i, delim, o[NOV];
	int w[NOV];

	if (ismot(i = getch()))
		return;
	delim = i;
	for (k = 0; (k < NOV) && (j = cbits(i = getch()), !issame(i, delim)) &&  (j != '\n'); k++) {
		o[k] = i;
		w[k] = width(i);
	}
	if (!issame(j, delim))
		nodelim(delim);
	o[k] = w[k] = 0;
	if (o[0])
		for (j = 1; j; ) {
			j = 0;
			for (k = 1; o[k] ; k++) {
				if (w[k-1] < w[k]) {
					j++;
					i = w[k];
					w[k] = w[k-1];
					w[k-1] = i;
					i = o[k];
					o[k] = o[k-1];
					o[k-1] = i;
				}
			}
		}
	else 
		return;
	pbbuf[pbp++] = makem(w[0] / 2);
	for (k = 0; o[k]; k++)
		;
	while (k>0) {
		k--;
		if (pbp >= pbsize-4)
			if (growpbbuf() == NULL) {
				errprint("no space for .ov");
				done(2);
			}
		pbbuf[pbp++] = makem(-((w[k] + w[k+1]) / 2));
		pbbuf[pbp++] = o[k];
	}
}
Ejemplo n.º 11
0
Archivo: n5.c Proyecto: aksr/heirloom
static void
open1(int flags)
{
	int	ns = nstreams;

	lgf++;
	if (skip(1) || !getname() || skip(1))
		return;
	streams = realloc(streams, sizeof *streams * ++nstreams);
	streams[ns].name = malloc(NS);
	strcpy(streams[ns].name, nextf);
	getname();
	if ((streams[ns].fd = open(nextf, flags, 0666)) < 0) {
		errprint("can't open file %s", nextf);
		done(02);
	}
}
Ejemplo n.º 12
0
status_t
read_config_ghashtable(
    vmi_instance_t vmi)
{
    status_t ret = VMI_FAILURE;
    GHashTable *configtbl = (GHashTable *)vmi->config;
    vmi->os_type = VMI_OS_UNKNOWN;

    g_hash_table_foreach(configtbl, (GHFunc)read_config_ghashtable_entries, vmi);

    if(vmi->os_type != VMI_OS_UNKNOWN) {
        ret = VMI_SUCCESS;
    } else {
        errprint("Unknown or undefined OS type!\n");
    }

    return ret;
}
Ejemplo n.º 13
0
status_t
file_get_memsize(
    vmi_instance_t vmi,
    uint64_t *size)
{
    status_t ret = VMI_FAILURE;
    struct stat s;

    if (fstat(file_get_instance(vmi)->fd, &s) == -1) {
        errprint("Failed to stat file.\n");
        goto error_exit;
    }
    *size = s.st_size;
    ret = VMI_SUCCESS;

error_exit:
    return ret;
}
Ejemplo n.º 14
0
inline font &
font_render ()
{
    static font * sp_font_renderer = nullptr;
    if (is_nullptr(sp_font_renderer))
    {
        sp_font_renderer = new font;
        if (not_nullptr(sp_font_renderer))
        {
            // sp_font_renderer->init(m_window)
        }
        else
        {
            errprint("could not create the application font object, crash!");
        }
    }
    return *sp_font_renderer;
}
Ejemplo n.º 15
0
/* finds the task struct for a given pid */
static addr_t
linux_get_taskstruct_addr_from_pid(
    vmi_instance_t vmi,
    vmi_pid_t pid)
{
    addr_t list_head = 0, next_process = 0;
    vmi_pid_t task_pid = -1;
    linux_instance_t linux_instance = NULL;
    int pid_offset = 0;
    int tasks_offset = 0;

    if (vmi->os_data == NULL) {
        errprint("VMI_ERROR: No os_data initialized\n");
        return 0;
    }

    linux_instance = vmi->os_data;

    pid_offset = linux_instance->pid_offset;
    tasks_offset = linux_instance->tasks_offset;

    /* First we need a pointer to the initial entry in the tasks list.
     * Note that this is task_struct->tasks, not the base addr
     *  of task_struct: task_struct base = $entry - tasks_offset.
     */
    next_process = vmi->init_task;
    list_head = next_process;

    do {
        vmi_read_32_va(vmi, next_process + pid_offset, 0, (uint32_t*)&task_pid);

        /* if pid matches, then we found what we want */
        if (task_pid == pid) {
            return next_process;
        }

        vmi_read_addr_va(vmi, next_process + tasks_offset, 0, &next_process);
        next_process -= tasks_offset;

        /* if we are back at the list head, we are done */
    } while(list_head != next_process);

    return 0;
}
Ejemplo n.º 16
0
/*
 * Return a status when page_info is not needed, but also use the cache,
 * which vmi_pagetable_lookup_extended() does not do.
 *
 * TODO: Should this eventually replace vmi_pagetable_lookup() in the API?
 */
status_t vmi_pagetable_lookup_cache(
    vmi_instance_t vmi,
    addr_t dtb,
    addr_t vaddr,
    addr_t *paddr)
{
    status_t ret = VMI_FAILURE;
    page_info_t info = { .vaddr = vaddr,
                         .dtb = dtb
                       };

    if(!paddr) return ret;

    *paddr = 0;

    /* check if entry exists in the cache */
    if (VMI_SUCCESS == v2p_cache_get(vmi, vaddr, dtb, paddr)) {

        /* verify that address is still valid */
        uint8_t value = 0;

        if (VMI_SUCCESS == vmi_read_8_pa(vmi, *paddr, &value)) {
            return VMI_SUCCESS;
        }
        else {
            if ( VMI_FAILURE == v2p_cache_del(vmi, vaddr, dtb) )
                return VMI_FAILURE;
        }
    }

    if(vmi->arch_interface && vmi->arch_interface->v2p) {
        ret = vmi->arch_interface->v2p(vmi, dtb, vaddr, &info);
    } else {
        errprint("Invalid paging mode during vmi_pagetable_lookup\n");
        ret = VMI_FAILURE;
    }

    /* add this to the cache */
    if (ret == VMI_SUCCESS) {
        *paddr = info.paddr;
        v2p_cache_set(vmi, vaddr, dtb, info.paddr);
    }
    return ret;
}
Ejemplo n.º 17
0
bool
midibus::init_in_sub ()
{
#ifdef SEQ64_HAVE_LIBASOUND
    int result = snd_seq_create_simple_port             /* create ports */
    (
        m_seq, "sequencer64 in",                        /* "seq24 in"   */
        SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE,
        SND_SEQ_PORT_TYPE_MIDI_GENERIC | SND_SEQ_PORT_TYPE_APPLICATION
    );
    m_local_addr_port = result;
    if (result < 0)
    {
        errprint("snd_seq_create_simple_port(write) error");
        return false;
    }
#endif
    return true;
}
Ejemplo n.º 18
0
bool
midibus::init_out_sub ()
{
#ifdef SEQ64_HAVE_LIBASOUND
    int result = snd_seq_create_simple_port             /* create ports */
    (
        m_seq, m_name.c_str(),
        SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ,
        SND_SEQ_PORT_TYPE_MIDI_GENERIC | SND_SEQ_PORT_TYPE_APPLICATION
    );
    m_local_addr_port = result;
    if (result < 0)
    {
        errprint("snd_seq_create_simple_port(write) error");
        return false;
    }
#endif
    return true;
}
Ejemplo n.º 19
0
static void do_error_with_file_and_line(const char *filename,
					const char *source_filename,
					int lineno,
					error_type type, 
					const char *format, 
					const errarg &arg1,
					const errarg &arg2,
					const errarg &arg3)
{
  int need_space = 0;
  if (program_name) {
    fprintf(stderr, "%s:", program_name);
    need_space = 1;
  }
  if (lineno >= 0 && filename != 0) {
    if (strcmp(filename, "-") == 0)
      filename = "<standard input>";
    if (source_filename != 0)
      fprintf(stderr, "%s (%s):%d:", filename, source_filename, lineno);
    else
      fprintf(stderr, "%s:%d:", filename, lineno);
    need_space = 1;
  }
  switch (type) {
  case FATAL:
    fputs("fatal error:", stderr);
    need_space = 1;
    break;
  case ERROR:
    break;
  case WARNING:
    fputs("warning:", stderr);
    need_space = 1;
    break;
  }
  if (need_space)
    fputc(' ', stderr);
  errprint(format, arg1, arg2, arg3);
  fputc('\n', stderr);
  fflush(stderr);
  if (type == FATAL)
    fatal_error_exit();
}
Ejemplo n.º 20
0
static status_t
set_driver_type(
    vmi_instance_t vmi,
    vmi_mode_t mode,
    uint64_t id,
    const char *name)
{
    if (VMI_AUTO == mode) {
        if (VMI_FAILURE == driver_init_mode(vmi, id, name)) {
            errprint("Failed to identify correct mode.\n");
            return VMI_FAILURE;
        }
    }
    else {
        vmi->mode = mode;
    }
    dbprint(VMI_DEBUG_CORE, "LibVMI Mode %d\n", vmi->mode);
    return VMI_SUCCESS;
}
Ejemplo n.º 21
0
status_t
file_get_memsize(
    vmi_instance_t vmi,
    uint64_t *allocated_ram_size,
    addr_t *max_physical_address)
{
    status_t ret = VMI_FAILURE;
    struct stat s;

    if (fstat(file_get_instance(vmi)->fd, &s) == -1) {
        errprint("Failed to stat file.\n");
        goto error_exit;
    }
    *allocated_ram_size = s.st_size;
    *max_physical_address = s.st_size;
    ret = VMI_SUCCESS;

error_exit:
    return ret;
}
Ejemplo n.º 22
0
status_t read_config_string(vmi_instance_t vmi,
        const char *config) {
    status_t ret = VMI_SUCCESS;
    FILE* config_file = NULL;

    if (config == NULL) {
        errprint("VMI_ERROR: NULL string passed for VMI_CONFIG_STRING\n");
        return VMI_FAILURE;
    }

    int length = snprintf(NULL, 0, "%s %s", vmi->image_type, config) + 1;
    char *config_str = g_malloc0(length);

    sprintf(config_str, "%s %s", vmi->image_type, config);

    config_file = fmemopen(config_str, length, "r");
    ret = read_config_file(vmi, config_file);

    free(config_str);

    return ret;
}
Ejemplo n.º 23
0
bool midibus::init_out ()
{

#ifdef HAVE_LIBASOUND

    int result = snd_seq_create_simple_port         /* create ports */
                 (
                     m_seq,
                     m_name.c_str(),
                     SND_SEQ_PORT_CAP_NO_EXPORT | SND_SEQ_PORT_CAP_READ,
                     SND_SEQ_PORT_TYPE_MIDI_GENERIC | SND_SEQ_PORT_TYPE_APPLICATION
                 );
    m_local_addr_port = result;

    if (result < 0)
    {
        errprint("snd_seq_create_simple_port(write) error");
        return false;
    }
    result = snd_seq_connect_to                     /* connect to port */
             (
                 m_seq, m_local_addr_port, m_dest_addr_client, m_dest_addr_port
             );
    if (result < 0)
    {
        fprintf
        (
            stderr,
            "snd_seq_connect_to(%d:%d) error\n",
            m_dest_addr_client, m_dest_addr_port
        );
        return false;
    }

#endif  // HAVE_LIBASOUND

    return true;
}
Ejemplo n.º 24
0
int
main(int argc, char **argv)
{
	FILS	fstr[NFILES];
	int	nfdone = 0;


	/* Get locale variables for environment */
	(void) setlocale(LC_ALL, "");

#if !defined(TEXT_DOMAIN)	/* Should be defined by cc -D */
#define	TEXT_DOMAIN "SYS_TEST"	/* Use this only if it weren't */
#endif
	(void) textdomain(TEXT_DOMAIN);

	mbcurmax = MB_CUR_MAX;
	Files = fstr;
	for (argc = findopt(argc, argv); argc > 0; --argc, ++argv) {
		if (Multi == 'm') {
			if (Nfiles >= NFILES - 1) die("too many files");
			if (mustopen(*argv, &Files[Nfiles++]) == NULL)
				++nfdone;	/* suppress printing */
		} else {
			if (print(*argv))
				(void) fclose(Files->f_f);
			++nfdone;
		}
	}
	if (!nfdone)	/* no files named, use stdin */
		(void) print(NOFILE);	/* on GCOS, use current file, if any */

	if (Report) {
		errprint();	/* print accumulated error reports */
		exit(Error);
	}

	return (Error);
}
Ejemplo n.º 25
0
static int
getlig(struct mfile *mp, int warn)	/* pick up ligature list */
{
	int lig;
	char *temp;

	lig = 0;
	while ((temp = sget(mp)) != NULL && strcmp(temp, "0") != 0) {
		if (strcmp(temp, "fi") == 0)
			lig |= LFI;
		else if (strcmp(temp, "fl") == 0)
			lig |= LFL;
		else if (strcmp(temp, "ff") == 0)
			lig |= LFF;
		else if (strcmp(temp, "ffi") == 0)
			lig |= LFFI;
		else if (strcmp(temp, "ffl") == 0)
			lig |= LFFL;
		else if (warn)
			errprint("illegal ligature %s\n", temp);
	}
	skipline(mp);
	return lig;
}
Ejemplo n.º 26
0
Archivo: core.c Proyecto: kittel/libvmi
uint64_t linux_get_offset(vmi_instance_t vmi, const char* offset_name) {
    const size_t max_length = 100;
    linux_instance_t linux_instance = vmi->os_data;

    if (linux_instance == NULL) {
        errprint("VMI_ERROR: OS instance not initialized\n");
        return 0;
    }

    if (strncmp(offset_name, "linux_tasks", max_length) == 0) {
        return linux_instance->tasks_offset;
    } else if (strncmp(offset_name, "linux_mm", max_length) == 0) {
        return linux_instance->mm_offset;
    } else if (strncmp(offset_name, "linux_pid", max_length) == 0) {
        return linux_instance->pid_offset;
    } else if (strncmp(offset_name, "linux_name", max_length) == 0) {
        return linux_instance->name_offset;
    } else if (strncmp(offset_name, "linux_pgd", max_length) == 0) {
        return linux_instance->pgd_offset;
    } else {
        warnprint("Invalid offset name in linux_get_offset (%s).\n", offset_name);
        return 0;
    }
}
Ejemplo n.º 27
0
Archivo: pr.c Proyecto: 00001/plan9port
void
main(int argc, char *argv[])
{
	Fils fstr[NFILES];
	int nfdone = 0;

	Binit(&bout, 1, OWRITE);
	Files = fstr;
	for(argc = findopt(argc, argv); argc > 0; --argc, ++argv)
		if(Multi == 'm') {
			if(Nfiles >= NFILES - 1)
				die("too many files");
			if(mustopen(*argv, &Files[Nfiles++]) == 0)
				nfdone++; /* suppress printing */
		} else {
			if(pr(*argv))
				Bterm(Files->f_f);
			nfdone++;
		}
	if(!nfdone)			/* no files named, use stdin */
		pr(nulls);		/* on GCOS, use current file, if any */
	errprint();			/* print accumulated error reports */
	exits(error? "error": 0);
}
Ejemplo n.º 28
0
/*
 * check that this vm uses a paging method that we support
 * and set pm/cr3/pae/pse/lme flags optionally on the given pointers
 */
status_t probe_memory_layout_x86(vmi_instance_t vmi) {
    // To get the paging layout, the following bits are needed:
    // 1. CR0.PG
    // 2. CR4.PAE
    // 3. Either (a) IA32_EFER.LME, or (b) the guest's address width (32 or
    //    64). Not all backends allow us to read an MSR; in particular, Xen's PV
    //    backend doessn't.

    status_t ret = VMI_FAILURE;
    page_mode_t pm = VMI_PM_UNKNOWN;
    uint8_t dom_addr_width = 0; // domain address width (bytes)

    /* pull info from registers, if we can */
    reg_t cr0, cr3, cr4, efer;
    int pae = 0, pse = 0, lme = 0;
    uint8_t msr_efer_lme = 0;   // LME bit in MSR_EFER

    /* get the control register values */
    if (driver_get_vcpureg(vmi, &cr0, CR0, 0) == VMI_FAILURE) {
        errprint("**failed to get CR0\n");
        goto _exit;
    }

    /* PG Flag --> CR0, bit 31 == 1 --> paging enabled */
    if (!VMI_GET_BIT(cr0, 31)) {
        dbprint(VMI_DEBUG_CORE, "Paging disabled for this VM, only physical addresses supported.\n");
        vmi->page_mode = VMI_PM_UNKNOWN;
        vmi->pae = 0;
        vmi->pse = 0;
        vmi->lme = 0;

        ret = VMI_SUCCESS;
        goto _exit;
    }

    //
    // Paging enabled (PG==1)
    //
    if (driver_get_vcpureg(vmi, &cr4, CR4, 0) == VMI_FAILURE) {
        errprint("**failed to get CR4\n");
        goto _exit;
    }

    /* PSE Flag --> CR4, bit 5 */
    pae = VMI_GET_BIT(cr4, 5);
    dbprint(VMI_DEBUG_CORE, "**set pae = %d\n", pae);

    /* PSE Flag --> CR4, bit 4 */
    pse = VMI_GET_BIT(cr4, 4);
    dbprint(VMI_DEBUG_CORE, "**set pse = %d\n", pse);

    ret = driver_get_vcpureg(vmi, &efer, MSR_EFER, 0);
    if (VMI_SUCCESS == ret) {
        lme = VMI_GET_BIT(efer, 8);
        dbprint(VMI_DEBUG_CORE, "**set lme = %d\n", lme);
    } else {
        dbprint(VMI_DEBUG_CORE, "**failed to get MSR_EFER, trying method #2\n");

        // does this trick work in all cases?
        ret = driver_get_address_width(vmi, &dom_addr_width);
        if (VMI_FAILURE == ret) {
            errprint
                ("Failed to get domain address width. Giving up.\n");
            goto _exit;
        }
        lme = (8 == dom_addr_width);
        dbprint
            (VMI_DEBUG_CORE, "**found guest address width is %d bytes; assuming IA32_EFER.LME = %d\n",
             dom_addr_width, lme);
    }   // if
    // Get current cr3 for sanity checking
    if (driver_get_vcpureg(vmi, &cr3, CR3, 0) == VMI_FAILURE) {
        errprint("**failed to get CR3\n");
        goto _exit;
    }

    // now determine addressing mode
    if (0 == pae) {
        dbprint(VMI_DEBUG_CORE, "**32-bit paging\n");
        pm = VMI_PM_LEGACY;
        cr3 &= 0xFFFFF000ull;
    }
    // PAE == 1; determine IA-32e or PAE
    else if (lme) {    // PAE == 1, LME == 1
        dbprint(VMI_DEBUG_CORE, "**IA-32e paging\n");
        pm = VMI_PM_IA32E;
        cr3 &= 0xFFFFFFFFFFFFF000ull;
    } else {  // PAE == 1, LME == 0
        dbprint(VMI_DEBUG_CORE, "**PAE paging\n");
        pm = VMI_PM_PAE;
        cr3 &= 0xFFFFFFE0;
    }   // if-else
    dbprint(VMI_DEBUG_CORE, "**sanity checking cr3 = 0x%.16"PRIx64"\n", cr3);

    /* testing to see CR3 value */
    if (!driver_is_pv(vmi) && cr3 >= vmi->max_physical_address) {   // sanity check on CR3
        dbprint(VMI_DEBUG_CORE, "** Note cr3 value [0x%"PRIx64"] exceeds memsize [0x%"PRIx64"]\n",
                cr3, vmi->size);
    }

    vmi->page_mode = pm;
    vmi->pae = pae;
    vmi->pse = pse;
    vmi->lme = lme;

_exit:
    return ret;
}
Ejemplo n.º 29
0
int main(int argc, char **argv)
{
	jas_image_t *image;
	cmdopts_t *cmdopts;
	jas_stream_t *in;
	jas_stream_t *out;
	clock_t startclk;
	clock_t endclk;
	long dectime;
	long enctime;
	int_fast16_t numcmpts;
	int i;

	/* Determine the base name of this command. */
	if ((cmdname = strrchr(argv[0], '/'))) {
		++cmdname;
	} else {
		cmdname = argv[0];
	}

	if (jas_init()) {
		errprint(0, "error: cannot initialize jasper library\n");
		abort();
	}

	/* set our error callback */
	jas_set_error_cb(errprint);

	/* Parse the command line options. */
	if (!(cmdopts = cmdopts_parse(argc, argv))) {
		jas_eprintf("error: cannot parse command line\n");
		exit(EXIT_FAILURE);
	}

	if (cmdopts->version) {
		jas_eprintf("%s\n", JAS_VERSION);
		jas_eprintf("libjasper %s\n", jas_getversion());
		exit(EXIT_SUCCESS);
	}

	jas_setdbglevel(cmdopts->debug);

	if (cmdopts->verbose) {
		cmdinfo();
	}

	/* Open the input image file. */
	if (cmdopts->infile) {
		/* The input image is to be read from a file. */
		if (!(in = jas_stream_fopen(cmdopts->infile, "rb"))) {
			jas_eprintf("error: cannot open input image file %s\n",
			  cmdopts->infile);
			exit(EXIT_FAILURE);
		}
	} else {
		/* The input image is to be read from standard input. */
		if (!(in = jas_stream_fdopen(0, "rb"))) {
			jas_eprintf("error: cannot open standard input\n");
			exit(EXIT_FAILURE);
		}
	}

	/* Open the output image file. */
	if (cmdopts->outfile) {
		/* The output image is to be written to a file. */
		if (!(out = jas_stream_fopen(cmdopts->outfile, "w+b"))) {
			jas_eprintf("error: cannot open output image file %s\n",
			  cmdopts->outfile);
			exit(EXIT_FAILURE);
		}
	} else {
		/* The output image is to be written to standard output. */
		if (!(out = jas_stream_fdopen(1, "w+b"))) {
			jas_eprintf("error: cannot open standard output\n");
			exit(EXIT_FAILURE);
		}
	}

	if (cmdopts->infmt < 0) {
		if ((cmdopts->infmt = jas_image_getfmt(in)) < 0) {
			jas_eprintf("error: input image has unknown format\n");
			exit(EXIT_FAILURE);
		}
	}

	/* Get the input image data. */
	startclk = clock();
	if (!(image = jas_image_decode(in, cmdopts->infmt, cmdopts->inopts))) {
		jas_eprintf("error: cannot load image data\n");
		exit(EXIT_FAILURE);
	}
	endclk = clock();
	dectime = endclk - startclk;

	/* If requested, throw away all of the components except one.
	  Why might this be desirable?  It is a hack, really.
	  None of the image formats other than the JPEG-2000 ones support
	  images with two, four, five, or more components.  This hack
	  allows such images to be decoded with the non-JPEG-2000 decoders,
	  one component at a time. */
	numcmpts = jas_image_numcmpts(image);
	if (cmdopts->cmptno >= 0 && cmdopts->cmptno < numcmpts) {
		for (i = numcmpts - 1; i >= 0; --i) {
			if (i != cmdopts->cmptno) {
				jas_image_delcmpt(image, i);
			}
		}
	}

	if (cmdopts->srgb) {
		jas_image_t *newimage;
		jas_cmprof_t *outprof;
		jas_eprintf("forcing conversion to sRGB\n");
		if (!(outprof = jas_cmprof_createfromclrspc(JAS_CLRSPC_SRGB))) {
			jas_eprintf("cannot create sRGB profile\n");
			exit(EXIT_FAILURE);
		}
		if (!(newimage = jas_image_chclrspc(image, outprof, JAS_CMXFORM_INTENT_PER))) {
			jas_eprintf("cannot convert to sRGB\n");
			exit(EXIT_FAILURE);
		}
		jas_image_destroy(image);
		jas_cmprof_destroy(outprof);
		image = newimage;
	}

	/* Generate the output image data. */
	startclk = clock();
	if (jas_image_encode(image, out, cmdopts->outfmt, cmdopts->outopts)) {
		jas_eprintf("error: cannot encode image\n");
		exit(EXIT_FAILURE);
	}
	jas_stream_flush(out);
	endclk = clock();
	enctime = endclk - startclk;

	if (cmdopts->verbose) {
		jas_eprintf("decoding time = %f\n", dectime / (double)
		  CLOCKS_PER_SEC);
		jas_eprintf("encoding time = %f\n", enctime / (double)
		  CLOCKS_PER_SEC);
	}

	/* If this fails, we don't care. */
	(void) jas_stream_close(in);

	/* Close the output image stream. */
	if (jas_stream_close(out)) {
		jas_eprintf("error: cannot close output image file\n");
		exit(EXIT_FAILURE);
	}

	cmdopts_destroy(cmdopts);
	jas_image_destroy(image);
	jas_image_clearfmts();

	/* Success at last! :-) */
	return EXIT_SUCCESS;
}
Ejemplo n.º 30
0
command()
{
double tval;
int i,echeck;
int pmin,pmax,pstep;

while (echeck = getstring(": ")) {
	if (echeck == EOF) {
		fileinput(EOF);
	}
	else if (in[0] == '\0') {
		errprint("");
	}
	else if (startsame(in,"cycle")) {
		cycle();
	}
	else if (startsame(in,"clear")) {
		clear();
	}
	else if (startsame(in,"coarticulation")) {
		getint(&coartflag);
	}
	else if (startsame(in,"rc")) {
		zarrays();
		cycle();
	}
	else if (startsame(in,"wordacts")) {
		scr_words(printmin,printmax,3,0,"MAX");
	}
	else if (startsame(in,"wtacts")) {
		scr_words(printmin,printmax,3,0,"ALL");
	}
	else if (startsame(in,"owtacts")) {
		getstring("word: ");
		scr_words(printmin,printmax,3,0,in);
	}
	else if (startsame(in,"phonacts")) {
		scr_phonemes(printmin,printmax,3,0);
	}
	else if (startsame(in,"featacts")) {
		scr_features();
	}
	else if (startsame(in,"sfeatacts")) {
		getstring("fname: ");
		sfeatacts(in);
	}
	else if (startsame(in,"memo")) {
		getstring("string: ");
		strcpy(memo,in);
	}
	else if (startsame(in,"expr")) {
		setex();
	}
	else if (startsame(in,"fcopt")) {
	    getint(&fcflag);
	}
	else if (startsame(in,"fpcyc")) {
	    getint(&fpcyc);
	}
	else if (startsame(in,"finput")) {
		fileinput(NONSTD);
	}
	else if (startsame(in,"inoise")) {
		getval(&inoise);
	}
	else if (startsame(in,"inspecs")) {
		getstring("File name (- = stdin): ");
		inspecs(in);
	}
	else if (startsame(in,"infeatures")) {
		getstring("File name: ");
		infeats(in);
	}
	/* NOT PRESENTLY OPERATIVE -- JLM 10-5-82
	else if (startsame(in,"wsubset")) {
		wordsubset();
	}
	*/
	else if (startsame(in,"test")) {
		getstring("test string: ");
		strcpy(memo,in);
		test(in);
	}
	else if (startsame(in,"topdown")) {
		topdown();
	}
	else if (startsame(in,"output")) {
		setout();
	}
	else if (startsame(in,"ofile")) {
		getstring("give filename (or - for none): ");
		setoutfile(in);
	}
	else if (in[0] == '?') {
		help();
	}
	else if (startsame(in,"help")) {
		help();
	}
	else if (startsame(in,"lexicon")) {
		getlex();
	}
	else if (startsame(in,"params")) {
		getpars();
	}
	else if (startsame(in,"quit")) {
		quit();
	}
	else if (startsame(in,"decay")) {
		getdouble(decay,NLEVS,levlabs);
	}
	else if (startsame(in,"alpha")) {
		getdouble(alpha,NPARAMS,conlabs);
	}
	else if (startsame(in,"gamma")) {
		getdouble(ga,NLEVS,levlabs);
	}
	else if (startsame(in,"grace")) {
		getint(&grace);
	}
	else if (startsame(in,"rest")) {
		tval = rest[W];
		getdouble(rest,NLEVS,levlabs);
		if (tval != rest[W]) {
			initialize();
		}
	}
	else if (startsame(in,"fweight")) {
		getdouble(fweight,NCONTINS,contname);
	}
	else if (startsame(in,"pthresh")) {
		getdouble(pthresh,NLEVS,levlabs);
	}
	else if (startsame(in,"ngraph")) {
		newgraph(pmin,ng_max,pstep);
	}
	else if (startsame(in,"ngmax")) {
		getint(&ng_max);
	}
	else if (startsame(in,"ngwscale")) {
		getval(&ng_wscale);
	}
	else if (startsame(in,"ngsscale")) {
		getval(&ng_sscale);
	}
	else if (startsame(in,"ngpscale")) {
		getval(&ng_pscale);
	}
	else if (startsame(in,"nreps")) {
		getint(&nreps);
	}
	else if (startsame(in,"pfreq")) {
		getint(&printfreq);
	}
	else if (startsame(in,"rarate")) {
		getval(&rarate);
	}
	else if (startsame(in,"sumpr")) {
		scr_sum(pmin,pmax,pstep);
	}
	else if (startsame(in,"sinspec")) {
		sinspec();
	}
	else if (startsame(in,"sfeatures")) {
		getstring("Filename: ");
		sfeatures(in);
	}
	else if (startsame(in,"dinspec")) {
		dinspec();
	}
	else if (startsame(in,"sumopt")) {
	    getint(&sumflag);
	}
	else if (startsame(in,"pmin")) {
		getint(&pmin);
	}
	else if (startsame(in,"pmax")) {
		getint(&pmax);
	}
	else if (startsame(in,"pstep")) {
		getint(&pstep);
	}
	else if (startsame(in,"min")) {
		getval(&min);
	}
	else if (startsame(in,"max")) {
		getval(&max);
	}
	else if (startsame(in,"windowcent")) {
		getval(&windowcent);
	}
	else if (startsame(in,"wbase")) {
		getval(&wbase);
	}
	else if (startsame(in,"wgraph")) {
		wgraph(pmin,ng_max,pstep);
	}
	else if (startsame(in,"wchange")) {
		getval(&wchange);
	}
	else if (startsame(in,"wgain")) {
		getval(&wgain);
	}
	else if (startsame(in,"wramp")) {
		getval(&wramp);
	}
	else if (startsame(in,"imax")) {
		getval(&imax);
	}
	else if (startsame(in,"sscale")) {
		getval(&sscale);
	}
	else if (startsame(in,"nsscale")) {
		getval(&nsscale);
	}
	else if (startsame(in,"freqscale")) {
		tval = fscale;
		getval(&fscale);
		if (tval != fscale) {
		    initialize();
		}
	}
	else if (startsame(in,"abort")) {
		abort();	/* to get a core dump for sdb */
	}
	else {
		errprint("Unrecognized request: For help type ?.");
		if (infp != stdin) fileinput(STD);
	}
	wait(0);
}
}