Cygwin: access: Fix X_OK behaviour for backup operators and admins
[newlib-cygwin.git] / newlib / libc / sys / mmixware / sbrk.c
blob621169fc8a0436654686aec9c667925afaefce43
1 /* sbrk for MMIXware.
3 Copyright (C) 2001, 2012, 2023 Hans-Peter Nilsson
5 Permission to use, copy, modify, and distribute this software is
6 freely granted, provided that the above copyright notice, this notice
7 and the following disclaimer are preserved with no changes.
9 THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
10 IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
11 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
12 PURPOSE. */
14 #include <_ansi.h>
15 #include <sys/types.h>
16 #include <sys/stat.h>
17 #include "sys/syscall.h"
19 extern char *_Sbrk_high;
21 /* When the program is loaded, the first location in Pool_Segment holds
22 the first available octabyte in the memory pool (a.k.a. the heap);
23 somewhere after the command-line parameters. We don't have to
24 initialize that location, we can just use it straight up as a pointer;
25 just point the symbol there.
27 This file will be compiled with -no-builtin-syms, so we need to define
28 Pool_Segment and any other symbols that would be predefined in mmixal. */
30 __asm__ (" .global _Sbrk_high\n"
31 "_Sbrk_high IS Pool_Segment\n"
32 "Pool_Segment IS 0x40<<56");
34 void *
35 _sbrk (ptrdiff_t incr)
37 void *prev_heap_end;
39 prev_heap_end = _Sbrk_high;
41 /* A simulator that requires explicit memory allocation is expected
42 to hook that to the PRELD data prefetch insn, which is otherwise
43 typically a nop. */
44 if ((long) incr > 0)
46 size_t n = incr;
47 char *p = prev_heap_end;
48 #define A(N) __asm__ ("preld " #N ",%0,0" : : "r" (p))
49 #define PRELDOWNTO(N) while (n >= N + 1) { A(N); n -= N + 1; p += N + 1; }
51 PRELDOWNTO (255);
52 PRELDOWNTO (31);
53 PRELDOWNTO (3);
54 PRELDOWNTO (0);
57 _Sbrk_high += incr;
58 return prev_heap_end;