Created
March 12, 2021 02:17
-
-
Save jeremy-hiatt/424b2aad09b68f2f7fa589c0a3c86ac4 to your computer and use it in GitHub Desktop.
Trigger NEON alignment fault
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <glib.h> | |
#include <glib-object.h> | |
#include <graphene.h> | |
#include <stdio.h> | |
G_BEGIN_DECLS | |
#define GST_TYPE_GRAPHENE_ALIGN (graphene_align_get_type()) | |
#define GRAPHENE_ALIGN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_GRAPHENE_ALIGN,GrapheneAlign)) | |
#define GST_IS_GRAPHENE_ALIGN(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_GRAPHENE_ALIGN)) | |
#define GRAPHENE_ALIGN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass) ,GST_TYPE_GRAPHENE_ALIGN,GrapheneAlignClass)) | |
#define GST_IS_GRAPHENE_ALIGN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass) ,GST_TYPE_GRAPHENE_ALIGN)) | |
#define GRAPHENE_ALIGN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj) ,GST_TYPE_GRAPHENE_ALIGN,GrapheneAlignClass)) | |
typedef struct _GrapheneAlign GrapheneAlign; | |
typedef struct _GrapheneAlignClass GrapheneAlignClass; | |
struct _GrapheneAlign | |
{ | |
GObject parent; | |
// Simulate a bunch of other fields | |
char padding[64]; | |
graphene_vec3_t aligned_vector; | |
}; | |
struct _GrapheneAlignClass | |
{ | |
GObjectClass filter_class; | |
}; | |
GType graphene_align_get_type (void); | |
G_END_DECLS | |
#define graphene_align_parent_class parent_class | |
G_DEFINE_TYPE (GrapheneAlign, graphene_align, | |
G_TYPE_OBJECT); | |
static void | |
graphene_align_class_init (GrapheneAlignClass * klass) { | |
} | |
static void | |
graphene_align_init (GrapheneAlign * align) | |
{ | |
printf("Pointer to instance is %p, alignment is %#0x\n", align, G_ALIGNOF(GrapheneAlign)); | |
graphene_vec3_init(&align->aligned_vector, 0., 0., 0.); | |
} | |
int main(int argc, char **argv) { | |
unsigned pad = 0; | |
GrapheneAlign *align; | |
printf("Offset of graphene vector: %#0x\n", offsetof(GrapheneAlign, aligned_vector)); | |
if (argc > 1) { | |
pad = atoi(argv[1]); | |
} | |
if (pad > 0) { | |
printf("Allocating %u padding bytes\n", pad); | |
g_slice_alloc(pad); | |
} else { | |
printf("No padding bytes allocated\n"); | |
} | |
align = g_object_new(graphene_align_get_type(), NULL); | |
g_object_unref(align); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample Makefile:
Sample invocation: