segmentation-fault

Reading a file to string with mmap

佐手、 提交于 2019-12-18 12:38:28
问题 I'm trying to read a file to a string using mmap. I was following this example: http://www.lemoda.net/c/mmap-example/index.html My code looks like this unsigned char *f; int size; int main(int argc, char const *argv[]) { struct stat s; const char * file_name = argv[1]; int fd = open (argv[1], O_RDONLY); /* Get the size of the file. */ int status = fstat (fd, & s); size = s.st_size; f = (char *) mmap (0, size, PROT_READ, 0, fd, 0); for (i = 0; i < size; i++) { char c; c = f[i]; putchar(c); }

Reading a file to string with mmap

流过昼夜 提交于 2019-12-18 12:38:06
问题 I'm trying to read a file to a string using mmap. I was following this example: http://www.lemoda.net/c/mmap-example/index.html My code looks like this unsigned char *f; int size; int main(int argc, char const *argv[]) { struct stat s; const char * file_name = argv[1]; int fd = open (argv[1], O_RDONLY); /* Get the size of the file. */ int status = fstat (fd, & s); size = s.st_size; f = (char *) mmap (0, size, PROT_READ, 0, fd, 0); for (i = 0; i < size; i++) { char c; c = f[i]; putchar(c); }

PHPUnit Segmentation fault

本秂侑毒 提交于 2019-12-18 11:19:35
问题 When a PHPUnit test fails normally on my dev box (Linux Mint), it causes a "Segmentation Fault" on my Continous Integration box (Centos). Both machines are running the same version of PHPUnit. My dev box is running PHP 5.3.2-1ubuntu4.9, and the CI is PHP 5.2.17. I'd rather leave upgrading the PHP as a last resort though. As per this thread: PHPUnit gets segmentation fault I have tried deactivating / reinstalling Xdebug. I don't have inclue.so installed. On the CI box I currently only have two

segmentation fault vs page fault

六眼飞鱼酱① 提交于 2019-12-18 10:22:10
问题 I was wondering what differences and relations are between segmentation fault and page fault? Does segmentation fault only belong to segmented memory model? Does page fault only belong to paged memory model? If both are yes, since most computer systems such as x86 and Linux use paged memory model instead of segmented memory model, why does GCC C compiler sometimes report segmentation fault error? Thanks and regards! 回答1: These two things are very dissimilar, actually. A segmentation fault

Segmentation fault [duplicate]

冷暖自知 提交于 2019-12-18 09:26:50
问题 This question already has an answer here : Closed 8 years ago . Possible Duplicate: Segmentation fault in btree implementation I get an error like this, How can I debug it? Can you please give some some method to debug this error: *** glibc detected *** ./a.out: free(): invalid pointer: 0x0821b158 *** ======= Backtrace: ========= /lib/tls/i686/cmov/libc.so.6(+0x6b591)[0xbd7591] /lib/tls/i686/cmov/libc.so.6(+0x6cde8)[0xbd8de8] /lib/tls/i686/cmov/libc.so.6(cfree+0x6d)[0xbdbecd] ./a.out

C SIGSEGV Handler & Mprotect

戏子无情 提交于 2019-12-18 05:09:12
问题 I'm constructing a program which uses mprotect() to restrict a block of memory from accessing. When the memory is requested, a SIGSEGV is thrown which I listen for using a signal() call. Once the SIGSEGV has been detected, I need to somehow access the pointer to the memory that was requested (that threw the fault) and the size of the segment requested. Is this possible? void fifoSigHandler(){ // Needs to only remove protection from requested block of virtual memory mprotect(fifoVm,(size_t

x86 memory access segmentation fault

五迷三道 提交于 2019-12-18 05:04:09
问题 I am learning x86 assembly out of curiosity. I'm currently using a Linux based OS with the NASM assembler. I am having a difficult time understanding why SECTION .text global _start _start: nop mov ebx, 25 mov [0xFFF], ebx ;Exit the program mov eax, 1 mov ebx, 0 int 0x80 Would lead to a segmentation fault (when moving the contents of the ebx register to memory location 0xFFF). I was thinking that building a program in pure asm would give me unrestricted access to my process' virtual address

x86 memory access segmentation fault

谁说我不能喝 提交于 2019-12-18 05:04:07
问题 I am learning x86 assembly out of curiosity. I'm currently using a Linux based OS with the NASM assembler. I am having a difficult time understanding why SECTION .text global _start _start: nop mov ebx, 25 mov [0xFFF], ebx ;Exit the program mov eax, 1 mov ebx, 0 int 0x80 Would lead to a segmentation fault (when moving the contents of the ebx register to memory location 0xFFF). I was thinking that building a program in pure asm would give me unrestricted access to my process' virtual address

Node.js source code build giving segmentation fault on ARM

天涯浪子 提交于 2019-12-18 04:05:34
问题 tl;dr: I tried to install node.js on my ARMv7-based Cubox running Ubuntu 12.10 (quantal). When compiling node.js from source (see "Second attempt" below), node produces a segmentation fault. What can I do here? First attempt First of all, I tried to install node.js via the package manager, following the instructions for Ubuntu that are given here: Installing Node.js via package manager: Ubuntu, Mint Adding the repository mentioned there using sudo add-apt-repository ppa:chris-lea/node.js

Pointer-array-extern question

為{幸葍}努か 提交于 2019-12-17 22:35:27
问题 File 1.c int a[10]; File main.c: extern int *a; int main() { printf("%d\n", a[0]); return 0; } Gives me a segfault! What's going wrong? 回答1: Arrays decompose, or are implicitly converted to pointers when passed to a function as an argument, or when converted to an r-value on the right-hand-side of the assignment operator. So something like: int array[10]; int* a = array; //implicit conversion to pointer to type int void function(int* a); function(array); //implicit conversion to pointer to