Re: AfxIsValidAddress

2015-07-18 Thread Kyle Sluder
On Tue, Jul 14, 2015, at 12:09 PM, Wim Lewis wrote:
 It checks whether a given address range is mapped (or equivalent
 terminology on Windows). Windows has another function that programmers
 like to use, IsBadReadPtr(), that does something similar.

Raymond Chen (compatibility engineer at Microsoft) elaborates a little
more on what something similar actually means:
http://blogs.msdn.com/b/oldnewthing/archive/2006/09/27/773741.aspx

:P

--Kyle Sluder
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

AfxIsValidAddress

2015-07-14 Thread Raglan T. Tiger
Is there a Cocoa or OS X equivalent to the Windows function AfxIsValidAddress ?

Or, is this even a valid consideration for OS X?

-rags



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: AfxIsValidAddress

2015-07-14 Thread Wim Lewis

On Jul 14, 2015, at 9:44 AM, Jens Alfke j...@mooseyard.com wrote:
 On Jul 14, 2015, at 9:13 AM, Raglan T. Tiger r...@crusaderrabbit.net wrote:
 
 Is there a Cocoa or OS X equivalent to the Windows function 
 AfxIsValidAddress ?
 
 I don’t know, I’m not a Windows programmer. It would help if you told us what 
 that function does.


It checks whether a given address range is mapped (or equivalent terminology on 
Windows). Windows has another function that programmers like to use, 
IsBadReadPtr(), that does something similar.

It's possible to get this information by making some Mach API calls, but unless 
you're doing something pretty exotic, there isn't a good reason to do it. It's 
better to construct your program such that you know the memory region is valid; 
if it isn't valid, you know your program state is corrupt, and the right thing 
to do in that case is crash and send a crashdump to the developer so that it 
can be fixed. If you don't know (with enough certainty to omit a call to 
IsValidAddress) whether a pointer is readable, you certainly don't know whether 
the data there is what you expect to be there. Memory regions get reused a lot.



Wim Lewis / w...@omnigroup.com



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: AfxIsValidAddress

2015-07-14 Thread Jens Alfke

 On Jul 14, 2015, at 9:13 AM, Raglan T. Tiger r...@crusaderrabbit.net wrote:
 
 Is there a Cocoa or OS X equivalent to the Windows function AfxIsValidAddress 
 ?

I don’t know, I’m not a Windows programmer. It would help if you told us what 
that function does.

—Jens
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: AfxIsValidAddress

2015-07-14 Thread Scott Ribe
On Jul 14, 2015, at 10:44 AM, Jens Alfke j...@mooseyard.com wrote:
 
 I don’t know, I’m not a Windows programmer. It would help if you told us what 
 that function does.

It appears to be a placebo for debugging memory problems:

http://ofekshilon.com/2011/01/31/afxisvalidaddress-et-al-dont-work-as-advertised/

TL;DR, here you go:

BOOL AfxIsValidAddress(const void *p, size_t nBytes) {
  return p != NULL;
}

-- 
Scott Ribe
scott_r...@elevated-dev.com
http://www.elevated-dev.com/
https://www.linkedin.com/in/scottribe/
(303) 722-0567 voice






___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: AfxIsValidAddress

2015-07-14 Thread Jens Alfke

 On Jul 14, 2015, at 10:09 AM, Wim Lewis w...@omnigroup.com wrote:
 
 If you don't know (with enough certainty to omit a call to IsValidAddress) 
 whether a pointer is readable, you certainly don't know whether the data 
 there is what you expect to be there.

Plus, preflighting access this way involves race conditions — the memory could 
be unmapped by another thread after you preflight but before you actually 
access it.

There are ways to dereference a random pointer without crashing if it’s 
unmapped, but they involve using a signal handler to recover from the exception 
_after_ it happens. (For example, the Go language’s runtime does this to turn 
null-pointer derefs into Go-level ‘panic’ exceptions.) But writing signal 
handlers that can recover and unwind the stack is extremely deep magic, almost 
certainly not the kind of thing you want to try implementing yourself.

—Jens
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: AfxIsValidAddress

2015-07-14 Thread Raglan T. Tiger


 On Jul 14, 2015, at 11:22 AM, Scott Ribe scott_r...@elevated-dev.com wrote:
 
 This is a definite FUGGEDABOUTIT situation.

I already have!

-rags
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: AfxIsValidAddress

2015-07-14 Thread Scott Ribe
On Jul 14, 2015, at 11:09 AM, Wim Lewis w...@omnigroup.com wrote:
 
 It checks whether a given address range is mapped (or equivalent terminology 
 on Windows). Windows has another function that programmers like to use, 
 IsBadReadPtr(), that does something similar.

No, it doesn't. It is *DOCUMENTED* to do that, but it doesn't ;-)

Of course the rest of your post, about not depending on it, would be valid even 
if it worked...

This is a definite FUGGEDABOUTIT situation.

-- 
Scott Ribe
scott_r...@elevated-dev.com
http://www.elevated-dev.com/
https://www.linkedin.com/in/scottribe/
(303) 722-0567 voice






___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com