b9874d0941
Add redbear-usb-storage-check in-guest binary that validates USB mass storage read and write I/O: discovers /scheme/disk/ devices, writes a test pattern to sector 2048, reads it back, verifies match, restores original content. Updates test-usb-storage-qemu.sh with write-proof verification step. Includes all accumulated Red Bear OS work: kernel patches, relibc patches, driver infrastructure, DRM/GPU, KDE recipes, firmware, validation tooling, build system hardening, and documentation.
66 lines
1.6 KiB
C
66 lines
1.6 KiB
C
#include <assert.h>
|
|
#include <stdbool.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
// TODO: glibc requires arg to be not const, but not relibc
|
|
#ifndef __GLIBC__
|
|
const char *msg1 = "first";
|
|
const char *msg2 = "second";
|
|
const char *msg3 = "third";
|
|
#else
|
|
char *msg1 = "first";
|
|
char *msg2 = "second";
|
|
char *msg3 = "third";
|
|
#endif
|
|
|
|
void cleanup1(void *arg) {
|
|
printf("Running %s cleanup callback\n", (const char *)arg);
|
|
}
|
|
void cleanup2(void *arg) {
|
|
fprintf(stderr, "Running %s cleanup callback, to stderr\n", (const char *)arg);
|
|
}
|
|
void cleanup3(void *arg) {
|
|
printf("Running final (%s) callback\n", (const char *)arg);
|
|
}
|
|
|
|
void *routine(void *arg) {
|
|
assert(arg == NULL);
|
|
|
|
puts("1");
|
|
pthread_cleanup_push(cleanup1, msg1);
|
|
puts("2");
|
|
pthread_cleanup_push(cleanup2, msg2);
|
|
puts("3");
|
|
pthread_cleanup_push(cleanup3, msg3);
|
|
puts("4");
|
|
pthread_cleanup_pop(true);
|
|
puts("5");
|
|
//exit(EXIT_SUCCESS);
|
|
pthread_exit(NULL);
|
|
puts("6");
|
|
pthread_cleanup_pop(true);
|
|
pthread_cleanup_pop(true);
|
|
return NULL;
|
|
}
|
|
|
|
int main(void) {
|
|
int result;
|
|
|
|
puts("Main thread started");
|
|
pthread_t second_thread;
|
|
if ((result = pthread_create(&second_thread, NULL, routine, NULL)) != 0) {
|
|
fprintf(stderr, "thread creation failed: %s\n", strerror(result));
|
|
return EXIT_FAILURE;
|
|
}
|
|
if ((result = pthread_join(second_thread, NULL)) != 0) {
|
|
fprintf(stderr, "failed to join thread: %s\n", strerror(result));
|
|
return EXIT_FAILURE;
|
|
}
|
|
puts("Main thread about to exit");
|
|
return EXIT_SUCCESS;
|
|
}
|