File: test_stack_placement.c

package info (click to toggle)
emscripten 3.1.69%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 121,860 kB
  • sloc: ansic: 636,110; cpp: 425,974; javascript: 78,401; python: 58,404; sh: 49,154; pascal: 5,237; makefile: 3,366; asm: 2,415; lisp: 1,869
file content (37 lines) | stat: -rw-r--r-- 1,241 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
 * Copyright 2019 The Emscripten Authors.  All rights reserved.
 * Emscripten is available under two separate licenses, the MIT license and the
 * University of Illinois/NCSA Open Source License.  Both these licenses can be
 * found in the LICENSE file.
 */

#include <stdio.h>
#include <assert.h>
#include <emscripten/stack.h>

/* We had a regression where the stack position was not taking into account
 * the data and bss.  This test runs with 1024 byte stack which given that bug
 * would put the end of the bss after the entire stack region */
#define BSS_BYTES (10 * 1024)

int static_data = 1;
int static_bss[BSS_BYTES];

int main(int argc, char* argv[]) {
  int stack_var = 1;
  int* data_address = &static_data;
  int* bss_address = &static_bss[BSS_BYTES-1];
  int* stack_address = &stack_var;
  printf("data: %p bss: %p stack: %p\n", data_address, bss_address, stack_address);
  // Stack can either come after BSS or before data (In debug builds we link
  // with --stack-first).
  int stack_first = emscripten_stack_get_end() == 0;
  if (stack_first) {
    assert(stack_address < data_address);
  } else {
    assert(stack_address > bss_address);
  }
  assert(bss_address > data_address);
  printf("success.\n");
  return 0;
}