memory-alignment

Linux on arm64: sendto causes “Unhandled fault: alignment fault (0x96000021)” when sending data from mmapped coherent DMA buffer

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 13:27:47
I'm building a data acquisition system based on the UltraScale+ FPGA equipped with arm64 CPU. The data are transmitted to RAM via DMA. The DMA buffers in the driver are reserved as below: virt_buf[i] = dma_zalloc_coherent(&pdev->dev, BUF_SIZE, &phys_buf[i],GFP_KERNEL); In the driver's mmap function, the mapping to the user space is done in the following way: #ifdef ARCH_HAS_DMA_MMAP_COHERENT printk(KERN_INFO "Mapping with dma_map_coherent DMA buffer at phys: %p virt %p\n",phys_buf[off],virt_buf[off]); res = dma_mmap_coherent(&my_pdev->dev, vma, virt_buf[off], phys_buf[off], vsize); #else

Is it guaranteed that Complex Float variables will be 8-byte aligned in memory?

谁说我不能喝 提交于 2019-12-01 13:02:37
In C99 the new complex types were defined. I am trying to understand whether a compiler can take advantage of this knowledge in optimizing memory accesses. Are these objects ( A - F ) of type complex float guaranteed to be 8-byte aligned in memory? #include "complex.h" typedef complex float cfloat; cfloat A; cfloat B[10]; void func(cfloat C, cfloat *D) { cfloat E; cfloat F[10]; } Note that for D , the question relates to the object pointed to by D , not to the pointer storage itself. And, if that is assumed aligned, how can one be sure that the address passed is of an actual complex and not a

Linux on arm64: sendto causes “Unhandled fault: alignment fault (0x96000021)” when sending data from mmapped coherent DMA buffer

故事扮演 提交于 2019-12-01 09:42:44
问题 I'm building a data acquisition system based on the UltraScale+ FPGA equipped with arm64 CPU. The data are transmitted to RAM via DMA. The DMA buffers in the driver are reserved as below: virt_buf[i] = dma_zalloc_coherent(&pdev->dev, BUF_SIZE, &phys_buf[i],GFP_KERNEL); In the driver's mmap function, the mapping to the user space is done in the following way: #ifdef ARCH_HAS_DMA_MMAP_COHERENT printk(KERN_INFO "Mapping with dma_map_coherent DMA buffer at phys: %p virt %p\n",phys_buf[off],virt

Structure assignment in Linux fails in ARM but succeeds in x86

依然范特西╮ 提交于 2019-12-01 09:08:09
I've noticed something really strange. say I've got the following structure defined typedef struct { uint32_t a; uint16_t b; uint32_t c; } foo; This structure is contained in a big buffer I receive from network. The following code works in x86, but I receive SIGBUS on ARM. extern void * buffer; foo my_foo; my_foo = (( foo * ) buffer)[0]; replacing the pointer dereferencing with memcpy solved the issue. Searching about SIGBUS in ARM pointed me to the fact that this is related to memory alignment somwhow. Can someone explain what's going on ? You said it yourself: there are memory alignment

Win32 memory allocation with large alignment

有些话、适合烂在心里 提交于 2019-12-01 08:52:31
I need to allocate large regions of memory (megabytes) with large alignments (also potentially in the megabyte range). The VirtualAlloc family of functions don't seem to provide options to do this. What I do on Linux to achieve this is to mmap a larger region - large enough to guarantee that a sufficiently large region with the required alignment will be contained in it - and then munmap the regions at the beginning and the end of the large region that are not needed. As an example, let's say I need 4 megabytes, aligned on a 1 megabyte boundary (i.e. the start of the region having zeroes in

Output from arbitrary dereferenced pointer

微笑、不失礼 提交于 2019-12-01 08:20:34
I fill the memory as follows: char buf[8] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; And than put the unsigned long pointer in turn on first 5 bytes and output result: char *c_ptr; unsigned long *u_ptr; c_ptr = buf; for (int i=0;i<5;i++) { u_ptr = (unsigned long *)c_ptr; printf("%X\n",*u_ptr); c_ptr++; } When I execute this code on my x64 plaform I get what I expected: 44332211 55443322 66554433 77665544 88776655 But when I execute the same code on ARM platform I get following: 44332211 11443322 22114433 33221144 88776655 I.e. it get bound every 4 byte and dereference only 4 bytes

Win32 memory allocation with large alignment

半城伤御伤魂 提交于 2019-12-01 07:57:45
问题 I need to allocate large regions of memory (megabytes) with large alignments (also potentially in the megabyte range). The VirtualAlloc family of functions don't seem to provide options to do this. What I do on Linux to achieve this is to mmap a larger region - large enough to guarantee that a sufficiently large region with the required alignment will be contained in it - and then munmap the regions at the beginning and the end of the large region that are not needed. As an example, let's say

Output from arbitrary dereferenced pointer

末鹿安然 提交于 2019-12-01 07:52:44
问题 I fill the memory as follows: char buf[8] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; And than put the unsigned long pointer in turn on first 5 bytes and output result: char *c_ptr; unsigned long *u_ptr; c_ptr = buf; for (int i=0;i<5;i++) { u_ptr = (unsigned long *)c_ptr; printf("%X\n",*u_ptr); c_ptr++; } When I execute this code on my x64 plaform I get what I expected: 44332211 55443322 66554433 77665544 88776655 But when I execute the same code on ARM platform I get following:

What's the purpose of unnamed bit field at the end of structure

风流意气都作罢 提交于 2019-12-01 07:10:49
I am learning C. In C Primer Plus , I saw an bit field example as follows: struct box_props { bool opaque : 1; unsigned int fill_color : 3; unsigned int : 4; bool show_border : 1; unsigned int border_color : 3; unsigned int border_style : 2; unsigned int : 2; }; I do understand the 4-bit unnamed bit field in the middle is used for letting the following bits start at a new byte. However, I don't understand why there is another unnamed bit field at the end of the structure. What's the purpose of it? Is it necessary? Is it necessary? Nope, it's optional. What's the purpose of it? Here's what the

Why aligning of long long union member is bigger than the containing union/struct? Is this correct?

自作多情 提交于 2019-12-01 03:42:54
From this question one could start to believe that alignment of a union is not less than the largest alignment of it's individual members. But I have a problem with the long long type in gcc/g++. The full example can be found here , but here are the relevant parts for my question: union ull { long long m; }; struct sll { long long m; }; int main() { #define pr(v) cout << #v ": " << (v) << endl pr(sizeof(long long)); pr(__alignof__(long long)); pr(sizeof(ull)); pr(__alignof__(ull)); pr(sizeof(sll)); pr(__alignof__(sll)); }; This results in the following output: sizeof(long long): 8 __alignof__