コード例 #1
0
		inline static void display_stack_main(int LineNo = 0)
		{
			get_log_stream() << "Begin Stack -------------------- (" << LineNo << ")" <<  std::endl;
			for(std::vector<std::string>::iterator i = get_stack().begin();
				i != get_stack().end();++i)
			{
				get_log_stream() << *i << std::endl;
			}
			get_log_stream() << "End Stack --------------------" << std::endl;
		}
コード例 #2
0
ファイル: thread_pthread.c プロジェクト: mathewv/ruby-oneshot
static int
native_thread_init_stack(rb_thread_t *th)
{
    rb_nativethread_id_t curr = pthread_self();

    if (pthread_equal(curr, native_main_thread.id)) {
	th->machine.stack_start = native_main_thread.stack_start;
	th->machine.stack_maxsize = native_main_thread.stack_maxsize;
    }
    else {
#ifdef STACKADDR_AVAILABLE
	void *start;
	size_t size;

	if (get_stack(&start, &size) == 0) {
	    th->machine.stack_start = start;
	    th->machine.stack_maxsize = size;
	}
#elif defined get_stack_of
	if (!th->machine.stack_maxsize) {
	    native_mutex_lock(&th->interrupt_lock);
	    native_mutex_unlock(&th->interrupt_lock);
	}
#else
	rb_raise(rb_eNotImpError, "ruby engine can initialize only in the main thread");
#endif
    }
#ifdef __ia64
    th->machine.register_stack_start = native_main_thread.register_stack_start;
    th->machine.stack_maxsize /= 2;
    th->machine.register_stack_maxsize = th->machine.stack_maxsize;
#endif
    return 0;
}
コード例 #3
0
int main()
{
    int a1;
    void *stack_addr;
    size_t stack_size;
    pthread_t      tid;
    pthread_t      tid_1;
    pthread_t      tid_2;

    printf("The pthread id is:%d\n", getpid());
    printf("address of a1: %p\n", &a1);
    get_stack(&stack_addr, &stack_size);
    printf("stack start: %p, size: %zu\n", stack_addr, stack_size);
    int a2;
    printf("address of a2: %p\n", &a2);

    pthread_create(&tid, NULL, func, NULL);
    pthread_create(&tid_1, NULL, func_1, NULL);
    pthread_create(&tid_2, NULL, func_2, NULL);

    puts("\n==============================================\n");
    char buf[4096];
    FILE *fp = fopen("/proc/self/maps", "r");
    while (fgets(buf, sizeof(buf), fp))
        printf("%s", buf);
    fclose(fp);

    sleep(2);
    return 0;
}
コード例 #4
0
ファイル: scheduler.c プロジェクト: ruiaraujo/uKernel-SEMB
/* rtos_init can be a macro in case that USE_DEFAULT_IDLE == 1
 * so we undef it here.
 */
void rtos_init(void (*idle)(void*),uint16_t stack_len,uint16_t system ){
    set_sleep_mode(SLEEP_MODE_IDLE);
#if USE_DYNAMIC_MEMORY
	uint8_t interrupt = GET_INTERRUPTS;
	cli();
    kernel.system_stack = ( uint8_t * )malloc( sizeof(uint8_t)*system ) + system - 1;
	RESTORE_INTERRUPTS(interrupt);
#else
	kernel.system_stack = get_stack( sizeof(uint8_t)*system ) + system - 1;
#endif
	if ( kernel.system_stack == NULL  ){
		/**
		 * If we don't have enough stack for the system,
		 * we try to warn the user
		 */
		#if TEST_STACK_OVERFLOW
				cli();
				ACTION_IN_STACK_OVERFLOW;
				while (1);
		#endif
		return;
	}
	add_task(idle,NULL, NULL,0,0,0,stack_len);
	__asm__ volatile ("rjmp switch_task\n" ::);
};
コード例 #5
0
ファイル: ndc.cpp プロジェクト: qiuyuzhou/log4boost
	void ndc::pop()
	{
		context_stack_t& stack = get_stack();
		if(!stack.empty())
		{
			stack.pop();
		}
	}
コード例 #6
0
ファイル: ndc.cpp プロジェクト: qiuyuzhou/log4boost
	void ndc::clear()
	{
		context_stack_t& stack = get_stack();
		while(!stack.empty())
		{
			stack.pop();
		}
	}
コード例 #7
0
ファイル: ndc.cpp プロジェクト: qiuyuzhou/log4boost
	const ndc::context_type & ndc::get()
	{
		context_stack_t& stack = get_stack();
		if(!stack.empty())
		{
			return stack.top();
		}
		throw std::logic_error("ndc is empty");
	}
コード例 #8
0
/*
 * Initialize LWP by spinning of a schedular
 */
int
ldap_int_thread_initialize( void )
{
	thread_t		tid;
	stkalign_t		*stack;
	int			stackno;

	if (( stack = get_stack( &stackno )) == NULL ) {
		return -1;
	}

	lwp_create( &tid, lwp_scheduler, MINPRIO, 0, stack, 1, stackno );
	return 0;
}
コード例 #9
0
ファイル: schedule.c プロジェクト: dankamongmen/libtorque
static inline
int setup_thread_stack(stack_t *s,pthread_attr_t *attr){
	if(pthread_attr_init(attr)){
		return -1;
	}
	if((s->ss_sp = get_stack(&s->ss_size)) == NULL){
		pthread_attr_destroy(attr);
		return -1;
	}
	if(pthread_attr_setstack(attr,s->ss_sp,s->ss_size)){
		dealloc(s->ss_sp,s->ss_size);
		pthread_attr_destroy(attr);
		return -1;
	}
	s->ss_flags = 0;
	return 0;
}
コード例 #10
0
ファイル: search.cpp プロジェクト: hof/qm2
/**
 * Verifies is a position is drawn by 
 * a) lack of material
 * b) fifty quiet moves
 * c) repetition
 * @return true if it's an official draw
 */
bool search_t::is_draw() {
    if (brd.is_draw()) { //draw by no mating material
        return true;
    } else if (brd.stack->fifty_count > 3) {
        if (brd.stack->fifty_count >= (100 + stack->in_check)) {
            return true; //50 reversible moves
        }
        int stop_ply = brd.ply - brd.stack->fifty_count;
        for (int ply = brd.ply - 4; ply >= stop_ply; ply -= 2) { //draw by repetition
            if (ply >= 0 && get_stack(ply)->tt_key == brd.stack->tt_key) {
                return true;
            } else if (ply < 0 && rep_table::retrieve(root.fifty_count + ply) == brd.stack->tt_key) {
                return true;
            }
        }
    }
    return false;
}
コード例 #11
0
ファイル: machine.c プロジェクト: yoanncouillec/c-scheme
struct DEBRUIJN * eval_debruijn (struct DEBRUIJN * debruijn, struct STACK * stack) {
  switch (debruijn->type) {
  case TYPE_DEBRUIJN_INTEGER : {
    TRACE("integer");
    return debruijn;
    break;
  }
  case TYPE_DEBRUIJN_VARIABLE : {
    TRACE("variable");
    return get_stack (stack, debruijn->variable.value)->debruijn;
    break;
  }
  case TYPE_DEBRUIJN_QUOTE : {
    TRACE("quote");
    return debruijn->quote.value;
    break ; 
  }
  case TYPE_DEBRUIJN_ABSTRACTION : {
    TRACE("abstraction");
    return make_debruijn_closure (debruijn->abstraction.body, stack);
    break ; 
  }
  case TYPE_DEBRUIJN_CLOSURE : {
    TRACE("closure");
    return debruijn;
    break ; 
  }
  case TYPE_DEBRUIJN_APPLICATION : {
    TRACE("application");
    struct DEBRUIJN * v = eval_debruijn (debruijn->application.left, stack);
    switch (v->type) {
    case TYPE_DEBRUIJN_CLOSURE : {
      return eval_debruijn (v->closure.body, 
			    set_stack (v->closure.stack,
				       gen_ident(),
				       eval_debruijn (debruijn->application.right,
						      stack)));
    }
    default : {
      fprintf(stderr, "Not a debruijn closure\n");
      exit(1);
    }}
  }}
}
コード例 #12
0
ファイル: machine.c プロジェクト: yoanncouillec/c-scheme
struct TERM * debruijn_to_term (struct DEBRUIJN * debruijn, struct STACK * stack) {
  switch (debruijn->type) {
  case TYPE_DEBRUIJN_INTEGER : {
    TRACE("integer");
    return make_term_integer(debruijn->integer.value);
    break;
  }
  case TYPE_DEBRUIJN_VARIABLE : {
    TRACE("variable");
    struct STACK * v = get_stack (stack, debruijn->variable.value);
    return make_term_variable (v->ident);
    break;
  }
  case TYPE_DEBRUIJN_QUOTE : {
    TRACE("quote");
    return make_term_quote (debruijn_to_term (debruijn->quote.value, make_stack()));
    break ; 
  }
  case TYPE_DEBRUIJN_ABSTRACTION : {
    TRACE("abstraction");
    char * var = gen_ident();
    struct STACK * s = set_stack(stack, var, NULL); // We just want to get ident
    return make_term_abstraction (var,debruijn_to_term(debruijn->abstraction.body, s));
    break ; 
  }
  case TYPE_DEBRUIJN_CLOSURE : {
    TRACE("closure");
    char * var = gen_ident();
    struct STACK * s = set_stack(stack, var, NULL); // We just want to get ident
    return make_term_closure (var,debruijn_to_term(debruijn->abstraction.body, s), NULL); // Shouldn't be NULL. Should be stack->env transformation
    break ; 
  }
  case TYPE_DEBRUIJN_APPLICATION : {
    TRACE("application");
    return make_term_application(debruijn_to_term(debruijn->application.left, stack),
				 debruijn_to_term(debruijn->application.right, stack));
    break;
  }
  default:{
    fprintf(stderr, "Unknown debruijn term type\n");
    exit(1);
  }
  }
}
コード例 #13
0
ファイル: thread_pthread.c プロジェクト: amtep/ruby
void
ruby_init_stack(volatile VALUE *addr
#ifdef __ia64
    , void *bsp
#endif
    )
{
    native_main_thread.id = pthread_self();
#ifdef STACK_END_ADDRESS
    native_main_thread.stack_start = STACK_END_ADDRESS;
#else
    if (!native_main_thread.stack_start ||
        STACK_UPPER((VALUE *)(void *)&addr,
                    native_main_thread.stack_start > addr,
                    native_main_thread.stack_start < addr)) {
        native_main_thread.stack_start = (VALUE *)addr;
    }
#endif
#ifdef __ia64
    if (!native_main_thread.register_stack_start ||
        (VALUE*)bsp < native_main_thread.register_stack_start) {
        native_main_thread.register_stack_start = (VALUE*)bsp;
    }
#endif
    {
	size_t size = 0;
	size_t space = 0;
#if defined(STACKADDR_AVAILABLE)
	void* stackaddr;
	STACK_GROW_DIR_DETECTION;
	get_stack(&stackaddr, &size);
	space = STACK_DIR_UPPER((char *)addr - (char *)stackaddr, (char *)stackaddr - (char *)addr);
#elif defined(HAVE_GETRLIMIT)
	struct rlimit rlim;
	if (getrlimit(RLIMIT_STACK, &rlim) == 0) {
	    size = (size_t)rlim.rlim_cur;
	}
	space = size > 5 * 1024 * 1024 ? 1024 * 1024 : size / 5;
#endif
	native_main_thread.stack_maxsize = size - space;
    }
}
コード例 #14
0
ファイル: file.cpp プロジェクト: richcole/RJL
Object* native_file_read_into_offset_length(Object *cxt, Object *frame, Object *self) {
  Object *stack = get_stack(cxt, frame);
  
  FileBuffer *file_buf = get_file_buffer(self);
  Object *length_obj   = pop(cxt, stack);
  Object *offset_obj   = pop(cxt, stack);
  Object *char_array   = pop(cxt, stack);

  if ( file_buf == 0 ) {
  	return new_exception(cxt, frame, "Expected a file as self argument");
  }

  CharArrayBuffer *char_array_buf = get_char_array_buffer(char_array);
  if ( char_array_buf == 0 ) {
  	return new_exception(cxt, frame, "Expected a char_array as first argument");
  }

  if ( ! is_boxed_int(cxt, offset_obj) ) {
  	return new_exception(cxt, frame, "Expected a boxed int as second argument");
  }
  Fixnum offset = boxed_int_to_fixnum(cxt, offset_obj);
  
  if ( ! is_boxed_int(cxt, length_obj) ) {
  	return new_exception(cxt, frame, "Expected a fixnum as third argument");
  }
  Fixnum length = boxed_int_to_fixnum(cxt, length_obj);

  if ( offset + length > char_array_buf->reserved ) {
  	return new_exception(cxt, frame, "Offset + length exceeds char_array length");
  }
  
  int num_read = fread(char_array_buf->data + offset, 1, length, file_buf->file);
  if ( num_read >= 0 ) {
    char_array_truncate_buffer(cxt, char_array, offset + num_read);
    return frame;
  }
  else {
  	return new_errno_exception(cxt, frame, "Unable to read from file");
  }
}
コード例 #15
0
void
ruby_init_stack(volatile VALUE *addr
#ifdef __ia64
    , void *bsp
#endif
    )
{
    native_main_thread.id = pthread_self();
#ifdef STACK_END_ADDRESS
    native_main_thread.stack_start = STACK_END_ADDRESS;
#else
    if (!native_main_thread.stack_start ||
        STACK_UPPER((VALUE *)(void *)&addr,
                    native_main_thread.stack_start > addr,
                    native_main_thread.stack_start < addr)) {
        native_main_thread.stack_start = (VALUE *)addr;
    }
#endif
#ifdef __ia64
    if (!native_main_thread.register_stack_start ||
        (VALUE*)bsp < native_main_thread.register_stack_start) {
        native_main_thread.register_stack_start = (VALUE*)bsp;
    }
#endif
    {
	size_t size = 0;
	size_t space = 0;
#if defined(HAVE_PTHREAD_ATTR_GET_NP)
	void* addr;
	get_stack(&addr, &size);
#elif defined(HAVE_GETRLIMIT)
	struct rlimit rlim;
	if (getrlimit(RLIMIT_STACK, &rlim) == 0) {
	    size = (size_t)rlim.rlim_cur;
	}
#endif
	space = size > 5 * 1024 * 1024 ? 1024 * 1024 : size / 5;
	native_main_thread.stack_maxsize = size - space;
    }
}
コード例 #16
0
ファイル: ndc.cpp プロジェクト: qiuyuzhou/log4boost
	size_t ndc::get_depth()
	{
		context_stack_t& stack = get_stack();
		return stack.size();
	}
コード例 #17
0
ファイル: scheduler.c プロジェクト: ruiaraujo/uKernel-SEMB
int add_task(void (*f)(void*),void (*finisher)(void), void * init_data,uint16_t period,uint16_t delay, uint8_t priority, uint16_t stack_len ){
	task_t * new_task = NULL,* current, *previous;
	uint16_t min_stack_len = 0xFFFF;
	uint8_t interrupt;
	current = previous = kernel.stopped_tasks;
	while ( current != NULL )
	{
		/* Finding an task already created but stopped and which stack we can use*/
		if ( current->stack_len >= stack_len && current->stack_len <= min_stack_len )
		{
			if ( previous == current )
				kernel.stopped_tasks = current->next_task;
			else
				previous->next_task = current->next_task;
			new_task = current;
			min_stack_len = current->stack_len; 
			break;
		}
		previous = current;
		current = current->next_task;
	}	
	if ( new_task == NULL )
	{
		interrupt = GET_INTERRUPTS;
		cli();
#if USE_DYNAMIC_MEMORY
		new_task = ( task_t * ) malloc(sizeof(task_t));
		if ( new_task == NULL )
		{
			RESTORE_INTERRUPTS(interrupt);
			return NO_MEMORY;
		}
		new_task->bottom_stack = ( uint8_t * )malloc( sizeof(uint8_t)*stack_len );
		if (  new_task->bottom_stack == NULL)
		{
			free(new_task);
			RESTORE_INTERRUPTS(interrupt);
			return NO_MEMORY;
		}
#else
		if ( __current_position_tasks >=  NUMBER_OF_TASKS )
		{
			RESTORE_INTERRUPTS(interrupt);
			return NO_MEMORY;
		}
		new_task = &__all_taks[__current_position_tasks++];
		new_task->bottom_stack = get_stack( sizeof(uint8_t)*stack_len );
		if (  new_task->bottom_stack == NULL)
		{
			RESTORE_INTERRUPTS(interrupt);
			return NO_MEMORY;
		}
#endif
		RESTORE_INTERRUPTS(interrupt);
		new_task->stack_len = stack_len;
	}

	// This can be used to detect stack overflows.
	new_task->stack = new_task->bottom_stack + sizeof(uint8_t)*new_task->stack_len-1;
	// To jump start the task.
	// we use another function with no arguments.
 	*((new_task->stack)--) = ((uint16_t)task_starter) & 0xFF;
	*((new_task->stack)--) = (((uint16_t)task_starter) >> 8) & 0xFF;
	new_task->priority = priority;
	new_task->period = period;
	new_task->delay = delay;
	new_task->init_data = init_data;
	#if USE_MUTEX
	new_task->holding_mutex = NULL;
	#endif
	//placing arguments in the stack for further use
 	*((new_task->stack)--) = ((uint16_t)init_data) & 0xFF;
	*((new_task->stack)--) = (((uint16_t)init_data) >> 8) & 0xFF;
	new_task->func = f;
	new_task->finisher = finisher;
	interrupt = GET_INTERRUPTS;
	if ( delay == 0 ){
		new_task->state = TASK_STARTING;
		add_task_to_priority_list(new_task, &kernel.ready_tasks);
	}
	else{
		new_task->state = TASK_DELAYED;
		add_task_to_blocked(new_task, &kernel.spleeping_tasks);
	}
	RESTORE_INTERRUPTS(interrupt);
	return 0;
}
コード例 #18
0
ファイル: pingy.c プロジェクト: arylwen/terebi
void validate(){
    if(!this_player() || !environment() || !(this_player() == environment())){
        error("Pingy violation. Stack: "+get_stack());
    }
}
コード例 #19
0
int main() {
  printf("The address of the stack is: %x.\n", get_stack());
}
コード例 #20
0
static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
			   sigset_t *set, struct pt_regs * regs)
{
	struct rt_sigframe __user *frame;
	struct _fpstate __user *fp = NULL; 
	int err = 0;
	struct task_struct *me = current;

	if (used_math()) {
		fp = get_stack(ka, regs, sizeof(struct _fpstate)); 
		frame = (void __user *)round_down(
			(unsigned long)fp - sizeof(struct rt_sigframe), 16) - 8;

		if (!access_ok(VERIFY_WRITE, fp, sizeof(struct _fpstate)))
			goto give_sigsegv;

		if (save_i387(fp) < 0) 
			err |= -1; 
	} else
		frame = get_stack(ka, regs, sizeof(struct rt_sigframe)) - 8;

	if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
		goto give_sigsegv;

	if (ka->sa.sa_flags & SA_SIGINFO) { 
		err |= copy_siginfo_to_user(&frame->info, info);
		if (err)
			goto give_sigsegv;
	}
		
	/* Create the ucontext.  */
	err |= __put_user(0, &frame->uc.uc_flags);
	err |= __put_user(0, &frame->uc.uc_link);
	err |= __put_user(me->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
	err |= __put_user(sas_ss_flags(regs->rsp),
			  &frame->uc.uc_stack.ss_flags);
	err |= __put_user(me->sas_ss_size, &frame->uc.uc_stack.ss_size);
	err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, set->sig[0], me);
	err |= __put_user(fp, &frame->uc.uc_mcontext.fpstate);
	if (sizeof(*set) == 16) { 
		__put_user(set->sig[0], &frame->uc.uc_sigmask.sig[0]);
		__put_user(set->sig[1], &frame->uc.uc_sigmask.sig[1]); 
	} else
		err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));

	/* Set up to return from userspace.  If provided, use a stub
	   already in userspace.  */
	/* x86-64 should always use SA_RESTORER. */
	if (ka->sa.sa_flags & SA_RESTORER) {
		err |= __put_user(ka->sa.sa_restorer, &frame->pretcode);
	} else {
		/* could use a vstub here */
		goto give_sigsegv; 
	}

	if (err)
		goto give_sigsegv;

#ifdef DEBUG_SIG
	printk("%d old rip %lx old rsp %lx old rax %lx\n", current->pid,regs->rip,regs->rsp,regs->rax);
#endif

	/* Set up registers for signal handler */
	regs->rdi = sig;
	/* In case the signal handler was declared without prototypes */ 
	regs->rax = 0;	

	/* This also works for non SA_SIGINFO handlers because they expect the
	   next argument after the signal number on the stack. */
	regs->rsi = (unsigned long)&frame->info; 
	regs->rdx = (unsigned long)&frame->uc; 
	regs->rip = (unsigned long) ka->sa.sa_handler;

	regs->rsp = (unsigned long)frame;

	/* Set up the CS register to run signal handlers in 64-bit mode,
	   even if the handler happens to be interrupting 32-bit code. */
	regs->cs = __USER_CS;

	/* This, by contrast, has nothing to do with segment registers -
	   see include/asm-x86_64/uaccess.h for details. */
	set_fs(USER_DS);

	regs->eflags &= ~TF_MASK;
	if (test_thread_flag(TIF_SINGLESTEP))
		ptrace_notify(SIGTRAP);
#ifdef DEBUG_SIG
	printk("SIG deliver (%s:%d): sp=%p pc=%p ra=%p\n",
		current->comm, current->pid, frame, regs->rip, frame->pretcode);
#endif

	return 0;

give_sigsegv:
	force_sigsegv(sig, current);
	return -EFAULT;
}
コード例 #21
0
ファイル: file.cpp プロジェクト: richcole/RJL
Object* native_file_open(Object *cxt, Object *frame, Object *self) {
  Object *stack = get_stack(cxt, frame);
  push(cxt, stack, new_char_array(cxt, "r"));
  return native_file_open_mode(cxt, frame, self);
}
コード例 #22
0
ファイル: players.c プロジェクト: Elohim/FGmud
        30:165,
        32:192,
        34:221,
        36:252,
        38:285,
        40:450,
        ]);


void validate(){
    if(!master()->valid_apply(({ "SECURE", "ASSIST", "LIB_CONNECT" })) &&
            base_name(previous_object()) != CGI_LOGIN && !override &&
            base_name(previous_object()) != CMD_RID &&
            base_name(previous_object()) != CMD_SUICIDE){
        string offender = identify(previous_object(-1));
        debug("PLAYERS_D SECURITY VIOLATION: "+offender+" ",get_stack(),"red");
        log_file("security", "\n"+timestamp()+" PLAYERS_D breach: "+offender+" "+get_stack());
        error("PLAYERS_D SECURITY VIOLATION: "+offender+" "+get_stack());
    }
    override = 0;
}

// This function generates a table of required xp per level.
// The xp required for lower levels is high, approximately
// half-again the xp required for the previous level. As the
// player progresses, this ratio decreases.
mapping CompileLevelList(){
    int i=1;
    mixed title;
    int seed=300;
    float mod;
コード例 #23
0
ファイル: reaper.c プロジェクト: Elohim/FGmud
        if(memory_info() > MEMUSE_HARD_LIMIT){
            if(!EVENTS_D->GetRebooting()){
                EVENTS_D->eventReboot(MINUTES_REBOOT_WARNING);
            }
        }
    }
}

static void create() {
    daemon::create();
    SetNoClean(1);
    call_out((: eventReap :), 300);
    call_out((: CheckMem :), 60);
    set_heart_beat(5);
}

static void heart_beat(){
#ifdef __FLUFFOS__
    if(sizeof(get_garbage()) > 20000){
        reap_other();
    }
#endif
}

int eventDestruct(){
    if( !(master()->valid_apply(({ "SECURE" }))) )
        error("Illegal attempt to destruct reaper: "+get_stack()+" "+identify(previous_object(-1)));
    return ::eventDestruct();
}

コード例 #24
0
		inline static void add_to_stack(const std::string& function_name)
		{
			get_stack().push_back(function_name);
		}
コード例 #25
0
ファイル: ndc.cpp プロジェクト: qiuyuzhou/log4boost
	bool ndc::empty()
	{
		return get_stack().empty();
	}
コード例 #26
0
		inline static void pop_stack()
		{
			get_stack().pop_back();
		}
コード例 #27
0
int
add_pack(struct linked_list *item, int print_message)
{
    struct object   *obj, *op;
    int from_floor;

    if (item == NULL)
    {
        from_floor = TRUE;

        if ((item = find_obj(hero.y, hero.x)) == NULL)
        {
            msg("Nothing to pick up.");
            return(FALSE);
        }
    }
    else
        from_floor = FALSE;

    if (from_floor)
    {
        item = get_stack(item);

        if (!item)
            return(FALSE);
    }

    obj = OBJPTR(item);

    /* If it is gold, just add its value to rogue's purse and get rid of */

    if (obj->o_type == GOLD)
    {
        struct linked_list  *mitem;
        struct thing    *tp;

        if (print_message)
        {
            if (!terse)
                addmsg("You found ");

            msg("%d gold pieces.", obj->o_count);
        }

        /*
         * First make sure no greedy monster is after this gold. If
         * so, make the monster run after the rogue instead.
         */

        for (mitem = mlist; mitem != NULL; mitem = next(mitem))
        {
            tp = THINGPTR(mitem);

            if (tp->t_horde==obj)
            {
                tp->t_ischasing = TRUE;
                tp->t_chasee = &player;
                tp->t_horde  = NULL;
            }
        }

        /*
         * This will cause problems if people are able to drop and
         * pick up gold, or when GOLDSTEAL monsters are killed.
         */

        /* Thieves get EXP for gold they pick up */

        if (player.t_ctype == C_THIEF)
        {
            pstats.s_exp += obj->o_count / 4;
            check_level();
        }

        purse += obj->o_count;

        if (from_floor)
            rem_obj(item, TRUE);    /* Remove object from the level */

        return (TRUE);
    }

    /* see if he can carry any more weight */

    if (itemweight(obj) + pstats.s_pack > pstats.s_carry)
    {
        msg("Too much for you to carry.");

        if (print_message)
        {
            msg("%s onto %s", terse ? "Moved" : "You moved",
                inv_name(obj, LOWERCASE));
        }

        return(FALSE);
    }

    /*
     * Link it into the pack. If the item can be grouped, try to find its
     * neighbors and bump the count. A special case is food, which can't
     * be grouped, but an exact match allows the count to get
     * incremented.
     */

    if ((op = apply_to_bag(pack, obj->o_type, bff_group, NULL, obj)) != NULL)
    {
        op->o_count += obj->o_count;    /* add it to the rest */

        if (from_floor)
            rem_obj(item, FALSE);

        pack_report(op, print_message, "You now have ");

        return(TRUE);
    }

    /* Check for and deal with scare monster scrolls */

    if (obj->o_type == SCROLL && obj->o_which == S_SCARE)
        if (obj->o_flags & ISCURSED)
        {
            msg("The scroll turns to dust as you pick it up.");
            rem_obj(item, TRUE);
            return(TRUE);
        }

    /* Check if there is room */

    if (count_bag(pack, obj->o_type, NULL) == max_print())
    {
        msg("You have no room for more %s.", name_type(obj->o_type));

        if (print_message)
        {
            obj = OBJPTR(item);
            msg("%s onto %s.", terse ? "Moved" : "You moved",
                inv_name(obj, LOWERCASE));
        }

        return(FALSE);
    }

    /*
     * finally, add the new item to the bag, and free up the linked list
     * on top of it.
     */

    if (from_floor)
        rem_obj(item, FALSE);

    push_bag(&pack, obj);
    pack_report(obj, print_message, "You now have ");
    ur_free(item);

    return(TRUE);      /* signal success */
}
コード例 #28
0
/* Set stack bottom of Ruby implementation.
 *
 * You must call this function before any heap allocation by Ruby implementation.
 * Or GC will break living objects */
void
ruby_init_stack(volatile VALUE *addr
#ifdef __ia64
    , void *bsp
#endif
    )
{
    native_main_thread.id = pthread_self();
#ifdef STACK_END_ADDRESS
    native_main_thread.stack_start = STACK_END_ADDRESS;
#else
    if (!native_main_thread.stack_start ||
        STACK_UPPER((VALUE *)(void *)&addr,
                    native_main_thread.stack_start > addr,
                    native_main_thread.stack_start < addr)) {
        native_main_thread.stack_start = (VALUE *)addr;
    }
#endif
#ifdef __ia64
    if (!native_main_thread.register_stack_start ||
        (VALUE*)bsp < native_main_thread.register_stack_start) {
        native_main_thread.register_stack_start = (VALUE*)bsp;
    }
#endif
    {
	size_t size = 0;
	size_t space = 0;
#if MAINSTACKADDR_AVAILABLE
	void* stackaddr;
	STACK_GROW_DIR_DETECTION;
	get_stack(&stackaddr, &size);
	space = STACK_DIR_UPPER((char *)addr - (char *)stackaddr, (char *)stackaddr - (char *)addr);
	native_main_thread.stack_maxsize = size - space;
#elif defined(HAVE_GETRLIMIT)
	int pagesize = getpagesize();
	struct rlimit rlim;
	if (getrlimit(RLIMIT_STACK, &rlim) == 0) {
	    size = (size_t)rlim.rlim_cur;
	}
	addr = native_main_thread.stack_start;
	if (IS_STACK_DIR_UPPER()) {
	    space = ((size_t)((char *)addr + size) / pagesize) * pagesize - (size_t)addr;
	}
	else {
	    space = (size_t)addr - ((size_t)((char *)addr - size) / pagesize + 1) * pagesize;
	}
	native_main_thread.stack_maxsize = space;
#endif
    }

    /* If addr is out of range of main-thread stack range estimation,  */
    /* it should be on co-routine (alternative stack). [Feature #2294] */
    {
	void *start, *end;

	if (IS_STACK_DIR_UPPER()) {
	    start = native_main_thread.stack_start;
	    end = (char *)native_main_thread.stack_start + native_main_thread.stack_maxsize;
	}
	else {
	    start = (char *)native_main_thread.stack_start - native_main_thread.stack_maxsize;
	    end = native_main_thread.stack_start;
	}

	if ((void *)addr < start || (void *)addr > end) {
	    /* out of range */
	    native_main_thread.stack_start = (VALUE *)addr;
	    native_main_thread.stack_maxsize = 0; /* unknown */
	}
    }
}
コード例 #29
0
ファイル: ndc.cpp プロジェクト: qiuyuzhou/log4boost
	void ndc::push( const context_type& _context )
	{
		get_stack().push( _context );
	}
コード例 #30
0
ファイル: addemote.c プロジェクト: arylwen/terebi
#include <daemons.h>
#include <message_class.h>

inherit LIB_DAEMON;

static void MainMenu();
static void EditErrorMessage(string emote);
static void ShowEmote(string emote);
static void AddEmote(string emote);
static void AddRule(string rule, string emote);

static private void validate() {
    if(!this_player()) return 0;
    if( !((int)master()->valid_apply(({ "ASSIST" }))) &&
      !member_group(this_player(), "EMOTES") )
        error("Illegal attempt to access addemote: "+get_stack()+" "+identify(previous_object(-1)));
}

static void EnterEmote(string emote, string array emotes) {
    int x = to_int(emote);
    validate();
    if( x < 1 || x > sizeof(emotes) ) {
        if( member_array(emote, emotes) == -1 ) {
            if( emote[0] == 'q' ) {
                return;
            }
            MainMenu();
            return;
        }
    }
    else {