bus-error

How to get a “bus error”?

流过昼夜 提交于 2019-12-01 02:36:09
I am trying very hard to get a bus error. One way is misaligned access and I have tried the examples given here and here , but no error for me - the programs execute just fine. Is there some situation which is sure to produce a bus error? Bus errors can only be invoked on hardware platforms that: Require aligned access, and Don't compensate for an unaligned access by performing two aligned accesses and combining the results. You probably do not have access to such a system. This should reliably result in a SIGBUS on a POSIX-compliant system. #include <unistd.h> #include <stdio.h> #include <sys

Dereferencing function pointers in C to access CODE memory

橙三吉。 提交于 2019-11-30 20:21:41
We are dealing with C here. I'm just had this idea, wondering if it is possible to access the point in memory where a function is stored, say foo and copying the contents of the function to another point in memory. Specifically, I'm trying to get the following to work: #include <stdlib.h> #include <stdio.h> #include <string.h> void foo(){ printf("Hello World"); } int main(){ void (*bar)(void) = malloc(sizeof foo); memcpy(&bar, &foo, sizeof foo); bar(); return 0; } But running it gives a bus error: Bus error: 10 . I'm trying to copy over the contents of function foo into a space of memory bar

Calling callback from node.js native code

喜你入骨 提交于 2019-11-29 17:16:29
I'm writing an add-on for node.js using c++. here some snippets: class Client : public node::ObjectWrap, public someObjectObserver { public: void onAsyncMethodEnds() { Local<Value> argv[] = { Local<Value>::New(String::New("TheString")) }; this->callback->Call(Context::GetCurrent()->Global(), 1, argv); } .... private: static v8::Handle<v8::Value> BeInitiator(const v8::Arguments& args) { HandleScope scope; Client* client = ObjectWrap::Unwrap<Client>(args.This()); client->someObject->asyncMethod(client, NULL); return scope.Close(Boolean::New(true)); } static v8::Handle<v8::Value> SetCallback

Bus error vs Segmentation fault

给你一囗甜甜゛ 提交于 2019-11-28 19:44:49
问题 Difference between a bus error and a segmentation fault? Can it happen that a program gives a seg fault and stops for the first time and for the second time it may give a bus error and exit ? 回答1: On most architectures I've used, the distinction is that: a SEGV is caused when you access memory you're not meant to (e.g., outside of your address space). a SIGBUS is caused due to alignment issues with the CPU (e.g., trying to read a long from an address which isn't a multiple of 4). 回答2: SIGBUS

I feel confusion about bus error in string (C)

流过昼夜 提交于 2019-11-28 11:52:07
I feel confusion about the swap two characters in one string with C. It works well when I set it as an array: char strBase[8] = "acbdefg"; in this case I could swap any character. But it trigger the bus error when I set it as a string: char *strBase = "acbdefg"; Thanks a lot for anyone could explain it or give me some hint! The difference here is that char *strBase = "acbdefg"; will place acbdefg in the read-only parts of the memory and making strBase a pointer to that, making any writing operation on this memory illegal. It has no name and has static storage duration (meaning that it lives

Calling callback from node.js native code

那年仲夏 提交于 2019-11-28 11:26:17
问题 I'm writing an add-on for node.js using c++. here some snippets: class Client : public node::ObjectWrap, public someObjectObserver { public: void onAsyncMethodEnds() { Local<Value> argv[] = { Local<Value>::New(String::New("TheString")) }; this->callback->Call(Context::GetCurrent()->Global(), 1, argv); } .... private: static v8::Handle<v8::Value> BeInitiator(const v8::Arguments& args) { HandleScope scope; Client* client = ObjectWrap::Unwrap<Client>(args.This()); client->someObject->asyncMethod

I feel confusion about bus error in string (C)

风流意气都作罢 提交于 2019-11-27 06:34:20
问题 I feel confusion about the swap two characters in one string with C. It works well when I set it as an array: char strBase[8] = "acbdefg"; in this case I could swap any character. But it trigger the bus error when I set it as a string: char *strBase = "acbdefg"; Thanks a lot for anyone could explain it or give me some hint! 回答1: The difference here is that char *strBase = "acbdefg"; will place acbdefg in the read-only parts of the memory and making strBase a pointer to that, making any

Debugging SIGBUS on x86 Linux

此生再无相见时 提交于 2019-11-27 04:50:29
What can cause SIGBUS (bus error) on a generic x86 userland application in Linux? All of the discussion I've been able to find online is regarding memory alignment errors, which from what I understand doesn't really apply to x86. (My code is running on a Geode , in case there are any relevant processor-specific quirks there.) You can get a SIGBUS from an unaligned access if you turn on the unaligned access trap, but normally that's off on an x86. You can also get it from accessing a memory mapped device if there's an error of some kind. Your best bet is using a debugger to identify the

Debugging SIGBUS on x86 Linux

江枫思渺然 提交于 2019-11-26 11:18:30
问题 What can cause SIGBUS (bus error) on a generic x86 userland application in Linux? All of the discussion I\'ve been able to find online is regarding memory alignment errors, which from what I understand doesn\'t really apply to x86. (My code is running on a Geode, in case there are any relevant processor-specific quirks there.) 回答1: You can get a SIGBUS from an unaligned access if you turn on the unaligned access trap, but normally that's off on an x86. You can also get it from accessing a

What is a bus error?

喜夏-厌秋 提交于 2019-11-26 01:34:58
问题 What does the \"bus error\" message mean, and how does it differ from a segfault? 回答1: Bus errors are rare nowadays on x86 and occur when your processor cannot even attempt the memory access requested, typically: using a processor instruction with an address that does not satisfy its alignment requirements. Segmentation faults occur when accessing memory which does not belong to your process, they are very common and are typically the result of: using a pointer to something that was