privates.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. extern void **_privates;
  12. extern int _nprivates;
  13. int
  14. main(void)
  15. {
  16. unsigned char buf[512];
  17. uint64_t i, fail = 0;
  18. if (_privates == nil) {
  19. fprint(2, "_privates is nil\n");
  20. fail++;
  21. }
  22. if (_nprivates == 0) {
  23. fprint(2, "_nprivates is 0\n");
  24. fail++;
  25. }
  26. for (i = 0; i < _nprivates; i++) {
  27. _privates[i] = (void *)(0x77665544332210 + i);
  28. }
  29. memset(buf, 0, sizeof buf);
  30. for (i = 0; i < _nprivates; i++) {
  31. if (_privates[i] != (void *)(0x77665544332210 + i)){
  32. fprint(2, "_privates[%d] = %p\n", i, _privates[i]);
  33. fail++;
  34. }
  35. }
  36. void **p[_nprivates+1];
  37. for (i = 0; i < _nprivates; i++) {
  38. p[i] = privalloc();
  39. if(p[i] == nil){
  40. fail++;
  41. fprint(2, "privalloc[%d]: %p\n", i, p[i]);
  42. }
  43. }
  44. p[i] = privalloc();
  45. if(p[i] != nil){
  46. fail++;
  47. fprint(2, "privalloc[%d]: %p\n", i, p[i]);
  48. }
  49. for (i = 0; i < _nprivates; i++) {
  50. *(p[i]) = (void*)i;
  51. }
  52. for (i = 0; i < _nprivates; i++) {
  53. if(*(p[i]) != (void*)i){
  54. fprint(2, "p[%d] != %d\n", i, i);
  55. fail++;
  56. }
  57. }
  58. if (fail > 0) {
  59. print("FAIL\n");
  60. exits("FAIL");
  61. }
  62. print("PASS\n");
  63. exits("PASS");
  64. return 0;
  65. }