コード例 #1
0
ファイル: test-util.c プロジェクト: dm0-/systemd
static void test_physical_memory_scale(void) {
        uint64_t p;

        log_info("/* %s */", __func__);

        p = physical_memory();

        assert_se(physical_memory_scale(0, 100) == 0);
        assert_se(physical_memory_scale(100, 100) == p);

        log_info("Memory original: %" PRIu64, physical_memory());
        log_info("Memory scaled by 50%%: %" PRIu64, physical_memory_scale(50, 100));
        log_info("Memory divided by 2: %" PRIu64, physical_memory() / 2);
        log_info("Page size: %zu", page_size());

        /* There might be an uneven number of pages, hence permit these calculations to be half a page off... */
        assert_se(page_size()/2 + physical_memory_scale(50, 100) - p/2 <= page_size());
        assert_se(physical_memory_scale(200, 100) == p*2);

        assert_se(physical_memory_scale(0, 1) == 0);
        assert_se(physical_memory_scale(1, 1) == p);
        assert_se(physical_memory_scale(2, 1) == p*2);

        assert_se(physical_memory_scale(0, 2) == 0);

        assert_se(page_size()/2 + physical_memory_scale(1, 2) - p/2 <= page_size());
        assert_se(physical_memory_scale(2, 2) == p);
        assert_se(physical_memory_scale(4, 2) == p*2);

        assert_se(physical_memory_scale(0, UINT32_MAX) == 0);
        assert_se(physical_memory_scale(UINT32_MAX, UINT32_MAX) == p);

        /* overflow */
        assert_se(physical_memory_scale(UINT64_MAX/4, UINT64_MAX) == UINT64_MAX);
}
コード例 #2
0
//------------------------------------------------------------------------------
// Name: read_byte_base
// Desc: the base implementation of reading a byte
//------------------------------------------------------------------------------
quint8 DebuggerCoreUNIX::read_byte_base(edb::address_t address, bool *ok) {
	// TODO: assert that we are paused

	Q_ASSERT(ok);

	*ok = false;
	errno = -1;
	if(attached()) {
		// if this spot is unreadable, then just return 0xff, otherwise
		// continue as normal.

		// page_size() - 1 will always be 0xf* because pagesizes
		// are always 0x10*, so the masking works
		// range of a is [1..n] where n=pagesize, and we have to adjust
		// if a < wordsize
		const edb::address_t a = page_size() - (address & (page_size() - 1));

		if(a < EDB_WORDSIZE) {
			address -= (EDB_WORDSIZE - a); // LE + BE
		}

		long value = read_data(address, ok);

		if(*ok) {
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
			if(a < EDB_WORDSIZE) {
				value >>= CHAR_BIT * (EDB_WORDSIZE - a); // LE
			}
#else
			if(a < EDB_WORDSIZE) {
				value >>= CHAR_BIT * (a - 1);            // BE
			} else {
コード例 #3
0
ファイル: sigbus.c プロジェクト: dankor/systemd
static void sigbus_handler(int sn, siginfo_t *si, void *data) {
        unsigned long ul;
        void *aligned;

        assert(sn == SIGBUS);
        assert(si);

        if (si->si_code != BUS_ADRERR || !si->si_addr) {
                assert_se(sigaction(SIGBUS, &old_sigaction, NULL) == 0);
                raise(SIGBUS);
                return;
        }

        ul = (unsigned long) si->si_addr;
        ul = ul / page_size();
        ul = ul * page_size();
        aligned = (void*) ul;

        /* Let's remember which address failed */
        sigbus_push(aligned);

        /* Replace mapping with an anonymous page, so that the
         * execution can continue, however with a zeroed out page */
        assert_se(mmap(aligned, page_size(), PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED, -1, 0) == aligned);
}
コード例 #4
0
// There may be unallocated holes in the middle chunks
// that should be filled with dead objects to ensure parsability.
void MutableNUMASpace::ensure_parsability() {
  for (int i = 0; i < lgrp_spaces()->length(); i++) {
    LGRPSpace *ls = lgrp_spaces()->at(i);
    MutableSpace *s = ls->space();
    if (s->top() < top()) { // For all spaces preceding the one containing top()
      if (s->free_in_words() > 0) {
        intptr_t cur_top = (intptr_t)s->top();
        size_t words_left_to_fill = pointer_delta(s->end(), s->top());;
        while (words_left_to_fill > 0) {
          size_t words_to_fill = MIN2(words_left_to_fill, CollectedHeap::filler_array_max_size());
          assert(words_to_fill >= CollectedHeap::min_fill_size(),
                 "Remaining size (" SIZE_FORMAT ") is too small to fill (based on " SIZE_FORMAT " and " SIZE_FORMAT ")",
                 words_to_fill, words_left_to_fill, CollectedHeap::filler_array_max_size());
          CollectedHeap::fill_with_object((HeapWord*)cur_top, words_to_fill);
          if (!os::numa_has_static_binding()) {
            size_t touched_words = words_to_fill;
#ifndef ASSERT
            if (!ZapUnusedHeapArea) {
              touched_words = MIN2((size_t)align_object_size(typeArrayOopDesc::header_size(T_INT)),
                touched_words);
            }
#endif
            MemRegion invalid;
            HeapWord *crossing_start = (HeapWord*)round_to(cur_top, os::vm_page_size());
            HeapWord *crossing_end = (HeapWord*)round_to(cur_top + touched_words, os::vm_page_size());
            if (crossing_start != crossing_end) {
              // If object header crossed a small page boundary we mark the area
              // as invalid rounding it to a page_size().
              HeapWord *start = MAX2((HeapWord*)round_down(cur_top, page_size()), s->bottom());
              HeapWord *end = MIN2((HeapWord*)round_to(cur_top + touched_words, page_size()), s->end());
              invalid = MemRegion(start, end);
            }

            ls->add_invalid_region(invalid);
          }
          cur_top = cur_top + (words_to_fill * HeapWordSize);
          words_left_to_fill -= words_to_fill;
        }
      }
    } else {
      if (!os::numa_has_static_binding()) {
#ifdef ASSERT
        MemRegion invalid(s->top(), s->end());
        ls->add_invalid_region(invalid);
#else
        if (ZapUnusedHeapArea) {
          MemRegion invalid(s->top(), s->end());
          ls->add_invalid_region(invalid);
        } else {
          return;
        }
#endif
      } else {
          return;
      }
    }
  }
}
コード例 #5
0
ファイル: statement.cpp プロジェクト: cybergarage/cpp-driver
// Format: [<result_page_size>][<paging_state>][<serial_consistency>][<timestamp>]
// where:
// <result_page_size> is a [int]
// <paging_state> is a [bytes]
// <serial_consistency> is a [short]
// <timestamp> is a [long]
// <keyspace> is a [string]
int32_t Statement::encode_end(int version, RequestCallback* callback, BufferVec* bufs) const {
  int32_t length = 0;
  size_t paging_buf_size = 0;

  bool with_keyspace = this->with_keyspace(version);

  if (page_size() > 0) {
    paging_buf_size += sizeof(int32_t); // [int]
  }

  if (!paging_state().empty()) {
    paging_buf_size += sizeof(int32_t) + paging_state().size(); // [bytes]
  }

  if (callback->serial_consistency() != 0) {
    paging_buf_size += sizeof(uint16_t); // [short]
  }

  if (version >= 3 && callback->timestamp() != CASS_INT64_MIN) {
    paging_buf_size += sizeof(int64_t); // [long]
  }

  if (with_keyspace) {
    paging_buf_size += sizeof(uint16_t) + keyspace().size();
  }

  if (paging_buf_size > 0) {
    bufs->push_back(Buffer(paging_buf_size));
    length += paging_buf_size;

    Buffer& buf = bufs->back();
    size_t pos = 0;

    if (page_size() >= 0) {
      pos = buf.encode_int32(pos, page_size());
    }

    if (!paging_state().empty()) {
      pos = buf.encode_bytes(pos, paging_state().data(), paging_state().size());
    }

    if (callback->serial_consistency() != 0) {
      pos = buf.encode_uint16(pos, callback->serial_consistency());
    }

    if (version >= 3 && callback->timestamp() != CASS_INT64_MIN) {
      pos = buf.encode_int64(pos, callback->timestamp());
    }

    if (with_keyspace) {
      pos = buf.encode_string(pos, keyspace().data(), keyspace().size());
    }
  }

  return length;
}
コード例 #6
0
ファイル: tuple.cpp プロジェクト: glycerine/shore-mt
void page::fwrite_full_page(FILE *file) {
    size_t write_count = ::fwrite(this, 1, page_size(), file);
    if ( write_count != page_size() ) {
        TRACE(TRACE_ALWAYS, "::fwrite() wrote %zd/%zd page bytes %s\n",
              write_count,
              page_size(),
              strerror(errno));
        THROW2(FileException, "::fwrite() failed %s", strerror(errno));
    }
}
コード例 #7
0
ファイル: rst-malloc.c プロジェクト: AuthenticEshkinKot/criu
static inline unsigned long rst_mem_grow(unsigned long need_size)
{
	int rst_mem_batch = 2 * page_size();

	need_size = round_up(need_size, page_size());
	if (likely(need_size < rst_mem_batch))
		need_size = rst_mem_batch;
	else
		pr_debug("Growing rst memory %lu pages\n", need_size / page_size());
	return need_size;
}
コード例 #8
0
ファイル: memory.c プロジェクト: fcccode/libfiber
void stack_free(void *ptr)
{
	int ret;
	size_t pgsz = page_size();

	ptr = (char *) ptr - pgsz;
	ret = mprotect(ptr, page_size(), PROT_READ|PROT_WRITE);
	if (ret != 0) {
		msg_fatal("%s(%d), %s: mprotect error=%s",
			__FILE__, __LINE__, __FUNCTION__, last_serror());
	}
	free(ptr);
}
コード例 #9
0
ファイル: user_util.c プロジェクト: 12019/hg556a_source
void task_protections(unsigned long address)
{
	unsigned long guard = address + page_size();
	unsigned long stack = guard + page_size();
	int prot = 0, pages;

#ifdef notdef
	if(mprotect((void *) stack, page_size(), prot) < 0)
		panic("protecting guard page failed, errno = %d", errno);
#endif
	pages = (1 << UML_CONFIG_KERNEL_STACK_ORDER) - 2;
	prot = PROT_READ | PROT_WRITE | PROT_EXEC;
	if(mprotect((void *) stack, pages * page_size(), prot) < 0)
		panic("protecting stack failed, errno = %d", errno);
}
コード例 #10
0
ファイル: test-sleep.c プロジェクト: l10n-tw/systemd
static int test_fiemap(const char *path) {
        _cleanup_free_ struct fiemap *fiemap = NULL;
        _cleanup_close_ int fd = -1;
        int r;

        log_info("/* %s */", __func__);

        fd = open(path, O_RDONLY | O_CLOEXEC | O_NONBLOCK);
        if (fd < 0)
                return log_error_errno(errno, "failed to open %s: %m", path);
        r = read_fiemap(fd, &fiemap);
        if (r == -EOPNOTSUPP)
                exit(log_tests_skipped("Not supported"));
        if (r < 0)
                return log_error_errno(r, "Unable to read extent map for '%s': %m", path);
        log_info("extent map information for %s:", path);
        log_info("\t start: %" PRIu64, (uint64_t) fiemap->fm_start);
        log_info("\t length: %" PRIu64, (uint64_t) fiemap->fm_length);
        log_info("\t flags: %" PRIu32, fiemap->fm_flags);
        log_info("\t number of mapped extents: %" PRIu32, fiemap->fm_mapped_extents);
        log_info("\t extent count: %" PRIu32, fiemap->fm_extent_count);
        if (fiemap->fm_extent_count > 0)
                log_info("\t first extent location: %" PRIu64,
                         (uint64_t) (fiemap->fm_extents[0].fe_physical / page_size()));

        return 0;
}
コード例 #11
0
ファイル: kerndat.c プロジェクト: cyrillos/criu
static int check_pagemap(void)
{
	int ret, fd;
	u64 pfn = 0;

	fd = __open_proc(PROC_SELF, EPERM, O_RDONLY, "pagemap");
	if (fd < 0) {
		if (errno == EPERM) {
			pr_info("Pagemap disabled");
			kdat.pmap = PM_DISABLED;
			return 0;
		}

		return -1;
	}

	/* Get the PFN of some present page. Stack is here, so try it :) */
	ret = pread(fd, &pfn, sizeof(pfn), (((unsigned long)&ret) / page_size()) * sizeof(pfn));
	if (ret != sizeof(pfn)) {
		pr_perror("Can't read pagemap");
		return -1;
	}

	close(fd);

	if ((pfn & PME_PFRAME_MASK) == 0) {
		pr_info("Pagemap provides flags only\n");
		kdat.pmap = PM_FLAGS_ONLY;
	} else {
		pr_info("Pagemap is fully functional\n");
		kdat.pmap = PM_FULL;
	}

	return 0;
}
コード例 #12
0
ファイル: net_user.c プロジェクト: OpenHMR/Open-HMR600
static void change(char *dev, char *what, unsigned char *addr,
		   unsigned char *netmask)
{
	char addr_buf[sizeof("255.255.255.255\0")];
	char netmask_buf[sizeof("255.255.255.255\0")];
	char version[sizeof("nnnnn\0")];
	char *argv[] = { "uml_net", version, what, dev, addr_buf, 
			 netmask_buf, NULL };
	char *output;
	int output_len, pid;

	sprintf(version, "%d", UML_NET_VERSION);
	sprintf(addr_buf, "%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]);
	sprintf(netmask_buf, "%d.%d.%d.%d", netmask[0], netmask[1], 
		netmask[2], netmask[3]);

	output_len = page_size();
	output = um_kmalloc(output_len);
	if(output == NULL)
		printk("change : failed to allocate output buffer\n");

	pid = change_tramp(argv, output, output_len);
	if(pid < 0) return;

	if(output != NULL){
		printk("%s", output);
		kfree(output);
	}
}
コード例 #13
0
ファイル: ima-setup.c プロジェクト: GuillaumeSeren/systemd
int ima_setup(void) {
#ifdef HAVE_IMA
        _cleanup_fclose_ FILE *input = NULL;
        _cleanup_close_ int imafd = -1;
        unsigned lineno = 0;
        char line[page_size()];

        if (access(IMA_SECFS_DIR, F_OK) < 0) {
                log_debug("IMA support is disabled in the kernel, ignoring.");
                return 0;
        }

        if (access(IMA_SECFS_POLICY, W_OK) < 0) {
                log_warning("Another IMA custom policy has already been loaded, ignoring.");
                return 0;
        }

        imafd = open(IMA_SECFS_POLICY, O_WRONLY|O_CLOEXEC);
        if (imafd < 0) {
                log_error_errno(errno, "Failed to open the IMA kernel interface "IMA_SECFS_POLICY", ignoring: %m");
                return 0;
        }

        /* attempt to write the name of the policy file into sysfs file */
        if (write(imafd, IMA_POLICY_PATH, strlen(IMA_POLICY_PATH)) > 0)
                goto done;

        /* fall back to copying the policy line-by-line */
        input = fopen(IMA_POLICY_PATH, "re");
        if (!input) {
                log_full_errno(errno == ENOENT ? LOG_DEBUG : LOG_WARNING, errno,
                               "Failed to open the IMA custom policy file "IMA_POLICY_PATH", ignoring: %m");
                return 0;
        }

        close(imafd);

        imafd = open(IMA_SECFS_POLICY, O_WRONLY|O_CLOEXEC);
        if (imafd < 0) {
                log_error_errno(errno, "Failed to open the IMA kernel interface "IMA_SECFS_POLICY", ignoring: %m");
                return 0;
        }

        FOREACH_LINE(line, input,
                     return log_error_errno(errno, "Failed to read the IMA custom policy file "IMA_POLICY_PATH": %m")) {
                size_t len;

                len = strlen(line);
                lineno++;

                if (len > 0 && write(imafd, line, len) < 0)
                        return log_error_errno(errno, "Failed to load the IMA custom policy file "IMA_POLICY_PATH"%u: %m",
                                               lineno);
        }

done:
        log_info("Successfully loaded the IMA custom policy "IMA_POLICY_PATH".");
#endif /* HAVE_IMA */
        return 0;
}
コード例 #14
0
ファイル: mcpsvr_grab.cpp プロジェクト: zhengxiexie/m
int McpServlet::get_grab_list_by_type(const idl::mcp_get_grab_list_by_type_params& in, idl::mcp_get_grab_list_by_type_response& out)
{
    UB_LOG_TRACE( "get_grab_list_by_type start" );
    string type_id(in.type_id());
    uint32_t page(in.page());
    uint32_t page_size(in.page_size());

    vector<grab_t> grab_list;
    int count=0;
    ContentType type(type_id);
    type.set_page_info(page, page_size);
    int res=type.getGrabList(count, grab_list);
    if(res!=0){
        UB_LOG_FATAL( "getGrabList failed, [%s:%d]", __FILE__, __LINE__ );
        count = res;
        goto end;
    }
end:
    out.m_result_params()->set_result(count);
    vector<grab_t>::const_iterator iter=grab_list.begin();
    for(int i=0; iter!=grab_list.end(); ++i, ++iter){
        setGrabInfoResult(out.m_result_params()->mutable_grab_list(i), *iter);
    }
    UB_LOG_TRACE( "get_grab_list_by_type end" );
    return 0;
}
コード例 #15
0
ファイル: user_util.c プロジェクト: 12019/hg556a_source
void stack_protections(unsigned long address)
{
	int prot = PROT_READ | PROT_WRITE | PROT_EXEC;

        if(mprotect((void *) address, page_size(), prot) < 0)
		panic("protecting stack failed, errno = %d", errno);
}
コード例 #16
0
ファイル: GfxBitmapFont.cpp プロジェクト: kayru/reversez
	void BitmapFont::pr_create_character_quads()
	{
		for( uint8 c=0; c<255; ++c )
		{
			const Font::CharData& data = m_font_data.get_char(c);
			if( data.page!=Font::InvalidPage )
			{
				TextureDescr& texture_descr = m_texture_descr[data.page];
				Vector2 page_size(float(texture_descr.width), float(texture_descr.height));

				float w = float(data.width);
				float h = float(data.height);

				float px = float(data.offset_x);
				float py = float(data.offset_y);

				float tx = float(data.x)		/ page_size.x;
				float ty = float(data.y)		/ page_size.y;
				float tw = float(data.width)	/ page_size.x;
				float th = float(data.height)	/ page_size.y;

				TexturedQuad2D& q = m_chars[c];

				q.pos[0] = Vector2(px,		py);
				q.pos[1] = Vector2(px+w,	py);
				q.pos[2] = Vector2(px+w,	py+h);
				q.pos[3] = Vector2(px,		py+h);

				q.tex[0] = Vector2(tx,		ty);
				q.tex[1] = Vector2(tx+tw,	ty);
				q.tex[2] = Vector2(tx+tw,	ty+th);
				q.tex[3] = Vector2(tx,		ty+th);
			}
		}
	}
コード例 #17
0
ファイル: infect.c プロジェクト: Snorch/criu
static int parasite_mmap_exchange(struct parasite_ctl *ctl, unsigned long size)
{
	int fd;

	ctl->remote_map = remote_mmap(ctl, NULL, size,
				      PROT_READ | PROT_WRITE | PROT_EXEC,
				      MAP_ANONYMOUS | MAP_SHARED, -1, 0);
	if (!ctl->remote_map) {
		pr_err("Can't allocate memory for parasite blob (pid: %d)\n", ctl->rpid);
		return -1;
	}

	ctl->map_length = round_up(size, page_size());

	fd = ctl->ictx.open_proc(ctl->rpid, O_RDWR, "map_files/%p-%p",
		 ctl->remote_map, ctl->remote_map + ctl->map_length);
	if (fd < 0)
		return -1;

	ctl->local_map = mmap(NULL, size, PROT_READ | PROT_WRITE,
			      MAP_SHARED | MAP_FILE, fd, 0);
	close(fd);

	if (ctl->local_map == MAP_FAILED) {
		ctl->local_map = NULL;
		pr_perror("Can't map remote parasite map");
		return -1;
	}

	return 0;
}
コード例 #18
0
ファイル: allocator.cpp プロジェクト: SiderZhang/p2pns3
	void page_aligned_allocator::free(char* const block)
	{

#ifdef TORRENT_DEBUG_BUFFERS
		int page = page_size();
		// make the two surrounding pages non-readable and -writable
		mprotect(block - page, page, PROT_READ | PROT_WRITE);
		alloc_header* h = (alloc_header*)(block - page);
		int num_pages = (h->size + (page-1)) / page + 2;
		TORRENT_ASSERT(h->magic == 0x1337);
		mprotect(block + (num_pages-2) * page, page, PROT_READ | PROT_WRITE);
//		fprintf(stderr, "free: %p head: %p tail: %p size: %d\n", block, block - page, block + h->size, int(h->size));
		h->magic = 0;

#if defined __linux__ || (defined __APPLE__ && MAC_OS_X_VERSION_MIN_REQUIRED >= 1050)
		print_backtrace(h->stack, sizeof(h->stack));
#endif
		::free(block - page);
		return;
#endif

#ifdef TORRENT_WINDOWS
		_aligned_free(block);
#elif defined TORRENT_BEOS
		area_id id = area_for(block);
		if (id < B_OK) return;
		delete_area(id);
#else
		::free(block);
#endif
	}
コード例 #19
0
ファイル: test-sleep.c プロジェクト: vathpela/systemd
static int test_fiemap(const char *path) {
        _cleanup_free_ struct fiemap *fiemap = NULL;
        _cleanup_close_ int fd = -1;
        int r;

        fd = open(path, O_RDONLY | O_CLOEXEC | O_NONBLOCK);
        if (fd < 0)
                return log_error_errno(errno, "failed to open %s: %m", path);
        r = read_fiemap(fd, &fiemap);
        if (r == -EOPNOTSUPP) {
                log_info("Skipping test, not supported");
                exit(EXIT_TEST_SKIP);
        }
        if (r < 0)
                return log_error_errno(r, "Unable to read extent map for '%s': %m", path);
        log_info("extent map information for %s:", path);
        log_info("\t start: %llu", fiemap->fm_start);
        log_info("\t length: %llu", fiemap->fm_length);
        log_info("\t flags: %u", fiemap->fm_flags);
        log_info("\t number of mapped extents: %u", fiemap->fm_mapped_extents);
        log_info("\t extent count: %u", fiemap->fm_extent_count);
        if (fiemap->fm_extent_count > 0)
                log_info("\t first extent location: %llu",
                         fiemap->fm_extents[0].fe_physical / page_size());

        return 0;
}
コード例 #20
0
ファイル: helper.c プロジェクト: GodFox/magx_kernel_xpixl
int run_helper_thread(int (*proc)(void *), void *arg, unsigned int flags, 
		      unsigned long *stack_out, int stack_order)
{
	unsigned long stack, sp;
	int pid, status;

	stack = alloc_stack(stack_order, um_in_interrupt());
	if(stack == 0) return(-ENOMEM);

	sp = stack + (page_size() << stack_order) - sizeof(void *);
	pid = clone(proc, (void *) sp, flags | SIGCHLD, arg);
	if(pid < 0){
		printk("run_helper_thread : clone failed, errno = %d\n", 
		       errno);
		return(-errno);
	}
	if(stack_out == NULL){
		CATCH_EINTR(pid = waitpid(pid, &status, 0));
		if(pid < 0){
			printk("run_helper_thread - wait failed, errno = %d\n",
			       errno);
			pid = -errno;
		}
		if(!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
			printk("run_helper_thread - thread returned status "
			       "0x%x\n", status);
		free_stack(stack, stack_order);
	}
        else *stack_out = stack;
	return(pid);
}
コード例 #21
0
ファイル: tuple.cpp プロジェクト: glycerine/shore-mt
bool page::read_full_page(int fd) {
    
    /* create an aligned array of bytes we can read into */
    void* aligned_base;
    guard<char> ptr =
        (char*)aligned_alloc(page_size(), 512, &aligned_base);
    assert(ptr != NULL);


    /* read bytes over 'this' */
    /* read system call may return short counts */
    ssize_t size_read = rio_readn(fd, aligned_base, page_size());


    /* check for error */
    if (size_read == -1)
        THROW2(FileException, "::read failed %s", strerror(errno));

    
    /* check for end of file */
    if (size_read == 0)
        return false;


    /* rio_readn ensures we read the proper number of bytes */
    /* save page attributes that we'll be overwriting */
    page_pool* pool  = _pool;
    memcpy(this, aligned_base, size_read);
    _pool = pool;

    
    /* more error checking */
    if ( (page_size() != (size_t)size_read) ) {
        /* The page we read does not have the same size as the
           page object we overwrote. Luckily, we used the object
           size when reading, so we didn't overflow our internal
           buffer. */
        TRACE(TRACE_ALWAYS,
              "Read %zd byte-page with internal page size of %zd bytes. "
              "Sizes should all match.\n",
              size_read,
              page_size());
        THROW1(FileException, "::read read wrong size page");
    }
    
    return true;
}
コード例 #22
0
ファイル: infect.c プロジェクト: Snorch/criu
unsigned long compel_task_size(void)
{
	unsigned long task_size;

	for (task_size = TASK_SIZE_MIN; task_size < TASK_SIZE_MAX; task_size <<= 1)
		if (munmap((void *)task_size, page_size()))
			break;
	return task_size;
}
コード例 #23
0
size_t page_align(size_t size)
{
	size_t r;
	long psz = page_size();
	r = size % psz;
	if (r)
		return size + psz - r;
	return size;
}
コード例 #24
0
ファイル: memory.c プロジェクト: fcccode/libfiber
static size_t stack_size(size_t size)
{
	size_t pgsz = page_size(), sz;
	if (size < pgsz) {
		size = pgsz;
	}
	sz = (size + pgsz - 1) & ~(pgsz - 1);
	return sz;
}
コード例 #25
0
/**
 * \brief setup the default parameters
 * \param rawmidi RawMidi handle
 * \param params pointer to a snd_rawmidi_params_t structure
 * \return 0 on success otherwise a negative error code
 */
static int snd_rawmidi_params_default(snd_rawmidi_t *rawmidi, snd_rawmidi_params_t *params)
{
	assert(rawmidi);
	assert(params);
	params->buffer_size = page_size();
	params->avail_min = 1;
	params->no_active_sensing = 0;
	return 0;
}
コード例 #26
0
	char* page_aligned_allocator::malloc(page_aligned_allocator::size_type bytes)
	{
		TORRENT_ASSERT(bytes > 0);
		// just sanity check (this needs to be pretty high
		// for cases where the cache size is several gigabytes)
		TORRENT_ASSERT(bytes < 0x30000000);

		TORRENT_ASSERT(int(bytes) >= page_size());
#ifdef TORRENT_DEBUG_BUFFERS
		const int page = page_size();
		const int num_pages = (bytes + (page-1)) / page + 2;
		const int orig_bytes = bytes;
		bytes = num_pages * page;
#endif

		char* ret;
#if TORRENT_USE_POSIX_MEMALIGN
		if (posix_memalign(reinterpret_cast<void**>(&ret), page_size(), bytes)
			!= 0) ret = NULL;
#elif TORRENT_USE_MEMALIGN
		ret = static_cast<char*>(memalign(page_size(), bytes));
#elif defined TORRENT_WINDOWS
		ret = static_cast<char*>(_aligned_malloc(bytes, page_size()));
#elif defined TORRENT_BEOS
		area_id id = create_area("", &ret, B_ANY_ADDRESS
			, (bytes + page_size() - 1) & (page_size()-1), B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
		if (id < B_OK) return NULL;
		ret = static_cast<char*>(ret);
#else
		ret = static_cast<char*>(valloc(size_t(bytes)));
#endif
		if (ret == NULL) return NULL;

#ifdef TORRENT_DEBUG_BUFFERS
		// make the two surrounding pages non-readable and -writable
		alloc_header* h = (alloc_header*)ret;
		h->size = orig_bytes;
		h->magic = 0x1337;
		print_backtrace(h->stack, sizeof(h->stack));

#ifdef TORRENT_WINDOWS
#define mprotect(buf, size, prot) VirtualProtect(buf, size, prot, NULL)
#define PROT_READ PAGE_READONLY
#endif
		mprotect(ret, page, PROT_READ);
		mprotect(ret + (num_pages-1) * page, page, PROT_READ);

#ifdef TORRENT_WINDOWS
#undef mprotect
#undef PROT_READ
#endif
//		fprintf(stderr, "malloc: %p head: %p tail: %p size: %d\n", ret + page, ret, ret + page + bytes, int(bytes));

		return ret + page;
#endif // TORRENT_DEBUG_BUFFERS

		return ret;
	}
コード例 #27
0
ファイル: slip_user.c プロジェクト: FatSunHYS/OSCourseDesign
static int slip_tramp(char **argv, int fd)
{
	struct slip_pre_exec_data pe_data;
	char *output;
	int status, pid, fds[2], err, output_len;

	err = os_pipe(fds, 1, 0);
	if(err < 0){
		printk("slip_tramp : pipe failed, err = %d\n", -err);
		goto out;
	}

	err = 0;
	pe_data.stdin = fd;
	pe_data.stdout = fds[1];
	pe_data.close_me = fds[0];
	err = run_helper(slip_pre_exec, &pe_data, argv, NULL);
	if(err < 0)
		goto out_close;
	pid = err;

	output_len = page_size();
	output = um_kmalloc(output_len);
	if(output == NULL){
		printk("slip_tramp : failed to allocate output buffer\n");
		os_kill_process(pid, 1);
		err = -ENOMEM;
		goto out_free;
	}

	os_close_file(fds[1]);
	read_output(fds[0], output, output_len);
	printk("%s", output);

	CATCH_EINTR(err = waitpid(pid, &status, 0));
	if(err < 0)
		err = errno;
	else if(!WIFEXITED(status) || (WEXITSTATUS(status) != 0)){
		printk("'%s' didn't exit with status 0\n", argv[0]);
		err = -EINVAL;
	}
	else err = 0;

	os_close_file(fds[0]);

out_free:
	kfree(output);
	return err;

out_close:
	os_close_file(fds[0]);
	os_close_file(fds[1]);
out:
	return err;
}
コード例 #28
0
ファイル: process.c プロジェクト: FatSunHYS/OSCourseDesign
void init_new_thread_stack(void *sig_stack, void (*usr1_handler)(int))
{
	int flags = 0, pages;

	if(sig_stack != NULL){
		pages = (1 << UML_CONFIG_KERNEL_STACK_ORDER);
		set_sigstack(sig_stack, pages * page_size());
		flags = SA_ONSTACK;
	}
	if(usr1_handler) set_handler(SIGUSR1, usr1_handler, flags, -1);
}
コード例 #29
0
static void test_physical_memory(void) {
        uint64_t p;
        char buf[FORMAT_BYTES_MAX];

        p = physical_memory();
        assert_se(p > 0);
        assert_se(p < UINT64_MAX);
        assert_se(p % page_size() == 0);

        log_info("Memory: %s (%" PRIu64 ")", format_bytes(buf, sizeof(buf), p), p);
}
コード例 #30
0
//------------------------------------------------------------------------------
// Name: write_byte_base
// Desc: the base implementation of writing a byte
//------------------------------------------------------------------------------
void DebuggerCoreUNIX::write_byte_base(edb::address_t address, quint8 value, bool *ok) {
	// TODO: assert that we are paused

	Q_ASSERT(ok);

	*ok = false;
	if(attached()) {
		long v;
		long mask;
		// page_size() - 1 will always be 0xf* because pagesizes
		// are always 0x10*, so the masking works
		// range of a is [1..n] where n=pagesize, and we have to adjust
		// if a < wordsize
		const edb::address_t a = page_size() - (address & (page_size() - 1));

		v = value;
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
		if(a < EDB_WORDSIZE) {
			address -= (EDB_WORDSIZE - a);                       // LE + BE
			mask = ~(0xffUL << (CHAR_BIT * (EDB_WORDSIZE - a))); // LE
			v <<= CHAR_BIT * (EDB_WORDSIZE - a);                 // LE
		} else {
			mask = ~0xffUL; // LE
		}
#else /* BIG ENDIAN */
		if(a < EDB_WORDSIZE) {
			address -= (EDB_WORDSIZE - a);            // LE + BE
			mask = ~(0xffUL << (CHAR_BIT * (a - 1))); // BE
			v <<= CHAR_BIT * (a - 1);                 // BE
		} else {
			mask = ~(0xffUL << (CHAR_BIT * (EDB_WORDSIZE - 1))); // BE
			v <<= CHAR_BIT * (EDB_WORDSIZE - 1);                 // BE
		}
#endif

		v |= (read_data(address, ok) & mask);
		if(*ok) {
			*ok = write_data(address, v);
		}
	}
}