compat.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * fs kernel compatibility hacks for drivers from the cpu/terminal kernel
  3. */
  4. #include "all.h"
  5. #include "io.h"
  6. #include "mem.h"
  7. #include "../ip/ip.h" /* for Ether */
  8. #include "etherif.h" /* for Ether */
  9. #include "compat.h"
  10. enum {
  11. VectorPIC = 24, /* external [A]PIC interrupts */
  12. };
  13. void
  14. free(void *p) /* there's a struct member named "free". sigh. */
  15. {
  16. USED(p);
  17. }
  18. void *
  19. mallocz(ulong sz, int clr)
  20. {
  21. void *p = malloc(sz);
  22. if (clr && p != nil)
  23. memset(p, '\0', sz);
  24. return p;
  25. }
  26. void
  27. freeb(Block *b)
  28. {
  29. mbfree(b);
  30. }
  31. /*
  32. * free a list of blocks
  33. */
  34. void
  35. freeblist(Block *b)
  36. {
  37. Block *next;
  38. for(; b != 0; b = next){
  39. next = b->next;
  40. b->next = 0;
  41. freeb(b);
  42. }
  43. }
  44. int
  45. readstr(vlong, void *, int, char *)
  46. {
  47. return 0;
  48. }
  49. void
  50. addethercard(char *, int (*)(struct Ether *))
  51. {
  52. }
  53. void
  54. kproc(char *name, void (*f)(void), void *arg)
  55. {
  56. userinit(f, arg, strdup(name));
  57. }
  58. void
  59. intrenable(int irq, void (*f)(Ureg*, void*), void* a, int tbdf, char *name)
  60. {
  61. setvec(irq+VectorPIC, f, a);
  62. USED(tbdf, name);
  63. }
  64. int
  65. intrdisable(int irq, void (*f)(Ureg *, void *), void *a, int tbdf, char *name)
  66. {
  67. USED(irq, f, a, tbdf, name);
  68. return -1;
  69. }
  70. /*
  71. * Atomically replace *p with copy of s
  72. */
  73. void
  74. kstrdup(char **p, char *s)
  75. {
  76. int n;
  77. char *t, *prev;
  78. static Lock l;
  79. n = strlen(s)+1;
  80. /* if it's a user, we can wait for memory; if not, something's very wrong */
  81. if(0 && u){
  82. t = /* s */malloc(n);
  83. // setmalloctag(t, getcallerpc(&p));
  84. }else{
  85. t = malloc(n);
  86. if(t == nil)
  87. panic("kstrdup: no memory");
  88. }
  89. memmove(t, s, n);
  90. prev = *p;
  91. *p = t;
  92. free(prev);
  93. }