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

Fix: pass primitive pid to memory limit request #516

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions ios/dtx_codec/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,36 @@ 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)
diegoperini marked this conversation as resolved.
Show resolved Hide resolved
}

return d.methodCallWithReply(selector, auxiliary)
}

// MethodCallPrimitive 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) MethodCallPrimitive(selector string, args ...int) (Message, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the name is a bit misleading as now the only option is to pass int (or actually int32) args. Should we rather have the method take the already constructed auxiliary like

func (d *Channel) MethodCallWithAuxiliary(selector string, aux PrimitiveDictionary) (Message, error) {
	return d.methodCallWithReply(selector, aux)
}

and in DisableMemoryLimit

	aux := dtx.NewPrimitiveDictionary()
	aux.AddInt32(int(pid))
	msg, err := p.processControlChannel.MethodCallWithAuxiliary("requestDisableMemoryLimitsForPid:", aux)

auxiliary := NewPrimitiveDictionary()
for _, arg := range args {
auxiliary.AddInt32(arg)
}

return d.methodCallWithReply(selector, auxiliary)
}

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
2 changes: 1 addition & 1 deletion ios/instruments/processcontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ 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)
msg, err := p.processControlChannel.MethodCallPrimitive("requestDisableMemoryLimitsForPid:", int(pid))
if err != nil {
return false, err
}
Expand Down
Loading