You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

librm_mgmt.c 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * librm: a library for interfacing to real-mode code
  3. *
  4. * Michael Brown <mbrown@fensystems.co.uk>
  5. *
  6. */
  7. FILE_LICENCE ( GPL2_OR_LATER );
  8. #include <stdint.h>
  9. #include <realmode.h>
  10. /*
  11. * This file provides functions for managing librm.
  12. *
  13. */
  14. /**
  15. * Allocate space on the real-mode stack and copy data there from a
  16. * user buffer
  17. *
  18. * @v data User buffer
  19. * @v size Size of stack data
  20. * @ret sp New value of real-mode stack pointer
  21. */
  22. uint16_t copy_user_to_rm_stack ( userptr_t data, size_t size ) {
  23. userptr_t rm_stack;
  24. rm_sp -= size;
  25. rm_stack = real_to_user ( rm_ss, rm_sp );
  26. memcpy_user ( rm_stack, 0, data, 0, size );
  27. return rm_sp;
  28. };
  29. /**
  30. * Deallocate space on the real-mode stack, optionally copying back
  31. * data to a user buffer.
  32. *
  33. * @v data User buffer
  34. * @v size Size of stack data
  35. */
  36. void remove_user_from_rm_stack ( userptr_t data, size_t size ) {
  37. if ( data ) {
  38. userptr_t rm_stack = real_to_user ( rm_ss, rm_sp );
  39. memcpy_user ( rm_stack, 0, data, 0, size );
  40. }
  41. rm_sp += size;
  42. };
  43. PROVIDE_UACCESS_INLINE ( librm, phys_to_user );
  44. PROVIDE_UACCESS_INLINE ( librm, user_to_phys );
  45. PROVIDE_UACCESS_INLINE ( librm, virt_to_user );
  46. PROVIDE_UACCESS_INLINE ( librm, user_to_virt );
  47. PROVIDE_UACCESS_INLINE ( librm, userptr_add );
  48. PROVIDE_UACCESS_INLINE ( librm, memcpy_user );
  49. PROVIDE_UACCESS_INLINE ( librm, memmove_user );
  50. PROVIDE_UACCESS_INLINE ( librm, memset_user );
  51. PROVIDE_UACCESS_INLINE ( librm, strlen_user );
  52. PROVIDE_UACCESS_INLINE ( librm, memchr_user );