Skip to content

Commit

Permalink
Fix: pass primitive pid to memory limit request (danielpaulus#516)
Browse files Browse the repository at this point in the history
* Fix: pass primitive pid to memory limit request

* simplify reading

---------

Authored-by: fish-sauce <victor.kachalov@saucelabs.com>
  • Loading branch information
kvs-coder authored Nov 19, 2024
1 parent 1fcc2a1 commit 72a4560
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 14 additions & 2 deletions ios/dtx_codec/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,31 @@ func (d *Channel) ReceiveMethodCall(selector string) Message {
// MethodCall is the standard DTX style remote method invocation pattern. The ObjectiveC Selector goes as a NSKeyedArchiver.archived NSString into the
// DTXMessage payload, and the arguments are separately NSKeyArchiver.archived and put into the Auxiliary DTXPrimitiveDictionary. It returns the response message and an error.
func (d *Channel) MethodCall(selector string, args ...interface{}) (Message, error) {
payload, _ := nskeyedarchiver.ArchiveBin(selector)
auxiliary := NewPrimitiveDictionary()
for _, arg := range args {
auxiliary.AddNsKeyedArchivedObject(arg)
}

return d.methodCallWithReply(selector, auxiliary)
}

// MethodCallWithAuxiliary is a DTX style remote method invocation pattern. The ObjectiveC Selector goes as a NSKeyedArchiver.archived NSString into the
// DTXMessage payload, and the primitive arguments put into the Auxiliary DTXPrimitiveDictionary. It returns the response message and an error.
func (d *Channel) MethodCallWithAuxiliary(selector string, aux PrimitiveDictionary) (Message, error) {
return d.methodCallWithReply(selector, aux)
}

func (d *Channel) methodCallWithReply(selector string, auxiliary PrimitiveDictionary) (Message, error) {
payload, _ := nskeyedarchiver.ArchiveBin(selector)
msg, err := d.SendAndAwaitReply(true, Methodinvocation, payload, auxiliary)
if err != nil {
log.WithFields(log.Fields{"channel_id": d.channelName, "error": err, "methodselector": selector}).Info("failed starting invoking method")
return msg, err
}
if msg.HasError() {
return msg, fmt.Errorf("Failed invoking method '%s' with error: %s", selector, msg.Payload[0])
return msg, fmt.Errorf("failed invoking method '%s' with error: %s", selector, msg.Payload[0])
}

return msg, nil
}

Expand Down
4 changes: 3 additions & 1 deletion ios/instruments/processcontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ func NewProcessControl(device ios.DeviceEntry) (*ProcessControl, error) {

// DisableMemoryLimit disables the memory limit of a process.
func (p ProcessControl) DisableMemoryLimit(pid uint64) (bool, error) {
msg, err := p.processControlChannel.MethodCall("requestDisableMemoryLimitsForPid:", pid)
aux := dtx.NewPrimitiveDictionary()
aux.AddInt32(int(pid))
msg, err := p.processControlChannel.MethodCallWithAuxiliary("requestDisableMemoryLimitsForPid:", aux)
if err != nil {
return false, err
}
Expand Down

0 comments on commit 72a4560

Please sign in to comment.