Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file library: implement file_close #100

Open
perlun opened this issue Oct 6, 2017 · 3 comments
Open

file library: implement file_close #100

perlun opened this issue Oct 6, 2017 · 3 comments

Comments

@perlun
Copy link
Contributor

perlun commented Oct 6, 2017

We have support for opening, and reading from files, but we don't have any support at the moment for closing file handles... 😉

@doverhill
Copy link

doverhill commented Oct 6, 2017 via email

@perlun
Copy link
Contributor Author

perlun commented Oct 7, 2017

Or deallocating memory... ;)

We actually have that implemented, but it's not enabled by default. Probably doesn't work very well. But yes, we should definitely fix that. I've also given the general subject a bit of thought, see #4. (discusses sbrk etc.)

/* Deallocate the given block. */
/* FIXME: Think about whether the virtual or physical memory should be
deallocated first. */
return_type memory_deallocate (void **address)
{
uint32_t page_number = ((uint32_t) *address) / SIZE_PAGE;
if (!current_tss->initialised)
{
return STORM_RETURN_ACCESS_DENIED;
}
#ifndef DEALLOCATE
return STORM_RETURN_SUCCESS;
#endif
mutex_kernel_wait (&memory_mutex);
switch (memory_virtual_deallocate (page_number))
{
case RETURN_SUCCESS:
{
page_table_entry *page_table = (page_table_entry *)
(BASE_PROCESS_PAGE_TABLES + (page_number / (1 * MB)) * SIZE_PAGE);
uint32_t physical_page = page_table[page_number % 1024].page_base;
/* FIXME: Check the return value from this call. But what do we
do should it fail? */
memory_physical_deallocate (physical_page);
mutex_kernel_signal (&memory_mutex);
*address = NULL;
return STORM_RETURN_SUCCESS;
}
case RETURN_MEMORY_NOT_ALLOCATED:
{
mutex_kernel_signal (&memory_mutex);
return STORM_RETURN_MEMORY_NOT_ALLOCATED;
}
default:
{
DEBUG_HALT ("Unknown return code.");
}
}
}

@perlun
Copy link
Contributor Author

perlun commented Jul 5, 2019

For the record: I tested enabling memory deallocation but it made the system run into errors, so we definitely have a problem there. Continuing in #4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants