Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid memory operations in the IDE #503

Open
svspire opened this issue Jul 1, 2024 · 2 comments
Open

Invalid memory operations in the IDE #503

svspire opened this issue Jul 1, 2024 · 2 comments
Labels
darwin help wanted ide Issues in the CCL IDE

Comments

@svspire
Copy link
Contributor

svspire commented Jul 1, 2024

In the IDE in CCL 1.12.2 DarwinX8664, assuming there is some editor window open behind the listener, (describe (gui::target)) consistently throws 'invalid memory operation' . Usually it thows to the Altconsole, from which it is rarely recoverable without restarting CCL.

Narrowing this down a bit:
(slot-value (gui::target) 'NS:_SIZE-LIMITS)
consistently throws an error in the Listener.

But that's only one of the problems.

Further clue:
(slot-value (gui::target) 'NS:_FRAME) ; doesn't throw an error, but it returns nonsense float values

The following two patches completely fix the error throws:

;;; Pretty sure the standard definition of nsobject-description is causing crashes
(defun ccl::nsobject-description (nsobject)
  (if (ccl::initialized-nsobject-p nsobject)
      "initialized generic nsobject"
      "uninitialized generic nsobject"))

; Without this patch, following form throws an error:
; (slot-value  (gui::target) 'NS:_SIZE-LIMITS)
(defmethod print-object ((s ns::ns-size) stream)
  (flet ((maybe-round (x)
           (multiple-value-bind (q r) (round x)
             (if (zerop r) q x))))
    (unless nil ; (ccl::%null-ptr-p s)
      (print-unreadable-object (s stream :type t :identity t)
        (format stream "~s X ~s"
                "foo" ;(maybe-round (ns::ns-size-width s)) ; <-- these are the problem
                "bar" ;(maybe-round (ns::ns-size-height s))
                )))
    (ccl::describe-macptr-allocation-and-address s stream)
    ))

With the above two dummy redefinitions, (describe (gui::target)) does not crash.
But those patches are useless beyond stopping the errors because they fail to return enough information or they return nonsense.

I need help tracking this down. Obviously I'd like to fix the above issues, but there's also a systemic problem that has crept in some time over the last few versions of MacOS that's causing our assumptions about how to inspect ObjC objects to fail. I'd like to fix the systemic issue.

@svspire svspire added help wanted darwin ide Issues in the CCL IDE labels Jul 1, 2024
@xrme
Copy link
Member

xrme commented Oct 24, 2024

I was reading https://github.com/apple-oss-distributions/objc4/blob/89543e2c0f67d38ca5211cea33f42c51500287d5/runtime/objc-runtime-new.mm#L9321 and there's now a thing called an extended tagged pointer.

/***********************************************************************
* Tagged pointer objects.
*
* Tagged pointer objects store the class and the object value in the
* object pointer; the "pointer" does not actually point to anything.
*
* Tagged pointer objects currently use this representation:
* (LSB)
*  1 bit   set if tagged, clear if ordinary object pointer
*  3 bits  tag index
* 60 bits  payload
* (MSB)
* The tag index defines the object's class.
* The payload format is defined by the object's class.
*
* If the tag index is 0b111, the tagged pointer object uses an
* "extended" representation, allowing more classes but with smaller payloads:
* (LSB)
*  1 bit   set if tagged, clear if ordinary object pointer
*  3 bits  0b111
*  8 bits  extended tag index
* 52 bits  payload
* (MSB)
*
* Some architectures reverse the MSB and LSB in these representations.
*
* This representation is subject to change. Representation-agnostic SPI is:
* objc-internal.h for class implementers.
* objc-gdb.h for debuggers.
**********************************************************************/

https://github.com/apple-oss-distributions/objc4/blob/89543e2c0f67d38ca5211cea33f42c51500287d5/runtime/objc-gdb.h#L230 has a comment about that.

I wonder if we need to deal with that case. (I haven't actually looked; I'm just noting that here in this issue in the hopes that I or someone can look at it later.)

If we could somehow manage to stick to the published Objective-C runtime API (e.g., object_getClassName), that would be great, because they already deal with the tagged pointer case

@svspire
Copy link
Contributor Author

svspire commented Oct 24, 2024

See #299 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
darwin help wanted ide Issues in the CCL IDE
Projects
None yet
Development

No branches or pull requests

2 participants