Renamed thread/team syscalls to new scheme.
Removed old ERR_* error codes. Removed funny area names in rldheap.c. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6884 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
5a253979d3
commit
5d83d63c08
@ -74,7 +74,7 @@ relocate_rel(image_t *image, struct Elf32_Rel *rel, int rel_len)
|
|||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
printf("unhandled relocation type %d\n", ELF32_R_TYPE(rel[i].r_info));
|
printf("unhandled relocation type %d\n", ELF32_R_TYPE(rel[i].r_info));
|
||||||
return ERR_NOT_ALLOWED;
|
return B_NOT_ALLOWED;
|
||||||
}
|
}
|
||||||
|
|
||||||
*P = final_val;
|
*P = final_val;
|
||||||
|
@ -1,20 +1,29 @@
|
|||||||
/*
|
/*
|
||||||
** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
|
** Copyright 2003-2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
|
||||||
|
** Distributed under the terms of the OpenBeOS License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
** Copyright 2002, Manuel J. Petit. All rights reserved.
|
** Copyright 2002, Manuel J. Petit. All rights reserved.
|
||||||
** Copyright 2001, Travis Geiselbrecht. All rights reserved.
|
** Copyright 2001, Travis Geiselbrecht. All rights reserved.
|
||||||
** Distributed under the terms of the NewOS License.
|
** Distributed under the terms of the NewOS License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string.h>
|
#ifdef _KERNEL_MODE
|
||||||
#include <stdio.h>
|
# undef _KERNEL_MODE
|
||||||
#include <Errors.h>
|
#endif
|
||||||
#include <kerrors.h>
|
|
||||||
|
#include <OS.h>
|
||||||
|
|
||||||
#include <elf32.h>
|
#include <elf32.h>
|
||||||
#include <user_runtime.h>
|
#include <user_runtime.h>
|
||||||
#include <syscalls.h>
|
#include <syscalls.h>
|
||||||
#include <arch/cpu.h>
|
#include <arch/cpu.h>
|
||||||
#include <sem.h>
|
#include <sem.h>
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "rld_priv.h"
|
#include "rld_priv.h"
|
||||||
|
|
||||||
// ToDo: implement better locking strategy
|
// ToDo: implement better locking strategy
|
||||||
@ -23,10 +32,9 @@
|
|||||||
// sure that B_ADD_ON_IMAGE is set correctly
|
// sure that B_ADD_ON_IMAGE is set correctly
|
||||||
// ToDo: implement search paths $LIBRARY_PATH, $ADDON_PATH
|
// ToDo: implement search paths $LIBRARY_PATH, $ADDON_PATH
|
||||||
|
|
||||||
#define PAGE_SIZE 4096
|
#define PAGE_MASK (B_PAGE_SIZE - 1)
|
||||||
#define PAGE_MASK ((PAGE_SIZE)-1)
|
#define PAGE_OFFS(y) ((y) & (PAGE_MASK))
|
||||||
#define PAGE_OFFS(y) ((y)&(PAGE_MASK))
|
#define PAGE_BASE(y) ((y) & ~(PAGE_MASK))
|
||||||
#define PAGE_BASE(y) ((y)&~(PAGE_MASK))
|
|
||||||
|
|
||||||
/* david - added '_' to avoid macro's in kernel.h */
|
/* david - added '_' to avoid macro's in kernel.h */
|
||||||
#define _ROUNDOWN(x,y) ((x)&~((y)-1))
|
#define _ROUNDOWN(x,y) ((x)&~((y)-1))
|
||||||
@ -130,7 +138,7 @@ static struct uspace_program_args const *gProgramArgs;
|
|||||||
#define FATAL(x,y...) \
|
#define FATAL(x,y...) \
|
||||||
if (x) { \
|
if (x) { \
|
||||||
printf("rld.so: " y); \
|
printf("rld.so: " y); \
|
||||||
sys_exit(0); \
|
_kern_exit(0); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -147,7 +155,7 @@ rld_unlock()
|
|||||||
static void
|
static void
|
||||||
rld_lock()
|
rld_lock()
|
||||||
{
|
{
|
||||||
thread_id self = sys_get_current_thread_id();
|
thread_id self = find_thread(NULL);
|
||||||
if (self != rld_sem_owner) {
|
if (self != rld_sem_owner) {
|
||||||
acquire_sem(rld_sem);
|
acquire_sem(rld_sem);
|
||||||
rld_sem_owner = self;
|
rld_sem_owner = self;
|
||||||
@ -243,21 +251,21 @@ static status_t
|
|||||||
parse_elf_header(struct Elf32_Ehdr *eheader, int32 *_pheaderSize, int32 *_sheaderSize)
|
parse_elf_header(struct Elf32_Ehdr *eheader, int32 *_pheaderSize, int32 *_sheaderSize)
|
||||||
{
|
{
|
||||||
if (memcmp(eheader->e_ident, ELF_MAGIC, 4) != 0)
|
if (memcmp(eheader->e_ident, ELF_MAGIC, 4) != 0)
|
||||||
return ERR_INVALID_BINARY;
|
return B_NOT_AN_EXECUTABLE;
|
||||||
|
|
||||||
if (eheader->e_ident[4] != ELFCLASS32)
|
if (eheader->e_ident[4] != ELFCLASS32)
|
||||||
return ERR_INVALID_BINARY;
|
return B_NOT_AN_EXECUTABLE;
|
||||||
|
|
||||||
if (eheader->e_phoff == 0)
|
if (eheader->e_phoff == 0)
|
||||||
return ERR_INVALID_BINARY;
|
return B_NOT_AN_EXECUTABLE;
|
||||||
|
|
||||||
if (eheader->e_phentsize < sizeof(struct Elf32_Phdr))
|
if (eheader->e_phentsize < sizeof(struct Elf32_Phdr))
|
||||||
return ERR_INVALID_BINARY;
|
return B_NOT_AN_EXECUTABLE;
|
||||||
|
|
||||||
*_pheaderSize = eheader->e_phentsize * eheader->e_phnum;
|
*_pheaderSize = eheader->e_phentsize * eheader->e_phnum;
|
||||||
*_sheaderSize = eheader->e_shentsize * eheader->e_shnum;
|
*_sheaderSize = eheader->e_shentsize * eheader->e_shnum;
|
||||||
|
|
||||||
return *_pheaderSize > 0 && *_sheaderSize > 0 ? B_OK : ERR_INVALID_BINARY;
|
return *_pheaderSize > 0 && *_sheaderSize > 0 ? B_OK : B_NOT_AN_EXECUTABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -377,9 +385,9 @@ parse_program_headers(image_t *image, char *buff, int phnum, int phentsize)
|
|||||||
*/
|
*/
|
||||||
image->regions[regcount].start = pheader->p_vaddr;
|
image->regions[regcount].start = pheader->p_vaddr;
|
||||||
image->regions[regcount].size = pheader->p_memsz;
|
image->regions[regcount].size = pheader->p_memsz;
|
||||||
image->regions[regcount].vmstart = _ROUNDOWN(pheader->p_vaddr, PAGE_SIZE);
|
image->regions[regcount].vmstart = _ROUNDOWN(pheader->p_vaddr, B_PAGE_SIZE);
|
||||||
image->regions[regcount].vmsize = _ROUNDUP(pheader->p_memsz +
|
image->regions[regcount].vmsize = _ROUNDUP(pheader->p_memsz +
|
||||||
(pheader->p_vaddr % PAGE_SIZE), PAGE_SIZE);
|
(pheader->p_vaddr % B_PAGE_SIZE), B_PAGE_SIZE);
|
||||||
image->regions[regcount].fdstart = pheader->p_offset;
|
image->regions[regcount].fdstart = pheader->p_offset;
|
||||||
image->regions[regcount].fdsize = pheader->p_filesz;
|
image->regions[regcount].fdsize = pheader->p_filesz;
|
||||||
image->regions[regcount].delta = 0;
|
image->regions[regcount].delta = 0;
|
||||||
@ -400,9 +408,9 @@ parse_program_headers(image_t *image, char *buff, int phnum, int phentsize)
|
|||||||
|
|
||||||
image->regions[regcount].start = pheader->p_vaddr;
|
image->regions[regcount].start = pheader->p_vaddr;
|
||||||
image->regions[regcount].size = pheader->p_filesz;
|
image->regions[regcount].size = pheader->p_filesz;
|
||||||
image->regions[regcount].vmstart = _ROUNDOWN(pheader->p_vaddr, PAGE_SIZE);
|
image->regions[regcount].vmstart = _ROUNDOWN(pheader->p_vaddr, B_PAGE_SIZE);
|
||||||
image->regions[regcount].vmsize = _ROUNDUP (pheader->p_filesz +
|
image->regions[regcount].vmsize = _ROUNDUP (pheader->p_filesz +
|
||||||
(pheader->p_vaddr % PAGE_SIZE), PAGE_SIZE);
|
(pheader->p_vaddr % B_PAGE_SIZE), B_PAGE_SIZE);
|
||||||
image->regions[regcount].fdstart = pheader->p_offset;
|
image->regions[regcount].fdstart = pheader->p_offset;
|
||||||
image->regions[regcount].fdsize = pheader->p_filesz;
|
image->regions[regcount].fdsize = pheader->p_filesz;
|
||||||
image->regions[regcount].delta = 0;
|
image->regions[regcount].delta = 0;
|
||||||
@ -420,7 +428,9 @@ parse_program_headers(image_t *image, char *buff, int phnum, int phentsize)
|
|||||||
image->regions[regcount].start = pheader->p_vaddr;
|
image->regions[regcount].start = pheader->p_vaddr;
|
||||||
image->regions[regcount].size = pheader->p_memsz - pheader->p_filesz;
|
image->regions[regcount].size = pheader->p_memsz - pheader->p_filesz;
|
||||||
image->regions[regcount].vmstart = image->regions[regcount-1].vmstart + image->regions[regcount-1].vmsize;
|
image->regions[regcount].vmstart = image->regions[regcount-1].vmstart + image->regions[regcount-1].vmsize;
|
||||||
image->regions[regcount].vmsize = _ROUNDUP (pheader->p_memsz + (pheader->p_vaddr % PAGE_SIZE), PAGE_SIZE) - image->regions[regcount-1].vmsize;
|
image->regions[regcount].vmsize = _ROUNDUP(pheader->p_memsz
|
||||||
|
+ (pheader->p_vaddr % B_PAGE_SIZE), B_PAGE_SIZE)
|
||||||
|
- image->regions[regcount-1].vmsize;
|
||||||
image->regions[regcount].fdstart = 0;
|
image->regions[regcount].fdstart = 0;
|
||||||
image->regions[regcount].fdsize = 0;
|
image->regions[regcount].fdsize = 0;
|
||||||
image->regions[regcount].delta = 0;
|
image->regions[regcount].delta = 0;
|
||||||
@ -536,7 +546,7 @@ map_image(int fd, char const *path, image_t *image, bool fixed)
|
|||||||
LOCK_RW,
|
LOCK_RW,
|
||||||
REGION_PRIVATE_MAP,
|
REGION_PRIVATE_MAP,
|
||||||
path,
|
path,
|
||||||
_ROUNDOWN(image->regions[i].fdstart, PAGE_SIZE));
|
_ROUNDOWN(image->regions[i].fdstart, B_PAGE_SIZE));
|
||||||
|
|
||||||
if (image->regions[i].id < 0)
|
if (image->regions[i].id < 0)
|
||||||
goto error;
|
goto error;
|
||||||
@ -722,20 +732,20 @@ resolve_symbol(image_t *image, struct Elf32_Sym *sym, addr *sym_addr)
|
|||||||
sym2 = find_symbol_in_loaded_images(&shimg, symname);
|
sym2 = find_symbol_in_loaded_images(&shimg, symname);
|
||||||
if (!sym2) {
|
if (!sym2) {
|
||||||
printf("elf_resolve_symbol: could not resolve symbol '%s'\n", symname);
|
printf("elf_resolve_symbol: could not resolve symbol '%s'\n", symname);
|
||||||
return ERR_ELF_RESOLVING_SYMBOL;
|
return B_MISSING_SYMBOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure they're the same type
|
// make sure they're the same type
|
||||||
if (ELF32_ST_TYPE(sym->st_info) != STT_NOTYPE
|
if (ELF32_ST_TYPE(sym->st_info) != STT_NOTYPE
|
||||||
&& ELF32_ST_TYPE(sym->st_info) != ELF32_ST_TYPE(sym2->st_info)) {
|
&& ELF32_ST_TYPE(sym->st_info) != ELF32_ST_TYPE(sym2->st_info)) {
|
||||||
printf("elf_resolve_symbol: found symbol '%s' in shared image but wrong type\n", symname);
|
printf("elf_resolve_symbol: found symbol '%s' in shared image but wrong type\n", symname);
|
||||||
return ERR_ELF_RESOLVING_SYMBOL;
|
return B_MISSING_SYMBOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ELF32_ST_BIND(sym2->st_info) != STB_GLOBAL
|
if (ELF32_ST_BIND(sym2->st_info) != STB_GLOBAL
|
||||||
&& ELF32_ST_BIND(sym2->st_info) != STB_WEAK) {
|
&& ELF32_ST_BIND(sym2->st_info) != STB_WEAK) {
|
||||||
printf("elf_resolve_symbol: found symbol '%s' but not exported\n", symname);
|
printf("elf_resolve_symbol: found symbol '%s' but not exported\n", symname);
|
||||||
return ERR_ELF_RESOLVING_SYMBOL;
|
return B_MISSING_SYMBOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
*sym_addr = sym2->st_value + shimg->regions[0].delta;
|
*sym_addr = sym2->st_value + shimg->regions[0].delta;
|
||||||
@ -746,9 +756,9 @@ resolve_symbol(image_t *image, struct Elf32_Sym *sym, addr *sym_addr)
|
|||||||
return B_NO_ERROR;
|
return B_NO_ERROR;
|
||||||
|
|
||||||
case SHN_COMMON:
|
case SHN_COMMON:
|
||||||
// XXX finish this
|
// ToDo: finish this
|
||||||
printf("elf_resolve_symbol: COMMON symbol, finish me!\n");
|
printf("elf_resolve_symbol: COMMON symbol, finish me!\n");
|
||||||
return ERR_NOT_IMPLEMENTED_YET;
|
return B_ERROR; //ERR_NOT_IMPLEMENTED_YET;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// standard symbol
|
// standard symbol
|
||||||
|
@ -3,39 +3,27 @@
|
|||||||
** Distributed under the terms of the NewOS License.
|
** Distributed under the terms of the NewOS License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <syscalls.h>
|
#include <syscalls.h>
|
||||||
#include "rld_priv.h"
|
#include "rld_priv.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
char const * const names[]=
|
|
||||||
{
|
|
||||||
"I'm too sexy!",
|
|
||||||
"BEWARE OF THE DUCK!",
|
|
||||||
"B_DONT_DO_THAT",
|
|
||||||
"I need a girlfriend!",
|
|
||||||
"assert(C++--!=C)",
|
|
||||||
"5038 RIP Nov. 2001",
|
|
||||||
"1.e4 e5 2.Nf3 Nc6 3.Bb5",
|
|
||||||
"Press any key..."
|
|
||||||
};
|
|
||||||
#define RLD_SCRATCH_SIZE 65536
|
#define RLD_SCRATCH_SIZE 65536
|
||||||
#define RLD_PROGRAM_BASE 0x00200000 /* keep in sync with app ldscript */
|
#define RLD_PROGRAM_BASE 0x00200000 /* keep in sync with app ldscript */
|
||||||
|
|
||||||
|
|
||||||
|
static region_id rld_region;
|
||||||
static region_id rld_region;
|
static region_id rld_region_2;
|
||||||
static region_id rld_region_2;
|
static char *rld_base;
|
||||||
static char *rld_base;
|
static char *rld_base_2;
|
||||||
static char *rld_base_2;
|
static char *rld_ptr;
|
||||||
static char *rld_ptr;
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
rldheap_init(void)
|
rldheap_init(void)
|
||||||
{
|
{
|
||||||
rld_region = _kern_create_area((char *)names[sys_get_current_team_id() % (sizeof(names) / sizeof(names[0]))],
|
rld_region = _kern_create_area("rld scratch",
|
||||||
(void **)&rld_base, B_ANY_ADDRESS, RLD_SCRATCH_SIZE,
|
(void **)&rld_base, B_ANY_ADDRESS, RLD_SCRATCH_SIZE,
|
||||||
B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
|
B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user