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

Make C++ compatible #13

Closed
wants to merge 20 commits into from
Closed

Conversation

hidmic
Copy link
Contributor

@hidmic hidmic commented Jul 8, 2020

Precisely what the title says. This patch allows Mimick to be used in C++ tests for C API.

Depends on #11 and #12. Only 31c6ce0, 8381645, and 0b67235 are specific to this patch.

Blast545 and others added 13 commits July 6, 2020 17:18
Signed-off-by: Jorge Perez <jjperez@ekumenlabs.com>
Signed-off-by: Jorge Perez <jjperez@ekumenlabs.com>
Signed-off-by: Jorge Perez <jjperez@ekumenlabs.com>
Signed-off-by: Jorge Perez <jjperez@ekumenlabs.com>
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
@hidmic
Copy link
Contributor Author

hidmic commented Jul 14, 2020

Alright, @Snaipe PTAL!

hidmic added 2 commits July 22, 2020 14:03
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
@hidmic hidmic force-pushed the hidmic/cxx-compatibility branch from 1858560 to 077c389 Compare July 22, 2020 18:47
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
@hidmic hidmic force-pushed the hidmic/cxx-compatibility branch 2 times, most recently from 14c28eb to a82593e Compare July 27, 2020 16:22
* Target external, undefined symbols only.
* Fix indirect symbol type check.
* Fix table lookup.

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
@hidmic hidmic force-pushed the hidmic/cxx-compatibility branch 2 times, most recently from 335b1be to 46afad4 Compare July 27, 2020 16:37
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
@hidmic hidmic force-pushed the hidmic/cxx-compatibility branch 2 times, most recently from 2665884 to da21a47 Compare July 27, 2020 23:56
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
@hidmic hidmic force-pushed the hidmic/cxx-compatibility branch from da21a47 to fb0e5b3 Compare July 28, 2020 00:05
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
};

typedef void(*mmk_fn)(void);
typedef struct mmk_stub *mmk_stub;
struct mmk_stub;
Copy link
Owner

Choose a reason for hiding this comment

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

This breaks the API as far as I'm concerned. I'd rather have mmk_stub be an alias for struct mmk_stub *. I would be fine if struct mmk_stub was renamed to struct mmk_stub_ however.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does break API, but I could only find one place where the mmk_stub alias was being used instead of struct mmk_stub *. I figured I'd normalize to the struct <name> syntax instead.

Copy link
Owner

Choose a reason for hiding this comment

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

This is mostly about API usage -- mmk_stub is an opaque type, so having the user type struct mmk_stub in C is just misleading because you'd expect to be able to change or read some fields in there.

In other words, I am fine with keeping struct and union keywords when it's possible to access the underlying type, and this is not one of these situations.

off[j++] = i;
if ((s->n_type & N_EXT) && ((s->n_type & N_TYPE) == N_UNDF)) {
const char *symname = strtab + s->n_un.n_strx;
if (!strcmp(symname + 1, name)) off[j++] = i;
Copy link
Owner

Choose a reason for hiding this comment

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

nit: I'd prefer if the if statement was over two lines.

Comment on lines +126 to +133
if (lc->cmd == MMK_LC_SEGMENT) {
const segment_cmd * sc = (void *) lc;
if (strstr(sc->segname, "TEXT") != NULL) {
text = sc;
} else if (strstr(sc->segname, "LINKEDIT") != NULL) {
linkedit = sc;
}
}
Copy link
Owner

Choose a reason for hiding this comment

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

nit: spacing

# define MMK_COMMA_APPEND(_, prefix, content) (void) (prefix content),

# define mmk_struct_initialize(variable, ...) \
(MMK_EXPAND(MMK_APPLY_N_(MMK_COMMA_APPEND, MMK_VA_NARGS(__VA_ARGS__), variable, __VA_ARGS__)) \
Copy link
Owner

Choose a reason for hiding this comment

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

Hah, what a clever hack -- I love it!

return dst;
}

va_list & mmk_assign(va_list & dst, va_list src) {
Copy link
Owner

Choose a reason for hiding this comment

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

That should probably be inline

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point.

@hidmic
Copy link
Contributor Author

hidmic commented Aug 12, 2020

This grew massive and hard to review. I'll close this now, and open smaller PRs with these and other fixes. Hope you can take a look @Snaipe.

@hidmic hidmic closed this Aug 12, 2020
ziyao233 pushed a commit to ziyao233/Mimick that referenced this pull request Feb 9, 2024
Signed-off-by: Stephen Brawner <brawner@gmail.com>
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