mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-31 09:42:27 +00:00
Make memcmp() and memchr() go fast again
Readahead within the specified size is legal, even if it overlaps a page boundary; it's the fault of the caller if that causes a segfault.
This commit is contained in:
parent
70155df7a9
commit
ff955aaa01
4 changed files with 137 additions and 49 deletions
|
@ -16,24 +16,10 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/runtime/sysconf.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/map.h"
|
||||
#include "libc/sysv/consts/prot.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(memchr, test) {
|
||||
const char *s = "hello";
|
||||
ASSERT_EQ(s + 1, memchr(s, 'e', 5));
|
||||
}
|
||||
|
||||
TEST(memchr, pageOverlapTorture) {
|
||||
long pagesz = sysconf(_SC_PAGESIZE);
|
||||
char *map = mmap(0, pagesz * 2, PROT_READ | PROT_WRITE,
|
||||
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
|
||||
ASSERT_SYS(0, 0, mprotect(map + pagesz, pagesz, PROT_NONE));
|
||||
strcpy(map + pagesz - 9, "12345678");
|
||||
EXPECT_EQ(map + pagesz - 1, memchr(map + pagesz - 9, 0, 79));
|
||||
EXPECT_SYS(0, 0, munmap(map, pagesz * 2));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue