I'm reading some runtime of code of golang(go1.6.2 linux/amd64), Could someone help me to understand the underlying mechanism of getg() function in runtime/stubs.go file?
// getg returns the pointer to the current g.
// The compiler rewrites calls to this function into instructions
// that fetch the g directly (from TLS or from the dedicated register).
func getg() *g
how do the getg() function operate here? What is the body of this function?
See Function signature with no function body, and the specification for Function Declarations.
In the case of runtime.getg the code is directly emitted by the compiler.
It's not being executed—exactly because, as stated in the comment
The compiler rewrites calls to this function into instructions
that fetch the g directly (from TLS or from the dedicated register).
As you can obtain yourself via something like
grep -rFw getg /usr/share/go-1.7/src/
the code which is emitted when the compiler sees a call to runtime.getg()
is architecture-dependent and is located in the files
{src}/src/cmd/compile/internal/{arch}/ggen.go
(for Go 1.7)—where {src} is the source directory of your Go code
and {arch} is an architecture-specific directory.
Say, for amd64, it's {src}/cmd/compile/internal/amd64/ggen.go.
Related
I am using a 3rd party library that invokes a Core Foundation function.
Since that lib has a bug, passing incorrect values to a CF function, I need to intercept that call to fix the passed values.
How do I hook into the CF function call so that I can look at the passed parameters, change them and then call the actual (original) function?
I have the impression I can get to the actual function with the CFBundleGetFunctionPointerForName, passing CFBundleGetMainBundle()as the first parameter and the name of the CF function as the second parameter.
In my particular case, that would be:
void *p = CFBundleGetFunctionPointerForName (CFBundleGetMainBundle(), "CFRunLoopTimerCreate");
But that returns NULL.
I also tried this:
void *p = CFBundleGetFunctionPointerForName (CFBundleGetBundleWithIdentifier("com.apple.Cocoa"), "CFRunLoopTimerCreate");
That returns a non-null value but it still does not appear to be a pointer I could change but rather the actual starting address of the function's code.
So, how do I get an address of a function pointer to an imported API function that I can save and then change to point to my intercepting function? Or how else could I hook into an imported function?
CFBundleGetFunctionPointerForName will just return the address of a function in a given bundle; this will never let you change the destination of calls to the function. If you really want to do something like that, please refer to Is it possible to hook API calls on Mac OS? Note that this is highly not recommended.
After doing promisify on a specific function with bluebird - is it possible to get a reference to the original function that was promisified?
Why: I'm using a helper that gets argument names from the function and on promisified functions it gives back (_arg0, _arg1, _arg2), I was hoping it was possible to get the original function signature from somewhere.
No, you can work around it though.
If it is promisified with promisifyAll you can access it without the Async suffix - otherwise, you'd have to do it yourself:
var promisified = Promise.promisify(cbFunction);
promisified.original = cbFunction;
// access as promisified.cbFunction from that point on.
Otherwise, the original function is captured via a closure and you can't reliably access it. In all honesty you probably shouldn't since that'd meddle with minification anyway.
There are lots of gcc attributes one can assign to variables/functions these days. I have gone through the gcc documentation and I haven't found what I am looking for -- or may be I missed it. Hence the question.
What I am looking for is some mechanism when using gcc, that a function 'X' be called when function 'f' enters and function 'Y' be called when function 'f' exits. Basically I have lot of code currently that does following and I am wondering if the LOCK/UNLOCK could be done "automatically" through some kind of attribute.
f() {
LOCK_RESOURCE();
UNLOCK_RESOURCE();
}
You're looking for __attribute__((cleanup)):
The cleanup attribute runs a function when the variable goes out of scope. This attribute can only be applied to auto function scope variables; it may not be applied to parameters or variables with static storage duration. The function must take one parameter, a pointer to a type compatible with the variable. The return value of the function (if any) is ignored.
how to debug built-in js files in v8.(i.e v8natives.js,array.js,string.js)
Please let me know any documentations or insights regarding this.
Thanks
You can call %GlobalPrint("hello");, the argument must be converted to a string before you pass it (So don't call %GlobalPrint(1) but %GlobalPrint("1") and it only takes one argument.
List of the functions you can call is at runtime/runtime.h (with their implementations and possibly some documentation in the runtime .cc files), these are on top of the normal javascript functions you can call like JSON.parse.
For example in the apinatives.js file:
function InstantiateFunction(data, name) {
// We need a reference to kApiFunctionCache in the stack frame
// if we need to bail out from a stack overflow.
%GlobalPrint("Called instantiate function with ");
%DebugPrint(data);
%GlobalPrint("and");
%DebugPrint(name);
...
}
i want to find that place and set a flag in that request so i can identify these requests in block io layer.
i changed bio structure and add an extra flag and i want to set this flag for all indirect block requests which sent to disk.
I believe what you are looking for is
the call to ext3_get_branch in /fs/ext3/inode.c is what you are looking for.
which reads the chain of indirect blocks leading to data.
The call trace up to the read syscall is as follows:
/fs/ext3/inode.c
ext3_get_branch is called by ext3_get_blocks_handle
ext3_get_blocks_handle is called by ext3_get_block
ext3_get_block is passed as function pointer to be called by mpage_readpage in /fs/mpage.c by ext3_readpage
/mm/filemap.c
ext3_readpage is called by mapping->a_ops->readpage(filp, page); in do_generic_file_read
do_generic_file_read is called by generic_file_aio_read
/fs/read_write.c
generic_file_aio_read is called by ret = filp->f_op->aio_read(&kiocb, &iov, 1, kiocb.ki_pos);`` indo_sync_readwhere filp->f_op->aio_readis the function pointer ofgeneric_file_aio_read` defined in /fs/ext3/inode.c
do_sync_read is mapped to the read system call in the struct definition of generic_ro_fops.