Exemple #1
0
void l4x_vmalloc_unmap_vm_area(unsigned long address, unsigned long end)
{
	if (address & ~PAGE_MASK)
		enter_kdebug("unmap_vm_area: Unaligned address!");

	for (; address < end; address += PAGE_SIZE) {

#ifdef CONFIG_ARM
		unsigned long o;
		if ((o = l4x_arm_is_selfmapped_addr(address))) {
			address += o - PAGE_SIZE;
			continue;
		}
#endif

		/* check whether we are really flushing a vm page */
		if (address < (unsigned long)high_memory
#if defined(CONFIG_X86_64) || defined(CONFIG_ARM)
		    && !(address >= MODULES_VADDR && address < MODULES_END)
#endif
		    ) {
			printk("flushing wrong page, addr: %lx\n", address);
			enter_kdebug("l4x_vmalloc_unmap_vm_area");
			continue;
		}
		l4x_virtual_mem_unregister(address);
		l4lx_memory_unmap_virtual_page(address);
	}
}
Exemple #2
0
int smp_delete_all_threads(space_t * space)
{
    //IPI_PRINTF("%s (%x)\n", __FUNCTION__, victim);
    cpu_mailbox_t * mailbox = get_mailbox();
    for (dword_t cpu = 0; cpu < CONFIG_SMP_MAX_CPU; cpu++)
    {
	if (cpu == get_cpu_id())
	    continue;
	if (!is_cpu_online(cpu))
	    continue;

	mailbox->param[0] = (dword_t)space;
	dword_t status = mailbox->send_command(cpu, SMP_CMD_DELETE_ALL_THREADS);
	switch(status)
	{
	case MAILBOX_OK:
	    return 1;
	case MAILBOX_UNWIND_REMOTE:
	    /* we have to perform a remote unwind */
	    IPI_PRINTF("%s: remote unwind %x\n", mailbox->tcb);
	    unwind_ipc(mailbox->tcb);
	    break;
	case MAILBOX_ERROR:
	    enter_kdebug("smp_delete_task: error deleting task");
	    break;
	default:
	    enter_kdebug("smp_delete_task: unexpected return value");
	    break;
	}
    }
    return 0;
}
Exemple #3
0
static Region_map *vrm_determine_local_rm_address()
{
    /*
     * Determine the address of the RE kernel's local RM.
     */

    /*
     * 1. Try to find symbol in ELF image file
     */
    if (dbg_elf) VG_(printf)("opening rom/l4re\n");
    SysRes res = VG_(open)((const Char*)"rom/l4re", VKI_O_RDONLY, 0);
    if (dbg_elf) VG_(printf)("opened: %ld\n", sr_Res(res));
    if (sr_isError(res)) {
        VG_(printf)("Error opening file: %ld\n", sr_Err(res));
        enter_kdebug();
    }

    int fd = sr_Res(res);

    struct vg_stat statbuf;
    int err = VG_(fstat)(fd, &statbuf);
    if (dbg_elf) VG_(printf)("stat: %d, size %d\n", err, (int)statbuf.size);

    if (err) {
        VG_(printf)("error on fstat(): %d\n", err);
        enter_kdebug();
    }

    void *a = 0;
    a = mmap(a, statbuf.size, VKI_PROT_READ, VKI_MAP_PRIVATE, fd, 0);
    if (dbg_elf) VG_(printf)("mmap to %p\n", a);

    melf_global_elf_info i;
    err = melf_parse_elf(a, &i);
    if (dbg_elf) VG_(printf)("parsed: %d\n", err);

    char *rm_addr = melf_find_symbol_by_name(&i, (char*)"__local_rm");
    if (dbg_elf) VG_(printf)("Found symbol %s @ %p\n", (char*)"__local_rm", rm_addr);

    munmap(a, VG_PGROUNDUP(statbuf.size));
    VG_(close)(fd);

    if (rm_addr)
        return reinterpret_cast<Region_map*>(rm_addr);

    /*
     * 2. If not successful parsing binary, try hard-coded value
     */
    VG_(printf)("Did not find local-rm, aborting\n");
    VG_(exit)(1);

    /* Not found? */
}
Exemple #4
0
IDL4_INLINE CORBA_long directory_resolve_implementation(CORBA_Object _caller, CORBA_long objID, CORBA_long size, CORBA_char *name, l4_threadid_t *dsvrID, CORBA_long *dobjID, idl4_server_environment *_env)

{
  int pos;

  if (size>256) size=256;
/**/  if (size<0) enter_kdebug("too small");
  name[size]=0;

  #ifdef DEBUG
  printf("%X resolved %s[%d] in %d",_caller.raw,name,size,objID);
  #endif

  if ((objID>=MAXDIRS) || (!directory[objID].active))
    return ESUPP;
  
  #ifdef DEBUG
  printf(", which is active");
  #endif
    
  pos=directory[objID].first_child;
  while ((pos>=0) && (strcmp(nameslot[pos].ascii,name)))
    pos=nameslot[pos].next_peer;
      
  if (pos<0)    
    return ENOTFOUND;
    
  #ifdef DEBUG
  printf(", to <%X,%d>\n",nameslot[pos].svrID.raw,nameslot[pos].objID);
  #endif  
    
  *dsvrID=nameslot[pos].svrID;
  *dobjID=nameslot[pos].objID;
  return ESUCCESS;
}
Exemple #5
0
void l4x_vmalloc_map_vm_area(unsigned long address, unsigned long end)
{
	if (address & ~PAGE_MASK)
		enter_kdebug("map_vm_area: Unaligned address!");

	for (; address < end; address += PAGE_SIZE) {
		pte_t *ptep;

#ifdef ARCH_arm
		unsigned long o;
		if ((o = l4x_arm_is_selfmapped_addr(address))) {
			address += o - PAGE_SIZE;
			continue;
		}
#endif

		ptep = lookup_pte(swapper_pg_dir, address);

		if (!ptep || !pte_present(*ptep)) {
			if (0)
				printk("%s: No (valid) PTE for %08lx?!"
			               " (ptep: %p, pte: %08"
#ifndef ARCH_arm
				       "l"
#endif
				       "x\n",
			               __func__, address,
			               ptep, pte_val(*ptep));
			continue;
		}
		l4x_virtual_mem_register(address, pte_val(*ptep));
		l4lx_memory_map_virtual_page(address, pte_val(*ptep),
		                             pte_write(*ptep));
	}
}
Exemple #6
0
pte_t *
lookup_pte(pgd_t *page_dir, unsigned long pf_address)
{
	/*
	 * find the page table entry within the page table hierarchy
	 */
	pte_t *pte = NULL;
	pgd_t *pgd = page_dir + pgd_index(pf_address);

#ifdef DEBUG_LOOKUP_PTABS
	if ((int)page_dir < 0x1000) {
		printk("%s: page_dir=%x\n", __func__, (int)page_dir);
		enter_kdebug("page_dir<4096");
	}
	printk("%s: %lx pdir = %p\n", __func__, pf_address, pgd);
#endif
	if (pgd_present(*pgd)) {
		pmd_t *pmd = pmd_offset(pgd, pf_address);
#ifdef DEBUG_LOOKUP_PTABS
		printk("pgd_present(*%x) is true\n", pgd);
		printk(" pmd = %p\n", pmd);
#endif
		if (pmd_present(*pmd)) {
#ifdef DEBUG_LOOKUP_PTABS
			printk("pmd_present(*%x) is true\n", pmd);
#endif
			pte = pte_offset_map(pmd, pf_address);
		}
	}
#ifdef DEBUG_LOOKUP_PTABS
	printk("returning:  pte = %p\n", pte);
#endif
	return pte;
}
Exemple #7
0
void kdebug_check_breakin()
{
    if ((inb(COMPORT+5) & 0x01))
    {
	if (inb(COMPORT) == 0x1b)
	    enter_kdebug("breakin");
    }
}
Exemple #8
0
void l4x_vmalloc_map_vm_area(unsigned long address, unsigned long end)
{
	if (address & ~PAGE_MASK)
		enter_kdebug("map_vm_area: Unaligned address!");

	if (!(   (VMALLOC_START <= address && end <= VMALLOC_END)
	      || (MODULES_VADDR <= address && end <= MODULES_END))) {
		pr_err("%s: %lx-%lx outside areas: %lx-%lx, %lx-%lx\n",
		       __func__, address, end,
		       VMALLOC_START, VMALLOC_END, MODULES_VADDR, MODULES_END);
		pr_err("%s: %p\n", __func__, __builtin_return_address(0));
		enter_kdebug("KK");
		return;
	}

	for (; address < end; address += PAGE_SIZE) {
		pte_t *ptep;

#ifdef CONFIG_ARM
		unsigned long o;
		if ((o = l4x_arm_is_selfmapped_addr(address))) {
			address += o - PAGE_SIZE;
			continue;
		}
#endif

		ptep = lookup_pte(&init_mm, address);

		if (!ptep || !pte_present(*ptep)) {
			if (0)
				printk("%s: No (valid) PTE for %08lx?!"
			               " (ptep: %p, pte: %08"
#ifndef CONFIG_ARM
				       "l"
#endif
				       "x\n",
			               __func__, address,
			               ptep, pte_val(*ptep));
			continue;
		}
		l4x_virtual_mem_register(address, *ptep);
		l4lx_memory_map_virtual_page(address, *ptep);
	}
}
Exemple #9
0
void check_multiboot_header(dword_t mb_magic, multiboot_info **mbi)

{
  // *** Find the multiboot header and check sanity. If the header was not
  //     passed in correctly via parameters, try 1M

  if (mb_magic != MULTIBOOT_VALID) 
    {
      mb_magic = *(dword_t *) (1024*1024);
      if (mb_magic == MULTIBOOT_VALID) 
        *mbi = (multiboot_info *)(*(dword_t *)(1024*1024 + 4));
        else enter_kdebug("Failed to find a multiboot header");
    } 

  #ifdef PEDANTIC
  if (!((*mbi)->flags & MB_INFO_MODS))
    enter_kdebug("WARNING: Incorrect flags in multiboot header");
  #endif    
}    
Exemple #10
0
unsigned long get_cpu_khz (void) {
  l4_kernel_info_t *kip = l4re_kip(); 

  if(kip)
    return kip->frequency_cpu;
  else {
    printf("Can't map KIP to local place.\n");
    enter_kdebug("KIP failed");
  }

  return 0;
}
Exemple #11
0
void l4lx_thread_stack_register(l4_cap_idx_t thread, void *stack_pointer)
{
	/* Calculate array entry of this stack as returned by
	 * l4lx_thread_stack_get */
	int offset = (char *)stack_pointer - l4lx_thread_stacks;
	int n = (offset / L4LX_THREAD_STACK_SIZE);
	if (offset % L4LX_THREAD_STACK_SIZE == 0)
		n--;

	/* sanity check */
	if (n < 0 || n >= L4LX_THREAD_NO_THREADS)
		enter_kdebug("Wrong stack_pointer given?!");
	else
		/* eventually register it */
		l4lx_thread_stack_to_thread_no[n] = thread;
}
Exemple #12
0
void smp_flush_tlb()
{
#warning inefficient implementation of tlb shootdown
    cpu_mailbox_t * mailbox = get_mailbox();
    for (dword_t cpu = 0; cpu < CONFIG_SMP_MAX_CPU; cpu++)
    {
	if (cpu == get_cpu_id())
	    continue;
	if (!is_cpu_online(cpu))
	    continue;

	dword_t status = mailbox->send_command(cpu, SMP_CMD_FLUSH_TLB);
	if (status != MAILBOX_OK)
	    enter_kdebug("smp_flush_tlb");
    }
}
Exemple #13
0
IDL4_INLINE CORBA_long directory_link_implementation(CORBA_Object _caller, CORBA_long objID, CORBA_long size, CORBA_char *name, l4_threadid_t *dsvrID, CORBA_long dobjID, idl4_server_environment *_env)

{
  int pos=0;

  if (size>256) size=256;
  if (size<0) enter_kdebug("small2");
  name[size]=0;
  
  #ifdef DEBUG
  printf("%X is linking %s to <%X,%d> in object %d...\n",_caller.raw,name,dsvrID->raw,dobjID,objID);
  #endif  
  
  if ((objID>=MAXDIRS) || (!directory[objID].active))
    return ESUPP;
    
  if (size>=MAXLENGTH)
    return EBADPARM;
    
  pos=directory[objID].first_child;
  while ((pos>=0) && (strcmp(nameslot[pos].ascii,name)))
    pos=nameslot[pos].next_peer;
  if (pos>=0)
    return EEXISTS;

  // --- scan for an empty name slot
    
  pos=0;  
  while ((pos<MAXNAMES) && (nameslot[pos].active))
    pos++;
    
  if (pos>=MAXNAMES)
    return EFULL;

  // --- enter the name  
  
  nameslot[pos].active=1;
  nameslot[pos].next_peer=directory[objID].first_child;
  strncpy(nameslot[pos].ascii,name,size);
  nameslot[pos].ascii[size+1]=0;
  directory[objID].first_child=pos;
  nameslot[pos].svrID=*dsvrID;
  nameslot[pos].objID=dobjID;
  
  return ESUCCESS;
}
Exemple #14
0
static void log_efault(const char *str, const void *user_addr,
                       const void *kernel_addr, unsigned long size)
{
    pte_t *ptep = lookup_pte((pgd_t *)current->mm->pgd,
                             (unsigned long)user_addr);

    printk("%s returning efault, \n"
           "  user_addr: %p, kernel_addr: %p, size: %08lx\n"
           "  task: %s (%p) " PRINTF_L4TASK_FORM
           ", pdir: %p, ptep: %p, pte: %lx\n",
           str, user_addr, kernel_addr, size,
           current->comm, current,
           PRINTF_L4TASK_ARG(current->thread.user_thread_id),
           current->mm->pgd, ptep, ptep ? pte_val(*ptep) : 0);
#ifdef DEBUG_KDEBUG_EFAULT
    enter_kdebug("log_efault");
#endif
}
Exemple #15
0
/* Pull down the entire world */
void VG_(exit)( Int status )
{
#if defined(VGO_linux)
   (void)VG_(do_syscall1)(__NR_exit_group, status );
#elif defined(VGO_aix5) || defined(VGO_darwin)
   (void)VG_(do_syscall1)(__NR_exit, status );
#elif defined(VGO_l4re)
   VG_(printf)("Valgrind exitting. Status = %lx\n", status);
   enter_kdebug("VG_(exit)");
   l4_sleep_forever();
#else
#  error Unknown OS
#endif
   /*NOTREACHED*/
   // We really shouldn't reach here.  Just in case we do, use some very crude
   // methods to force abort
   __builtin_trap();
   *(volatile Int*)0 = 'x';
}
Exemple #16
0
void booter_server()

{
    unsigned int msgdope, dummy, fnr, reply, w0, w1, w2;
    l4_threadid_t partner;
    struct {
        unsigned int stack[768];
        l4_fpage_t rcv_window;
        unsigned int size_dope;
        unsigned int send_dope;
        unsigned int message[BOOTER_MSGBUF_SIZE];
        idl4_strdope_t str[BOOTER_STRBUF_SIZE];
    } buffer;

    for (w0 = 0; w0 < BOOTER_STRBUF_SIZE; w0++)
    {
        buffer.str[w0].rcv_addr = malloc(8000);
        buffer.str[w0].rcv_size = 8000;
    }

    while (1)
    {
        buffer.size_dope = BOOTER_RCV_DOPE;
        buffer.rcv_window = idl4_nilpage;
        partner = idl4_nilthread;
        reply = idl4_nil;
        w0 = w1 = w2 = 0;

        while (1)
        {
            idl4_reply_and_wait(reply, buffer, partner, msgdope, fnr, w0, w1, w2, dummy);

            if (msgdope & 0xF0)
                break;

            idl4_process_request(booter_itable[(fnr >> IDL4_FID_BITS) & BOOTER_IID_MASK], fnr & BOOTER_FID_MASK, reply, buffer, partner, w0, w1, w2, dummy);
        }

        enter_kdebug("message error");
    }
}
Exemple #17
0
INLINE void transfer_message(tcb_t* const from, tcb_t* const to, const dword_t snd_desc)
{
    
    /* UD: use temporary variables to give gcc a hint
           to->ipc_buffer = from->ipc_buffer resulted in only one register
	   being used for all three dwords -> stalls	*/
    dword_t w0, w1, w2;
    w0 = from->ipc_buffer[0];
    w1 = from->ipc_buffer[1];
    w2 = from->ipc_buffer[2];
    to->ipc_buffer[0] = w0;
    to->ipc_buffer[1] = w1;
    to->ipc_buffer[2] = w2;

#if 1
#warning REVIEWME: p-bit
	/* What's up with the p-bit?? We don't support autopropagation,
	   but we can't simply assume the bit to be zero !!! */
#else
    if (snd_desc & 1)
	enter_kdebug("propagate");
#endif

    /* IPC optimization - register ipc. */
    if (EXPECT_FALSE( snd_desc & ~0x1 ))
    {
	/*
	 * Make sure that we are marked as doing IPC (in case we are
	 * descheduled).  Also set the SENDING_IPC flag while we are
	 * in the send phase.
	 */
	from->thread_state = TS_LOCKED_RUNNING;
	from->flags |= TF_SENDING_IPC;
	extended_transfer(from, to, snd_desc);
	from->thread_state = TS_RUNNING;
	from->flags &= ~TF_SENDING_IPC;
    }
    else
	to->msg_desc = 0;
}
Exemple #18
0
int main(int argc, char **argv)
{
	(void)argc; (void)argv;

	pthread_t pt;
	printf("\033[32mhello from main thread\033[0m\n");

	int res = pthread_create(&pt, NULL, thread, NULL);
	assert(res == 0);

	for (unsigned i = 0; i < 5; ++i) {
	//while (1) {
		printf("\033[32mhello world from main\033[0m\n");
		sleep(1);
	}

	pthread_join(pt, NULL);

	enter_kdebug("before return");

	return 0;
}
Exemple #19
0
void dispatch_thread(tcb_t * tcb)
{
    tcb_t * current = get_current_tcb();

    if (tcb == current)
	return;

    if (tcb == get_idle_tcb()) {
	printf("dispatch: switch to idle, current=%x, state=%x\n", 
	       current, current->thread_state);
	enter_kdebug("dispatch: switch to idle");
	switch_to_idle(current);
	return;
    }

    //printf("dispatch: %p -> %p\n", current, tcb);
    /* Do not insert TCBS not in the ready queue into the prio_queue */
    if (tcb->queue_state & TS_QUEUE_READY)
	prio_queue[tcb->priority] = tcb;

    //printf("switch_to %x->%x (%x)\n", current, tcb, tcb->thread_state);
    switch_to_thread(tcb, current);
}
Exemple #20
0
dword_t cpu_mailbox_t::send_command(dword_t cpu, dword_t command, dword_t value)
{
    int count = MAILBOX_TIMEOUT;
    m_status = value;
    m_command = command;

    /* signal the request */
    cpu_mailbox[cpu].set_request(get_cpu_id());

    /* send command IPI to the cpu */
    send_command_ipi(cpu);
    spin1(71);

    /* and now wait for the cpu to handle the reuqest */
    while (m_status == value) {
	spin1(70);

	if (count-- == 0)
	{
	    IPI_PRINTF("mailbox::send_command timeout - resend IPI to %d\n", cpu);
	    enter_kdebug("timeout");
	    send_command_ipi(cpu);
	    count = MAILBOX_TIMEOUT;
	}

	/* allow incoming requests from other cpus */
	if (pending_requests)
	{
	    IPI_PRINTF("mailbox::send_command incoming request\n");
	    handle_pending_requests();
	    continue;
	}

	__asm__ __volatile__ (".byte 0xf3; .byte 0x90\n");
    }
    return m_status;
}
Exemple #21
0
int smp_ex_regs(tcb_t * tcb, dword_t * uip, dword_t * usp, 
		l4_threadid_t * pager, dword_t * flags)
{
    cpu_mailbox_t * mailbox = get_mailbox();
    IPI_PRINTF("xcpu ex_regs tcb=%x ip=%x sp=%x pager=%x\n", 
	       tcb, *uip, *usp, *pager);

    mailbox->tcb = tcb;
    mailbox->param[0] = *uip;
    mailbox->param[1] = *usp;
    mailbox->tid = *pager;

    switch(mailbox->send_command(tcb->cpu, SMP_CMD_THREAD_EX_REGS))
    {
    case MAILBOX_ERROR:
	IPI_PRINTF("xcpu ex_regs failed\n");
	return 0;
    case MAILBOX_UNWIND_REMOTE:
	enter_kdebug("smp_ex_regs unwind remote");
	*uip = mailbox->param[0];
	*usp = mailbox->param[1];
	*flags = mailbox->param[3];
	*pager = mailbox->tid;
	unwind_ipc(mailbox->tcb);
	return 1;
    case MAILBOX_OK:
	IPI_PRINTF("xcpu ex_regs done\n");
	*uip = mailbox->param[0];
	*usp = mailbox->param[1];
	*flags = mailbox->param[3];
	*pager = mailbox->tid;
	return 1;
    default:
	printf("smp_ex_regs: unknown response\n");
    }
    return 0;
}
Exemple #22
0
int smp_unwind_ipc(tcb_t * tcb)
{
    IPI_PRINTF("smp_unwind_ipc(%x), partner=%x, current=%x, xcpu_mb=%x\n", 
	   tcb, tcb->partner, get_current_tcb(), xcpu_unwind_mailbox);
    /* check if we are already performing an unwind ipc operation */
    if (xcpu_unwind_mailbox)
    {
	xcpu_unwind_mailbox->tcb = tcb;
	xcpu_unwind_mailbox->set_status(MAILBOX_UNWIND_REMOTE);
	return 1;
    }

    dword_t status;
    cpu_mailbox_t * mailbox = get_mailbox();
    mailbox->tcb = tcb;
    
    status = mailbox->send_command(tcb->cpu, SMP_CMD_UNWIND);
    
    switch(status)
    {
    case MAILBOX_UNWIND_REMOTE:
	/* we have to perform a remote unwind */
	unwind_ipc(mailbox->tcb);
	break;
    case MAILBOX_OK:
	/* unwind done */
	break;
    case MAILBOX_ERROR:
	/* thread may have moved */
	return 0;
    default:
	enter_kdebug("smp_unwind: unexpected return value");
	return 0;
    };
    return 1;
}
/* Note: this is VG_, not ML_. */
SysRes VG_(am_do_mmap_NO_NOTIFY)( Addr start, SizeT length, UInt prot, 
                                  UInt flags, Int fd, Off64T offset)
{
#define DEBUG_MYSELF 0
#if defined(VGO_l4re)
   void *val;
#endif
   SysRes res;
   aspacem_assert(VG_IS_PAGE_ALIGNED(offset));
#  if defined(VGP_x86_linux) || defined(VGP_ppc32_linux) \
      || defined(VGP_arm_linux)
   /* mmap2 uses 4096 chunks even if actual page size is bigger. */
   aspacem_assert((offset % 4096) == 0);
   res = VG_(do_syscall6)(__NR_mmap2, (UWord)start, length,
                          prot, flags, fd, offset / 4096);
#  elif defined(VGP_amd64_linux) || defined(VGP_ppc64_linux) \
        || defined(VGP_ppc32_aix5) || defined(VGP_ppc64_aix5) \
        || defined(VGP_s390x_linux)
   res = VG_(do_syscall6)(__NR_mmap, (UWord)start, length, 
                         prot, flags, fd, offset);
#  elif defined(VGP_x86_darwin)
   if (fd == 0  &&  (flags & VKI_MAP_ANONYMOUS)) {
       fd = -1;  // MAP_ANON with fd==0 is EINVAL
   }
   res = VG_(do_syscall7)(__NR_mmap, (UWord)start, length,
                          prot, flags, fd, offset & 0xffffffff, offset >> 32);
#  elif defined(VGP_amd64_darwin)
   if (fd == 0  &&  (flags & VKI_MAP_ANONYMOUS)) {
       fd = -1;  // MAP_ANON with fd==0 is EINVAL
   }
   res = VG_(do_syscall6)(__NR_mmap, (UWord)start, length,
                          prot, flags, (UInt)fd, offset);
#  elif defined(VGO_l4re)
   #if DEBUG_MYSELF
   VG_(am_show_nsegments)(0,"before mmap");
   l4re_rm_show_lists();
   VG_(debugLog)(1, "aspacem", "\033[34mmmap(start=%p, length=%d (0x%x), fd=%d,\033[0m\n",(void *)start, (int) length, (int)length, fd);
   VG_(debugLog)(1, "aspacem", "\033[34moffset=%ld (0x%lx), prot=%d=%c%c%c, flags=%d=%s%s%s%s)\033[0m\n",
                 (long)offset, (long) offset,
                 prot,
                 prot & VKI_PROT_READ ? 'r' : '-',
                 prot & VKI_PROT_WRITE ? 'w' : '-',
                 prot & VKI_PROT_EXEC ? 'x' : '-',
                 flags,
                 flags & VKI_MAP_SHARED ? "MAP_SHARED " : "",
                 flags & VKI_MAP_PRIVATE ? "MAP_PRIVATE " : "",
                 flags & VKI_MAP_FIXED ? "MAP_FIXED " : "",
                 flags & VKI_MAP_ANONYMOUS ? "MAP_ANONYMOUS " : "");

   #endif

   val = mmap((void *)start, VG_PGROUNDUP(length), prot, flags, fd, offset);

   #if DEBUG_MYSELF
      VG_(debugLog)(1, "aspacem", "\033[34;1mmmap returns %p\n", val);
      VG_(am_show_nsegments)(0,"after mmap");
      l4re_rm_show_lists();
   #endif

   res._isError = (val == (void *)-1);
   if (sr_isError(res)) {
      res._err = - (int)val;
      res._res = -1;
      VG_(debugLog)(1, "aspacem", "mmap failed\n");
      enter_kdebug("ERROR: mmap failed");
   } else {
      res._err = 0;
      res._res = (int)val;
   }

#  else
#    error Unknown platform
#  endif
   return res;
}
Exemple #24
0
/* the stupid version */
ptr_t kmem_alloc(dword_t size)
{
    spin_lock(&kmem_spinlock);

    dword_t*	prev;
    dword_t*	curr;
    dword_t*	tmp;
    dword_t	i;
    
    //printf("%s(%d) kfl: %p\n", __FUNCTION__, size, kmem_free_list);
    for (prev = (dword_t*) &kmem_free_list, curr = kmem_free_list;
	 curr;
	 prev = curr, curr = (dword_t*) *curr)
    {
//	printf("curr=%x\n", curr);
	/* properly aligned ??? */
	if (!((dword_t) curr & (size - 1)))
	{
//	    printf("%s(%d):%d: curr=%x\n", __FUNCTION__, size, __LINE__, curr);
	    tmp = (dword_t*) *curr;
	    for (i = 1; tmp && (i < (size / KMEM_CHUNKSIZE)); i++)
	    {
//		printf("%s():%d: i=%d, tmp=%x\n", __FUNCTION__, __LINE__, i, tmp);
		if ((dword_t) tmp != ((dword_t) curr + KMEM_CHUNKSIZE*i))
		{
//		    printf("skip: %x\n", curr);
		    tmp = 0;
		    break;
		};
		tmp = (dword_t*) *tmp;
	    }
	    if (tmp)
	    {
		/* dequeue */
		*prev = (dword_t) tmp;

		/* zero the page */
		for (dword_t i = 0; i < (size / sizeof(dword_t)); i++)
		    curr[i] = 0;

		/* update counter */
		free_chunks -= (size/KMEM_CHUNKSIZE);

		/* successful return */
		spin_unlock(&kmem_spinlock);
		//printf("kmalloc: %x->%p (%d), kfl: %p\n", size, curr, free_chunks, kmem_free_list);
		return curr;
	    }
	}
    }
#if 0
    dword_t * tmp1 = kmem_free_list;
    while(tmp1) {
	printf("%p -> ");
	tmp1 = (dword_t*)*tmp1;
    }
#endif
    enter_kdebug("kmem_alloc: out of kernel memory");
    spin_unlock(&kmem_spinlock);
    return NULL;
}
Exemple #25
0
/******************************************************************************
 * main                                                                       *
 *                                                                            *
 * Main function                                                              *
 ******************************************************************************/
int main(int argc, char *argv[])
{
  int error = 0;
  l4_threadid_t dummy_l4id = L4_NIL_ID;

  CORBA_Environment _env = dice_default_environment;

  /* init */
  do_args(argc, argv);
  my_l4id = l4thread_l4_id( l4thread_myself() );

  LOG("Hello, I'm running as "l4util_idfmt, l4util_idstr(my_l4id));

  /* ask for 'con' (timeout = 5000 ms) */
  if (names_waitfor_name(CON_NAMES_STR, &con_l4id, 50000) == 0) 
    {
      LOG("PANIC: %s not registered at names", CON_NAMES_STR);
      enter_kdebug("panic");
    }

  if (con_if_openqry_call(&con_l4id, MY_SBUF_SIZE, 0, 0,
		     L4THREAD_DEFAULT_PRIO,
		     &vc_l4id, 
	  	     CON_VFB, &_env))
    enter_kdebug("Ouch, open vc failed");
  
  if (con_vc_smode_call(&vc_l4id, CON_OUT, &dummy_l4id, &_env))
    enter_kdebug("Ouch, setup vc failed");

  if (con_vc_graph_gmode_call(&vc_l4id, &gmode, &xres, &yres,
			 &bits_per_pixel, &bytes_per_pixel,
			 &bytes_per_line, &accel_flags, 
			 &fn_x, &fn_y, &_env))
    enter_kdebug("Ouch, graph_gmode failed");

  if (bytes_per_pixel != 2)
    {
      printf("Graphics mode not 2 bytes/pixel, exiting\n");
      con_vc_close_call(&vc_l4id, &_env);
      exit(0);
    }

  if (create_logo())
    enter_kdebug("Ouch, logo creation failed");

  while (!error) 
    {
      if ((error = clear_screen()))
	enter_kdebug("Ouch, clear_screen failed");
      if ((error = logo()))
	enter_kdebug("Ouch, logo failed");
      l4_sleep(2000);
    }

  if (con_vc_close_call(&vc_l4id, &_env))
    enter_kdebug("Ouch, close vc failed?!");
  
  LOG("Finally closed vc");

  LOG("Going to bed ...");
  l4_sleep(-1);

  return 0;
}
Exemple #26
0
/* Run a thread all the way to the end, then do appropriate exit actions
   (this is the last-one-out-turn-off-the-lights bit).  */
static void run_a_thread_NORETURN ( Word tidW )
{
   ThreadId          tid = (ThreadId)tidW;
   VgSchedReturnCode src;
   Int               c;

   VG_(debugLog)(1, "syswrap-l4re", 
                    "run_a_thread_NORETURN(tid=%lld): pre-thread_wrapper\n",
                    (ULong)tidW);

   /* Run the thread all the way through. */
   src = thread_wrapper(tid);  

   VG_(debugLog)(1, "syswrap-l4re", 
                    "run_a_thread_NORETURN(tid=%lld): post-thread_wrapper\n",
                    (ULong)tidW);

   c = VG_(count_living_threads)();
   vg_assert(c >= 1); /* stay sane */

   // Tell the tool this thread is exiting
   VG_TRACK( pre_thread_ll_exit, tid );

   if (c == 1) {

      VG_(debugLog)(1, "syswrap-l4re", 
                       "run_a_thread_NORETURN(tid=%lld): "
                          "last one standing\n",
                          (ULong)tidW);

      /* We are the last one standing.  Keep hold of the lock and
         carry on to show final tool results, then exit the entire system. 
         Use the continuation pointer set at startup in m_main. */
      ( * VG_(address_of_m_main_shutdown_actions_NORETURN) ) (tid, src);

   } else {

      ThreadState *tst;

      VG_(debugLog)(1, "syswrap-l4re", 
                       "run_a_thread_NORETURN(tid=%lld): "
                          "not last one standing\n",
                          (ULong)tidW);

      /* OK, thread is dead, but others still exist.  Just exit. */
      tst = VG_(get_ThreadState)(tid);

      /* This releases the run lock */
      VG_(exit_thread)(tid);
      vg_assert(tst->status == VgTs_Zombie);

      /* We have to use this sequence to terminate the thread to
         prevent a subtle race.  If VG_(exit_thread)() had left the
         ThreadState as Empty, then it could have been reallocated,
         reusing the stack while we're doing these last cleanups.
         Instead, VG_(exit_thread) leaves it as Zombie to prevent
         reallocation.  We need to make sure we don't touch the stack
         between marking it Empty and exiting.  Hence the
         assembler. */
#if defined(VGO_l4re)
      //XXX: some other threads still exists, so only this thread should exit
      l4_sleep_forever();
      enter_kdebug("hmm!");
#else
# error Unknown platform
#endif

      VG_(core_panic)("Thread exit failed?\n");
   }

   /*NOTREACHED*/
   vg_assert(0);
}
Exemple #27
0
void smp_move_thread(tcb_t * tcb, dword_t cpu)
{
    cpu_mailbox_t * mailbox = get_mailbox();
    //mailbox->command = SMP_CMD_THREAD_MOVE;
    mailbox->tcb = tcb;
    //mailbox->status = MAILBOX_NULL;
    mailbox->param[0] = tcb->queue_state;

    //IPI_PRINTF("smp move thread %p from cpu %d to cpu %d\n", tcb, tcb->cpu, cpu);

    /* do not move thread if already on cpu */
    if (tcb->cpu == cpu)
	return;

    /* do not migrate to inactive cpus */
    if (!is_cpu_online(cpu))
	return;

 retry_migration:

    if (tcb->cpu == get_cpu_id())
    {
	/* we have the thread - so, we can give it away */
	thread_dequeue_present(tcb);
	thread_dequeue_ready(tcb);
	thread_dequeue_wakeup(tcb);
	
	IPI_PRINTF("before thread put (current: %x, pdir=%x, tcb: %x)\n", 
		   get_current_tcb(), get_current_pagetable(), tcb);

	mailbox->send_command(cpu, SMP_CMD_THREAD_PUT);

	IPI_PRINTF("thread_put done (current: %x, pdir=%x, cpu: %d/%d)\n", 
		   get_current_tcb(), get_current_pagetable(), 
		   get_cpu_id(), get_apic_cpu_id());
    }
    else
    {
	/* we don't have the thread - ask the cpu */
	dword_t status;
	status = mailbox->send_command(tcb->cpu, SMP_CMD_THREAD_GET);
	
	/* thread may have moved meanwhile */
	if (status != MAILBOX_OK)
	    goto retry_migration;
	
	if (cpu == get_cpu_id())
	{
	    /* the thread comes to us */
	    tcb->cpu = cpu;
	    thread_adapt_queue_state(tcb, mailbox->param[1]);
	    /* adjust the page directory for this tcb */
	    //printf("pgdir: %x\n", tcb->page_dir);
	    thread_adapt_pagetable(tcb, get_cpu_id());
	    //printf("pgdir: %x\n", tcb->page_dir);
	}
	else
	{
	    status = mailbox->send_command(cpu, SMP_CMD_THREAD_PUT);
	    
	    if (status != MAILBOX_OK)
	    {
		enter_kdebug("3-cpu thread migration failed");
		return;
	    }
	}
    } 
}
Exemple #28
0
/* central inter-cpu command handler */
void smp_handle_request(dword_t from_cpu)
{
    dword_t current_cpu = get_cpu_id();
    cpu_mailbox_t * mailbox = &cpu_mailbox[from_cpu];
    if (mailbox->get_command() > SMP_CMD_IPC_RECEIVE)
	IPI_PRINTF("smp-ipi command %d from %d\n", mailbox->get_command(), from_cpu);
    spin1(72);

    if (current_cpu == from_cpu) {
	enter_kdebug("self command ipi???");
	return;
    }

    //IPI_PRINTF("smp-ipi command %x from %d\n", mailbox->get_command(), from_cpu);

    switch(mailbox->get_command()) {
    case SMP_CMD_IPC_SHORT: 
	do_xcpu_ipc_short(mailbox);
	break;

    case SMP_CMD_IPC_START:
	do_xcpu_ipc_start(mailbox);
	break;

    case SMP_CMD_IPC_END:
	do_xcpu_ipc_end(mailbox);
	break;

    case SMP_CMD_IPC_RECEIVE:
	do_xcpu_ipc_receive(mailbox);
	break;

    case SMP_CMD_THREAD_GET:
	do_xcpu_thread_get(mailbox);
	break;

    case SMP_CMD_THREAD_PUT:
	do_xcpu_thread_put(mailbox);
	break;
       
    case SMP_CMD_THREAD_EX_REGS:
	do_xcpu_thread_ex_regs(mailbox);
	break;

    case SMP_CMD_UNWIND:
	do_xcpu_unwind(mailbox);
	break;

    case SMP_CMD_DELETE_ALL_THREADS:
	do_xcpu_delete_all_threads(mailbox);
	break;
	
    case SMP_CMD_FLUSH_TLB:
	do_xcpu_flush_tlb(mailbox);
	break;

    default:
	printf("cpu%d: unhandled command from cpu %d: cmd: %x, tcb: %p\n",
	       get_cpu_id(), from_cpu, mailbox->get_command(), mailbox->tcb);
    }
}
Exemple #29
0
/******************************************************************************
 * main                                                                       *
 *                                                                            *
 * Main function                                                              *
 ******************************************************************************/
int main(int argc, char *argv[])
{
  int error = 0, i=1;
  l4_threadid_t dummy_l4id = L4_NIL_ID, loader_id;
//  l4events_event_t event;
//  l4events_nr_t eventnr;

  CORBA_Environment _env = dice_default_environment;

  /* init */
  do_args(argc, argv);
  my_l4id = l4thread_l4_id( l4thread_myself() );

  LOG("Hello, I'm running as "l4util_idfmt, l4util_idstr(my_l4id));

  /* ask for 'con' (timeout = 5000 ms) */
  if (names_waitfor_name(CON_NAMES_STR, &con_l4id, 50000) == 0) 
    {
      LOG("PANIC: %s not registered at names", CON_NAMES_STR);
      enter_kdebug("panic");
    }

  if (names_waitfor_name("LOADER", &loader_id, 50000) == 0)
    {
      LOG("PANIC: LOADER not registered at names");
      enter_kdebug("panic");
    }
  
  if (con_if_openqry_call(&con_l4id, MY_SBUF_SIZE, 0, 0,
		     L4THREAD_DEFAULT_PRIO,
		     &vc_l4id, 
	  	     CON_VFB, &_env))
    enter_kdebug("Ouch, open vc failed");
  
  if (con_vc_smode_call(&vc_l4id, CON_OUT, &dummy_l4id, &_env))
    enter_kdebug("Ouch, setup vc failed");

  if (con_vc_graph_gmode_call(&vc_l4id, &gmode, &xres, &yres,
			 &bits_per_pixel, &bytes_per_pixel,
			 &bytes_per_line, &accel_flags, 
			 &fn_x, &fn_y, &_env))
    enter_kdebug("Ouch, graph_gmode failed");

  if (bytes_per_pixel != 2)
    {
      printf("Graphics mode not 2 bytes/pixel, exiting\n");
      con_vc_close_call(&vc_l4id, &_env);
      exit(0);
    }

  if (create_logo())
    enter_kdebug("Ouch, logo creation failed");

  while (!error && (i>0)) 
    {
      if ((error = clear_screen()))
	enter_kdebug("Ouch, clear_screen failed");
      if ((error = logo()))
	enter_kdebug("Ouch, logo failed");
      l4_sleep(500);
      i--;
    }

  if (con_vc_close_call(&vc_l4id, &_env))
    enter_kdebug("Ouch, close vc failed?!");
  
  LOG("Finally closed vc");

  LOG("Going to bed ...");

  names_register("CON_DEMO1");
/*
  my_id = l4_myself();
  event.len=sizeof(l4_umword_t);
  *(l4_umword_t*)event.str=my_id.id.task;
  
  l4events_send(1, &event, &eventnr, L4EVENTS_SEND_ACK);
  l4events_get_ack(eventnr, L4_IPC_NEVER);
*/  
  return 0;
}
Exemple #30
0
void booter_discard()

{
    enter_kdebug("discarding request for booter");
}