struct sigaction act;
size_t pgsz = (size_t)sysconf(_SC_PAGESIZE);
+
+ GC_ASSERT((word)bound >= pgsz);
GC_ASSERT(I_HOLD_LOCK());
act.sa_handler = GC_fault_handler_openbsd;
if (sigsetjmp(GC_jmp_buf_openbsd, 1) == 0) {
result = (ptr_t)((word)p & ~(pgsz-1));
for (;;) {
- result += pgsz;
- if ((word)result >= (word)bound) {
+ if ((word)result >= (word)bound - pgsz) {
result = bound;
break;
}
+ result += pgsz; /* no overflow expected */
GC_noop1((word)(*result));
}
}
struct sigaction act;
size_t pgsz = (size_t)sysconf(_SC_PAGESIZE);
+
+ GC_ASSERT((word)bound >= pgsz);
GC_ASSERT(I_HOLD_LOCK());
act.sa_handler = GC_fault_handler_openbsd;
result = (ptr_t)((word)p & ~(pgsz-1));
if (sigsetjmp(GC_jmp_buf_openbsd, 1) != 0 || firstpass) {
firstpass = 0;
- result += pgsz;
- if ((word)result >= (word)bound) {
+ if ((word)result >= (word)bound - pgsz) {
result = bound;
} else {
+ result += pgsz; /* no overflow expected */
GC_noop1((word)(*result));
}
}
/* static since it's only called with the */
/* allocation lock held. */
+ GC_ASSERT(up ? (word)bound >= MIN_PAGE_SIZE
+ : (word)bound <= ~(word)MIN_PAGE_SIZE);
GC_ASSERT(I_HOLD_LOCK());
GC_setup_temporary_fault_handler();
if (SETJMP(GC_jmp_buf) == 0) {
& ~(MIN_PAGE_SIZE-1));
for (;;) {
if (up) {
- result += MIN_PAGE_SIZE;
- if ((word)result >= (word)bound) {
+ if ((word)result >= (word)bound - MIN_PAGE_SIZE) {
result = bound;
break;
}
+ result += MIN_PAGE_SIZE; /* no overflow expected */
} else {
- result -= MIN_PAGE_SIZE;
- if ((word)result <= (word)bound) {
+ if ((word)result <= (word)bound + MIN_PAGE_SIZE) {
result = bound - MIN_PAGE_SIZE;
/* This is to compensate */
/* further result increment (we */
/* by setjmp otherwise). */
break;
}
+ result -= MIN_PAGE_SIZE; /* no underflow expected */
}
GC_noop1((word)(*result));
}