Exemplo n.º 1
0
/*
 * udp_instance_alloc()
 */
struct udp_instance *udp_instance_alloc(struct ip_instance *ii)
{
	struct udp_instance *ui;
	struct ip_client *ic;

	ui = (struct udp_instance *)membuf_alloc(sizeof(struct udp_instance), NULL);
	ui->ui_client_attach = udp_client_attach;
	ui->ui_client_detach = udp_client_detach;
	ui->ui_client_list = NULL;
	spinlock_init(&ui->ui_lock, 0x24);

	/*
	 * Attach this protocol handler to the IP stack.
	 */
	ic = ip_client_alloc();
	ic->ic_protocol = 0x11;
	ic->ic_recv = udp_recv_netbuf;
	ic->ic_recv_icmp = NULL;
	ic->ic_instance = ui;
	udp_instance_ref(ui);
	
	ui->ui_server = ii->ii_ip_client_attach(ii, ic);
	ip_client_deref(ic);
	
	return ui;
}
Exemplo n.º 2
0
struct semaphore *
sem_create(const char *name, int initial_count)
{
    struct semaphore *sem;

    KASSERT(initial_count >= 0);

    sem = kmalloc(sizeof(struct semaphore));
    if (sem == NULL) {
        return NULL;
    }

    sem->sem_name = kstrdup(name);
    if (sem->sem_name == NULL) {
        kfree(sem);
        return NULL;
    }

    sem->sem_wchan = wchan_create(sem->sem_name);
    if (sem->sem_wchan == NULL) {
        kfree(sem->sem_name);
        kfree(sem);
        return NULL;
    }

    spinlock_init(&sem->sem_lock);
    sem->sem_count = initial_count;

    return sem;
}
Exemplo n.º 3
0
struct vnode *
vn_initialize(
	struct inode	*inode)
{
	struct vnode	*vp = LINVFS_GET_VP(inode);

	XFS_STATS_INC(vn_active);
	XFS_STATS_INC(vn_alloc);

	vp->v_flag = VMODIFIED;
	spinlock_init(&vp->v_lock, "v_lock");

	spin_lock(&vnumber_lock);
	if (!++vn_generation)	/* v_number shouldn't be zero */
		vn_generation++;
	vp->v_number = vn_generation;
	spin_unlock(&vnumber_lock);

	ASSERT(VN_CACHED(vp) == 0);

	/* Initialize the first behavior and the behavior chain head. */
	vn_bhv_head_init(VN_BHV_HEAD(vp), "vnode");

#ifdef	XFS_VNODE_TRACE
	vp->v_trace = ktrace_alloc(VNODE_TRACE_SIZE, KM_SLEEP);
#endif	/* XFS_VNODE_TRACE */

	vn_trace_exit(vp, "vn_initialize", (inst_t *)__return_address);
	return vp;
}
Exemplo n.º 4
0
void tprintf_init(void)
{
	spinlock_init(&buffer_lock);

	setvbuf(stdout, NULL, _IONBF, 0);
	setvbuf(stderr, NULL, _IONBF, 0);
}
Exemplo n.º 5
0
struct lock *
lock_create(const char *name)
{
    struct lock *lock;

    lock = kmalloc(sizeof(struct lock));
    if (lock == NULL) {
        return NULL;
    }

    lock->lk_name = kstrdup(name);
    if (lock->lk_name == NULL) {
        kfree(lock);
        return NULL;
    }
#if OPT_A1
    lock->lock_wchan = wchan_create(lock->lk_name);
    if (lock->lock_wchan == NULL) {
        kfree(lock->lk_name);
        kfree(lock);
    }

    spinlock_init(&lock->lk_spinlock);
    lock->available = true;
#endif
    return lock;
}
Exemplo n.º 6
0
__init void console_early_init() {
    con_global = &glob;
    con_global->lockup = false;
    spinlock_init(&con_global->lock);

    vram_early_init(con_global);
}
Exemplo n.º 7
0
/**
 * The module initialisation routine, called when the module
 * is first loaded.
 */
void
ModuleInit()
{
    MXS_NOTICE("Initialise debug CLI router module %s.", version_str);
    spinlock_init(&instlock);
    instances = NULL;
}
Exemplo n.º 8
0
int id_gen_test(int nargs, char **args){
	sem_numthread = sem_create("sem_testidgen",0);
	struct spinlock splock;
	spinlock_init(&splock);
	idgen = idgen_create(0);

	KASSERT(idgen != NULL);

	(void)nargs;
	(void)args;

	const int NUMTHREAD = 3;

	int i = 0;
	for (; i < NUMTHREAD; i++){
		kprintf ("MAKING THREAD %d\n", i);
		thread_fork("id_gen_test", NULL, test_generator, NULL, i);
	}

	for (int j = 0; j < NUMTHREAD; j++,i++){
		kprintf ("MAKING THREAD %d\n", i);
		thread_fork("id_gen_test", NULL, test_generator2, NULL, i);
	}

	for (int j = 0; j < 2*NUMTHREAD; j++){
		P(sem_numthread);
	}

	idgen_destroy(idgen);
	sem_destroy(sem_numthread);
	return 0;
}
Exemplo n.º 9
0
/**
 * Allocate a new service for the gateway to support
 *
 *
 * @param servname	The service name
 * @param router	Name of the router module this service uses
 *
 * @return		The newly created service or NULL if an error occured
 */
SERVICE *
service_alloc(char *servname, char *router)
{
SERVICE 	*service;

	if ((service = (SERVICE *)malloc(sizeof(SERVICE))) == NULL)
		return NULL;
	if ((service->router = load_module(router, MODULE_ROUTER)) == NULL)
	{
		free(service);
		return NULL;
	}
	service->name = strdup(servname);
	service->routerModule = strdup(router);
	memset(&service->stats, 0, sizeof(SERVICE_STATS));
	service->ports = NULL;
	service->stats.started = time(0);
	service->state = SERVICE_STATE_ALLOC;
	service->credentials.name = NULL;
	service->credentials.authdata = NULL;
	service->users = users_alloc();
	service->enable_root = 0;
	service->routerOptions = NULL;
	service->databases = NULL;
	spinlock_init(&service->spin);

	spinlock_acquire(&service_spin);
	service->next = allServices;
	allServices = service;
	spinlock_release(&service_spin);

	return service;
}
Exemplo n.º 10
0
struct cv *
cv_create(const char *name)
{
	struct cv *cv;

	cv = kmalloc(sizeof(*cv));
	if (cv == NULL) {
		return NULL;
	}

	cv->cv_name = kstrdup(name);
	if (cv->cv_name==NULL) {
		kfree(cv);
		return NULL;
	}

	cv->cv_wchan = wchan_create(cv->cv_name);
	if (cv->cv_wchan == NULL) {
		kfree(cv->cv_name);
		kfree(cv);
		return NULL;
	}

	spinlock_init(&cv->cv_spinlock);
	// add stuff here as needed

	return cv;
}
Exemplo n.º 11
0
u32
prepare_for_sleep (u32 firmware_waking_vector)
{
	u8 *p;
	int wakeup_entry_len;

	/* Get the suspend-lock to make other processors stopping or staying
	   in the guest mode. */
	get_suspend_lock ();

	/* Now the VMM is executed by the current processor only.
	   Call suspend functions. */
	call_initfunc ("suspend");

	/* Initialize variables used by wakeup functions */
	wakeup_cpucount = 0;
	spinlock_init (&wakeup_cpucount_lock);
	waking_vector = firmware_waking_vector;
	wakeup_prepare ();

	/* Copy the wakeup_entry code. */
	wakeup_entry_len = wakeup_entry_end - wakeup_entry_start;
	p = mapmem_hphys (wakeup_entry_addr, wakeup_entry_len, MAPMEM_WRITE);
	memcpy (p, wakeup_entry_start, wakeup_entry_len);
	unmapmem (p, wakeup_entry_len);
	return wakeup_entry_addr;
}
Exemplo n.º 12
0
struct lock *
lock_create(const char *name)
{
	struct lock *lock;

	lock = kmalloc(sizeof(*lock));
	if (lock == NULL) {
		return NULL;
	}

	lock->lk_name = kstrdup(name);
	if (lock->lk_name == NULL) {
		kfree(lock);
		return NULL;
	}

	lock->lk_wchan = wchan_create(lock->lk_name);
	if (lock->lk_wchan == NULL) {
		kfree(lock->lk_name);
		kfree(lock);
		return NULL;
	}

	spinlock_init(&lock->lk_spinlock);
	lock->lk_isheld = false;
	lock->lk_curthread = NULL;
	// add stuff here as needed

	return lock;
}
Exemplo n.º 13
0
struct lock *
lock_create(const char *name)
{
        struct lock *lock;

        lock = kmalloc(sizeof(struct lock));
        if (lock == NULL) {
                return NULL;
        }

        lock->lk_name = kstrdup(name);
        if (lock->lk_name == NULL) {
                kfree(lock);
                return NULL;
        }

        // add stuff here as needed
		//Peng 2.19.2016		
        lock->lock_wchan = wchan_create(lock->lk_name);
        if (lock->lock_wchan == NULL) {
        kfree(lock->lk_name);
        kfree(lock);
        return NULL;
        }
        spinlock_init(&lock->lock_splk);
        lock->held=false;
        lock->holder=NULL;
		//Peng

        return lock;
}
Exemplo n.º 14
0
/*
 * hubspc_init
 * Registration of the hubspc devices with the hub manager
 */
void
hubspc_init(void)
{
        /*
         * Register with the hub manager
         */

        /* The reference counters */
        hubdev_register(mem_refcnt_attach);

	/* Prom space */
	hubdev_register(cpuprom_attach);

#if defined(CONFIG_SERIAL_SGI_L1_PROTOCOL)
	/* L1 system controller link */
	if ( !IS_RUNNING_ON_SIMULATOR() ) {
		/* initialize the L1 link */
		void l1_cons_init( l1sc_t *sc );
		elsc_t *get_elsc(void);

		l1_cons_init((l1sc_t *)get_elsc());
	}
#endif

#ifdef	HUBSPC_DEBUG
	printf("hubspc_init: Completed\n");
#endif	/* HUBSPC_DEBUG */
	/* Initialize spinlocks */
	spinlock_init(&cpuprom_spinlock, "promlist");
}
Exemplo n.º 15
0
// 新しいデバイスの発見
void pro100_new(struct pci_device *dev)
{
	PRO100_CTX *ctx = SeZeroMalloc(sizeof(PRO100_CTX));

	debugprint ("pro100_new\n");

#ifdef VTD_TRANS
        if (iommu_detected) {
                add_remap(dev->address.bus_no ,dev->address.device_no ,dev->address.func_no,
                          vmm_start_inf() >> 12, (vmm_term_inf()-vmm_start_inf()) >> 12, PERM_DMA_RW) ;
        }
#endif // of VTD_TRANS

	ctx->dev = dev;
	spinlock_init (&ctx->lock);
	dev->host = ctx;
	dev->driver->options.use_base_address_mask_emulation = 1;

	pro100_alloc_recv_buffer(ctx);

	if (pro100_ctx == NULL)
	{
		pro100_ctx = ctx;
	}
	else
	{
		debugprint("Error: Two or more pro100 devices found.\n");
		pro100_beep(1234, 5000);
	}
}
Exemplo n.º 16
0
/**
 * Allocate a new hash table
 *
 * @param size		The size of the hash table
 * @param hashfn	The user supplied hash function
 * @param cmpfn		The user supplied key comparison function
 * @return The hashtable table
 */
HASHTABLE *
hashtable_alloc(int size, int (*hashfn)(), int (*cmpfn)())
{
HASHTABLE 	*rval;

	if ((rval = malloc(sizeof(HASHTABLE))) == NULL)
		return NULL;

#if defined(SS_DEBUG)
        rval->ht_chk_top = CHK_NUM_HASHTABLE;
        rval->ht_chk_tail = CHK_NUM_HASHTABLE;
#endif
	rval->hashsize = size;
	rval->hashfn = hashfn;
	rval->cmpfn = cmpfn;
	rval->kcopyfn = nullfn;
	rval->vcopyfn = nullfn;
	rval->kfreefn = nullfn;
	rval->vfreefn = nullfn;
	rval->n_readers = 0;
	rval->writelock = 0;
	spinlock_init(&rval->spin);
	if ((rval->entries = (HASHENTRIES **)calloc(size, sizeof(HASHENTRIES *))) == NULL)
	{
		free(rval);
		return NULL;
	}
	memset(rval->entries, 0, size * sizeof(HASHENTRIES *));

	return rval;
}
Exemplo n.º 17
0
static struct ata_channel *ata_new_channel(struct ata_host* host)
{
	struct ata_channel *channel;
	struct atapi_device *atapi_device;

	channel = alloc_ata_channel();
	memset(channel, 0, sizeof(*channel));
	spinlock_init (&channel->locked_lock);
	channel->locked = false;
	channel->waiting = 0;
	channel->hd[ATA_ID_CMD] = -1;
	channel->hd[ATA_ID_CTL] = -1;
	channel->hd[ATA_ID_BM] = -1;
	ata_init_ata_device(&channel->device[0]);
	ata_init_ata_device(&channel->device[1]);
	channel->host = host;
	channel->state = ATA_STATE_READY;
	ata_init_prd(channel);
	ata_init_pio_buf (channel);
	host_id++; device_id = 0;

	/* atapi device */
	atapi_device = alloc_atapi_device();
	memset(atapi_device, 0, sizeof(*atapi_device));
	channel->atapi_device = atapi_device;
	channel->atapi_device->atapi_flag = 0;
	channel->atapi_device->dma_state = ATA_STATE_DMA_THROUGH;

	return channel;
}
Exemplo n.º 18
0
/* Initialize a driver list. */
static void list_init(driver_list_t *dl, const char *name)
{
  spinlock_init(&dl->mutex);
  dl->n = 0;
  dl->drivers = 0;
  dl->name = name;
}
Exemplo n.º 19
0
Arquivo: mfs.c Projeto: bedreamer/fool
/*设备挂载响应函数*/
int mfs_mount(struct inode *pi,struct itemdata *proot,void ** mntprivate)
{
	if (NULL==pi||NULL==mntprivate) return INVALID;
	if (ITYPE_BLK_DEV!=pi->i_data.i_attrib.i_type) return INVALID;
	if (MFS_NEED_MIN_SCTS>pi->i_data.i_attrib.i_size) return INVALID;

	struct mfs_super_blk sblk={0},*psblk;
	int result = mfsr_superblk(&(pi->i_data),&sblk);
	if (INVALID==result) return INVALID;
	if (MFS_MAGIC!=sblk.mfs_magic) return INVALID;

	psblk = kmalloc(sizeof(struct mfs_super_blk));
	if (NULL==psblk) return INVALID;

	memcpy(psblk,&sblk,sizeof(struct mfs_super_blk));
	spinlock_init(psblk->lck_cmap);	/*必须要初始化这个成员*/

	* mntprivate = psblk;

	struct mfs_core *pc = cmfs_cache_alloc();
	if (NULL==pc) goto faile;

	pc->i_fat[0] = sblk.clst_root;
	pc->m_cluster = sblk.clst_root;
	pc->m_itm = &(proot->i_attrib);
	pc->m_itm->i_type = ITYPE_DIR;

	proot->i_private = pc;
faile:
	kfree(psblk);
	return VALID;
}
Exemplo n.º 20
0
/** Init everything for the driver manager. */
int driver_lists_init(void)
{
  int i, err = 0;
  const int n = sizeof(registered_lists) / sizeof(*registered_lists);

  spinlock_init(&driver_lists_mutex);
  driver_lists = 0;
  for (i=0; i<n; ++i) {
    driver_list_reg_t * reg = registered_lists + i;

    if (driver_lists_add(reg) < 0) {
      SDERROR("[%s] : [%s,%08x] registration failed.\n",
	      __FUNCTION__, reg->name, reg->type);
      ++ err;
    } else {
      /* $$$ ben : careful ! driver list will not been initiliazed if
	 the registration failed. This couls be dangerous since we used
	 extern driver list. This could be ok as soon as these extern be
	 removed.
      */
      list_init(reg->list, reg->name);
      SDDEBUG("[%s] : [%s,%08x] initialized.\n",
	      __FUNCTION__, reg->name, reg->type);
    }
  }
  return -err;
}
Exemplo n.º 21
0
Arquivo: synch.c Projeto: simnic31/OS
struct lock *
lock_create(const char *name)
{
        struct lock *lock;

        lock = kmalloc(sizeof(struct lock));
        if (lock == NULL) {
                return NULL;
        }

        lock->lk_name = kstrdup(name);
        if (lock->lk_name == NULL) {
                kfree(lock);
                return NULL;
        }
        // add stuff here as needed

        lock->lk_wchan = wchan_create(lock->lk_name);
		  if (lock->lk_wchan == NULL){
			  kfree(lock->lk_name);
			  kfree(lock);
			  return NULL;
		  }

		  spinlock_init(&lock->lk_spinlock);
		  lock->lk_owner = NULL;
        
        return lock;
}
Exemplo n.º 22
0
int scsi_init(struct scsi_ifc *ifc) {
    int rc;
    scsi = kzalloc(sizeof(struct scsi_dev));
    if (scsi == NULL)
        return ERR_NO_MEM;

    /* Copy the driver interface */
    scsi->driver = ifc->driver;
    scsi->read = ifc->read;
    scsi->write = ifc->write;
    spinlock_init(&scsi->lock);

    rc = scsi_read_capacity();
    DEBUG("Reading device capacity parameters %s", DEBUG_STATUS(rc));

    if(rc < 0) {
        kfree(scsi);
        return -1;
    }

    DEBUG("Device block size %d, block count %d",
          scsi->block_size, scsi->total_block_count);

    scsi->op_status = OPERATING;

    return 0;
}
Exemplo n.º 23
0
/*
 * Create a proc structure.
 */
static
struct proc *
proc_create(const char *name)
{
	struct proc *proc;

	proc = kmalloc(sizeof(*proc));
	if (proc == NULL) {
		return NULL;
	}
	proc->p_name = kstrdup(name);
	if (proc->p_name == NULL) {
		kfree(proc);
		return NULL;
	}

	threadarray_init(&proc->p_threads);
	spinlock_init(&proc->p_lock);

	/* VM fields */
	proc->p_addrspace = NULL;

	/* VFS fields */
	proc->p_cwd = NULL;

#ifdef UW
	proc->console = NULL;
#endif // UW

	return proc;
}
Exemplo n.º 24
0
Arquivo: mwmr.c Projeto: Masshat/almos
struct fifomwmr_s* mwmr_init(int item, int length, int isAtomic)
{
	kmem_req_t req;
	struct fifomwmr_s *fifo;
	char *data;

	req.type  = KMEM_GENERIC;
	req.size  = sizeof(*fifo);
	req.flags = AF_BOOT | AF_ZERO;
  
	if((fifo = kmem_alloc(&req)) == NULL)
		return NULL;
  
	req.size = sizeof (unsigned int) * item * length;

	if((data = kmem_alloc(&req)) == NULL)
	{
		printk(WARNING, "WARNING: mwmr_init: MEMORY SHORTAGE\n");
		req.ptr = fifo;
		kmem_free(&req);
		return NULL;
	}

	spinlock_init(&fifo->lock, "MWMR");
	fifo->isAtomic = isAtomic;
	fifo->item     = item;
	fifo->length   = length * item;
	fifo->data     = data;
  
	return fifo;
}
Exemplo n.º 25
0
struct cv *
cv_create(const char *name)
{
    struct cv *cv;

    cv = kmalloc(sizeof(struct cv));
    if (cv == NULL) {
        return NULL;
    }

    cv->cv_name = kstrdup(name);
    if (cv->cv_name==NULL) {
        kfree(cv);
        return NULL;
    }
#if OPT_A1
    cv->cv_wchan = wchan_create(cv->cv_name);
    if (cv->cv_wchan == NULL) {
        kfree(cv->cv_name);
        kfree(cv);
    }

    spinlock_init(&cv->cv_lock);
#endif
    return cv;
}
Exemplo n.º 26
0
int el_loader_init(void)
{
  PRINTF("entrylist_load_init...\n");

  spinlock_init(&loader_mutex);
  memset(&loader, 0, sizeof(loader));
  loader_status = LOADER_INIT;
  loader_thd = 0;
  PRINTF("entrylist_load_init : create semaphore.\n");
  loader_sem = sem_create(1);
  PRINTF("entrylist_load_init : semaphore [%p].\n",loader_sem);
  if (!loader_sem) {
    printf("entrylist_load_init : can not create semaphore.\n");
    return -1;
  }
  PRINTF("entrylist_load_init : first wait semaphore.\n");
  sem_wait(loader_sem);

  PRINTF("entrylist_load_init : create thread.\n");
  loader_thd = thd_create(THD_DEFAULTS, loader_thread, loader_sem);
  if (!loader_thd) {
    printf("entrylist_load_init : thread failed.\n");
    sem_signal(loader_sem);
    sem_destroy(loader_sem);
    loader_sem = 0;
    printf("entrylist_load_init : can not create loader thread.\n");
    return -1;
  }
  PRINTF("entrylist_load_init : thread created, rename it.\n");
  thd_set_label((kthread_t *)loader_thd, "Loader-thd");
  PRINTF("entrylist_load_init : complete (thd=%p).\n", loader_thd);
  return 0;
}
Exemplo n.º 27
0
Arquivo: file.c Projeto: gapry/os161
int
filetable_init(void)
{
    DEBUG(DB_VFS, "*** Initializing filetable\n");
    struct filetable *ft = (struct filetable *)kmalloc(sizeof(struct filetable));
    
    /* Initialize first 3 filedescriptors */
    int result;
    char path[5];
    strcpy(path, "con:");
    
    ft->ft_entries[0] = (struct filetable_entry *)kmalloc(sizeof(struct filetable_entry));
    struct vnode *cons_vnode = NULL;
    result = vfs_open(path, O_RDWR, 0, &cons_vnode);
    ft->ft_entries[0]->ft_vnode = cons_vnode;
    ft->ft_entries[0]->ft_pos = 0;
    ft->ft_entries[0]->ft_flags = O_RDWR;
    ft->ft_entries[0]->ft_count = 3;
    
    ft->ft_entries[1] = ft->ft_entries[0];
    ft->ft_entries[2] = ft->ft_entries[0];
    
    /* Initialize the rest of filetable entries to NULL. */
    int fd;
    for (fd = 3; fd < __OPEN_MAX; fd++) {
        ft->ft_entries[fd] = NULL;
    }
    
	spinlock_init(&ft->ft_spinlock);
    
    /* Update current thread's filetable field. */
    curthread->t_filetable = ft;
    
    return 0;
}	
Exemplo n.º 28
0
/**
 * Start the instance of the monitor, returning a handle on the monitor.
 *
 * This function creates a thread to execute the actual monitoring.
 *
 * @return A handle to use when interacting with the monitor
 */
static	void 	*
startMonitor(void *arg)
{
MYSQL_MONITOR *handle;

	if (arg != NULL)
	{
		handle = (MYSQL_MONITOR *)arg;
		handle->shutdown = 0;
	}
	else
	{
		if ((handle = (MYSQL_MONITOR *)malloc(sizeof(MYSQL_MONITOR))) == NULL)
			return NULL;
		handle->databases = NULL;
		handle->shutdown = 0;
		handle->defaultUser = NULL;
		handle->defaultPasswd = NULL;
		handle->id = MONITOR_DEFAULT_ID;
		handle->interval = MONITOR_INTERVAL;
		spinlock_init(&handle->lock);
	}
	handle->tid = (THREAD)thread_start(monitorMain, handle);
	return handle;
}
Exemplo n.º 29
0
Arquivo: netlog.c Projeto: brho/akaros
void netloginit(struct Fs *f)
{
	f->alog = kzmalloc(sizeof(struct Netlog), 0);
	spinlock_init(&f->alog->lock);
	qlock_init(&f->alog->qlock);
	rendez_init(&f->alog->r);
}
Exemplo n.º 30
0
/// Inicjalizuje obsługę tyknięć zegara systemowego.
void
clock_init()
{
     spinlock_init(&soft_guard);
     load_cmos_time();
     list_create(&__callouts, offsetof(callout_t, L_callouts), FALSE);
}