-
-
Notifications
You must be signed in to change notification settings - Fork 554
[feat] Add basic support for iOS 6.1 #1828
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
base: main
Are you sure you want to change the base?
Conversation
|
While this thing might work, the fact that it's generated suggests we cannot merge it as is. Because there's no human review, and there is a copyright concern (the AI might have copied code from someone else that is unlicensed). Putting the general issue of AI-generated code aside, i see there's a massive style violation. We're not defining or using a macro token like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are several issues with this implementation, in particular with the feature availability checking, which should best be done using configure checks.
Also, given that the proc_taskinfo structure is allocated on the stack, we should be VERY careful, that we are not mixing ABI boundaries with libproc (which doesn't exist for iPhone 6, but might for later models). Thus ensure, that you only ever have this structure defined when using your own code for accessing proc_taskinfo-related stuff OR know you are using the structure definition that comes from the libproc you are calling.
And now for the elephant in the room: While there is no general ban of AI generated code per se, we still require for contributions to include proper attribution for all (non-trivial) source code copied (or adapted) from other places. An example for this in your PR is with the proc_taskinfo struct (and some other stub types you define), but this also includes magic values like IFT_LOOP, RTM_IFINFO2, AT_FDCWD, AT_SYMLINK_NOFOLLOW,
You should be able to provide a valid and qualified Developer Certificate of Origin alongside with your code, which ATM is not the case (due to the insufficiently attributed third-party sources).
|
Thank you @BenBE and @Explorer09 for the very detailed reviews! Let me address them and get back to you. Putting this to Is there unit tests that I can run? |
|
Please note the instruction regarding rebasing/amending your commits for PRs in the style guide. |
|
Still grinding on it! 💪
I think I’m getting somewhere pointing the compiler to a libproc from another SDK. If that works, we don’t need a code change, and it will just be a matter of documenting what build parameters to use.
Thank you for the continuous discussion today!
|
|
The entire PR has become too messy for me to review further. There are still coding style violations here and there. But it seems like there are some compatibility fixes that can be cherry-picked early (such as the check of |
|
Dear @Explorer09, Please keep discussion in here civilized. If you don't like AI-generated code: Fine. If someone has no experience with a certain tool: Help them to get to know that tool or point them to resources that provide an introduction or explain necessary concepts. If code doesn't follow the coding style: Explain the issue and provide possible alternatives. BUT: This is no place for attacks or personal vendettas against any particular technology, just because someone chooses to use them. This is voluntary work. Nobody forces you to respond to each and every issue/PR. |
|
I'm sorry you feel this way @Explorer09 . Please take a break and you're welcome back when you feel better. To both of you @Explorer09 and @BenBE : Thanks for the reviews again. Let me put this PR to draft mode again while I'm at it. (I might need to pick this up only at a next weekend, though.) In general, I'm a bit confused about the "code style" that you all have been referring to. I thought those changes are applied automatically, yet I don't see a pre-commit hook or a CI job kicking in. I've been treating the code style doc as "hey don't be surprised if we modify your code this way eventually / don't be offended when a script keeps formatting your code this way", but judging from your comments this isn't the case. Are those code style rules to be followed manually? |
Some code style cannot be automated prior to commit, and our attitude to pull requests is that: it is the OP's responsibility to code in our style when proposing code changes. If someone cannot bother to adapt to our code style, then it's better to maintain htop in their fork and not propose upstream. Significant disruption to code style and/or paradigms can complicate other developers when reviewing your code. And note that I only review htop PRs on the voluntary basis - and it would be unpleasant for me if someone seems to be deliberately wasting my time. |
0b64c08 to
dc1b54e
Compare
|
Hi all, What a journey! This Frankenstein-style SDK worked better than I expected (🤦 ). It inspired me to use iPhone Simulator's SDK files for this I guess this "simulator SDK will help a lot" is common knowledge to the jailbreak community 🤷 . But when it comes to learning something, later is better than never! :D I appreciate you all guiding me through this weekend hobbyist project of mine, as I'm quite amateur when it comes to |
darwin/Platform.c
Outdated
| used += vm->compressor_page_count; | ||
| mtr->values[MEMORY_METER_USED] = (double)(used - vm->compressor_page_count) * page_K; | ||
| #else | ||
| mtr->values[MEMORY_METER_USED] = (double)used * page_K; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A separate mtr->values[MEMORY_METER_USED] assignment line doesn't look right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, there are already two branches. To avoid assigning again, I'll have to introduce a new variable:
@@ -401,6 +401,7 @@
const struct vm_statistics* vm = &dhost->vm_stats;
#endif
double page_K = (double)vm_page_size / (double)1024;
+ double usedPages = 0.0;
mtr->total = dhost->host_info.max_mem / 1024;
#ifdef HAVE_STRUCT_VM_STATISTICS64
@@ -411,13 +412,14 @@
#endif
#ifdef HAVE_STRUCT_VM_STATISTICS64_COMPRESSOR_PAGE_COUNT
used += vm->compressor_page_count;
- mtr->values[MEMORY_METER_USED] = (double)(used - vm->compressor_page_count) * page_K;
+ usedPages = (double)(used - vm->compressor_page_count);
#else
- mtr->values[MEMORY_METER_USED] = (double)used * page_K;
+ usedPages = (double)used;
#endif
#else
- mtr->values[MEMORY_METER_USED] = (double)(vm->active_count + vm->wire_count) * page_K;
+ usedPages = (double)(vm->active_count + vm->wire_count);
#endif
+ mtr->values[MEMORY_METER_USED] = usedPages * page_K;
// mtr->values[MEMORY_METER_SHARED] = "shared memory, like tmpfs and shm"
#ifdef HAVE_STRUCT_VM_STATISTICS64
#ifdef HAVE_STRUCT_VM_STATISTICS64_COMPRESSOR_PAGE_COUNTwhich doesn't look too elegant to me. What do you say?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, it might be good to examine why there were two branches in the first place. Ideally the formula for counting "used" memory shouldn't differ between 32-bits and 64-bits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like Apple Silicon support (731812d), perhaps something to do with Unified Memory if I'm reading it right.
That said, it's not yet clear to me how to unify all three branches together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to sort out the amount of used/external/compressed memory first, before assigning. The external and compressed memory should be restricted to cases where they are provided by the OS, thus in these cases modifying the used value should be trivial in the appropriate branches. After that's done, updating the mtr->values[MEMORY_METER_USED] should be straight forward.
It furthermore helps to limit nesting things to the bare minimum.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gave it a pass. I introduced two local variables: used_counts_from_statistics64 (to decouple the existing mtr->values[MEMORY_METER_USED] assignments from the existing #ifdef HAVE_STRUCT_VM_STATISTICS64 branches) and external_page_count (to hide #ifdef HAVE_[...]_EXTERNAL_PAGE_COUNT behind it, so that we avoid a reassignment). There's actually one more local variable used_count I introduced, but it's mainly for typography.
|
Turns out the deprecated name ( I've force-pushed again to make use of #if __IPHONE_OS_VERSION_MIN_REQUIRED <= __IPHONE_6_1
as a stricter way to apply the patches. When building for iOS, this macro is needed anyway. I can put this in |
8cf5d91 to
f608416
Compare
Transition Compat.[ch] into the Linux platform directory. Linux is the only platform using this code after several years now so best if its not compiled into all the other platforms htop binary. However, this change is primarily intended to assist with the iOS port. Related: htop-dev#1828
Transition Compat.[ch] into the Linux platform directory. Linux is the only platform using this code after several years now so best if its not compiled into all the other platforms htop binary. However, this change is primarily intended to assist with the iOS port. Related: htop-dev#1828
2c58703 to
8635db1
Compare
Transition Compat.[ch] into the Linux platform directory. Linux is the only platform using this code after several years now so best if its not compiled into all the other platforms htop binary. However, this change is primarily intended to assist with the iOS port. Related: htop-dev#1828
BenBE
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor note on the commit messages: The common format is a short subject line, with optional explanatory text following after a blank.
So a message like
Handle when external/compressed page counts are unavailable
Some SDKs (especially older ones like iPhoneOS 6.1) do not expose …
read much cleaner. Similar:
Handle legacy references to kIOMainPortDefault
In old SDKs
kIOMainPortDefaultwas originally calledkIOMasterPortDefault.
Handling this legacy name allows for support of old SDKs like iPhoneOS 6.1.
And lastly:
Handle include order constraints
Some old SDKs (e.g. for iPhoneOS 6.1) require includes to be ordered such
that headernet/if.his included aftersys/socket.h
Speaking of which: mach/port.h should appear after unistd.h, unless there's a constraint on that one too (unrelated to your patch, but can be cleaned up when we are touching there anyways; separate commit "Clean up include order" please).
darwin/Platform.c
Outdated
| used += vm->compressor_page_count; | ||
| mtr->values[MEMORY_METER_USED] = (double)(used - vm->compressor_page_count) * page_K; | ||
| #else | ||
| mtr->values[MEMORY_METER_USED] = (double)used * page_K; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to sort out the amount of used/external/compressed memory first, before assigning. The external and compressed memory should be restricted to cases where they are provided by the OS, thus in these cases modifying the used value should be trivial in the appropriate branches. After that's done, updating the mtr->values[MEMORY_METER_USED] should be straight forward.
It furthermore helps to limit nesting things to the bare minimum.
Some SDKs (especially older ones like iPhoneOS 6.1) do not expose external and compressed page counts exposed in memory statistics.
In old SDKs `kIOMainPortDefault` was originally called `kIOMasterPortDefault`. Handling this legacy name allows for support of old SDKs like iPhoneOS 6.1.
Some old SDKs (e.g. for iPhoneOS 6.1) require includes to be ordered such that header `net/if.h` is included after `sys/socket.h`.
Tested working on an iPod touch (4th gen) running iOS 6.1.6:
How to build
Prerequisites:
/Volumes/Xcode.brew install automake)brew install ncurses)Prepare the SDK
htopneeds the IOKit framework for probing battery, disk I/O, and GPU statuses. The vanilla iPhoneOS6.1 SDK does not provide headers for IOKit, so we'll have to stitch together a Frankenstein-style SDK for getting around it.Assuming you are at a directory outside of
htopcodebase:Don't unmount the Xcode DMG just yet; we still need the simulator's SDK (for
libproc.h).Build
Assuming you are now in the
htopdirectory, here's the full commands needed to build: