On Thu, Mar 31, 2016 at 7:52 AM, Yichao Yu <[email protected]> wrote:
> On Thu, Mar 31, 2016 at 5:23 AM, Laurent Bartholdi
> <[email protected]> wrote:
>> Thanks for the quick reply! Yes, that would be wonderful.
>>
>> I want to interface to a library that has its own garbage collection; that
>> library walks the stack to find potential objects that must be kept alive.
>> Therefore, all calls to that library must be done in the form
>>   library_global_StackBottomBags = __builtin_frame_address(0);
>>   library_function(...)
>
>
> OK, this is a reasonable use case if the library requires this....
> It's a weird API though.
>
> You can use llvm intrinsics to do that. This is basically how
> `__builtin_frame_address` is implemented in clang.
>
> julia> function f()
>            Base.llvmcall(("""
>                           declare i8 *@llvm.frameaddress(i32)
>                           """, """
>                           %1 = call i8 *@llvm.frameaddress(i32 0)
>                           ret i8 *%1
>                           """), Ptr{UInt8}, Tuple{})
>        end
> f (generic function with 1 method)
>
> julia> f()
> Ptr{UInt8} @0x00007ffecb9a3130
>

Note that this is 0.5 only.

You can hack sth to work on 0.4

```
julia> f(p) = p
f (generic function with 1 method)

julia> g() = ccall(cfunction(f, Ptr{Void}, Tuple{Ptr{Void}}),
Ptr{Void}, (Ptr{Int},), &1)
g (generic function with 1 method)

julia> g()
Ptr{Void} @0x00007ffe4ec24920
```

>
>
>>
>>
>> On Thursday, 31 March 2016 00:25:13 UTC+2, Yichao Yu wrote:
>>>
>>>
>>> On Mar 30, 2016 6:22 PM, "Yichao Yu" <[email protected]> wrote:
>>> >
>>> >
>>> > On Mar 30, 2016 6:21 PM, "Laurent Bartholdi" <[email protected]>
>>> > wrote:
>>> > >
>>> > > Hi,
>>> > > Is there a way to obtain the address of the current stack frame (the
>>> > > ebp register on x86 processors)?
>>> > >
>>> > > In GCC, there's the bultin primitive __builtin_frame_address() that
>>> > > does precisely that.
>>> >
>>> > Why do you want this?
>>> >
>>>
>>> It's possible but should not be done in general.
>>>
>>> > >
>>> > > Many thanks in advance, Laurent

Reply via email to