Plan 9 from Bell Labs’s /usr/web/sources/contrib/quanstro/root/sys/src/cmd/upas/fs/bos.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include <u.h>
#include <libc.h>
#include <bio.h>

/*
 * assume:
 * - the stack segment can't be resized
 * - stacks may not be segattached (by name Stack, anyway)
 * - no thread library
 */
uintptr
absbos(void)
{
	char buf[64], *f[10], *s, *r;
	int n;
	uintptr p, q;
	Biobuf *b;

	p = 0xd0000000;	/* guess pc kernel */
	snprint(buf, sizeof buf, "/proc/%ud/segment", getpid());
	b = Bopen(buf, OREAD);
	if(b == nil)
		return p;
	for(; s = Brdstr(b, '\n', 1); free(s)){
		if((n = tokenize(s, f, nelem(f))) < 3)
			continue;
		if(strcmp(f[0], "Stack") != 0)
			continue;
		/*
		 * addressing from end because segment
		 * flags could become discontiguous  if
		 * additional flags are added
		 */
		q = strtoull(f[n - 3], &r, 16);
		if(*r == 0 && (char*)q > end)
			p = q;
	}
	Bterm(b);
	return p;
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.