This is expected. FunctionCallbackInfo instances are rarely constructed via
C++ `new`; instead they are usually created manually on the stack. So
adding a field to the class definition is going to be a lot of work, and
that field's type can't be a std::string -- it would have to be something
where you have precise control over the object layout.

I would suggest that you explore alternative approaches.


On Fri, Mar 27, 2020 at 6:21 AM L TY <n0b0dy...@gmail.com> wrote:

> Hi everyone,
>
> For some research reason, I need to log all property access to Blink in
> v8. Since all the property load information is passed to Blink through
> class `FunctionCallbackInfo`, I tried to add a pointer field in this class
> to hold the property name (represented as std::string) like follow:
>
>       V8_INLINE FunctionCallbackInfo(internal::Address* implicit_args,
>                                  internal::Address* values, int length);
>   internal::Address* implicit_args_;
>   internal::Address* values_;
>   int length_;
>   std::string* property_info_; // The field I add.
>
> }
>
> The `property_info_` field is initialized in the constructor function
> through c++ `new`.
> I also added a const setter function for the `property_info_` field. The
> setter function like follow:
>
> void FunctionCallbackInfo<T>::SetPropertyInfo(::std::string s) const {
>   *property_info_ = s;
> }
>
> In Blink, I modified the template file to set this field every time an
> attribute in Blink is visited.
> In code snips I write by myself,  it works well. However, when I try to
> run the code on some real-world websites, I found that the value of the
> field property_info_ is set to a strange value 0x38, so the pointer to the
> string is overlapped by some other value.
> I tried to mark the property_info_ field as private and even moved it to
> class `ReturnValue<T>`, the overlapping case still happens:
>
> template<typename T>
> class ReturnValue {
>  public:
>   template <class S> V8_INLINE ReturnValue(const ReturnValue<S>& that)
>       : value_(that.value_) {
>     TYPE_CHECK(T, S);
>   }
>   // Local setters
>   template <typename S>
>   V8_INLINE void Set(const Global<S>& handle);
>   template <typename S>
>   V8_INLINE void Set(const TracedGlobal<S>& handle);
>   template <typename S>
>   V8_INLINE void Set(const Local<S> handle);
>   // Fast primitive setters
>   V8_INLINE void Set(bool value);
>   V8_INLINE void Set(double i);
>   V8_INLINE void Set(int32_t i);
>   V8_INLINE void Set(uint32_t i);
>   // Fast JS primitive setters
>   V8_INLINE void SetNull();
>   V8_INLINE void SetUndefined();
>   V8_INLINE void SetEmptyString();
>   // Convenience getter for Isolate
>   V8_INLINE Isolate* GetIsolate() const;
>
>   // Pointer setter: Uncompilable to prevent inadvertent misuse.
>   template <typename S>
>   V8_INLINE void Set(S* whatever);
>
>   // Getter. Creates a new Local<> so it comes with a certain performance
>   // hit. If the ReturnValue was not yet set, this will return the
> undefined
>   // value.
>   V8_INLINE Local<Value> Get() const;
>   // use for taint map by n0b0dy
>   V8_INLINE internal::Address GetValueAddr() const;
>
>   V8_INLINE void SetProperty(std::string) const; // The setter function I
> add
>
>  private:
>   template<class F> friend class ReturnValue;
>   template<class F> friend class FunctionCallbackInfo;
>   template<class F> friend class PropertyCallbackInfo;
>   template <class F, class G, class H>
>   friend class PersistentValueMapBase;
>   V8_INLINE void SetInternal(internal::Address value) { *value_ = value; }
>   V8_INLINE internal::Address GetDefaultValue();
>   V8_INLINE explicit ReturnValue(internal::Address* slot);
>   internal::Address* value_;
>   internal::Address* property_info_; // the field I add
> };
>
>
>
> I read the in
> https://source.chromium.org/chromium/chromium/src/+/master:v8/src/builtins/x64/builtins-x64.cc;drc=34ad93361f96ad875bf350ced27e15b7aa126113;bpv=1;bpt=1;l=3317
> and found that v8 will arrange the stack frame with its own call
> convention, But I didn't find why the pointer value is still overlapped in
> class ReturnValue.
>
> Does anyone have ideas about what should I do?
>
> Thanks a lot!
>
> --
> --
> v8-dev mailing list
> v8-dev@googlegroups.com
> http://groups.google.com/group/v8-dev
> ---
> You received this message because you are subscribed to the Google Groups
> "v8-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to v8-dev+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/v8-dev/96c9afe2-5c55-40fc-86b6-9f34de988809%40googlegroups.com
> <https://groups.google.com/d/msgid/v8-dev/96c9afe2-5c55-40fc-86b6-9f34de988809%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
-- 
v8-dev mailing list
v8-dev@googlegroups.com
http://groups.google.com/group/v8-dev
--- 
You received this message because you are subscribed to the Google Groups 
"v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-dev/CAKSzg3QaT%2BOhfDriONiem%3DuSQSdoWYeg9zTkoFKvzKHbQvPGhw%40mail.gmail.com.

Reply via email to