Skip to content
Advertisement

Segmentation fault on memcpy() function [closed]

I have the following memory base address which contains some data of 256 bytes:

JavaScript

Now I have the following array which will store the data from TX_PTR.

JavaScript

When I try to memcpy the data from the memory base address to the array by:

JavaScript

I get a segmentation fault. I am running this code in linux. What could be the problem here?

Advertisement

Answer

I am running freertos and openamp on a zynq board.

From this comment, I am led to believe that the “memory” is implemented in the FPGA’s address space, or that FreeRTOS is running and has written to this memory.

If this is the case, then to access data that is physically located at a point in memory, you need to use mmap().

Linux processes do not sit on phyisical addresses – the MMU will map virtual memory to physical memory.

To get access to physical memory, you need to use mmap() – something like this:

JavaScript

After the call to mmap(), the memory will be available in your process’ virtual address space at the address held in my_memory – don’t use TX_PTR.

Note also, that tx_arr is an array, and thus can be passed as a pointer without using &tx_arr.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement