memory-access

Checking C code for invalid memory access with Frama-C

戏子无情 提交于 2019-12-11 01:38:06
问题 I am given this C code (the details of the code, including possible bugs, are not very relevant): int read_leb128(char **ptr, char *end) { int r = 0; int s = 0; char b; do { if ((intptr_t)*ptr >= (intptr_t)end) (exit(1)); b = *(*ptr)++; r += (b & (char)0x7f) << s; s += 7; } while (b & (char)0x80); return r; } and I want to throw some formal methods at it to rule out dangerous bugs. In particular, I would like a assurance that this function does not modify any value besides *ptr and only reads

Generic OpenCL stencil kernel and host

喜夏-厌秋 提交于 2019-12-10 15:14:25
问题 I am new to OpenCL. I would like to write a generic kernel so later I can extend its use to other memory non-coalescing patterns and pairing this with Rectangular stencil pattern for simplicity (also avoiding out-of-bound access). This kernel controls the use of local memory ( __local float ∗lmem ). As of now, I have structures my .cl file as bellow: __kernel void kmain ( __global float ∗in , __global float ∗out , __global float ∗in2 , __local float ∗lmem) { int wg_x = get group id(0); int wg

How to read/write type values from “raw” memory in C?

天大地大妈咪最大 提交于 2019-12-08 17:40:31
问题 How do I make something like this work? void *memory = malloc(1000); //allocate a pool of memory *(memory+10) = 1; //set an integer value at byte 10 int i = *(memory+10); //read an integer value from the 10th byte 回答1: Easy example: treat the memory as an array of unsigned char void *memory = malloc(1000); //allocate a pool of memory uint8_t *ptr = memory+10; *ptr = 1 //set an integer value at byte 10 uint8_t i = *ptr; //read an integer value from the 10th byte You can use integers too, but

Accessing Memory of other applications C++

蓝咒 提交于 2019-12-06 04:22:49
问题 I am thinking about a problem I have been having for some time now.. I would like to write a C/C++ program (under windows first) that can access(read/change values) the memory(stack, heap, everything) of other running programs. (Not like shared memory but any memory the computer has..) Without having to start the application from my own application.. I have seen something like this before but I just can't figure out how it's done.. If I were to access the memory of any running program I would

What is the Cost of an L1 Cache Miss?

▼魔方 西西 提交于 2019-12-04 07:25:23
问题 Edit : For reference purposes (if anyone stumbles across this question), Igor Ostrovsky wrote a great post about cache misses. It discusses several different issues and shows example numbers. End Edit I did some testing <long story goes here> and am wondering if a performance difference is due to memory cache misses. The following code demonstrates the issue and boils it down to the critical timing portion. The following code has a couple of loops that visit memory in random order and then in

Is there fmemopen() in MinGW

依然范特西╮ 提交于 2019-12-04 03:24:21
问题 I'm trying to compile some code that uses the fmemopen function in MinGW. I found out that this function is not available MinGW. I need a function equivalent to fmemopen() . Are there any alternative functions that I can use? 回答1: there are no fmemopen equivalents on win32 because of missing functionality in the kernel, I think cygwin implements it using a temp file like this one: https://github.com/kespindler/python-tesseract/blob/master/util-fmemopen.c 来源: https://stackoverflow.com

Why am I getting this memory access error 'double free or corruption'?

好久不见. 提交于 2019-12-03 03:25:00
I am getting the following type of error. I know it has something to do with me improperly accessing memory, but I don't exactly how. Please help me see where I have gone wrong. *note I have simplified my function and it is not obvious what the variables are doing, I just need to know how I am implementing the function incorrectly or where I am misusing memory access. int my_function(char const *file_name, size_t max) { myStruct.pStore = fopen(file_name,"w+"); //pStore is a FILE* myStruct.max = max; // fill the with zeros ('0') int numberOfZeros = max*SIZE; char zeros[numberOfZeros]; int i=0;

What is the Cost of an L1 Cache Miss?

随声附和 提交于 2019-12-02 13:57:34
Edit : For reference purposes (if anyone stumbles across this question), Igor Ostrovsky wrote a great post about cache misses. It discusses several different issues and shows example numbers. End Edit I did some testing <long story goes here> and am wondering if a performance difference is due to memory cache misses. The following code demonstrates the issue and boils it down to the critical timing portion. The following code has a couple of loops that visit memory in random order and then in ascending address order. I ran it on an XP machine (compiled with VS2005: cl /O2) and on a Linux box

Where is EXC_BAD_ACCESS documented? [closed]

空扰寡人 提交于 2019-12-02 12:51:37
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . One of the more commonplace debugging errors in my own development (Mac, iOS) is EXC_BAD_ACCESS. Despite its commonness, its origin and precise meaning remain mysterious. Google lists many occurrences of the error, but the only explanation I could find is informal and incomplete. I know that this exception (if

Where is EXC_BAD_ACCESS documented? [closed]

眉间皱痕 提交于 2019-12-02 05:33:28
One of the more commonplace debugging errors in my own development (Mac, iOS) is EXC_BAD_ACCESS. Despite its commonness, its origin and precise meaning remain mysterious. Google lists many occurrences of the error, but the only explanation I could find is informal and incomplete. I know that this exception (if that's the proper term for it) means that the code has attempted to access an address to which it does not have read and/or write privileges—the null address, for example, or an address outside of the process's address space. But this is an intuitive interpretation based on my prior