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

Finish porting advapi32 to v0.3 #447

Merged
merged 23 commits into from
Apr 6, 2018
Merged

Conversation

austinwagner
Copy link
Contributor

Used @Susurrus's fork as a base.

All functions exported by advapi32 that can be found in the SDK headers* have been added to their corresponding Rust files with the exception of SetServiceBits (um/LMServer.h). If a Rust version of a header already existed then only the required pieces were added to the file. If the Rust file didn't exist already the full header was ported to the extent I was able to.

*139 functions are exported from the DLL but have no declaration in any header in the latest Windows SDK.

@austinwagner
Copy link
Contributor Author

Unused macros? Is this a CI issue or did I break something? I tried building each of the features that I added or modified with Rust stable and I don't get any errors.

@retep998
Copy link
Owner

retep998 commented May 22, 2017

It's a new nightly lint that got caught in deny(unused). However because 99.9% of the crate disables itself without any features enabled, the macros remain and end up unused.

@Susurrus
Copy link
Contributor

@austinwagner That issue is being addressed in #446.

@Susurrus
Copy link
Contributor

@austinwagner Your header import declarations in build.rs aren't listed alphabetically, which is why they're failing the tests.

@austinwagner
Copy link
Contributor Author

Yes it's clear why it's failing this time. 🙂 Apparently I'm not good at quickly eyeballing alphabetical order. I'm going to fix it as soon as I get home from work. The error message shows me all of the build.rs sorting problems, but is there a way to quickly sort the imports in the other files? I haven't tried rustfmt because I don't know if it will keep the rest of the file formatted the way that our Benevolent Bunny likes.

@Susurrus
Copy link
Contributor

I believe the only errors are in build.rs, so I don't think you need to reorder anything in any of the actual .rs files. But regarding rustfmt, #444 is tracking its suitability for winapi-rs.

@Susurrus Susurrus mentioned this pull request May 22, 2017
@austinwagner
Copy link
Contributor Author

Is using the memset and strnlen from ntdll acceptable? I know that anything exported by ntdll is considered to be an internal function, but I doubt they're going away. If it's a problem I can replace them with simple loop implementations though.

@retep998
Copy link
Owner

core::ptr::write_bytes is a thing you know.

@austinwagner
Copy link
Contributor Author

No I did not know. My search for intrinsics led me to a page that said they will likely never make it to stable. "...they should be used through stabilized interfaces in the rest of the standard library" makes it sound like you can't access the intrinsics on stable when no_std is set.

@retep998
Copy link
Owner

retep998 commented May 26, 2017

core::ptr::write_bytes is stable though, despite being under the intrinsics.

@Susurrus
Copy link
Contributor

Susurrus commented Jun 1, 2017

@austinwagner Needs rebasing now that #448 was merged.

@austinwagner
Copy link
Contributor Author

@Susurrus Is rebasing the right approach or should I just merge again like I did for smaller conflicts? I've never contributed to a large, popular repo so I don't know what's considered best practice.

@Susurrus
Copy link
Contributor

Susurrus commented Jun 1, 2017

I always rebase rather than merge as if bisecting ever needs to be done, it's easier with less merge nodes. I also find it easier to review PRs that don't have a ton of extraneous "merge ..." nodes.

@Susurrus
Copy link
Contributor

Susurrus commented Jun 1, 2017

I also rebase and squash/edit commits to get rid of all of those small "fix ..." commits (like you have in this commit). The way I look at my commits is that they should always result in a compilable source tree. That's not always possible, but I strive for it. So merging smaller fix commits into the original commit that broke thing before merging is nice.

@austinwagner
Copy link
Contributor Author

You answered my next question before I got to ask it 😃 I'll take care of this as soon as I'm able so the PR can be nice and clean!

I do have one more question for now: was splitting up the commits by header a good approach? I specifically used hunk staging to isolate each one even though I didn't actually start making commits until I finished the porting.

@retep998
Copy link
Owner

retep998 commented Jun 1, 2017

You have some commits which are actually rebased versions of commits by @Susurrus which makes it a lot harder to review this PR. Once those commits are rebased away so this PR is just your commits, I'll be able to review it.

@Susurrus
Copy link
Contributor

Susurrus commented Jun 1, 2017

@austinwagner Re the single-header commits, I haven't seen @retep998 complain about it yet, but it at least makes it easy for me to review and check that I have all the necessary changes for a single header/family of headers to be enabled.

@austinwagner austinwagner force-pushed the finish_advapi32 branch 2 times, most recently from 5108a82 to c5e9b05 Compare June 3, 2017 00:52
@austinwagner
Copy link
Contributor Author

All cleaned up with a rebase

@Susurrus
Copy link
Contributor

Susurrus commented Jun 3, 2017

timezoneapi's functions are in kernel32, so that needs to specified as a dependency. Additionally, those functions are all in lib/kernel32/src/lib.rs. Can you remove those functions from that file in that same commit?

LoggerNameOffset: ULONG,
}}
pub type PEVENT_TRACE_PROPERTIES = *mut EVENT_TRACE_PROPERTIES;
// TODO: The single item structs are defined with the ":" bitfield syntax
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this TODO still need to be resolved?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh it looks like I simply forgot to remove the comment after I found the macro to handle bitfields.

}
#[inline(always)]
pub unsafe fn EventDescCreate(
EventDescriptor: PEVENT_DESCRIPTOR, Id: USHORT, Version: UCHAR, Channel: UCHAR, Level: UCHAR,
Copy link
Contributor

Choose a reason for hiding this comment

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

These arguments all need to be on different lines.

Copy link
Contributor

Choose a reason for hiding this comment

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

This applies to the following function declarations as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't realize that style applied to function definitions. Thought it was only for the declarations. I'll go through all the files and validate that I don't have the same issue elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@retep998 Looking at some existing #[inline] functions, if everything up to and including the open curly bracket fits within the 99 character limit then the parameters should all stay on a single line, correct?

Copy link
Owner

Choose a reason for hiding this comment

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

For function definitions (functions with bodies), if the function signature fits within a single line then it can stay on one line but it's not required. If it isn't a single line, then it should follow the same one parameter per line that all other definitions follow.

However, you shouldn't be using #[inline(always)]. Function definitions should always use #[inline].

StringSecurityDescriptor: *mut LPWSTR,
StringSecurityDescriptorLen: PULONG,
) -> BOOL;
}
Copy link
Owner

Choose a reason for hiding this comment

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

Don't forget end of file newlines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does Github ignore EOF newlines? It was missing before, but it's definitely there now. Checked the file directly downloaded from Github in a hex editor to make sure I wasn't going crazy.

#[cfg(target_arch = "x86_64")]
const __SIZE_OF_WMIREGGUIDW_u: usize = 8;
UNION2!{union WMIREGGUIDW_u {
[u8; __SIZE_OF_WMIREGGUIDW_u],
Copy link
Owner

Choose a reason for hiding this comment

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

I recently added support for UNION2 to have two storages specified, one for 32bit and one for 64bit. Also, an array of u8 is usually the wrong thing because the union needs to have the correct alignment (otherwise when placed inside a struct it could have the wrong position resulting in issues like #452).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How do you determine which to use then? I just got the sizes by looking at the output of sizeof() in C++ for both 32 and 64 bit builds.

Copy link
Owner

Choose a reason for hiding this comment

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

char const * type_for_alignment(uintptr_t align) {
    switch (align) {
    case 1: return "u8";
    case 2: return "u16";
    case 4: return "u32";
    case 8: return "u64";
    }
    throw;
}
#define PRINT_UNION(x) cout << "[" << type_for_alignment(alignof(x)) << "; " << sizeof(x) / alignof(x) << "]" << endl;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's handy! I think it makes sense to add this block of code and the new UNION2 style to CONTRIBUTING.md. The rules regarding function definition styles and EOF newlines should probably also be there.

Copy link
Contributor

@Susurrus Susurrus Jun 3, 2017

Choose a reason for hiding this comment

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

@austinwagner UNION2 is already documented. I just updated #456 about the other things discussed her excluding this example code. I'll add this alignment example to UNION2 however.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, you're right that the dual-alignment UNION2 isn't documented. I'm doing that now.

Copy link
Contributor

Choose a reason for hiding this comment

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

@austinwagner Does my latest commit for #456 make things clear?

@Susurrus
Copy link
Contributor

Susurrus commented Jun 7, 2017

@austinwagner This needs to be updated with the recent merge of #454.

@retep998 retep998 changed the base branch from dev to 0.3 February 4, 2018 05:46
@retep998
Copy link
Owner

retep998 commented Apr 2, 2018

PR currently failing CI.

@retep998 retep998 merged commit 4a69b4a into retep998:0.3 Apr 6, 2018
@skdltmxn skdltmxn mentioned this pull request Apr 30, 2018
mattlknight pushed a commit to mattlknight/winapi-rs that referenced this pull request Aug 31, 2018
* Mark timezoneapi as dependent on advapi32.dll

* Add advapi32 functions to winsvc

* Add accctrl in preparation for aclapi

* Add aclapi

* Add ImpersonateNamedPipeClient to namedpipeapi

Fixes:
- Add namedpipeapi to Cargo.toml
- Typo correction in namedpipeapi header

* Add advapi32 functions to lsalookup

* Add winefs

* Add advapi32 functions to wincred

* Add wct

* Add advapi32 functions to securitybaseapi

* Add advapi32 functions to processthreadsapi

* Add advapi32 functions to ntsecapi

* Add evntprov

* Add wmistr

* Add evntrace and evntcons

* Add sddl

* Add appmgmt

* Add ntlsa

* Add mschapp

* Add perflib

* Add winsafer

* Fix securitybaseapi imports
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants