本文整理汇总了C++中page_size函数的典型用法代码示例。如果您正苦于以下问题:C++ page_size函数的具体用法?C++ page_size怎么用?C++ page_size使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了page_size函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: test_physical_memory_scale
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);
}
开发者ID:dm0-,项目名称:systemd,代码行数:35,代码来源:test-util.c
示例2: Q_ASSERT
//------------------------------------------------------------------------------
// 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 {
开发者ID:TheCrazyT,项目名称:edb-debugger,代码行数:36,代码来源:DebuggerCoreUNIX.cpp
示例3: sigbus_handler
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);
}
开发者ID:dankor,项目名称:systemd,代码行数:25,代码来源:sigbus.c
示例4: lgrp_spaces
// 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;
}
}
}
}
开发者ID:campolake,项目名称:openjdk9,代码行数:60,代码来源:mutableNUMASpace.cpp
示例5: sizeof
// 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;
}
开发者ID:cybergarage,项目名称:cpp-driver,代码行数:63,代码来源:statement.cpp
示例6: page_size
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));
}
}
开发者ID:glycerine,项目名称:shore-mt,代码行数:10,代码来源:tuple.cpp
示例7: rst_mem_grow
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;
}
开发者ID:AuthenticEshkinKot,项目名称:criu,代码行数:11,代码来源:rst-malloc.c
示例8: stack_free
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);
}
开发者ID:fcccode,项目名称:libfiber,代码行数:13,代码来源:memory.c
示例9: task_protections
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);
}
开发者ID:12019,项目名称:hg556a_source,代码行数:15,代码来源:user_util.c
示例10: test_fiemap
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;
}
开发者ID:l10n-tw,项目名称:systemd,代码行数:27,代码来源:test-sleep.c
示例11: check_pagemap
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;
}
开发者ID:cyrillos,项目名称:criu,代码行数:35,代码来源:kerndat.c
示例12: change
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);
}
}
开发者ID:OpenHMR,项目名称:Open-HMR600,代码行数:29,代码来源:net_user.c
示例13: ima_setup
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;
}
开发者ID:GuillaumeSeren,项目名称:systemd,代码行数:60,代码来源:ima-setup.c
示例14: UB_LOG_TRACE
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;
}
开发者ID:zhengxiexie,项目名称:m,代码行数:26,代码来源:mcpsvr_grab.cpp
示例15: stack_protections
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);
}
开发者ID:12019,项目名称:hg556a_source,代码行数:7,代码来源:user_util.c
示例16: page_size
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);
}
}
}
开发者ID:kayru,项目名称:reversez,代码行数:35,代码来源:GfxBitmapFont.cpp
示例17: parasite_mmap_exchange
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;
}
开发者ID:Snorch,项目名称:criu,代码行数:31,代码来源:infect.c
示例18: page_size
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
}
开发者ID:SiderZhang,项目名称:p2pns3,代码行数:31,代码来源:allocator.cpp
示例19: test_fiemap
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;
}
开发者ID:vathpela,项目名称:systemd,代码行数:27,代码来源:test-sleep.c
示例20: run_helper_thread
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);
}
开发者ID:GodFox,项目名称:magx_kernel_xpixl,代码行数:31,代码来源:helper.c
注:本文中的page_size函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论