Sorted out proc refcounting with ARCs
[akaros.git] / kern / src / string.c
index ba7ab14..8cde851 100644 (file)
@@ -5,6 +5,8 @@
 #endif
 
 #include <string.h>
+#include <ros/memlayout.h>
+#include <assert.h>
 
 int
 strlen(const char *s)
@@ -106,6 +108,16 @@ strchr(const char *s, char c)
        return 0;
 }
 
+void *
+memchr(void* mem, int chr, int len)
+{
+       char* s = (char*)mem;
+       for(int i = 0; i < len; i++)
+               if(s[i] == (char)chr)
+                       return s+i;
+       return NULL;
+}
+
 // Return a pointer to the first occurrence of 'c' in 's',
 // or a pointer to the string-ending null character if the string has no 'c'.
 char *
@@ -129,7 +141,7 @@ memset16(uint32_t *COUNT(n/sizeof(uint32_t)) _v, uint32_t c, size_t n)
        v = _v;
        c = c | c<<8 | c<<16 | c<<24;
 
-       if(n >= 64 && ((intptr_t)v) % 8 == 0)
+       if(n >= 64 && ((uintptr_t)v) % 8 == 0)
        {
                uint64_t* v64 = (uint64_t*)v;
                uint64_t c64 = c | ((uint64_t)c)<<32;
@@ -182,6 +194,24 @@ memcpy16(uint32_t *COUNT(n/sizeof(uint32_t)) _dst,
 }
 
 void *
+pagecopy(void* d, void* s)
+{
+       static_assert(PGSIZE % 64 == 0);
+       for(int i = 0; i < PGSIZE; i += 64)
+       {
+               *((uint64_t*)(d+i+0)) = *((uint64_t*)(s+i+0));
+               *((uint64_t*)(d+i+8)) = *((uint64_t*)(s+i+8));
+               *((uint64_t*)(d+i+16)) = *((uint64_t*)(s+i+16));
+               *((uint64_t*)(d+i+24)) = *((uint64_t*)(s+i+24));
+               *((uint64_t*)(d+i+32)) = *((uint64_t*)(s+i+32));
+               *((uint64_t*)(d+i+40)) = *((uint64_t*)(s+i+40));
+               *((uint64_t*)(d+i+48)) = *((uint64_t*)(s+i+48));
+               *((uint64_t*)(d+i+56)) = *((uint64_t*)(s+i+56));
+       }
+       return d;
+}
+
+void *
 memset(void *COUNT(_n) v, int c, size_t _n)
 {
        char *BND(v,v+_n) p;