miscthings.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "linux/threads.h"
  2. #include "linux/stddef.h" // for NULL
  3. #include "linux/elf.h" // for AT_NULL
  4. /* The following function nicked from arch/ppc/kernel/process.c and
  5. * adapted slightly */
  6. /*
  7. * XXX ld.so expects the auxiliary table to start on
  8. * a 16-byte boundary, so we have to find it and
  9. * move it up. :-(
  10. */
  11. void shove_aux_table(unsigned long sp)
  12. {
  13. int argc;
  14. char *p;
  15. unsigned long e;
  16. unsigned long aux_start, offset;
  17. argc = *(int *)sp;
  18. sp += sizeof(int) + (argc + 1) * sizeof(char *);
  19. /* skip over the environment pointers */
  20. do {
  21. p = *(char **)sp;
  22. sp += sizeof(char *);
  23. } while (p != NULL);
  24. aux_start = sp;
  25. /* skip to the end of the auxiliary table */
  26. do {
  27. e = *(unsigned long *)sp;
  28. sp += 2 * sizeof(unsigned long);
  29. } while (e != AT_NULL);
  30. offset = ((aux_start + 15) & ~15) - aux_start;
  31. if (offset != 0) {
  32. do {
  33. sp -= sizeof(unsigned long);
  34. e = *(unsigned long *)sp;
  35. *(unsigned long *)(sp + offset) = e;
  36. } while (sp > aux_start);
  37. }
  38. }
  39. /* END stuff taken from arch/ppc/kernel/process.c */