Userspace.cpp 924 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "Userspace.h"
  2. #include "Syscall.h"
  3. #include "StdLib.h"
  4. namespace Userspace {
  5. int strlen(const char* str)
  6. {
  7. int len = 0;
  8. while (*(str++))
  9. ++len;
  10. return len;
  11. }
  12. int open(const char* path)
  13. {
  14. return DO_SYSCALL_A2(Syscall::PosixOpen, path, strlen(path));
  15. }
  16. int close(int fd)
  17. {
  18. return DO_SYSCALL_A1(Syscall::PosixClose, fd);
  19. }
  20. int read(int fd, void* outbuf, size_t nread)
  21. {
  22. return DO_SYSCALL_A3(Syscall::PosixRead, fd, outbuf, nread);
  23. }
  24. int seek(int fd, int offset)
  25. {
  26. return DO_SYSCALL_A2(Syscall::PosixRead, fd, offset);
  27. }
  28. int kill(pid_t pid, int sig)
  29. {
  30. return DO_SYSCALL_A2(Syscall::PosixKill, pid, sig);
  31. }
  32. uid_t getuid()
  33. {
  34. return DO_SYSCALL_A0(Syscall::PosixGetuid);
  35. }
  36. void sleep(DWORD ticks)
  37. {
  38. DO_SYSCALL_A1(Syscall::Sleep, ticks);
  39. }
  40. void yield()
  41. {
  42. DO_SYSCALL_A0(Syscall::Yield);
  43. }
  44. void putch(char ch)
  45. {
  46. DO_SYSCALL_A1(Syscall::PutCharacter, ch);
  47. }
  48. }